:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-text: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --series-1: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --bad-wash: rgba(208, 59, 59, 0.10);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 12px;
  --font: system-ui, "Segoe UI Variable Text", "Segoe UI", -apple-system, sans-serif;
}

/* Dark: follows the OS, unless the web build forces a theme with data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-text: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --bad-wash: rgba(230, 103, 103, 0.14);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-text: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --good: #0ca30c;
  --bad: #e66767;
  --bad-wash: rgba(230, 103, 103, 0.14);
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-y: auto;
}
h1 { font-size: 24px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
p { margin: 0; }
.muted { color: var(--muted); }
.lede { color: var(--ink-2); max-width: 62ch; }
kbd {
  font: 600 11px var(--font);
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid currentColor;
  opacity: 0.65;
  margin-left: 6px;
}
button { font: inherit; color: inherit; }

/* ---- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 56px; padding: 0 20px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand img { border-radius: 6px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 8px 16px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.active { background: var(--accent-wash); color: var(--accent-text); }
.top-right { justify-self: end; display: flex; align-items: center; gap: 10px; }
body[data-view="game"] .topbar, body[data-view="game"] main,
body[data-view="e80game"] .topbar, body[data-view="e80game"] main { display: none; }

/* ---- segmented control -------------------------------------------------- */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: 9px;
}
.seg button {
  border: 0; background: none; cursor: pointer;
  padding: 5px 12px; border-radius: 7px; color: var(--ink-2); font-size: 13px;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border); font-weight: 500; }

