:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1d2433;
  --ink-2: #4d5566;
  --ink-3: #7b8292;
  --line: #ddd8cc;
  --accent: #2c5fa8;
  --accent-ink: #ffffff;
  --good: #1f8a5b;
  --good-soft: #d7f0e3;
  --warn: #b7791f;
  --bad: #b8453b;
  --bad-soft: #f7dedb;
  --hint-bg: #fff6dc;
  --hint-line: #ecd48f;
  /* fact status ramp: locked → new → learning → review → secure → mastered */
  --st-locked: #ebe8e0;
  --st-new: #f3d9a4;
  --st-learning: #efbd6a;
  --st-review: #b9dfc6;
  --st-secure: #6cbf8e;
  --st-mastered: #2b8a5a;
  --st-mastered-ink: #ffffff;
  --radius: 14px;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d; --surface: #1d2129; --surface-2: #262b35; --ink: #eef0f4; --ink-2: #b9bfcc; --ink-3: #8a91a0;
    --line: #333946; --accent: #6b9be0; --accent-ink: #0d1117; --good: #4cc38a; --good-soft: #17392a; --bad: #e07a70;
    --bad-soft: #3d1f1c; --hint-bg: #332c17; --hint-line: #6b5a24;
    --st-locked: #262b35; --st-new: #5c4a24; --st-learning: #8a6424; --st-review: #285c41; --st-secure: #2f8a5c; --st-mastered: #5fd39a; --st-mastered-ink: #0d1117;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100dvh; display: flex; flex-direction: column; -webkit-tap-highlight-color: transparent; }
