*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

body {
  min-height: 100vh;
  background: #1d1d1d;
  display: flex;
  flex-direction: column;
  padding: 4rem 2rem;
  font-family: sans-serif;
}

/* 見出し */
.c3-head {
  width: 100%;
  max-width: 112rem;
  margin: 0 auto 3rem;
  text-align: center;
}

.c3-head-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 1.2rem;
}

.c3-head-top h1 {
  grid-column: 2;
}

.c3-head-top .lang-switch {
  grid-column: 3;
  justify-self: end;
}

.lang-switch {
  margin: 0;
}

.lang-switch a {
  display: inline-block;
  color: #cfe0ef;
  text-decoration: none;
  font-size: 1.6rem;
  background: #2b3540;
  border: 0.1rem solid #3a4856;
  border-radius: 0.8rem;
  padding: 0.5rem 1.4rem;
  transition: background 0.12s ease;
}

.lang-switch a:hover {
  background: #34414f;
}

.c3-head h1 {
  color: #e8e4df;
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1.35;
}

.c3-head .accent {
  color: #b9c4cf;
}

.c3-head p {
  color: #9a9591;
  font-size: 1.6rem;
  line-height: 1.8;
  max-width: 70rem;
  margin: 1.2rem auto 0;
}

/* アプリ本体：左＝プレビュー＋コード / 右＝サイドバー */
.c3-app {
  width: 100%;
  max-width: 112rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34rem;
  gap: 2.8rem;
  align-items: start;
}

.c3-main {
  display: flex;
  flex-direction: column;
  gap: 2.4rem;
  min-width: 0;
}

/* 大きなプレビュー */
.preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42rem;
  padding: 3rem;
  overflow: hidden;
  background: #161616;
  border: 0.1rem solid #2a2a2a;
  border-radius: 1.6rem;
}

.preview[data-bg="light"] {
  background: #f5f5f5;
  border-color: #e2e2e2;
}

.bg-toggle {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 3;
  display: flex;
  gap: 0.4rem;
}

.bg-btn {
  background: rgba(0, 0, 0, 0.35);
  color: #e0dcd7;
  border: 0.1rem solid rgba(255, 255, 255, 0.18);
  border-radius: 0.7rem;
  padding: 0.5rem 1.1rem;
  font-size: 1.6rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.bg-btn.is-active {
  background: #b9c4cf;
  border-color: #b9c4cf;
  color: #141414;
  font-weight: 700;
}

.preview[data-bg="light"] .bg-btn {
  background: rgba(255, 255, 255, 0.7);
  color: #444;
  border-color: rgba(0, 0, 0, 0.15);
}

.preview[data-bg="light"] .bg-btn.is-active {
  background: #2b3540;
  color: #f5f5f5;
  border-color: #2b3540;
}

/* タイプ別のプレビューをマウントするホスト */
.c3-host {
  width: 100%;
  height: 100%;
  min-height: 36rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === 3Dカルーセル本体（メリーゴーランド） === */
.c3-scene {
  --c3-hue: 210;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 36rem;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1200px;
  touch-action: pan-y;
  user-select: none;
}

.c3-tilt {
  position: relative;
  width: 1px;
  height: 1px;
  transform-style: preserve-3d;
}

.c3-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-style: preserve-3d;
}

.c3-card {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 1.6rem;
  background: linear-gradient(
    160deg,
    hsl(var(--c3-hue), 40%, 34%),
    hsl(var(--c3-hue), 46%, 12%)
  );
  border: 0.1rem solid hsla(var(--c3-hue), 50%, 80%, 0.25);
  box-shadow: 0 1.8rem 4rem rgba(0, 0, 0, 0.45);
  color: hsl(var(--c3-hue), 45%, 86%);
  font-size: 3.2rem;
  font-weight: 700;
  overflow: hidden;
}

/* === カードスタック型（テンプレート2） === */
.cs-wrap {
  --cs-hue: 8;
  position: relative;
  width: 100%;
  max-width: var(--cs-w, 500px);
  height: var(--cs-h, 400px);
  margin: 0 auto;
  perspective: var(--cs-p, 1000px);
  touch-action: pan-y;
  user-select: none;
}

.cs-card {
  position: absolute;
  inset: 0;
  display: flex;
  background: #fff;
  border-radius: 1.4rem;
  overflow: hidden;
  box-shadow: 0 1.4rem 3.6rem hsla(var(--cs-hue), 85%, 55%, 0.55);
  transform-style: preserve-3d;
  will-change: transform, opacity;
}

.cs-card:nth-child(even) {
  flex-direction: row-reverse;
}

.cs-img {
  width: 56%;
  height: 100%;
  background: linear-gradient(150deg, hsl(var(--cs-hue), 72%, 62%), hsl(var(--cs-hue), 65%, 38%));
}

.cs-text {
  width: 44%;
  padding: 2rem 2.2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.6rem;
}

.cs-text h3 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.3;
}

.cs-text p {
  margin: 0;
  font-size: 1.6rem;
  color: #666;
}

/* サイドバー */
.c3-sidebar {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  position: sticky;
  top: 2rem;
}

.panel {
  background: #161616;
  border: 0.1rem solid #2a2a2a;
  border-radius: 1.4rem;
  padding: 1.8rem;
}

.panel-title {
  color: #e8e4df;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.panel-note {
  margin-top: 0.4rem;
  margin-bottom: 1.4rem;
  color: #8f8a86;
  font-size: 1.5rem;
  line-height: 1.6;
}

/* トグル行（自動回転など） */
.toggle-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.6rem;
}

