/* Math Flash — the screen.
   Layout note: every overlay is positioned against #main, NOT the viewport
   (R-C2). An overlay fixed to the viewport covers #hdr, and a header behind a
   scrim is a home button that does not exist. */

:root {
  --bg: #0f1a24;
  --panel: #172635;
  --panel2: #1e3244;
  --line: #2b4256;
  --ink: #e8f1f8;
  --dim: #9db3c5;
  --accent: #ffb454;
  --accent-ink: #2a1c05;
  --ok: #34d399;
  --bad: #f87171;
  --unseen: #2b3d4f;
  --learning: #e9973f;
  --fast: #2fae7e;
  --pad: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  /* R-C15: the page itself never scrolls. Every scrolling region is an inner
     one with its own overflow, so a rubber-band drag cannot pull the header
     and the pad off screen mid-answer. */
  overflow: hidden;
}
body {
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- header ---------- */
#hdr {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.iconbtn {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
  background: transparent; color: var(--ink);
  border: 0; border-radius: 12px; cursor: pointer;
}
.iconbtn:active { background: var(--panel2); }
#statusLbl { margin-left: auto; font-size: 15px; font-weight: 700; color: var(--dim); font-variant-numeric: tabular-nums; }
#tallyLbl { font-size: 15px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }

/* ---------- the content region ---------- */
#main {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: var(--pad);
  padding: var(--pad); overflow: hidden;
}

/* ---------- the card ---------- */
#stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 12px;
}
#opTag {
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--dim);
}
#prompt {
  font-size: clamp(38px, 13vw, 72px); font-weight: 800; line-height: 1.05;
  font-variant-numeric: tabular-nums; text-align: center;
}
#entry {
  min-height: 54px; min-width: 130px;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  padding: 4px 16px;
  background: var(--panel2); border: 2px solid var(--line); border-radius: 14px;
  font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums;
}
#entry.right { border-color: var(--ok); color: var(--ok); }
#entry.slow { border-color: var(--learning); color: var(--learning); }
#entry.wrong { border-color: var(--bad); color: var(--bad); }
#caret { width: 3px; height: 30px; background: var(--accent); border-radius: 2px; animation: blink 1s steps(1) infinite; }
#entry.right #caret, #entry.slow #caret, #entry.wrong #caret { display: none; }
@keyframes blink { 50% { opacity: 0; } }
#verdict { font-size: 16px; font-weight: 700; min-height: 22px; color: var(--dim); text-align: center; }
#verdict.right { color: var(--ok); }
#verdict.wrong { color: var(--bad); }
#verdict.slow { color: var(--accent); }

/* ---------- break it down ---------- */
/* Deliberately quiet. R30c: if working it out is the better screen, children
   will answer slowly on purpose and the latency data — which is the whole
   product — rots. The celebration stays on the fast path. */
#deriveLead { font-size: 15px; color: var(--dim); text-align: center; min-height: 0; }
#chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  min-height: 44px; padding: 0 16px;
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--panel2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.chip.on { border-color: var(--accent); color: var(--accent); }
#afterRow { display: flex; gap: 8px; justify-content: center; }
.softbtn.sm { min-height: 44px; padding: 0 14px; font-size: 15px; flex: 0 1 auto; }
#stepTag { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--dim); }

/* ---------- the pad ---------- */
#pad {
  flex: none;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.key {
  min-height: 56px;
  font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 14px; cursor: pointer;
}
.key:active { background: var(--line); }
.key.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.key.wide { font-size: 22px; }
.key[disabled] { opacity: .45; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: none; flex-direction: column; align-items: stretch; gap: 10px;
  padding: 16px; overflow: auto;
  background: var(--bg);
}
.overlay.show { display: flex; }
.overlay h1 { margin: 4px 0 0; font-size: 30px; text-align: center; }
.overlay h2 { margin: 4px 0 0; font-size: 24px; text-align: center; }
.sub { color: var(--dim); font-size: 15px; line-height: 1.45; text-align: center; }
.blurb { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.4; text-align: center; }
.best { color: var(--accent); font-weight: 700; text-align: center; font-size: 15px; font-variant-numeric: tabular-nums; min-height: 20px; }

.bigbtn, .softbtn {
  min-height: 52px; font-size: 18px; font-weight: 700;
  border-radius: 14px; cursor: pointer; border: 1px solid var(--line);
}
.bigbtn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.softbtn { background: var(--panel2); color: var(--ink); }

.rules { margin: 0; padding-left: 20px; color: var(--ink); font-size: 15px; line-height: 1.5; }
.rules li { margin-bottom: 8px; }

/* ---------- mode cards ---------- */
#modeRow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modeCard {
  min-height: 96px; padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--line); border-radius: 16px; cursor: pointer;
  font-size: 17px; font-weight: 700;
}
.modeCard.sel { border-color: var(--accent); background: var(--panel2); }
.modeCard .me { font-size: 26px; }
.modeCard small { font-weight: 500; font-size: 12px; color: var(--dim); }

/* ---------- ⚙️ Settings ---------- */
#custom {
  flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px 12px 10px;
}
#custom > summary {
  min-height: 44px; display: flex; align-items: center;
  font-size: 16px; font-weight: 700; cursor: pointer; list-style: none;
}
#custom > summary::-webkit-details-marker { display: none; }
/* LABEL ABOVE, NOT BESIDE. A 72px label leaves 237px for the control, and the
   five range stops need 244 — so the last one wrapped onto a row of its own and
   read as a separate, wider control rather than the fifth of five. Stacking
   gives every row the panel's full 319px and nothing wraps. */
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.lbl { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1 1 0; min-width: 44px; min-height: 44px;
  font-size: 16px; font-weight: 700;
  background: var(--panel2); color: var(--dim);
  border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg button.locked { opacity: .75; }

/* ---------- results ---------- */
.tallyRow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tally {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 6px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
}
.tally b { font-size: 30px; font-variant-numeric: tabular-nums; }
.tally span { font-size: 12px; color: var(--dim); }
.tally.fast b { color: var(--fast); }
.tally.slow b { color: var(--learning); }
.tally.missed b { color: var(--bad); }

/* ---------- the mastery map ---------- */
#mapWrap { flex: 0 1 auto; min-height: 0; overflow: auto; }
#mapGrid { display: grid; gap: 2px; margin: 0 auto; width: max-content; }
.cell { width: 16px; height: 16px; border-radius: 3px; background: var(--unseen); }
.cell.unseen { background: var(--unseen); }
.cell.learning { background: var(--learning); }
.cell.fast { background: var(--fast); }
.cell.gone { background: transparent; }
.cell.hd { width: 16px; height: 16px; background: transparent; color: var(--dim); font-size: 9px; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.legend { display: flex; justify-content: center; gap: 14px; font-size: 12px; color: var(--dim); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; background: var(--unseen); }
.sw.unseen { background: var(--unseen); }
.sw.learning { background: var(--learning); }
.sw.fast { background: var(--fast); }

/* ---------- footer ---------- */
#footer { flex: none; min-height: 34px; display: flex; align-items: center; padding: 0 8px; }
#gameBar { display: flex; gap: 6px; }
