:root {
  --bg: #f7f5f0; --surface: #ffffff; --surface-2: #f0ede5; --ink: #1d2330; --muted: #5d6677; --line: #dcd7cb;
  --accent: #2456c8; --accent-ink: #ffffff; --good: #1b7f4c; --good-bg: #e3f4ea; --bad: #b3261e; --bad-bg: #fbe9e7; --warn: #8a5a00; --warn-bg: #fdf1d6;
  --c-blue: #2456c8; --c-orange: #d9661a; --c-green: #1b8a55; --c-red: #c7342b; --c-purple: #7a45c2; --c-teal: #0d8a94;
  --book: var(--accent);
  --radius: 12px; --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 4px 14px rgba(20, 25, 40, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d; --surface: #1c2029; --surface-2: #252a35; --ink: #e8eaf0; --muted: #a0a8b8; --line: #343a48;
    --accent: #7ea6ff; --accent-ink: #0d1220; --good: #5fd09a; --good-bg: #173326; --bad: #ff8a80; --bad-bg: #3a1c1a; --warn: #f0c060; --warn-bg: #382c12;
    --c-blue: #7ea6ff; --c-orange: #ffa25e; --c-green: #5fd09a; --c-red: #ff8a80; --c-purple: #c09bff; --c-teal: #5fd3dc;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.6 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; text-wrap: balance; margin: 0 0 .4em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); } h2 { font-size: 1.35rem; margin-top: 1.8em; } h3 { font-size: 1.12rem; }
p { margin: 0 0 .9em; } ul, ol { margin: 0 0 .9em; padding-left: 1.4em; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); font-size: .92em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

#topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); }
.topnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav a { padding: 5px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: .95rem; }
.topnav a:hover { background: var(--surface-2); }
.pill { margin-left: 5px; background: var(--bad); color: #fff; border-radius: 99px; padding: 0 7px; font-size: .75rem; font-weight: 700; }
.stats { display: flex; gap: 12px; align-items: center; font-size: .9rem; font-variant-numeric: tabular-nums; }
.stat { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.bar { display: inline-block; width: 64px; height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; vertical-align: middle; }
.bar > span { display: block; height: 100%; background: var(--book); border-radius: 99px; transition: width .4s; }

#view { max-width: 820px; margin: 0 auto; padding: 22px 16px 80px; }
.hero { padding: 26px 0 8px; } .hero p { max-width: 62ch; color: var(--muted); }
.tier { font-family: var(--font); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 2em 0 .7em; }
.banner { display: block; padding: 12px 16px; border-radius: var(--radius); background: var(--warn-bg); color: var(--ink); text-decoration: none; margin: 10px 0; border: 1px solid var(--line); }
.banner.soft { background: var(--surface); }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.book-card { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: var(--ink); overflow: hidden; transition: transform .15s; }
.book-card:hover { transform: translateY(-2px); }
.book-spine { width: 10px; background: var(--book); flex: none; }
.book-body { padding: 14px 16px; flex: 1; min-width: 0; } .book-body h3 { margin-bottom: .2em; }
.book-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); }
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.page-head { margin-bottom: 18px; } .lesson-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.eyebrow { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--book); font-weight: 700; margin-bottom: 4px; }
.read-along { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; font-size: .93rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; } .chip, .tag { display: inline-block; font-size: .78rem; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); text-decoration: none; white-space: nowrap; }
.tag.done { background: var(--good-bg); color: var(--good); }
.note-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
ul.plain { list-style: none; padding: 0; } ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--line); }

.chapter-list, .lesson-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.chapter-list a, .lesson-list a, .lab-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.chapter-list a:hover, .lesson-list a:hover, .lab-link:hover { border-color: var(--book); }
.chapter-list .soon a { background: transparent; }
.ch-n { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--book); color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
.soon .ch-n { background: var(--surface-2); color: var(--muted); }
.ch-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lab-link { margin-bottom: 6px; justify-content: space-between; }
.ring { position: relative; display: inline-block; flex: none; } .ring svg { width: 100%; height: 100%; display: block; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 3.6; } .ring-fg { fill: none; stroke: var(--good); stroke-width: 3.6; stroke-linecap: round; transition: stroke-dasharray .5s; }
.ring-txt { position: absolute; inset: 0; display: grid; place-items: center; color: var(--good); font-weight: 700; font-size: .8rem; }

.lesson .block, .block { margin: 0 0 20px; }
.block.text { max-width: 68ch; }
.math-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: .6em 0; }
.callout { border-left: 4px solid var(--c-blue); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; padding: 12px 16px; box-shadow: var(--shadow); }
.callout.strategy { border-color: var(--c-green); } .callout.pitfall { border-color: var(--c-red); } .callout.aside, .callout.extra { border-color: var(--c-purple); }
.callout-head { font-weight: 700; font-size: .88rem; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.callout p:last-child, .problem-prompt p:last-child, .hint p:last-child, .step p:last-child { margin-bottom: 0; }
.block-label { display: inline-block; font-size: .76rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--book); margin-bottom: 6px; }
.try, .flaw, .steps, .practice { background: transparent; }
.try { border: 2px solid var(--book); border-radius: var(--radius); padding: 14px; }
.gate-cover { border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--muted); margin-bottom: 20px; background: repeating-linear-gradient(135deg, transparent 0 10px, color-mix(in srgb, var(--surface-2) 60%, transparent) 10px 20px); }

