/* NMK42003 interactive chapters (shared): calculators, diagrams, Bode plots, exercises.
   Builds on the tokens in style.css. */

html { scroll-padding-top: 124px; }

.lab-lead { font-size: 1.08rem; color: var(--ink-2); max-width: var(--measure); margin-top: 14px; }
.lab-how { color: var(--ink-2); max-width: var(--measure); font-size: .95rem; }

/* ---------- Sticky section nav ---------- */
.lab-nav {
  position: -webkit-sticky; position: sticky; top: 60px; z-index: 40;
  background: var(--paper); /* fallback for browsers without color-mix (older Huawei/Android WebViews) */
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);
  backdrop-filter: saturate(1.2) blur(8px);
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.lab-nav .wrap { display: flex; align-items: center; gap: 4px; height: 48px; overflow-x: auto; }
.lab-nav a { color: var(--ink-2); text-decoration: none; font-size: .93rem; padding: 6px 14px; border-radius: 999px; white-space: nowrap; }
.lab-nav a:hover { color: var(--ink); background: var(--grid); }
.lab-nav a[aria-current="true"] { background: var(--ink); color: var(--paper); }

/* ---------- Groups and circuit sections ---------- */
.lab-group { padding: 48px 0 24px; }
.lab-group + .lab-group { border-top: 1px solid var(--rule); }
.group-head > p { color: var(--ink-2); max-width: var(--measure); margin: 10px 0 0; }
.toc-chips { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.toc-chips a {
  display: inline-block; font-size: .85rem; padding: 4px 11px; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2);
}
.toc-chips a:hover { border-color: var(--teal); color: var(--teal); }

.circuit { margin-top: 40px; padding-top: 32px; border-top: 1px dashed var(--rule); }
.circuit h3 { font-size: 1.45rem; margin-bottom: 12px; }
.circuit h3:focus { outline: none; }
.circuit h3:focus-visible { outline: 2px solid var(--focus); }
.circuit.flash .c-grid { animation: labflash 1.6s ease-out; }
@keyframes labflash { from { box-shadow: 0 0 0 6px var(--amber-soft); border-radius: var(--r-md); } }
@media (prefers-reduced-motion: reduce) { .circuit.flash .c-grid { animation: none; } }
.explain { max-width: var(--measure); color: var(--ink-2); }
.explain p:last-child { margin-bottom: 0; }

.c-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 20px; margin: 22px 0 18px; align-items: start; }
@media (max-width: 860px) { .c-grid { grid-template-columns: minmax(0, 1fr); } }
.c-grid > * { min-width: 0; }

/* ---------- Circuit diagram ---------- */
.diagram { margin: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 12px 12px 8px; }
/* keep the diagram in view while editing a long list of inputs beside it (only in the two-column calculator grid) */
@media (min-width: 861px) { .c-grid > .diagram { position: sticky; top: 124px; } }
.ckt-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ckt { display: block; width: 100%; height: auto; }
@media (max-width: 560px) { .ckt { min-width: 440px; } }
.swipe { display: none; }
@media (max-width: 480px) { .swipe { display: inline; } }
.diagram figcaption { font-size: .8rem; color: var(--ink-3); margin-top: 6px; }
.ckt .w { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ckt .op { fill: var(--surface); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }
.ckt .dot { fill: var(--ink); }
.ckt .term { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
.ckt text { fill: var(--ink-2); font-family: var(--sans); font-size: 14px; }
.ckt .sb { font-size: 10px; }
.ckt .sign { fill: var(--ink); font-size: 17px; font-weight: 500; }
.ckt .val { fill: var(--teal); font-weight: 600; }
.ckt .val.bad { fill: var(--danger); }
.ckt .val.over { fill: var(--amber); }

/* ---------- Inputs ---------- */
.inputs { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px; display: grid; gap: 14px; }
@media (min-width: 861px) { .inputs.many { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; } }
.field { min-width: 0; }
.ctl select:only-child { flex: 1; width: 100%; }
.field[hidden] { display: none; }
.field label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 4px; }
.field .hint { font-weight: 400; color: var(--ink-3); font-size: .82rem; }
.ctl { display: flex; gap: 6px; align-items: center; }
.ctl input, .ctl select, .ans-in input {
  font: inherit; font-size: .95rem; height: 40px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--paper); color: var(--ink);
}
.ctl input { flex: 1; }
.ctl select { flex: none; }
.ctl input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.unit { color: var(--ink-2); font-size: .92rem; min-width: 2.2em; }
.field input[type="range"] { width: 100%; height: 28px; margin: 4px 0 0; accent-color: var(--teal); touch-action: pan-y; }
/* iOS Safari zooms the page when a focused field is under 16px */
@media (max-width: 860px) { .ctl input, .ctl select, .ans-in input { font-size: 16px; height: 44px; } }
.err { color: var(--danger); font-size: .85rem; margin: 4px 0 0; }

/* ---------- Working ---------- */
.working { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px 20px 18px; }
.working h4, .bode h4 { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; margin: 0 0 8px; }
.result { font-weight: 600; margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { display: grid; gap: 2px; min-width: 0; }
.st-t { display: flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 500; color: var(--ink-3); }
.st-n {
  flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--teal-soft); color: var(--teal); font-size: .74rem; font-weight: 600;
}
.st-f, .st-s, .st-r { padding-left: 28px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.st-f { font-family: var(--serif); }
.st-s { color: var(--ink-2); }
.st-r { font-weight: 600; }
sub, sup { line-height: 0; }

/* ---------- Callouts ---------- */
.warnings { display: grid; gap: 10px; margin: 14px 0; }
.warnings:empty { display: none; }
.callout { padding: 12px 16px; border-left: 3px solid var(--ink-3); border-radius: 0 var(--r-sm) var(--r-sm) 0; font-size: .95rem; max-width: 100%; }
.callout strong:first-child { display: block; margin-bottom: 2px; }
.callout.warn { background: var(--amber-soft); border-left-color: var(--amber); }
.callout.warn strong:first-child { color: var(--amber); }
.callout.info { background: var(--teal-soft); border-left-color: var(--teal); }
.callout.note { background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--ink-3); margin: 14px 0; }
.callout.note strong:first-child { display: inline; }
.circuit > .callout.note strong:first-child { display: block; }

