/* =========================================================
   OTOMO PUZZLE — pure web-standards stylesheet
   使用技術: @layer / CSSネスト / oklch / color-mix / @property /
   scroll-driven animations / container queries / :has() /
   view transitions / text-wrap: balance
   ========================================================= */

@layer reset, tokens, base, components, sections, motion, game;

/* ---------- reset ---------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  img, canvas, svg { display: block; max-width: 100%; }
  img { height: auto; }
  button, input, select { font: inherit; color: inherit; }
  ul, ol { list-style: none; }
}

/* ---------- tokens ---------- */
@layer tokens {
  :root {
    color-scheme: dark;

    --bg: oklch(0.13 0.03 275);
    --bg-deep: oklch(0.10 0.025 280);
    --surface: oklch(0.18 0.035 275);
    --surface-2: oklch(0.22 0.04 275);
    --line: oklch(0.32 0.04 275 / 0.6);

    --text: oklch(0.93 0.01 270);
    --text-dim: oklch(0.72 0.02 270);

    --accent: oklch(0.78 0.16 195);       /* シアン */
    --accent-2: oklch(0.72 0.19 310);     /* マゼンタ寄り紫 */
    --accent-warm: oklch(0.8 0.15 60);    /* 琥珀 */
    --gold-text: #f2cc63;

    --glow: color-mix(in oklch, var(--accent) 40%, transparent);

    --radius: 18px;
    --radius-sm: 10px;

    --font-display: "Avenir Next", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;

    --space-section: clamp(5rem, 12vw, 9rem);
    --pad-inline: clamp(1.25rem, 4vw, 3rem);
  }

  /* アニメーション可能なカスタムプロパティ */
  @property --count-glow {
    syntax: "<percentage>";
    inherits: false;
    initial-value: 0%;
  }
}

/* ---------- base ---------- */
@layer base {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: 6rem;
    scrollbar-gutter: stable;
  }

  body {
    font-family: var(--font-display);
    background:
      radial-gradient(60rem 40rem at 80% -10%, color-mix(in oklch, var(--accent-2) 14%, transparent), transparent 60%),
      radial-gradient(50rem 35rem at -10% 30%, color-mix(in oklch, var(--accent) 10%, transparent), transparent 60%),
      linear-gradient(var(--bg), var(--bg-deep));
    color: var(--text);
    line-height: 1.8;
    overflow-x: clip;
    min-height: 100vh;
    min-height: 100svh;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  h1, h2, h3 {
    line-height: 1.25;
    text-wrap: balance;
    font-weight: 700;
    letter-spacing: 0.01em;
  }

  a { color: inherit; text-decoration: none; }

  .skip-link {
    position: fixed;
    top: -100%;
    left: 1rem;
    z-index: 100;
    padding: 0.6rem 1rem;
    background: var(--accent);
    color: oklch(0.15 0.02 275);
    border-radius: var(--radius-sm);
    &:focus-visible { top: 1rem; }
  }

  #starfield {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
  }
}

/* ---------- components ---------- */
@layer components {

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.65em 1.4em;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.3s ease, background 0.3s ease;

    &:active { transform: scale(0.97); }
    &:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  }

  .btn-primary {
    background: linear-gradient(120deg, var(--accent), color-mix(in oklch, var(--accent-2) 70%, var(--accent)));
    color: oklch(0.14 0.02 275);
    box-shadow: 0 0 0 0 var(--glow);

    &:hover {
      box-shadow: 0 0 2.2rem 0.2rem var(--glow);
      transform: translateY(-2px);
    }
  }

  .btn-ghost {
    background: color-mix(in oklch, var(--surface) 60%, transparent);
    border-color: var(--line);
    color: var(--text);
    backdrop-filter: blur(8px);

    &:hover { background: var(--surface-2); }
  }

  .btn-lg { padding: 0.85em 1.9em; font-size: 1.05rem; }

  /* --- ダイアログ共通 --- */
  dialog {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(color-mix(in oklch, var(--surface) 96%, var(--accent-2)), var(--surface));
    color: var(--text);
    padding: 0;
    max-inline-size: min(92vw, 640px);
    margin: auto;
    box-shadow: 0 2rem 6rem oklch(0 0 0 / 0.6);

    &::backdrop {
      background: oklch(0.08 0.02 275 / 0.7);
      backdrop-filter: blur(6px);
    }

    &[open] { animation: dialog-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }
  }

  @keyframes dialog-in {
    from { opacity: 0; transform: translateY(2rem) scale(0.96); }
  }

  .dialog-close {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    z-index: 2;
    inline-size: 2.2rem;
    block-size: 2.2rem;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: color-mix(in oklch, var(--bg) 70%, transparent);
    cursor: pointer;
    backdrop-filter: blur(4px);

    &:hover { background: var(--surface-2); }
  }

}

