  :root {
    --bg: #FFFDF5; --surface: #FFFFFF; --ink: #1E1A14; --muted: #6B6355;
    --accent: #F2B705; --accent-soft: #FFF1C2; --on-accent: #1E1A14;
    --line: #E8E1CF; --wrong: #C2410C; --wrong-soft: #FDE7DA;
    color-scheme: light;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #17140F; --surface: #201C15; --ink: #F5EFE0; --muted: #A89E8A;
      --accent: #F2B705; --accent-soft: #3A2F0E; --on-accent: #1E1A14;
      --line: #2E2920; --wrong: #FB923C; --wrong-soft: #3A2014; color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #17140F; --surface: #201C15; --ink: #F5EFE0; --muted: #A89E8A;
    --accent: #F2B705; --accent-soft: #3A2F0E; --on-accent: #1E1A14;
    --line: #2E2920; --wrong: #FB923C; --wrong-soft: #3A2014; color-scheme: dark;
  }
  *, *::before, *::after { box-sizing: inherit; margin: 0; }
  html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
  body {
    min-height: 100%; display: flex; flex-direction: column;
    background: var(--bg); color: var(--ink);
    font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 1rem; line-height: 1.5;
  }
  header, footer { padding: 1.25rem clamp(1.25rem, 5vw, 3rem); }
  header { border-bottom: 1px solid var(--line); }
  footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.875rem; }
  .logo {
    font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em;
    color: var(--ink); text-decoration: none;
    display: inline-flex; align-items: center; gap: 0.5rem;
  }
  .hex {
    display: inline-block; width: 0.8em; height: 0.8em; background: var(--accent); flex: none;
    clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  }
  a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  main {
    flex: 1; width: 100%; max-width: 40rem; margin: 0 auto;
    padding: clamp(2rem, 6vw, 4rem) clamp(1.25rem, 5vw, 3rem);
  }
  .date { color: var(--muted); font-size: 0.9375rem; }
  h1 {
    font-weight: 800; font-size: clamp(2.5rem, 9vw, 4.5rem);
    letter-spacing: -0.04em; line-height: 0.95; margin: 0.25rem 0 0.75rem;
  }
  h2 { font-weight: 800; font-size: 1.375rem; letter-spacing: -0.02em; margin-bottom: 1rem; }
  .lede { color: var(--muted); margin-bottom: 2rem; }
  [hidden] { display: none !important; }

  /* Difficulty picker */
  .levels { display: grid; gap: 0.75rem; }
  .level {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.25rem 1rem;
    width: 100%; text-align: left; font: inherit; color: var(--ink);
    padding: 1.1rem 1.25rem; background: var(--surface);
    border: 2px solid var(--line); border-radius: 14px; cursor: pointer;
  }
  .level:hover { border-color: var(--accent); }
  .level strong { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
  .level .desc { grid-column: 1; color: var(--muted); font-size: 0.9375rem; }
  .level .mult { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em; }
  .pips { display: inline-flex; gap: 0.25rem; vertical-align: middle; margin-left: 0.5rem; }
  .pips .hex { width: 0.75rem; height: 0.75rem; }
  .note { color: var(--muted); font-size: 0.875rem; margin-top: 1rem; }
  .rules { color: var(--muted); font-size: 0.9375rem; margin-top: 1.5rem; display: grid; gap: 0.35rem; }
  .rules strong { color: var(--ink); font-weight: 600; }

  /* Game */
  .topbar {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    margin-bottom: 1rem; font-weight: 600; flex-wrap: wrap;
  }
  .combs { display: flex; gap: 0.3rem; }
  .combs .hex { width: 1rem; height: 1rem; background: var(--line); }
  .combs .hex.solved { background: var(--accent); }
  .combs .hex.missed { background: var(--wrong); }
  .combs .hex.skipped { background: var(--muted); }
  .combs .hex.current { background: var(--ink); }
  .topbar-right { display: flex; align-items: center; gap: 0.75rem; }
  .running { font-variant-numeric: tabular-nums; }
  .badge { font-size: 0.875rem; padding: 0.2rem 0.65rem; border-radius: 999px; background: var(--accent-soft); color: var(--ink); }

  .card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
    padding: clamp(1.25rem, 4vw, 2rem);
  }
  .card.solved, .card.won { background: var(--accent-soft); border-color: var(--accent); }
  .card.missed, .card.lost { background: var(--wrong-soft); border-color: var(--wrong); }
  .card.bonus { border: 2px solid var(--ink); }
  .which { color: var(--muted); font-size: 0.9375rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .which-right { display: inline-flex; align-items: center; gap: 0.9rem; }
  .clock { font-variant-numeric: tabular-nums; }
  .lives { display: inline-flex; align-items: center; gap: 0.3rem; }
  .lives .hex { width: 0.9rem; height: 0.9rem; }
  .lives .hex.lost { background: var(--line); }
  .hint {
    font-size: clamp(1.375rem, 4.5vw, 1.875rem); font-weight: 600;
    letter-spacing: -0.015em; line-height: 1.2; margin: 0.75rem 0 1.5rem;
  }
  .shape { color: var(--muted); font-size: 0.9375rem; margin: -1rem 0 1.25rem; }
  .guess { display: flex; gap: 0.5rem; }
  .guess input {
    flex: 1; min-width: 0; font: inherit; font-size: 1.125rem; font-weight: 600;
    padding: 0.8rem 1rem; color: var(--ink); background: var(--bg);
    border: 2px solid var(--line); border-radius: 12px; text-transform: lowercase;
  }
  .guess input::placeholder { color: var(--muted); font-weight: 400; text-transform: none; }
  .guess input:focus { outline: none; border-color: var(--accent); }
  .btn { font: inherit; font-weight: 600; padding: 0.8rem 1.15rem; border-radius: 12px; cursor: pointer; border: none; }
  .btn-primary { background: var(--ink); color: var(--bg); }
  .btn-primary:hover { opacity: 0.88; }
  .btn-accent { background: var(--accent); color: var(--on-accent); }
  .btn-accent:hover { filter: brightness(1.05); }
  .btn-outline { background: none; color: var(--ink); border: 2px solid var(--line); }
  .btn-outline:hover { border-color: var(--ink); }
  .btn-quiet { background: none; color: var(--muted); padding: 0.5rem 0; text-decoration: underline; text-underline-offset: 3px; }
  .btn-quiet:hover { color: var(--ink); }
  .row-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 0.75rem; min-height: 2.5rem; }
  .msg { color: var(--wrong); font-size: 0.9375rem; }
  .reveal { display: grid; gap: 1rem; justify-items: start; }
  .reveal .word {
    display: flex; align-items: center; gap: 0.6rem;
    font-weight: 800; font-size: clamp(2rem, 7vw, 2.75rem); letter-spacing: -0.03em; line-height: 1;
  }
  .reveal .word .hex { width: 1.5rem; height: 1.5rem; }
  .card.missed .reveal .word .hex, .card.lost .reveal .word .hex { background: var(--wrong); }
  .card.skipped .reveal .word .hex { background: var(--muted); }
  .reveal p { color: var(--muted); }
  .reveal .earned { color: var(--ink); font-weight: 600; }
  .shake .guess input { border-color: var(--wrong); animation: shake 0.35s; }
  @keyframes shake { 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }

  /* Results */
  .total-label { color: var(--muted); font-weight: 600; }
  .total {
    font-weight: 800; font-size: clamp(4rem, 18vw, 7.5rem); letter-spacing: -0.05em; line-height: 0.9;
    font-variant-numeric: tabular-nums; margin: 0.25rem 0 0.5rem;
  }
  .total-sub { color: var(--muted); margin-bottom: 2rem; }
  .total-sub strong { color: var(--ink); }
  .summary { list-style: none; padding: 0; display: grid; gap: 0.5rem; margin: 0 0 2rem; }
  .summary li {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.15rem 1rem;
    padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  }
  .summary .w { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; font-size: 1.125rem; }
  .summary .r { grid-column: 1; color: var(--muted); font-size: 0.875rem; padding-left: 1.4rem; }
  .summary .pts { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
  .summary li.missed .hex { background: var(--wrong); }
  .summary li.skipped .hex { background: var(--muted); }
  .summary li.missed .pts, .summary li.skipped .pts { color: var(--muted); }
  .bonus-title { font-weight: 800; font-size: 1.375rem; letter-spacing: -0.02em; margin-bottom: 0.5rem; }
  .stakes { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 1.25rem 0; }
  .stake { padding: 0.85rem 1rem; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
  .stake span { display: block; color: var(--muted); font-size: 0.875rem; }
  .stake strong { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
  .actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

  /* Header nav */
  header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .nav { display: flex; gap: 1.25rem; }
  .nav a { color: var(--muted); text-decoration: none; font-weight: 600; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
  .nav a:hover { color: var(--ink); }
  .nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

  /* Save score panel */
  #savePanel:not(:empty) { margin: -0.75rem 0 2rem; }
  .save .field { display: grid; gap: 0.35rem; width: 100%; }
  .save { padding: 1.25rem; border-radius: 14px; background: var(--surface); border: 2px solid var(--accent); display: grid; gap: 0.75rem; justify-items: start; }
  .save .save-title { font-weight: 800; font-size: 1.125rem; letter-spacing: -0.01em; }
  .save p { color: var(--muted); }
  .save p strong { color: var(--ink); }
  .save.skipped { border: 1px dashed var(--line); }
  .save .warn-text { color: var(--wrong); }
  .btn-link { display: inline-block; text-decoration: none; }

  /* Rank line on results */
  .rank { margin: -1.25rem 0 2rem; font-weight: 600; }
  .rank a { color: var(--ink); text-underline-offset: 3px; }
  .rank.warn { color: var(--wrong); font-weight: 400; }

  /* Leaderboard */
  .tabs { display: inline-flex; padding: 0.25rem; gap: 0.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 0.5rem; }
  .tab { font: inherit; font-weight: 600; padding: 0.5rem 1rem; border: none; border-radius: 9px; background: none; color: var(--muted); cursor: pointer; }
  .tab[aria-selected="true"] { background: var(--ink); color: var(--bg); }
  .period { color: var(--muted); font-size: 0.9375rem; margin-bottom: 1rem; }
  .lb { list-style: none; padding: 0; display: grid; gap: 0.4rem; }
  .lb li {
    display: grid; grid-template-columns: 2.25rem 1fr auto; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  }
  .lb li.me { background: var(--accent-soft); border-color: var(--accent); }
  .lb li.gap { background: none; border: none; padding: 0; justify-items: center; color: var(--muted); grid-template-columns: 1fr; }
  .lb .pos { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
  .lb li:nth-child(-n+3):not(.gap) .pos { color: var(--ink); }
  .lb .who { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lb .you { color: var(--muted); font-weight: 400; }
  .lb .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
  .empty { color: var(--muted); padding: 1.25rem; border: 1px dashed var(--line); border-radius: 12px; }
  .winners { margin-top: 2.5rem; }
  .podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
  .podium div { padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
  .podium div:first-child { border: 2px solid var(--accent); }
  .podium .place { color: var(--muted); font-size: 0.875rem; }
  .podium .who { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .podium .sc { font-variant-numeric: tabular-nums; color: var(--muted); }
  @media (max-width: 520px) { .podium { grid-template-columns: 1fr; } }

  @media (prefers-reduced-motion: reduce) { .shake .guess input { animation: none; } }
  @media (max-width: 420px) {
    .guess { flex-direction: column; }
    .stakes { grid-template-columns: 1fr; }
  }

  /* Account + sign-in */
  .nav { align-items: center; }
  .account { display: inline-flex; align-items: center; gap: 0.75rem; }
  .account .who-me { font-weight: 600; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav .btn { padding: 0.45rem 0.9rem; }
  .signin { display: grid; gap: 0.9rem; width: 100%; }
  .btn-google { display: inline-flex; align-items: center; justify-content: center; gap: 0.6rem; background: var(--surface); color: var(--ink); border: 2px solid var(--line); width: 100%; }
  .btn-google:hover { border-color: var(--ink); }
  .or { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.875rem; }
  .or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
  .text-input {
    width: 100%; font: inherit; font-size: 1.0625rem; padding: 0.75rem 0.9rem; color: var(--ink);
    background: var(--bg); border: 2px solid var(--line); border-radius: 12px;
  }
  .text-input:focus { outline: none; border-color: var(--accent); }
  .inline-form { display: flex; gap: 0.5rem; width: 100%; }
  .inline-form .text-input { flex: 1; min-width: 0; }
  .form-msg { font-size: 0.9375rem; color: var(--muted); }
  .form-msg.error { color: var(--wrong); }
  .code-input { letter-spacing: 0.3em; font-weight: 800; font-variant-numeric: tabular-nums; }
  dialog.modal {
    width: min(26rem, calc(100% - 2rem)); padding: 1.5rem; border: 1px solid var(--line); border-radius: 18px;
    background: var(--surface); color: var(--ink);
  }
  dialog.modal::backdrop { background: rgba(30, 26, 20, 0.45); }
  .modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
  .modal-head h2 { margin: 0; }
  .icon-btn { font: inherit; font-size: 1.5rem; line-height: 1; background: none; border: none; color: var(--muted); cursor: pointer; padding: 0.25rem 0.5rem; }
  .config-warning { background: var(--wrong-soft); color: var(--ink); padding: 0.75rem clamp(1.25rem, 5vw, 3rem); font-size: 0.9375rem; }
  @media (max-width: 520px) {
    header { flex-wrap: wrap; }
    .inline-form { flex-direction: column; }
    .account .who-me { max-width: 6rem; }
  }

  /* Text pages (privacy policy) */
  .prose h2 { margin: 2.25rem 0 0.6rem; }
  .prose p, .prose li { max-width: 38rem; }
  .prose p + p { margin-top: 0.75rem; }
  .prose ul { padding-left: 1.25rem; margin: 0.75rem 0; display: grid; gap: 0.5rem; }
  .prose a, footer a { color: var(--ink); text-underline-offset: 3px; }
  footer a { color: var(--muted); }
  footer a:hover { color: var(--ink); }
