/* Neo-brutalist foundation: paper, ink, colour, and crisp offset shadows. */
:root {
  --bg: #f4f3eb;
  --surface: #fffef8;
  --surface-2: #eae9df;
  --text: #23261f;
  --muted: #62665a;
  --border: #30332a;
  --accent: #354b17;
  --accent-fill: #d5f968;
  --accent-soft: #eaf5d1;
  --on-accent: #23261f;
  --good: #2c6539;
  --good-soft: #e4f3de;
  --bad: #ab3630;
  --bad-soft: #fce6df;
  --basic: #2c6539;
  --intermediate: #865007;
  --advanced: #6e4594;
  --code-bg: #eeeee5;
  --lavender: #e5dcfa;
  --peach: #f8d9c8;
  --blue: #d7e8f0;
  --shadow: 4px 4px 0 var(--border);
  --radius: 4px;
  --font-scale: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191c18; --surface: #232720; --surface-2: #30362c;
    --text: #f0f1e6; --muted: #b5bbaa; --border: #8e9881;
    --accent: #d5f968; --accent-fill: #d5f968; --accent-soft: #344326;
    --good: #99dba0; --good-soft: #263b2b; --bad: #ffaaa0; --bad-soft: #412c29;
    --basic: #99dba0; --intermediate: #edc477; --advanced: #ccb4ed;
    --code-bg: #1c201a; --lavender: #3a3248; --peach: #46362c; --blue: #293e46;
    --shadow: 4px 4px 0 #080b07;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 110px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: calc(17px * var(--font-scale)) / 1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
button, a, input, select, summary { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:where(a, button, input, select, summary, [tabindex]):focus-visible { outline: 3px solid var(--accent); outline-offset: 5px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 110; top: -80px; left: 16px; padding: 12px 18px; background: var(--surface); border: 2px solid var(--border); box-shadow: var(--shadow); }
.skip-link:focus { top: 12px; }

/* App navigation */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  min-height: calc(86px + var(--safe-top)); padding: var(--safe-top) 40px 0;
  background: var(--bg); border-bottom: 2px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; flex-shrink: 0; color: var(--text); text-decoration: none; font-size: 19px; font-weight: 800; letter-spacing: -.04em; line-height: 1.3; }
.brand small { display: block; font-size: 10px; font-weight: 500; letter-spacing: .025em; color: var(--muted); margin-top: 4px; }
.brand-mark { display: grid; place-content: center; grid-auto-flow: column; width: 46px; height: 46px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--accent-fill); color: var(--on-accent); box-shadow: 2px 2px 0 var(--border); font: 800 26px/1 ui-monospace, monospace; letter-spacing: -3px; }
.brand-mark > span { color: inherit; }
.back { display: inline-flex; align-items: center; gap: 4px; max-width: 40%; min-height: 44px; padding: 8px 0; background: none; border: 0; color: var(--text); font-size: 13px; font-weight: 650; }
.back span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; }
.topbar.scrolled .topbar-title { opacity: 1; }
.header-settings { display: grid; place-items: center; flex: none; width: 44px; height: 44px; margin-left: auto; color: var(--text); background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: 6px; padding: 10px 12px calc(10px + var(--safe-bottom)); background: var(--bg); border-top: 2px solid var(--border); }
.tabbar a { flex: 1; min-width: 0; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 650; border: 2px solid transparent; border-radius: var(--radius); }
.tabbar a.active { color: var(--on-accent); background: var(--accent-fill); border-color: var(--border); box-shadow: 2px 2px 0 var(--border); }
.tabbar svg { width: 21px; height: 21px; }
body.focus .tabbar { display: none; }
body.focus .view { padding-bottom: calc(40px + var(--safe-bottom)); }