/* ---------- sections ---------- */
@layer sections {

  /* --- スクロール進捗（scroll-driven animation） --- */
  .scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 60;
    transform-origin: left;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    scale: 0 1;
  }

  @supports (animation-timeline: scroll()) {
    .scroll-progress {
      animation: grow-x linear both;
      animation-timeline: scroll(root);
    }
    @keyframes grow-x { from { scale: 0 1; } to { scale: 1 1; } }
  }

  /* --- header --- */
  .site-header {
    position: fixed;
    top: 0;
    inset-inline: 0;
    z-index: 50;
    padding: 0.9rem var(--pad-inline);
  }

  .nav {
    display: flex;
    align-items: center;
    gap: 2rem;
    max-inline-size: 1200px;
    margin-inline: auto;
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: color-mix(in oklch, var(--bg) 65%, transparent);
    backdrop-filter: blur(14px) saturate(1.4);
  }

  .brand {
    font-weight: 800;
    letter-spacing: 0.18em;
    font-size: 1.3rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    background: linear-gradient(180deg, #fff1a8 0%, #f6c84f 48%, #d99a28 100%);
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 1.4rem color-mix(in oklch, #f6c84f 45%, transparent);
  }

  .nav-links {
    display: flex;
    gap: 1.6rem;
    margin-inline-start: auto;
    font-size: 0.92rem;
    color: var(--text-dim);

    a {
      position: relative;
      transition: color 0.25s;
      &:hover { color: var(--text); }
      &::after {
        content: "";
        position: absolute;
        left: 0; right: 100%;
        bottom: -4px;
        height: 2px;
        background: var(--accent);
        transition: right 0.3s ease;
      }
      &:hover::after, &[aria-current="true"]::after { right: 0; }
      &[aria-current="true"] { color: var(--text); }
    }
  }

  @media (max-width: 720px) {
    .site-header {
      padding: 0.65rem clamp(0.5rem, 3vw, 1rem);
    }

    .nav-links { display: none; }

    .nav {
      flex-wrap: nowrap;
      gap: 0.65rem;
      padding: 0.5rem 0.75rem;
    }

    .brand {
      min-width: 0;
      flex: 1 1 auto;
      white-space: nowrap;
      font-size: clamp(0.95rem, 4.5vw, 1.15rem);
      letter-spacing: 0.1em;
    }

    .btn-book {
      min-height: 44px;
      flex: 0 0 auto;
      margin-inline-start: auto;
      padding: 0.6em 1em;
      white-space: nowrap;
      font-size: 0.9rem;
    }
  }

  /* --- hero --- */
  .hero {
    min-height: 100vh;
    min-height: 100svh;
    display: grid;
    place-content: center;
    justify-items: center;
    text-align: center;
    padding: 7rem var(--pad-inline) 4rem;
    position: relative;
  }

  .hero-eyebrow {
    letter-spacing: 0.35em;
    font-size: 0.78rem;
    color: var(--accent);
    margin-bottom: 1.4rem;
  }

  .hero-title {
    font-size: clamp(2.6rem, 8.5vw, 6rem);
    font-weight: 800;
    display: grid;

    .accent {
      background: linear-gradient(100deg, var(--accent), var(--accent-2), var(--accent-warm));
      background-clip: text;
      color: transparent;
    }
  }

  .hero-lead {
    max-inline-size: 42ch;
    margin-top: 1.6rem;
    color: var(--text-dim);
    text-wrap: pretty;
  }

  .hero-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 2.4rem;
  }

  /* --- section 共通 --- */
  .section {
    padding: var(--space-section) var(--pad-inline);
    max-inline-size: 1200px;
    margin-inline: auto;
  }

  #journey,
  #characters {
    content-visibility: auto;
    contain-intrinsic-block-size: auto 2600px;
  }

  .section-narrow { max-inline-size: 820px; }

  .section-head { text-align: center; margin-bottom: 3.5rem; }

  #destinations .section-head {
    scroll-margin-top: 2rem;
    margin-bottom: 2rem;
  }

  #destinations {
    padding-top: 2rem;
  }

  .section-eyebrow {
    letter-spacing: 0.35em;
    font-size: 0.75rem;
    color: var(--accent);
    margin-bottom: 0.8rem;
  }

  .section-title { font-size: clamp(1.7rem, 4.5vw, 2.7rem); }

  .section-lead {
    margin-top: 1rem;
    color: var(--text-dim);
    max-inline-size: 52ch;
    margin-inline: auto;
    text-wrap: pretty;
  }

  /* --- destinations（コンテナクエリ） --- */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 1.4rem;
  }

  .dest-card {
    container-type: inline-size;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 70%, transparent);
    overflow: clip;
    cursor: pointer;
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.3, 1.2), border-color 0.3s, box-shadow 0.3s;

    &:hover, &:focus-visible {
      transform: translateY(-6px);
      border-color: color-mix(in oklch, var(--accent) 60%, var(--line));
      box-shadow: 0 1.4rem 3rem oklch(0 0 0 / 0.4), 0 0 2rem var(--glow);
    }
    &:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  }

  .dest-visual {
    height: 170px;
    position: relative;
    overflow: clip;
    background: var(--bg-deep);

    &::before {
      content: "";
      position: absolute;
      inset: -20%;
      border-radius: 50%;
      transition: transform 0.6s ease;
    }
  }

  .dest-card:hover .dest-visual::before { transform: scale(1.08) rotate(6deg); }

  /* 各天体を純CSSグラデーションで描画 */
  [data-body="moon"]::before {
    inset: 22% 18% -55%;
    background:
      radial-gradient(18% 18% at 34% 28%, oklch(0.6 0.01 270 / 0.7), transparent 70%),
      radial-gradient(12% 12% at 62% 48%, oklch(0.58 0.01 270 / 0.6), transparent 70%),
      radial-gradient(circle at 35% 30%, oklch(0.92 0.005 270), oklch(0.55 0.01 270) 70%);
    box-shadow: 0 0 4rem oklch(0.9 0.01 270 / 0.35);
  }

  [data-body="mars"]::before {
    inset: 22% 18% -55%;
    background:
      radial-gradient(30% 12% at 50% 55%, oklch(0.4 0.1 35 / 0.8), transparent 70%),
      radial-gradient(circle at 35% 30%, oklch(0.75 0.16 45), oklch(0.42 0.13 30) 72%);
    box-shadow: 0 0 4rem oklch(0.65 0.18 40 / 0.4);
  }

  [data-body="europa"]::before {
    inset: 22% 18% -55%;
    background:
      linear-gradient(105deg, transparent 42%, oklch(0.6 0.06 60 / 0.5) 43%, transparent 45%),
      linear-gradient(70deg, transparent 60%, oklch(0.62 0.05 50 / 0.4) 61%, transparent 63%),
      radial-gradient(circle at 35% 30%, oklch(0.93 0.02 220), oklch(0.62 0.05 230) 72%);
    box-shadow: 0 0 4rem oklch(0.8 0.08 220 / 0.4);
  }

  [data-body="orbit"]::before {
    inset: 22% 18% -55%;
    background:
      radial-gradient(40% 25% at 45% 40%, oklch(0.85 0.05 140 / 0.5), transparent 70%),
      radial-gradient(circle at 35% 30%, oklch(0.8 0.12 230), oklch(0.4 0.12 250) 72%);
    box-shadow: 0 0 4rem oklch(0.7 0.14 235 / 0.45);
  }

  .dest-body { padding: 1.4rem 1.5rem 1.6rem; }

  .dest-tag {
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    color: var(--accent);
    margin-bottom: 0.5rem;
  }

  .dest-body h3 { font-size: 1.25rem; margin-bottom: 0.6rem; }

  .dest-desc { font-size: 0.9rem; color: var(--text-dim); }

  .dest-price {
    margin-top: 1rem;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;

    small { color: var(--text-dim); font-size: 0.75rem; }
    strong { color: var(--gold-text); font-size: 1.05rem; }
  }

  /* --- dest dialog --- */
  .dest-dialog { inline-size: min(92vw, 720px); }

  .dest-dialog-visual {
    height: 220px;
    position: relative;
    overflow: clip;
    background: var(--bg-deep);
    &::before {
      content: "";
      position: absolute;
      inset: -20%;
      border-radius: 50%;
    }
  }

  .dest-dialog-body { padding: 1.8rem 2rem 2rem; }

  .dest-dialog-body h3 { font-size: 1.6rem; margin-bottom: 0.8rem; }

  .dest-dialog-body > p { color: var(--text-dim); }

  .dest-dialog-facts {
    margin-block: 1.4rem;
    display: grid;
    gap: 0.5rem;

    li {
      display: flex;
      justify-content: space-between;
      gap: 1rem;
      padding: 0.6rem 0.9rem;
      border: 1px solid var(--line);
      border-radius: var(--radius-sm);
      background: color-mix(in oklch, var(--bg) 55%, transparent);
      font-size: 0.9rem;

      b { color: var(--accent); font-weight: 600; }
    }
  }

  .dest-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
  }

  /* --- timeline --- */
  .timeline {
    max-inline-size: 760px;
    margin-inline: auto;
    display: grid;
    gap: 1rem;
    counter-reset: step;
  }

  .timeline-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1.4rem;
    align-items: start;
    padding: 1.5rem 1.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 55%, transparent);
    position: relative;

    h3 { font-size: 1.1rem; margin-bottom: 0.4rem; }
    p { font-size: 0.92rem; color: var(--text-dim); }
  }

  .timeline-no {
    font-size: 1.5rem;
    font-weight: 800;
    color: color-mix(in oklch, var(--accent) 70%, var(--text));
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
  }

  /* --- 添付デザインに合わせた遊び方 --- */
  .howto-section {
    max-inline-size: 100%;
    padding-block: 2rem clamp(5.5rem, 9vw, 8rem);
  }

  .howto-content {
    width: min(100%, 760px);
    margin-inline: auto;
  }

  .howto-head {
    margin-bottom: 2rem;
  }

  .howto-head .section-title,
  #destinations .section-title {
    color: var(--gold-text);
    font-size: clamp(2rem, 5vw, 2.8rem);
    letter-spacing: 0.08em;
    text-shadow: 0 0 1.3rem color-mix(in oklch, var(--accent-warm) 35%, transparent);
  }

  .howto-list {
    display: grid;
    gap: 0.85rem;
  }

  .howto-card {
    padding: clamp(1rem, 3vw, 1.35rem);
    border: 1px solid var(--line);
    border-radius: 15px;
    background: color-mix(in oklch, var(--surface) 70%, transparent);
    box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.035), 0 0.9rem 2.5rem oklch(0 0 0 / 0.12);
  }

  .howto-title {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.9rem;
    color: var(--gold-text);
    font-size: clamp(1rem, 3vw, 1.18rem);
  }

  .howto-no {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 1.75rem;
    aspect-ratio: 1;
    border-radius: 50%;
    background: linear-gradient(145deg, #ffe68b, #efb83d);
    color: #2b1b07;
    font-weight: 900;
    line-height: 1;
    padding-bottom: 0.12rem;
    box-shadow: 0 0 0.8rem rgb(242 204 99 / 0.18);
  }

  .howto-figure {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.35rem, 1.6vw, 0.75rem);
    margin: 0.2rem auto 0.85rem;
  }

  .howto-figure figure {
    flex: 0 1 clamp(54px, 13vw, 78px);
    width: clamp(54px, 13vw, 78px);
    min-width: 0;
    text-align: center;
  }

  .howto-figure img,
  .howto-gods img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid color-mix(in oklch, var(--text-dim) 65%, var(--line));
    border-radius: 10px;
    background: var(--bg-deep);
  }

  .howto-figure figcaption {
    margin-top: 0.25rem;
    color: color-mix(in oklch, var(--text) 86%, var(--text-dim));
    font-size: clamp(0.56rem, 1.8vw, 0.7rem);
    line-height: 1.25;
    white-space: nowrap;
  }

  .howto-symbol {
    flex: 0 0 auto;
    color: var(--gold-text);
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    font-weight: 900;
    line-height: 1;
    -webkit-text-stroke: 0.055em var(--gold-text);
    translate: 0 -0.55rem;
    text-shadow: none;
  }

  .howto-god img,
  .howto-gods img {
    border-width: 2px;
    border-color: var(--gold-text);
    box-shadow: 0 0 0.8rem rgb(242 204 99 / 0.24);
  }

  .howto-text {
    color: color-mix(in oklch, var(--text) 90%, var(--text-dim));
    font-size: clamp(0.76rem, 2vw, 0.9rem);
    line-height: 1.75;
  }

  .howto-text strong,
  .howto-modes strong {
    color: var(--gold-text);
  }

  .howto-gods {
    --howto-god-size: clamp(54px, 13vw, 78px);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(0.25rem, 1vw, 0.5rem);
    margin-top: 0.8rem;
  }

  .howto-gods img {
    flex: 0 0 var(--howto-god-size);
    width: var(--howto-god-size);
    height: var(--howto-god-size);
    min-width: var(--howto-god-size);
    max-width: var(--howto-god-size);
  }

  .howto-modes {
    display: grid;
    gap: 0.22rem;
    color: color-mix(in oklch, var(--text) 90%, var(--text-dim));
    font-size: clamp(0.76rem, 2vw, 0.9rem);
    line-height: 1.65;
  }

  .howto-modes li {
    display: grid;
    grid-template-columns: 1.35rem max-content 1rem 1fr;
    align-items: start;
  }

  .howto-modes em {
    color: var(--text-dim);
    font-style: normal;
    text-align: center;
  }

  .howto-note {
    margin-top: 0.75rem;
  }

  @media (max-width: 520px) {
    .howto-section {
      padding-inline: 0.8rem;
    }

    .howto-card {
      padding: 0.9rem 0.75rem;
    }

    .howto-figure {
      gap: 0.28rem;
    }

    .howto-figure figure {
      flex-basis: clamp(47px, 18vw, 66px);
      width: clamp(47px, 18vw, 66px);
    }

    .howto-evolution figure {
      flex-basis: clamp(43px, 14.5vw, 58px);
      width: clamp(43px, 14.5vw, 58px);
    }

    .howto-gods {
      --howto-god-size: clamp(43px, 14.5vw, 58px);
    }

    .howto-modes li {
      grid-template-columns: 1.25rem max-content 0.8rem 1fr;
    }
  }

  /* --- キャラクター図鑑 --- */
  .character-codex {
    --codex-gold-light: #fff1a8;
    --codex-gold: #f6c84f;
    --codex-gold-deep: #a96c14;
    --codex-gold-gradient: linear-gradient(180deg, var(--codex-gold-light) 0%, var(--codex-gold) 48%, #d99a28 100%);
    max-inline-size: 960px;
    padding-top: 2rem;
    padding-bottom: clamp(2rem, 4vw, 3rem);
  }

  .dest-action {
    display: inline-flex;
    margin-top: 1rem;
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    transition: translate 0.25s ease;
  }

  .dest-card:hover .dest-action,
  .dest-card:focus-visible .dest-action {
    translate: 0.35rem 0;
  }

  .character-codex .section-head {
    margin-bottom: 2rem;
  }

  .character-codex .section-title {
    background: var(--codex-gold-gradient);
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 1.4rem color-mix(in oklch, var(--codex-gold) 45%, transparent);
  }

  .character-codex .section-eyebrow {
    color: var(--codex-gold-light);
  }

  .codex-list {
    display: grid;
    gap: 1rem;
    max-inline-size: 760px;
    margin-inline: auto;
  }

  .codex-card,
  .codex-finale {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: color-mix(in oklch, var(--surface) 70%, transparent);
    box-shadow: 0 1rem 2.4rem oklch(0 0 0 / 0.22);
    backdrop-filter: blur(7px);
  }

  .codex-card {
    --codex-evolution-gap: clamp(0.3rem, 1.2vw, 0.7rem);
    --codex-arrow-column: clamp(1rem, 2.5vw, 1.45rem);
    padding: clamp(1rem, 3vw, 1.5rem);
  }

  .codex-card-head {
    display: grid;
    grid-template-columns: minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr);
    column-gap: var(--codex-evolution-gap);
    align-items: stretch;
    padding-inline: 1rem;
    translate: 0 0.6rem;
  }

  .codex-name { grid-column: 1 / 6; }
  .codex-god-name { grid-column: 7; }

  .codex-name,
  .codex-god-name {
    display: grid;
    place-content: center;
    min-height: 2.7rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid color-mix(in oklch, var(--accent) 52%, var(--line));
    border-radius: 0.55rem;
    background: linear-gradient(180deg, color-mix(in oklch, var(--surface) 86%, var(--accent)), color-mix(in oklch, var(--bg-deep) 82%, var(--accent)));
    box-shadow:
      inset 0 0 0 1px color-mix(in oklch, var(--accent) 13%, transparent),
      0 0 0.75rem color-mix(in oklch, var(--accent) 9%, transparent);
    text-align: center;
    line-height: 1.1;
  }

  .codex-name h3,
  .codex-god-name strong {
    background: var(--codex-gold-gradient);
    background-clip: text;
    color: transparent;
    font-size: clamp(0.8rem, 2vw, 1rem);
    text-shadow: 0 0 0.7rem color-mix(in oklch, var(--codex-gold) 30%, transparent);
  }

  .codex-name span,
  .codex-god-name span {
    color: var(--text-dim);
    font-size: 0.58rem;
    letter-spacing: 0.15em;
  }

  .codex-name span { order: 2; }

  .codex-evolution {
    display: grid;
    grid-template-columns: minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr) var(--codex-arrow-column) minmax(54px, 1fr);
    column-gap: var(--codex-evolution-gap);
    align-items: center;
    margin-block: 1rem 0.8rem;
    padding: 1rem;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .codex-evolution figure {
    min-width: 0;
    align-self: start;
    text-align: center;
  }

  .codex-evolution img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid color-mix(in oklch, var(--text-dim) 65%, var(--line));
    border-radius: clamp(0.45rem, 1.5vw, 0.8rem);
    box-shadow: 0 0.6rem 1.1rem oklch(0 0 0 / 0.38);
  }

  .codex-evolution .codex-god img {
    border-width: 3px;
    border-color: #f0c34e;
    box-shadow:
      0 0 0.35rem rgb(240 195 78 / 0.62),
      0 0 0.8rem rgb(240 195 78 / 0.32);
  }

  .codex-evolution figcaption {
    margin-top: 0.35rem;
    color: var(--text-dim);
    font-size: clamp(0.52rem, 1.5vw, 0.7rem);
    line-height: 1.25;
  }

  .codex-evolution figcaption small {
    display: block;
    font-size: 0.9em;
  }

  .codex-arrow {
    color: var(--codex-gold);
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    font-weight: 900;
    line-height: 1;
    -webkit-text-stroke: 0.055em var(--codex-gold);
    translate: 0 -0.7rem;
    text-shadow: none;
    filter: none;
  }

  .codex-description {
    color: color-mix(in oklch, var(--text) 82%, var(--text-dim));
    font-size: clamp(0.75rem, 1.8vw, 0.9rem);
    line-height: 1.75;
  }

  .codex-description strong {
    color: var(--codex-gold);
  }

  .codex-finale {
    display: grid;
    justify-items: center;
    gap: 0.8rem;
    padding: clamp(1rem, 3vw, 1.6rem);
    text-align: center;
  }

  .codex-finale-label {
    display: grid;
    width: min(100%, 540px);
    min-height: 2.7rem;
    margin-bottom: 0.6rem;
    padding: 0.35rem 0.7rem;
    place-content: center;
    border: 1px solid color-mix(in oklch, var(--accent) 52%, var(--line));
    border-radius: 0.55rem;
    background: linear-gradient(180deg, color-mix(in oklch, var(--surface) 86%, var(--accent)), color-mix(in oklch, var(--bg-deep) 82%, var(--accent)));
    box-shadow:
      inset 0 0 0 1px color-mix(in oklch, var(--accent) 13%, transparent),
      0 0 0.75rem color-mix(in oklch, var(--accent) 9%, transparent);
  }

  .codex-finale-label span {
    background: var(--codex-gold-gradient);
    background-clip: text;
    color: transparent;
    font-size: clamp(0.8rem, 2vw, 1rem);
    font-weight: 700;
    letter-spacing: 0.12em;
    line-height: 1.4;
    text-shadow: 0 0 0.7rem color-mix(in oklch, var(--codex-gold) 30%, transparent);
  }

  .codex-finale img {
    width: min(100%, 540px);
    border: 3px solid var(--codex-gold);
    border-radius: var(--radius);
    box-shadow: 0 0 2rem color-mix(in oklch, var(--codex-gold) 30%, transparent);
  }

  .codex-finale h3 { color: var(--codex-gold); }
  .codex-finale > :last-child { color: var(--text-dim); font-size: 0.88rem; }

  @media (max-width: 520px) {
    .character-codex {
      padding-inline: 0.8rem;
    }

    .codex-list,
    .codex-card {
      min-width: 0;
    }

    .codex-card {
      --codex-evolution-gap: 0.2rem;
      --codex-arrow-column: 0.75rem;
      padding: 0.75rem;
    }

    .codex-card-head,
    .codex-evolution {
      grid-template-columns:
        minmax(0, 1fr) var(--codex-arrow-column)
        minmax(0, 1fr) var(--codex-arrow-column)
        minmax(0, 1fr) var(--codex-arrow-column)
        minmax(0, 1fr);
      column-gap: var(--codex-evolution-gap);
      padding-inline: 0;
    }

    .codex-evolution {
      padding-block: 0.75rem;
    }
  }

}

