/* ===== Tokens ===== */
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eaf0f8;
  --ink: #0f1b2d;
  --ink-2: #2c3b52;
  --muted: #5b6b82;
  --line: #d5deeb;
  --accent: #1e3a8a;
  --accent-ink: #162d6e;
  --accent-soft: #e5ecfa;
  --on-accent: #ffffff;
  --accent-2: #2563eb;
  --accent-2-soft: #e7effd;
  --warn: #b4540a;
  --warn-soft: #fff1e3;
  --def: #2563eb;
  --def-soft: #ebf1fd;
  --thm: #5b3fbf;
  --thm-soft: #f1eefb;
  --note: #1e3a8a;
  --note-soft: #e9eff9;
  --err: #b42318;
  --err-soft: #fdecea;
  --shadow: 0 1px 2px rgba(15, 30, 60, .07), 0 6px 20px rgba(15, 30, 60, .07);
  --radius: 14px;
  --plot-bg: #ffffff; --plot-grid: #e6ebf3; --plot-axis: #8592a8; --plot-seg: #6c7a92;
  --plot-c1: #d9480f; --plot-c2: #1d4ed8; --plot-c3: #7c3aed; --plot-c4: #db2777;
  --fig-soft: #e8eef8;
  --font: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Manrope", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #111a2e; --surface-2: #17223a; --ink: #e6ecf7; --ink-2: #c3cde0; --muted: #8e9bb5; --line: #25324e;
    --accent: #7aa2ff; --accent-ink: #a6c1ff; --accent-soft: #16264a; --on-accent: #0b1220; --accent-2: #93b4ff; --accent-2-soft: #1a2647;
    --warn: #f0a35b; --warn-soft: #2e2116; --def: #93b4ff; --def-soft: #17213f; --thm: #c4a8ff; --thm-soft: #221c3a; --note: #a6c1ff; --note-soft: #142140;
    --err: #ff8a80; --err-soft: #3a1714; --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3);
    --plot-bg: #0e1729; --plot-grid: #1c2842; --plot-axis: #6f7f9e; --plot-seg: #8090ad;
    --plot-c1: #ff8a5c; --plot-c2: #7aa2ff; --plot-c3: #b794f6; --plot-c4: #f472b6; --fig-soft: #1a2540;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2e; --surface-2: #17223a; --ink: #e6ecf7; --ink-2: #c3cde0; --muted: #8e9bb5; --line: #25324e;
  --accent: #7aa2ff; --accent-ink: #a6c1ff; --accent-soft: #16264a; --on-accent: #0b1220; --accent-2: #93b4ff; --accent-2-soft: #1a2647;
  --warn: #f0a35b; --warn-soft: #2e2116; --def: #93b4ff; --def-soft: #17213f; --thm: #c4a8ff; --thm-soft: #221c3a; --note: #a6c1ff; --note-soft: #142140;
  --err: #ff8a80; --err-soft: #3a1714; --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3);
  --plot-bg: #0e1729; --plot-grid: #1c2842; --plot-axis: #6f7f9e; --plot-seg: #8090ad;
  --plot-c1: #ff8a5c; --plot-c2: #7aa2ff; --plot-c3: #b794f6; --plot-c4: #f472b6; --fig-soft: #1a2540;
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 18px/1.68 var(--font); }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--ink); line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.7rem, 3.2vw, 2.3rem); font-weight: 800; margin: .2em 0 .6em; }
h2 { font-size: 1.45rem; font-weight: 700; margin: 2.2em 0 .6em; padding-top: .2em; }
h3 { font-size: 1.15rem; font-weight: 700; margin: 1.6em 0 .5em; }
p { margin: 0 0 1em; }
code { font-family: var(--font-mono); font-size: .86em; background: var(--surface-2); border: 1px solid var(--line); padding: .05em .35em; border-radius: 6px; }
img, svg, canvas { max-width: 100%; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.small { font-size: .9rem; } .muted { color: var(--muted); }
.katex { font-size: 1.07em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .2em 0; margin: .9em 0; }
.katex-display > .katex { white-space: nowrap; }

/* ===== Top bar ===== */
.topbar { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1440px; margin: 0 auto; display: flex; align-items: center; gap: 14px; height: 60px; padding: 0 20px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.logo-mark { width: 32px; height: 32px; flex: none; }
.brand-name { font-family: var(--font-head); font-weight: 600; font-size: 1.12rem; letter-spacing: -0.01em; }
.brand-name b { font-weight: 800; color: var(--accent); margin-left: 1px; }
.mainnav { margin-left: auto; display: flex; gap: 4px; }
.mainnav a { text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: .98rem; padding: 7px 12px; border-radius: 9px; }
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.toc-toggle { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.toc-toggle:hover { color: var(--accent); border-color: var(--accent); }
.toc-toggle { display: none; }
.theme-switch { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px; cursor: pointer; color: var(--ink-2); font: 600 .9rem var(--font-head); }
.theme-switch .ts-track { position: relative; width: 62px; height: 30px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 7px; transition: background .2s; }
.theme-switch .ts-track svg { width: 15px; height: 15px; color: var(--muted); position: relative; z-index: 1; }
.theme-switch .ts-thumb { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s ease; }
.theme-switch[aria-checked="true"] .ts-thumb { transform: translateX(32px); }
.theme-switch[aria-checked="false"] .i-sun, .theme-switch[aria-checked="true"] .i-moon { color: var(--on-accent); }
.theme-switch:hover .ts-track { border-color: var(--accent); }
.theme-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 999px; }

/* ===== Layout ===== */
.layout { max-width: 1440px; margin: 0 auto; display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 40px; padding: 0 20px; }
.layout.noside { grid-template-columns: minmax(0, 1fr); }
.sidebar { position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); overflow-y: auto; padding: 22px 6px 40px 0; scrollbar-width: thin; }
.main { min-width: 0; padding: 26px 0 60px; }
.article { max-width: 820px; }
@media (max-width: 1240px) { .layout { grid-template-columns: 260px minmax(0, 1fr); gap: 32px; } }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px; }
  .toc-toggle { display: grid; }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 60px; width: min(340px, 88vw); background: var(--surface); border-right: 1px solid var(--line); transform: translateX(-102%); transition: transform .22s ease; padding: 18px 12px 60px; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .mainnav { display: none; }
  .theme-switch { margin-left: auto; }
  .theme-switch .ts-label { display: none; }
  body { font-size: 17px; }
}

/* ===== TOC ===== */
.toc-title { font: 700 .78rem var(--font-head); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 10px 10px; }
.toc-list, .toc-list ol { list-style: none; margin: 0; padding: 0; }
.toc-ch > button { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 10px; cursor: pointer; color: var(--ink); font: 600 .95rem/1.35 var(--font); }
.toc-ch > button:hover { background: var(--surface-2); }
.toc-num { flex: none; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font: 700 .8rem var(--font-head); border: 1px solid var(--line); }
.toc-ch.current .toc-num { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.toc-chname { flex: 1; }
.toc-ch > ol { display: none; margin: 2px 0 8px 22px; border-left: 2px solid var(--line); }
.toc-ch.expanded > ol { display: block; }
.toc-ch li a, .toc-ch li.dim { display: block; padding: 5px 10px 5px 14px; font-size: .9rem; line-height: 1.35; color: var(--ink-2); text-decoration: none; border-radius: 0 8px 8px 0; margin-left: -2px; border-left: 2px solid transparent; }
.toc-ch li a:hover { color: var(--accent-ink); background: var(--surface-2); }
.toc-ch li a[aria-current="page"] { color: var(--accent-ink); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc-ch li.dim { color: var(--muted); opacity: .75; }
.toc-sid { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: 3px; }
.toc-quiz { font-weight: 600; }
.toc-quiz::before { content: "✎ "; }
.soon { display: inline-block; font: 700 .62rem var(--font-head); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; vertical-align: 2px; margin-left: 4px; }

/* ===== Article furniture ===== */
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); text-decoration: none; } .crumbs a:hover { color: var(--accent-ink); }
.crumbs span { margin: 0 4px; opacity: .6; }
.sec-head { margin-bottom: 1.4em; padding-bottom: 1em; border-bottom: 1px solid var(--line); }
.eyebrow { font: 700 .78rem var(--font-head); color: var(--accent); text-transform: uppercase; letter-spacing: .09em; }
.sec-no { color: var(--accent); margin-right: .15em; }
.article ul, .article ol { padding-left: 1.4em; }
.article li { margin: .3em 0; }
.article table { border-collapse: collapse; width: 100%; margin: 1em 0 1.4em; font-size: .95rem; display: block; overflow-x: auto; }
.article th, .article td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.article th { background: var(--surface-2); font-weight: 700; }
.box { border: 1px solid var(--line); border-left: 4px solid var(--b, var(--accent)); background: var(--bs, var(--surface)); border-radius: 12px; padding: 14px 18px 4px; margin: 1.4em 0; }
.box-title { font: 800 .8rem var(--font-head); text-transform: uppercase; letter-spacing: .07em; color: var(--b); margin-bottom: 6px; }
.box.def { --b: var(--def); --bs: var(--def-soft); }
.box.thm { --b: var(--thm); --bs: var(--thm-soft); }
.box.note { --b: var(--note); --bs: var(--note-soft); }
.box.warn { --b: var(--warn); --bs: var(--warn-soft); }
.box.recipe { --b: var(--accent-2); --bs: var(--accent-2-soft); }
.box.recipe ol { counter-reset: r; list-style: none; padding-left: 0; }
.box.recipe ol > li { counter-increment: r; position: relative; padding-left: 2.1em; margin: .55em 0; }
.box.recipe ol > li::before { content: counter(r); position: absolute; left: 0; top: .15em; width: 1.5em; height: 1.5em; border-radius: 50%; background: var(--accent-2); color: var(--on-accent); font: 700 .78rem/1.5em var(--font-head); text-align: center; }

