/* AI From the Ground Up: one stylesheet, two themes. Theme colors are hex
   because canvas widgets read and blend them. */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --sidebar-w: 292px;
  --content-w: 760px;
}
[data-theme="dark"] {
  --bg: #0d0f17;
  --surface: #141826;
  --surface-2: #1a1f30;
  --surface-3: #232a40;
  --border: #2c3450;
  --text: #e6e9f2;
  --text-muted: #9aa3bd;
  --accent: #8b7dff;
  --accent-strong: #a79cff;
  --accent-2: #3ccfcf;
  --accent-ink: #0d0f17;
  --good: #3fcf8e;
  --bad: #ff6b81;
  --warn: #ffc14d;
  --class-a: #ff8a5b;
  --class-b: #4fb3ff;
  --code-bg: #10131e;
  --tk-kw: #c792ea;
  --tk-str: #a5d6a7;
  --tk-num: #f7a76c;
  --tk-com: #6b7594;
  --tk-fn: #82aaff;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f2f3f9;
  --surface-3: #e7e9f3;
  --border: #d9dcea;
  --text: #171a26;
  --text-muted: #5b6380;
  --accent: #5b4cf0;
  --accent-strong: #4234d6;
  --accent-2: #0b8f8f;
  --accent-ink: #ffffff;
  --good: #14895a;
  --bad: #d42a4a;
  --warn: #a86500;
  --class-a: #e0602b;
  --class-b: #1c7fd6;
  --code-bg: #f4f5fb;
  --tk-kw: #8a2bc2;
  --tk-str: #2d7a32;
  --tk-num: #b45309;
  --tk-com: #7a819b;
  --tk-fn: #1d5fd1;
  --shadow: 0 8px 30px rgba(25, 30, 60, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16.5px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-underline-offset: 2px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 3.2vw, 2.4rem); margin: .2em 0 .4em; }
h2 { font-size: 1.4rem; margin: 2.2em 0 .7em; }
h3 { font-size: 1.1rem; margin: 1.6em 0 .5em; }
p, li { max-width: 72ch; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }
.noscript { padding: 2rem; }
.error { color: var(--bad); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-bg { fill: var(--accent); }
.brand-fg { stroke: var(--accent-ink); }
.top-links { display: flex; gap: 4px; }
.top-links a { color: var(--text-muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 500; }
.top-links a:hover { color: var(--text); background: var(--surface-2); }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
[data-theme="dark"] .icon-moon, [data-theme="light"] .icon-sun { display: none; }
.nav-toggle { display: none; }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%; height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
}
.search input::placeholder { color: var(--text-muted); }
.search-results {
  position: absolute; top: 46px; left: 0; right: 0; max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.sr-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 11px; border-radius: 9px; text-decoration: none; color: var(--text); }
.sr-item:hover, .sr-item.active { background: var(--surface-3); }
.sr-title { font-weight: 600; }
.sr-sub { font-size: .78rem; color: var(--text-muted); align-self: center; }
.sr-snippet { grid-column: 1 / -1; font-size: .85rem; color: var(--text-muted); }
.sr-empty, .sr-all { display: block; padding: 10px 12px; font-size: .9rem; color: var(--text-muted); }
.search-page-results { display: grid; gap: 6px; }
.search-page-results .sr-item { background: var(--surface); border: 1px solid var(--border); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  border-right: 1px solid var(--border); padding: 16px 12px 40px; background: var(--surface);
}
.overall-progress { padding: 4px 8px 14px; }
.op-row { display: flex; justify-content: space-between; font-size: .85rem; color: var(--text-muted); margin-bottom: 6px; }
.op-row strong { color: var(--text); }
.side-phase { margin-bottom: 2px; }
.side-phase summary { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; list-style: none; font-weight: 600; font-size: .92rem; }
.side-phase summary::-webkit-details-marker { display: none; }
.side-phase summary:hover { background: var(--surface-2); }
.side-n { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: 7px; background: var(--surface-3); font-size: .78rem; }
.side-phase[open] .side-n { background: var(--accent); color: var(--accent-ink); }
.side-title { flex: 1; }
.side-pct { font-size: .75rem; color: var(--text-muted); font-weight: 500; }
.side-phase ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 16px; }
.side-phase li a { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px; color: var(--text-muted); text-decoration: none; font-size: .9rem; line-height: 1.35; }
.side-phase li a:hover { color: var(--text); background: var(--surface-2); }
.side-phase li a.current { color: var(--text); background: var(--surface-3); font-weight: 600; }
.scrim { display: none; }
.side-links { list-style: none; padding: 12px 8px 0; margin: 12px 0 0; border-top: 1px solid var(--border); display: grid; gap: 2px; font-size: .9rem; }
.side-links a { color: var(--text-muted); text-decoration: none; display: block; padding: 5px 8px; border-radius: 7px; }
.side-links a:hover { color: var(--text); background: var(--surface-2); }

