:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6a65;
  --line: #e2e0d8; --grid: #eeece5; --axis: #b9b7ae;
  --e: #d23f31; --b: #2a66d4; --s: #1f8a4c; --probe: #8a8880; --src: #b76e00;
  --good: #1f8a4c; --bad: #c23b22; --chip-on: #1d1d1b; --chip-on-ink: #ffffff;
  --q-bg: #f1efe8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131312; --panel: #1c1c1a; --ink: #ecebe6; --muted: #9a9992;
    --line: #2e2d2a; --grid: #252522; --axis: #56554d;
    --e: #ff6b5c; --b: #6f9fff; --s: #4cc47e; --probe: #8d8b83; --src: #f0a940;
    --good: #4cc47e; --bad: #ff7a5c; --chip-on: #ecebe6; --chip-on-ink: #131312;
    --q-bg: #232320;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131312; --panel: #1c1c1a; --ink: #ecebe6; --muted: #9a9992;
  --line: #2e2d2a; --grid: #252522; --axis: #56554d;
  --e: #ff6b5c; --b: #6f9fff; --s: #4cc47e; --probe: #8d8b83; --src: #f0a940;
  --good: #4cc47e; --bad: #ff7a5c; --chip-on: #ecebe6; --chip-on-ink: #131312;
  --q-bg: #232320;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 16px 40px; }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
h1 span { display: block; font-size: 14px; font-weight: 400; color: var(--muted); }
h2 { margin: 0 0 8px; font-size: 19px; }

.level { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--panel); }
.level button { border: 0; border-radius: 999px; padding: 6px 14px; background: transparent; }
.level button.on { background: var(--chip-on); color: var(--chip-on-ink); }

.toc { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 12px 0 4px; font-size: 13px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--ink); text-decoration: underline; }

body[data-level="ug"] .adv, body[data-level="adv"] .ug { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-top: 14px; min-width: 0; }
.card p, .card li { max-width: 78ch; }
.card ul, .card ol { padding-left: 22px; }
.q { background: var(--q-bg); border-left: 3px solid var(--axis); padding: 8px 12px; border-radius: 6px; font-style: italic; }
.answer { border-left: 3px solid var(--s); padding-left: 12px; }
.m { font-family: "STIX Two Math", "Cambria Math", "Times New Roman", Georgia, serif; font-size: 1.06em; white-space: nowrap; }
.eq {
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", Georgia, serif; font-size: 17px;
  background: var(--q-bg); border-radius: 8px; padding: 8px 12px; margin: 8px 0; overflow-x: auto; max-width: 78ch;
}

button, select, input[type="number"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
}
button { padding: 5px 12px; cursor: pointer; }
button:hover { border-color: var(--axis); }
button.on { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
button:focus-visible, canvas:focus-visible, input:focus-visible { outline: 2px solid var(--b); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 4px; }
.chips button { border-radius: 999px; }
.chip-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin: 8px 0; font-size: 14px; }
.controls .chips { margin: 0; }
.controls label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.controls input[type="range"] { width: 130px; }
.controls output { min-width: 3.6em; color: var(--ink); font-variant-numeric: tabular-nums; }
.play { min-width: 86px; }

.canvas-box { position: relative; width: 100%; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.canvas-box canvas { display: block; width: 100%; height: 100%; }
.c3d { height: 360px; cursor: grab; touch-action: pan-y; }
.c3d.short { height: 300px; }
.c3d:active { cursor: grabbing; }
.ctrace { height: 150px; }
.cstrip { height: 90px; margin-top: 8px; }
.cslope { height: 280px; cursor: ew-resize; touch-action: pan-y; }
.cline { height: 240px; cursor: crosshair; }
.cmap { aspect-ratio: 1 / 1; cursor: crosshair; }
.cphase { height: 200px; margin-bottom: 8px; }
.overlay-hint { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: var(--muted); pointer-events: none; }
.cslope .overlay-hint, .cline .overlay-hint { top: 4px; bottom: auto; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 12px; margin-top: 10px; align-items: start; }
.split.wide-left { grid-template-columns: minmax(0, 1fr) 360px; }
.split.dipole { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.readouts { display: grid; gap: 6px; font-size: 13px; }
.readouts > div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.readouts span { color: var(--muted); }
.readouts b { font-variant-numeric: tabular-nums; text-align: right; }
.readouts.row { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-top: 8px; }
.readouts.row > div { flex-direction: column; gap: 0; }
.readouts.row b { text-align: left; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.legend { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.k { display: inline-block; width: 16px; height: 3px; vertical-align: middle; margin-right: 4px; border-radius: 2px; }
.k.e { background: var(--e); } .k.b { background: var(--b); } .k.s { background: var(--s); }
.k.src { background: var(--src); } .k.probe { background: var(--probe); }
.k.dash { background: repeating-linear-gradient(90deg, var(--b) 0 4px, transparent 4px 7px); }
.k.dash-e { background: repeating-linear-gradient(90deg, var(--e) 0 7px, transparent 7px 10px); margin-right: 1px; }

table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }
.maxwell tbody td:last-child { width: 26px; text-align: center; font-weight: 700; }
.maxwell code { font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.maxwell tr.fail td:first-child { color: var(--bad); font-weight: 600; }
.bar { display: inline-block; width: 70px; height: 7px; background: var(--grid); border-radius: 4px; vertical-align: middle; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--bad); }
.maxwell tfoot td { color: var(--muted); border: 0; font-size: 12.5px; line-height: 1.45; }
.sum td b { white-space: nowrap; }
.foot { color: var(--muted); font-size: 12px; margin-top: 18px; text-align: center; }

@media (max-width: 820px) {
  .split, .split.wide-left, .split.dipole { grid-template-columns: minmax(0, 1fr); }
  .c3d { height: 300px; }
  .c3d.short { height: 260px; }
}
@media (max-width: 520px) {
  .card { padding: 12px 12px; }
  h1 { font-size: 22px; }
  .controls input[type="range"] { width: 110px; }
  .eq { font-size: 15px; }
  .m { white-space: normal; }
  .sum th:nth-child(4), .sum td:nth-child(4) { display: none; }
}

/* §6 — same pattern elsewhere */
.sys:not(.on) { display: none; }
.tabs button { font-weight: 600; }
.cpic { height: 190px; }
.cprof { height: 200px; margin-top: 8px; }
@media (max-width: 520px) { .cpic { height: 160px; } }
