/* Word Hunt — letterpress tiles on warm paper (light) or on night ink (dark).
   Colours are tokens per theme; app.js sets <html data-theme="light|dark">
   from the setting (Automatic follows the system). Everything that moves
   moves with transform/opacity only. */

:root {
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.45, 0.5, 1);

  --bg-a: #f4efe5;
  --bg-b: #e3d9c7;
  --blob-1: rgba(255, 253, 247, 0.95);
  --blob-2: rgba(110, 200, 182, 0.3);
  --ink: #262a33;
  --ink-soft: #6d685f;
  --paper: #fcfaf5;
  --paper-2: #f2ece1;
  --line: rgba(66, 52, 30, 0.12);
  --btn: rgba(255, 255, 255, 0.66);
  --btn-hover: rgba(255, 255, 255, 0.94);
  --btn-border: rgba(80, 62, 36, 0.13);
  --accent: #26a593;
  --accent-2: #167c6f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(38, 165, 147, 0.17);
  --ca-accent: #167c6f;
  --badge: #262a33;
  --badge-ink: #fffaf3;
  --shadow: rgba(76, 56, 28, 0.2);
  --backdrop: rgba(48, 38, 24, 0.32);
  --gold: #e3a12a;
  --bad: #dc5346;
  --dup: #d99528;

  --tile: #fffcf6;
  --tile-top: #ffffff;
  --tile-edge: rgba(150, 120, 80, 0.26);
  --tile-shade: rgba(90, 66, 30, 0.16);
  --glyph: #2a2e37;
  --sel: #22a08e;
  --sel-top: #3fc0ac;
  --sel-glyph: #ffffff;
  --trail: rgba(34, 160, 142, 0.5);
  --found-l: 80%;
  --found-s: 66%;
  --found-glyph-l: 22%;
  --found-trail-l: 50%;
  --locked: 0.94;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-a: #151b27;
  --bg-b: #0b0f17;
  --blob-1: rgba(80, 120, 170, 0.12);
  --blob-2: rgba(50, 190, 165, 0.1);
  --ink: #edf0f5;
  --ink-soft: #9ca5b4;
  --paper: #1b2130;
  --paper-2: #252d3d;
  --line: rgba(255, 255, 255, 0.09);
  --btn: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
  --btn-border: rgba(255, 255, 255, 0.1);
  --accent: #3ccab3;
  --accent-2: #1f9e8b;
  --accent-ink: #04231f;
  --accent-soft: rgba(60, 202, 179, 0.18);
  --ca-accent: #167c6f;
  --badge: #edf0f5;
  --badge-ink: #151b27;
  --shadow: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(3, 6, 12, 0.5);
  --gold: #f0b94a;
  --bad: #f07267;
  --dup: #e9aa45;

  --tile: #252e3f;
  --tile-top: #2e384b;
  --tile-edge: rgba(0, 0, 0, 0.45);
  --tile-shade: rgba(0, 0, 0, 0.42);
  --glyph: #f2f5fa;
  --sel: #22a591;
  --sel-top: #43cdb7;
  --sel-glyph: #ffffff;
  --trail: rgba(70, 215, 190, 0.45);
  --found-l: 31%;
  --found-s: 42%;
  --found-glyph-l: 93%;
  --found-trail-l: 62%;
  --locked: 1;
  color-scheme: dark;
}