main { padding: 28px clamp(16px, 4vw, 48px) 80px; min-width: 0; outline: none; }
.page { max-width: var(--content-w); margin: 0 auto; }
.page.wide, .page.home { max-width: 1100px; }
.module-page { max-width: calc(var(--content-w) + 260px); display: grid; grid-template-columns: minmax(0, var(--content-w)) 220px; gap: 40px; }
.toc { position: sticky; top: calc(var(--topbar-h) + 24px); align-self: start; font-size: .86rem; }
.toc-title { font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; margin: 0 0 8px; }
.toc ol { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--border); }
.toc a { display: block; padding: 4px 12px; color: var(--text-muted); text-decoration: none; }
.toc a:hover { color: var(--text); }

/* ---------- Status dots & progress ---------- */
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; border: 2px solid var(--border); }
.dot.st-done { background: var(--good); border-color: var(--good); }
.dot.st-progress { background: var(--warn); border-color: var(--warn); }
.dot.st-ready { border-color: var(--accent); }
.pbar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.pbar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; transition: width .3s ease; }

/* ---------- Buttons, chips, badges ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .93rem; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); background: transparent; }
.btn-lg { min-height: 48px; padding: 10px 22px; font-size: 1rem; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; color: var(--text-muted); }
.chip-full { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.chip-outline { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-3); color: var(--text-muted); vertical-align: 1px; }
.badge-try { background: var(--accent-2); color: var(--accent-ink); }
.badge-done { background: var(--good); color: var(--accent-ink); }
.badge-paper { background: color-mix(in srgb, var(--class-a) 25%, var(--surface-2)); color: var(--text); }
.badge-course { background: color-mix(in srgb, var(--accent) 25%, var(--surface-2)); color: var(--text); }
.badge-docs { background: color-mix(in srgb, var(--class-b) 25%, var(--surface-2)); color: var(--text); }
.badge-book { background: color-mix(in srgb, var(--good) 25%, var(--surface-2)); color: var(--text); }
.badge-code { background: color-mix(in srgb, var(--warn) 25%, var(--surface-2)); color: var(--text); }
.badge-article { background: color-mix(in srgb, var(--accent-2) 25%, var(--surface-2)); color: var(--text); }
.tag-outline { font-size: .7rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; margin-left: 6px; }

/* ---------- Home ---------- */
.hero { padding: 24px 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: .75rem; font-weight: 700; color: var(--accent-2); margin: 0; }
.eyebrow a { color: inherit; text-decoration: none; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); margin: .15em 0 .3em; background: linear-gradient(90deg, var(--text), var(--accent-strong)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { font-size: 1.12rem; color: var(--text-muted); max-width: 66ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 22px 0; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px 28px; list-style: none; padding: 0; color: var(--text-muted); }
.hero-stats strong { color: var(--text); font-size: 1.15rem; }
.how-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; padding: 0; list-style: none; counter-reset: s; }
.how-steps li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 16px 52px; position: relative; counter-increment: s; }
.how-steps li::before { content: counter(s); position: absolute; left: 16px; top: 16px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .8rem; }
.phase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.phase-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.phase-card h3 { margin: 0; }
.phase-card p { margin: 0; color: var(--text-muted); font-size: .93rem; }
.phase-card-head { display: flex; justify-content: space-between; align-items: center; }
.phase-n { font-weight: 700; font-size: .78rem; color: var(--accent-2); text-transform: uppercase; letter-spacing: .06em; }
.phase-mods { list-style: none; padding: 0; margin: 6px 0 0; font-size: .92rem; }
.phase-mods li { padding: 3px 0; display: flex; align-items: center; }
.phase-mods a { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.phase-mods a:hover { color: var(--accent-strong); }
.settings { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; margin: 0 auto 20px; max-width: 1100px; }

/* ---------- Module ---------- */
.mod-header { padding-bottom: 8px; }
.mod-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.prereqs { font-size: .93rem; margin-bottom: 12px; }
.ok-mark { color: var(--good); }
.opener { font-size: 1.2rem; line-height: 1.6; border-left: 4px solid var(--accent); padding: 4px 0 4px 18px; margin: 18px 0; color: var(--text); }
.objectives li { margin: 4px 0; }
.mod-section { scroll-margin-top: calc(var(--topbar-h) + 12px); }
.mod-section > h2 { padding-top: 10px; border-top: 1px solid var(--border); }
code.inline { font-family: var(--mono); font-size: .88em; padding: .1em .38em; border-radius: 5px; background: var(--surface-3); }
.math { font-family: var(--mono); font-size: 1rem; text-align: center; padding: 12px; margin: 14px 0; border-radius: var(--radius-sm); background: var(--surface-2); overflow-x: auto; white-space: pre; }
.note { border: 1px solid var(--border); border-left: 4px solid var(--accent-2); background: var(--surface); border-radius: var(--radius-sm); padding: 10px 14px; margin: 16px 0; }
.note-warn { border-left-color: var(--warn); }
.note-tip { border-left-color: var(--good); }
.note-title { display: block; margin-bottom: 2px; }
.note p, .note div { margin: 0; }
.table-wrap { overflow-x: auto; margin: 14px 0; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; }
tr.total td { font-weight: 700; }

.code-fig { position: relative; margin: 14px 0; }
.code-fig figcaption { font-size: .8rem; color: var(--text-muted); margin-bottom: 4px; }
pre.code { margin: 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; font: .87rem/1.55 var(--mono); }
.copy-btn { position: absolute; right: 8px; bottom: calc(100% - 38px); z-index: 1; font-size: .72rem; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); cursor: pointer; opacity: .8; }
.code-fig figcaption + .copy-btn { bottom: auto; top: 30px; }
.copy-btn:hover { opacity: 1; color: var(--text); }
.tk-kw { color: var(--tk-kw); }
.tk-str { color: var(--tk-str); }
.tk-num { color: var(--tk-num); }
.tk-com { color: var(--tk-com); font-style: italic; }
.tk-fn { color: var(--tk-fn); }

/* ---------- Widgets ---------- */
.widget-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; box-shadow: var(--shadow); }
.widget-head { display: flex; align-items: center; gap: 10px; }
.widget-head h3 { margin: 0; }
.widget-caption { color: var(--text-muted); font-size: .93rem; margin: 6px 0 12px; }
.widget-root { display: grid; gap: 12px; }
.wcanvas { width: 100%; height: auto; display: block; border-radius: var(--radius-sm); border: 1px solid var(--border); touch-action: none; background: var(--surface-2); }
.ctl-row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; }
.ctl { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 10px; min-width: 200px; flex: 1 1 200px; font-size: .88rem; }
.ctl label { color: var(--text-muted); white-space: nowrap; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); min-height: 28px; }
.ctl-val { font-family: var(--mono); font-size: .85rem; min-width: 4.5ch; text-align: right; color: var(--text); }
.ctl select, .widget-root input[type=text], .widget-root input[type=number], .widget-root textarea {
  font: inherit; font-size: .9rem; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); min-height: 36px;
}
.ctl select { grid-column: 2 / 4; }
.ctl-check { grid-template-columns: auto 1fr; min-width: 0; flex: 0 1 auto; }
.ctl-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.ctl-check label { color: var(--text); }
.widget-root .wide-input { width: 100%; }
.readout { font-family: var(--mono); font-size: .86rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; white-space: pre-wrap; overflow-x: auto; }
.readout .good { color: var(--good); }
.readout .bad { color: var(--bad); }
.readout .hl { color: var(--accent-strong); font-weight: 700; }
.w-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.w-cells { display: flex; flex-wrap: wrap; gap: 4px; font-family: var(--mono); }
.w-cell { min-width: 38px; padding: 6px 8px; text-align: center; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); font-size: .85rem; }
.w-cell.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.w-cell.alt { background: var(--accent-2); color: var(--accent-ink); border-color: var(--accent-2); }
.w-label { font-size: .78rem; color: var(--text-muted); margin: 0 0 4px; }
.token-chips { display: flex; flex-wrap: wrap; gap: 3px; font-family: var(--mono); font-size: .9rem; line-height: 1.2; }
.token-chip { padding: 4px 5px; border-radius: 5px; white-space: pre; border: 1px solid transparent; }
.heatmap { display: grid; gap: 2px; font-family: var(--mono); font-size: .75rem; overflow-x: auto; }
.heatmap button, .heatmap span:not(.w-cell) { border: 0; padding: 4px 2px; border-radius: 4px; text-align: center; font: inherit; color: var(--text); background: transparent; min-width: 0; }
.heatmap button { cursor: pointer; }
.heatmap .hm-cell { color: var(--text); }
.heatmap .hm-row.sel { outline: 2px solid var(--accent-2); }
.trace { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: .88rem; }
.trace li { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.trace .t-kind { font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; margin-right: 6px; }
.t-think .t-kind { color: var(--accent-strong); }
.t-tool .t-kind { color: var(--accent-2); }
.t-obs .t-kind { color: var(--warn); }
.t-final .t-kind { color: var(--good); }
.t-bad .t-kind { color: var(--bad); }
.git-graph { overflow-x: auto; }

/* ---------- Exercise ---------- */
.exercise { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.exercise-head { display: flex; align-items: center; gap: 10px; }
.exercise-head h3 { margin: 0; }
.editor-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin: 12px 0 10px; }
.editor-bar { display: flex; justify-content: space-between; padding: 6px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: .78rem; }
.lang-tag { font-weight: 700; color: var(--accent-2); }
.editor { display: block; width: 100%; border: 0; resize: vertical; padding: 12px 14px; background: var(--code-bg); color: var(--text); font: .87rem/1.55 var(--mono); tab-size: 4; white-space: pre; overflow-x: auto; }
.editor:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; border-radius: 0; }
.run-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.run-status { font-size: .88rem; color: var(--text-muted); }
.run-status.ok { color: var(--good); font-weight: 600; }
.run-status.bad { color: var(--bad); font-weight: 600; }
.run-output { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font: .84rem/1.5 var(--mono); white-space: pre-wrap; overflow-x: auto; margin: 10px 0 0; max-height: 360px; overflow-y: auto; }
.run-output:empty { display: none; }
.run-err { color: var(--bad); }
.checks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; font-size: .9rem; }
.checks:empty { display: none; }
.checks li { padding: 6px 10px; border-radius: 7px; background: var(--surface-2); }
.checks .pass .check-icon { color: var(--good); font-weight: 700; }
.checks .fail .check-icon { color: var(--bad); font-weight: 700; }
.checks .hint { color: var(--text-muted); }
details { margin-top: 10px; }
details > summary { cursor: pointer; color: var(--accent-strong); font-weight: 600; font-size: .93rem; padding: 4px 0; }
.runner-frame { position: absolute; width: 0; height: 0; border: 0; visibility: hidden; }

