/* ==========================================================
   Vector Calculus Primer — shared styles
   ========================================================== */

:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #f0ebdf;
  --ink: #1b1d23;
  --ink-2: #363a46;
  --muted: #646a78;
  --line: #e2dbcb;
  --accent: #2f55d4;
  --accent-ink: #ffffff;
  --grad: #0a7f97;
  --div: #c9531f;
  --curl: #7444c9;
  --em: #946010;
  --ok: #147a43;
  --bad: #c03030;
  --tint-grad: rgba(10, 127, 151, .09);
  --tint-div: rgba(201, 83, 31, .09);
  --tint-curl: rgba(116, 68, 201, .09);
  --tint-em: rgba(154, 100, 16, .10);
  --tint-bad: rgba(192, 48, 48, .08);
  --tint-ok: rgba(20, 122, 67, .09);
  --tint-accent: rgba(47, 85, 212, .08);
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 8px 28px rgba(20, 20, 60, .07);
  --hero-a: #e9e3d4;
  --hero-b: #f6f3ec;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  --mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111318;
    --surface: #181b22;
    --surface-2: #20242d;
    --ink: #e8eaf0;
    --ink-2: #cdd1db;
    --muted: #9aa1af;
    --line: #2b303b;
    --accent: #7b9bff;
    --accent-ink: #0d1020;
    --grad: #3cc6dd;
    --div: #ff8b55;
    --curl: #b48cff;
    --em: #e5ad4f;
    --ok: #4bd18b;
    --bad: #ff6b6b;
    --tint-grad: rgba(60, 198, 221, .12);
    --tint-div: rgba(255, 139, 85, .12);
    --tint-curl: rgba(180, 140, 255, .12);
    --tint-em: rgba(229, 173, 79, .12);
    --tint-bad: rgba(255, 107, 107, .11);
    --tint-ok: rgba(75, 209, 139, .11);
    --tint-accent: rgba(123, 155, 255, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    --hero-a: #171a22;
    --hero-b: #111318;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --surface: #181b22;
  --surface-2: #20242d;
  --ink: #e8eaf0;
  --ink-2: #cdd1db;
  --muted: #9aa1af;
  --line: #2b303b;
  --accent: #7b9bff;
  --accent-ink: #0d1020;
  --grad: #3cc6dd;
  --div: #ff8b55;
  --curl: #b48cff;
  --em: #e5ad4f;
  --ok: #4bd18b;
  --bad: #ff6b6b;
  --tint-grad: rgba(60, 198, 221, .12);
  --tint-div: rgba(255, 139, 85, .12);
  --tint-curl: rgba(180, 140, 255, .12);
  --tint-em: rgba(229, 173, 79, .12);
  --tint-bad: rgba(255, 107, 107, .11);
  --tint-ok: rgba(75, 209, 139, .11);
  --tint-accent: rgba(123, 155, 255, .12);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  --hero-a: #171a22;
  --hero-b: #111318;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
/* keep KaTeX's absolutely-positioned MathML inside scrolling containers */
.table-wrap, .katex-display, .tabpanel, .formula, .callout, figure { position: relative; }
.tabpanel { overflow-x: auto; }
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--sans); line-height: 1.25; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; margin: 2.2rem 0 .6rem; }
h4 { font-size: 1rem; margin: 1.4rem 0 .4rem; }
p { margin: .7rem 0; }
code, .mono { font-family: var(--mono); font-size: .88em; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.zh { font-family: var(--sans); font-size: .78em; color: var(--muted); font-weight: 500; margin-left: .25em; }

/* operator colours */
.op-grad { color: var(--grad); }
.op-div { color: var(--div); }
.op-curl { color: var(--curl); }
.op-em { color: var(--em); }

/* reading progress */
#progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50;
  background: linear-gradient(90deg, var(--grad), var(--div), var(--curl));
  transform-origin: 0 50%; transform: scaleX(0);
}

