:root {
  --bg: #0b1122; --fg: #e6ecff; --muted: #8891b8; --card: #111a33; --line: rgba(82, 214, 230, 0.16); --acc: #52d6e6;
  --x: #e0a040; --z: #4f9cff; --good: #39c37a; --bad: #ff5c5c; --focus: #ffd166;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "DejaVu Sans Mono", Menlo, monospace;
  color-scheme: dark;
}
/* same palette as the homepage, light theme from its tp-theme choice */
:root[data-theme="light"] { --bg: #eef1f8; --fg: #101828; --muted: #57617d; --card: #f8faff; --line: rgba(10, 111, 128, 0.2); --acc: #0a6f80; --focus: #b35c00; --good: #1e7f4a; --x: #a8650a; --z: #1f6fe0; --bad: #c62828; color-scheme: light; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 80% at 84% 0%, rgba(155, 123, 255, 0.17), transparent 58%),
    radial-gradient(90% 70% at 2% 96%, rgba(82, 214, 230, 0.13), transparent 58%),
    linear-gradient(180deg, #111a36 0%, var(--bg) 42%, #080e1e 100%);
}
:root[data-theme="light"] body::before {
  background:
    radial-gradient(120% 80% at 84% 0%, rgba(82, 51, 196, 0.10), transparent 58%),
    radial-gradient(90% 70% at 2% 96%, rgba(10, 111, 128, 0.09), transparent 58%),
    linear-gradient(180deg, #e7ecf7 0%, var(--bg) 42%, #e3e9f5 100%);
}
.page { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: clamp(1.45rem, 1rem + 1.6vw, 2rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 14px 0 8px; }
h2 { font: 600 0.72rem/1.4 var(--mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--acc); margin: 0 0 10px; }
a { color: var(--acc); }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.lead { max-width: 110ch; color: var(--fg); margin: 0 0 8px; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nav { display: flex; gap: 8px 22px; flex-wrap: wrap; }
.nav a { font: 0.7rem/1.6 var(--mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); text-decoration: none; border-bottom: 1px solid transparent; }
.nav a:hover, .nav a:focus-visible { color: var(--acc); border-bottom-color: var(--acc); }
.nav [hidden] { display: none; }

/* index */
.cards { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.lcard { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); text-decoration: none; }
.lcard:hover { border-color: var(--acc); }
.lcard .num { font: 0.72rem var(--mono); letter-spacing: 0.2em; color: var(--acc); }
.lcard span:last-child { color: var(--muted); font-size: 0.95rem; }

/* panels */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 12px 0; min-width: 0; }
.panel[hidden], section[hidden] { display: none; }
.panel label { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select, input[type=number], button { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
button:disabled { opacity: 0.6; cursor: wait; }
#play { min-width: 76px; font-weight: 600; border-color: var(--focus); }

/* player: the figure, then its controls, in one panel */
.timeline-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 10px 0 2px; }
.where { color: var(--muted); font: 0.8rem var(--mono); letter-spacing: 0.04em; }
.inject-box { margin-left: auto; font-size: 0.95rem; }
.inject-box[hidden] { display: none; }
.strip-scroll, .heat-scroll, .table-wrap { overflow-x: auto; max-width: 100%; }
.strip { position: relative; }
.strip.fluid { width: 100%; }
.phase-row { position: relative; height: 20px; }
.phase { position: absolute; top: 0; height: 18px; padding: 0 4px; font: 11px/18px var(--mono); color: var(--muted); border-left: 2px solid var(--line); overflow: hidden; white-space: nowrap; }
.phase.tight { color: transparent; }
.block-row { display: flex; }
.gblock { flex: 0 0 38px; width: 38px; height: 42px; margin: 0; padding: 2px 0; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--muted); font: 11px/14px var(--mono); display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; }
.strip.fluid .gblock { flex: 1 1 0; width: auto; min-width: 34px; }
.gblock span { display: block; white-space: nowrap; }
.gblock.inject { color: var(--bad); border-color: var(--bad); }
.gblock.current { background: var(--focus); color: var(--bg); border-color: var(--focus); font-weight: 700; }
/* the thumb centre travels exactly over the strip below */
.slider { display: block; width: calc(100% + 18px); margin: 4px -9px 2px; height: 24px; background: transparent; -webkit-appearance: none; appearance: none; }
.slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--focus); border: 2px solid var(--bg); }
.slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--focus); border: 2px solid var(--bg); box-sizing: border-box; }
/* the caption sits with the controls so it stays next to the slider (sticky on phones) */
.controls .caption { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); min-height: 3.2em; }
.layer-text { min-height: 3.5em; }
.caption { margin: 0; }
.checkline { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pill { display: inline-flex; align-items: center; white-space: nowrap; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.85rem; color: var(--muted); }
.pill b { color: var(--fg); margin-right: 2px; }
.pill .sw { margin: 0 3px 0 8px; }
.sw-ok { background: var(--good); }

/* stage: one player panel with the figure, its controls and the layer text */
.stage { margin: 12px 0 0; }
.stage .panel { margin: 0; }
.error-panel:empty, .error-panel[hidden] { display: none; }
.error-panel { margin-top: 10px; padding: 8px 10px; border-left: 3px solid var(--bad); background: var(--bg); border-radius: 4px; }
/* sized so that figure, controls and the layer text fit one screen */
.patches { display: block; width: 100%; height: auto; max-height: clamp(220px, calc(100vh - 490px), 480px); }
/* phones: the controls come first and stay on screen while the stacked patches scroll under them, inside the player only */
@media (max-width: 600px) {
  .player { display: flex; flex-direction: column; }
  .player .controls { order: -1; position: sticky; top: 0; z-index: 2; background: var(--card); padding-bottom: 6px; }
  .patches { max-height: none; }
  .player .legend { order: 1; }
  .layer-text { order: 2; }
  .pill { font-size: 0.78rem; padding: 2px 8px; }
  .controls .caption { font-size: 0.92rem; min-height: 0; padding-top: 8px; margin-top: 6px; }
  .pill .sw { margin-left: 6px; }
}
.qdot { fill: var(--card); stroke: var(--fg); stroke-width: 2; }
.qdot.hit { fill: var(--bad); }
.qnum { font-size: 11px; fill: var(--fg); pointer-events: none; }
.logline { stroke: var(--fg); stroke-width: 3; stroke-dasharray: 2 4; stroke-opacity: 0.55; }
.logline-on { stroke-width: 5; stroke-linecap: round; }
.logline-on.x { stroke: var(--x); }
.logline-on.z { stroke: var(--z); }
.logline-bad { stroke: var(--bad); stroke-width: 5; stroke-linecap: round; }
.loglab { font-size: 12px; fill: var(--muted); }
.pname { font-size: 15px; font-weight: 600; fill: var(--fg); }
.cxarrow { fill: none; stroke: var(--focus); stroke-width: 3; }
.glab { font-size: 12px; font-weight: 700; fill: var(--focus); paint-order: stroke; stroke: var(--card); stroke-width: 3; }
.glab.err { fill: var(--fg); stroke: var(--bad); stroke-width: 4; }
.legend { font-size: 0.85rem; color: var(--muted); margin: 8px 0 0; }
.sw { display: inline-block; width: 14px; height: 12px; vertical-align: -1px; margin: 0 2px 0 8px; border-radius: 2px; border: 2px solid transparent; }
.sw:first-child { margin-left: 0; }
.sw-x { background: color-mix(in srgb, var(--x) 32%, var(--card)); border-color: var(--x); }
.sw-z { background: color-mix(in srgb, var(--z) 32%, var(--card)); border-color: var(--z); }
.sw-fire { background: var(--bad); }
.sw-off { background: color-mix(in srgb, var(--muted) 22%, var(--card)); border-color: var(--line); }
.und { fill: color-mix(in srgb, var(--muted) 22%, var(--card)); }
.sw-gate { border-color: var(--focus); border-radius: 50%; }
.sw-log { height: 0; width: 16px; border: 0; border-top: 5px solid var(--x); border-radius: 3px; vertical-align: 3px; }
.sw-inj { border-left: 3px dashed var(--bad); border-radius: 0; width: 4px; }
.state ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 20px; }
.state .lbl { color: var(--muted); font: 0.72rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase; margin-right: 6px; }
#error-panel p { margin: 0 0 4px; }
sub { font-size: 0.7em; }