/* Before app.js sets data-theme (the first paint), follow the system. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-a: #151b27;
    --bg-b: #0b0f17;
    --blob-1: rgba(80, 120, 170, 0.12);
    --blob-2: rgba(50, 190, 165, 0.1);
    --ink: #edf0f5;
    --ink-soft: #9ca5b4;
    --paper: #1b2130;
    --paper-2: #252d3d;
    --line: rgba(255, 255, 255, 0.09);
    --btn: rgba(255, 255, 255, 0.06);
    --btn-hover: rgba(255, 255, 255, 0.12);
    --btn-border: rgba(255, 255, 255, 0.1);
    --accent: #3ccab3;
    --accent-2: #1f9e8b;
    --accent-ink: #04231f;
    --accent-soft: rgba(60, 202, 179, 0.18);
    --ca-accent: #167c6f;
    --badge: #edf0f5;
    --badge-ink: #151b27;
    --shadow: rgba(0, 0, 0, 0.45);
    --backdrop: rgba(3, 6, 12, 0.5);
    --gold: #f0b94a;
    --bad: #f07267;
    --dup: #e9aa45;

    --tile: #252e3f;
    --tile-top: #2e384b;
    --tile-edge: rgba(0, 0, 0, 0.45);
    --tile-shade: rgba(0, 0, 0, 0.42);
    --glyph: #f2f5fa;
    --sel: #22a591;
    --sel-top: #43cdb7;
    --sel-glyph: #ffffff;
    --trail: rgba(70, 215, 190, 0.45);
    --found-l: 31%;
    --found-s: 42%;
    --found-glyph-l: 93%;
    --found-trail-l: 62%;
    --locked: 1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; background: var(--bg-b); }
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(170deg, var(--bg-a), var(--bg-b));
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; -webkit-touch-callout: none; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .blob { position: absolute; border-radius: 50%; filter: blur(70px); }
.bg .b1 { width: 70vmax; height: 70vmax; left: -26vmax; top: -30vmax; background: var(--blob-1); }
.bg .b2 { width: 54vmax; height: 54vmax; right: -24vmax; bottom: -22vmax; background: var(--blob-2); }

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 620px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 2px 16px; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand img { width: 38px; height: 38px; flex: 0 0 auto; border-radius: 10px; filter: drop-shadow(0 2px 3px var(--shadow)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--round); font-weight: 750; font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-size: 10.5px; color: var(--ink-soft); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { display: flex; align-items: center; gap: 0; flex: 0 0 auto; }
.account-slot { display: inline-flex; margin-left: 4px; }

.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: var(--btn); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg, .hud-mode svg, .pill-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ hud */
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 4px 16px 0; }
.hud-mode {
  appearance: none; justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--btn-border); background: var(--btn); border-radius: 999px;
  padding: 6px 12px 6px 9px; min-height: 38px; cursor: pointer; max-width: 100%;
  transition: background 0.2s, transform 0.15s;
}
.hud-mode:hover { background: var(--btn-hover); }
.hud-mode:active { transform: scale(0.96); }
.hud-mode svg { width: 18px; height: 18px; color: var(--accent-2); flex: 0 0 auto; }
.hud-mode b { font: 700 14px var(--round); white-space: nowrap; }
.hud-mode small { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
.hud-clock { display: flex; flex-direction: column; align-items: center; min-width: 86px; }
.hud-clock b { font: 750 27px/1.05 var(--round); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; transition: color 0.3s; }
.hud-clock.low b { color: var(--bad); animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.07); } }
.hud-bar { position: relative; display: block; width: 76px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 4px; }
.hud-bar i { position: absolute; inset: 0; border-radius: 2px; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transform-origin: left; transform: scaleX(var(--from, 1)); }
.hud-bar i.run { animation: drain var(--dur, 60s) linear forwards; }
.hud-bar i.paused { animation-play-state: paused; }
@keyframes drain { from { transform: scaleX(var(--from, 1)); } to { transform: scaleX(0); } }
.hud-clock.zen .hud-bar { display: none; }
.hud-clock.zen b { font-size: 22px; color: var(--ink-soft); }
.hud-score { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.hud-score span { font-size: 10.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); }
.hud-score b { font: 750 22px var(--round); font-variant-numeric: tabular-nums; }
.hud-score b.bump { animation: bump 0.45s var(--spring); }
@keyframes bump { 35% { transform: scale(1.22); } }

/* ----------------------------------------------------- the current word */
.wordrow { position: relative; padding: 8px 16px 2px; display: flex; flex-direction: column; align-items: center; }
.pill {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; min-width: min(78%, 300px); max-width: 100%; padding: 4px 8px 4px 20px;
  border-radius: 999px; background: var(--paper); border: 1.5px solid var(--line);
  box-shadow: 0 2px 8px -4px var(--shadow);
  transition: background 0.18s, border-color 0.18s, transform 0.18s var(--spring);
}
.pill-text { flex: 1 1 auto; min-width: 0; text-align: center; font: 750 25px/1.15 var(--round); letter-spacing: 0.09em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 12px; }
.pill.empty .pill-text { font: 500 14.5px var(--sans); letter-spacing: 0; color: var(--ink-soft); padding-right: 12px; }
.pill.valid { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 12%, var(--paper)); }
.pill.dup { border-color: var(--dup); }
.pill.bad { border-color: var(--bad); animation: shakeX 0.36s ease; }
.pill.good { animation: bump 0.4s var(--spring); }
.pill-btn {
  appearance: none; flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: transparent; color: var(--ink-soft); cursor: pointer;
}
.pill-btn.send { color: var(--accent-ink); background: var(--accent-2); }
.pill-btn svg { width: 19px; height: 19px; stroke-width: 2.1; }
.note {
  min-height: 24px; margin-top: 4px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 10px;
  font-size: 13.5px; line-height: 1.3; text-align: center; color: var(--ink-soft);
  opacity: 0; transform: translateY(-4px); transition: opacity 0.2s, transform 0.25s var(--ease);
}
.note.show { opacity: 1; transform: none; }
.note b { color: var(--ink); font-weight: 650; }
.note.good b { color: var(--accent-2); }
:root[data-theme="dark"] .note.good b { color: var(--accent); }
.note.bad b { color: var(--bad); }
.note .link {
  appearance: none; border: 1.5px solid var(--accent); background: transparent; color: var(--accent-2);
  border-radius: 999px; padding: 4px 12px; font: 600 13px var(--sans); cursor: pointer; min-height: 32px;
}
:root[data-theme="dark"] .note .link { color: var(--accent); }
.note .link:active { transform: scale(0.96); }

/* -------------------------------------------------------------- the board */
.stage { flex: 10 1 0; min-height: 0; max-height: calc(100vw + 4px); display: grid; place-items: center; padding: 6px 12px; container-type: size; }
.board {
  --n: 5;
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  touch-action: none;
  container-type: inline-size;
  outline: none;
  border-radius: 6%;
}
.board:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.tiles, .glyphs {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  pointer-events: none;
}
.tile {
  --pitch: calc(100cqi / var(--n));
  margin: calc(var(--pitch) * 0.055);
  border-radius: calc(var(--pitch) * 0.24);
  background: linear-gradient(180deg, var(--tile-top), var(--tile));
  box-shadow: inset 0 -2px 0 var(--tile-edge), 0 calc(var(--pitch) * 0.04) calc(var(--pitch) * 0.1) -1px var(--tile-shade);
  transition: background-color 0.2s, transform 0.2s var(--spring), opacity 0.3s;
}
.glyph {
  display: grid; place-items: center;
  font: 720 calc(100cqi / var(--n) * 0.47) / 1 var(--round);
  color: var(--glyph);
  letter-spacing: 0;
  transition: color 0.18s, transform 0.2s var(--spring);
  font-synthesis: none;
}
.tile.sel { background: linear-gradient(180deg, var(--sel-top), var(--sel)); transform: scale(1.05); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16), 0 4px 12px -4px color-mix(in oklab, var(--sel) 70%, black); }
.glyph.sel { color: var(--sel-glyph); transform: scale(1.05); }
.tile.head { transform: scale(1.1); }
.glyph.head { transform: scale(1.1); }
.tile.found { background: hsl(var(--h) var(--found-s) var(--found-l)); box-shadow: inset 0 -2px 0 hsl(var(--h) 40% 50% / 0.25); transform: scale(var(--locked)); }
.glyph.found { color: hsl(var(--h) 45% var(--found-glyph-l)); }
.tile.found.sel { background: linear-gradient(180deg, var(--sel-top), var(--sel)); }
.tile.hint { position: relative; }
.tile.hint::after {
  content: ""; position: absolute; inset: -3px; border-radius: inherit;
  border: 2.5px solid var(--gold); animation: ring 1.6s ease-in-out infinite;
}
@keyframes ring { 50% { opacity: 0.35; transform: scale(1.06); } }
.tile.peek { background: color-mix(in oklab, var(--gold) 45%, var(--tile)); }
.glyph.peek { color: var(--ink); }

.trails { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.trails polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trail { stroke: var(--trail); stroke-width: 0.3; transition: stroke 0.15s; }
.trail.good { stroke: color-mix(in oklab, var(--accent) 70%, transparent); }
.trail.bad { stroke: color-mix(in oklab, var(--bad) 65%, transparent); }
.trail.dup { stroke: color-mix(in oklab, var(--dup) 65%, transparent); }
.found-trail { stroke: hsl(var(--h) 60% var(--found-trail-l) / 0.5); stroke-width: 0.24; }
.hint-trail { stroke: var(--gold); stroke-width: 0.08; stroke-dasharray: 0.12 0.16; opacity: 0.9; }
.review { stroke: color-mix(in oklab, var(--gold) 80%, transparent); stroke-width: 0.26; }

.pop { animation: pop 0.44s var(--spring) calc(var(--i, 0) * 34ms) both; }
@keyframes pop { 45% { transform: scale(1.18); } 100% { transform: scale(1); } }
.shake { animation: shakeX 0.38s ease; }
@keyframes shakeX { 20% { translate: -4px 0; } 40% { translate: 4px 0; } 60% { translate: -3px 0; } 80% { translate: 2px 0; } }
.nudge { animation: nudge 0.34s ease; }
@keyframes nudge { 50% { transform: scale(0.92); } }
.wave { animation: wave 0.7s var(--spring) calc(var(--d, 0) * 55ms) both; }
@keyframes wave { 40% { transform: scale(1.14) rotate(-3deg); } 100% { transform: scale(var(--locked)); } }

.veil {
  position: absolute; inset: -2px; z-index: 3; border-radius: 6%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 20px; text-align: center;
  background: color-mix(in oklab, var(--paper) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  animation: fade 0.25s;
}
.veil h2 { font: 750 26px var(--round); margin: 0; }
.veil p { margin: 0 0 12px; color: var(--ink-soft); max-width: 30ch; font-size: 14.5px; }
.veil .btn { flex: 0 0 auto; padding: 12px 22px; }
.loading { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px; color: var(--ink-soft); }
.loading.failed .spinner { display: none; }
.loading p { margin: 0; max-width: 30ch; font-size: 14.5px; }
.loading .btn { flex: 0 0 auto; padding: 10px 20px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ the panel */
.panel { flex: 1 1 0; padding: 2px 16px 0; display: flex; flex-direction: column; gap: 6px; min-height: 64px; }
.zen-meta { display: flex; justify-content: center; gap: 14px; font-size: 13px; color: var(--ink-soft); }
.zen-meta b { color: var(--ink); font-weight: 650; }
.words {
  list-style: none; margin: 0; padding: 2px 0 4px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  flex: 1 1 auto; min-height: 34px; overflow-y: auto; overscroll-behavior: contain; align-content: flex-start;
  mask-image: linear-gradient(180deg, transparent 0, #000 6px, #000 calc(100% - 8px), transparent 100%);
}
.w {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; min-height: 28px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--line);
  font: 700 13px/1.1 var(--round); letter-spacing: 0.05em; white-space: nowrap;
}
.w em { font-style: normal; font-weight: 600; font-size: 11px; color: var(--ink-soft); letter-spacing: 0; }
.w.hidden-word { background: color-mix(in oklab, var(--accent) 15%, var(--paper)); border-color: color-mix(in oklab, var(--accent) 45%, transparent); }
.w.hidden-word svg { width: 11px; height: 11px; fill: var(--gold); stroke: none; }
.w.fresh { animation: chipIn 0.4s var(--spring); }
@keyframes chipIn { from { transform: scale(0.6); opacity: 0; } }
.w.slot { gap: 3px; padding: 4px 10px; color: var(--ink-soft); }
.w.slot i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); box-shadow: inset 0 0 0 1px var(--btn-border); }
.w.slot i.lit { background: var(--gold); }
.w.slot.done { color: hsl(var(--h) 45% var(--found-glyph-l)); background: hsl(var(--h) var(--found-s) var(--found-l)); border-color: transparent; }
.w.slot.open { color: var(--ink); }
button.w { appearance: none; cursor: pointer; }
button.w:active { transform: scale(0.96); }
button.w[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 2px color-mix(in oklab, var(--gold) 40%, transparent); }
.w.missed { background: var(--paper-2); }
.review-tabs { display: flex; justify-content: center; gap: 6px; }
.review-tip { margin: 0; text-align: center; font-size: 12.5px; color: var(--ink-soft); }

/* ------------------------------------------------------------- actions */
.actions { display: flex; gap: 8px; padding: 8px 14px 12px; }
.btn {
  appearance: none; position: relative; flex: 1; min-width: 0;
  border: 1px solid var(--btn-border); background: var(--btn); color: var(--ink);
  font: 550 15px var(--sans); padding: 11px 10px; min-height: 46px; border-radius: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  box-shadow: 0 1px 2px var(--shadow);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 55%), linear-gradient(180deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-color: color-mix(in oklab, var(--accent-2) 80%, black);
  box-shadow: 0 5px 14px -6px color-mix(in oklab, var(--accent-2) 80%, black), inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.08);
  font-weight: 650;
}
:root:not([data-theme="dark"]) .btn.primary { background: radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 55%), linear-gradient(180deg, #1f9584, var(--accent-2)); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.pulse { animation: bump 0.6s var(--spring); }
.btn .badge {
  position: absolute; top: -7px; right: -5px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--badge); color: var(--badge-ink); font: 700 11.5px/20px var(--round); font-style: normal; text-align: center;
  box-shadow: 0 1px 3px var(--shadow);
}
.btn .badge:empty { display: none; }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--backdrop); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; z-index: 21;
  max-width: 560px; max-height: 90dvh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px var(--shadow); padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2, .dialog h2 { font-family: var(--round); font-weight: 750; font-size: 24px; margin: 0; }
.sheet-body { overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 2px 22px 26px; font-size: 15px; line-height: 1.55; }
.sheet-body h3 { font-family: var(--round); font-weight: 700; font-size: 16.5px; margin: 20px 0 8px; }
.sheet-body h3:first-child { margin-top: 6px; }
.prose { -webkit-user-select: text; user-select: text; }
.prose p { margin: 0 0 10px; }
.points-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; margin: 4px 0 8px; }
.points-table span { background: var(--paper-2); border-radius: 10px; padding: 5px 8px; font-size: 13px; text-align: center; }
.about { font-size: 12.5px; margin-top: 22px; text-align: center; color: var(--ink-soft); }
@media (min-width: 700px) and (min-height: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 84dvh; animation: popSheet 0.28s var(--ease); }
}
@keyframes popSheet { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 22;
  width: min(92vw, 420px); max-height: 92dvh; overflow: auto;
  background: var(--paper); color: var(--ink); border-radius: 26px; padding: 26px 22px 20px;
  box-shadow: 0 24px 64px var(--shadow); text-align: center;
  animation: popc 0.34s var(--spring);
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -46%) scale(0.92); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.dialog .btn { font-size: 15px; padding: 12px; }
.result { overflow-x: hidden; }
.result .glow { position: absolute; inset: -45% -20% auto; height: 75%; background: radial-gradient(ellipse at 50% 45%, var(--accent-soft), transparent 65%); pointer-events: none; }
.result.solved .glow { background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--gold) 38%, transparent), transparent 65%); }
.result h2 { position: relative; font-size: 28px; }
.result .result-sub { position: relative; margin: 2px 0 12px; font-size: 14px; }
.score { position: relative; display: flex; flex-direction: column; align-items: center; margin: 2px 0 14px; }
.score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.score b { font-family: var(--round); font-size: 46px; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; }
.score em { font-style: normal; font: 700 13px var(--round); color: var(--accent-ink); background: linear-gradient(180deg, var(--accent), var(--accent-2)); padding: 3px 10px; border-radius: 999px; margin-top: 4px; animation: starIn 0.5s var(--spring) 0.3s backwards; }
@keyframes starIn { from { transform: scale(0.3); opacity: 0; } }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 16px; position: relative; }
.result-stats div { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; min-width: 0; }
.result-stats span { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); text-align: center; }
.result-stats b { font-family: var(--round); font-size: 18px; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friends { text-align: left; margin: 0 0 16px; }
.friends h3 { font: 700 15px var(--round); margin: 0 0 6px; text-align: center; color: var(--ink-soft); }

/* ----------------------------------------------------- options, toggles */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none; border: 1.5px solid var(--line); background: var(--paper-2); color: var(--ink);
  font: 550 14px var(--sans); padding: 8px 6px; min-height: 44px; border-radius: 14px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  cursor: pointer; transition: border-color 0.2s, background 0.2s, transform 0.15s; flex: 1 1 0; min-width: 0;
}
.opt small { font-size: 11.5px; color: var(--ink-soft); font-weight: 500; }
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.opt b { font: 700 16px var(--round); white-space: nowrap; }
.hint-line { margin: 8px 0 0; font-size: 13.5px; color: var(--ink-soft); min-height: 2.6em; }
.start { width: 100%; margin-top: 18px; padding: 14px; font-size: 16.5px; }
.linkish { appearance: none; border: 0; background: none; color: var(--accent-2); font: 500 14px var(--sans); padding: 12px 4px 0; cursor: pointer; display: block; margin: 0 auto; }
:root[data-theme="dark"] .linkish { color: var(--accent); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.field > span { font-size: 15px; }
select {
  appearance: none; font: 500 15px var(--sans); color: var(--ink); background: var(--paper-2);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 34px 9px 12px; min-height: 44px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; cursor: pointer; font-size: 15px; position: relative; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 48px; height: 29px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.25s; box-shadow: inset 0 0 0 1px var(--btn-border); }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 23px; height: 23px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent-2); }
.toggle input:checked + .track::after { transform: translateX(19px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.wide-btn { width: 100%; margin-top: 20px; }

/* ------------------------------------------------------------- results */
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num, td.num { text-align: right; }
td.best { font: 700 15px var(--round); }
td small { color: var(--ink-soft); font-size: 12px; }
.reports { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.reports li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--paper-2); border-radius: 12px; padding: 8px 12px; }
.reports b { font: 700 14px var(--round); letter-spacing: 0.05em; }
.reports span { font-size: 12.5px; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 4px; }
.reports .added { color: var(--accent-2); font-weight: 600; }
:root[data-theme="dark"] .reports .added { color: var(--accent); }
.reports svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; }

.live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ----------------------------------------------------- phone sizes */
@media (max-width: 440px) {
  .btn.narrow { flex: 0 0 52px; }
  .btn.narrow span { display: none; }
}
@media (max-width: 380px) {
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .hud-mode small { display: none; }
  .actions .btn span { font-size: 14px; }
}
@media (max-height: 700px) {
  .top { padding-top: 4px; }
  .brand img { width: 32px; height: 32px; }
  .brand small { display: none; }
  .pill { min-height: 42px; }
  .pill-text { font-size: 22px; }
  .actions { padding-top: 4px; padding-bottom: 8px; }
  .btn { min-height: 42px; padding: 8px; }
}

/* --------------------------------------- wide screens: board beside the panel */
@media (min-width: 860px) and (min-aspect-ratio: 5/4), (max-height: 520px) and (orientation: landscape) {
  .app {
    max-width: 1220px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "stage hud" "stage word" "stage panel" "stage actions";
    column-gap: 10px;
  }
  .top { grid-area: top; }
  .hud { grid-area: hud; padding-top: 16px; }
  .wordrow { grid-area: word; padding-top: 16px; }
  .stage { grid-area: stage; padding: 8px 4px 16px 18px; max-height: none; }
  .panel { grid-area: panel; padding-top: 12px; }
  .words { max-height: none; flex: 1 1 auto; align-content: flex-start; }
  .actions { grid-area: actions; flex-wrap: wrap; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .top { padding: 2px 10px 0 14px; }
  .brand small { display: none; }
  .hud { padding-top: 4px; }
  .wordrow { padding-top: 6px; }
  .stage { padding: 4px 4px 8px 12px; }
  .panel { padding-top: 4px; }
  .actions { padding: 4px 10px 8px; }
  .btn { min-height: 40px; padding: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; animation-delay: 0ms !important; }
  .hud-bar i.run { animation: none; }
}
