/* Number–Letter Trainer — single stylesheet.
   Dark by default, light on request, built for one-handed portrait use on a
   phone and for mouse + keyboard on a desktop. */

:root {
  color-scheme: dark;
  --bg: #0a0e1a;
  --bg-grad: radial-gradient(120% 80% at 50% -10%, #16203c 0%, #0a0e1a 55%);
  --surface: #141a2e;
  --surface-2: #1c2540;
  --surface-3: #2a3557;
  --line: #28314f;
  --text: #eaeefb;
  --muted: #8f9bc0;
  --faint: #616e95;
  --accent: #7b96ff;
  --accent-ink: #0a0e1a;
  --good: #2fd38a;
  --good-dim: #10452f;
  --bad: #ff5c72;
  --bad-dim: #4c1420;
  --warn: #ffb02e;
  --radius: 14px;
  --radius-lg: 20px;
  --text-scale: 1;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --speed: 130ms;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fc;
  --bg-grad: radial-gradient(120% 80% at 50% -10%, #e3e9ff 0%, #f4f6fc 55%);
  --surface: #ffffff;
  --surface-2: #eef1fa;
  --surface-3: #e2e7f6;
  --line: #d7deef;
  --text: #121729;
  --muted: #5b668a;
  --faint: #8691b0;
  --accent: #3a5bd9;
  --accent-ink: #ffffff;
  --good: #0f9f63;
  --good-dim: #d6f5e6;
  --bad: #d9304a;
  --bad-dim: #fde0e5;
  --warn: #b97400;
  --shadow: 0 8px 24px rgba(20, 30, 70, .10);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6fc;
    --bg-grad: radial-gradient(120% 80% at 50% -10%, #e3e9ff 0%, #f4f6fc 55%);
    --surface: #ffffff;
    --surface-2: #eef1fa;
    --surface-3: #e2e7f6;
    --line: #d7deef;
    --text: #121729;
    --muted: #5b668a;
    --faint: #8691b0;
    --accent: #3a5bd9;
    --accent-ink: #ffffff;
    --good: #0f9f63;
    --good-dim: #d6f5e6;
    --bad: #d9304a;
    --bad-dim: #fde0e5;
    --warn: #b97400;
    --shadow: 0 8px 24px rgba(20, 30, 70, .10);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, sans-serif;
  font-size: calc(16px * var(--text-scale));
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; }

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  cursor: pointer;
  border: 0;
  background: none;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
.reduce-motion * { transition-duration: .001ms !important; animation-duration: .001ms !important; }

/* ------------------------------------------------------------------ layout */

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 8px;
  background: linear-gradient(var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}

.topbar h1 { font-size: 1.05em; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 1.1em;
  background: var(--surface);
  border: 1px solid var(--line);
}
.iconbtn:active { background: var(--surface-2); }

.scroll { flex: 1; padding-bottom: 24px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .82em; }
.tiny { font-size: .74em; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
h2.section { font-size: .78em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
h2.section:first-child { margin-top: 4px; }

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 1em;
  transition: transform var(--speed) ease, background var(--speed) ease;
}
.btn:active { transform: scale(.975); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.seg { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: var(--radius); border: 1px solid var(--line); }
.seg button {
  flex: 1; min-height: 44px; border-radius: 10px; font-size: .88em; font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* A scrolling chip row, for when there are too many options to squeeze in. */
.seg.chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.seg.chips::-webkit-scrollbar { display: none; }
.seg.chips button { flex: 0 0 auto; min-width: 68px; padding: 0 14px; white-space: nowrap; }

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

.hero { padding: 6px 2px 14px; }
.hero .title { font-size: 1.6em; font-weight: 750; letter-spacing: -.02em; margin: 0; }
.hero .tag { color: var(--muted); margin: 2px 0 0; }

.statstrip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.statstrip .cell { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.statstrip .k { font-size: .7em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.statstrip .v { font-size: 1.3em; font-weight: 700; }

.modelist { display: flex; flex-direction: column; gap: 10px; }
.modecard {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 14px 16px; text-align: left;
  transition: transform var(--speed) ease, border-color var(--speed) ease;
}
.modecard:active { transform: scale(.99); border-color: var(--accent); }
.modecard .badge {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 13px;
  display: grid; place-items: center; font-weight: 750; font-size: 1.05em;
  background: var(--surface-2); color: var(--accent);
}
.modecard .name { font-weight: 650; }
.modecard .desc { color: var(--muted); font-size: .84em; }
.modecard .chev { color: var(--faint); font-size: 1.2em; }
.modecard.feature { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.modecard.feature .badge { background: var(--accent); color: var(--accent-ink); }

/* -------------------------------------------------------------- drill stage */

.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.drillbar { display: flex; gap: 8px; align-items: center; padding: 2px 0 10px; }
.chip {
  padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: .76em; font-weight: 650; color: var(--muted); white-space: nowrap;
}
.chip.strong { color: var(--text); }
.chip.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }

.progressline { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 10px; }
.progressline i { display: block; height: 100%; background: var(--accent); transition: width var(--speed) linear; }
.progressline.urgent i { background: var(--bad); }

.qcard {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 190px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  transition: border-color var(--speed) ease, background var(--speed) ease;
}
.qcard .ask { font-size: .78em; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.qcard .prompt {
  font-size: clamp(68px, 23vw, 128px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.qcard .answerline { min-height: 1.6em; font-size: 1.05em; font-weight: 600; }
.qcard .entry { font-size: 2em; font-weight: 750; letter-spacing: .04em; font-variant-numeric: tabular-nums; min-height: 1.2em; }
.qcard.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.qcard.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.qcard .verdict.good { color: var(--good); }
.qcard .verdict.bad { color: var(--bad); }

/* ---------------------------------------------------------------- keypads */

.pad { padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.letterpad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.letterpad .key:nth-child(25), .letterpad .key:nth-child(26) { grid-column: span 3; }

.numberpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.key {
  display: grid; place-items: center;
  min-height: 52px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 1.22em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: transform 90ms ease, background 90ms ease;
}
.key:active { transform: scale(.94); background: var(--accent); color: var(--accent-ink); }
.key.wide { grid-column: span 2; }
.key.go { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.key.util { font-size: .95em; font-weight: 600; color: var(--muted); background: var(--surface); }
.key[disabled] { opacity: .3; pointer-events: none; }
.numberpad .key { min-height: 58px; font-size: 1.4em; }

.nativeinput {
  width: 100%; min-height: 60px; text-align: center;
  font-size: 1.8em; font-weight: 750; letter-spacing: .1em;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px;
}

.padhint { color: var(--faint); font-size: .76em; text-align: center; }

/* ---------------------------------------------------------- learn / grids */

.learngrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.tile {
  position: relative;
  min-height: 72px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: transform 90ms ease, border-color 90ms ease, background 90ms ease;
}
.tile:active { transform: scale(.96); }
.tile .big { font-size: 1.55em; font-weight: 780; line-height: 1; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .8em; font-weight: 650; color: var(--muted); min-height: 1.2em; }
.tile.revealed { background: var(--surface-2); border-color: var(--accent); }
.tile.revealed .sub { color: var(--accent); }
.tile.anchor::after {
  content: ""; position: absolute; top: 6px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--warn);
}
.tile.dim { opacity: .38; }

.masterygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; }
.mcell {
  min-height: 56px; border-radius: 12px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface);
}
.mcell .l { font-size: 1.2em; font-weight: 780; line-height: 1.05; }
.mcell .n { font-size: .68em; color: var(--muted); font-variant-numeric: tabular-nums; }
.mcell.mastered { background: color-mix(in srgb, var(--good) 24%, var(--surface)); border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.mcell.developing { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.mcell.weak { background: color-mix(in srgb, var(--bad) 22%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 52%, var(--line)); }
.mcell.untested { opacity: .6; }
.mcell[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .76em; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.mastered { background: var(--good); }
.legend i.developing { background: var(--warn); }
.legend i.weak { background: var(--bad); }
.legend i.untested { background: var(--surface-3); }

/* --------------------------------------------------------------- dashboard */

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { font-size: .7em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi .v { font-size: 1.45em; font-weight: 750; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: .74em; color: var(--faint); }

.listrow { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.listrow:last-child { border-bottom: 0; }
.listrow .pair { width: 54px; font-weight: 700; font-variant-numeric: tabular-nums; }
.listrow .bar { flex: 1; height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.listrow .bar i { display: block; height: 100%; background: var(--bad); }
.listrow .num { width: 66px; text-align: right; font-size: .85em; color: var(--muted); font-variant-numeric: tabular-nums; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.spark i { flex: 1; min-width: 4px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.spark i.empty { background: var(--surface-2); }

.streakwrap { display: flex; align-items: center; gap: 14px; }
.streaknum { font-size: 2.2em; font-weight: 800; line-height: 1; }

/* ------------------------------------------------------------------ memory */

.seqrow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.seqchip {
  min-width: 56px; min-height: 68px; padding: 6px 10px;
  border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 1.9em; font-weight: 780; font-variant-numeric: tabular-nums;
}
.slotrow { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; }
.slot {
  min-width: 46px; min-height: 58px; border-radius: 12px;
  border: 2px dashed var(--line); background: var(--surface);
  display: grid; place-items: center;
  font-size: 1.5em; font-weight: 750; font-variant-numeric: tabular-nums;
}
.slot.filled { border-style: solid; border-color: var(--accent); background: var(--surface-2); }
.slot.active { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.slot.ok { border-color: var(--good); color: var(--good); border-style: solid; }
.slot.no { border-color: var(--bad); color: var(--bad); border-style: solid; }

/* ---------------------------------------------------------------- overlays */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 24px;
}
.overlay .panel {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow);
}
.overlay .panel h3 { margin: 0 0 6px; font-size: 1.15em; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 999px; padding: 10px 16px; font-size: .88em; max-width: calc(100% - 28px);
}
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

.pbbanner {
  background: linear-gradient(135deg, color-mix(in srgb, var(--warn) 30%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: var(--radius); padding: 12px 14px; font-weight: 650;
}

/* ----------------------------------------------------------------- settings */

.settingrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.settingrow:last-child { border-bottom: 0; }
.settingrow .label { flex: 1; }
.settingrow .label .n { font-weight: 600; }
.settingrow .label .d { font-size: .78em; color: var(--muted); }

.switch {
  position: relative; width: 52px; height: 32px; flex: 0 0 auto;
  border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line);
  transition: background var(--speed) ease;
}
/* The track stays small; the tap target is a comfortable 48px tall. */
.switch::before { content: ""; position: absolute; inset: -8px -6px; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--text); transition: transform var(--speed) ease;
}
.switch[aria-pressed="true"] { background: var(--accent); border-color: transparent; }
.switch[aria-pressed="true"]::after { transform: translateX(20px); background: #fff; }
.switch:active::after { width: 28px; }

.filepick { display: none; }

/* ----------------------------------------------------------------- desktop */

@media (min-width: 760px) and (pointer: fine) {
  .screen { max-width: 620px; }
  .qcard { min-height: 240px; }
  .key:hover { background: var(--surface-3); }
  .modecard:hover { border-color: var(--accent); }
  .tile:hover { border-color: var(--accent); }
}

@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