.problem { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow); }
.problem.solved { border-color: var(--good); }
.problem.tier-challenge { border-left: 4px solid var(--c-purple); }
.problem-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.problem-num { font-weight: 700; font-size: .85rem; color: var(--muted); } .dots { font-size: .6rem; letter-spacing: 2px; color: var(--book); }
.problem-prompt { margin-bottom: 10px; }
.answer-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
input.answer, .w-input, textarea, select { font: inherit; color: var(--ink); background: var(--bg); border: 1.5px solid var(--line); border-radius: 9px; padding: 8px 11px; }
input.answer { flex: 1 1 200px; min-width: 0; } textarea { width: 100%; resize: vertical; }
input.answer:focus, textarea:focus { border-color: var(--accent); outline: none; }
.unit { color: var(--muted); }
.btn, .w-btn { font: inherit; font-size: .93rem; font-weight: 600; cursor: pointer; padding: 8px 14px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-block; }
.btn:hover:not(:disabled), .w-btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary, .w-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); } .btn.small { padding: 4px 10px; font-size: .84rem; margin-left: 6px; }
.btn:disabled, .w-btn:disabled { opacity: .45; cursor: not-allowed; }
.choices { display: grid; gap: 7px; margin: 8px 0; }
.choice { font: inherit; text-align: left; cursor: pointer; padding: 9px 13px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); }
.choice p { margin: 0; } .choice.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.feedback { min-height: 1.2em; font-weight: 600; font-size: .95rem; } .feedback:empty { min-height: 0; }
.feedback.good { color: var(--good); } .feedback.bad { color: var(--bad); } .feedback.warn { color: var(--warn); } .feedback p { margin: 0; font-weight: 400; color: var(--ink); }
.hint { display: flex; gap: 10px; background: var(--warn-bg); border-radius: 9px; padding: 9px 12px; margin-top: 8px; }
.hint-n { flex: none; font-size: .76rem; font-weight: 700; text-transform: uppercase; color: var(--warn); padding-top: 3px; }
.solution { margin-top: 10px; padding: 12px 14px; background: var(--good-bg); border-radius: 9px; overflow-x: auto; }
.solution-answer { margin-bottom: 6px; }
details.note { margin-top: 8px; font-size: .9rem; } details.note summary { cursor: pointer; color: var(--muted); }
.step-list { padding-left: 1.3em; } .step { margin-bottom: 12px; animation: rise .3s; }
.flaw-lines { padding-left: 1.6em; } .flaw-lines li { margin: 5px 0; }
.flaw-line { font: inherit; color: var(--ink); width: 100%; text-align: left; background: var(--surface); border: 1.5px solid var(--line); border-radius: 9px; padding: 7px 12px; cursor: pointer; }
.flaw-line p { margin: 0; } .flaw-line:hover { border-color: var(--accent); } .flaw-line.hit { border-color: var(--good); background: var(--good-bg); } .flaw-line.miss { border-color: var(--bad); opacity: .65; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 36px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); } .tile-value { font: 700 2rem var(--serif); }
.prog-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; margin-bottom: 6px; } .tool summary { cursor: pointer; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 99px; z-index: 50; transition: opacity .5s; } .toast.out { opacity: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.shake { animation: shake .3s; }

/* ---------- widgets ---------- */
.widget-block { margin: 0 0 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.widget-title { font-weight: 700; margin-bottom: 8px; } figcaption { color: var(--muted); font-size: .92rem; margin-top: 8px; } figcaption p:last-child { margin: 0; }
.widget { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.w-svg { width: 100%; height: auto; display: block; margin: 0 auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; overflow: visible; }
.w-grid { stroke: var(--line); stroke-width: 1; opacity: .7; fill: none; } .w-axis { stroke: var(--muted); stroke-width: 1.4; fill: none; }
.w-tick { fill: var(--muted); font: 11px var(--font); } .w-label { fill: var(--ink); font: 600 13px var(--font); }
.w-line { stroke: var(--ink); stroke-width: 2; fill: none; stroke-linecap: round; } .w-curve { stroke: var(--c-blue); stroke-width: 2.5; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.w-point { fill: var(--ink); stroke: var(--surface); stroke-width: 1.5; } .w-point.open { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.w-shape { fill: color-mix(in srgb, var(--c-blue) 16%, transparent); stroke: var(--c-blue); stroke-width: 2; stroke-linejoin: round; }
.w-area { fill: color-mix(in srgb, var(--c-blue) 22%, transparent); stroke: none; }
.w-fill-solid { fill: var(--ink); stroke: none; } .w-arrow .w-line { stroke: var(--ink); }
.w-drag-hit { fill: transparent; } .w-drag-dot { fill: var(--c-orange); stroke: var(--surface); stroke-width: 2.5; } .w-drag:focus-visible .w-drag-dot { stroke: var(--ink); }
.c-blue.w-line, .c-blue.w-curve, .c-blue .w-line { stroke: var(--c-blue); } .c-orange.w-line, .c-orange.w-curve, .c-orange .w-line { stroke: var(--c-orange); } .c-green.w-line, .c-green.w-curve, .c-green .w-line { stroke: var(--c-green); } .c-red.w-line, .c-red.w-curve, .c-red .w-line { stroke: var(--c-red); } .c-purple.w-line, .c-purple.w-curve, .c-purple .w-line { stroke: var(--c-purple); } .c-teal.w-line, .c-teal.w-curve, .c-teal .w-line { stroke: var(--c-teal); }
.c-blue.w-point, .c-blue .w-fill-solid, .c-blue.w-label, .c-blue .w-drag-dot { fill: var(--c-blue); } .c-orange.w-point, .c-orange .w-fill-solid, .c-orange.w-label, .c-orange .w-drag-dot { fill: var(--c-orange); } .c-green.w-point, .c-green .w-fill-solid, .c-green.w-label, .c-green .w-drag-dot { fill: var(--c-green); } .c-red.w-point, .c-red .w-fill-solid, .c-red.w-label, .c-red .w-drag-dot { fill: var(--c-red); } .c-purple.w-point, .c-purple .w-fill-solid, .c-purple.w-label, .c-purple .w-drag-dot { fill: var(--c-purple); } .c-teal.w-point, .c-teal .w-fill-solid, .c-teal.w-label, .c-teal .w-drag-dot { fill: var(--c-teal); }
.c-blue.w-shape { stroke: var(--c-blue); fill: color-mix(in srgb, var(--c-blue) 16%, transparent); } .c-orange.w-shape { stroke: var(--c-orange); fill: color-mix(in srgb, var(--c-orange) 18%, transparent); } .c-green.w-shape { stroke: var(--c-green); fill: color-mix(in srgb, var(--c-green) 18%, transparent); } .c-red.w-shape { stroke: var(--c-red); fill: color-mix(in srgb, var(--c-red) 16%, transparent); } .c-purple.w-shape { stroke: var(--c-purple); fill: color-mix(in srgb, var(--c-purple) 16%, transparent); } .c-teal.w-shape { stroke: var(--c-teal); fill: color-mix(in srgb, var(--c-teal) 16%, transparent); }
.c-blue.w-area { fill: color-mix(in srgb, var(--c-blue) 22%, transparent); } .c-orange.w-area { fill: color-mix(in srgb, var(--c-orange) 24%, transparent); } .c-green.w-area { fill: color-mix(in srgb, var(--c-green) 24%, transparent); } .c-red.w-area { fill: color-mix(in srgb, var(--c-red) 22%, transparent); } .c-purple.w-area { fill: color-mix(in srgb, var(--c-purple) 22%, transparent); } .c-teal.w-area { fill: color-mix(in srgb, var(--c-teal) 22%, transparent); }
.w-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.w-slider { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 0; font-size: .93rem; } .w-slider input { flex: 1; min-width: 80px; accent-color: var(--accent); } .w-slider-label p { margin: 0; }
.w-slider-val { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.w-toggle, .w-select { display: inline-flex; align-items: center; gap: 6px; font-size: .93rem; } .w-toggle p, .w-select p { margin: 0; } .w-input { width: 7em; padding: 5px 8px; }
.w-readout { background: var(--surface-2); border-radius: 9px; padding: 8px 12px; font-variant-numeric: tabular-nums; overflow-x: auto; } .w-readout p:last-child { margin: 0; }
.w-missing { color: var(--muted); font-style: italic; }
.w-cells { display: grid; gap: 3px; } .w-cell { display: grid; place-items: center; aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); font-size: .85rem; font-variant-numeric: tabular-nums; border: 0; color: var(--ink); font-family: inherit; }
button.w-cell { cursor: pointer; } .w-cell.on { background: var(--c-blue); color: var(--surface); } .w-cell.alt { background: var(--c-orange); color: var(--surface); } .w-cell.dim { opacity: .35; }
@media (max-width: 560px) { body { font-size: 16px; } .stats .bar { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { #topbar, .pager, .btn { display: none; } }
/* long inline formulas scroll inside their own block instead of widening the page */
.problem-prompt, .block.text, .callout > div, .hint > div, .step > div, .choice, .flaw-line, .feedback, figcaption, .try > div { max-width: 100%; overflow-x: auto; }
/* controls with long labels shrink to the widget instead of widening the page */
.w-select, .w-toggle { max-width: 100%; min-width: 0; } .w-select select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }
