:root {
  --bg: #fbfaf7; --fg: #1f2328; --muted: #5b6168; --line: #8a9099;
  --node: #ffffff; --accent: #2f6fb0; --hbm: #b0552f; --grey: #b9bdc2;
  --panel: #f1efe9;
  /* slider heat scale (heat.js): below the default, at it, above it */
  --heat-lo: #2b6cb0; --heat-mid: #ffffff; --heat-hi: #e08214;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b; --fg: #e6e6e3; --muted: #a2a7ad; --line: #6c727a;
    --node: #22262b; --accent: #6aa6e0; --hbm: #e08a5f; --grey: #4a4f55;
    --panel: #1e2125;
    --heat-lo: #5b9de0; --heat-mid: #0c0d0f; --heat-hi: #f2a541;
  }
}
* { box-sizing: border-box; }
body { margin: 0 auto; max-width: 1200px; padding: 0 16px 24px; background: var(--bg);
       color: var(--fg); font: 15px/1.45 system-ui, sans-serif; }
h1 { margin: 16px 0 4px; font-size: 1.6rem; }
.banner { font-weight: 600; margin: 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.85rem; }
.key { padding: 2px 8px; border-radius: 6px; border: 2px solid var(--fg); }
.key.estimated { border-style: dashed; }
.key.grey { border-color: var(--grey); color: var(--muted); }
.key.curve { border-color: transparent; }
.key.curve svg { width: 36px; height: 12px; vertical-align: middle; fill: none; }

main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 16px; }
@media (max-width: 800px) { main { grid-template-columns: minmax(0, 1fr); } }
#views { min-width: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.tabs [role=tab] { border-radius: 6px 6px 0 0; border-bottom-width: 3px; border-bottom-color: transparent; }
.tabs [role=tab][aria-selected=true] { border-bottom-color: var(--accent); font-weight: 600; }
.machine-wrap { margin: 0; overflow-x: auto; }
#machine { width: 100%; min-width: 540px; height: auto; display: block; }

/* SVG machine */
.node rect { fill: var(--node); stroke: var(--fg); stroke-width: 1.5; }
.node .fill { fill: var(--accent); opacity: 0.25; stroke: none; }
.node .fill.target { fill: var(--hbm); }
#node-hbm_valve .fill { fill: var(--hbm); opacity: 0.6; }
.node.not-in-model rect { stroke: var(--grey); stroke-dasharray: 4 3; fill: none; }
.node.not-in-model text { fill: var(--muted); }
.node.partial rect { stroke: var(--grey); stroke-width: 2; }
text { fill: var(--fg); font-size: 12px; text-anchor: middle; }
text.label { font-weight: 600; font-size: 12.5px; }
text.sub, text.tag { font-size: 10.5px; fill: var(--muted); }
text.tag { font-style: italic; }
text.readout { font-size: 11px; font-variant-numeric: tabular-nums; }
.flow { fill: none; stroke: var(--line); stroke-width: 2; }
.flow.off { stroke: var(--grey); stroke-dasharray: 4 4; }
.flow.partial { stroke: var(--grey); stroke-dasharray: 8 3; }
.flow.pipe { stroke-width: 5; stroke-opacity: 0.35; }
.flow.link { stroke-dasharray: 2 3; }
.particles circle { fill: var(--accent); }
.pulse { fill: none; stroke: var(--hbm); stroke-width: 3; }
.gauge .dial { fill: var(--panel); stroke: var(--line); }
.gauge .needle { stroke: var(--hbm); stroke-width: 3; stroke-linecap: round; }
.gauge .hub { fill: var(--fg); }

/* Time curves (bands under the machine, and the State variables plots) */
.curve-static { fill: none; stroke: var(--fg); stroke-opacity: 0.55; stroke-width: 1.2; }
.curve-run { fill: none; stroke: var(--accent); stroke-opacity: 0.7; stroke-width: 1.5; }
.curve-tail { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; }
.curve-head { fill: var(--accent); stroke: var(--bg); stroke-width: 1; }
.curve-base { stroke: var(--line); stroke-width: 1; }
text.curve-label { font-size: 8.5px; fill: var(--muted); }
.curve.full .curve-static { stroke-width: 1.6; }
.curve.full .curve-run { stroke-width: 2; }
.curve.full .curve-tail { stroke-width: 3.5; }
.axis text { fill: var(--muted); font-size: 10px; }
.axis path, .axis line { stroke: var(--line); }
#plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.plot { margin: 0; padding: 6px 8px; border: 1px solid var(--grey); border-radius: 8px; min-width: 0; }
.plot figcaption { font-size: 0.85rem; }
.plot .now { font-variant-numeric: tabular-nums; color: var(--accent); }
.plot svg { width: 100%; height: auto; display: block; }
.plot .note { margin: 2px 0 0; font-size: 0.75rem; color: var(--muted); }

/* Controls */
#side { display: flex; flex-direction: column; gap: 8px; }
.timeline { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center;
            background: var(--panel); padding: 8px; border-radius: 8px; }
.timeline input { grid-column: 1 / -1; width: 100%; }
.timeline .ends { grid-column: 1 / -1; display: flex; justify-content: space-between;
                  margin-top: -6px; font-size: 0.8rem; color: var(--muted); }
.playopts { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.playopts input { width: auto; }
.playopts .opt { margin-right: auto; }
#status:empty { display: none; }
#status { color: var(--hbm); font-weight: 600; }
.rule { font-weight: 600; margin: 0 0 4px; }
.control { border: 2px solid var(--fg); border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; }
.control.estimated { border-style: dashed; }
.control.not-in-model { border: 2px dashed var(--grey); color: var(--muted); }
.control.inline { display: inline-block; margin: 0; }
.control.plain { border-color: transparent; }
.panel { background: var(--panel); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.panel h3 { font-size: 0.95rem; margin: 0 0 6px; }
.panel .control:not(.plain) { background: var(--bg); }
.panel.shocks { border-left: 4px solid var(--hbm); }
.control label { display: flex; justify-content: space-between; gap: 8px; }
.control input[type=range] { width: 100%; }
/* Model sliders: track and thumb in the value's heat colour (heat.js sets
 * --track and --thumb). The timeline and the disabled saturation slider keep
 * the browser's own look. */
input.heat { appearance: none; -webkit-appearance: none; background: transparent; height: 20px; margin: 2px 0; }
input.heat::-webkit-slider-runnable-track { height: 8px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--track, var(--heat-mid)); }
input.heat::-webkit-slider-thumb { -webkit-appearance: none; box-sizing: border-box; width: 18px; height: 18px; margin-top: -5px;
  border-radius: 50%; border: 2px solid var(--fg); background: var(--thumb, var(--heat-mid)); }
input.heat::-moz-range-track { height: 6px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--track, var(--heat-mid)); }
input.heat::-moz-range-thumb { box-sizing: border-box; width: 18px; height: 18px;
  border-radius: 50%; border: 2px solid var(--fg); background: var(--thumb, var(--heat-mid)); }
.unit { font-size: 0.8rem; color: var(--muted); }
.tag { font-style: italic; font-size: 0.8rem; }
.badge summary { cursor: pointer; font-size: 0.8rem; color: var(--muted); }
.badge ul { margin: 4px 0 0; padding-left: 18px; font-size: 0.8rem; overflow-wrap: anywhere; }
.lab { font-size: 0.75rem; padding: 0 4px; border: 1px solid var(--fg); border-radius: 4px; }
.lab.e { border-style: dashed; }
/* The shock tool: an armed shock button is filled; while one is armed every
 * curve takes the pointer (crosshair) and shows the month under it. */
.shock-btn { border: 2px solid var(--hbm); }
.shock-btn[aria-pressed=true] { background: var(--hbm); color: var(--bg); font-weight: 600; }
#shock-hint { margin: 0 0 6px; }
.curve-hit { fill: transparent; pointer-events: none; }
.placing .curve-hit { pointer-events: all; cursor: crosshair; }
.shock-mark { stroke: var(--hbm); stroke-width: 1.5; stroke-dasharray: 3 2; }
.place-guide { stroke: var(--hbm); stroke-width: 1.5; pointer-events: none; }
#placed { list-style: none; margin: 4px 0 0; padding: 0; font-size: 0.85rem; }
#placed li { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
button.remove { min-width: 24px; min-height: 24px; padding: 0 6px; line-height: 1; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
button { font: inherit; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line);
         background: var(--node); color: var(--fg); cursor: pointer; }

/* Under the hood */
#hood { margin-top: 16px; background: var(--panel); border-radius: 8px; padding: 8px 12px; }
#hood summary { font-weight: 600; cursor: pointer; }
#equations-tex h4 { margin: 10px 0 2px; font-size: 0.9rem; }
#equations-tex .eq { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px;
                     background: var(--node); border-radius: 6px; padding: 0 8px; margin: 3px 0; }
#equations-tex .tex { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 0 4px 2px; }
#equations-tex .katex-display { margin: 6px 0; }
#equations-tex .note { font-size: 0.8rem; color: var(--muted); }
#eq-plain summary { font-weight: 400; font-size: 0.85rem; }
pre { overflow-x: auto; font-size: 12px; background: var(--node); padding: 8px; border-radius: 6px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; font-size: 0.8rem; }
td, th { border-top: 1px solid var(--grey); padding: 4px 6px; vertical-align: top; text-align: left; }
td { overflow-wrap: anywhere; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
a { color: var(--accent); }
footer { margin-top: 16px; font-size: 0.8rem; color: var(--muted); }

/* Hover definitions (glossary.js, roadmap item 10.5): one popover for every
 * element with data-term. HTML terms get a dotted underline; the machine's
 * boxes and the KaTeX symbols only the help cursor. */
/* pointer-events: none, so a press on the popover reaches the slider under it. */
#gloss-pop { position: fixed; z-index: 100; max-width: min(320px, calc(100vw - 16px)); pointer-events: none;
             padding: 6px 10px; background: var(--node); color: var(--fg);
             border: 1px solid var(--fg); border-radius: 6px; font-size: 0.85rem; line-height: 1.4;
             box-shadow: 0 2px 10px rgb(0 0 0 / 0.25); overflow-wrap: anywhere; }
#gloss-pop p { margin: 2px 0; }
#gloss-pop .unit { font-size: 0.8rem; }
[data-term] { cursor: help; }
.key[data-term], label[data-term], h3[data-term], h4[data-term], figcaption b[data-term],
td[data-term], .syms [data-term] { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
[data-term]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#machine [data-term]:focus-visible { outline: none; }
.node:focus-visible > rect:first-child, .gauge:focus-visible .dial { stroke: var(--accent); stroke-width: 3; }
/* A 24 px target (WCAG 2.5.8), 8 px clear of its control: with no gap, Chrome's
 * touch adjustment gives a tap on the "?" to the button beside it. */
.q { display: inline-block; box-sizing: border-box; min-width: 24px; min-height: 24px; line-height: 22px;
     margin-left: 8px; text-align: center;
     border: 1px solid var(--line); border-radius: 50%; font-size: 0.75rem; color: var(--muted);
     vertical-align: middle; user-select: none; }
#equations-tex .syms { flex-basis: 100%; margin: 0 0 4px; font-size: 0.75rem; color: var(--muted); }
#equations-tex .syms code { margin-right: 4px; }
.hit { fill: none; pointer-events: all; }
.node > rect:first-child { pointer-events: all; }
.qrow { display: flex; align-items: center; gap: 6px; }
.qrow label { flex: 1; }
