/* RL Step by Step — stylesheet.
 * Semantic colours: reward (amber), gamma/discount (blue), value (green), policy (violet),
 * delta/advantage/error (rose), step size (slate). They are used identically in text, math and charts.
 */
:root {
  --bg: #f6f5ef; --paper: #fffefa; --paper-2: #f1f0e8; --paper-3: #e9e8de;
  --ink: #17302a; --ink-2: #2f463e; --muted: #5d6c65; --faint: #8a968f;
  --line: #dde1d6; --line-2: #c8cfc2;
  --brand: #1b6b50; --brand-ink: #ffffff; --brand-soft: #e5f0e9; --brand-2: #145740;
  --reward: #9a5a0a; --reward-soft: #fbefdb; --reward-line: #e8c48d;
  --gamma: #2a6694; --gamma-soft: #e5eff8; --gamma-line: #9dc0de;
  --value: #17704c; --value-soft: #e0f1e7; --value-line: #93cbb0;
  --policy: #6a4fa6; --policy-soft: #eee8f8; --policy-line: #bfb0e3;
  --delta: #ad3445; --delta-soft: #f9e3e6; --delta-line: #e5a3ad;
  --step: #55616b; --step-soft: #eaedef; --step-line: #b9c2c9;
  --muted-tone: #6f7b75;
  --ok: #17704c; --ok-soft: #e0f1e7; --bad: #ad3445; --bad-soft: #f9e3e6; --warn: #9a5a0a; --warn-soft: #fbefdb;
  --focus: #c1801f;
  --shadow-1: 0 1px 2px rgba(23, 48, 42, .06);
  --shadow-2: 0 1px 2px rgba(23, 48, 42, .05), 0 10px 30px rgba(23, 48, 42, .07);
  --radius: 18px; --radius-md: 14px; --radius-sm: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-math: "STIX Two Math", "STIX Two Text", "Cambria Math", "Latin Modern Math", "Times New Roman", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --header-h: 60px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1613; --paper: #15201c; --paper-2: #1b2823; --paper-3: #23332c;
  --ink: #e6eee8; --ink-2: #cbd7cf; --muted: #9aaea4; --faint: #71857b;
  --line: #29392f; --line-2: #36493e;
  --brand: #5dc49a; --brand-ink: #0a1812; --brand-soft: #193127; --brand-2: #7fd6b1;
  --reward: #e4a651; --reward-soft: #36270f; --reward-line: #7a5a2a;
  --gamma: #82b8e6; --gamma-soft: #16263a; --gamma-line: #3b5f82;
  --value: #5dc49a; --value-soft: #143026; --value-line: #2f6b52;
  --policy: #b6a0f2; --policy-soft: #251f3c; --policy-line: #57488c;
  --delta: #f08c98; --delta-soft: #3a1c22; --delta-line: #8a3d48;
  --step: #a9b5bf; --step-soft: #222c34; --step-line: #4b5864;
  --muted-tone: #93a39b;
  --ok: #5dc49a; --ok-soft: #143026; --bad: #f08c98; --bad-soft: #3a1c22; --warn: #e4a651; --warn-soft: #36270f;
  --focus: #e4a651;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font-sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1, h2, h3, h4 { color: var(--ink); margin: 0; font-weight: 600; }
h1 { font: 600 clamp(30px, 4.2vw, 46px)/1.1 var(--font-serif); letter-spacing: -0.6px; }
h2 { font: 600 clamp(24px, 2.8vw, 31px)/1.2 var(--font-serif); letter-spacing: -0.3px; }
h3 { font-size: 18px; line-height: 1.35; }
h4 { font-size: 15px; line-height: 1.4; }
p { margin: 0 0 .85em; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-2); }
.ext { font-size: .8em; margin-left: 2px; opacity: .7; }
code { font-family: var(--font-mono); font-size: .88em; background: var(--paper-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 6px; }
strong { font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; line-height: 1.55; }
.eyebrow { font-size: 11.5px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--brand); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 40; height: var(--header-h); display: flex; align-items: center; gap: 18px; padding: 0 clamp(14px, 3vw, 28px); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; white-space: nowrap; }
.brand:hover { color: var(--ink); }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; }
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); letter-spacing: .2px; margin-top: -2px; }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { position: relative; text-decoration: none; color: var(--ink-2); font-weight: 550; font-size: 14.5px; padding: 8px 12px; border-radius: 999px; white-space: nowrap; }
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-2); }
:root[data-theme="dark"] .nav a[aria-current="page"] { color: var(--brand); }
.nav .badge { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 5px; font-size: 11px; font-weight: 750; border-radius: 99px; background: var(--reward); color: var(--paper); vertical-align: 1px; }
.theme-btn { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; width: 38px; height: 38px; display: grid; place-items: center; flex: none; }
.theme-btn svg { width: 18px; height: 18px; }

/* ---------- layout ---------- */
main { display: block; min-height: calc(100vh - var(--header-h) - 80px); }
main:focus, main:focus-visible { outline: none; }
[tabindex="-1"]:focus { outline: none; }
.page { max-width: 1180px; margin: 0 auto; padding: clamp(22px, 4vw, 44px) clamp(16px, 3.4vw, 32px) 64px; }
.page-narrow { max-width: 860px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head p { color: var(--muted); max-width: 64ch; margin: 10px 0 0; font-size: 17px; }
.footer { border-top: 1px solid var(--line); padding: 20px clamp(16px, 3vw, 28px); color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.footer a { color: var(--muted); }
.banner { max-width: 1180px; margin: 12px auto 0; padding: 0 clamp(16px, 3.4vw, 32px); }
.banner > div { background: var(--warn-soft); border: 1px solid var(--reward-line); color: var(--ink); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---------- buttons & controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--paper); color: var(--ink); font-weight: 600; font-size: 14.5px; line-height: 1.2; text-decoration: none; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--paper-2); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-danger { color: var(--bad); border-color: var(--delta-line); }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13.5px; }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: 16px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.linkbtn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 0; text-decoration: underline; text-underline-offset: 3px; }