/* ---- layout ------------------------------------------------------------- */
main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 56px; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  margin-bottom: 20px;
}
.filters { display: flex; align-items: center; gap: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.sub { color: var(--muted); font-size: 13px; }

/* ---- controls ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: 36px; padding: 0 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--surface); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled:hover { background: var(--accent); }
.btn.big { height: 46px; padding: 0 26px; font-size: 16px; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.link { background: none; border: 0; color: var(--accent-text); padding: 0 6px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.danger:hover { color: var(--bad); }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="number"] {
  width: 64px; height: 32px; padding: 0 6px; text-align: center;
  font: inherit; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 7px;
}
input[type="number"]::-webkit-inner-spin-button { display: none; }
input[type="number"]:disabled { opacity: 0.4; }
select {
  height: 34px; padding: 0 10px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px;
}
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.check.small { font-size: 13px; color: var(--ink-2); gap: 7px; }
.inline-field { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); white-space: nowrap; }

/* ---- play --------------------------------------------------------------- */
.play-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.side .card + .card { margin-top: 16px; }
.setup { padding: 26px 28px; }
.setup .lede { margin-bottom: 22px; }
.op-row { display: grid; grid-template-columns: 136px 1fr; align-items: center; gap: 12px; min-height: 58px; padding: 10px 0; border-top: 1px solid var(--border); }
.op-row .check span { font-weight: 500; }
.range { display: flex; align-items: center; gap: 5px; color: var(--ink-2); white-space: nowrap; }
.range input[type="number"] { width: 52px; }
.rg { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.field-row { display: grid; grid-template-columns: 136px auto; align-items: center; gap: 12px; padding: 16px 0 22px; border-top: 1px solid var(--border); }
.field-row label { font-weight: 500; }
.field-row select { justify-self: start; min-width: 160px; }

.record { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.mini-label { font-size: 12px; color: var(--muted); }
.mini-value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.spark { color: var(--series-1); }
.spark svg { display: block; }
.focus-list { list-style: none; padding: 0; margin: 4px 0 14px; }
.focus-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.focus-list li:first-child { border-top: 0; }
.focus-list .name { flex: 1; min-width: 0; }
.focus-list .num { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.empty-note { color: var(--ink-2); }

/* ---- op badge ----------------------------------------------------------- */
.op {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 13px;
}

/* ---- game --------------------------------------------------------------- */
.game { height: 100vh; height: 100dvh; display: none; flex-direction: column; background: var(--page); }
.game.active { display: flex; }
.banner {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 28px; font-size: 18px; color: var(--ink-2);
  font-variant-numeric: tabular-nums; background: var(--surface); border-bottom: 1px solid var(--border);
}
.game-label { font-size: 14px; color: var(--accent-text); }
.timebar { height: 3px; background: var(--grid); }
.timebar span { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.arena { flex: 1; display: grid; place-items: center; padding-bottom: 6vh; }
.problem { display: flex; align-items: center; gap: 22px; font-size: 64px; font-weight: 500; letter-spacing: -0.01em; }
.problem .eq { color: var(--muted); }
#answer {
  width: 4.4ch; height: 1.5em; padding: 0 16px;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 2px solid var(--axis); border-radius: 14px; outline: none;
  font-variant-numeric: tabular-nums;
}
#answer:focus { border-color: var(--accent); }
#answer.wrong { border-color: var(--bad); background: var(--bad-wash); }
.game-hint { text-align: center; color: var(--muted); padding-bottom: 26px; }

/* ---- results ------------------------------------------------------------ */
.hero-card { padding: 26px 28px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 22px; }
.hero-label { color: var(--ink-2); font-weight: 500; }
.hero-row { display: flex; align-items: center; gap: 14px; }
.hero { font-size: 84px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero-sub { color: var(--ink-2); margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--accent-wash); color: var(--accent-text);
}
.res-cols { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 16px; margin-top: 16px; align-items: start; }
.res-cols .card + .card { margin-top: 0; }

.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.plist li:first-child { border-top: 0; padding-top: 0; }
.plist .q { font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plist .detail { color: var(--ink-2); font-size: 13px; flex: 1; min-width: 0; }
.plist .t { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; margin-left: auto; }
.typed { color: var(--bad); font-variant-numeric: tabular-nums; }

/* ---- stat tiles --------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12.5px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.tile .note { font-size: 12px; color: var(--muted); }
.tiles.compact { grid-template-columns: repeat(2, minmax(130px, 1fr)); margin: 0; }
.tiles.compact .tile { box-shadow: none; background: var(--page); padding: 10px 14px; }
.tiles.compact .value { font-size: 20px; }

/* ---- charts ------------------------------------------------------------- */
.chart { position: relative; min-height: 220px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-size: 13px; font-weight: 600; }
.chart .note-label { fill: var(--ink-2); font-size: 12px; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hover-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  padding: 8px 11px; border-radius: 8px; font-size: 12.5px; line-height: 1.45;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
}
.tip b { font-weight: 600; }
.tip .tmuted { color: var(--ink-2); }

/* ---- category table ----------------------------------------------------- */
table.cats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cats th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 0 8px 8px; }
.cats th.num, .cats td.num { text-align: right; }
.cats td { padding: 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.cats td:first-child, .cats th:first-child { padding-left: 0; }
.cats td:last-child, .cats th:last-child { padding-right: 0; text-align: right; }
.cats .who { display: flex; align-items: center; gap: 10px; }
.cats .ex { color: var(--muted); font-size: 12.5px; }
.cats tr.thin td { color: var(--muted); }
.cats tr.thin .op { opacity: 0.6; }
.costcell { width: 34%; }
.cost { display: flex; align-items: center; gap: 10px; }
.track { position: relative; flex: 1; height: 10px; }
.track .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; }
.track .avg { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--ink-2); }
.cats tr.thin .fill { opacity: 0.35; }
.cost .v { width: 44px; text-align: right; font-weight: 600; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border-strong); border-radius: 999px; padding: 0 6px; margin-left: 6px; }
.more-row { margin-top: 10px; }

/* ---- heat map ----------------------------------------------------------- */
.stats-cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.stats-cols .card + .card { margin-top: 0; }
.stats-cols + .card { margin-top: 16px; }
.hm { display: grid; grid-template-columns: 44px repeat(4, 1fr); gap: 2px; font-variant-numeric: tabular-nums; }
.hm .colh { font-size: 12px; color: var(--ink-2); text-align: center; padding-bottom: 6px; line-height: 1.25; }
.hm .colh small { display: block; color: var(--muted); font-size: 11px; }
.hm .rowh {
  border: 0; background: none; cursor: pointer; text-align: right; padding: 0 10px 0 0;
  color: var(--ink-2); font-weight: 600; font-size: 13px; border-radius: 6px;
}
.hm .rowh:hover { color: var(--accent-text); }
.hm-cell {
  display: grid; place-items: center;
  height: 30px; border: 0; border-radius: 4px; cursor: pointer;
  font-size: 12.5px; font-weight: 600;
}
.hm-cell:hover { outline: 2px solid var(--ink); outline-offset: -2px; }
.hm-cell.thin { opacity: 0.5; }
.hm-cell.hm-none { background: var(--surface-2); color: var(--muted); cursor: default; font-weight: 400; }
.hm-cell.hm-none:hover { outline: 0; }
.legend { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend .ramp { flex: 0 0 160px; height: 10px; border-radius: 3px; }

/* ---- mistake bars ------------------------------------------------------- */
.mk { list-style: none; margin: 0; padding: 0; }
.mk li { padding: 9px 0; border-top: 1px solid var(--border); }
.mk li:first-child { border-top: 0; padding-top: 0; }
.mk .row1 { display: flex; align-items: center; gap: 10px; }
.mk .label { width: 46%; font-weight: 500; }
.mk .track { height: 8px; }
.mk .n { width: 34px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.mk .eg { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

/* ---- trouble ------------------------------------------------------------ */
.trouble { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 24px; }
.trouble .plist li:first-child { border-top: 1px solid var(--border); padding-top: 8px; }

/* ---- drill -------------------------------------------------------------- */
.drill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.drill-grid .card + .card { margin-top: 0; }
.drill-card { display: flex; flex-direction: column; }
.drill-card .lede { margin-bottom: 14px; }
.drill-card .grow { flex: 1; }
.drill-card .actions { margin-top: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.chip .c { color: var(--ink-2); font-size: 12px; }
button.chip { cursor: pointer; }
button.chip:hover { background: var(--surface-2); }
button.chip.on { background: var(--accent-wash); border-color: var(--accent); color: var(--accent-text); }
button.chip.on .c { color: var(--accent-text); }
.pick-group { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.pick-group:first-of-type { border-top: 0; }
.pick-group .g { font-weight: 500; padding-top: 5px; }

/* ---- misc --------------------------------------------------------------- */
.empty { text-align: center; padding: 56px 24px; color: var(--ink-2); }
.empty h2 { font-size: 18px; color: var(--ink); }
.stats-foot { display: flex; gap: 6px; justify-content: flex-end; margin-top: 20px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--page);
  font-size: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

/* ---- 80 in 8 ------------------------------------------------------------ */
.rules { list-style: none; padding: 0; margin: 6px 0 22px; }
.rules li { padding: 11px 0; border-top: 1px solid var(--border); color: var(--ink-2); }
.rules li:first-child { border-top: 0; }
.rules li b { color: var(--ink); font-weight: 600; }
.rules select { height: 30px; margin: 0 4px; }
.fine { font-size: 12.5px; color: var(--muted); margin-top: 18px; max-width: 64ch; }

.e80-stage { display: flex; flex-direction: column; align-items: center; gap: 48px; width: min(940px, 92vw); }
.e80-q { font-size: 58px; font-weight: 500; letter-spacing: -0.01em; text-align: center; }
.e80-opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: 100%; }
.e80-opt {
  position: relative; height: 88px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--axis); background: var(--surface); color: var(--ink);
  font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.e80-opt:hover { border-color: var(--accent); background: var(--accent-wash); }
.e80-opt .key { position: absolute; top: 7px; left: 11px; font-size: 12px; font-weight: 600; color: var(--muted); }
.e80-opt.good { border-color: var(--good); background: rgba(12, 163, 12, 0.12); }
.e80-opt.bad { border-color: var(--bad); background: var(--bad-wash); }
.chart .ref { stroke: var(--ink-2); stroke-width: 1; opacity: 0.55; }
.chart .ref-label { fill: var(--ink-2); font-size: 11.5px; }

.rules kbd, .game-hint kbd { margin: 0 2px; }

/* ---- sync --------------------------------------------------------------- */
.sync-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.sync-btn:hover { color: var(--ink); background: var(--surface-2); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-btn[data-state="ok"] .sync-dot, .sync-btn[data-state="idle"] .sync-dot { background: var(--good); }
.sync-btn[data-state="syncing"] .sync-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-btn[data-state="error"] .sync-dot { background: var(--bad); }
.sync-btn[data-state="error"] { color: var(--bad); }
@keyframes pulse { 50% { opacity: 0.3; } }

.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.42);
}
.modal-card {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px 24px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
}
.steps { margin: 14px 0 18px; padding-left: 20px; color: var(--ink-2); }
.steps li { margin-bottom: 8px; }
.steps a, .modal-card a { color: var(--accent-text); }
code { font: 13px ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.field { display: grid; gap: 5px; margin-bottom: 12px; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.field input {
  height: 40px; padding: 0 12px; font: 15px var(--font); color: var(--ink);
  background: var(--page); border: 1px solid var(--border-strong); border-radius: 8px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.sync-msg { margin-top: 12px; min-height: 1.4em; color: var(--ink-2); }
.sync-msg.bad { color: var(--bad); }

/* ---- game chrome for touch ---------------------------------------------- */
.banner-right { display: inline-flex; align-items: center; gap: 14px; }
.quit {
  height: 30px; padding: 0 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  border: 1px solid var(--border-strong); background: none; color: var(--ink-2);
}
.quit:hover { color: var(--ink); background: var(--surface-2); }
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  kbd, .game-hint { display: none; }
  .kbd-only { display: none; }
  .touch-only { display: inline; }
}

/* ---- phone -------------------------------------------------------------- */
@media (max-width: 700px) {
  body { font-size: 15px; }
  .topbar {
    grid-template-columns: auto 1fr auto; gap: 6px; padding: env(safe-area-inset-top) 10px 0;
    height: calc(54px + env(safe-area-inset-top));
  }
  .brand span, .theme-seg, .range-label { display: none; }
  .tabs { justify-content: center; gap: 0; }
  .tab { padding: 8px 7px; white-space: nowrap; font-size: 14px; }
  .sync-btn { padding: 0 9px; height: 32px; font-size: 12px; gap: 5px; }
  main { padding: 18px 14px calc(40px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .setup { padding: 18px 16px; }
  .play-grid, .drill-grid, .stats-cols, .res-cols { grid-template-columns: minmax(0, 1fr); }
  .op-row { grid-template-columns: 1fr; gap: 8px; }
  .range { flex-wrap: wrap; white-space: normal; gap: 6px 8px; }
  .range input[type="number"] { width: 50px; height: 36px; }
  .field-row { grid-template-columns: 1fr auto; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .filters { flex-wrap: wrap; gap: 10px; }
  .seg { max-width: 100%; overflow-x: auto; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles > .tile:last-child:nth-child(odd) { grid-column: span 2; }
  .tile .value { font-size: 22px; }
  .hero-top { flex-direction: column; }
  .hero { font-size: 68px; }
  .tiles.compact { width: 100%; }
  .trouble { grid-template-columns: minmax(0, 1fr); }
  .card-head { flex-wrap: wrap; }
  table.cats th:nth-child(2), table.cats td:nth-child(2), .cost .track { display: none; }
  .costcell { width: auto; }
  .cost .v { width: auto; }
  .cats td, .cats th { padding-left: 4px; padding-right: 4px; }
  .pick-group { grid-template-columns: 1fr; gap: 6px; }
  .hm { grid-template-columns: 30px repeat(4, minmax(0, 1fr)); }
  .hm .colh { font-size: 11px; }
  .hm .colh small { display: none; }
  .mk .label { width: 52%; }
  .stats-foot { flex-wrap: wrap; justify-content: center; }
  .plist li { flex-wrap: wrap; }

  .banner { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; font-size: 15px; }
  .game-label { display: none; }
  .arena { place-items: start center; padding: 8vh 14px 0; }
  .problem { flex-direction: column; gap: 16px; font-size: 46px; }
  .problem .eq { display: none; }
  #answer { width: 5ch; text-align: center; }
  .e80-stage { gap: 30px; }
  .e80-q { font-size: 40px; }
  .e80-opts { grid-template-columns: 1fr 1fr; gap: 10px; }
  .e80-opt { height: 78px; font-size: 25px; }
  .modal-card { padding: 18px 16px; }
}

/* ---- goals -------------------------------------------------------------- */
.goal { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.goal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.goal-edit { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.goal-edit input[type="number"] { width: 56px; height: 28px; }
.goal-track { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.goal-track span { display: block; height: 100%; background: var(--good); border-radius: 0 4px 4px 0; }
.chart .ref.goal { stroke: var(--good); opacity: 0.9; }

/* ---- manage data -------------------------------------------------------- */
.modal-card.wide { width: min(720px, 100%); }
.game-list { max-height: 46vh; overflow-y: auto; }
.game-list li { align-items: center; }
.game-list .q { font-weight: 500; font-size: 13px; min-width: 120px; }
.btn.danger-solid { background: var(--bad); border-color: transparent; color: #fff; }
.btn.danger-solid:hover { background: var(--bad); filter: brightness(0.92); }

/* ---- smart drill stats ---------------------------------------------------- */
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tiles.four .tile { box-shadow: none; background: var(--page); }
.mini-h { font-size: 14px; font-weight: 600; margin: 18px 0 8px; }
.better { color: var(--good); font-weight: 600; }
.worse { color: var(--bad); font-weight: 600; }
.tag.live { color: var(--accent-text); border-color: var(--accent); margin-left: 0; }
.tag.done { color: var(--good); border-color: var(--good); margin-left: 0; }
@media (max-width: 700px) { .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- undo / history ----------------------------------------------------- */
.undo-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; margin-bottom: 14px; border-radius: 10px;
  background: var(--accent-wash); color: var(--ink); font-weight: 500;
}
.game-list.history { max-height: 30vh; }

/* ---- notices, footer, what's new ---------------------------------------- */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px; padding: 10px 14px; border-radius: 10px;
  background: var(--accent-wash); border: 1px solid var(--accent); color: var(--ink);
}
.notice a { color: var(--accent-text); font-weight: 600; }
.app-foot { margin-top: 36px; text-align: center; font-size: 12.5px; color: var(--muted); }
.app-foot .btn.link { font-size: 12.5px; height: auto; }
.changes { margin: 0 0 14px; padding-left: 20px; color: var(--ink-2); }
.changes li { margin-bottom: 4px; }

/* ---- round options, countdown, hurry, keypad ------------------------------ */
.field-row.tight { padding: 8px 0; }
.field-row.tight + .field-row.tight { border-top: 0; }
.field-row.tight:last-of-type { padding-bottom: 22px; }
.countdown {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: color-mix(in srgb, var(--page) 82%, transparent); pointer-events: none;
}
.countdown span { font-size: 120px; font-weight: 700; color: var(--accent); animation: pop 0.7s ease-out infinite; }
@keyframes pop { from { transform: scale(1.25); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .countdown span { animation: none; } }
.hurry #secondsLeft, .hurry #e80Time { color: var(--bad); font-weight: 600; }
.hurry .timebar span { background: var(--bad); }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  width: min(420px, 100%); margin: 0 auto; padding: 0 14px calc(14px + env(safe-area-inset-bottom));
}
.keypad button {
  height: 62px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: 600 26px var(--font);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
}
.keypad button:active { background: var(--accent-wash); border-color: var(--accent); }
.keypad button.fn { background: var(--surface-2); color: var(--ink-2); font-size: 22px; }
#answer[readonly] { caret-color: transparent; }
@media (max-width: 700px) { .keypad button { height: 58px; } }

/* ---- results delta ------------------------------------------------------ */
.hero-delta { margin-top: 4px; color: var(--ink-2); }
.hero-delta:empty { display: none; }

/* ---- phone: tabs move to a bottom bar ------------------------------------ */
@media (max-width: 700px) {
  .topbar { grid-template-columns: 1fr auto; }
  .brand span { display: inline; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tab { padding: 10px 4px; font-size: 13.5px; text-align: center; border-radius: 10px; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (max-width: 700px) {
  .field-row, .field-row.tight { grid-template-columns: 104px minmax(0, 1fr); }
  .field-row select { width: 100%; min-width: 0; }
}

/* ---- account ------------------------------------------------------------ */
.btn.google { width: 100%; height: 46px; gap: 10px; font-size: 15px; margin-top: 4px; }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--muted); font-size: 12.5px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