/* circuit */
.circuit svg { display: block; width: 100%; max-width: 900px; height: auto; margin: 0 auto; }
.wire { stroke: var(--fg); stroke-width: 1.6; }
.cwire { fill: none; stroke: var(--fg); stroke-width: 1.1; }
.cbox { fill: var(--card); stroke: var(--fg); stroke-width: 1.6; }
.cdot { fill: var(--fg); }
.ctarget { fill: none; stroke: var(--fg); stroke-width: 1.6; }
.sep { stroke: var(--line); stroke-dasharray: 4 4; }
.clab { font-size: 15px; fill: var(--fg); }
.cnote { font-size: 12px; fill: var(--muted); text-anchor: middle; }

/* results */
table { border-collapse: collapse; font-size: 0.9rem; min-width: 560px; width: 100%; }
caption { text-align: left; color: var(--muted); padding-bottom: 6px; caption-side: top; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th[scope=row], thead th:first-child { text-align: left; }
th[scope=row] { white-space: normal; min-width: 11em; }
thead th { font: 600 0.68rem/1.4 var(--mono); letter-spacing: 0.06em; color: var(--muted); white-space: normal; vertical-align: bottom; }
.source { font: 0.75rem/1.5 var(--mono); color: var(--muted); margin: 8px 0 0; }

/* live */
.live-form { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-start; }
.live-form > label { flex-direction: column; align-items: flex-start; gap: 2px; }
.live-form fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 10px; display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0; min-width: 0; }
.live-form input[type=number] { width: 4.5em; }
.live-form input[type=range] { width: 180px; max-width: 100%; }
#lv-run { font-weight: 600; border-color: var(--z); }
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 150px; flex: 1 1 150px; }
.card .big { font-size: 1.4rem; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 0.85rem; }
.heat-inner { width: 100%; }
.heat-inner .gblock { cursor: default; }
.hlab { font-size: 11px; fill: var(--muted); }
.live-form fieldset:disabled label { opacity: 0.5; }