.ctl { display: grid; gap: 6px; min-width: 0; }
.ctl-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ctl-label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.ctl-value { font: 650 14px var(--font-mono); color: var(--ink); background: var(--paper-2); border-radius: 6px; padding: 1px 7px; }
.ctl-hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.ctl.is-disabled { opacity: .5; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: var(--line); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--paper); border: 2px solid var(--brand); box-shadow: var(--shadow-1); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 2px solid var(--brand); }
.ctl.tone-gamma input[type=range]::-webkit-slider-thumb { border-color: var(--gamma); }
.ctl.tone-policy input[type=range]::-webkit-slider-thumb { border-color: var(--policy); }
.ctl.tone-reward input[type=range]::-webkit-slider-thumb { border-color: var(--reward); }
.ctl.tone-value input[type=range]::-webkit-slider-thumb { border-color: var(--value); }
.ctl.tone-delta input[type=range]::-webkit-slider-thumb { border-color: var(--delta); }
.ctl.tone-step input[type=range]::-webkit-slider-thumb { border-color: var(--step); }
.ctl.tone-gamma .ctl-value { color: var(--gamma); background: var(--gamma-soft); }
.ctl.tone-policy .ctl-value { color: var(--policy); background: var(--policy-soft); }
.ctl.tone-reward .ctl-value { color: var(--reward); background: var(--reward-soft); }
.ctl.tone-value .ctl-value { color: var(--value); background: var(--value-soft); }
.ctl.tone-delta .ctl-value { color: var(--delta); background: var(--delta-soft); }
.ctl.tone-step .ctl-value { color: var(--step); background: var(--step-soft); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; }
.seg-btn { border: 0; background: transparent; border-radius: 9px; padding: 6px 11px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); min-height: 32px; }
.seg-btn:hover { background: var(--paper); }
.seg-btn.active { background: var(--paper); color: var(--ink); box-shadow: 0 0 0 1px var(--line-2), var(--shadow-1); }
.seg-btn:disabled { cursor: default; }
.select { appearance: none; -webkit-appearance: none; border: 1px solid var(--line-2); background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7a72' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center; border-radius: 10px; padding: 8px 34px 8px 12px; min-height: 40px; }
.ctl-check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.ctl-check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------- tones ---------- */
.tone-reward { --tone: var(--reward); --tone-soft: var(--reward-soft); --tone-line: var(--reward-line); }
.tone-gamma { --tone: var(--gamma); --tone-soft: var(--gamma-soft); --tone-line: var(--gamma-line); }
.tone-value { --tone: var(--value); --tone-soft: var(--value-soft); --tone-line: var(--value-line); }
.tone-policy { --tone: var(--policy); --tone-soft: var(--policy-soft); --tone-line: var(--policy-line); }
.tone-delta { --tone: var(--delta); --tone-soft: var(--delta-soft); --tone-line: var(--delta-line); }
.tone-step { --tone: var(--step); --tone-soft: var(--step-soft); --tone-line: var(--step-line); }
.tone-ok { --tone: var(--ok); --tone-soft: var(--ok-soft); --tone-line: var(--value-line); }
.tone-bad { --tone: var(--bad); --tone-soft: var(--bad-soft); --tone-line: var(--delta-line); }
.tone-muted { --tone: var(--muted-tone); --tone-soft: var(--paper-2); --tone-line: var(--line-2); }
.c-reward { color: var(--reward); } .c-gamma { color: var(--gamma); } .c-value { color: var(--value); }
.c-policy { color: var(--policy); } .c-delta { color: var(--delta); } .c-step { color: var(--step); }

/* ---------- math ---------- */
.math { font-family: var(--font-math); font-size: 1.08em; white-space: normal; line-height: 1; }
.math .m-g, .math sub, .math sup, .math .m-ss, .math .m-c, .math .m-tip, .math .m-frac { white-space: nowrap; }
.math-display { margin: 18px 0; padding: 16px 18px; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-md); text-align: center; overflow-x: auto; }
.math-display .math { font-size: 1.28em; line-height: 1.9; white-space: normal; }
.math-error { color: var(--bad); font-family: var(--font-mono); font-size: .85em; }
.m-v { font-style: italic; }
.m-n, .m-ord, .m-fn, .m-text { font-style: normal; }
.m-fn { margin: 0 .08em; }
.m-text { font-family: var(--font-sans); font-size: .82em; }
.m-it { font-style: italic; }
.m-op { margin: 0 .22em; }
.m-rel { margin: 0 .3em; }
.m-big { font-size: 1.25em; margin: 0 .08em; vertical-align: -0.08em; }
.m-punct { margin-right: .18em; }
.m-sub, .m-sup { font-size: .72em; line-height: 0; }
sub.m-sub { vertical-align: -.35em; }
sup.m-sup { vertical-align: .55em; }
.m-sub .m-op, .m-sup .m-op, .m-sub .m-rel, .m-sup .m-rel { margin: 0 .08em; }
/* Stacked super- and subscript: the box's baseline is the superscript's, so raise it. */
.m-ss { display: inline-flex; flex-direction: column; vertical-align: .42em; line-height: 1.05; margin-left: .05em; }
.m-ss .m-sup, .m-ss .m-sub { line-height: 1.05; }
.m-frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .12em; line-height: 1.15; }
.m-num { padding: 0 .15em .08em; border-bottom: 1px solid currentColor; }
.m-den { padding: .08em .15em 0; }
.math-display .m-frac { font-size: .92em; }
.m-sqrt { white-space: nowrap; }
.m-rad { border-top: 1px solid currentColor; padding: 0 .1em; }
.m-acc { position: relative; display: inline-block; }
.m-acc-hat::before, .m-acc-widehat::before { content: "^"; position: absolute; left: 0; right: 0; top: -.62em; text-align: center; font-size: .8em; }
.m-acc-bar, .m-acc-overline { border-top: 1px solid currentColor; }
.m-ub { display: inline-flex; flex-direction: column; align-items: center; vertical-align: top; margin: 0 .06em; }
.m-ub-body { border-bottom: 1.5px solid currentColor; border-radius: 0 0 8px 8px; padding: 0 .12em .12em; }
.m-ub-label { font-family: var(--font-sans); font-size: .58em; line-height: 1.3; margin-top: .25em; color: var(--muted); white-space: nowrap; font-style: normal; }
.m-boxed { border: 1px solid currentColor; padding: .1em .3em; border-radius: 4px; }
.m-xarrow { display: inline-flex; flex-direction: column; align-items: center; vertical-align: -.05em; margin: 0 .25em; line-height: 1; }
.m-xarrow-label { font-size: .68em; padding: 0 .3em; margin-bottom: -.12em; }
.m-xarrow-arrow { font-size: 1.1em; }
.m-hl { background: color-mix(in srgb, var(--reward) 16%, transparent); border-radius: 4px; padding: 0 .12em; }
.m-sp1 { margin-left: .17em; } .m-sp2 { margin-left: .22em; } .m-sp3 { margin-left: .28em; }
.m-quad { margin-left: 1em; } .m-qquad { margin-left: 2em; }
.m-not { text-decoration: line-through; }
.m-c { font-weight: 500; }
.m-c-reward { color: var(--reward); } .m-c-gamma { color: var(--gamma); } .m-c-value { color: var(--value); }
.m-c-policy { color: var(--policy); } .m-c-delta { color: var(--delta); } .m-c-step { color: var(--step); } .m-c-muted { color: var(--muted-tone); }
.m-tip { border-bottom: 1.5px dotted currentColor; cursor: help; border-radius: 2px; }
.m-tip:hover, .m-tip:focus { background: color-mix(in srgb, currentColor 12%, transparent); outline: none; }

