/* Layout: graph-paper page, one centred column; level map is a "ruler" plus a ladder of level cards. */
:root {
  --paper: #f2f6fb;
  --grid: rgba(47, 99, 171, 0.09);
  --card: #ffffff;
  --ink: #18263b;
  --muted: #56667e;
  --line: #d3deeb;
  --ink-blue: #2a63c7;
  --pencil: #ffba1f;
  --pencil-deep: #c98a00;
  --coral: #ef6a4c;
  --good: #1d9a57;
  --good-bg: #e5f6ec;
  --bad: #c9423a;
  --bad-bg: #fcebe8;
  --shape: #dce8fb;
  --shape-alt: #fff1cc;
  --display: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13201c; --grid: rgba(220, 240, 230, 0.05); --card: #1c2c27; --ink: #e9f1ed; --muted: #9fb3aa;
    --line: #2e423b; --ink-blue: #7fb0ff; --pencil: #ffc94a; --pencil-deep: #ffd77a; --coral: #ff8a6e;
    --good: #4fcf8a; --good-bg: #173a29; --bad: #ff7d72; --bad-bg: #3d1f1d; --shape: #24405f; --shape-alt: #4a3d17;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #13201c; --grid: rgba(220, 240, 230, 0.05); --card: #1c2c27; --ink: #e9f1ed; --muted: #9fb3aa;
  --line: #2e423b; --ink-blue: #7fb0ff; --pencil: #ffc94a; --pencil-deep: #ffd77a; --coral: #ff8a6e;
  --good: #4fcf8a; --good-bg: #173a29; --bad: #ff7d72; --bad-bg: #3d1f1d; --shape: #24405f; --shape-alt: #4a3d17;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font: 17px/1.5 var(--body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink-blue); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 880px; margin: 0 auto;
  padding-block: 14px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand {
  display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 0;
  font-family: var(--display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.01em;
}
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--pencil); color: #1b1300;
  display: grid; place-items: center; font-size: 1rem; transform: rotate(-6deg);
}
.xp {
  font-family: var(--mono); font-size: 0.85rem; font-weight: 700;
  background: var(--card); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 12px;
  font-variant-numeric: tabular-nums;
}