/* Page hierarchy and the learning dashboard */
.view { max-width: 820px; margin: 0 auto; padding: 40px 28px calc(116px + var(--safe-bottom)); outline: none; }
.view:focus { outline: none; }
body[data-page="learn"] .view { max-width: 1160px; }
.large-title { font-size: clamp(30px, 4vw, 44px); font-weight: 800; line-height: 1.12; letter-spacing: -.045em; margin: 6px 0 14px; text-wrap: balance; overflow-wrap: break-word; }
.subtitle { max-width: 620px; font-size: 15px; line-height: 1.75; color: var(--muted); margin: 0 0 28px; }
.page-heading { display: grid; grid-template-columns: 1.35fr 1fr; align-items: center; gap: 64px; margin-bottom: 40px; }
.hero-copy { min-width: 0; }
.page-heading .large-title { font-size: clamp(42px, 5.6vw, 68px); margin: 22px 0; line-height: 1.08; letter-spacing: -.055em; }
.title-highlight { background: var(--accent-fill); color: var(--on-accent); padding: 0 9px 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.page-heading .subtitle { margin-bottom: 20px; }
.eyebrow { font: 650 10px/1.5 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .075em; text-transform: uppercase; }
.hero-copy .eyebrow { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.status-dot { width: 7px; height: 7px; flex: none; background: var(--accent); border-radius: 50%; }
.hero-link { display: inline-flex; align-items: center; gap: 22px; min-height: 44px; color: var(--text); font-size: 13px; font-weight: 700; text-decoration: none; border-bottom: 2px solid var(--border); }
.hero-link > span { font-size: 20px; }
.next-step { min-width: 0; padding: 26px; background: var(--accent-soft); border: 2px solid var(--border); border-radius: var(--radius); box-shadow: 6px 6px 0 var(--border); }
.next-step-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.next-step-mark { font-size: 25px; line-height: 1; }
.next-step h2 { font-size: 23px; line-height: 1.3; letter-spacing: -.03em; margin: 16px 0 10px; text-wrap: balance; }
.next-step p { color: var(--muted); font: 11px/1.6 ui-monospace, monospace; margin: 0 0 24px; }
.next-step .btn { justify-content: space-between; }
.section-label { margin: 30px 0 12px; font: 650 11px/1.5 ui-monospace, "SF Mono", Menlo, monospace; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 38px 0 20px; }
.section-heading h2 { color: var(--text); font: 800 24px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: -.035em; text-transform: none; margin: 0; }
.section-heading .meta { text-transform: none; letter-spacing: 0; font-weight: 400; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { padding: 18px 20px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.stat b { display: block; font-size: 30px; font-weight: 800; line-height: 1.3; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stat small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.home-stats { gap: 0; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.home-stats .stat { border: 0; border-radius: 0; background: none; padding: 20px 26px; }
.home-stats .stat + .stat { border-left: 2px solid var(--border); }

/* Subjects, modules, and reusable surfaces */
.card, .list, .tile, .link-card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.card { padding: 20px; margin-bottom: 14px; }
.list { overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 16px; padding: 20px; min-height: 60px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 16px; font-weight: 700; line-height: 1.5; }
.row-sub { color: var(--muted); font-size: 13px; line-height: 1.65; margin-top: 5px; }
.row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.meta { color: var(--muted); font-size: 12px; }
.chev { color: var(--text); flex: none; }
.num { display: grid; place-items: center; flex: none; width: 38px; height: 38px; background: var(--accent-fill); color: var(--on-accent); border: 1.5px solid var(--border); border-radius: var(--radius); font: 700 15px ui-monospace, monospace; }
.check { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border: 2px solid var(--border); border-radius: var(--radius); }
.check.done { background: var(--good); border-color: var(--good); color: var(--surface); }
.tile { display: block; color: inherit; text-decoration: none; padding: 22px; margin-bottom: 14px; box-shadow: var(--shadow); }
.tile h3 { margin: 0 0 8px; font-size: 21px; letter-spacing: -.025em; line-height: 1.3; }
.tile p { color: var(--muted); font-size: 14px; line-height: 1.7; margin: 0; }
.subject-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.subject-tile { --tile-tint: var(--accent-soft); display: flex; flex-direction: column; min-width: 0; margin: 0; padding: 24px; }
.subject-tile[data-tone="lavender"] { --tile-tint: var(--lavender); }
.subject-tile[data-tone="peach"] { --tile-tint: var(--peach); }
.subject-tile[data-tone="blue"] { --tile-tint: var(--blue); }
.tile-top { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.subject-icon { display: grid; place-items: center; width: 46px; height: 46px; background: var(--tile-tint); border: 1.5px solid var(--border); border-radius: var(--radius); color: var(--text); font: 700 23px ui-monospace, monospace; }
.tile-index { margin-left: auto; color: var(--muted); font: 11px ui-monospace, monospace; }
.tile-arrow { display: grid; place-items: center; width: 30px; height: 30px; font-size: 22px; color: var(--text); }
.subject-tile p { flex: 1; font-size: 13px; }
.subject-tile .row-meta { margin-top: 22px; }
.subject-tile .meta { font-size: 10px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.tile-footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; font-size: 11px; color: var(--muted); }
.tile-footer > span:last-child { color: var(--text); font-weight: 700; }
.badge { display: inline-block; padding: 2px 7px; border: 1px solid currentColor; border-radius: 3px; font: 650 10px/1.6 ui-monospace, monospace; text-transform: capitalize; background: var(--surface); color: var(--muted); }
.badge.basic { color: var(--basic); background: var(--good-soft); }
.badge.intermediate { color: var(--intermediate); background: color-mix(in srgb, var(--intermediate) 12%, var(--surface)); }
.badge.advanced { color: var(--advanced); background: var(--lavender); }
.progress { height: 7px; margin-top: 10px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent-fill); transition: width .2s; }
.subject-tile .progress { height: 6px; margin-top: 8px; }

/* Controls share the same pressed-paper interaction. */
.btn { display: flex; justify-content: center; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 14px 18px; background: var(--accent-fill); color: var(--on-accent); border: 2px solid var(--border); border-radius: var(--radius); box-shadow: 3px 3px 0 var(--border); font-size: 14px; font-weight: 750; line-height: 1.4; text-decoration: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.plain { background: var(--surface); color: var(--text); }
.btn:disabled { opacity: .45; box-shadow: none; }
.btn-row { display: flex; gap: 12px; margin-top: 14px; }
.btn-row .btn { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { min-height: 44px; padding: 9px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 13px; line-height: 1.4; }
.chip[aria-pressed="true"] { background: var(--accent-fill); color: var(--on-accent); box-shadow: 2px 2px 0 var(--border); font-weight: 650; }
.section-label .chip { margin-top: -10px; }
.icon-btn { min-width: 44px; min-height: 44px; padding: 6px; border: 1px solid transparent; border-radius: var(--radius); background: none; color: var(--muted); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--border); }
.search-input, .subject-select { width: 100%; min-height: 54px; padding: 14px 16px; background: var(--surface); color: var(--text); border: 2px solid var(--border); border-radius: var(--radius); font-size: 15px; }
.search-input { box-shadow: 3px 3px 0 var(--border); }
.search-input:focus { outline: 3px solid var(--accent); outline-offset: 3px; }
.setting { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); font-size: 15px; }
.setting:last-child { border-bottom: 0; }
.stepper { display: flex; gap: 8px; }
.stepper button { width: 48px; height: 44px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-weight: 750; }
.danger { min-height: 44px; padding: 0; color: var(--bad); background: none; border: 0; font-weight: 650; }

/* Comfortable reading, with visual weight reserved for the controls. */
.lesson-head { padding-bottom: 22px; margin-bottom: 18px; border-bottom: 2px solid var(--border); }
.lesson-head .large-title { margin-top: 14px; }
.prose { line-height: 1.85; overflow-wrap: break-word; }
.prose h2 { font-size: 1.3em; line-height: 1.3; letter-spacing: -.025em; padding-top: 12px; margin: 1.9em 0 .5em; text-wrap: balance; }
.prose h3 { font-size: 1.1em; line-height: 1.4; margin: 1.4em 0 .4em; }
.prose h4 { font-size: 1em; margin: 1.2em 0 .3em; }
.prose p { margin: .95em 0; }
.prose ul, .prose ol { padding-left: 1.4em; margin: .6em 0; }
.prose li { margin: .3em 0; padding-left: .2em; }
.prose li > ul, .prose li > ol { margin: .2em 0; }
.prose code, .option code, .option-explanation code { overflow-wrap: anywhere; }
.prose code { font: .86em/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: var(--code-bg); padding: .1em .35em; border-radius: 2px; }
.prose pre { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 1em 0; font-size: 12px; line-height: 1.4; }
.prose pre code { background: none; padding: 0; font-size: 12px; line-height: 1.45; white-space: pre; }
.table-wrap { overflow-x: auto; margin: 1em 0; border: 1px solid var(--border); border-radius: var(--radius); }
.prose table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .88em; }
.prose th, .prose td { padding: 12px 15px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.prose th { background: var(--surface-2); font-size: .85em; font-weight: 700; }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.callout { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--muted); border-radius: var(--radius); padding: 16px 20px; margin: 1.5em 0; }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-weight: 750; font-size: .92em; margin-bottom: 2px; }
.callout-note { border-left-color: var(--accent); background: var(--accent-soft); }
.callout-tip { border-left-color: var(--good); background: var(--good-soft); }
.callout-warning { border-left-color: var(--intermediate); background: color-mix(in srgb, var(--intermediate) 12%, var(--surface)); }
.callout-example { border-left-color: var(--advanced); background: var(--lavender); }
.lesson-contents { margin: 24px 0; padding: 4px 18px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.lesson-contents summary { padding: 12px 0; cursor: pointer; font-size: 14px; font-weight: 700; }
.lesson-contents summary .meta { margin-left: 12px; font-weight: 400; }
.lesson-contents > div { display: grid; padding-bottom: 14px; }
.lesson-contents button { min-height: 44px; padding: 8px 12px; text-align: left; border: 0; background: none; color: var(--muted); font-size: 14px; }

/* Practice and answer states */
.quiz-progress { display: flex; align-items: center; gap: 10px; margin: 4px 0 26px; }
.quiz-progress .progress { flex: 1; margin: 0; }
.quiz-prompt { font-size: 1.15em; font-weight: 650; line-height: 1.5; }
.quiz-prompt p:first-child { margin-top: 0; }
.quiz-hint { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.practice-age { min-width: 0; margin: 24px 0 0; padding: 18px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.practice-age legend { padding: 0 8px; font-size: 13px; font-weight: 700; }
.practice-age-summary { font-size: 15px; font-weight: 700; margin: 20px 0 12px; }
.practice-age-control + .practice-age-control { margin-top: 16px; }
.practice-age-input { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.practice-age-input > span { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.practice-age-input input { width: 90px; min-height: 44px; padding: 8px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--bg); font-size: 16px; font-variant-numeric: tabular-nums; }
.practice-age input[type="range"] { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 44px; margin: 8px 0 0; background: transparent; cursor: pointer; touch-action: pan-y; }
.practice-age input[type="range"]::-webkit-slider-runnable-track { height: 8px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 4px; }
.practice-age input[type="range"]::-moz-range-track { height: 6px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 4px; }
.practice-age input[type="range"]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11.5px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--accent-fill); box-shadow: 2px 2px 0 var(--border); }
.practice-age input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--accent-fill); box-shadow: 2px 2px 0 var(--border); }
.practice-age .meta { margin: 12px 0 0; }
.options { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.answer-card { min-width: 0; }
.option { display: flex; gap: 14px; align-items: flex-start; width: 100%; padding: 18px; text-align: left; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); line-height: 1.65; }
.option .key { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 3px; background: var(--surface-2); color: var(--text); font: 700 13px ui-monospace, monospace; }
.option .opt-body { flex: 1; min-width: 0; }
.option .opt-text p { margin: 0; }
.option.selected { background: var(--accent-soft); box-shadow: 3px 3px 0 var(--border); }
.option.selected .key { background: var(--accent-fill); color: var(--on-accent); }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.correct .key { background: var(--good); color: var(--surface); border-color: var(--good); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .key { background: var(--bad); color: var(--surface); border-color: var(--bad); }
.option:disabled { cursor: default; color: inherit; }
.opt-why { font-size: .9em; margin-top: 8px; color: var(--text); }
.opt-why p { margin: .3em 0; }
.opt-tag { font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }
.answer-card.correct .opt-tag { color: var(--good); }
.answer-card.wrong .opt-tag { color: var(--bad); }
.verdict { border-radius: var(--radius); margin: 6px 0 18px; }
.verdict.good { background: var(--good-soft); }
.verdict.bad { background: var(--bad-soft); }
.worked { padding: 24px; margin-top: 24px; }
.worked > h3 { margin: 0 0 4px; color: var(--accent); font-size: 15px; }
.worked pre code, .opt-why pre code { font-size: 11px; }
.worked pre, .opt-why pre { padding: 10px 12px; }
.link-card { display: flex; align-items: center; gap: 12px; padding: 16px; margin: 14px 0; font-size: 14px; color: inherit; text-decoration: none; }
.link-card .ic { display: grid; place-items: center; flex: none; width: 34px; height: 34px; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--border); border-radius: var(--radius); }
.link-card > span:last-child { min-width: 0; }
.link-card small { display: block; color: var(--muted); font-size: 12px; word-break: break-all; }
.sticky-actions { position: sticky; bottom: 0; z-index: 3; margin: 18px -16px 0; padding: 12px 16px calc(12px + var(--safe-bottom)); background: var(--bg); border-top: 1px solid var(--border); }
body:not(.focus) .sticky-actions { bottom: calc(72px + var(--safe-bottom)); padding-bottom: 12px; }
.score-ring { display: block; width: 170px; height: 170px; margin: 36px auto 24px; }
.center { text-align: center; }
.empty { margin: 24px 0; padding: 40px 16px; text-align: center; background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: 14px; }
.empty b { display: block; color: var(--text); font-size: 19px; margin-bottom: 6px; }
.empty-icon { display: block; color: var(--accent); font-size: 38px; margin-bottom: 12px; }
.empty .btn { max-width: 230px; margin: 22px auto 0; }
mark { background: var(--accent-fill); color: var(--on-accent); padding: 0 2px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(92px + var(--safe-bottom)); z-index: 20; display: flex; align-items: center; gap: 12px; max-width: 480px; margin: 0 auto; padding: 12px 16px; background: var(--text); color: var(--bg); border: 2px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 14px; }
.toast button { margin-left: auto; min-height: 44px; background: none; border: 0; color: inherit; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }

/* Code and expandable examples retain their own scrolling area. */
.example-block { margin: 24px 0; min-width: 0; overflow: hidden; text-align: left; font-weight: 400; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.example-block figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); line-height: 1.3; }
.example-label { min-width: 0; overflow-wrap: anywhere; color: var(--muted); font: 700 10px/1.5 ui-monospace, monospace; text-transform: uppercase; letter-spacing: .075em; }
.example-actions { display: flex; gap: 6px; flex-shrink: 0; }
.example-actions button { min-height: 44px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 11px; font-weight: 650; }
.example-content { max-width: 100%; overflow: auto; overscroll-behavior-x: contain; }
.prose .example-block pre, .expanded-example pre { margin: 0; padding: 20px; border: 0; border-radius: 0; background: var(--code-bg); font-size: 13px; line-height: 1.7; }
.prose .example-block pre code, .expanded-example pre code { padding: 0; background: none; font: 13px/1.7 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre; tab-size: 4; }
.is-diagram .example-content { background-image: radial-gradient(var(--muted) .5px, transparent .5px); background-size: 18px 18px; }
.example-text { border-top: 1px solid var(--border); }
.example-text summary { padding: 10px 16px; cursor: pointer; color: var(--muted); font-size: 11px; }
.example-dialog { width: min(1040px, 94vw); max-height: 90dvh; padding: 24px; color: var(--text); background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); box-shadow: 8px 8px 0 var(--border); }
.example-dialog::backdrop { background: #10150fbb; }
.example-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.example-dialog h2 { font-size: 18px; margin: 0; }
.example-dialog button { min-width: 44px; min-height: 44px; padding: 8px 12px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--radius); }
.example-zoom { display: flex; align-items: center; gap: 10px; padding: 20px 0; }
.example-zoom output { min-width: 50px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.expanded-example { max-height: 60dvh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.expanded-example .example-content { width: max-content; min-width: 100%; max-width: none; overflow: visible; }
.example-open { overflow: hidden; }

/* Responsive layouts and input feedback */
@media (hover: hover) {
  .tile, .btn, .chip, .header-settings { transition: transform .15s, box-shadow .15s, background .15s; }
  .tile:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--border); }
  .row:hover, .lesson-contents button:hover, .header-settings:hover { background: var(--surface-2); }
  .btn:not(:disabled):hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--border); }
  .chip:hover, .option:not(:disabled):hover { background: var(--accent-soft); }
  .chip[aria-pressed="true"]:hover { background: var(--accent-fill); }
  .tabbar a:not(.active):hover { color: var(--text); background: var(--surface-2); }
}
.tile:active, .btn:not(:disabled):active { transform: translate(2px, 2px); box-shadow: none; }
@media (min-width: 1000px) {
  .topbar { padding-right: 570px; }
  .topbar-title { display: none; }
  .header-settings { position: absolute; right: 40px; top: calc(20px + var(--safe-top)); }
  .tabbar { left: auto; right: 106px; top: calc(20px + var(--safe-top)); bottom: auto; width: 430px; padding: 0; gap: 8px; border: 0; background: none; }
  .tabbar a { flex-direction: row; gap: 8px; min-height: 44px; font-size: 12px; }
  .tabbar svg { width: 18px; height: 18px; }
  .view { padding-top: 52px; padding-bottom: 64px; }
  .subject-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  body:not(.focus) .sticky-actions { bottom: 0; }
  .toast { bottom: 24px; }
}
@media (max-width: 760px) {
  .page-heading { grid-template-columns: 1fr; gap: 30px; }
  .page-heading .large-title { font-size: 54px; }
  .next-step { padding: 22px; }
  .next-step-top { margin-bottom: 16px; }
  .next-step h2 { font-size: 21px; }
}
@media (max-width: 600px) {
  html { scroll-padding-top: 88px; }
  .topbar { min-height: calc(68px + var(--safe-top)); padding-inline: 18px; gap: 14px; }
  .brand { gap: 10px; font-size: 16px; }
  .brand small, .topbar-title { display: none; }
  .brand-mark { width: 36px; height: 36px; font-size: 22px; }
  .back { margin-left: auto; max-width: 43%; font-size: 12px; }
  .header-settings { width: 40px; height: 40px; }
  .back:not([hidden]) ~ .header-settings { display: none; }
  .view { padding: 30px 20px calc(110px + var(--safe-bottom)); }
  .page-heading { margin-bottom: 30px; }
  .page-heading .large-title { font-size: clamp(44px, 12vw, 54px); }
  .hero-copy .eyebrow { font-size: 9px; }
  .next-step { box-shadow: 4px 4px 0 var(--border); }
  .stats { gap: 8px; }
  .stat, .home-stats .stat { padding: 15px 10px; }
  .stat b { font-size: 24px; }
  .stat small { font-size: 10px; }
  .stat span { font-size: 10px; line-height: 1.5; }
  .home-stats { gap: 0; }
  .section-heading { margin-top: 30px; }
  .section-heading h2 { font-size: 22px; }
  .section-heading .meta { font-size: 11px; }
  .subject-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .subject-tile { padding: 22px; }
  .tile-top { margin-bottom: 18px; }
  .row { padding: 17px 15px; gap: 12px; }
  .row-title { font-size: 15px; }
  .btn-row { flex-wrap: wrap; }
  .btn-row .btn { flex-basis: 140px; }
  .worked { padding: 18px; }
  .callout { padding: 14px 16px; }
  .example-block figcaption { padding: 7px 10px; }
  .example-dialog { padding: 16px; }
}
@media (prefers-color-scheme: dark) {
  .option.correct .key, .check.done { color: #19291b; }
  .option.wrong .key { color: #351c19; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Structured illustrations: labels are text; nodes and connections are vectors. */
.vector-diagram {
  display: block;
  width: var(--diagram-width);
  height: auto;
  max-width: 100%;
  margin: 8px auto;
  overflow: visible;
}
.vector-diagram .dv-label { fill: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-weight: 500; }
.vector-diagram .dv-grid-label { fill: var(--text); font: 15px ui-monospace, SFMono-Regular, Menlo, monospace; }
.vector-diagram .dv-node { fill: var(--surface); stroke: color-mix(in srgb, var(--accent) 35%, var(--border)); stroke-width: 1.5; }
.vector-diagram .dv-muted { fill: var(--surface-2); }
.vector-diagram .dv-area { fill: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); stroke: var(--accent); stroke-width: 1.3; }
.vector-diagram .dv-cell { fill: var(--accent-soft); stroke: color-mix(in srgb, var(--accent) 45%, var(--border)); stroke-width: 1; }
.vector-diagram .dv-edge { stroke: var(--accent); stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.vector-diagram .dv-return { stroke-dasharray: 6 5; }
.vector-diagram .dv-lifeline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 6; opacity: .45; fill: none; }
.vector-diagram .dv-arrow, .vector-diagram .dv-dot { fill: var(--accent); }
.vector-diagram .dv-dot-open { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; }
.vector-diagram .dv-edge-label { fill: var(--surface); stroke: none; }
.vector-diagram .dv-step { fill: var(--accent-soft); stroke: none; }
.vector-diagram.dv-sequence { min-width: min(var(--diagram-width), 760px); }
.vector-diagram.dv-graph, .vector-diagram.dv-memory, .vector-diagram.dv-matrix { min-width: min(var(--diagram-width), 520px); }
.expanded-example .vector-diagram { max-width: none; }
.diagram-hint { padding: 9px 16px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); line-height: 1.6; }
.example-label { min-width: 0; overflow-wrap: anywhere; }
.diagram-hint { border-top: 0; border-bottom: 1px solid var(--border); }
.vector-diagram.dv-tree { min-width: min(var(--diagram-width), 680px); }

/* Definitions remain part of the reading flow, with a small nonmodal panel. */
.technical-term { display: inline; max-width: 100%; white-space: normal; overflow-wrap: anywhere; padding: 0; margin: 0; border: 0; border-radius: var(--radius); background: transparent; color: inherit; font: inherit; line-height: inherit; text-align: inherit; cursor: pointer; text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: .2em; }
.technical-term:hover, .technical-term[aria-expanded="true"] { color: var(--accent); text-decoration-color: currentColor; }
.technical-term:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.term-help { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 20px 0; }
.term-help a { white-space: nowrap; }
.term-popover { position: fixed; z-index: 100; box-sizing: border-box; padding: 18px; overflow-y: auto; overscroll-behavior: contain; border: 2px solid var(--border); border-radius: var(--radius); color: var(--text); background: var(--surface); box-shadow: var(--shadow); font-size: 14px; line-height: 1.6; }
.term-popover header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.term-popover h2 { margin: 2px 0 0; font-size: 21px; line-height: 1.3; }
.term-category { color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.term-close { flex: 0 0 44px; width: 44px; height: 44px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text); font-size: 16px; cursor: pointer; }
.term-popover p { margin: 14px 0; }
.term-example { padding: 12px; border-radius: var(--radius); background: var(--surface-2); }
.term-example b { display: block; margin-bottom: 3px; font-size: 12px; }
.term-popover footer { display: flex; flex-wrap: wrap; gap: 4px 18px; border-top: 1px solid var(--border); padding-top: 6px; }
.term-popover footer a { display: inline-flex; align-items: center; min-height: 44px; font-size: 13px; }
.dictionary-results { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.dictionary-entry { padding: 22px; min-width: 0; overflow-wrap: anywhere; }
.dictionary-entry h2 { margin: 6px 0 12px; font-size: 21px; }
.dictionary-entry p { line-height: 1.65; font-size: 14px; }
.dictionary-entry .meta { font-size: 12px; }
#dictionary-status { margin: 18px 0; color: var(--muted); font-size: 13px; }
@media (max-width: 600px) { .dictionary-results { grid-template-columns: 1fr; } }

/* Answer reveal: the verdict names the right answer; correct and chosen cards carry a coloured ribbon;
   the remaining distractors collapse so the correct option is the obvious thing on screen. */
.verdict { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 2px solid currentColor; font-weight: 400; color: var(--text); }
.verdict.good { border-color: var(--good); }
.verdict.bad { border-color: var(--bad); }
.verdict.good, .verdict.bad { color: var(--text); }
.verdict-icon { flex: none; width: 30px; height: 30px; border-radius: var(--radius); display: grid; place-items: center; color: #fff; }
.verdict.good .verdict-icon { background: var(--good); }
.verdict.bad .verdict-icon { background: var(--bad); }
.verdict-title { font-weight: 750; font-size: 1.05em; }
.verdict.good .verdict-title { color: var(--good); }
.verdict.bad .verdict-title { color: var(--bad); }
.verdict-detail { font-size: .95em; }
.verdict-answer { margin-top: 8px; padding: 8px 12px; border-left: 3px solid var(--good); background: var(--surface); border-radius: 0; font-size: .92em; }
.verdict-answer p { margin: 0; }
.answer-card.correct, .answer-card.wrong { border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.answer-card.correct { border-color: var(--good); box-shadow: 3px 3px 0 var(--good); }
.answer-card.wrong { border-color: var(--bad); }
.answer-card.correct .option, .answer-card.wrong .option { border: 0; border-radius: 0; box-shadow: none; }
.answer-card.correct .option { background: var(--good-soft); }
.answer-card.wrong .option { background: var(--bad-soft); }
.opt-ribbon { display: flex; align-items: center; gap: 8px; padding: 7px 18px; color: #fff; font-size: 12px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.answer-card.correct .opt-ribbon { background: var(--good); }
.answer-card.wrong .opt-ribbon { background: var(--bad); }
.answer-card.correct > .opt-why, .answer-card.wrong > .opt-why { padding: 14px 18px 16px; border-top: 1px solid var(--border); }
details.answer-card.dim { border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); opacity: .72; }
details.answer-card.dim[open] { opacity: 1; }
details.answer-card.dim > summary { list-style: none; display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; cursor: pointer; font-size: .92em; }
details.answer-card.dim > summary::-webkit-details-marker { display: none; }
details.answer-card.dim .key { flex: none; width: 26px; height: 26px; border-radius: var(--radius); display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
details.answer-card.dim .opt-body { flex: 1; min-width: 0; }
details.answer-card.dim .opt-text p { margin: 0; }
details.answer-card.dim .why-toggle { flex: none; align-self: center; font-size: 12px; font-weight: 650; color: var(--accent); }
details.answer-card.dim[open] .why-toggle { visibility: hidden; }
details.answer-card.dim > .opt-why { padding: 0 16px 14px 54px; margin: 0; }
@media (prefers-color-scheme: dark) {
  .verdict-icon, .opt-ribbon { color: #10131c !important; }
}

/* Formula blocks: the equation, then every symbol defined. */
.formula { margin: 1.2em 0; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.formula figcaption { padding: 8px 14px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); }
.formula-eq { padding: 14px; font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif; font-size: 1.08em; line-height: 1.6; overflow-x: auto; white-space: pre-wrap; text-align: center; }
.formula-eq > div + div { margin-top: 2px; }
.formula-eq sub, .formula-where sub { font-size: .7em; }
.formula-eq sup, .formula-where sup { font-size: .7em; }
.formula-where-label { padding: 0 14px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.formula-where { margin: 6px 0 0; padding: 0 14px 12px; display: grid; gap: 8px; }
.formula-where > div { display: grid; grid-template-columns: minmax(2.4em, max-content) minmax(0, 1fr); gap: 10px; align-items: baseline; }
.formula-where dt { font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif; font-size: 1.1em; font-weight: 600; text-align: right; }
.formula-where dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-size: .92em; }
.formula-words { margin: 0; padding: 10px 14px 12px; border-top: 1px solid var(--border); font-size: .92em; }
.formula-words b { color: var(--accent); margin-right: 4px; }
.opt-why .formula, .worked .formula { font-size: .95em; }
