/* ==========================================================================
   0) Design tokens & global resets
   ========================================================================== */

@layer tokens {
  /* --- base tokens (light defaults) --- */
  :root {
    color-scheme: light;

    --bg: #f6f7fb;
    --text: #0b1020;
    --card-text: #0b1020;
    --muted: #6b7280;
    --muted-fg: #6b7280;
    --toast-bg: rgba(15, 23, 42, 0.96);
    --toast-text: #f8fafc;
    --card: #fff;
    --card-subtle: #f8fafc;
    --border: #e5e7eb;
    --dot-border: #e2e8f0;
    --accent: #111827;
    --accent-bg: #e7eaf1;
    --accent-bg-hover: #dfe3ec;
    --ok: #10b981;
    --no: #ef4444;
    --panel: #ffffff;
    --panel-border: #d2d6db;
    --brand: #1e40af;
    --brand-hover: #1b3a9a;
    --overlay-scrim: rgba(17, 24, 39, 0.55);
    --confirm-gradient-start: #10b981;
    --confirm-gradient-end: #059669;
    --confirm-text: #fff;
    --selected: #f0f2f6;
    --answer-bg: #fafafa;
    --answer-hover-bg: #f3f4f6;
    --answer-bg: #fafafa;
    --answer-hover-bg: #f3f4f6;
    --muted-fg: #6b7280;
    --toast-text: #f8fafc;

    --icon-btn-bg: #e7eaf1;
    --icon-btn-hover-bg: #dfe3ec;
    --icon-btn-border: #cfd3db;
    --icon-btn-icon: #0b1020;

    --radius-lg: 10px;
    --shadow-md: 0 8px 24px rgba(2, 6, 23, 0.08);
    --shadow-sm: 0 2px 10px rgba(2, 6, 23, 0.06);
    --container: 720px;
    --card-width: 560px;

    --focus: 2px solid #1e40af;
    --font-ui:
      ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
      "Helvetica Neue", Arial, sans-serif;
    --flip-dur: 600ms;
    --fade-dur: 260ms;
    --pulse-dur: 2.5s;

    --rule: #e6e8ee;
    --gutter: clamp(6px, 2.2vw, 12px);

    /* stats */
    --stat-low: #a16207;
    --stat-mid: #0284c7;
    --stat-high: #047857;
    --stat-pending: #6366f1;

    /* fireworks */
    --spark-a: #d97706;
    --spark-b: #2563eb;
    --spark-c: #059669;
    --spark-d: #db2777;
  }

  /* --- OS-driven dark defaults (only when no user override) --- */
  @media (prefers-color-scheme: dark) {
    :root {
      color-scheme: dark;
      --bg: #0b0d12;
      --text: #e8eaf1;
      --card-text: #e8eaf1;
      --answer-text: #e8eaf1;
      --muted: #97a0b3;
      --card: #12151d;
      --card-subtle: #27324a;
      --border: #202434;
      --dot-border: rgba(255, 255, 255, 0.08);
      --accent: #0b0d12;
      --accent-bg: #e8eaf1;
      --accent-bg-hover: #dfe3ec;
      --shadow-md: 0 10px 40px rgba(0, 0, 0, 0.35);
      --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.25);
      --panel: #111827;
      --panel-border: #374151;
      --brand: #93c5fd;
      --brand-hover: #bfdbfe;
      --overlay-scrim: rgba(0, 0, 0, 0.6);
      --focus: 2px solid #93c5fd;
      --confirm-gradient-start: #059669;
      --confirm-gradient-end: #065f46;
      --confirm-text: #e8fdf3;
      --on-dark: #fff;
      --on-dark-muted-green: #cff7df;
      --on-dark-muted-red: #ffd7d7;
      --selected: #94a3b8;
      --answer-bg: #1f2433;
      --answer-hover-bg: #2a3144;
      --icon-btn-bg: #1e293b;
      --icon-btn-hover-bg: #2c3649;
      --icon-btn-border: #374151;
      --icon-btn-icon: #f9fafb;
      --stat-low: #fbbf24;
      --stat-mid: #38bdf8;
      --stat-high: #10b981;
      --stat-pending: #818cf8;
      --muted-fg: #a4abba;
      --answer-text: #e8eaf1;
      --toast-bg: #1c1e23d9;
      --toast-text: #f5f7ff;

      /* fireworks */
      --spark-a: #fbbf24;
      --spark-b: #93c5fd;
      --spark-c: #6ee7b7;
      --spark-d: #f9a8d4;
    }
  }

  /* --- USER OVERRIDES --- */
  :root[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f7fb;
    --text: #0b1020;
    --card-text: #0b1020;
    --answer-text: #0b1020;
    --toast-bg: rgba(15, 23, 42, 0.96);
    --muted: #6b7280;
    --card: #fff;
    --card-subtle: #f8fafc;
    --border: #e5e7eb;
    --dot-border: #e2e8f0;
    --accent: #111827;
    --accent-bg: #e7eaf1;
    --accent-bg-hover: #dfe3ec;
    --ok: #10b981;
    --no: #ef4444;
    --shadow-md: 0 8px 24px rgba(2, 6, 23, 0.08);
    --shadow-sm: 0 2px 10px rgba(2, 6, 23, 0.06);
    --panel: #ffffff;
    --panel-border: #d2d6db;
    --brand: #1e40af;
    --brand-hover: #1b3a9a;
    --overlay-scrim: rgba(17, 24, 39, 0.55);
    --focus: 2px solid #1e40af;
    --confirm-gradient-start: #10b981;
    --confirm-gradient-end: #059669;
    --confirm-text: #fff;
    --selected: #f0f2f6;
    --answer-bg: #fafafa;
    --answer-hover-bg: #f3f4f6;
    --muted-fg: #6b7280;
    --icon-btn-bg: #e7eaf1;
    --icon-btn-hover-bg: #dfe3ec;
    --icon-btn-border: #cfd3db;
    --icon-btn-icon: #0b1020;
    --stat-low: #a16207;
    --stat-mid: #0284c7;
    --stat-high: #047857;
    --stat-pending: #6366f1;

    /* fireworks */
    --spark-a: #d97706;
    --spark-b: #2563eb;
    --spark-c: #059669;
    --spark-d: #db2777;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b0d12;
    --text: #e8eaf1;
    --card-text: #e8eaf1;
    --answer-text: #e8eaf1;
    --muted: #97a0b3;
    --toast-bg: #1c1e23d9;
    --card: #12151d;
    --card-subtle: #27324a;
    --border: #202434;
    --dot-border: rgba(255, 255, 255, 0.08);
    --accent: #0b0d12;
    --accent-bg: #e8eaf1;
    --accent-bg-hover: #dfe3ec;
    --shadow-md: 0 10px 40px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.25);
    --panel: #111827;
    --panel-border: #374151;
    --brand: #93c5fd;
    --brand-hover: #bfdbfe;
    --overlay-scrim: rgba(0, 0, 0, 0.6);
    --focus: 2px solid #93c5fd;
    --confirm-gradient-start: #059669;
    --confirm-gradient-end: #065f46;
    --confirm-text: #e8fdf3;
    --on-dark: #fff;
    --on-dark-muted-green: #cff7df;
    --on-dark-muted-red: #ffd7d7;
    --selected: #334155;
    --answer-bg: #1f2433;
    --answer-hover-bg: #2a3144;
    --icon-btn-bg: #1e293b;
    --icon-btn-hover-bg: #2c3649;
    --icon-btn-border: #374151;
    --icon-btn-icon: #f9fafb;
    --stat-low: #fbbf24;
    --stat-mid: #38bdf8;
    --stat-high: #10b981;
    --stat-pending: #818cf8;
    --muted-fg: #a4abba;
    --toast-text: #f5f7ff;

    /* fireworks */
    --spark-a: #fbbf24;
    --spark-b: #93c5fd;
    --spark-c: #6ee7b7;
    --spark-d: #f9a8d4;
    --correct-dark-bg: #204a24;
    --wrong-dark-bg: #4a1c1c;
  }
}