/* ---------------- hero ---------------- */
.hero {
  position: relative; overflow: hidden;
  background: radial-gradient(1200px 500px at 70% -10%, var(--hero-a), var(--hero-b));
  border-bottom: 1px solid var(--line);
}
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; pointer-events: none; }
.hero-inner { position: relative; max-width: 1100px; margin: 0 auto; padding: 72px 24px 56px; }
.kicker { font-family: var(--sans); font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 .6rem; font-weight: 600; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.6rem); margin: 0 0 1rem; font-weight: 700; }
.hero h1 .nabla { font-family: var(--serif); background: linear-gradient(90deg, var(--grad), var(--div), var(--curl)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { font-size: 1.2rem; max-width: 720px; color: var(--ink-2); }
.maxwell { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 2rem 0 1.6rem; max-width: 1000px; }
.mx {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 10px;
  display: flex; flex-direction: column; gap: 4px; font-size: 1.05rem; backdrop-filter: blur(4px);
}
.mx small { font-family: var(--sans); font-size: .75rem; }
.mx .tag { font-family: var(--sans); font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; align-self: flex-start; padding: 2px 8px; border-radius: 99px; }
.mx-grad { border-top: 3px solid var(--grad); } .mx-grad .tag { background: var(--tint-grad); color: var(--grad); }
.mx-div { border-top: 3px solid var(--div); } .mx-div .tag { background: var(--tint-div); color: var(--div); }
.mx-curl { border-top: 3px solid var(--curl); } .mx-curl .tag { background: var(--tint-curl); color: var(--curl); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--sans); font-size: .95rem; font-weight: 600;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------------- layout ---------------- */
.layout { max-width: 1240px; margin: 0 auto; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 48px; padding: 0 24px; }
.toc { position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto; padding: 32px 0 24px; font-family: var(--sans); font-size: .9rem; }
.toc h2 { font-size: .75rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 0 0 .8rem; }
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: toc; }
.toc li { counter-increment: toc; }
.toc a {
  display: block; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; border-left: 2px solid transparent;
}
.toc a::before { content: counter(toc, decimal-leading-zero) "  "; color: var(--muted); font-family: var(--mono); font-size: .78rem; }
.toc a:hover { background: var(--surface-2); }
.toc a.active { background: var(--surface); border-left-color: var(--accent); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.toc-box { margin-top: 1.4rem; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.toc-box .big { font-size: 1.5rem; font-weight: 700; }
.toc-box .bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.toc-box .bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s ease; }
.toc-tools { display: flex; gap: 8px; margin-top: 1rem; flex-wrap: wrap; }

main { min-width: 0; padding-bottom: 80px; }
section.lesson { padding: 56px 0 24px; border-bottom: 1px solid var(--line); }
section.lesson:last-of-type { border-bottom: none; }
.sec-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: .6rem; }
.sec-num { font-family: var(--mono); font-size: .85rem; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; flex: none; }
section.lesson h2 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 0; }
.sec-sub { color: var(--muted); font-style: italic; margin-top: 0; }

/* ---------------- callouts ---------------- */
.callout { border-radius: var(--radius); padding: 16px 20px; margin: 1.4rem 0; border: 1px solid var(--line); background: var(--surface); position: relative; }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .label { font-family: var(--sans); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; display: block; margin-bottom: .35rem; }
.callout.def { border-left: 4px solid var(--accent); background: var(--tint-accent); } .callout.def .label { color: var(--accent); }
.callout.idea { border-left: 4px solid var(--curl); background: var(--tint-curl); } .callout.idea .label { color: var(--curl); }
.callout.em { border-left: 4px solid var(--em); background: var(--tint-em); } .callout.em .label { color: var(--em); }
.callout.warn { border-left: 4px solid var(--bad); background: var(--tint-bad); } .callout.warn .label { color: var(--bad); }
.callout.key { border-left: 4px solid var(--ok); background: var(--tint-ok); } .callout.key .label { color: var(--ok); }
.callout.grad { border-left: 4px solid var(--grad); background: var(--tint-grad); } .callout.grad .label { color: var(--grad); }
.callout.div { border-left: 4px solid var(--div); background: var(--tint-div); } .callout.div .label { color: var(--div); }
.callout.curl { border-left: 4px solid var(--curl); background: var(--tint-curl); } .callout.curl .label { color: var(--curl); }