/* ---------- motion ---------- */
@layer motion {

  /* 基本は IntersectionObserver フォールバック用のクラス切替 */
  .reveal {
    opacity: 0;
    translate: 0 2.2rem;
    transition: opacity 0.7s ease, translate 0.7s cubic-bezier(0.2, 0.8, 0.3, 1);
  }

  .reveal.in-view {
    opacity: 1;
    translate: 0 0;
  }

  /* scroll-driven animations 対応ブラウザではビュー連動に置換 */
  @supports (animation-timeline: view()) {
    .reveal, .reveal.in-view {
      opacity: 1;
      translate: 0 0;
      transition: none;
      animation: reveal-up linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 55%;
    }

    /* ヒーロー内はページ表示時に即見えるので対象外にし、時間アニメで出す */
    .hero .reveal, .hero .reveal.in-view {
      animation: hero-in 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) both;
      animation-timeline: auto;
    }
    .hero .reveal:nth-child(2) { animation-delay: 0.1s; }
    .hero-title .reveal:nth-child(1) { animation-delay: 0.15s; }
    .hero-title .reveal:nth-child(2) { animation-delay: 0.3s; }
    .hero-lead { animation-delay: 0.45s !important; }
    .hero-actions { animation-delay: 0.6s !important; }
  }

  /* サイト全体をスクロール位置で動かしたり薄くしたりしない */
  .reveal,
  .reveal.in-view,
  .hero .reveal,
  .hero .reveal.in-view {
    opacity: 1;
    translate: 0 0;
    filter: none;
    transition: none;
    animation: none;
    animation-timeline: auto;
  }

  @keyframes reveal-up {
    from { opacity: 0; translate: 0 3rem; }
    to { opacity: 1; translate: 0 0; }
  }

  @keyframes hero-in {
    from { opacity: 0; translate: 0 2rem; filter: blur(6px); }
    to { opacity: 1; translate: 0 0; filter: blur(0); }
  }

  /* View Transitions（ダイアログ開閉時に JS から起動） */
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.35s;
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
    html { scroll-behavior: auto; }
    .reveal { opacity: 1; translate: 0 0; }
  }
}

