@font-face { font-family: "HK Grotesk"; src: url("assets/HKGrotesk-Regular.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "HK Grotesk"; src: url("assets/HKGrotesk-Bold.otf") format("opentype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Fira Code"; src: url("assets/FiraCode-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }

:root {
  --text: #002337;
  --secondary: #4a5c68;
  --canvas: #f7f8f6;
  --panel: #fff;
  --subtle: #e9eef0;
  --divider: #c7d4d9;
  --input-border: #7c929d;
  --accent: #13d6a3;
  --focus: #00634c;
  --ready-text: #00543f;
  --ready-bg: #d7f6eb;
  --waiting-text: #6d4c00;
  --waiting-bg: #fff0c6;
  --late-text: #8d2222;
  --late-bg: #fce5df;
  --running-text: #005074;
  --running-bg: #dcebf6;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--text); font: 1rem/1.5 "HK Grotesk", Arial, sans-serif; }
main { max-width: 1264px; margin: auto; padding: 24px 32px 32px; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.25rem; line-height: 1.2; }
button, input { font: inherit; }
a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
button, summary, input { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.mono, code, output, .duration { font-family: "Fira Code", monospace; font-weight: 400; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin-bottom: 8px; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.intro { margin-top: 8px; color: var(--secondary); }
.reference-label { display: grid; justify-items: end; gap: 12px; font-size: .75rem; }
.tag { padding: 4px 12px; border: 1px solid var(--divider); background: var(--subtle); font-size: .875rem; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 20px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: .875rem; color: var(--secondary); }
.examples { display: flex; gap: 0; }
.examples legend { margin-bottom: 8px; }
.examples label { position: relative; cursor: pointer; }
.examples input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.examples label > span { display: block; min-height: 44px; padding: 8px 16px; border: 1px solid var(--input-border); background: var(--panel); font-weight: 700; }
.examples small { margin-left: 8px; font-size: .875rem; font-weight: 400; }
.examples label + label > span { border-left: 0; }
.examples input:checked + span { background: var(--ready-bg); box-shadow: inset 0 -3px var(--focus); }
.examples input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 3px; position: relative; z-index: 1; }
.transport { display: flex; align-items: center; gap: 8px; }
button { min-height: 44px; padding: 8px 16px; border: 1px solid var(--input-border); color: var(--text); background: var(--panel); font-weight: 700; }
button:disabled { cursor: default; background: var(--subtle); color: var(--secondary); border-color: var(--divider); }
.play { display: flex; min-height: 56px; align-items: center; gap: 8px; background: var(--accent); border-color: var(--focus); }
.play svg { height: 14px; width: 14px; fill: currentColor; }
.board-caption { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: .875rem; }
.board-caption > span:first-child { font-weight: 700; }
.board-caption #elapsed { margin-left: 12px; font-size: .875rem; font-weight: 400; }
.board-caption > span:last-child { color: var(--secondary); }
.board { position: relative; display: grid; grid-template-columns: 15% 35% 13% 20% 17%; border: 1px solid var(--divider); background: var(--panel); }
.stage { min-width: 0; display: grid; grid-template-rows: 68px 300px 112px auto; }
.stage + .stage { border-left: 1px solid var(--divider); }
.stage-heading { display: flex; gap: 8px; align-items: center; padding: 16px 12px; border-bottom: 1px solid var(--divider); }
.stage-heading h2 { font-size: 1.125rem; }
.stage-number { font: .75rem "Fira Code", monospace; color: var(--secondary); }
.media { position: relative; padding: 12px; }
.route { display: flex; position: relative; align-items: center; gap: 16px; min-height: 84px; margin-bottom: 12px; }
.route::before { content: ""; position: absolute; top: 50%; left: -13px; right: -13px; height: 1px; background: var(--input-border); }
.inputs .route::before { left: 50%; }
.node { position: relative; display: grid; align-content: start; gap: 8px; min-height: 84px; padding: 8px 12px 30px; border: 1px solid var(--input-border); background: var(--panel); font-size: .875rem; line-height: 1.3; }
.node .mono { font-size: .75rem; }
.source { width: 100%; background: var(--text); color: var(--panel); border-color: var(--text); }
.source .mono { color: var(--accent); }
.node-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.function { min-width: 108px; }
.long { width: 100%; }
.functions .route:last-child > .function:first-child { flex: 0 0 34%; }
.async { flex: 1; border-style: dashed; }
.duration { white-space: nowrap; }
.extra .node { min-width: 0; width: 100%; padding: 8px 8px 30px; }
.extra .node-heading { gap: 8px; }
.bypass > span { position: relative; align-self: end; background: var(--panel); color: var(--secondary); font-size: .75rem; padding-right: 4px; }
.read-plane { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-left: 2px dashed var(--focus); }
.mixer { position: relative; height: 276px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 8px 12px 30px; background: var(--subtle); border: 1px solid var(--input-border); font-size: .875rem; }
.mixer > p { font-weight: 700; }
.grain { display: inline-block; padding: 4px 8px; font: .75rem/1.3 "Fira Code", monospace; color: var(--text); border: 1px solid var(--focus); background: var(--ready-bg); white-space: nowrap; }
.mixer-time { font-size: 1.25rem; line-height: 1.2; }
.mixer-queues { width: 100%; display: grid; gap: 4px; }
.queue-row { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; align-items: center; font: .75rem "Fira Code", monospace; color: var(--secondary); text-align: left; }
.queue-lane { height: 24px; border-bottom: 1px solid var(--divider); }
.mixer-caption { font-size: .75rem; color: var(--secondary); }
.status { display: inline-block; width: fit-content; padding: 3px 8px; font-size: .75rem; line-height: 1.5; white-space: nowrap; }
.status.ready { color: var(--ready-text); background: var(--ready-bg); }
.status.late { color: var(--late-text); background: var(--late-bg); }
.status.waiting { color: var(--waiting-text); background: var(--waiting-bg); }
.status.running { color: var(--running-text); background: var(--running-bg); }
.read-plane.reading { border-left-width: 4px; border-left-style: solid; }
.read-plane.late { border-color: var(--late-text); }
.output .media { display: flex; align-items: center; }
.output-wire { position: absolute; left: 0; right: 12px; top: 50%; height: 1px; background: var(--input-border); }
.output-wire::after { content: ""; position: absolute; right: -1px; top: -3px; width: 7px; height: 7px; border-top: 1px solid var(--input-border); border-right: 1px solid var(--input-border); transform: rotate(45deg); }
.programme { width: calc(100% - 8px); min-height: 152px; margin-right: 8px; }
.programme[data-state="late"] { border-style: dashed; background: var(--late-bg); }
.identity { color: var(--secondary); font-size: .75rem; }
.stage-note { padding: 12px; font-size: .875rem; border-bottom: 1px solid var(--divider); }
.stage-note > span { font-weight: 700; }
.stage-note p { margin-top: 8px; color: var(--secondary); font-size: .75rem; }
.faders { padding: 16px 12px 12px; background: var(--canvas); }
.faders legend { float: left; width: 100%; min-height: 44px; color: var(--text); font-weight: 700; }
.fader-row { display: flex; justify-content: space-around; clear: both; gap: 8px; }
.fader { display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: center; gap: 12px; text-align: center; font-size: .75rem; }
input[type="range"] { appearance: none; writing-mode: vertical-lr; direction: rtl; width: 44px; height: 116px; margin: 0; background: transparent; touch-action: none; }
input[type="range"]::-webkit-slider-runnable-track { width: 4px; height: 100%; background: var(--divider); border: 1px solid var(--input-border); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 32px; height: 14px; margin-left: -15px; border: 1px solid var(--focus); border-radius: 0; background: var(--accent); }
input[type="range"]::-moz-range-track { width: 4px; height: 100%; background: var(--divider); border: 1px solid var(--input-border); }
input[type="range"]::-moz-range-thumb { width: 30px; height: 12px; border: 1px solid var(--focus); border-radius: 0; background: var(--accent); }
output { font-size: .875rem; white-space: nowrap; }
.scale { margin-top: 12px; text-align: center; color: var(--secondary); font: .75rem "Fira Code", monospace; }
.board-footer { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 12px 16px; border: 1px solid var(--divider); border-top: 0; background: var(--subtle); font-size: .875rem; }
.timestamp-note { display: flex; align-items: center; gap: 12px; }
.board-footer > .mono { font-size: .75rem; white-space: nowrap; }
.mockup-note { margin-top: 12px; color: var(--secondary); font-size: .875rem; }
.arrival-section { margin-top: 28px; }
.arrival-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.arrival-heading p { color: var(--secondary); font-size: .75rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--panel); font-size: .875rem; text-align: left; }
th, td { padding: 10px 16px; border-bottom: 1px solid var(--divider); }
thead th { background: var(--subtle); font-weight: 400; color: var(--secondary); }
td.mono { font-size: .75rem; }
.table-note { margin-top: 8px; color: var(--secondary); font-size: .875rem; }
.explanation { margin-top: 20px; border-top: 1px solid var(--divider); }
summary { padding: 12px 0; font-weight: 700; min-height: 44px; }
.explanation-content { padding: 4px 0 16px; max-width: 920px; }
.explanation-content p + p { margin-top: 12px; }
dl { margin: 0 0 16px; }
dl > div { display: grid; grid-template-columns: 160px 1fr; gap: 16px; padding: 8px 0; }
dt { font-weight: 700; }
dd { margin: 0; }
ul { margin: 0 0 16px; padding-left: 20px; }
li + li { margin-top: 8px; }
.sources { margin-top: 0; }
.sources code { font-size: .875rem; }
.function[data-active="true"] { background: var(--running-bg); }
[data-process]::after { content: ""; position: absolute; height: 4px; left: 0; bottom: 0; width: var(--progress, 0%); background: var(--focus); }
.grain-layer { position: absolute; inset: 0; overflow: clip; pointer-events: none; z-index: 2; }
.grain-particle { position: absolute; transform: translate(-50%, -50%); padding: 2px 5px; min-width: 48px; text-align: center; font: .75rem/1.3 "Fira Code", monospace; white-space: nowrap; color: var(--text); background: var(--accent); border: 1px solid var(--focus); }
.grain-particle.waiting { color: var(--waiting-text); background: var(--waiting-bg); border-color: var(--waiting-text); }
.grain-particle.late { color: var(--late-text); background: var(--late-bg); border-color: var(--late-text); border-style: dashed; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (min-width: 1101px) {
  .extra .route::after { content: ""; position: absolute; right: -12px; top: calc(50% - 3px); width: 7px; height: 7px; border-top: 1px solid var(--input-border); border-right: 1px solid var(--input-border); transform: rotate(45deg); }
}

@media (max-width: 1100px) {
  .page-heading { align-items: start; }
  .reference-label { min-width: 170px; }
  .toolbar { align-items: start; flex-wrap: wrap; }
  .board { grid-template-columns: 1fr; }
  .stage { grid-template-columns: minmax(0, 1fr) 260px; grid-template-rows: auto auto auto; }
  .stage + .stage { border-left: 0; border-top: 1px solid var(--divider); }
  .stage-heading { grid-column: 1 / -1; }
  .media { grid-column: 1; grid-row: 2; }
  .stage-note { grid-column: 1; grid-row: 3; border-bottom: 0; }
  .faders { grid-column: 2; grid-row: 2 / 4; border-left: 1px solid var(--divider); }
  .faders legend { min-height: 36px; }
  .route::before { left: 0; right: 0; }
  .inputs .route::before { display: none; }
  .source { max-width: 200px; }
  .extra .node { max-width: 160px; }
  .bypass > span { align-self: center; padding: 4px 8px; }
  .mixer { max-width: 320px; height: 276px; }
  .read-plane { left: 4px; }
  .output .media { min-height: 180px; }
  .programme { max-width: 240px; }
}

@media (max-width: 650px) {
  main { padding: 16px 12px 24px; }
  .page-heading { flex-direction: column; gap: 12px; margin-bottom: 20px; }
  .reference-label { display: flex; align-items: center; justify-items: start; flex-wrap: wrap; min-width: 0; }
  .toolbar { gap: 12px; }
  .examples { flex-wrap: wrap; }
  .examples label { flex: 1; }
  .examples label > span { padding: 8px 12px; }
  .examples small { display: block; margin-left: 0; }
  .transport { flex-wrap: wrap; }
  .board-caption { flex-direction: column; gap: 4px; }
  .stage { display: flex; flex-direction: column; }
  .stage-heading { padding: 12px; }
  .stage-note { padding-top: 0; }
  .faders { border-left: 0; border-top: 1px solid var(--divider); }
  .faders legend { min-height: 32px; }
  .node { min-height: 84px; }
  .functions .route:last-child { gap: 12px; }
  .functions .route:last-child > .function:first-child { flex-basis: 32%; }
  .function { min-width: 92px; }
  .node-heading { gap: 8px; }
  .async { min-height: 84px; }
  .board-footer { flex-direction: column; align-items: start; gap: 12px; padding: 12px; }
  .timestamp-note { align-items: start; }
  .arrival-heading { flex-direction: column; align-items: start; gap: 8px; }
  th, td { padding: 8px; }
  td.mono { white-space: nowrap; }
  dl > div { grid-template-columns: 1fr; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