main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px; outline: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { line-height: 1.5; margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; min-height: 56px; }
.topbar .title { font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.25; }
.topbar .tag { font-size: .75rem; color: var(--ink-3); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.back { min-height: 44px; min-width: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 0 12px; cursor: pointer; }

/* buttons */
.btn { min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { min-height: 72px; font-size: 1.25rem; padding: 0 28px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* profiles */
.profile { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; cursor: pointer; min-height: 110px; }
.profile .name { font-size: 1.3rem; font-weight: 700; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.badge.sim { background: var(--hint-bg); color: var(--warn); border: 1px solid var(--hint-line); }
form.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; color: var(--ink-2); }
input[type=text], input[type=number], select { font: inherit; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--surface); color: var(--ink); }

/* child home */
.child-home { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 20px; padding-top: 24px; }
.child-home .hello { font-size: 2rem; font-weight: 700; }
.next-up { font-size: 1.1rem; color: var(--ink-2); max-width: 480px; }
.next-up strong { color: var(--ink); }
.home-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; width: 100%; max-width: 520px; }
.home-actions .btn { min-height: 110px; font-size: 1.35rem; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.home-actions .btn small { font-weight: 400; font-size: .85rem; opacity: .85; }

/* question screen */
.play { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 520px; margin: 0 auto; }
.progress { width: 100%; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s linear; }
.progress.limit > i { background: var(--warn); transition: none; }
.qwrap { width: 100%; min-height: 168px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); padding: 16px; position: relative; }
.qwrap.flash { background: var(--good-soft); border-color: var(--good); transition: background .05s; }
.chip-new { position: absolute; top: 10px; left: 12px; font-size: .75rem; font-weight: 700; color: var(--accent); }
.question { font-size: clamp(2.6rem, 11vw, 4.2rem); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.answer { min-width: 3.5ch; min-height: 1.3em; font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 700; font-variant-numeric: tabular-nums; border-bottom: 3px solid var(--line); text-align: center; padding: 0 8px; }
.answer.wrong { color: var(--bad); border-color: var(--bad); }
.answer.wrong { animation: nudge .25s; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.hint { width: 100%; min-height: 64px; border-radius: 12px; padding: 10px 14px; font-size: 1.05rem; line-height: 1.4; display: flex; align-items: center; gap: 10px; }
.hint.on { background: var(--hint-bg); border: 1px solid var(--hint-line); }
.hint .tier { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--warn); font-weight: 700; white-space: nowrap; }
.why { font-size: .8rem; color: var(--ink-3); text-align: center; min-height: 1.2em; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 360px; touch-action: manipulation; user-select: none; }
.key { min-height: 64px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 1.7rem; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums; }
.key:active { background: var(--surface-2); transform: scale(.98); }
.key.del { font-size: 1.1rem; }
.key.blank { visibility: hidden; }
@media (min-height: 820px) { .key { min-height: 72px; } }

/* overlay (trick card) */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.overlay[hidden] { display: none; }
.trick { max-width: 440px; width: 100%; background: var(--surface); border-radius: 18px; padding: 24px; text-align: center; display: flex; flex-direction: column; gap: 16px; }
.trick .big { font-size: 1.5rem; font-weight: 700; line-height: 1.35; }

/* summary */
.summary { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; text-align: center; padding-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--ink-2); }
.facts-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.facts-list span { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-variant-numeric: tabular-nums; }

/* adult */
.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: thin; }
.tab { min-height: 44px; padding: 0 14px; border: 0; background: none; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; color: var(--ink-2); font-weight: 700; }
.tab[aria-selected=true] { color: var(--ink); border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tile .lbl { font-size: .8rem; color: var(--ink-2); display: flex; align-items: center; gap: 4px; }
.tile .val { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .78rem; color: var(--ink-3); }
.order-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.order-strip .t { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--surface); font-variant-numeric: tabular-nums; min-width: 54px; text-align: center; }
.order-strip .t b { display: block; font-size: 1rem; }
.order-strip .t span { font-size: .72rem; color: var(--ink-3); }
.order-strip .t.secure { background: var(--good-soft); border-color: var(--good); }
.order-strip .t.current { border: 2px solid var(--accent); }
.order-strip .t.locked { opacity: .55; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .map-layout { grid-template-columns: minmax(0, 1fr); } }
.heat-scroll { overflow-x: auto; }
.heat { display: grid; gap: 3px; min-width: 0; }
.heat .h { font-size: .75rem; color: var(--ink-3); display: flex; align-items: center; justify-content: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.heat .c { aspect-ratio: 1; min-width: 22px; border-radius: 5px; border: 0; background: var(--st-locked); font-size: clamp(.55rem, 1.4vw, .75rem); font-variant-numeric: tabular-nums; cursor: pointer; position: relative; padding: 0; color: var(--ink); }
.heat .c[data-mode=stage][data-s=new] { background: var(--st-new); }
.heat .c[data-mode=stage][data-s=learning] { background: var(--st-learning); }
.heat .c[data-mode=stage][data-s=review] { background: var(--st-review); }
.heat .c[data-mode=stage][data-s=secure] { background: var(--st-secure); }
.heat .c[data-mode=stage][data-s=mastered] { background: var(--st-mastered); color: var(--st-mastered-ink); }
.heat .c.flag::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); }
.heat .c.sel { outline: 3px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: .8rem; color: var(--ink-2); margin: 10px 0; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 4px; }
.detail h3 { font-size: 1.4rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; margin: 8px 0 12px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.routes { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: .875rem; }
.routes li { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.routes li.best { border-color: var(--good); background: var(--good-soft); }
.routes li.off { opacity: .6; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--ink-2); font-weight: 700; white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.section { margin-bottom: 22px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.choice input { margin-top: 4px; width: 20px; height: 20px; }
.notice { background: var(--hint-bg); border: 1px solid var(--hint-line); border-radius: 12px; padding: 10px 14px; font-size: .9rem; }
.spark { display: block; }
.empty { color: var(--ink-3); font-style: italic; }
@media (max-width: 480px) {
  main { padding: 12px 16px; }
  .home-actions .btn { min-height: 92px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* touch: 44px targets (house rule #53 / WCAG 2.5.8). The fluency map scrolls sideways inside its own box instead. */
label.row:has(input[type=checkbox]) { min-height: 44px; cursor: pointer; }
input[type=checkbox] { width: 24px; height: 24px; }
@media (pointer: coarse) {
  .heat { grid-template-columns: 28px repeat(12, 44px) !important; }
  .heat .c { min-width: 44px; }
}
.legend { row-gap: 16px; }
table.data th { padding: 10px 6px; }
.qbar { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.btn.ghost { background: transparent; color: var(--ink-2); }

/* speed ramp (dataviz validator: ordinal, one hue, PASS light on #ffffff and dark on #1d2129, 2026-10-24) */
:root { --sp0: #104281; --sp1: #1c5cab; --sp2: #2a78d6; --sp3: #5598e7; --sp4: #86b6ef; --sp5: #d9d3c6; --sp-ink-dark: #ffffff; --sp-ink-light: #0d1b2e; --crit: #d03b3b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sp0: #cde2fb; --sp1: #9ec5f4; --sp2: #6da7ec; --sp3: #3987e5; --sp4: #256abf; --sp5: #4a4f5c; --sp-ink-dark: #0d1117; --sp-ink-light: #ffffff; } }
.heat .c[data-mode=speed][data-b="0"], .heat .c.avg[data-b="0"], .sw[data-b="0"], .bf[data-b="0"] { background: var(--sp0); color: var(--sp-ink-dark); }
.heat .c[data-mode=speed][data-b="1"], .heat .c.avg[data-b="1"], .sw[data-b="1"], .bf[data-b="1"] { background: var(--sp1); color: var(--sp-ink-dark); }
.heat .c[data-mode=speed][data-b="2"], .heat .c.avg[data-b="2"], .sw[data-b="2"], .bf[data-b="2"] { background: var(--sp2); color: var(--sp-ink-dark); }
.heat .c[data-mode=speed][data-b="3"], .heat .c.avg[data-b="3"], .sw[data-b="3"], .bf[data-b="3"] { background: var(--sp3); color: var(--sp-ink-light); }
.heat .c[data-mode=speed][data-b="4"], .heat .c.avg[data-b="4"], .sw[data-b="4"], .bf[data-b="4"] { background: var(--sp4); color: var(--sp-ink-light); }
.heat .c[data-mode=speed][data-b="5"], .heat .c.avg[data-b="5"], .sw[data-b="5"], .bf[data-b="5"] { background: var(--sp5); color: var(--ink); }
.heat .c[data-mode=speed][data-b=none], .sw[data-b=none], .bf[data-b=none] { background: var(--st-locked); }
.heat .c[data-mode=speed][data-b=wrong], .sw[data-b=wrong] { background: var(--surface); box-shadow: inset 0 0 0 2px var(--crit); }
.heat .c.avg { cursor: default; font-weight: 700; border-radius: 5px; aspect-ratio: auto; display: flex; align-items: center; justify-content: center; min-height: 22px; }
.heat .c.avg[data-b=none] { background: transparent; }
.heat .avg-h { font-style: italic; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 4px; }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--crit); vertical-align: middle; margin-right: 4px; }
.heat .c.flag::after { background: var(--crit); }
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 4px 0 6px; }
.seg { min-height: 44px; padding: 0 14px; border: 0; background: var(--surface); cursor: pointer; font-weight: 700; color: var(--ink-2); }
.seg[aria-checked=true] { background: var(--accent); color: var(--accent-ink); }
.cell-tip { position: fixed; z-index: 60; background: var(--ink); color: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: .8rem; line-height: 1.4; pointer-events: none; max-width: 240px; }
.bands { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 18px; }
.bandrow { display: grid; grid-template-columns: 150px minmax(0, 1fr) 90px; gap: 10px; align-items: center; font-size: .875rem; }
.bandrow .bt { height: 18px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bandrow .bf { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 0; }
.bandrow .bv { font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); }
@media (max-width: 480px) { .bandrow { grid-template-columns: 110px minmax(0, 1fr) 76px; } }
.order-strip .t .avg { display: block; font-size: .72rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.when { margin-bottom: 16px; }
main .when .rs-trackwrap { padding: 0 22px; } /* room for the 44px end handles: no sideways scroll at 375px */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.sub > td { background: var(--surface-2); }
table.data.inner { background: var(--surface); border-radius: 8px; }
tr.excluded td { color: var(--ink-3); font-style: italic; }
@media (pointer: coarse) { .heat { grid-template-columns: 28px repeat(12, 44px) 52px !important; } }
.heat .c.thin { opacity: .55; }
.legend .sw.thin-sw { opacity: .55; }