/* ---------- glossary terms & popover ---------- */
.term { font: inherit; color: inherit; background: none; border: 0; padding: 0; border-bottom: 1.5px dotted var(--brand); cursor: help; }
.term:hover, .term:focus-visible { color: var(--brand-2); background: var(--brand-soft); border-radius: 3px; }
:root[data-theme="dark"] .term:hover { color: var(--brand); }
.term-missing { border-bottom: 1.5px dashed var(--bad); }
.popover { position: fixed; z-index: 90; max-width: min(340px, calc(100vw - 24px)); background: var(--ink); color: var(--paper); padding: 11px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; box-shadow: 0 12px 34px rgba(0, 0, 0, .22); pointer-events: auto; }
.popover b { color: var(--paper); display: block; margin-bottom: 2px; }
.popover a { color: color-mix(in srgb, var(--paper) 80%, var(--brand)); }
.popover .math { color: var(--paper); }
.popover .m-c { color: var(--paper); }
.popover-foot { margin-top: 6px; font-size: 12.5px; opacity: .8; }

/* ---------- home ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: clamp(20px, 4vw, 44px); align-items: center; margin-bottom: 38px; }
.hero h1 { margin: 10px 0 14px; }
.hero-lead { font-size: 18.5px; color: var(--ink-2); max-width: 36em; }
.hero-art { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-2); }
.hero-art figcaption { font-size: 13px; color: var(--muted); padding: 4px 6px 2px; }
.progress-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 26px 0 8px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 14px 16px; }
.stat b { display: block; font: 650 25px/1.2 var(--font-serif); }
.stat span { font-size: 13px; color: var(--muted); }
.method { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 10px 0 40px; }
.method-step { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 16px; }
.method-step .num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; font-size: 13px; margin-bottom: 8px; background: var(--tone-soft, var(--brand-soft)); color: var(--tone, var(--brand)); }
.method-step h3 { font-size: 16px; margin-bottom: 4px; }
.method-step p { font-size: 14px; color: var(--muted); margin: 0; }
.part { margin-top: 34px; }
.part-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.part-head h2 { font-size: 24px; }
.part-head p { color: var(--muted); margin: 0; }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.module-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 12px; box-shadow: var(--shadow-1); display: flex; flex-direction: column; }
.module-card header { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.module-num { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font: 700 16px var(--font-serif); background: var(--brand-soft); color: var(--brand-2); }
:root[data-theme="dark"] .module-num { color: var(--brand); }
.module-card h3 { font-size: 17.5px; }
.module-card .summary { font-size: 14px; color: var(--muted); margin: 3px 0 0; }
.module-bar { height: 5px; border-radius: 5px; background: var(--paper-3); overflow: hidden; margin: 10px 0 8px; }
.module-bar i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
.lesson-list { list-style: none; padding: 0; margin: 4px 0 0; }
.lesson-list li + li { border-top: 1px solid var(--line); }
.lesson-link { display: flex; align-items: center; gap: 10px; padding: 9px 4px; text-decoration: none; color: var(--ink); border-radius: 8px; }
.lesson-link:hover { background: var(--paper-2); color: var(--ink); }
.lesson-link .title { flex: 1; font-size: 14.5px; font-weight: 550; }
.lesson-link .mins { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.lesson-link.is-pending { opacity: .55; }
.status { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--paper); }
.status.s-started { border-color: var(--brand); background: conic-gradient(var(--brand) 0 50%, transparent 50% 100%); }
.status.s-done { border-color: var(--brand); background: var(--brand); }
.status.s-mastered { border-color: var(--reward); background: var(--reward); }
.status.s-done::after { content: "✓"; color: var(--brand-ink); }
.status.s-mastered::after { content: "★"; color: var(--paper); font-size: 10px; }
.legend-row { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); align-items: center; }
.legend-row span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- lesson ---------- */
.lesson-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 40px; max-width: 1180px; margin: 0 auto; padding: 28px clamp(16px, 3.4vw, 32px) 64px; }
.rail { position: sticky; top: calc(var(--header-h) + 20px); align-self: start; max-height: calc(100vh - var(--header-h) - 40px); overflow: auto; padding-right: 4px; }
.rail-mod { font-size: 12px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--brand); margin: 0 0 4px; }
.rail h2 { font: 600 19px/1.3 var(--font-serif); margin-bottom: 12px; }
.rail .lesson-link { padding: 8px 8px; }
.rail .lesson-link.is-current { background: var(--brand-soft); }
.rail .lesson-link .title { font-size: 14px; }
.rail-links { margin-top: 18px; display: grid; gap: 6px; font-size: 14px; }
.lesson-main { min-width: 0; max-width: 780px; }
.lesson-head { margin-bottom: 22px; }
.crumbs { font-size: 13.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.lesson-head h1 { font-size: clamp(30px, 3.6vw, 40px); margin-bottom: 12px; }
.lesson-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.objectives { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 16px 18px 12px; margin: 18px 0 8px; }
.objectives h2 { font: 700 12px/1 var(--font-sans); letter-spacing: 1.3px; text-transform: uppercase; color: var(--brand); margin-bottom: 10px; }
.objectives ul { margin: 0; padding-left: 20px; }
.objectives li { margin: 4px 0; }
.loopmini { display: inline-flex; align-items: center; gap: 8px; }
.loopmini svg { width: 44px; height: 44px; }
.loopmini .lm-dot { fill: var(--paper-3); stroke: var(--line-2); }
.loopmini .lm-dot.on { fill: var(--brand); stroke: var(--brand); }
.loopmini .lm-ring { fill: none; stroke: var(--line-2); stroke-width: 1.5; }
.loopmini-text { font-size: 13px; color: var(--muted); }
.loopmini-text b { color: var(--ink-2); }

.steps { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
/* Grid children must be allowed to shrink below their content's width (tables scroll, math wraps). */
.steps > *, .w-view > *, .w-controls > *, .quiz-list > *, .q-options > *, .metrics > *, .card-grid > *, .modules > * { min-width: 0; }
.step { animation: stepIn .35s ease both; }
@keyframes stepIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.step-text { font-size: 17px; line-height: 1.72; color: var(--ink); }
.step-text p { margin: 0 0 .9em; }
.step-text p:last-child { margin-bottom: 0; }
.step-text > .math-display:first-child { margin-top: 0; }
.step-text > .math-display:last-child { margin-bottom: 0; }
.md-h { font: 600 21px/1.3 var(--font-serif); margin: 8px 0 10px; }
h4.md-h { font: 700 15px/1.4 var(--font-sans); }
.md-list { margin: 0 0 .9em; padding-left: 1.3em; }
.md-list li { margin: .3em 0; }
.md-callout { border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 12px 16px; margin: 4px 0 .9em; }
.md-callout p:last-child { margin: 0; }
.step-figure { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.step-figure figcaption { font-size: 13.5px; color: var(--muted); margin-top: 8px; padding: 0 4px; }
.step-note { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper); }
.step-note > summary { cursor: pointer; padding: 13px 16px; font-weight: 650; font-size: 15px; list-style: none; display: flex; gap: 10px; align-items: center; }
.step-note > summary::-webkit-details-marker { display: none; }
.step-note > summary::before { content: "＋"; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--gamma-soft); color: var(--gamma); flex: none; }
.step-note[open] > summary::before { content: "−"; }
.step-note .note-kicker { font-size: 11px; font-weight: 750; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gamma); }
.step-note .note-body { padding: 0 18px 14px 48px; font-size: 15.5px; line-height: 1.65; }
.step-worked { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.step-worked h3 { font-size: 16px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 10px; }
.step-worked h3 .pill { background: var(--reward-soft); color: var(--reward); border-color: var(--reward-line); }
.worked-list { list-style: none; counter-reset: w; padding: 0; margin: 0 0 12px; }
.worked-list li { counter-increment: w; position: relative; padding: 8px 0 8px 40px; border-top: 1px dashed var(--line); animation: stepIn .3s ease both; }
.worked-list li:first-child { border-top: 0; }
.worked-list li::before { content: counter(w); position: absolute; left: 0; top: 8px; width: 26px; height: 26px; border-radius: 50%; background: var(--reward-soft); color: var(--reward); display: grid; place-items: center; font-size: 13px; font-weight: 750; }
.worked-list li p:last-child { margin: 0; }
.worked-list .math-display { margin: 8px 0; padding: 10px; }
.step-summary { background: linear-gradient(180deg, var(--brand-soft), transparent 140%); border: 1px solid var(--value-line); border-radius: var(--radius); padding: 18px 20px 10px; }
.step-summary h3 { font-size: 15px; letter-spacing: .3px; margin-bottom: 8px; }
.step-summary ul { margin: 0; padding-left: 20px; }
.step-summary li { margin: 6px 0; }
.frontier { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 26px 0 0; padding: 16px 0 0; border-top: 1px solid var(--line); }
.frontier .progress-text { font-size: 13.5px; color: var(--muted); }
.frontier .gate-hint { font-size: 13.5px; color: var(--reward); }
.lesson-progress { height: 4px; background: var(--paper-3); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.lesson-progress i { display: block; height: 100%; background: var(--brand); transition: width .3s; }
.quiz-section { margin-top: 36px; }
.quiz-head { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.quiz-head p { margin: 6px 0 0; color: var(--muted); }
.quiz-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.quiz-result { margin-top: 20px; border-radius: var(--radius); padding: 18px 20px; border: 1px solid var(--line); background: var(--paper); }
.quiz-result.is-mastered { border-color: var(--reward-line); background: linear-gradient(180deg, var(--reward-soft), var(--paper) 90%); }
.quiz-result h3 { font: 600 22px/1.25 var(--font-serif); margin-bottom: 6px; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.lesson-nav a { text-decoration: none; display: grid; gap: 2px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper); color: var(--ink); max-width: 48%; }
.lesson-nav a:hover { border-color: var(--line-2); background: var(--paper-2); }
.lesson-nav small { color: var(--muted); font-size: 12px; }
.lesson-nav .next { margin-left: auto; text-align: right; }
.deeper { margin-top: 22px; font-size: 14px; color: var(--muted); }
.deeper a { font-weight: 600; }

/* ---------- questions ---------- */
.q-card { background: var(--paper); border: 1px solid var(--line); border-left: 5px solid var(--gamma); border-radius: var(--radius-md); padding: 16px 18px; box-shadow: var(--shadow-1); }
.q-ctx-predict { border-left-color: var(--policy); }
.q-ctx-quiz { border-left-color: var(--brand); }
.q-ctx-review, .q-ctx-practice { border-left-color: var(--reward); }
.q-card.is-correct { border-left-color: var(--ok); }
.q-card.is-wrong { border-left-color: var(--bad); }
.q-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.q-kicker { font-size: 11.5px; font-weight: 750; letter-spacing: 1.3px; text-transform: uppercase; color: var(--gamma); }
.q-ctx-predict .q-kicker { color: var(--policy); }
.q-ctx-quiz .q-kicker { color: var(--brand); }
.q-ctx-review .q-kicker, .q-ctx-practice .q-kicker { color: var(--reward); }
.q-meta { font-size: 12.5px; color: var(--muted); }
.q-rand { color: var(--reward); }
.q-prompt { font-size: 16.5px; line-height: 1.6; margin-bottom: 12px; }
.q-prompt p:last-child { margin-bottom: 0; }
.q-instr { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.q-options { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.q-opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 11px 13px; background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; line-height: 1.5; font-size: 15.5px; transition: border-color .12s, background .12s; }
.q-opt:hover:not(:disabled) { border-color: var(--line-2); background: var(--paper-2); }
.q-opt-mark { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 12.5px; font-weight: 750; background: var(--paper-2); border: 1px solid var(--line-2); color: var(--ink-2); margin-top: -1px; }
.q-multi .q-opt-mark { border-radius: 6px; }
.q-opt.is-selected { border-color: var(--gamma); background: var(--gamma-soft); }
.q-opt.is-selected .q-opt-mark { background: var(--gamma); color: var(--paper); border-color: var(--gamma); }
.q-multi .q-opt.is-selected .q-opt-mark::after { content: "✓"; }
.q-ctx-predict .q-opt.is-selected { border-color: var(--policy); background: var(--policy-soft); }
.q-ctx-predict .q-opt.is-selected .q-opt-mark { background: var(--policy); border-color: var(--policy); }
.q-opt.is-right { border-color: var(--ok); background: var(--ok-soft); }
.q-opt.is-right .q-opt-mark { background: var(--ok); color: var(--paper); border-color: var(--ok); }
.q-opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-opt.is-wrong .q-opt-mark { background: var(--bad); color: var(--paper); border-color: var(--bad); }
.q-opt.is-truth { box-shadow: inset 0 0 0 1.5px var(--ok); }
.q-opt.is-truth::after { content: "What actually happens"; margin-left: auto; font-size: 11px; font-weight: 700; color: var(--ok); white-space: nowrap; align-self: center; }
.q-opt:disabled { cursor: default; opacity: 1; color: inherit; }
.q-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.q-feedback:empty { display: none; }
.q-feedback { margin-top: 12px; }
.fb { border-radius: 12px; padding: 12px 14px; font-size: 15px; line-height: 1.6; border: 1px solid var(--line); }
.fb p { margin: 6px 0 0; } .fb p:first-of-type { margin-top: 4px; }
.fb-title { display: block; }
.fb-ok { background: var(--ok-soft); border-color: var(--value-line); }
.fb-ok .fb-title { color: var(--ok); }
.fb-bad { background: var(--bad-soft); border-color: var(--delta-line); }
.fb-bad .fb-title { color: var(--bad); }
.fb-neutral { background: var(--policy-soft); border-color: var(--policy-line); }
.fb-neutral .fb-title { color: var(--policy); }
.fb-reveal { background: var(--paper-2); }
.fb-nudge { background: var(--warn-soft); border-color: var(--reward-line); }
.fb-explain { margin-top: 10px; padding-top: 10px; border-top: 1px solid color-mix(in srgb, currentColor 14%, transparent); }
.fb-explain p:last-child { margin-bottom: 0; }
.fb-list { margin: 8px 0 0; padding-left: 20px; }
.fb-list li { margin: 4px 0; }
.fb-hint { color: var(--ink-2); }
.fb-retry { font-size: 13.5px; color: var(--muted); }
.fb-details { margin-top: 8px; }
.fb-details summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--brand); }
.fb-reveal-body { margin-top: 8px; }
.q-numrow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.q-numlabel { font-weight: 600; font-size: 14.5px; }
.q-input { width: min(280px, 100%); font: 600 17px var(--font-mono); padding: 9px 12px; border: 1.5px solid var(--line-2); border-radius: 10px; background: var(--paper); }
.q-input:focus { border-color: var(--gamma); outline: none; box-shadow: 0 0 0 3px var(--gamma-soft); }
.q-card.is-correct .q-input { border-color: var(--ok); background: var(--ok-soft); }
.q-unit { color: var(--muted); }
.q-order { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.q-order-item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); }
.q-order-item.is-right { border-color: var(--ok); background: var(--ok-soft); }
.q-order-item.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-order-num { width: 24px; height: 24px; border-radius: 50%; background: var(--paper-2); display: grid; place-items: center; font-size: 12px; font-weight: 750; flex: none; }
.q-order-text { flex: 1; font-size: 15px; }
.q-order-btns { display: flex; gap: 2px; }
.q-order-btns .btn { min-height: 30px; padding: 4px 9px; }
.q-class { display: grid; gap: 10px; }
.q-class-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; }
.q-class-row.is-right { border-color: var(--ok); background: var(--ok-soft); }
.q-class-row.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-class-text { font-size: 15px; }
.q-class-fb:empty { display: none; }
.q-class-fb { grid-column: 1 / -1; font-size: 14px; color: var(--ink-2); }

/* ---------- labs ---------- */
.lab { margin: 0; background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow-2); overflow: hidden; }
.lesson-main .lab { margin-left: clamp(-60px, -4vw, 0px); margin-right: clamp(-60px, -4vw, 0px); }
.lab-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); background: var(--paper-2); }
.lab-kicker { font-size: 10.5px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; color: var(--paper); background: var(--brand); padding: 3px 8px; border-radius: 6px; }
.lab-title { font-weight: 650; font-size: 15px; flex: 1; }
.lab-body { padding: 18px; }
.lab-taskwrap { border-top: 1px solid var(--line); padding: 12px 18px 14px; background: color-mix(in srgb, var(--reward-soft) 55%, var(--paper)); }
.lab-taskhead { font-size: 11px; font-weight: 800; letter-spacing: 1.3px; text-transform: uppercase; color: var(--reward); margin-bottom: 6px; }
.lab-tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lab-task { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.lab-task-box { flex: none; width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--reward-line); margin-top: 2px; display: grid; place-items: center; background: var(--paper); transition: all .2s; }
.lab-task.is-done .lab-task-box { background: var(--ok); border-color: var(--ok); }
.lab-task.is-done .lab-task-box::after { content: "✓"; color: var(--paper); font-size: 12px; font-weight: 800; }
.lab-task.is-done .lab-task-text { color: var(--muted); }
.lab-task.is-done { animation: pop .4s ease; }
@keyframes pop { 40% { transform: scale(1.02); } }
.w-row { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 22px; align-items: start; }
.w-row.w-wide { grid-template-columns: minmax(0, 1fr); }
.w-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.w-view { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.w-caption { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.w-log { font-size: 14px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
.w-log b { color: var(--ink); }
.w-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.w-table th, .w-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
/* Header text is not uppercased: headers often contain symbols (γ, δ, Q^π) that must keep their case. */
.w-table th { font-size: 12.5px; letter-spacing: .2px; color: var(--muted); font-weight: 700; }
.w-table td.num, .w-table th.num { text-align: right; font-family: var(--font-mono); white-space: nowrap; }
.w-table tr.is-hl td { background: var(--reward-soft); }
.w-scroll { overflow-x: auto; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.metrics.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metrics.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { .metrics.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.metric { background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.metric-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric-value { font: 650 20px/1.2 var(--font-mono); color: var(--tone, var(--ink)); overflow-wrap: anywhere; }
.metric-foot { font-size: 12px; color: var(--muted); line-height: 1.35; }
.metric[class*="tone-"] { background: var(--tone-soft); border-color: var(--tone-line); }
.barrow { display: grid; grid-template-columns: minmax(90px, 150px) minmax(0, 1fr) 64px; gap: 10px; align-items: center; font-size: 14px; }
.barrow + .barrow { margin-top: 8px; }
.barrow-label { color: var(--ink-2); }
.barrow-track { position: relative; height: 12px; background: var(--paper-3); border-radius: 6px; overflow: hidden; }
.barrow-fill { position: absolute; top: 0; bottom: 0; background: var(--tone, var(--brand)); border-radius: 6px; transition: left .2s, width .2s; }
.barrow-zero { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink-2); opacity: .5; }
.barrow-val { font-family: var(--font-mono); text-align: right; color: var(--tone, var(--ink)); }
.barrow.is-hl .barrow-label { font-weight: 700; color: var(--ink); }
.callout { border-radius: 12px; padding: 11px 14px; font-size: 14.5px; line-height: 1.55; border: 1px solid var(--line); background: var(--paper-2); }
.callout-ok { background: var(--ok-soft); border-color: var(--value-line); }
.callout-bad { background: var(--bad-soft); border-color: var(--delta-line); }
.callout-warn { background: var(--warn-soft); border-color: var(--reward-line); }
.callout-info { background: var(--gamma-soft); border-color: var(--gamma-line); }
.callout-policy { background: var(--policy-soft); border-color: var(--policy-line); }
.callout p:last-child { margin: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 650; background: var(--tone-soft, var(--paper-2)); color: var(--tone, var(--ink-2)); border: 1px solid var(--tone-line, var(--line)); }
.kbd { font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; background: var(--paper); }

/* ---------- charts ---------- */
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { stroke: var(--line-2); stroke-width: 1.2; }
.chart-zero { stroke: var(--ink-2); stroke-width: 1; opacity: .45; }
.chart-tick { fill: var(--muted); font-size: 11.5px; font-family: var(--font-sans); }
.chart-label { fill: var(--ink-2); font-size: 12.5px; font-weight: 600; font-family: var(--font-sans); }
.chart-line { fill: none; stroke: var(--tone); stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.is-dash { stroke-dasharray: 7 5; stroke-width: 2; }
.chart-line.is-faint { stroke-width: 1.2; opacity: .35; }
.chart-dot { fill: var(--tone); stroke: var(--paper); stroke-width: 1.5; }
.chart-marker { fill: var(--tone); stroke: var(--paper); stroke-width: 2.5; }
.chart-band { fill: var(--tone); opacity: .14; stroke: none; }
.chart-shade { fill: var(--tone-soft); stroke: none; }
.chart-ref { stroke: var(--tone); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-reflabel { fill: var(--tone); font-size: 11.5px; font-weight: 650; font-family: var(--font-sans); }
.chart-bar { fill: var(--tone); opacity: .88; }
.chart-bar.is-hl { opacity: 1; stroke: var(--ink); stroke-width: 1.5; }
.chart-barval { fill: var(--ink-2); font-size: 12px; font-weight: 650; font-family: var(--font-mono); }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 18px; height: 3px; border-radius: 3px; background: var(--tone); display: inline-block; }
.chart-legend .is-dash i { background: repeating-linear-gradient(90deg, var(--tone) 0 5px, transparent 5px 8px); }

/* ---------- the Trail ---------- */
.trail { width: 100%; height: auto; display: block; font-family: var(--font-sans); }
/* On phones the diagram is drawn narrow, so enlarge its text (sizes are in viewBox units). */
@media (max-width: 600px) {
  .trail .trail-name { font-size: 25px; }
  .trail .trail-value { font-size: 22px; }
  .trail .trail-note, .trail .trail-enote { font-size: 17px; }
  .trail .trail-elabel { font-size: 19px; }
  .trail .trail-prob { font-size: 17px; }
  .trail .trail-end text { font-size: 18px; }
}
.trail-state rect { fill: var(--paper); stroke: var(--line-2); stroke-width: 1.6; transition: stroke .2s, fill .2s; }
.trail-state.is-hl rect { stroke: var(--brand); stroke-width: 3; fill: var(--brand-soft); }
.trail-state.is-agent rect { stroke: var(--policy); stroke-width: 3; }
.trail-name { font: 700 17px var(--font-sans); fill: var(--ink); }
.trail-value { font: 650 16px var(--font-mono); fill: var(--tone, var(--value)); }
.trail-value.is-unknown { fill: var(--faint); }
.trail-note { font-size: 12.5px; fill: var(--muted); }
.trail-end rect { fill: var(--paper-2); stroke: var(--line-2); stroke-width: 1.4; }
.trail-end.is-agent rect { stroke: var(--policy); stroke-width: 2.5; }
.trail-end text { font-size: 13.5px; fill: var(--muted); font-weight: 600; }
.trail-line { fill: none; stroke: var(--line-2); stroke-linecap: round; transition: stroke .2s, stroke-width .2s; }
.trail-arrowhead { fill: var(--line-2); }
.trail-hit { fill: none; stroke: transparent; stroke-width: 26; }
.trail-edge.is-hl .trail-line { stroke: var(--brand); }
.trail-edge.is-taken .trail-line { stroke: var(--policy); }
.trail-edge.is-faint .trail-line { opacity: .35; }
.trail-elabel { font-size: 13.5px; font-weight: 650; fill: var(--reward); }
.trail-prob { font: 600 12.5px var(--font-mono); fill: var(--policy); }
.trail-enote { font-size: 12px; fill: var(--muted); }
.trail-edge[role=button] { cursor: pointer; }
.trail-edge[role=button]:hover .trail-line, .trail-edge[role=button]:focus .trail-line { stroke: var(--policy); }
.trail-edge[role=button]:focus { outline: none; }
.trail-edge[role=button]:focus .trail-elabel { text-decoration: underline; }
.trail-agent circle { fill: var(--policy); stroke: var(--paper); stroke-width: 3; }
.trail-agent text { display: none; }

/* ---------- grid world ---------- */
.gridworld { width: 100%; height: auto; display: block; font-family: var(--font-sans); }
.gw-cell { fill: var(--paper); stroke: var(--line-2); stroke-width: 1; }
.gw-cell.is-wall { fill: var(--ink-2); }
.gw-cell.is-cliff { fill: var(--bad-soft); stroke: var(--delta-line); }
.gw-cell.is-goal { fill: var(--value-soft); stroke: var(--value-line); }
.gw-cell.is-hl { stroke: var(--reward); stroke-width: 3; }
.gw-heat { fill: var(--value); pointer-events: none; }
.gw-val { font: 600 10.5px var(--font-mono); fill: var(--ink-2); }
.gw-mark { font-size: 11px; font-weight: 700; fill: var(--bad); }
.gw-goal { fill: var(--value); font-size: 14px; }
.gw-start { fill: var(--policy); font-size: 12px; }
.gw-arrow { stroke: var(--ink-2); stroke-width: 2.2; stroke-linecap: round; }
.gw-arrowhead { fill: var(--ink-2); }
.gw-path { fill: none; stroke: var(--tone, var(--policy)); stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; opacity: .85; }
.gw-path.is-dash { stroke-dasharray: 7 6; }
.gw-agent { fill: var(--policy); stroke: var(--paper); stroke-width: 3; }

/* ---------- learning loop diagram ---------- */
.loop { width: 100%; height: auto; display: block; font-family: var(--font-sans); }
.loop-node rect { fill: var(--paper); stroke: var(--line-2); stroke-width: 1.5; transition: all .2s; }
.loop-node text { fill: var(--ink); }
.loop-node .loop-num { font-size: 11px; font-weight: 800; letter-spacing: 1.2px; fill: var(--brand); }
.loop-node .loop-name { font-size: 16px; font-weight: 700; }
.loop-node .loop-sub { font-size: 12.5px; fill: var(--muted); }
.loop-node.is-on rect { stroke: var(--brand); stroke-width: 3; fill: var(--brand-soft); }
.loop-node[role=button] { cursor: pointer; }
.loop-node[role=button]:hover rect, .loop-node[role=button]:focus rect { stroke: var(--brand); }
.loop-node[role=button]:focus { outline: none; }
.loop-edge { fill: none; stroke: var(--line-2); stroke-width: 2; }
.loop-edge.is-on { stroke: var(--brand); stroke-width: 3; }
.loop-arrowhead { fill: var(--line-2); }
.loop-center { font-family: var(--font-serif); font-size: 19px; fill: var(--ink); font-weight: 600; }
.loop-center-sub { font-size: 13px; fill: var(--muted); }

/* ---------- review / labs / glossary / reference ---------- */
.review-box { max-width: 780px; }
.review-progress { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.review-progress .lesson-progress { flex: 1; margin: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-1); }
.card h3 { font-size: 16.5px; margin-bottom: 4px; }
.card p { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
a.card { display: block; text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--line-2); transform: translateY(-1px); color: var(--ink); }
.card .card-foot { font-size: 12.5px; color: var(--muted); }
.search { width: min(420px, 100%); padding: 10px 14px; border: 1.5px solid var(--line-2); border-radius: 999px; background: var(--paper); font-size: 15px; }
.search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.gloss-list { display: grid; gap: 10px; margin-top: 18px; }
.gloss-item { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 14px 16px; }
.gloss-item:target, .gloss-item.is-target { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.gloss-item h3 { font-size: 16.5px; margin-bottom: 4px; }
.gloss-item p { margin: 0 0 6px; }
.gloss-item .gloss-meta { font-size: 13px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.letter-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 14px; }
.letter-nav a { font-size: 13px; font-weight: 700; text-decoration: none; padding: 3px 8px; border-radius: 6px; background: var(--paper-2); color: var(--ink-2); }
.notation-table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.notation-table th, .notation-table td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 15px; }
.notation-table th { background: var(--paper-2); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.notation-table td:first-child { white-space: nowrap; font-size: 17px; width: 1%; }
.algo-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-1); }
.algo-card + .algo-card { margin-top: 14px; }
.algo-card header { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.algo-card h3 { font: 600 22px var(--font-serif); }
.algo-steps { margin: 10px 0; padding-left: 22px; }
.algo-steps li { margin: 5px 0; }
.algo-roles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-top: 10px; }
.algo-role { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13.5px; }
.algo-role small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 18px; }
.settings { display: grid; gap: 14px; }
.settings-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 14px 16px; }
.settings-row p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.prose { font-size: 16.5px; line-height: 1.7; max-width: 72ch; }
.prose h2 { margin: 30px 0 10px; font-size: 24px; }
.prose h3 { margin: 20px 0 6px; }
.empty { text-align: center; padding: 40px 20px; background: var(--paper); border: 1px dashed var(--line-2); border-radius: var(--radius); color: var(--muted); }
.empty h2 { margin-bottom: 8px; color: var(--ink); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 95; transition: all .25s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { max-width: 760px; margin: 40px auto; padding: 20px; border: 1px solid var(--reward-line); background: var(--warn-soft); border-radius: 14px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .lesson-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .rail { display: none; }
  .lesson-main { margin: 0 auto; }
  .lesson-main .lab { margin-left: 0; margin-right: 0; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .progress-strip, .method { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .w-row { grid-template-columns: minmax(0, 1fr); }
  .brand small { display: none; }
}
@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .btn { white-space: normal; max-width: 100%; text-align: center; }
  .topbar { gap: 10px; }
  .brand-text { display: none; }
  .nav a { padding: 7px 9px; font-size: 13.5px; }
  .step-text { font-size: 16.5px; }
  .lab-body { padding: 14px; }
  .q-card { padding: 14px; }
  .barrow { grid-template-columns: 92px minmax(0, 1fr) 54px; font-size: 13px; }
  .q-class-row { grid-template-columns: minmax(0, 1fr); }
  .lesson-nav a { max-width: 100%; width: 100%; }
  .modules { grid-template-columns: minmax(0, 1fr); }
  .math-display .math { font-size: 1.12em; }
  .theme-btn { width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .rail, .frontier, .lesson-nav, .footer, .lab-reset, .q-actions { display: none !important; }
  body { background: #fff; }
  .lesson-layout { display: block; }
}