.toggle-btn {
  flex: 1;
  background: #232323;
  color: #b6b1ac;
  border: 0.1rem solid #343434;
  border-radius: 0.9rem;
  padding: 0.9rem;
  font-size: 1.6rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.toggle-btn:hover {
  background: #2c2c2c;
}

.toggle-btn.is-active {
  background: #2b3540;
  border-color: #b9c4cf;
  color: #cfe0ef;
  font-weight: 700;
}

/* テンプレート（プリセット） */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
}

.tpl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem 0.4rem;
  background: #232323;
  border: 0.1rem solid #343434;
  border-radius: 1rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.tpl-btn:hover {
  background: #2c2c2c;
}

.tpl-btn.is-active {
  background: #2b3540;
  border-color: #b9c4cf;
}

.tpl-id {
  color: #d8d3ce;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.tpl-btn.is-active .tpl-id {
  color: #cfe0ef;
}

/* スライダー */
.ctrl {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  width: 100%;
}

.ctrl-row {
  display: grid;
  grid-template-columns: 7rem 1fr 4.5rem;
  align-items: center;
  gap: 0.8rem;
}

.ctrl-name {
  color: #8f8a86;
  font-size: 1.6rem;
  font-family: monospace;
}

.ctrl-val {
  color: #cfcac5;
  font-size: 1.6rem;
  font-family: monospace;
  text-align: right;
}

.sld {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.4rem;
  border-radius: 0.4rem;
  background: #3a3a3a;
  cursor: pointer;
}

.sld::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: #b9c4cf;
  border: none;
  cursor: pointer;
}

.sld::-moz-range-thumb {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: #b9c4cf;
  border: none;
  cursor: pointer;
}

.sld-hue {
  background: linear-gradient(
    to right,
    hsl(0, 60%, 60%),
    hsl(60, 60%, 60%),
    hsl(120, 60%, 60%),
    hsl(180, 60%, 60%),
    hsl(240, 60%, 60%),
    hsl(300, 60%, 60%),
    hsl(360, 60%, 60%)
  );
}

/* 生成コードパネル */
.code-panel {
  width: 100%;
  background: #141414;
  border: 0.1rem solid #2c2c2c;
  border-radius: 1.2rem;
  overflow: hidden;
}

.code-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.2rem;
  padding: 1.4rem 1.6rem;
  background: #1b1b1b;
  border-bottom: 0.1rem solid #2c2c2c;
}

.code-title {
  color: #e8e4df;
  font-size: 1.7rem;
  font-weight: 700;
}

.code-meta {
  margin-left: 0.6rem;
  color: #8f8a86;
  font-size: 1.5rem;
  font-weight: 400;
  font-family: monospace;
}

.code-tabs {
  display: inline-flex;
  gap: 0.6rem;
  margin-left: auto;
}

.tab {
  background: #262626;
  color: #b6b1ac;
  border: 0.1rem solid #353535;
  border-radius: 0.8rem;
  padding: 0.7rem 1.2rem;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.tab:hover {
  background: #2f2f2f;
}

.tab.is-active {
  background: #b9c4cf;
  color: #141414;
  border-color: #b9c4cf;
  font-weight: 700;
}

.copy-btn {
  background: #2b3540;
  color: #cfe0ef;
  border: 0.1rem solid #3a4856;
  border-radius: 0.8rem;
  padding: 0.7rem 1.4rem;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.12s ease;
}

.copy-btn:hover {
  background: #34414f;
}

.copy-btn.is-copied {
  background: #2f5d3a;
  border-color: #2f5d3a;
  color: #d6f5dd;
}

.code-block {
  margin: 0;
  padding: 1.8rem;
  overflow-x: auto;
  max-height: 44rem;
}

.code-block code {
  display: block;
  color: #d6d1cc;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 1.6rem;
  line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

/* 広告（ツール系ページ規格：固定サイズ・CLS防止） */
.ad-wrap {
  min-height: 90px;
}

.ad-banner {
  width: 728px;
  height: 90px;
}

@media screen and (max-width: 727px) {
  .ad-wrap {
    min-height: 100px;
  }
  .ad-banner {
    width: 320px;
    height: 100px;
  }
}

.c3-foot {
  margin: 4rem auto 0;
  text-align: center;
  color: #6f6b68;
  font-size: 1.6rem;
  line-height: 2;
}

.c3-foot a {
  color: #9aa6b2;
  text-decoration: none;
}

.c3-foot a:hover {
  text-decoration: underline;
}

.c3-foot-links {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.6rem;
  margin-left: 1.6rem;
}

/* 狭い画面：h1と言語ボタンを縦積み */
@media (max-width: 860px) {
  .c3-head-top {
    grid-template-columns: 1fr;
  }
  .c3-head-top h1 {
    grid-column: 1;
    grid-row: 2;
  }
  .c3-head-top .lang-switch {
    grid-column: 1;
    grid-row: 1;
    margin-bottom: 1.2rem;
  }
}

/* タブレット以下：1カラム（プレビュー → 設定 → コード） */
@media (max-width: 880px) {
  .c3-app {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2rem;
  }
  .c3-main {
    display: contents;
  }
  .preview {
    order: 1;
    position: sticky;
    top: 0;
    z-index: 5;
    min-height: 34rem;
  }
  .c3-sidebar {
    order: 2;
    position: static;
  }
  .code-panel {
    order: 3;
  }
}

@media (max-width: 480px) {
  .preview {
    min-height: 30rem;
    padding: 1.5rem;
  }
  .c3-head h1 {
    font-size: 2.4rem;
  }
  .c3-foot-links {
    display: flex;
    margin-left: 0;
    margin-top: 0.8rem;
  }
}