main {
  max-width: 880px; margin: 0 auto;
  padding-block: 8px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 24px;
}
h1, h2 { font-family: var(--display); line-height: 1.1; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2rem, 6vw, 3rem); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; font-weight: 700; }
.eyebrow { margin: 0 0 4px; font-family: var(--mono); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.lede { margin: 8px 0 0; color: var(--muted); max-width: 60ch; }

.btn {
  border: 2px solid var(--ink); background: var(--card); border-radius: 12px; padding: 10px 18px;
  font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--pencil); color: #1b1300; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 4px 0; cursor: pointer; color: var(--ink-blue); font-weight: 700; }

/* ---------- home tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tile {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 6px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 18px;
  min-width: 0;
}
.tile p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.tile .ic { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.tile.live { border-color: var(--ink); box-shadow: 0 5px 0 var(--ink); cursor: pointer; transition: transform .12s, box-shadow .12s; grid-column: span 1; }
.tile.live .ic { color: var(--ink-blue); }
.tile.live:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); }
.tile.live:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.tile.soon { opacity: .62; border-style: dashed; }
.tile .tag {
  position: absolute; top: 16px; right: 16px; font-family: var(--mono); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; padding: 3px 8px; border-radius: 6px; border: 1.5px solid var(--line); color: var(--muted);
}
.tile .tag.go { background: var(--pencil); color: #1b1300; border-color: var(--ink); }
.tile-foot { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: .88rem; color: var(--muted); }
.meter { height: 10px; border-radius: 99px; background: var(--paper); border: 1.5px solid var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--good); }

.stars { color: var(--pencil-deep); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--line); }

/* ---------- level map ---------- */
.crumbs { margin-bottom: -12px; }
.ruler {
  margin-top: 18px; display: grid; grid-template-columns: repeat(10, 1fr);
  background: var(--pencil); border: 2px solid var(--ink); border-radius: 8px; height: 46px; overflow: hidden;
}
.ruler span {
  position: relative; border-right: 1.5px solid var(--ink);
  background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 1px), rgba(0,0,0,.45) calc(20% - 1px) 20%) top / 100% 9px no-repeat;
}
.ruler span:last-child { border-right: 0; }
.ruler span.on { background-color: var(--good); }
.ruler em { position: absolute; bottom: 4px; right: 5px; font: 700 .78rem var(--mono); font-style: normal; color: #1b1300; }

.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 12px; }
.lvl {
  display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r); padding: 12px 14px;
  box-shadow: 0 4px 0 var(--ink); min-width: 0; transition: transform .1s, box-shadow .1s;
}
.lvl:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.lvl.locked { cursor: default; border-color: var(--line); box-shadow: none; opacity: .65; }
.lvl.next { outline: 3px dashed var(--pencil-deep); outline-offset: 3px; }
.lvl-n {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font: 800 1.35rem var(--display); background: var(--paper); border: 2px solid currentColor;
}
.lvl.done .lvl-n { background: var(--good); color: #fff; border-color: var(--good); }
.lvl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lvl-body b { font-family: var(--display); font-size: 1.15rem; line-height: 1.2; }
.lvl-body small { color: var(--muted); font-size: .85rem; }
.lvl-s { flex: none; font-size: 1.1rem; }
.parent { margin: 0; font-size: .85rem; color: var(--muted); }

/* ---------- play ---------- */
.playtop { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.where { font-family: var(--display); font-weight: 700; font-size: 1.1rem; flex: 1; min-width: 0; text-align: center; }
.dots { display: flex; gap: 6px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); }
.dots i.cur { background: var(--pencil); }
.dots i.ok { background: var(--good); border-color: var(--good); }
.dots i.no { background: var(--bad); border-color: var(--bad); }

.qcard {
  background: var(--card); border: 2px solid var(--ink); border-radius: 18px; box-shadow: 0 6px 0 var(--ink);
  padding: clamp(18px, 4vw, 32px); display: flex; flex-direction: column; gap: 18px;
}
.qnum { margin: 0; font-family: var(--mono); font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.prompt { font-size: clamp(1.15rem, 3.2vw, 1.4rem); line-height: 1.45; max-width: 60ch; }
.prompt b { color: var(--ink-blue); }
.fig { margin: 0; background: var(--paper); border-radius: 12px; border: 1.5px solid var(--line); padding: 8px; }
.fig svg { display: block; width: 100%; max-width: 460px; height: auto; margin: 0 auto; }
.fig .sh { fill: var(--shape); stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.fig .sh.cut { fill: var(--paper); stroke-dasharray: 0; }
.fig .sh.alt { fill: var(--shape-alt); }
.fig .seg { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 6 5; }
.fig .ra { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.fig .lbl { font: 700 14px var(--mono); fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.fig .lbl.q { fill: var(--coral); font-size: 16px; }

.answer { display: flex; gap: 12px; flex-wrap: wrap; align-items: stretch; }
.field {
  display: flex; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper);
  padding: 0 14px; flex: 0 1 280px; min-width: 0;
}
.field input {
  border: 0; background: transparent; outline: none; font: 700 1.5rem var(--mono); color: var(--ink);
  width: 100%; min-width: 0; padding: 10px 0;
}
.field:focus-within { outline: 3px solid var(--ink-blue); outline-offset: 2px; }
.field .unit, .field .pre { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.field.right { border-color: var(--good); background: var(--good-bg); }
.field.wrong { border-color: var(--bad); background: var(--bad-bg); }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.choice {
  border: 2px solid var(--ink); border-radius: 12px; background: var(--paper); padding: 14px; cursor: pointer;
  font-family: var(--mono); font-weight: 700; font-size: 1.05rem; box-shadow: 0 3px 0 var(--ink);
}
.choice:hover:not(:disabled) { background: var(--shape); }
.choice:disabled { cursor: default; }
.choice.right { background: var(--good-bg); border-color: var(--good); box-shadow: 0 3px 0 var(--good); }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad); box-shadow: 0 3px 0 var(--bad); }

.hintrow { display: flex; flex-direction: column; gap: 6px; }
.hinttext { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--shape-alt); max-width: 60ch; }

.feedback { border-radius: 14px; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.feedback.good { background: var(--good-bg); border: 2px solid var(--good); }
.feedback.bad { background: var(--bad-bg); border: 2px solid var(--bad); }
.feedback p { margin: 0; }
.verdict { font-family: var(--display); font-size: 1.3rem; font-weight: 800; }
.plus { font: 700 .85rem var(--mono); color: var(--good); }
.why { font-family: var(--mono); font-size: .95rem; }
.feedback .btn { margin-top: 6px; }

/* ---------- results ---------- */
.result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-block: 32px; }
.result .lede { margin-inline: auto; }
.bigstars { font-size: 3.4rem; line-height: 1.1; margin: 8px 0; }
.result.win .bigstars { animation: pop .5s ease-out; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
@keyframes pop { from { transform: scale(.4); } 70% { transform: scale(1.15); } to { transform: scale(1); } }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (max-width: 520px) {
  .where { order: 3; flex-basis: 100%; text-align: left; }
  .answer .btn { flex: 1 1 100%; }
  .field { flex: 1 1 100%; }
}

/* ---------- home: areas from the score report ---------- */
.area { display: flex; flex-direction: column; gap: 12px; }
.area-h { font-size: 1.15rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
  font: 700 .72rem var(--mono); text-transform: uppercase; letter-spacing: .08em;
  background: var(--coral); color: #fff; padding: 3px 9px; border-radius: 999px;
}

/* ---------- graphs & tables ---------- */
.fig .gl { stroke: var(--line); stroke-width: 1; }
.fig .ax { stroke: var(--ink); stroke-width: 2; }
.fig .bar { fill: var(--ink-blue); }
.fig .bar.miss { fill: none; stroke: var(--coral); stroke-width: 2; stroke-dasharray: 5 4; }
.fig .tk { font: 600 12px var(--mono); fill: var(--ink); }
.fig .ttl { font: 700 14px var(--body); fill: var(--muted); }
.fig .xm { font: 700 20px var(--mono); fill: var(--ink-blue); }
.fig .qm { font: 800 20px var(--display); fill: var(--coral); }
.fig .ico { fill: var(--pencil); stroke: var(--pencil-deep); stroke-width: 1.5; }
.prompt code { font: 700 .9em var(--mono); background: var(--paper); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.dtable { border-collapse: collapse; margin: 12px 0; font-family: var(--mono); font-size: 1rem; font-variant-numeric: tabular-nums; }
.dtable th, .dtable td { border: 1.5px solid var(--line); padding: 6px 16px; text-align: left; }
.dtable th { background: var(--paper); font-family: var(--body); }
.dtable td:last-child { text-align: right; }
.fig .tkf { font: 700 17px var(--body); fill: var(--ink); }

/* ---------- fractions ---------- */
.fig .fb { fill: var(--card); stroke: var(--ink); stroke-width: 2; }
.fig .fb.on { fill: var(--pencil); }
.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; font-family: var(--mono); font-weight: 700; font-size: .9em; margin: 0 .12em; }
.fr > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .15em; }
.choice .fr { font-size: 1em; }
.feedback .fr, .hinttext .fr { font-size: .95em; }

/* ---------- area model ---------- */
.dtable.area th, .dtable.area td { text-align: center; min-width: 64px; }
.dtable.area th:first-child { color: var(--muted); }
.dtable.area td { background: var(--shape); }
.qcell { color: var(--coral); font-size: 1.2em; }

/* ---------- angles & lines ---------- */
.fig .ray { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.fig .ray.hl { stroke: var(--coral); }
.fig .ahd { fill: var(--ink); }
.fig .arc { fill: none; stroke: var(--ink-blue); stroke-width: 2.5; }
.fig .arcmk { fill: none; stroke: var(--ink-blue); stroke-width: 2.5; }
.fig .vtx { fill: var(--ink); }
.fig .angl { font: 700 15px var(--mono); fill: var(--ink-blue); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.fig .lbl.ang { fill: var(--ink-blue); }
.fig .prot { fill: var(--shape-alt); stroke: var(--ink); stroke-width: 2; }
.fig .tick { stroke: var(--ink); stroke-width: 1.3; }
.fig .ptk { font: 600 10px var(--mono); fill: var(--ink); }
.fig .clk { fill: var(--card); stroke: var(--ink); stroke-width: 3; }
.fig .hand { stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.fig .hand.hr { stroke-width: 6; stroke: var(--ink-blue); }
.qcount { margin-top: 3px; font: 700 .72rem var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-blue); }
.lvl.locked .qcount { color: var(--muted); }
.build { text-align: center; font: 600 .7rem var(--mono); color: var(--muted); letter-spacing: .06em; padding-block: 0 24px; }
.dtable.io th, .dtable.io td { text-align: center; min-width: 52px; padding: 6px 10px; }
.dtable.io th { color: var(--muted); }
.prompt .qcell { font-family: var(--mono); }

/* ---------- parent PIN dialog ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(10, 18, 30, .55);
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.sheet {
  width: min(100%, 380px); background: var(--card); border: 2px solid var(--ink); border-radius: 18px; box-shadow: 0 6px 0 var(--ink);
  padding: 22px; display: flex; flex-direction: column; gap: 12px;
}
.sheet .lede { margin: 0; font-size: .95rem; }
.pin {
  font: 700 1.4rem var(--mono); letter-spacing: .3em; text-align: center; color: var(--ink);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; padding: 10px; width: 100%;
}
.pin:focus { outline: 3px solid var(--ink-blue); outline-offset: 2px; }
.pin-err { margin: 0; color: var(--bad); font-weight: 700; font-size: .9rem; }
.sheet .actions { margin-top: 4px; justify-content: flex-end; }

/* ---------- login, parent page, report ---------- */
.top .right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.who .link { font-size: .85rem; }
.build .link { font-size: .75rem; }
.players .player { align-items: center; text-align: center; padding-block: 26px; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--pencil); color: #1b1300; font: 800 2rem var(--display); border: 2px solid var(--ink); }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.link.small { font-size: .85rem; align-self: flex-start; }
.tabs { display: flex; gap: 8px; border-bottom: 2px solid var(--line); }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 8px 14px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tab.on { color: var(--ink); border-bottom-color: var(--pencil-deep); }
.panel { background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.panel h2 { font-size: 1.2rem; }
.panel label { font-weight: 700; font-size: .85rem; margin-top: 6px; }
.txt { font: 600 1rem var(--mono); color: var(--ink); background: var(--paper); border: 2px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0; }
.txt:focus { outline: 3px solid var(--ink-blue); outline-offset: 1px; }
.actions.left { justify-content: flex-start; margin-top: 8px; }
.pin-msg { margin: 0; font-size: .9rem; min-height: 1.2em; }
.pin-msg.good { color: var(--good); } .pin-msg.bad { color: var(--bad); }
.sync-note { margin: 14px 0 0; font-size: .8rem; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpis div { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; }
.kpis b { font: 800 1.7rem var(--display); font-variant-numeric: tabular-nums; }
.kpis span { color: var(--muted); font-size: .8rem; }
.rep-h { font-size: 1.2rem; margin-top: 8px; }
.tablewrap { overflow-x: auto; }
.rep { border-collapse: collapse; width: 100%; font-size: .9rem; background: var(--card); }
.rep th, .rep td { border-bottom: 1.5px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.rep th { font: 700 .72rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--paper); }
.rep .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rep .muted { font-size: .8rem; }
.chip { display: inline-block; font: 700 .68rem var(--mono); text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 99px; border: 1.5px solid var(--line); color: var(--muted); }
.chip.slow { border-color: var(--coral); color: var(--coral); }
.chip.fast, .chip.ok { border-color: var(--good); color: var(--good); }
.callout { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--bad-bg); border: 2px solid var(--bad); }
.empty { display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 520px) { .brand-t { display: none; } }