.formula { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 18px; margin: 1.2rem 0; box-shadow: var(--shadow); }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; margin: .8em 0; }
.katex { font-size: 1.07em; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; margin: 1.2rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.nice { border-collapse: collapse; width: 100%; font-size: .95rem; }
table.nice th, table.nice td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.nice th { font-family: var(--sans); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: var(--surface-2); }
table.nice tr:last-child td { border-bottom: none; }

/* ---------------- figures ---------------- */
figure { margin: 1.6rem 0; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
figure svg { width: 100%; height: auto; display: block; max-height: 360px; }
figcaption { font-size: .9rem; color: var(--muted); margin-top: .7rem; text-align: center; }
svg text { font-family: var(--sans); font-size: 14px; fill: var(--ink); }
svg .t-muted { fill: var(--muted); }
svg .t-grad { fill: var(--grad); } svg .t-div { fill: var(--div); } svg .t-curl { fill: var(--curl); } svg .t-em { fill: var(--em); }
svg .t-serif { font-family: var(--serif); font-style: italic; font-size: 17px; }
.s-ink { stroke: var(--ink); } .s-muted { stroke: var(--muted); } .s-grad { stroke: var(--grad); } .s-div { stroke: var(--div); } .s-curl { stroke: var(--curl); } .s-em { stroke: var(--em); } .s-line { stroke: var(--line); }
.f-ink { fill: var(--ink); } .f-muted { fill: var(--muted); } .f-grad { fill: var(--grad); } .f-div { fill: var(--div); } .f-curl { fill: var(--curl); } .f-em { fill: var(--em); } .f-surface { fill: var(--surface); }
.f-tint-grad { fill: var(--tint-grad); } .f-tint-div { fill: var(--tint-div); } .f-tint-curl { fill: var(--tint-curl); } .f-tint-em { fill: var(--tint-em); } .f-none { fill: none; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col > * { min-width: 0; }

/* ---------------- labs ---------------- */
.lab {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin: 1.6rem 0; box-shadow: var(--shadow);
}
.lab-title { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; font-family: var(--sans); font-weight: 700; font-size: 1rem; margin: 0; }
.lab-title .pill { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; padding: 3px 9px; border-radius: 99px; background: var(--tint-accent); color: var(--accent); }
.lab-canvas { width: 100%; max-width: 560px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #0f1218; }
.lab-canvas canvas { display: block; touch-action: none; cursor: crosshair; }
.lab-hint { font-family: var(--sans); font-size: .8rem; color: var(--muted); text-align: center; margin: .5rem 0 0; }
.lab-side { display: flex; flex-direction: column; gap: 12px; font-family: var(--sans); font-size: .9rem; min-width: 0; }
.ctl { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.ctl output { font-family: var(--mono); font-weight: 400; color: var(--muted); }
.ctl select, .ctl input[type=range] { width: 100%; }
select {
  font: inherit; font-weight: 500; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
}
input[type=range] { accent-color: var(--accent); }
.chk { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
.readout { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; }
.ro { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.ro span { color: var(--muted); }
.ro b { font-family: var(--mono); font-weight: 600; font-size: .88rem; text-align: right; }
.ro b.g { color: var(--grad); } .ro b.d { color: var(--div); } .ro b.c { color: var(--curl); } .ro b.e { color: var(--em); }
.verdict { margin: 6px 0 0; padding-top: 8px; border-top: 1px dashed var(--line); font-size: .86rem; line-height: 1.5; color: var(--ink-2); }
.meter { position: relative; height: 10px; border-radius: 99px; background: linear-gradient(90deg, var(--tint-bad), var(--surface-2), var(--tint-ok)); margin: 6px 0 2px; }
.meter i { position: absolute; top: -3px; width: 4px; height: 16px; border-radius: 2px; background: var(--ink); transform: translateX(-2px); transition: left .08s; }
.meter-labels { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: .78rem; color: var(--muted); }
.legend .sw { display: inline-block; width: 22px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* ---------------- quick checks ---------------- */
.quiz { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 1.4rem 0; background: var(--surface); }
.quiz .q-label { font-family: var(--sans); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.quiz .q { margin: .3rem 0 .8rem; font-weight: 500; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.opts button {
  text-align: left; font: inherit; font-size: .98rem; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s;
}
.opts button:hover { border-color: var(--accent); }
.quiz.done .opts button { cursor: default; }
.quiz.done .opts button:not(.right):not(.wrong) { opacity: .55; }
.opts button.right { border-color: var(--ok); background: var(--tint-ok); }
.opts button.wrong { border-color: var(--bad); background: var(--tint-bad); }
.explain { display: none; margin-top: .9rem; padding-top: .8rem; border-top: 1px dashed var(--line); font-size: .96rem; }
.quiz.done .explain { display: block; }
.explain .verdict-line { font-family: var(--sans); font-weight: 700; }
.quiz.is-right .verdict-line { color: var(--ok); }
.quiz.is-wrong .verdict-line { color: var(--bad); }
.retry { font-family: var(--sans); font-size: .8rem; background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------------- worked examples ---------------- */
details.example { border: 1px solid var(--line); border-radius: var(--radius); margin: 1.2rem 0; background: var(--surface); overflow: hidden; }
details.example summary {
  cursor: pointer; padding: 14px 18px; font-family: var(--sans); font-weight: 600; font-size: .98rem; list-style: none; display: flex; gap: 10px; align-items: baseline;
}
details.example summary::-webkit-details-marker { display: none; }
details.example summary::before { content: '▸'; color: var(--muted); transition: transform .2s; display: inline-block; }
details.example[open] summary::before { transform: rotate(90deg); }
details.example .ex-tag { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ok); background: var(--tint-ok); padding: 2px 8px; border-radius: 99px; flex: none; }
details.example .ex-body { padding: 0 20px 16px; border-top: 1px dashed var(--line); }
.try { font-family: var(--sans); font-size: .82rem; color: var(--muted); font-weight: 500; margin-left: auto; font-style: italic; }

/* ---------------- steps / misc ---------------- */
.steps { counter-reset: st; list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 10px; }
.steps li { counter-increment: st; position: relative; padding: 12px 14px 12px 52px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.steps li::before { content: counter(st); position: absolute; left: 14px; top: 12px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-family: var(--sans); font-weight: 700; font-size: .85rem; display: grid; place-items: center; }

.tabs { margin: 1.2rem 0; }
.tablist { display: flex; gap: 6px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tablist button {
  font-family: var(--sans); font-weight: 600; font-size: .9rem; padding: 9px 16px; border: 1px solid transparent; border-bottom: none;
  background: none; color: var(--muted); cursor: pointer; border-radius: 10px 10px 0 0; margin-bottom: -1px;
}
.tablist button[aria-selected="true"] { background: var(--surface); color: var(--ink); border-color: var(--line); }
.tabpanel { background: var(--surface); border: 1px solid var(--line); border-top: none; border-radius: 0 0 var(--radius) var(--radius); padding: 6px 18px 14px; }

.pitfalls { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 1.2rem 0; }
.pit { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.pit h4 { margin: 0 0 .3rem; font-size: .95rem; display: flex; gap: 8px; align-items: center; }
.pit h4::before { content: '✕'; color: var(--bad); font-weight: 800; }
.pit p { margin: .3rem 0; font-size: .95rem; }

.cheat { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin: 1.2rem 0; }
.cheat .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; border-top: 4px solid var(--line); }
.cheat .card h4 { margin: .5rem 0 .2rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.cheat .card.g { border-top-color: var(--grad); } .cheat .card.d { border-top-color: var(--div); } .cheat .card.c { border-top-color: var(--curl); } .cheat .card.e { border-top-color: var(--em); }
.cheat .katex-display { margin: .4em 0; }

.cta { text-align: center; padding: 32px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); margin: 1.6rem 0; }
.cta h3 { margin-top: 0; }

footer.site { text-align: center; color: var(--muted); font-family: var(--sans); font-size: .82rem; padding: 32px 16px 48px; border-top: 1px solid var(--line); }

/* ---------------- exam page ---------------- */
.exam-bar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); font-family: var(--sans); font-size: .9rem;
}
.exam-bar .inner { max-width: 900px; margin: 0 auto; padding: 10px 24px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.exam-bar .stat b { font-family: var(--mono); }
.exam-bar .grow { flex: 1; }
.exam-wrap { max-width: 900px; margin: 0 auto; padding: 0 24px 80px; }
.exam-wrap > section { padding-top: 40px; }
.q-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin: 14px 0; transition: border-color .2s; }
.q-card header { display: flex; gap: 10px; align-items: center; font-family: var(--sans); font-size: .78rem; margin-bottom: .2rem; flex-wrap: wrap; }
.q-num { font-family: var(--mono); font-weight: 700; font-size: .85rem; }
.chip { padding: 2px 9px; border-radius: 99px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; background: var(--surface-2); color: var(--muted); }
.chip.grad { background: var(--tint-grad); color: var(--grad); } .chip.div { background: var(--tint-div); color: var(--div); } .chip.curl { background: var(--tint-curl); color: var(--curl); } .chip.coords, .chip.ident { background: var(--tint-em); color: var(--em); } .chip.basics { background: var(--tint-accent); color: var(--accent); }
.q-type { color: var(--muted); margin-left: auto; }
.q-opts { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-top: .6rem; }
.q-opts label { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; }
.q-opts label:has(input:checked) { border-color: var(--accent); background: var(--tint-accent); }
.q-opts input { accent-color: var(--accent); }
.num-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: .6rem; font-family: var(--sans); font-size: .9rem; }
.num-in {
  font-family: var(--mono); font-size: .95rem; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 210px; max-width: 100%;
}
.num-in.sm { width: 110px; }
.num-in:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.q-card.right { border-color: var(--ok); box-shadow: inset 4px 0 0 var(--ok); }
.q-card.wrong { border-color: var(--bad); box-shadow: inset 4px 0 0 var(--bad); }
.q-card.self { border-color: var(--em); box-shadow: inset 4px 0 0 var(--em); }
.q-feedback { font-family: var(--sans); font-weight: 600; margin-top: .7rem; }
.q-card.right .q-feedback { color: var(--ok); } .q-card.wrong .q-feedback { color: var(--bad); }
.q-sol { margin-top: .6rem; padding: 10px 14px; background: var(--bg); border-radius: 10px; border: 1px dashed var(--line); font-size: .96rem; }
.q-sol h4 { margin: .2rem 0; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.self-assess { display: flex; gap: 8px; margin-top: .6rem; flex-wrap: wrap; align-items: center; font-family: var(--sans); font-size: .88rem; }
.results { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); margin-top: 24px; }
.results .score-big { font-family: var(--sans); font-size: 3rem; font-weight: 800; line-height: 1; }
.topic-bars { display: grid; gap: 8px; margin: 16px 0; font-family: var(--sans); font-size: .88rem; }
.topic-bar { display: grid; grid-template-columns: 150px 1fr 60px; gap: 10px; align-items: center; }
.topic-bar .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.topic-bar .track span { display: block; height: 100%; border-radius: 99px; }
.topic-bar b { font-family: var(--mono); text-align: right; }

.pg-kinds { display: flex; flex-wrap: wrap; gap: 8px; margin: 1rem 0; }
.pg-kinds button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pg-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.pg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 1rem; }
.pg-fb { font-family: var(--sans); font-weight: 600; margin-top: .8rem; min-height: 1.4em; }
.pg-fb.ok { color: var(--ok); } .pg-fb.no { color: var(--bad); }
.pg-stats { display: flex; gap: 20px; font-family: var(--sans); font-size: .9rem; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.pg-stats b { color: var(--ink); font-family: var(--mono); }

/* ---------------- responsive ---------------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .toc { display: none; }
  .lab { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  .layout, .hero-inner, .exam-wrap, .exam-bar .inner { padding-left: 16px; padding-right: 16px; }
  .hero-inner { padding-top: 48px; }
  .two-col { grid-template-columns: 1fr; }
  .lab { padding: 12px; }
  figure { padding: 12px; }
  .topic-bar { grid-template-columns: 100px 1fr 50px; }
  .callout { padding: 14px 14px; }
}

@media print {
  .toc, .hero canvas, .lab, #progress, .hero-actions, .quiz, details.example:not([open]) { display: none !important; }
  .layout { display: block; }
  body { background: #fff; color: #000; font-size: 12pt; }
  section.lesson { break-inside: avoid-page; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn { transition: none; }
}