@layer base {
  /* --- Global reset --- */
  * {
    box-sizing: border-box;
  }

  html,
  body {
    height: 100%;
    scroll-behavior: smooth;
  }

  body {
    margin: 0;
    font: 16px/1.5 var(--font-ui);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .hidden {
    display: none !important;
  }
}

@layer layout {
  /* ==========================================================================
   1) Shell & layout
   ========================================================================== */

  .shell {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  main {
    display: grid;
    place-items: start center;
    padding: 24px;
  }

  .container {
    width: min(100%, var(--container));
    display: grid;
    place-items: center;
  }

  .game-board {
    width: min(100%, var(--card-width));
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 20px 20px 16px;
  }

  /* ==========================================================================
   2) Header & navigation
   ========================================================================== */

  header.site {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 64px;
    border-bottom: 1px solid var(--border);
    padding-inline: 16px;
    gap: 12px;
  }

  header.site::before {
    content: "";
  }

  header .brand {
    font-weight: 700;
    letter-spacing: 0.2px;
    font-size: 40px;
    color: var(--text);
    text-decoration: none;
  }

  header.site .brand {
    grid-column: 2;
    justify-self: center;
  }

  header .brand:focus-visible {
    outline: var(--focus);
    outline-offset: 4px;
  }

  header.site .nav-button-container {
    grid-column: 3;
    justify-self: end;
    display: inline-flex;
    gap: 8px;
  }

  header .brand small {
    color: var(--muted);
    font-weight: 500;
    margin-left: 0.5ch;
  }

  .nav-icon {
    padding: 0;
    border: 1px solid var(--icon-btn-border);
    line-height: 0;
    vertical-align: middle;
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    background: var(--icon-btn-bg);
    border-radius: 8px;
    cursor: pointer;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease;
  }

  .nav-icon svg {
    width: 20px;
    height: 20px;
    stroke: var(--icon-btn-icon);
    stroke-width: 2;
  }

  .nav-icon:hover {
    background: var(--icon-btn-hover-bg);
  }

  .nav-icon:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
  }

  /* ==========================================================================
   3) Rows, rails, and question/answer grid
   ========================================================================== */

  .toprow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  /* structure */
  .questions-container {
    position: relative;
    padding-left: var(--gutter);
    box-sizing: border-box;
  }

  /* vertical rail */
  .questions-container::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 1px;
    background: var(--rule, var(--border));
    opacity: 0;
    transition: opacity 300ms ease;
  }

  .row {
    position: relative;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    gap: clamp(1px, 3vw, 20px);
    padding: 10px 0;
    --row-delay: 0ms;
  }

  .row::after {
    --gutter: 6px;
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--rule, var(--border));
    height: 1px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
  }

  .row:last-child::after {
    display: none;
  }

  .row > * {
    opacity: 0;
    transition: opacity var(--fade-dur) ease;
  }

  .trivia-container {
    flex: 0 1 160px;
    min-width: 140px;
    max-width: 200px;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-left: 0;
    padding-right: 5px;
  }

  .category-container {
    display: flex;
    flex-direction: column;
    font-size: 0.65rem;
  }
  .category {
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
    opacity: 0.8;
  }
  .stats-container {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    letter-spacing: 0em;
    padding-top: 4px;
    line-height: 1.1;
    opacity: 0;
    will-change: opacity;
    margin: 2px 0;
  }

  .stat-low {
    color: var(--stat-low);
  }

  .stat-mid {
    color: var(--stat-mid);
  }

  .stat-high {
    color: var(--stat-high);
  }

  .stat-pending {
    color: var(--stat-pending);
  }

  .stats-icon {
    box-sizing: border-box;
    inline-size: 18px;
    aspect-ratio: 1 / 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease;
    line-height: 0;
    flex: 0 0 auto;
    border: 1px solid color-mix(in oklab, currentColor 60%, transparent);
    background: color-mix(in oklab, currentColor 10%, transparent);
    border-radius: 3px;
  }

  .stats-icon svg {
    width: 14px;
    height: 14px;
    stroke-width: 2;
  }

  .stats-text {
    line-height: 1.1;
    display: flex;
    align-items: center;
    block-size: 30px;
  }

  .question-text {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.35;
    color: inherit;
    overflow-wrap: anywhere;
    opacity: 0;
    transition: opacity 3000ms ease;
  }

  .row.is-active .question-text {
    opacity: 1;
    pointer-events: auto;
  }

  .options-container {
    flex: 1 1 320px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    justify-items: center;
    gap: 12px;
    width: 100%;
    max-width: 320px;
    padding: 0 5px;
    perspective: 900px;
  }
}

@layer components {
  /* ==========================================================================
   4) Answer tiles (flip states, selection, results)
   ========================================================================== */

  .answer {
    position: relative;
    overflow: visible;
    height: 90px;
    width: 90px; /* desktop cap; mobile overrides below */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 12px 14px;
    background: var(--answer-bg);
    color: var(--answer-text, var(--card-text));
    border: 1px solid var(--border);
    cursor: default;
    user-select: none;
    text-align: center;
    word-break: break-word;

    /* 3D flip essentials */
    transform-style: preserve-3d;
    transform: rotateY(0deg);
    transition:
      transform var(--flip-dur) cubic-bezier(0.2, 0.7, 0.2, 1) var(--delay, 0ms),
      background-color 0.12s ease,
      border-color 0.12s ease;
    pointer-events: none;
  }

  /* Faces share common geometry */
  .answer::before,
  .answer .label,
  .answer .result-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    border-radius: inherit;
  }

  /* FRONT (pre-reveal) */
  .answer::before {
    content: "";
    background: var(--answer-bg);
    transform: rotateY(0deg);
    z-index: 0;
  }

  /* BACK (first flip shows label) */
  .answer .label {
    transform: rotateY(180deg);
    opacity: 1;
    z-index: 1;
    font-weight: 600;
  }

  /* BACK (second flip shows results) */
  .answer .result-face {
    transform: rotateY(0deg);
    font-weight: 600;
    line-height: 1.2;
    z-index: 2;
  }

  /* State progression */
  .answer.is-revealed {
    transform: rotateY(180deg);
    pointer-events: auto;
  }

  .answer.is-result {
    transform: rotateY(360deg);
  }

  .answer.is-result::before {
    opacity: 0;
  }

  .answer.is-revealed:not(:disabled) {
    cursor: pointer;
  }

  .answer:disabled,
  .answer[aria-disabled="true"] {
    pointer-events: none;
    cursor: default;
  }

  /* Hover/focus (only when interactive) */
  .answer:not(:disabled):hover {
    background: var(--answer-hover-bg);
  }

  .answer:not(:disabled):focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
  }

  /* Selected (role-aware) */
  .answer[role="radio"][aria-checked="true"]:not(:disabled),
  .answer.is-selected:not(:disabled) {
    border-color: var(--text);
    box-shadow: inset 0 0 0 1px var(--text);
    background: var(--selected);
  }

  /* Improve label contrast on dark when selected */
  :root[data-theme="dark"]
    .answer:is(.is-selected, [aria-pressed="true"], [aria-checked="true"])
    .label {
    color: var(--on-dark);
  }

  /* Correct/Wrong borders */
  .answer.is-correct {
    border-color: var(--ok);
    border-width: 2px;
  }

  .answer.is-wrong {
    border-color: var(--no);
    border-width: 2px;
  }

  /* Results text */
  .result-face {
    user-select: none;
  }

  .result-face .result-label {
    font-weight: 600;
  }

  .result-face .subtext {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 2px;
  }

  .answer .subtext {
    white-space: pre-line;
    line-height: 1.15;
    color: var(--muted-fg, #6b7280);
    font-size: 0.9em;
  }

  :root[data-theme="dark"] .answer.is-correct {
    background-color: var(--correct-dark-bg, #204a24);
  }

  :root[data-theme="dark"] .answer.is-wrong {
    background-color: var(--wrong-dark-bg, #4a1c1c);
  }

  :root[data-theme="dark"] .is-correct .result-label {
    color: var(--on-dark);
  }

  :root[data-theme="dark"] .is-correct .subtext {
    color: var(--on-dark-muted-green);
  }

  :root[data-theme="dark"] .is-wrong .result-label {
    color: var(--on-dark);
  }

  :root[data-theme="dark"] .is-wrong .subtext {
    color: var(--on-dark-muted-red);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .answer.is-correct {
      background-color: var(--correct-dark-bg, #204a24);
    }

    :root:not([data-theme]) .answer.is-wrong {
      background-color: var(--wrong-dark-bg, #4a1c1c);
    }

    :root:not([data-theme]) .is-correct .result-label {
      color: var(--on-dark);
    }

    :root:not([data-theme]) .is-correct .subtext {
      color: var(--on-dark-muted-green);
    }

    :root:not([data-theme]) .is-wrong .result-label {
      color: var(--on-dark);
    }

    :root:not([data-theme]) .is-wrong .subtext {
      color: var(--on-dark-muted-red);
    }
  }

  /* Pulses */
  @keyframes pulse-correct {
    0% {
      box-shadow: 0 0 0 rgba(67, 210, 126, 0.6);
    }

    70% {
      box-shadow: 0 0 12px rgba(67, 210, 126, 0.8);
    }

    100% {
      box-shadow: 0 0 0 rgba(67, 210, 126, 0);
    }
  }
  @keyframes pulse-wrong {
    0% {
      box-shadow: 0 0 0 rgba(255, 92, 92, 0.55);
    }

    70% {
      box-shadow: 0 0 12px rgba(255, 92, 92, 0.8);
    }

    100% {
      box-shadow: 0 0 0 rgba(255, 92, 92, 0);
    }
  }

  .answer.pulse-correct {
    animation: pulse-correct var(--pulse-dur) ease;
  }

  .answer.pulse-wrong {
    animation: pulse-wrong var(--pulse-dur) ease;
  }

  /* ==========================================================================
   5) Intro stages (rails/rules & staggered content)
   ========================================================================== */

  /* 1) blank */
  #game.intro-blank .questions-container::before,
  #game.intro-blank .row::after,
  #game.intro-blank .row > * {
    opacity: 0;
  }

  /* 2) lines only */
  #game.intro-lines .questions-container::before,
  #game.intro-lines .row::after {
    opacity: 1;
  }

  #game.intro-lines .row > * {
    opacity: 0;
  }

  /* 3) content (staggered) */
  #game.intro-content .row > * {
    opacity: 1;
    transition-delay: var(--row-delay, 0ms);
  }

  /* ==========================================================================
   6) Overlays & buttons
   ========================================================================== */

  .overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: var(--overlay-scrim);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 1;
    transition:
      opacity 0.25s ease,
      visibility 0.25s ease;
  }

  .overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .overlay-card {
    width: min(92vw, 520px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow:
      0 18px 40px rgba(0, 0, 0, 0.18),
      0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 24px 24px 20px;
    color: var(--text);
  }

  .overlay-header {
    font: 700 20px/1.3 var(--font-ui);
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin: 0 0 4px;
  }

  .overlay-description {
    color: var(--muted);
    max-width: 65ch;
    font-size: 1rem;
    line-height: 1.6;
    margin: 0 0 24px;
  }

  .overlay-start {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--brand);
    color: var(--card);
    font-weight: 700;
    letter-spacing: 0.2px;
    box-shadow: 0 6px 16px rgba(30, 64, 175, 0.28);
    cursor: pointer;
    transition:
      transform 0.12s ease,
      background-color 0.12s ease,
      box-shadow 0.12s ease;
  }

  .info-card {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  #info-desc {
    margin-bottom: 0;
  }

  #info-widget {
    max-width: 90%;
  }

  .overlay-start:hover {
    transform: translateY(-1px);
    background: var(--brand-hover);
  }

  .overlay-start:active {
    transform: translateY(0);
  }

  .overlay-start:focus-visible {
    outline: var(--focus);
    outline-offset: 3px;
  }

  .btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--accent-bg);
    color: var(--accent);
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    transition:
      background-color 0.12s ease,
      transform 0.12s ease;
  }

  .btn:hover {
    background: var(--accent-bg-hover);
  }

  .btn:active {
    transform: translateY(1px);
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .confirm-sticky {
    position: fixed;
    padding-top: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    height: 65px;
    border: 0;
    background: linear-gradient(
      180deg,
      var(--confirm-gradient-start),
      var(--confirm-gradient-end)
    );
    color: var(--confirm-text);
    font: 600 16px/1.2 var(--font-ui);
    display: grid;
    place-items: center;
    z-index: 9999;
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.6);
    cursor: pointer;
    transform: translate(var(--tx, 0), var(--ty, 0));
  }

  .confirm-sticky[disabled],
  .confirm-sticky[aria-disabled="true"] {
    display: none;
  }

  .confirm-sticky:focus-visible {
    outline: var(--focus);
    outline-offset: 3px;
  }

  footer.site {
    border-top: 1px solid var(--border);
    color: var(--muted);
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
  }

  a:link,
  a:visited {
    color: var(--brand);
    text-decoration: underline;
  }

  /* ==========================================================================
   7) Game results & misc
   ========================================================================== */

  .game-results {
    margin-top: 24px;
    padding: 28px 24px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius-lg) + 2px);
    background: var(--panel);
    text-align: center;
    box-shadow: var(--shadow-sm);
    scroll-margin-top: 72px;
  }

  .streak-header-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
  }

  .streak-header-icon svg {
    width: 42px;
    height: 42px;
    stroke-width: 2.2;
    color: var(--spark-a);
  }

  .streak-list {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 4px 0 20px 0;
  }

  .streak-label {
    font-weight: 300;
    text-align: center;
  }

  .streak-icon {
    box-sizing: border-box;
    inline-size: 30px;
    aspect-ratio: 1 / 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease;
    line-height: 0;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    background: var(--card-subtle);
    border-radius: 3px;
  }

  .streak-icon.completed {
    background: var(--ok);
    border-color: var(--ok);
  }

  .streak-icon svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    display: none;
    color: var(--muted);
  }

  .streak-icon.completed svg,
  .streak-icon.completed i {
    display: block;
    color: var(--card);
  }

  .game-results p {
    font: 500 15px/1.6 var(--font-ui);
    color: var(--muted);
    margin: 0;
  }

  .game-results #midnight-countdown {
    font:
      600 15px/1.6 ui-monospace,
      SFMono-Regular,
      Menlo,
      monospace;
    color: var(--text);
    letter-spacing: 0.05em;
  }

  /* simple utility animation */
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ========= EMOJI GRID CARD ========= */
  .emoji-grid {
    --row-gap: 12px;
    display: grid;
    grid-auto-rows: min-content;
    row-gap: var(--row-gap);
    width: 100%;
    text-align: center;

    border-radius: calc(var(--radius-lg) - 2px);
    background: var(--card-subtle);
    padding: 18px 22px;
    border: 1px solid var(--border);
    box-shadow: none;
  }

  @media (prefers-color-scheme: dark) {
    .emoji-grid {
      border-color: rgba(255, 255, 255, 0.05);
    }
  }

  .emoji-grid.has-copy {
    position: relative;
    padding-right: 56px;
  }

  .share-button.in-card {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--icon-btn-border);
    background: var(--icon-btn-bg);
    display: grid;
    place-items: center;
    line-height: 0;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease,
      transform 0.06s ease;
  }
  .share-button.in-card svg {
    width: 18px;
    height: 18px;
    stroke: var(--icon-btn-icon);
    stroke-width: 2;
  }
  .share-button.in-card:hover {
    background: var(--icon-btn-hover-bg);
  }
  .share-button.in-card:active {
    transform: translateY(1px);
  }
  .share-button.in-card:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
  }

  .emoji-grid > .date {
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0 0 12px 0;
    color: color-mix(in srgb, var(--text) 85%, transparent);
  }

  /* ========= EMOJI ROWS + HEADER ========= */
  .emoji-table {
    display: grid;
    grid-auto-columns: auto;
    gap: 12px;
    width: max-content;
    justify-content: center;
    justify-items: center;

    margin: 0 auto;
    font-size: clamp(44px, 5vw, 56px);
    line-height: 1;
  }

  .emoji-table.has-friend {
    grid-template-columns: 2.6em 1.6em 1.6em;
  }

  .emoji-table.no-friend {
    grid-template-columns: 2.6em 1.6em;
  }

  .emoji-row,
  .emoji-header {
    display: flex;
    font-size: 56px;
    justify-content: center;
    gap: 20px;
  }

  .emoji-header span {
    font-size: 0.28em;
    font-weight: 700;
    width: 100%;
  }

  .left,
  .right {
    width: 100%;
    max-width: 100px;
  }

  .emoji-header span:nth-child(2),
  .emoji-header span:nth-child(3) {
    border-bottom: 2px solid var(--accent-bg);
    padding-bottom: 0.25em;
  }

  .emoji-row:nth-of-type(2) .left,
  .emoji-row:nth-of-type(4) .left {
    position: relative;
    top: -2px;
  }

  .reddit-link,
  .reddit-link:link,
  .reddit-link:visited,
  .reddit-link:hover,
  .reddit-link:active {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
    font: 500 15px/1.6 var(--font-ui);
    color: var(--muted);
    margin-top: 8px;
  }

  .reddit-icon {
    height: 20px;
    width: 20px;
  }

  /* ========= SHARE BUTTON COLUMN ========= */

  .share-button {
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--icon-btn-border);
    background: var(--icon-btn-bg);
    display: inline-grid;
    place-items: center;
    line-height: 0;
    cursor: pointer;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease,
      transform 0.06s ease;
  }

  .share-button:active {
    transform: translateY(1px);
  }

  .share-button svg {
    width: 18px;
    height: 18px;
    stroke: var(--icon-btn-icon);
    stroke-width: 2;
  }

  .share-button:hover {
    background: var(--icon-btn-hover-bg);
    transform: translateY(-1px);
  }
  .share-button:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
  }

  .share-container {
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    gap: 12px;
    border: 2px dotted var(--dot-border);
    padding: 0 24px 24px 24px;
    background: transparent;
    margin-top: 24px;
  }

  .share-header {
    margin-bottom: 8px;
  }

  .share-header h2 {
    margin-bottom: 8px;
  }

  .copy-toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translate(-50%, 20px);
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font: 600 14px/1.4 var(--font-ui);
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition:
      opacity 0.2s ease,
      transform 0.2s ease;
    z-index: 10000;
  }

  .copy-toast.copy-toast--visible {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@layer utilities {
  /* ==========================================================================
   8) Responsive adaptations
   ========================================================================== */

  /* ≤550: phone */
  @media (max-width: 550px) {
    main,
    .game-board {
      padding: 8px;
    }

    .row {
      flex-direction: row;
      align-items: center;
      gap: 0;
    }

    .trivia-container,
    .options-container {
      max-width: none;
      padding: 0;
    }

    .trivia-container {
      justify-content: flex-start;
      padding-right: 2px;
    }

    .options-container {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      align-items: start;
      width: 100%;
      gap: 5px;
    }

    .answer {
      width: 100%;
    }

    .label {
      padding: 0 4px;
    }

    .confirm-sticky {
      left: 0;
      right: 0;
      bottom: max(0px, env(safe-area-inset-bottom));
      --tx: 0;
    }
  }

  @media (max-width: 500px) {
    .stats-icon {
      inline-size: 23px;
    }

    .stats-icon svg {
      width: 18px;
      height: 18px;
    }
  }

  /* ≤374: very small (e.g., iPhone SE) */
  @media (max-width: 374px) {
    main,
    .game-board {
      padding: 12px;
    }

    .row {
      flex-direction: row;
      gap: 8px;
    }

    .trivia-container,
    .options-container {
      max-width: none;
      padding: 0;
    }

    .trivia-container {
      justify-content: flex-start;
    }

    .options-container {
      justify-items: stretch;
      grid-template-columns: 1fr;
    }

    .answer {
      width: 100%;
      min-width: 58px;
    }

    .question-text {
      margin-top: 16px;
    }

    .confirm-sticky {
      left: 0;
      right: 0;
      bottom: max(0px, env(safe-area-inset-bottom));
      --tx: 0;
    }
  }

  /* ≥551: desktop confirm bar centered to card width */
  @media (min-width: 551px) {
    .confirm-sticky {
      left: 50%;
      bottom: max(0px, env(safe-area-inset-bottom));
      min-width: var(--card-width);
      --tx: -50%;
    }

    .stats-text {
      white-space: nowrap;
    }
  }

  /* ==========================================================================
   9) Accessibility: reduced motion
   ========================================================================== */

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation: none !important;
    }

    #game,
    .overlay,
    .overlay-card,
    .overlay-start,
    .question-text,
    .questions-container::before,
    .row::after,
    .row > * {
      transition: none;
      opacity: 1;
    }

    /* remove 3D transforms to avoid mirrored text */
    .answer,
    .answer.is-revealed,
    .answer.is-result {
      transform: none;
    }
    .answer .label,
    .answer .result-face {
      transform: none !important;
    }

    .answer .label {
      opacity: 1;
    }

    .answer.pulse-correct,
    .answer.pulse-wrong {
      animation: none !important;
    }
  }

  /* ==========================================================================
   10) Fireworks!
   ========================================================================== */

  /* particle layer */
  .burst {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    contain: layout paint;
  }
  .spark {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--spark-a);
    transform: translate(0, 0) scale(0.8);
    opacity: 0;
    will-change: transform, opacity;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  }
  .spark.line {
    width: 2px;
    height: 10px;
    border-radius: 2px;
    box-shadow: none;
  }
}