.example { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px 8px; margin: 1.6em 0; box-shadow: var(--shadow); }
.ex-title { font: 800 .82rem var(--font-head); text-transform: uppercase; letter-spacing: .07em; color: var(--accent); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.ex-title::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); transform: rotate(45deg); }
details.solution, details.answer { margin: .4em 0 .8em; }
details.solution > summary, details.answer > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; font: 700 .9rem var(--font-head); color: var(--accent-ink); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--accent); background: var(--accent-soft); user-select: none; }
details.answer > summary { padding: 2px 10px; font-size: .8rem; }
details > summary::-webkit-details-marker { display: none; }
details.solution > summary::before, details.answer > summary::before { content: "▸"; transition: transform .15s; }
details[open].solution > summary::before, details[open].answer > summary::before { transform: rotate(90deg); }
details.solution[open] { border-top: 1px dashed var(--line); padding-top: 4px; }
details.solution[open] > summary { margin-bottom: 8px; }
details.answer[open] { display: block; background: var(--surface-2); border-radius: 10px; padding: 6px 12px; }
ol.steps { padding-left: 1.3em; }
ol.steps > li { margin: .6em 0; padding-left: .2em; }
ol.steps > li::marker { color: var(--accent); font-weight: 700; }
.exercises { margin-top: 3em; border-top: 2px solid var(--line); }
.exercises > ol > li { margin: .9em 0; padding-left: .3em; }
.exercises > ol > li::marker { font-weight: 700; color: var(--muted); }

/* ===== Buttons & forms ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; font: 700 .92rem var(--font-head); border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.big { padding: 12px 20px; font-size: 1rem; border-radius: 12px; }

/* ===== Solver card ===== */
.solver-card, .quiz-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px 22px; margin: 2em 0; box-shadow: var(--shadow); overflow: hidden; }
.solver-card::before, .quiz-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.solver-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.solver-badge { font: 800 .68rem var(--font-head); text-transform: uppercase; letter-spacing: .09em; color: var(--accent-ink); background: var(--accent-soft); border-radius: 6px; padding: 3px 8px; }
.solver-badge.quiz { color: var(--accent-2); background: var(--accent-2-soft); }
.solver-title { margin: 0; font-size: 1.12rem; }
.solver-blurb { color: var(--ink-2); font-size: .95rem; margin: 8px 0 12px; }
.solver-form { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld.wide { flex: 1 1 260px; }
.fld[hidden] { display: none; }
.fld-label { font-size: .84rem; font-weight: 600; color: var(--muted); }
.fld input, .fld select { font: 500 1rem var(--font-mono); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; width: 100%; }
.fld:not(.wide) input { width: 11em; }
.fld select { font-family: var(--font); width: auto; }
.fld input:focus, .fld select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.fld-hint { font-size: .78rem; color: var(--muted); }
.solver-preview { margin: 12px 0 4px; padding: 6px 14px; background: var(--surface-2); border-radius: 12px; min-height: 2.6em; border: 1px dashed var(--line); }
.solver-preview.bad { color: var(--muted); }
.solver-preview .katex-display { margin: .4em 0; }
.solver-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.solver-error { margin-top: 12px; background: var(--err-soft); color: var(--err); border-radius: 10px; padding: 10px 14px; font-size: .95rem; }
.solver-output:not(:empty) { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 8px; }
.steplist { list-style: none; padding: 0; margin: 0; }
.step { position: relative; padding: 10px 0 10px 44px; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step::before { content: ""; position: absolute; left: 14px; top: 40px; bottom: -10px; width: 2px; background: var(--line); }
.step:last-child::before, .step.final::before { display: none; }
.step-head { display: flex; align-items: center; gap: 10px; margin-left: -44px; }
.step-no { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); font: 800 .85rem var(--font-head); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.step.final .step-no { background: var(--accent); color: var(--on-accent); }
.step-title { font: 700 1rem var(--font-head); }
.step-body { margin-top: 4px; font-size: .98rem; overflow-x: auto; }
.step-body p { margin: .4em 0; }
.step.final .step-body { background: var(--accent-soft); border-radius: 12px; padding: 4px 14px; }
.step.appear { animation: appear .28s ease; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.step-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.step-counter { color: var(--muted); font-size: .88rem; margin-left: auto; }
table.mini { display: table !important; width: auto !important; font-size: .9rem !important; margin: .6em 0 !important; }
table.mini th, table.mini td { padding: 5px 10px !important; }
.plot-wrap { margin-top: 14px; position: relative; }
canvas.plot { display: block; width: 100%; border-radius: 12px; border: 1px solid var(--line); cursor: crosshair; touch-action: manipulation; }
.plot-readout { font: .84rem var(--font-mono); color: var(--muted); margin-top: 6px; min-height: 1.4em; }

/* ===== Quiz ===== */
.quiz-actions { margin: 6px 0 4px; }
.quiz-item { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-top: 14px; background: var(--bg); }
.quiz-q { display: flex; gap: 12px; }
.quiz-no { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-2); color: var(--on-accent); font: 800 .95rem var(--font-head); }
.quiz-topic { font: 800 .72rem var(--font-head); text-transform: uppercase; letter-spacing: .08em; color: var(--accent-2); }
.quiz-statement { overflow-x: auto; }
.quiz-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.quiz-answer { margin-top: 10px; background: var(--accent-2-soft); border-radius: 10px; padding: 4px 12px; overflow-x: auto; }
.quiz-sol { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 4px; }

/* ===== Ads ===== */

/* ===== Prev / next ===== */
.prevnext { max-width: 820px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 28px; }
.pn { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-decoration: none; color: var(--ink); font-weight: 600; line-height: 1.35; }
.pn span { font: 700 .72rem var(--font-head); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.pn.next { text-align: right; grid-column: 2; }
.pn:hover { border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 600px) { .prevnext { grid-template-columns: 1fr; } .pn.next { grid-column: 1; } }

/* ===== Home ===== */
.hero { display: grid; grid-template-columns: 1.25fr 1fr; gap: 32px; align-items: center; padding: 20px 0 10px; }
.hero-title { font-size: clamp(2rem, 4.4vw, 3rem); line-height: 1.1; margin: .25em 0 .4em; }
.hero-title .hl { color: var(--accent); }
.hero-lead { font-size: 1.12rem; color: var(--ink-2); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.demo-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow); background-image: linear-gradient(var(--plot-grid) 1px, transparent 1px), linear-gradient(90deg, var(--plot-grid) 1px, transparent 1px); background-size: 22px 22px; background-position: -1px -1px; }
.demo-label { font: 800 .7rem var(--font-head); color: var(--accent); text-transform: uppercase; letter-spacing: .09em; }
.demo-steps { font-size: .92rem; background: var(--surface); border-radius: 10px; padding: 8px 8px 8px 2em; }
.demo-steps li::marker { color: var(--accent); font-weight: 700; }
.home-sec { margin-top: 2.6em; }
.home-chs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.home-ch { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; text-decoration: none; color: var(--ink); transition: border-color .12s, transform .12s; }
.home-ch:hover { border-color: var(--accent); transform: translateY(-2px); }
.home-ch.dim { opacity: .62; }
.hc-n { font: 800 1.4rem var(--font-head); color: var(--accent); }
.hc-t { font-weight: 700; line-height: 1.3; }
.hc-s { font-size: .82rem; color: var(--muted); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.feat { padding: 16px; border-radius: 14px; background: var(--accent-soft); }
.feat h3 { margin-top: 0; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }

/* ===== Grids ===== */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 1em 0; }
.tool-card { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-decoration: none; color: var(--ink); }
.tool-card:hover { border-color: var(--accent); }
.tc-name { font: 700 1rem var(--font-head); color: var(--accent-ink); }
.tc-desc { font-size: .9rem; color: var(--ink-2); line-height: 1.45; }
.sec-cards { list-style: none; padding: 0 !important; display: grid; gap: 10px; }
.sec-cards li { margin: 0 !important; }
.sec-cards a, .sec-cards li.dim > span { display: flex; gap: 14px; align-items: baseline; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--ink); font-weight: 600; }
.sec-cards a:hover { border-color: var(--accent); }
.sec-cards li.dim { opacity: .6; }
.sc-id { font: 800 .95rem var(--font-head); color: var(--accent); min-width: 2.6em; }
.sec-cards .quizcard a { background: var(--accent-2-soft); }
.sec-cards .quizcard .sc-id { color: var(--accent-2); }
.course-grid { display: grid; gap: 14px; }
.course-ch { display: flex; gap: 16px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.course-ch.dim { opacity: .7; }
.course-ch h2 { margin: 0 0 .3em; font-size: 1.15rem; }
.course-ch h2 a { color: var(--ink); text-decoration: none; }
.course-ch ul { margin: 0; padding-left: 1.1em; font-size: .94rem; columns: 2 260px; }
.cc-n { font: 800 1.6rem var(--font-head); color: var(--accent); min-width: 1.4em; }

/* ===== Footer ===== */
.footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 40px; }
.footer-in { max-width: 1440px; margin: 0 auto; padding: 28px 20px; color: var(--muted); font-size: .92rem; }
.foot-brand { display: flex; align-items: center; gap: 8px; font: 800 1rem var(--font-head); color: var(--ink); margin-bottom: 8px; }
.foot-brand .logo-mark { width: 24px; height: 24px; }
.footer nav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0; }
.footer nav a { color: var(--ink-2); text-decoration: none; }
.footer nav a:hover { color: var(--accent-ink); }
.copy { margin: 0; font-size: .85rem; }

@media print { .topbar, .sidebar, .prevnext, .footer, .solver-card, .quiz-card { display: none !important; } .layout { display: block; } details > * { display: block !important; } }
.step:not(:has(~ .step:not([hidden])))::before { display: none; }

/* ===== Figures ===== */
figure.fig { margin: 1.8em auto; text-align: center; color: var(--ink); }
figure.fig .fig-svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
figure.fig.wide .fig-svg { width: 100%; }
figure.fig figcaption { font-size: .92rem; color: var(--muted); margin-top: .5em; text-align: left; max-width: 640px; margin-left: auto; margin-right: auto; }
figure.fig figcaption b { color: var(--ink-2); }
.fig-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: end; }
.fig-missing { border: 1px dashed var(--err); color: var(--err); padding: 20px; border-radius: 10px; }
.solver-plot { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.plot-title { font: 700 .95rem var(--font-head); margin-bottom: 6px; }
.plot-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .86rem; color: var(--ink-2); margin-top: 6px; }
.plot-legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.solver-form input[type=range] { width: 100%; }
.copy a { color: var(--muted); }