/* ---------- OTOMO puzzle additions ---------- */
@layer game {
  .hero > :not(.hero-otomo) {
    position: relative;
    z-index: 1;
  }

  .hero-game-title {
    align-content: center;
    gap: 0.9rem;
    padding-block: 7.5rem 5.5rem;
  }

  .hero-game-title .game-logo {
    font-size: clamp(2.8rem, 7vw, 5.4rem);
    line-height: 1.1;
    letter-spacing: 0.12em;
    background: linear-gradient(180deg, #fff1a8 0%, #f6c84f 48%, #d99a28 100%);
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 1.4rem color-mix(in oklch, #f6c84f 45%, transparent);
    white-space: nowrap;
  }

  .hero-game-title .hero-game-art {
    width: min(52vw, 320px, 38vh);
    width: min(52vw, 320px, 38svh);
    max-height: none;
  }

  .hero-game-title .game-copy {
    font-size: clamp(0.95rem, 2vw, 1.15rem);
  }

  .hero-otomo {
    position: absolute;
    left: 50%;
    bottom: 1.5rem;
    translate: -50% 0;
    width: min(76vw, 720px);
    max-height: 54vh;
    max-height: 54svh;
    object-fit: contain;
    opacity: 0.2;
    filter: saturate(0.85) drop-shadow(0 0 3rem color-mix(in oklch, var(--accent-2) 35%, transparent));
    mask-image: linear-gradient(to bottom, transparent 0%, #000 24%, #000 68%, transparent 100%);
    pointer-events: none;
  }

  body.game-page-active .site-header,
  body.game-page-active .scroll-progress {
    display: none;
  }

  body.game-page-active main > section:not(#gameScreen) {
    display: none;
  }

  body.game-page-active {
    background:
      radial-gradient(55rem 34rem at 80% 0%, color-mix(in oklch, var(--accent-2) 17%, transparent), transparent 65%),
      radial-gradient(45rem 32rem at 0% 80%, color-mix(in oklch, var(--accent) 12%, transparent), transparent 60%),
      color-mix(in oklch, var(--bg-deep) 96%, black);
  }

  .stage-select-page[hidden] {
    display: none !important;
  }

  .stage-select-page {
    min-height: 0;
    padding: 0;
    animation: stage-page-enter 0.32s ease both;
  }

  .stage-select-inner {
    width: min(100%, 760px);
    margin-inline: auto;
  }

  .stage-select-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2.4rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
  }

  .stage-select-toolbar[hidden] {
    display: none;
  }

  .stage-select-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-dim);
    font-size: 0.82rem;
  }

  .stage-select-breadcrumb b {
    color: var(--line);
  }

  .stage-select-breadcrumb strong {
    color: var(--accent);
  }

  @keyframes stage-page-enter {
    from { opacity: 0; translate: 0 1.2rem; }
    to { opacity: 1; translate: 0 0; }
  }

  .game-page[hidden] { display: none !important; }

  .game-page {
    min-height: 100vh;
    min-height: 100svh;
    animation: game-screen-enter 0.24s ease-out both;
  }

  @keyframes game-screen-enter {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .game-title-screen {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 1rem;
    text-align: center;
  }

  .game-eyebrow {
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.28em;
    text-transform: uppercase;
  }

  .game-logo {
    font-size: clamp(3rem, 11vw, 6.8rem);
    line-height: 0.9;
    letter-spacing: 0.08em;
    background: linear-gradient(100deg, var(--accent), var(--accent-2), var(--accent-warm));
    background-clip: text;
    color: transparent;
  }

  .game-logo span {
    display: block;
    margin-top: 0.55rem;
    font-size: 0.24em;
    letter-spacing: 0.52em;
    color: var(--text);
  }

  .game-title-art {
    width: min(70vw, 460px, 36vh);
    width: min(70vw, 460px, 36svh);
    max-height: none;
    object-fit: contain;
    filter: drop-shadow(0 1.5rem 2.5rem oklch(0 0 0 / 0.45));
  }

  .game-copy { color: var(--text-dim); }

  .game-title-actions,
  .game-menu-links,
  #controls,
  #resultBtns,
  #confirmBox .btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
  }

  .game-play-screen {
    width: min(100%, 960px);
    margin-inline: auto;
  }

  .game-head {
    margin-bottom: 2rem;
    text-align: center;
  }

  .game-head h2 {
    margin-top: 0.35rem;
    font-size: clamp(2rem, 7vw, 3.3rem);
  }

  #stageSelectTitle {
    margin-top: 0;
    color: var(--gold-text);
    font-size: clamp(2rem, 5vw, 2.8rem);
    letter-spacing: 0.08em;
    text-shadow: 0 0 1.3rem color-mix(in oklch, var(--accent-warm) 35%, transparent);
  }

  .stage-select-page .game-head {
    margin-bottom: 0.4rem;
  }

  .game-head > p:last-child:not(.game-eyebrow) {
    margin-top: 0.6rem;
    color: var(--text-dim);
  }

  .game-panel-list { display: grid; gap: 0.9rem; max-width: 720px; margin-inline: auto; }

  .game-panel {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1.1rem;
    align-items: start;
    padding: 1.3rem 1.4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 65%, transparent);
  }

  .game-panel > b {
    color: var(--accent);
    font-size: 1.5rem;
  }

  .game-panel h3 { margin-bottom: 0.25rem; }
  .game-panel p { color: var(--text-dim); font-size: 0.92rem; }
  .game-back { display: flex; margin: 1.5rem auto 0; }

  .game-character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.9rem;
  }

  .game-character-grid article {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 65%, transparent);
    text-align: center;
  }

  .game-character-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    margin-bottom: 0.6rem;
    filter: drop-shadow(0 0.7rem 1rem oklch(0 0 0 / 0.35));
  }

  .game-character-grid h3 { font-size: 1rem; }
  .game-character-grid p { color: var(--accent); font-size: 0.8rem; }

  .game-menu-links { margin-bottom: 1rem; }

  #totalStars {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.6rem;
    margin: 0.5rem auto 1.2rem;
    color: var(--text-dim);
    font-size: 0.8rem;
    letter-spacing: 0.12em;
  }

  #totalStars b { color: var(--gold-text); font-size: 1.6rem; }

  #demoRow {
    max-width: 720px;
    margin: 1rem auto;
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: color-mix(in oklch, var(--surface) 55%, transparent);
  }

  #demoRow[hidden] { display: none; }
  #demoRow > span { display: grid; gap: 0.18rem; }
  #demoRow small { color: var(--text-dim); font-size: 0.72rem; }

  #demoToggle {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.48rem 0.55rem 0.48rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-dim);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s, background 0.2s;
  }

  #demoToggle .demo-state {
    min-width: 2.7rem;
    padding: 0.25rem 0.48rem;
    border-radius: 999px;
    background: color-mix(in oklch, var(--text-dim) 16%, transparent);
    color: var(--text-dim);
    text-align: center;
  }

  #demoToggle.is-on {
    border-color: var(--accent);
    background: color-mix(in oklch, var(--accent) 10%, var(--surface-2));
    color: var(--text);
    box-shadow: 0 0 1rem color-mix(in oklch, var(--accent) 24%, transparent);
  }

  #demoToggle.is-on .demo-state { background: var(--accent); color: var(--bg-deep); }
  #demoToggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  #catTabs {
    display: flex;
    gap: 0.55rem;
    max-width: 100%;
    margin: -0.9rem auto 0.5rem;
    overflow-x: auto;
    padding: 1.1rem;
    scrollbar-width: thin;
  }

  .cat-tab {
    flex: 0 0 auto;
    padding: 0.62rem 1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: color-mix(in oklch, var(--surface) 62%, transparent);
    color: var(--text-dim);
    cursor: pointer;
  }

  .cat-tab.active {
    border-color: var(--accent);
    background: color-mix(in oklch, var(--accent) 10%, var(--surface-2));
    color: var(--text);
    box-shadow: 0 0 1rem color-mix(in oklch, var(--accent) 24%, transparent);
  }

  .cat-tab .n { margin-left: 0.5rem; color: var(--accent); font-size: 0.72rem; }
  #stageRows { display: grid; gap: 0.8rem; }

  .stage-card {
    display: grid;
    grid-template-columns: 2.2rem 3.2rem minmax(0, 1fr) auto;
    gap: 0.8rem;
    align-items: center;
    padding: 1rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 65%, transparent);
    cursor: pointer;
    transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
  }

  .stage-card:not(.locked):hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    background: color-mix(in oklch, var(--accent) 10%, var(--surface-2));
    box-shadow: 0 0 1rem color-mix(in oklch, var(--accent) 24%, transparent);
  }

  .stage-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
  }

  .stage-card.locked { opacity: 0.55; cursor: not-allowed; }
  .stage-card .sc-no { color: var(--text-dim); font-variant-numeric: tabular-nums; }
  .stage-card .icon { font-size: 1.8rem; text-align: center; }
  .stage-card .name { font-weight: 700; }
  .stage-card .meta { display: flex; gap: 0.35rem; margin: 0.3rem 0; }
  .stage-card .chip { padding: 0.08rem 0.45rem; border: 1px solid var(--line); border-radius: 999px; color: var(--accent); font-size: 0.68rem; }
  .stage-card .chip.demo { margin-left: 0.4rem; color: var(--gold-text); }
  .stage-card .desc,
  .stage-card .rec,
  .stage-card .lockmsg { color: var(--text-dim); font-size: 0.78rem; }
  .stage-card .rec { color: var(--accent); }
  .stage-card .right { min-width: 3.8rem; text-align: right; }
  .stars .on { color: var(--gold-text); text-shadow: 0 0 0.7rem color-mix(in oklch, var(--accent-warm) 50%, transparent); }
  .stars .off { color: var(--line); }

  .game-play-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    position: relative;
    z-index: 1;
  }

  #topbar {
    width: min(100%, 700px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
  }

  #backBtn { grid-column: 1; justify-self: start; }
  #stageName { grid-column: 2; min-width: 0; text-align: center; font-weight: 700; }
  #pauseBtn {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    display: grid;
    place-items: center;
    width: 4rem;
    height: 4rem;
    padding: 0;
    border-radius: 50%;
  }

  .pause-bars {
    width: 12px;
    height: 18px;
    border-inline: 3px solid currentColor;
    border-radius: 0;
    box-sizing: border-box;
  }

  #altar {
    width: min(100%, 560px);
    display: grid;
    gap: 0.35rem;
  }

  .god-slot {
    position: relative;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    overflow: visible;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 30%, color-mix(in oklch, var(--surface-2) 72%, transparent), color-mix(in oklch, var(--bg-deep) 82%, transparent));
  }

  .god-slot .q { color: var(--text-dim); font-size: clamp(0.85rem, 2.2vw, 1.35rem); }
  .god-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; opacity: 0; transform: scale(0.8); transition: opacity 0.35s, transform 0.35s; }
  .god-slot.got img { opacity: 1; transform: scale(1); }
  .god-slot.got .q { opacity: 0; }
  .god-slot .gname { position: absolute; left: 50%; bottom: -0.34rem; z-index: 2; display: none; min-width: 2.6rem; padding: 0.12rem 0.48rem; transform: translateX(-50%); border: 1px solid color-mix(in oklch, var(--gold-text) 72%, transparent); border-radius: 999px; background: oklch(0.08 0.025 275 / 0.94); color: var(--gold-text); font-size: clamp(0.4rem, 0.9vw, 0.54rem); font-weight: 800; line-height: 1; text-align: center; white-space: nowrap; box-shadow: 0 0 0.55rem color-mix(in oklch, var(--gold-text) 24%, transparent); }
  .god-slot.got .gname { display: block; }
  .god-slot .cnt { position: absolute; top: 0.15rem; right: 0.2rem; z-index: 1; opacity: 0; color: var(--gold-text); font-size: 0.7rem; font-weight: 700; }
  .god-slot.multi .cnt { opacity: 1; }
  .god-slot.got { border-color: var(--gold-text); box-shadow: 0 0 0.8rem color-mix(in oklch, var(--gold-text) 42%, transparent), inset 0 0 1rem color-mix(in oklch, var(--accent-warm) 12%, transparent); }

  #status {
    position: relative;
    width: min(100%, 560px);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
    gap: clamp(0.75rem, 4vw, 3.5rem);
    min-height: 2.8rem;
    overflow: hidden;
    padding: 0.15rem 0.35rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-size: clamp(0.9rem, 1.4vw, 1.05rem);
    letter-spacing: 0.04em;
  }

  #status.has-timer {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(0.35rem, 1.5vw, 1rem);
  }

  #status > span {
    width: min(100%, 8rem);
    padding: 0.35rem 0.45rem 0.48rem;
    text-align: center;
    white-space: nowrap;
  }

  #status > span:first-child { justify-self: start; }
  #status > span:not(:first-child) { justify-self: center; }
  #status:not(.has-timer) > span:nth-of-type(3),
  #status.has-timer > span:nth-of-type(4) { justify-self: end; }
  #status b { color: var(--gold-text); font-size: 1.25em; font-weight: 850; }
  #timerBox { font-variant-numeric: tabular-nums; }

  #autoBar {
    width: min(100%, 560px);
    height: 4px;
    overflow: hidden;
    border-radius: 99px;
    background: var(--surface-2);
  }

  #autoBarFill {
    width: 100%;
    height: 100%;
    transform: scaleX(0);
    transform-origin: left center;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    will-change: transform;
  }
  #autoBar.danger #autoBarFill { background: linear-gradient(90deg, var(--accent-warm), oklch(0.68 0.22 25)); }

  #boardWrap {
    width: min(100%, 560px);
    display: grid;
    place-items: center;
    padding: clamp(0.4rem, 1.3vw, 0.7rem);
    border: 1px solid color-mix(in oklch, var(--accent) 35%, var(--line));
    border-radius: var(--radius);
    background: color-mix(in oklch, var(--surface) 66%, transparent);
    box-shadow: 0 1.5rem 4rem oklch(0 0 0 / 0.35), inset 0 0 2rem color-mix(in oklch, var(--accent) 5%, transparent);
    backdrop-filter: blur(8px);
  }

  #board {
    --cols: 5;
    --rows: 5;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
    gap: clamp(3px, 1vw, 7px);
    aspect-ratio: var(--cols) / var(--rows);
    touch-action: none;
  }

  .cell {
    position: relative;
    aspect-ratio: 1 / 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid color-mix(in oklch, var(--line) 85%, transparent);
    border-radius: clamp(6px, 1.4vw, 12px);
    background: color-mix(in oklch, var(--bg-deep) 68%, transparent);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  }

  .cell.drop-merge {
    border-color: var(--accent-warm);
    box-shadow: inset 0 0 1rem color-mix(in oklch, var(--accent-warm) 25%, transparent), 0 0 0.8rem color-mix(in oklch, var(--accent-warm) 30%, transparent);
  }

  .piece {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: inherit;
    cursor: grab;
    user-select: none;
  }

  .piece:active { cursor: grabbing; }
  .piece.dragging { opacity: 0.2; }
  .piece img { width: 100%; height: 100%; aspect-ratio: 1 / 1; object-fit: cover; pointer-events: none; filter: drop-shadow(0 0.35rem 0.4rem oklch(0 0 0 / 0.35)); }
  .piece .lv {
    position: absolute;
    top: 2px;
    left: 2px;
    display: inline-flex;
    align-items: baseline;
    gap: 1px;
    padding: 1.5px 6px;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: oklch(0.1 0.035 275 / 0.88);
    color: var(--accent);
    box-shadow: 0 0 7px color-mix(in oklch, currentColor 42%, transparent);
    font-family: var(--font-display);
    font-size: 8.5px;
    font-style: italic;
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1.15;
    white-space: nowrap;
    text-shadow: 0 1px 2px oklch(0 0 0 / 0.9);
    pointer-events: none;
  }

  .piece .lv-mark {
    font-size: 0.82em;
    font-weight: 700;
    opacity: 0.82;
  }

  .piece .lv strong {
    color: oklch(0.98 0.02 95);
    font-size: 1.25em;
    font-weight: 950;
    line-height: 0.9;
  }

  .piece.lv1 .lv {
    color: var(--accent);
    background: linear-gradient(160deg, oklch(0.3 0.12 205 / 0.94), oklch(0.14 0.08 220 / 0.94));
  }
  .piece.lv2 .lv {
    color: var(--gold-text);
    background: linear-gradient(160deg, oklch(0.38 0.1 80 / 0.94), oklch(0.17 0.065 68 / 0.94));
  }
  .piece.lv3 .lv {
    color: oklch(0.78 0.18 315);
    background: linear-gradient(160deg, oklch(0.32 0.16 310 / 0.94), oklch(0.2 0.12 300 / 0.94));
    box-shadow: 0 0 9px color-mix(in oklch, currentColor 55%, transparent);
  }
  .piece.lv3 { background: radial-gradient(circle, color-mix(in oklch, var(--accent-2) 22%, transparent), transparent 68%); }
  .piece.merged { animation: merge-pop 0.45s cubic-bezier(0.2, 1.3, 0.4, 1); }
  @keyframes merge-pop { 45% { transform: scale(1.2); filter: brightness(1.4); } }

  #controls { width: min(100%, 700px); }
  #controls[hidden] { display: none; }
  #summonBtn { display: grid; justify-items: center; min-width: min(100%, 240px); }
  #summonBtn[hidden] { display: none; }
  #summonBtn .small { display: block; font-size: 0.65rem; font-weight: 500; opacity: 0.72; }
  #summonBtn:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; transform: none; }
  #summonBtn.shake { animation: shake 0.35s linear; }
  @keyframes shake { 25%, 75% { translate: -5px 0; } 50% { translate: 5px 0; } }

  #hint {
    width: min(100%, 700px);
    color: var(--text-dim);
    font-size: 0.72rem;
    line-height: 1.55;
    text-align: center;
  }

  #ghost {
    display: none;
    position: fixed;
    z-index: 70;
    translate: -50% -50%;
    overflow: hidden;
    border-radius: clamp(6px, 1.4vw, 12px);
    pointer-events: none;
    opacity: 0.82;
  }

  #ghost img { display: block; width: 100%; height: 100%; object-fit: cover; filter: drop-shadow(0 0 1rem var(--accent)); }

  #toast {
    position: absolute;
    z-index: 1;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    border-radius: inherit;
    background: color-mix(in oklch, var(--surface-2) 88%, var(--accent));
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(35%);
    transition: opacity 0.2s, transform 0.2s;
  }

  #toast.show { opacity: 1; transform: translateY(0); }
  #toast .t1 { font-weight: 700; }
  #toast .t2 { color: var(--accent); font-size: 0.76rem; font-weight: 700; }

  #pauseOverlay,
  #confirmOverlay,
  #result {
    display: none;
    position: fixed;
    z-index: 90;
    inset: 0;
    place-items: center;
    padding: 1rem;
    background: oklch(0.06 0.02 275 / 0.8);
    backdrop-filter: blur(8px);
  }

  #pauseOverlay.show,
  #confirmOverlay.show,
  #result.show { display: grid; }

  #confirmBox,
  .pause-card,
  .result-card {
    width: min(92vw, 560px);
    padding: 1.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(color-mix(in oklch, var(--surface) 96%, var(--accent-2)), var(--surface));
    text-align: center;
    box-shadow: 0 2rem 6rem oklch(0 0 0 / 0.55);
  }

  #pauseOverlay { z-index: 85; }

  .pause-card {
    max-height: calc(100svh - 2rem);
    overflow-y: auto;
  }

  .pause-card h2 {
    margin-top: 0;
    color: var(--text);
    font-size: clamp(2rem, 8vw, 3.4rem);
    letter-spacing: 0.08em;
  }

  .pause-actions {
    display: grid;
    gap: 0.65rem;
    margin-top: 1.35rem;
  }

  .pause-action {
    width: 100%;
    min-height: 3.4rem;
    justify-content: center;
    letter-spacing: 0.05em;
  }

  #pauseSound {
    justify-content: center;
    min-height: 2.7rem;
    margin-top: 0.85rem;
    padding: 0.55rem 1rem;
  }

  .pause-sound-icon { font-size: 1rem; }

  #confirmBox .msg { margin-bottom: 1.2rem; white-space: pre-line; }
  #resultTitle { font-size: clamp(1.7rem, 6vw, 2.8rem); font-weight: 800; }
  #resultStars { margin: 0.5rem 0; font-size: 2rem; letter-spacing: 0.14em; }
  #resultImgWrap { min-height: 2rem; }
  #resultImgWrap .syugou { width: min(100%, 420px, 34vh); width: min(100%, 420px, 34svh); max-height: none; margin: 0 auto; object-fit: contain; }
  #resultImgWrap .god-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.55rem;
    min-height: 7rem;
  }
  #resultImgWrap .god-row img {
    width: min(18%, 86px);
    aspect-ratio: 1;
    object-fit: cover;
    border: 2px solid color-mix(in oklch, var(--gold-text) 78%, var(--line));
    border-radius: 50%;
    background: var(--bg-deep);
    box-shadow:
      0 0 0.85rem color-mix(in oklch, var(--gold-text) 28%, transparent),
      inset 0 0 0.6rem color-mix(in oklch, var(--gold-text) 12%, transparent);
    animation: result-rise 0.45s both;
  }
  @keyframes result-rise { from { opacity: 0; translate: 0 1rem; } }
  #resultStats { margin: 0.8rem 0 1.2rem; color: var(--text-dim); font-size: 0.88rem; }
  #resultStats b,
  #resultStats .newrec { color: var(--accent); }
  #result.fail #resultTitle { color: oklch(0.74 0.18 25); }

  .spark {
    position: fixed;
    z-index: 75;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    pointer-events: none;
    animation: spark-out 0.65s ease-out both;
  }

  @keyframes spark-out { to { translate: var(--dx) var(--dy); scale: 0; opacity: 0; } }

  .confetti {
    position: fixed;
    z-index: 95;
    top: -1rem;
    width: 7px;
    height: 12px;
    pointer-events: none;
    animation: confetti-fall linear both;
  }

  @keyframes confetti-fall { to { translate: 0 110vh; rotate: 720deg; } }

  .fly {
    position: fixed;
    z-index: 78;
    pointer-events: none;
    transition: left 0.9s cubic-bezier(0.2, 0.8, 0.3, 1), top 0.9s cubic-bezier(0.2, 0.8, 0.3, 1), width 0.9s, height 0.9s;
  }

  .fly img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 0 1rem var(--accent-warm)); }

  @media (max-width: 620px) {
    .hero-otomo { width: 105vw; opacity: 0.15; }
    .hero-game-title {
      min-height: min(100svh, 720px);
      gap: 0.75rem;
      padding-block: 5.5rem 3rem;
    }
    #destinations { padding-top: 1rem; }
    #catTabs {
      flex-wrap: wrap;
      justify-content: center;
      overflow-x: visible;
      padding: 0.75rem 0.1rem;
    }
    .cat-tab {
      min-width: 0;
      flex: 0 1 calc(50% - 0.275rem);
      padding: 0.62rem 0.45rem;
      white-space: nowrap;
      font-size: 0.9rem;
      text-align: center;
    }
    .hero-game-title .game-logo { font-size: clamp(2.2rem, 11vw, 3.4rem); }
    .hero-game-title .hero-game-art { width: min(76vw, 300px, 34vh); width: min(76vw, 300px, 34svh); max-height: none; }
    .stage-card { grid-template-columns: 1.8rem 2.4rem minmax(0, 1fr); padding: 0.8rem; }
    .stage-card .right { grid-column: 3; text-align: left; }
    .stage-card .desc { line-height: 1.5; }
    #demoRow { align-items: stretch; flex-direction: column; }
    #demoToggle { justify-content: space-between; }
    #topbar { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
    #topbar #backBtn { grid-column: 1; grid-row: 1; }
    #topbar #stageName { grid-column: 2; grid-row: 1; }
    #topbar #pauseBtn { grid-column: 3; grid-row: 1; }
    #pauseBtn { width: 3.2rem; height: 3.2rem; }
    .pause-bars { height: 16px; }
    .stage-select-toolbar { align-items: flex-start; flex-direction: column; }
    .stage-select-breadcrumb { order: -1; }
    #backBtn { padding: 0.5em 0.7em; font-size: 0.7rem; }
    #stageName { font-size: 0.86rem; }
    .god-slot .gname { display: none; }
    #status { gap: 0.35rem; border-radius: var(--radius-sm); font-size: 0.8rem; }
    #status > span { padding-inline: 0.12rem; }
    #boardWrap { padding: 0.4rem; }
    #hint { display: none; }
  }

  @media (max-width: 340px) {
    .cat-tab {
      flex-basis: 100%;
    }
  }

  @media (max-width: 620px) and (max-height: 720px) {
    .game-play-screen { gap: 0.45rem; padding-top: max(0.6rem, env(safe-area-inset-top)); }
    #altar { max-height: 76px; }
    .god-slot { height: auto; aspect-ratio: 1; }
    #hint { display: none; }
  }
}