/* ---------- Quiz ---------- */
.quiz-q { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; margin: 0 0 12px; background: var(--surface); }
.quiz-q legend { font-weight: 600; padding: 0 6px; margin-left: -6px; max-width: 100%; }
.qnum { color: var(--accent-2); }
.quiz-opt { display: flex; gap: 10px; align-items: flex-start; padding: 6px 8px; border-radius: 8px; }
.quiz-opt input { margin-top: 5px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.quiz-opt label { cursor: pointer; }
.quiz-opt:hover { background: var(--surface-2); }
.quiz-opt.opt-correct { background: color-mix(in srgb, var(--good) 16%, transparent); }
.quiz-opt.opt-picked-wrong { background: color-mix(in srgb, var(--bad) 16%, transparent); }
.quiz-q.is-right { border-color: color-mix(in srgb, var(--good) 60%, var(--border)); }
.quiz-q.is-wrong { border-color: color-mix(in srgb, var(--bad) 60%, var(--border)); }
.quiz-feedback { font-size: .92rem; margin-top: 6px; }
.quiz-feedback:empty { display: none; }
.is-right .quiz-feedback strong { color: var(--good); }
.is-wrong .quiz-feedback strong { color: var(--bad); }
.quiz-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.quiz-score { margin: 0; font-weight: 600; }
.quiz-score.perfect { color: var(--good); }

/* ---------- Sources, mastery, footer ---------- */
.sources { list-style: none; padding: 0; display: grid; gap: 10px; }
.sources li { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.src-note { color: var(--text-muted); font-size: .9rem; }
.mastery { list-style: none; padding: 0; display: grid; gap: 6px; }
.mastery li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.mastery input { width: 20px; height: 20px; margin-top: 3px; flex: none; accent-color: var(--good); }
.mastery label { cursor: pointer; }
.mod-footer { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--border); display: grid; gap: 16px; }
.mod-footer > .btn { justify-self: start; }
.prevnext { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Glossary ---------- */
.gloss { border-bottom: 1.5px dotted var(--accent-2); cursor: help; }
.gloss:hover { color: var(--accent-2); }
.tooltip { position: absolute; z-index: 80; background: var(--surface-3); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-size: .88rem; line-height: 1.5; display: grid; gap: 2px; pointer-events: none; }
.letters { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0 20px; }
.letters a { padding: 2px 9px; border-radius: 6px; background: var(--surface-2); text-decoration: none; font-weight: 600; }
.glossary { margin: 0; }
.gl-entry { padding: 12px 0; border-bottom: 1px solid var(--border); scroll-margin-top: calc(var(--topbar-h) + 16px); }
.gl-entry dt { font-weight: 700; }
.gl-entry dd { margin: 2px 0 0; color: var(--text-muted); }
.gl-used { display: block; font-size: .85rem; margin-top: 2px; }
.gl-entry.flash { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 8px; padding-left: 10px; }

/* ---------- Map ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; list-style: none; padding: 0; font-size: .88rem; color: var(--text-muted); }
.legend li { display: flex; align-items: center; gap: 7px; }
.map-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 8px; }
.map-svg { width: 100%; height: auto; display: block; font-family: var(--font); }
.map-band.even { fill: var(--surface-2); }
.map-band.odd { fill: transparent; }
.map-phase-n { fill: var(--accent-2); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.map-phase-t { fill: var(--text); font-size: 12.5px; font-weight: 600; }
.map-edge { fill: none; stroke: var(--text-muted); stroke-width: 1.4; opacity: .45; transition: opacity .15s; }
.map-edge.hi { stroke: var(--accent-strong); opacity: 1; stroke-width: 2.2; }
.map-edge.dim { opacity: .12; }
.map-arrow { fill: var(--text-muted); }
.map-node rect { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; transition: stroke .15s; }
.map-node.is-full rect { stroke-width: 2; }
.map-node:hover rect, .map-node:focus rect { stroke: var(--accent); }
.map-node:focus { outline: none; }
.map-node:focus-visible rect { stroke: var(--accent-2); stroke-width: 3; }
.map-node.st-done rect { fill: color-mix(in srgb, var(--good) 18%, var(--surface)); stroke: var(--good); }
.map-node.st-progress rect { stroke: var(--warn); }
.map-node.st-ready rect { stroke: var(--accent); }
.map-node-t { fill: var(--text); font-size: 12.5px; font-weight: 600; }
.map-node-h { fill: var(--text-muted); font-size: 10.5px; }
.map-check { fill: var(--good); font-size: 14px; font-weight: 700; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--surface-3); color: var(--text); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 90; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .module-page { grid-template-columns: minmax(0, 1fr); max-width: var(--content-w); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-grid; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: 0; width: min(86vw, 320px); height: auto; z-index: 60; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; }
  .scrim:not([hidden]) { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0, 0, 0, .45); z-index: 55; }
  .top-links { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .brand span { display: none; }
  .search { max-width: none; }
  main { padding: 20px 14px 60px; }
  .widget-card, .exercise { padding: 12px; margin-left: -4px; margin-right: -4px; }
  .ctl { min-width: 100%; }
  .opener { font-size: 1.08rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .sidebar, .toc, .run-actions, .editor-wrap { display: none; }
  .layout { display: block; }
}