/* ---------- Bode plot ---------- */
.bode { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px 16px 12px; margin: 14px 0; }
.bode-plot { min-height: 200px; }
.bode-plot svg { display: block; max-width: 100%; height: auto; cursor: crosshair; touch-action: manipulation; }
.bode .gl { stroke: var(--grid); stroke-width: 1; }
.bode .gl.minor { opacity: .55; }
.bode .axis { fill: var(--ink-3); font-family: var(--sans); font-size: 11px; }
.bode .curve { fill: none; stroke: var(--teal); stroke-width: 2.4; stroke-linejoin: round; }
.bode .ref { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 6 4; }
.bode .reflab { fill: var(--amber); font-family: var(--sans); font-size: 11px; font-weight: 600; }
.bode .mk { stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 3 3; }
.bode .mklab { fill: var(--ink-2); font-family: var(--sans); font-size: 12px; font-weight: 600; }
.bode .sb { font-size: 9px; }
.bode .pt { fill: var(--danger); stroke: var(--surface); stroke-width: 2; }
.bode .ptlab { fill: var(--danger); font-family: var(--sans); font-size: 12px; font-weight: 600; }
.bode .reflab, .bode .mklab, .bode .ptlab { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.bode-cap { font-size: .82rem; color: var(--ink-3); margin: 8px 0 0; }

/* ---------- Comparison table ---------- */
table.cmp { width: 100%; border-collapse: collapse; font-size: .93rem; min-width: 560px; }
.cmp th, .cmp td { text-align: left; vertical-align: top; padding: 12px 16px; border-bottom: 1px solid var(--grid); }
.cmp thead th { color: var(--ink-3); font-weight: 500; font-size: .85rem; border-bottom: 1px solid var(--rule); }
.cmp tbody th { font-weight: 600; width: 20%; }
.cmp td { color: var(--ink-2); }
.cmp tr:last-child th, .cmp tr:last-child td { border-bottom: 0; }

/* ---------- Exercises ---------- */
.ex { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 22px 24px; margin-top: 22px; }
.ex h3 { font-size: 1.2rem; margin-bottom: 8px; }
.ex .q { color: var(--ink-2); max-width: var(--measure); }
.ex-answers { display: grid; gap: 10px; }
.ans { display: grid; grid-template-columns: minmax(0, 11em) minmax(0, 13em) minmax(0, 1fr); gap: 6px 12px; align-items: center; }
.ans label { font-size: .95rem; }
.ans-in { display: flex; align-items: center; gap: 8px; }
.ans-in input { width: 100%; background: var(--paper); }
.mark { font-size: .9rem; font-weight: 600; color: var(--ink-3); }
.mark.ok { color: var(--teal); }
.mark.no { color: var(--danger); }
@media (max-width: 560px) {
  .ans { grid-template-columns: minmax(0, 1fr) auto; }
  .ans label { grid-column: 1 / -1; }
}
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn {
  font: inherit; font-size: .92rem; font-weight: 500; padding: 8px 14px; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid var(--teal); background: var(--teal); color: var(--surface);
}
.btn:hover { background: var(--teal-strong); border-color: var(--teal-strong); }
.btn.ghost { background: var(--surface); color: var(--teal); }
.btn.ghost:hover { background: var(--teal-soft); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .88rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
.ex-status { font-size: .88rem; color: var(--ink-2); margin: 8px 0 0; }
.ex-status strong { color: var(--teal); }
.ex-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 8px; }
.ex-head h3 { margin: 0; }
.ex-badge { font-size: .8rem; font-weight: 600; color: var(--teal); background: var(--teal-soft); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.ex.solved { border-color: color-mix(in srgb, var(--teal) 45%, var(--rule)); }
.ex-hints { display: grid; gap: 8px; margin-top: 12px; }
.ex-hints:empty { display: none; }
.callout.hint { background: var(--amber-soft); border-left-color: var(--amber); }
.callout.hint strong:first-child { color: var(--amber); }
.ex .q table { border-collapse: collapse; margin: 10px 0; font-variant-numeric: tabular-nums; }
.ex .q th, .ex .q td { padding: 4px 14px; border-bottom: 1px solid var(--grid); text-align: right; }
.ex .q th { color: var(--ink-3); font-weight: 500; font-size: .85rem; }

/* ---------- Chapter byline ---------- */
.authors { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 14px; font-size: .9rem; color: var(--ink-2); }
.by-label { color: var(--ink-3); font-size: .85rem; }
.by-person { display: inline-flex; align-items: center; gap: 8px; }
.by-person img, .by-init { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; }
.by-init { display: inline-grid; place-items: center; background: var(--teal-soft); color: var(--teal); font-family: var(--serif); font-weight: 600; font-size: .8rem; }

/* ---------- Layout variants ---------- */
.c-grid.single { grid-template-columns: minmax(0, 1fr); }
.c-grid.single .inputs { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }
.widget { margin: 20px 0 18px; }
.ex-working { display: grid; gap: 12px; margin-top: 16px; }
.ex-working[hidden] { display: none; }
.ex-working .working { background: var(--paper); }
.ex .callout.note { margin-bottom: 0; }

@media (max-width: 560px) {
  .working, .bode { padding-left: 14px; padding-right: 14px; }
  .st-f, .st-s, .st-r { padding-left: 0; }
  .ex { padding: 18px 16px; }
}

/* ======== Shared widgets (chips, quizzes, plots, definitions) ======== */
.sub-h { font-family: var(--serif); font-size: 1.1rem; margin: 22px 0 10px; }
.formula { font-family: var(--serif); font-size: 1.15rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-sm); display: inline-block; padding: 8px 16px; }
.widget-lead { color: var(--ink-2); max-width: var(--measure); }
.defs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; margin: 14px 0; padding: 0; }
.defs > div { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 10px 14px; }
.defs dt { font-weight: 600; color: var(--teal); font-size: .95rem; }
.defs dd { margin: 2px 0 0; color: var(--ink-2); font-size: .93rem; }
.ticks { padding-left: 1.2em; color: var(--ink-2); max-width: var(--measure); }
.ticks li { margin-bottom: 6px; }
.rules { color: var(--ink-2); max-width: var(--measure); padding-left: 1.3em; }
.rules li { margin-bottom: 6px; }
.explain .rules, .explain .defs { color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; margin: 10px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--teal); }
.slider-field { margin-bottom: 14px; }
.slider-field label { font-size: .92rem; }
.slider-field input[type="range"] { width: 100%; accent-color: var(--teal); height: 28px; touch-action: pan-y; }

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 16px; }
.chip-btn {
  font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 999px; cursor: pointer; min-height: 38px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2);
}
.chip-btn:hover { border-color: var(--teal); color: var(--teal); }
.chip-btn[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: var(--surface); }

.plot-box { margin: 0; max-width: 820px; }
.extra .plot { max-width: 760px; }
.plot { display: block; width: 100%; height: auto; }
.plot .gl { stroke: var(--grid); stroke-width: 1; }
.plot .axis { fill: var(--ink-3); font: 11px var(--sans); }
.plot .lvl { stroke: var(--amber); stroke-width: .6; opacity: .35; }
.plot .trace-a { fill: none; stroke: var(--teal); stroke-width: 2.4; stroke-linejoin: round; }
.plot .trace-d { fill: none; stroke: var(--amber); stroke-width: 2.2; stroke-linejoin: round; }
.plot .trace-in { fill: none; stroke: var(--ink-3); stroke-width: 1.8; stroke-dasharray: 6 4; }
.plot .mk { stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 3 3; }
.plot .mklab { fill: var(--ink-2); font: 600 12px var(--sans); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.plot .lagline { stroke: var(--danger); stroke-width: 2.5; }
.plot .ref { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 6 4; }
.plot .reflab { fill: var(--amber); font: 600 11px var(--sans); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.plot .pt { fill: var(--danger); stroke: var(--surface); stroke-width: 2; }
.plot .ptlab { fill: var(--danger); font: 600 12px var(--sans); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.plot .shot { fill: var(--amber); stroke: var(--surface); stroke-width: 1.5; }
.plot .band { fill: var(--teal-soft); }
.plot .meanline { stroke: var(--teal); stroke-width: 2.5; }
.key { display: inline-block; width: 16px; height: 3px; vertical-align: middle; margin-right: 4px; background: var(--teal); }
.key.digital { background: var(--amber); }
.key.input { background: none; border-top: 2px dashed var(--ink-3); height: 0; }
.key.band { height: 10px; background: var(--teal-soft); border: 1px solid var(--teal); }

/* ---------- Quiz ---------- */
.quiz-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 18px 20px; max-width: 760px; }
.quiz-top { display: flex; justify-content: space-between; font-size: .85rem; color: var(--ink-3); margin-bottom: 8px; }
.quiz-q { font-size: 1.05rem; margin-bottom: 12px; }
.quiz-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 8px; }
.quiz-opt {
  font: inherit; font-size: .95rem; text-align: left; padding: 12px 14px; min-height: 48px; cursor: pointer;
  border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--paper); color: var(--ink);
}
.quiz-opt:hover:not(:disabled) { border-color: var(--teal); }
.quiz-opt:disabled { cursor: default; opacity: .75; }
.quiz-opt.right { border-color: var(--teal); background: var(--teal-soft); color: var(--ink); opacity: 1; }
.quiz-opt.right::before { content: "✓ "; color: var(--teal); font-weight: 700; }
.quiz-opt.wrong { border-color: var(--danger); opacity: 1; }
.quiz-opt.wrong::before { content: "✗ "; color: var(--danger); font-weight: 700; }
.quiz-fb { margin: 12px 0 10px; min-height: 1.2em; color: var(--ink-2); }
.quiz-fb:empty { margin: 4px 0; }
.quiz-score { font-size: 1.05rem; }
/* ---------- Code blocks ---------- */
.code { position: relative; background: #0f1b24; color: #d7e3ea; border-radius: var(--r-md); margin: 10px 0 16px; border: 1px solid var(--rule); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; border-bottom: 1px solid #22323f; font-size: .8rem; color: #9fb3c1; }
.code-copy { font: inherit; font-size: .8rem; color: #d7e3ea; background: #1d2d39; border: 1px solid #33485a; border-radius: var(--r-sm); padding: 5px 10px; cursor: pointer; min-height: 32px; }
.code-copy:hover { background: #26394a; }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; font: 13.5px/1.55 ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace; tab-size: 2; }
.code .kw { color: #6fd6ce; } .code .ty { color: #e8b04b; } .code .fn { color: #9cc8ff; } .code .num { color: #f3a683; } .code .str { color: #b9f5a0; } .code .com { color: #7d90a1; font-style: italic; } .code .pp { color: #d0a6ff; }

/* ---------- Chapter hero: learning goals ---------- */
.goals { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px 20px; margin: 18px 0 12px; max-width: var(--measure); }
.goals h2 { font-size: 1.05rem; margin-bottom: 8px; }
.goals ul { margin: 0; padding-left: 1.2em; color: var(--ink-2); }
.goals li { margin-bottom: 4px; }

#signal .slider-field, #resolution .slider-field { max-width: 520px; }
.sig-read { max-width: 820px; }

.sig-card .ans-in { display: flex; gap: 8px; max-width: 360px; }
.sig-card .ans-in input { flex: 1; font: inherit; height: 44px; padding: 0 12px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--paper); color: var(--ink); min-width: 0; }

/* ---------- Collapsible working ---------- */
details.working.fold { padding: 0; }
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; font-family: var(--serif); font-weight: 600; font-size: 1rem; min-height: 48px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary:hover .fold-t { color: var(--teal); }
.fold-h::after { content: "Show ▾"; font-family: var(--sans); font-weight: 500; font-size: .85rem; color: var(--teal); white-space: nowrap; }
details.fold[open] .fold-h::after { content: "Hide ▴"; }
.fold-body { padding: 4px 18px 16px; border-top: 1px solid var(--rule); }
.fold-body > .working { border: 0; padding: 8px 0 0; background: none; }
.fold-body .callout { margin-top: 10px; }
.fold-result { font-weight: 600; margin: 4px 0 8px; }

/* ---------- Exercise carousel (swipe left and right) ---------- */
.ex-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; margin: 8px 0 12px; position: -webkit-sticky; position: sticky; top: 110px; z-index: 5; background: color-mix(in srgb, var(--paper) 92%, transparent); padding: 6px 0; }
.ex-arrow { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font-size: 1.6rem; line-height: 1; cursor: pointer; }
.ex-arrow:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.ex-arrow:disabled { opacity: .35; cursor: default; }
.ex-count { font-weight: 600; min-width: 10em; text-align: center; }
.ex-dots { flex-basis: 100%; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.ex-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--ink-3); background: transparent; padding: 0; cursor: pointer; }
.ex-dot.done { background: var(--teal-soft); border-color: var(--teal); }
.ex-dot.on { background: var(--teal); border-color: var(--teal); transform: scale(1.25); }
.ex-track { display: flex; align-items: flex-start; gap: 16px; overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scrollbar-width: none; padding-bottom: 4px; }
.ex-track::-webkit-scrollbar { display: none; }
.ex-track > .ex { flex: 0 0 100%; scroll-snap-align: start; margin-top: 0; min-width: 0; }
.ans-in select { flex: 1; min-width: 0; font: 16px var(--sans); height: 44px; padding: 0 10px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--paper); color: var(--ink); }

@media (prefers-reduced-motion: reduce) { .ex-track { scroll-behavior: auto; } }

/* ---------- Photos and video links (shared by chapters) ---------- */
.photo2 { margin: 12px 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; max-width: 720px; }
.photo2 img { display: block; width: 100%; height: auto; }
.photo2 figcaption { font-size: .8rem; color: var(--ink-3); padding: 7px 12px; border-top: 1px solid var(--rule); }
.photo2 figcaption a { color: var(--ink-3); }
.photo2.small { max-width: 360px; }
.photo2.shot { max-width: 680px; }
.photo2.shot.small { max-width: 460px; }
.photo2.shot img { background: #fff; }
.two-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 14px; margin: 14px 0; }
.two-photos .photo2 { margin: 0; max-width: none; }
.two-photos .photo2 img { height: 240px; object-fit: cover; }
.videos { margin: 14px 0 6px; }
.video-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 10px; }
.video { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 10px 14px; text-decoration: none; color: var(--ink); min-height: 60px; }
.video:hover { border-color: #e1322a; }
.video-play { flex: none; width: 44px; height: 32px; border-radius: 8px; background: #e1322a; display: grid; place-items: center; }
.video-play svg { width: 18px; height: 18px; fill: #fff; }
.video-t strong { display: block; font-weight: 600; font-size: .95rem; line-height: 1.3; }
.video-t small { color: var(--ink-3); font-size: .8rem; }
.video-play.read { background: var(--teal); }
.video:hover:has(.read) { border-color: var(--teal); }
.video-play.read svg { fill: none; stroke: #fff; stroke-width: 2; stroke-linejoin: round; }

/* ======== Animated notes: scenes, graphs and the animation player (Chapters 3 and 4) ======== */
:root {
  --mag: #d81b7a; --pur: #7a2e8e; --yel: #f5e24a;
  --water: #5aaee8; --metal: #9aa6b1; --metal-d: #66737f; --sky: #dfe9f1; --grass: #cfe3c4; --road: #7c858d;
  --lcd: #17261d; --lcd-t: #86f09a; --glass: #8fa3b3; --red: #e2553a; --steel: #8e99a3;
}
:root[data-theme="dark"] {
  --mag: #ec4b9b; --pur: #c58ad8; --yel: #e8d43c;
  --water: #3d8fc9; --metal: #7f8b96; --metal-d: #a9b5c0; --sky: #1b2a36; --grass: #1f3324; --road: #3a444d;
  --lcd: #0b140e; --glass: #6f8596; --steel: #6f7a84;
}

/* ---------- Scene, graph and player layout ---------- */
.pv { margin: 8px 0 0; }
.pv-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px; align-items: start; margin: 12px 0 8px; }
.pv-grid.park { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 760px) { .pv-grid, .pv-grid.park { grid-template-columns: minmax(0, 1fr); } }
.pv-scene, .pv-graph, .scene-box, .extra .plot-box, .lv-graph { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 8px; margin: 0; }
.pv-graph .plot, .lv-graph .plot, .extra .plot { max-width: none; }
.scene-box { margin: 12px 0 8px; }
.scene-box figcaption { font-size: .82rem; color: var(--ink-3); padding: 4px 4px 0; }
.scene-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scene { display: block; width: 100%; height: auto; }
.scene.mic, .scene.tree, .scene.relay { min-width: 420px; max-width: 700px; margin: 0 auto; }
.pv-read { color: var(--ink-2); max-width: var(--measure); margin: 8px 0 10px; min-height: 3.2em; }
.legend { font-size: .82rem; color: var(--ink-3); margin: 4px 4px 0; }
.legend .key { margin-left: 8px; }
.legend .key:first-child { margin-left: 0; }
.small-note { font-size: .82rem; color: var(--ink-3); margin: 4px 0 0; }
.lv-graph { margin-bottom: 8px; }
.extra { margin: 14px 0; }
.extra .plot-box { max-width: 560px; }
.pv-graph .plot, .lv-graph .plot { max-width: 560px; margin: 0 auto; }
.cmp-grid { margin: 12px 0; }

/* player controls */
.pl { display: flex; align-items: center; gap: 8px; max-width: 560px; }
.pl-b { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--rule); background: var(--surface); color: var(--teal); cursor: pointer; display: grid; place-items: center; }
.pl-b:first-child { background: var(--teal); border-color: var(--teal); color: var(--surface); }
.pl-b svg { width: 20px; height: 20px; fill: currentColor; }
.pl-b:hover { border-color: var(--teal); }
.pl-s { flex: 1; min-width: 0; accent-color: var(--teal); height: 28px; touch-action: pan-y; }
.pl-t { flex: none; min-width: 5.5em; font-size: .85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Plot additions ---------- */
.plot .ax { fill: none; stroke: var(--ink-3); stroke-width: 1.2; }
.plot .axl { fill: var(--ink-2); font: 500 12px var(--sans); }
.plot .ghost { fill: none; stroke: var(--ink-3); stroke-width: 1.4; opacity: .35; }
.plot .slope { fill: none; stroke: var(--amber); stroke-width: 1.8; stroke-dasharray: 4 3; }
.plot .band { opacity: .8; }

/* ---------- Scene parts ---------- */
.scene text { fill: var(--ink-2); font: 13px var(--sans); }
.scene .tt { fill: var(--ink); font-weight: 600; font-size: 14px; }
.scene .small { font-size: 12px; fill: var(--ink-3); }
.scene .inv { fill: #fff; }
.scene .lt { fill: #fff; font-weight: 600; }
.scene .w { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.scene .w.thin { stroke-width: 1.2; }
.scene .dot { fill: var(--ink); }
.scene .term { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
.scene .bx, .scene .meter { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
.scene .lcd { fill: var(--lcd); }
.scene .lcdt { fill: var(--lcd-t); font: 600 15px ui-monospace, "Cascadia Code", Consolas, monospace; }
.scene .lcdt.dim { opacity: .7; font-size: 13px; }
.scene .glass { fill: none; stroke: var(--glass); stroke-width: 3; stroke-linejoin: round; }
.scene .water { opacity: .75; }
.scene .plate { stroke: var(--ink-3); stroke-width: 1; }
.scene .ice { fill: #e9f6ff; stroke: #9cc7e6; }
.scene .bubble { fill: none; stroke: #fff; stroke-width: 1.2; opacity: .8; }
.scene .tube { fill: var(--surface); stroke: var(--ink-3); stroke-width: 1.4; }
.scene .merc { fill: var(--red); }
.scene .probe { fill: var(--ink-2); }
.scene .probe-tip { fill: var(--amber); }
.scene .cable { fill: none; stroke: var(--ink-3); stroke-width: 2.5; }
.scene .floor { stroke: var(--ink-3); stroke-width: 2; }
.scene .sky { fill: var(--sky); }
.scene .ground { fill: var(--road); }
.scene .ground.grass, .scene .grass { fill: var(--grass); }
.scene .dist-box { fill: var(--surface); stroke: var(--rule); }
.scene .dist-t { fill: var(--ink); font-weight: 600; font-size: 13px; }
.scene .dist-t.on { fill: var(--amber); }

.plot .mk { fill: none; }
.scene .lcdt.sm { font-size: 13px; }
.lv-graph { max-width: 600px; }
.pv .slider-field { max-width: 560px; }
@media (min-width: 561px) { #exercises .ans { grid-template-columns: minmax(0, 22em) minmax(0, 17em) minmax(0, 1fr); } }
@media (max-width: 560px) {
  .pv .plot .axis, .lv-graph .plot .axis, .extra .plot .axis { font-size: 12.5px; }
  .pv .plot .axl, .lv-graph .plot .axl, .extra .plot .axl { font-size: 13.5px; }
  .pv .plot .ptlab, .pv .plot .mklab, .pv .plot .reflab { font-size: 13px; }
  .scene .small { font-size: 13px; }
}
.tone-btn { margin: 4px 0 6px; }
.tone-btn[aria-pressed="true"] { background: var(--teal); color: var(--surface); }
.tone-i { font-size: 1.1em; }

/* ---------- Chapter 5: oscilloscope and overview ---------- */
.scope-box { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 8px; max-width: 620px; }
.scope-note { max-width: var(--measure); }
.key.ref-key { background: none; border-top: 2px dashed var(--amber); height: 0; }
.scene.cond { min-width: 540px; max-width: 820px; margin: 0 auto; }
.scene .scope { fill: #0f1b24; stroke: var(--ink-3); }
.scene .scope-t { fill: none; stroke: #86f09a; stroke-width: 2; stroke-linejoin: round; }
.scene .flow-l { stroke: var(--ink-3); stroke-width: 2; }
.scene .espbig { fill: #1f3b57; }
.scene .tt.sm { font-size: 13px; }
.scene .op { fill: var(--surface); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }

