/* Math — one stylesheet, no framework.
   Same family as the other apps (dark, high contrast, big type) in indigo on
   slate, so it is easy to tell apart on a home screen full of them.

   The register matters here more than usual. He is 13 and behind on his
   tables, which means he has met a lot of math software designed for an
   8-year-old. Nothing in this file is cartoonish: no rockets, no stickers, no
   bouncing praise. It should read like a stopwatch app, because the only
   scoreboard the app has is his own time coming down. */

:root {
  --bg: #0f172a;
  --card: #1b2540;
  --card-2: #243050;
  --line: #334166;
  --text: #eef2ff;
  --muted: #9aa8c7;
  --accent: #6366f1;
  --accent-2: #4338ca;
  --good: #22c55e;
  --bad: #f87171;
  --warn: #fbbf24;
  --unseen: #44507a;
  --radius: 14px;
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 13px; }
.center { text-align: center; }

/* ---- login ---- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card .logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-radius: 18px; font-size: 34px; font-weight: 800; color: #fff;
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card form { margin-top: 20px; display: grid; gap: 10px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ---- inputs ---- */

input, textarea, select {
  width: 100%; padding: 13px 14px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 13px 16px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #fff; border: 0; border-radius: 11px;
  font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
button:disabled { opacity: .55; }
button.secondary { background: var(--card); border: 1px solid var(--line); color: var(--text); }
button.small { padding: 9px 13px; font-size: 14px; }
button.wide { display: block; width: calc(100% - 32px); margin: 12px 16px 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- the frame: top bar, a feature's tabs, the screen ---- */

#app { min-height: 100vh; }
#screen { max-width: 760px; margin: 0 auto; padding-bottom: calc(env(safe-area-inset-bottom) + 40px); }

.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 12px 10px;
  border-bottom: 1px solid var(--line);
}
/* Explicit columns: a hidden Back button mustn't pull the title to the left. */
#back { grid-column: 1; justify-self: start; }
.topbar-title { grid-column: 2; font-size: 19px; font-weight: 700; text-align: center; }
#gear { grid-column: 3; justify-self: end; }
.topbar-btn {
  white-space: nowrap;
  background: none; border: 0; color: var(--accent); padding: 8px 6px;
  font-size: 16px; font-weight: 600; border-radius: 8px;
}

.tabs {
  display: flex; justify-content: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.tab {
  padding: 9px 16px; border-radius: 99px; font-size: 15px; font-weight: 600;
  color: var(--muted); text-decoration: none; background: var(--card);
  border: 1px solid var(--line);
}
.tab.active { color: var(--text); background: rgba(139, 92, 246, .22); border-color: var(--accent); }

/* A flashcard round: nothing but the card. */
body.focus .topbar, body.focus .tabs { display: none; }

/* ---- shared pieces ---- */

.section-label {
  padding: 20px 16px 8px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
}
.card {
  margin: 12px 16px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.pad { padding: 0 16px; }
.empty { color: var(--muted); text-align: center; padding: 26px 16px; font-size: 15px; }
.msg { min-height: 20px; font-size: 14px; padding: 6px 16px 0; }
.card .msg, .sec-body .msg { padding: 0; }
.msg.ok { color: var(--good); }
.msg.bad { color: var(--bad); }
.item-meta { font-size: 13px; color: var(--muted); }

.sec { margin: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sec-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: none; border: 0; padding: 15px 16px; color: var(--text); font-size: 17px; font-weight: 700;
  text-align: left; border-radius: 0;
}
.sec-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sec-meta { font-size: 14px; font-weight: 500; color: var(--muted); }
.sec-chevron { transition: transform .2s; color: var(--muted); font-size: 20px; }
/* Child combinators, not descendant: an open section must not open every
   section inside it (SpellingApp learned this the hard way). */
.sec.open > .sec-head .sec-chevron { transform: rotate(90deg); }
.sec-body { display: none; padding: 0 16px 16px; gap: 10px; grid-template-columns: 1fr; }
.sec.open > .sec-body { display: grid; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 14px; font-size: 15px; font-weight: 600;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 99px;
}
.chip.on { background: rgba(139, 92, 246, .22); border-color: var(--accent); color: var(--text); }
.chip-meta { margin-left: 8px; font-weight: 500; font-size: 13px; opacity: .8; }

.bar { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s; }
.bar-fill.full { background: var(--good); }

.stack { display: flex; height: 12px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.stack-part { height: 100%; }
.stack-part.fast { background: var(--good); }
.stack-part.slow { background: var(--warn); }
.stack-part.wrong { background: var(--bad); }
.stack-part.new { background: var(--unseen); }

.tag {
  display: inline-block; padding: 3px 10px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted);
}

/* ---- home ---- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; padding: 18px 16px; }
.tile {
  display: grid; gap: 8px; align-content: start; padding: 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  color: var(--text); text-decoration: none;
}
.tile-emoji { font-size: 38px; line-height: 1; }
.tile-name { font-size: 23px; font-weight: 800; }
.tile-blurb { font-size: 15px; color: var(--muted); line-height: 1.4; }
.tile-line { font-size: 14px; margin-top: 4px; }
.tile-line.bad { color: var(--bad); }


/* ---- menus: choosing what to practise ---- */

.menu { padding: 16px; display: grid; gap: 4px; }
.lede { margin: 0 0 8px; font-size: 16px; color: var(--muted); line-height: 1.45; }
.menu-h {
  margin: 16px 0 8px; font-size: 13px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  flex: 1 1 auto; min-width: 72px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 10px;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 20px; font-weight: 700;
}
.chip.on { background: rgba(99, 102, 241, .22); border-color: var(--accent); color: var(--text); }
.chip-sub { font-size: 12px; font-weight: 500; opacity: .85; letter-spacing: 0; }

button.wide { width: 100%; }
button.big { padding: 17px; font-size: 18px; margin-top: 18px; }
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
button.linkish {
  background: none; border: 0; color: var(--muted);
  padding: 4px 0; font-size: 15px; font-weight: 600; text-align: left;
}

/* ---- where each operation stands ---- */

.op-list { display: grid; gap: 10px; }
.op-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.op-symbol { font-size: 26px; font-weight: 800; width: 28px; text-align: center; color: var(--accent); }
.op-mid { flex: 1; display: grid; gap: 6px; min-width: 0; }
.op-name { font-size: 16px; font-weight: 700; }
.op-note { font-size: 13px; color: var(--muted); }

/* ---- the runner: one question, a keypad, a verdict ---- */

/* Every row above the keypad has a FIXED height, so the keypad cannot move
   while he is working (Luke, 2026-11-06: "it should stay in place the entire
   time and not move").

   The bug this fixes: .runner-answer was min-height, and the empty-state
   placeholder made it 99px tall against 48px once digits were in it — a 51px
   jump on every single question, which pushed the keypad down and back up
   under his thumb. Heights here are fixed, never min-, and nothing between
   the prompt and the pad may grow.

   dvh as well as vh because mobile Safari's toolbar changes vh as it hides,
   which would move the keypad for a different reason. */
.runner {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-width: 460px; margin: 0 auto;
}
.runner-head { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.runner-progress { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.runner-stop {
  padding: 7px 14px; font-size: 14px;
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
}
.runner-bar { width: 100%; height: 4px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.runner-bar-fill { height: 100%; background: var(--accent); transition: width .2s; }

/* The question. Big enough that nothing else on the screen competes with it. */
.runner-prompt {
  margin-top: clamp(10px, 4vh, 36px);
  height: clamp(50px, 15vw, 78px);
  display: flex; align-items: center;
  font-size: clamp(44px, 14vw, 72px); font-weight: 800;
  letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1;
}
/* Fixed height and centred, so an empty box, a typed number and a struck-out
   wrong answer all occupy exactly the same space. */
.runner-answer {
  height: clamp(52px, 13vw, 64px);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(38px, 11vw, 54px); font-weight: 700;
  color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1;
}
/* A caret of the same height as a digit, so it displaces nothing. */
.runner-answer.empty::after {
  content: ''; width: .45em; height: 3px; border-radius: 2px;
  background: currentColor; opacity: .3;
}
.runner-answer.wrong { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 3px; }

.runner-verdict {
  height: 28px; display: flex; align-items: center;
  font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.runner-verdict.good { color: var(--good); }
.runner-verdict.ok { color: var(--warn); }
.runner-verdict.bad { color: var(--bad); }

/* The strategy line. The whole reason it is here rather than just the answer:
   drill alone gets accuracy, drill plus the method gets it to stick. */
.runner-hint { width: 100%; min-height: 0; display: grid; gap: 10px; }
.runner-hint.shown {
  padding: 13px 15px; background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px;
}
.hint-body { font-size: 16px; line-height: 1.5; text-align: left; }
.hint-next { padding: 11px; font-size: 16px; }

/* ---- the keypad ---- */

.keypad {
  margin-top: auto; width: 100%;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px;
}
.key {
  padding: clamp(14px, 3.4vh, 22px) 0;
  font-size: clamp(22px, 6vw, 28px); font-weight: 700;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 13px;
  font-variant-numeric: tabular-nums;
}
.key:active { background: var(--card-2); }
.key-go { background: linear-gradient(160deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.key-back { color: var(--muted); }

/* ---- after a session ---- */

.summary { padding: 20px 16px; display: grid; gap: 6px; }
.summary-title { margin: 0; font-size: 26px; font-weight: 800; text-align: center; }
.summary-h {
  margin: 20px 0 8px; font-size: 13px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.summary-actions { margin-top: 24px; display: grid; gap: 10px; }
.good-text { color: var(--good); }

.stats {
  margin: 18px 0 6px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 10px;
}
.stat {
  padding: 12px 8px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.stat-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 3px; font-size: 12px; color: var(--muted); }
.stat.big .stat-value { color: var(--accent); }
.stat.good .stat-value { color: var(--good); }
.stat.ok .stat-value { color: var(--warn); }
.stat.bad .stat-value { color: var(--bad); }

.fact-list { display: grid; gap: 7px; }
.fact-row {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  padding: 10px 13px; background: var(--card);
  border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 10px;
}
.fact-row.wrong { border-left-color: var(--bad); }
.fact-row.slow { border-left-color: var(--warn); }
.fact-prompt { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fact-typed { font-size: 13px; color: var(--bad); }
.fact-tries { font-size: 12px; color: var(--warn); font-weight: 600; font-variant-numeric: tabular-nums; }
.fact-tag {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--bg); background: var(--muted); border-radius: 4px; padding: 1px 5px;
}
.fact-ms { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fact-hint { flex-basis: 100%; font-size: 14px; color: var(--muted); line-height: 1.45; }

/* ---- the heat map ---- */

.grid-wrap { overflow-x: auto; margin: 4px -16px; padding: 0 16px; }
.heat { border-collapse: separate; border-spacing: 3px; margin: 0 auto; }
.heat-corner { font-size: 17px; font-weight: 800; color: var(--accent); }
.heat-h { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 2px; }
.heat-cell {
  width: 22px; height: 22px; min-width: 22px;
  border-radius: 5px; background: var(--unseen); cursor: pointer; padding: 0;
}
.heat-cell.fast { background: var(--good); }
.heat-cell.slow { background: var(--warn); }
.heat-cell.wrong { background: var(--bad); }
.heat-cell.new { background: var(--unseen); opacity: .45; }
.heat-cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin: 10px 0 2px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.legend-dot.fast { background: var(--good); }
.legend-dot.slow { background: var(--warn); }
.legend-dot.wrong { background: var(--bad); }
.legend-dot.new { background: var(--unseen); opacity: .45; }

.detail-slot { min-height: 54px; }
.cell-detail {
  margin-top: 10px; padding: 11px 14px; text-align: center;
  background: var(--card); border: 1px solid var(--accent); border-radius: 11px;
}
.cell-prompt { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cell-meta { margin-top: 3px; font-size: 13px; color: var(--muted); }

/* ---- reports ---- */

.report-list { display: grid; gap: 9px; padding: 0 16px; }
.report-row {
  display: grid; gap: 6px; text-align: left; width: 100%;
  padding: 13px 15px; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 500;
}
.report-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.report-when { font-size: 16px; font-weight: 700; }
.report-op { font-size: 13px; color: var(--muted); }
.report-bottom { display: flex; gap: 14px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.report-avg { margin-left: auto; }

.trend { width: 100%; max-width: 420px; display: block; margin: 0 auto; height: 120px; }
.trend-line { stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend-dot { fill: var(--accent); }
.trend-label { fill: var(--muted); font-size: 9px; font-family: inherit; }

/* ---- the speed threshold ---- */

.setting-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-row input { width: 92px; flex: 0 0 auto; }
.setting-row button { flex: 0 0 auto; padding: 11px 16px; }

/* ---- pointer devices ---- */

@media (hover: hover) {
  button:not(:disabled):hover { filter: brightness(1.12); }
  .tile:hover { border-color: var(--accent); }
  .tab:hover { color: var(--text); }
  .report-row:hover { border-color: var(--accent); }
  .heat-cell:hover { outline: 2px solid var(--text); outline-offset: 1px; }
  .topbar-btn:hover { filter: none; background: var(--card); }
  .chip:hover { border-color: var(--accent); }
}

/* A phone in portrait: the keypad has to stay reachable with a thumb, so the
   question shrinks before the keys do. */
@media (max-width: 420px) {
  .tabs { gap: 6px; padding: 9px 8px; }
  .tab { padding: 8px 12px; font-size: 14px; }
  .heat-cell { width: 20px; height: 20px; min-width: 20px; }
  .runner { gap: 8px; }
}

@media (min-width: 900px) {
  .runner { padding-top: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill, .runner-bar-fill, .sec-chevron { transition: none; }
}
