@import url('./tokens.css');
@import url('./hyphae.css');

/* Studio first, story below. The stage and the control rail share one viewport-tall row;
   the rail scrolls on its own and keeps the transport and export pinned. */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
button, a, input, summary { -webkit-tap-highlight-color: transparent; }
button, input, summary { cursor: pointer; }
button { font: inherit; color: inherit; transition: background .15s, border-color .15s, color .15s, box-shadow .2s; }
a { color: inherit; text-decoration: none; }
button:disabled { opacity: .4; cursor: not-allowed; }
:where(button,a,input,summary,canvas):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Top bar */
.masthead { height: 56px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 10px; font: 500 13px var(--mono); letter-spacing: -.01em; }
.brand-studio { color: var(--faint); font-weight: 400; }
.header-actions { display: flex; align-items: center; gap: 20px; }
.theme-toggle { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 13px; font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.theme-toggle:hover { color: var(--text); border-color: var(--line-strong); }

/* Page order: studio, then the story of the running process. */
main { display: flex; flex-direction: column; padding: 0 24px; }
.process-picker { order: 1; }
.workspace { order: 2; }
.intro { order: 3; }
.notes { order: 4; }

/* Process tabs; each dot carries its process colour. */
.process-picker { display: flex; align-items: stretch; height: 52px; gap: 4px; }
.process-picker button { display: flex; align-items: center; gap: 10px; padding: 0 16px; border: 0; border-bottom: 1px solid transparent; background: transparent; color: var(--muted); font-size: 13px; text-align: left; white-space: nowrap; }
/* Six processes fit in one row at 1440 px: only the active tab shows its subtitle. */
.process-picker button:not([aria-pressed=true]) small { display: none; }
.process-picker button > span:nth-child(2) { display: flex; align-items: baseline; gap: 10px; }
.process-picker small { font-size: 12px; color: var(--faint); }
.process-picker button:hover { color: var(--text); }
.process-picker button[aria-pressed=true] { color: var(--text); border-bottom-color: var(--accent); box-shadow: inset 0 -1px 0 var(--accent); }
.process-number { font: 11px var(--mono); color: var(--faint); }
.process-dot { order: -1; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .45; }
#process-barkley .process-dot { color: #3ce296; }
#process-physarum .process-dot { color: #39c7f8; }
#process-grayscott .process-dot { color: #ff3cbe; }
:root[data-theme=light] #process-barkley .process-dot { color: #0b7a4f; }
:root[data-theme=light] #process-physarum .process-dot { color: #0a6d99; }
:root[data-theme=light] #process-grayscott .process-dot { color: #b10f7e; }
.process-picker button[aria-pressed=true] .process-dot { opacity: 1; box-shadow: 0 0 10px currentColor; }

/* Workspace */
.workspace { display: grid; grid-template-columns: minmax(0,1fr) 320px; height: calc(100svh - 56px - 52px - 24px); min-height: 620px; border: 1px solid var(--line); background: var(--stage); }

/* Stage: always black, like the reels. A faint lab grid fades out towards the edges. */
.viewport { position: relative; min-width: 0; min-height: 0; overflow: hidden; container-type: size;
  background:
    radial-gradient(ellipse at 50% 50%, transparent 20%, var(--stage) 78%),
    radial-gradient(circle, #ffffff12 1px, transparent 1.6px) center / 24px 24px,
    var(--stage); }
.viewport-top, .viewport-bottom { position: absolute; left: 0; right: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; font: 11px var(--mono); letter-spacing: .06em; color: var(--hud); pointer-events: none; }
.viewport-top { top: 0; text-transform: uppercase; }
.viewport-bottom { bottom: 0; letter-spacing: .02em; }
#clock { color: var(--hud-strong); font-variant-numeric: tabular-nums; }
.live-dot { position: relative; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); margin: 0 9px 1px 0; }
.live-dot::after { content: ""; position: absolute; inset: -5px; border: 1px solid var(--accent); border-radius: 50%; opacity: 0; animation: live 2.6s ease-out infinite; }
@keyframes live { from { transform: scale(.35); opacity: .7; } to { transform: scale(1.5); opacity: 0; } }
.is-paused .live-dot { background: var(--hud); box-shadow: none; }
.is-paused .live-dot::after { animation: none; }

/* The field fits the largest square the stage allows; brackets and a ruler frame it. */
.canvas-wrap { position: absolute; inset: 0; margin: auto; --side: min(calc(100cqw - 56px), calc(100cqh - 116px)); width: var(--side); height: var(--side); outline: 1px solid #ffffff0f; }
.canvas-wrap::before { content: ""; position: absolute; left: 0; right: 0; top: -7px; height: 4px; pointer-events: none; background: repeating-linear-gradient(90deg, #ffffff38 0 1px, transparent 1px 6.25%); }
.canvas-wrap::after { content: ""; position: absolute; inset: -10px; pointer-events: none; --c: #ffffff5c; --l: 12px;
  background:
    linear-gradient(var(--c),var(--c)) left top / var(--l) 1px,
    linear-gradient(var(--c),var(--c)) left top / 1px var(--l),
    linear-gradient(var(--c),var(--c)) right top / var(--l) 1px,
    linear-gradient(var(--c),var(--c)) right top / 1px var(--l),
    linear-gradient(var(--c),var(--c)) left bottom / var(--l) 1px,
    linear-gradient(var(--c),var(--c)) left bottom / 1px var(--l),
    linear-gradient(var(--c),var(--c)) right bottom / var(--l) 1px,
    linear-gradient(var(--c),var(--c)) right bottom / 1px var(--l);
  background-repeat: no-repeat; }
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.cursor-ring { position: absolute; border: 1px solid #ffffffb0; border-radius: 50%; pointer-events: none; transform: translate(-50%,-50%); }

/* In-frame data block, as the reels cite their model. Only where the stage has a wide gutter. */
.readout { display: none; position: absolute; left: 20px; bottom: 56px; z-index: 2; width: 136px; margin: 0; font: 11px/1.45 var(--mono); pointer-events: none; }
.readout div { padding: 8px 0; border-top: 1px solid #ffffff17; }
.readout dt { color: var(--hud); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.readout dd { margin: 2px 0 0; color: var(--hud-strong); }
@container (min-aspect-ratio: 136/100) {
  body[data-process=barkley] .readout[data-model=barkley],
  body[data-process=physarum] .readout[data-model=physarum],
  body[data-process=grayscott] .readout[data-model=grayscott] { display: block; }
}

/* Control rail */
.controls { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 22px 20px 0; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.panel-heading { margin-bottom: 16px; }
.panel-heading .eyebrow { display: none; }
.panel-heading h2 { margin: 0; font: 400 26px/1.1 var(--display); letter-spacing: -.02em; }
.panel-heading > p:last-child { margin: 5px 0 0; font-size: 12.5px; color: var(--muted); }
.control-section { border-top: 1px solid var(--line); padding-top: 14px; margin: 0 0 14px; }
.section-label { display: flex; justify-content: space-between; margin-bottom: 12px; font: 10.5px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.section-label h3 { font: inherit; margin: 0; color: var(--muted); }
.segments { display: flex; gap: 4px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.segments button { flex: 1; padding: 8px 4px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12.5px; }
.segments button:hover { color: var(--text); }
.segments button[aria-pressed=true] { background: var(--surface); border-color: var(--line-strong); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.help { font-size: 12px; line-height: 1.5; color: var(--muted); margin: 6px 0 2px; }
label { display: flex; align-items: baseline; gap: 6px; font-size: 12.5px; margin: 12px 0 2px; }
output { margin-left: auto; color: var(--accent); font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.parameter-symbol { color: var(--faint); font: italic 12px var(--display); }
input[type=range] { display: block; appearance: none; width: 100%; height: 20px; margin: 0; background: transparent; --track: linear-gradient(to right,var(--accent) var(--fill,50%),var(--line-strong) var(--fill,50%)); }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--track); }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); transition: box-shadow .2s; }
input[type=range]:hover::-webkit-slider-thumb, input[type=range]:active::-webkit-slider-thumb { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 20%, transparent); }
input[type=range]::-moz-range-track { height: 2px; background: var(--track); }
input[type=range]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); }
.legend { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 4px; color: var(--muted); font: 10.5px var(--mono); }
.gradient { grid-column: 1/3; height: 6px; border-radius: 3px; background: linear-gradient(90deg,#06100b,#003e2c,#009660,#3ce296,#afface,#f0fff6); }
.species-key { display: flex; gap: 18px; color: var(--muted); font-size: 12px; }
.species-key i, .cue-key i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 6px 1px 0; }
.cyan { background: #39c7f8; } .magenta { background: #f4449c; }
.cue-key { font-size: 12px; color: var(--muted); } .cue-key i { background: #d6ad5b; }

/* Sister rails: Folding, Turing and Affinity share one layout. Order follows the DOM, so focus order is
   the visual order. Every group reads its visible label from its own aria-label, like a slider
   label; the palette name sits beside the swatches. Ramps and accents of each card follow below. */
:is(#folding-controls, #grayscott-controls, #affinity-controls) { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > * { flex: 1 0 100%; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > :is(.segments, [id$=-palettes]) { position: relative; margin-top: 38px; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > :is(.segments, [id$=-palettes]):first-child { margin-top: 26px; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > :is(.segments, [id$=-palettes])::before { content: attr(aria-label); position: absolute; left: 0; bottom: 100%; padding-bottom: 7px; color: var(--text); font: 12.5px/1.5 var(--sans); white-space: nowrap; pointer-events: none; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > .segments::before { left: -1px; }
:is(#folding-controls, #grayscott-controls, #affinity-controls) > .help { margin-top: 16px; }
/* Palette swatches in the language of Reentry channels: one per palette, three in Demo, six in Studio. */
:is(#folding-palettes, #grayscott-palettes) { flex: 0 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 26px; gap: 10px; padding: 4px 0; }
:is(#folding-palettes, #grayscott-palettes) button { width: 26px; aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%; overflow: hidden; font-size: 0; color: transparent; background: var(--swatch); box-shadow: inset 0 0 0 1px #ffffff29; transition: transform .2s, box-shadow .2s; }
:is(#folding-palettes, #grayscott-palettes) button:hover { transform: scale(1.08); }
:is(#folding-palettes, #grayscott-palettes) button[aria-pressed=true] { box-shadow: inset 0 0 0 1px #ffffff33, 0 0 0 2.5px var(--panel), 0 0 0 4px var(--text); }
:root[data-theme=light] :is(#folding-palettes, #grayscott-palettes) button:not([aria-pressed=true]) { box-shadow: 0 0 0 1px #0000001f; }
:is(#folding-palette-name, #grayscott-palette-name) { flex: 1 1 0; align-self: flex-end; min-width: max-content; text-align: right; color: var(--text); font: 400 10.5px/34px var(--mono); letter-spacing: .1em; }
/* Form stops: a segment under the Form slider, named after each form. */
#form-stops { display: flex; gap: 2px; margin-top: 8px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
#form-stops button { flex: 1; min-width: 0; padding: 6px 0; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted); font-size: 11.5px; }
#form-stops button:hover { color: var(--text); }
#form-stops button[aria-pressed=true] { background: var(--surface); border-color: var(--line-strong); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
/* Legends: the ramp of the running palette, thin as in Reentry. */
:is(#folding-image, #grayscott-image) .legend { margin-top: 10px; }
:is(#folding-image, #grayscott-image) .gradient { height: 4px; border-radius: 2px; }
:root[data-theme=light] :is(#folding-image, #grayscott-image) .gradient { box-shadow: inset 0 0 0 1px var(--line); }
/* Stage: the live dot and the cursor stay in the bright stop on the black stage in both themes. */
body:is([data-process=folding], [data-process=grayscott], [data-process=affinity]) .live-dot { background: var(--accent-stage); box-shadow: 0 0 10px var(--accent-stage); }
body:is([data-process=folding], [data-process=grayscott], [data-process=affinity]) .live-dot::after { border-color: var(--accent-stage); }
body:is([data-process=folding], [data-process=grayscott], [data-process=affinity]).is-paused .live-dot { background: var(--hud); box-shadow: none; }
/* Symmetry copies of the brush: thinner and quieter than the cursor they follow. */
#cursor-ghosts .cursor-ring.ghost { border-width: .5px; opacity: .4; }
/* Readout: a chip of the running ramp before the palette name. */
:is(#folding-palette, #grayscott-palette-readout, #affinity-palette-readout)::before { content: ""; display: inline-block; width: 18px; height: 4px; margin: 0 8px 2px 0; border-radius: 2px; vertical-align: middle; }
:is(#folding-nodes, #grayscott-field-readout) { font-variant-numeric: tabular-nums; }

/* ---------- Folding · differential growth ----------
   Accent = the running palette; the tab keeps CULTURE, the identity of the process, as PHOSPHOR in
   Reentry. Kept in this file: the release file lists admit no other stylesheet (docs/design_notes.md). */
#process-folding .process-dot { color: #56eb46; }
:root[data-theme=light] #process-folding .process-dot { color: #2f7d1f; }
body[data-process=folding] #process-folding[aria-pressed=true] { border-bottom-color: #56eb46; box-shadow: inset 0 -1px 0 #56eb46; }
:root[data-theme=light] body[data-process=folding] #process-folding[aria-pressed=true] { border-bottom-color: #2f7d1f; box-shadow: inset 0 -1px 0 #2f7d1f; }

/* ---------- Accent from the running palette ----------
   --accent-stage: the bright stop, on the black stage in both themes.
   --accent-light: darker step for light surfaces, at least 4.6:1 on --bg. Values as in reentry.css;
   CULTURE is the stop of the reel, #2f7d1f on light (4.7:1 on --bg, 5.2:1 on the rail). */
body[data-process=folding] { --accent-stage: #56eb46; --accent-light: #2f7d1f; --accent-ink: #041203; }
body[data-process=folding][data-palette=RUBY] { --accent-stage: #f0343a; --accent-light: #de000d; --accent-ink: #180204; }
body[data-process=folding][data-palette=ICE] { --accent-stage: #3092ff; --accent-light: #0068e4; --accent-ink: #020a18; }
body[data-process=folding][data-palette=NEON] { --accent-stage: #60e8f0; --accent-light: #d5007c; --accent-ink: #021416; }
body[data-process=folding][data-palette=OXIDE] { --accent-stage: #f0a234; --accent-light: #a25d1f; --accent-ink: #180f02; }
body[data-process=folding][data-palette=MERCURY] { --accent-stage: #a0aaba; --accent-light: #606f85; --accent-ink: #0b0c0e; }
body[data-process=folding] { --accent: var(--accent-stage); }
:root[data-theme=light] body[data-process=folding] { --accent: var(--accent-light); --accent-ink: #ffffff; }

/* Ramp of the running palette (docs/folding_propozycja.md §10) for the stage readout. The controller
   writes the same --p0…4 on each swatch and on #folding-image, and those win where present. */
body[data-process=folding] { --p0: #000e0a; --p1: #006e46; --p2: #56eb46; --p3: #c8ff6e; --p4: #f0ffdc; }
body[data-process=folding][data-palette=RUBY] { --p0: #100206; --p1: #780c28; --p2: #f04048; --p3: #ff966e; --p4: #ffe8d2; }
body[data-process=folding][data-palette=ICE] { --p0: #000614; --p1: #003482; --p2: #148cff; --p3: #6edcff; --p4: #e1faff; }
body[data-process=folding][data-palette=NEON] { --p0: #0a0018; --p1: #560096; --p2: #d000a0; --p3: #00d2ff; --p4: #c8ffff; }
body[data-process=folding][data-palette=OXIDE] { --p0: #0e0600; --p1: #6e2800; --p2: #eb8214; --p3: #ffcd5a; --p4: #fff5d7; }
body[data-process=folding][data-palette=MERCURY] { --p0: #060608; --p1: #383a42; --p2: #8c919c; --p3: #cdd2da; --p4: #fafafc; }

/* Five-stop ramp: a swatch is a colony, oldest tissue in the middle, new growth at the rim. */
#folding-palettes button { --swatch: radial-gradient(circle closest-side, var(--p0) 0, var(--p1) 34%, var(--p2) 60%, var(--p3) 82%, var(--p4) 100%); }
/* Age: oldest tissue is the first stop, new growth the last. */
#folding-image .gradient { background: linear-gradient(90deg, var(--p0), var(--p1), var(--p2), var(--p3), var(--p4)); }
#folding-palette::before { background: linear-gradient(90deg, var(--p1), var(--p2), var(--p3), var(--p4)); }

/* ---------- Stage ---------- */
@container (min-aspect-ratio: 136/100) {
  body[data-process=folding] .readout[data-model=folding] { display: block; }
}
/* Seed over a colony recolours it with the running palette: the ring previews the new colour. */
body[data-process=folding] #cursor[data-recolour] { border: 1.5px solid var(--accent-stage); background: color-mix(in srgb, var(--accent-stage) 14%, transparent); box-shadow: 0 0 14px -2px color-mix(in srgb, var(--accent-stage) 70%, transparent); }

/* ---------- Turing · Gray–Scott ----------
   Accent = the running palette; the tab keeps SYNAPSE (tokens.css), as PHOSPHOR in Reentry. */
body[data-process=grayscott] #process-grayscott[aria-pressed=true] { border-bottom-color: #ff3cbe; box-shadow: inset 0 -1px 0 #ff3cbe; }
:root[data-theme=light] body[data-process=grayscott] #process-grayscott[aria-pressed=true] { border-bottom-color: #b10f7e; box-shadow: inset 0 -1px 0 #b10f7e; }

/* ---------- Accent from the running palette ----------
   --accent-stage on the black stage in both themes, --accent-light at least 4.6:1 on --bg.
   SYNAPSE as in tokens.css, the others as in reentry.css. */
body[data-process=grayscott] { --accent-stage: #ff3cbe; --accent-light: #b10f7e; --accent-ink: #1a0212; }
body[data-process=grayscott][data-palette=ICE] { --accent-stage: #3092ff; --accent-light: #0068e4; --accent-ink: #020a18; }
body[data-process=grayscott][data-palette=CIRCUIT] { --accent-stage: #ff5e00; --accent-light: #c24400; --accent-ink: #160600; }
body[data-process=grayscott][data-palette=OXIDE] { --accent-stage: #f0a234; --accent-light: #a25d1f; --accent-ink: #180f02; }
body[data-process=grayscott][data-palette=CITRON] { --accent-stage: #aace14; --accent-light: #617601; --accent-ink: #0b1000; }
body[data-process=grayscott][data-palette=MERCURY] { --accent-stage: #a0aaba; --accent-light: #606f85; --accent-ink: #0b0c0e; }
body[data-process=grayscott][data-palette] { --accent: var(--accent-stage); }
:root[data-theme=light] body[data-process=grayscott][data-palette] { --accent: var(--accent-light); --accent-ink: #ffffff; }

/* Six-stop ramps (docs/grayscott_propozycja.md §10). The controller does not write them, so each
   swatch takes its own and the body takes the running one for the legend and the readout chip.
   Inline --p0…5 from the controller would win over these. */
body[data-process=grayscott], [data-grayscott-palette=SYNAPSE] { --p0: #06001c; --p1: #560096; --p2: #d000a0; --p3: #ff3cbe; --p4: #00e1ff; --p5: #c8ffff; }
body[data-process=grayscott][data-palette=ICE], [data-grayscott-palette=ICE] { --p0: #020618; --p1: #102c8c; --p2: #1864e2; --p3: #3caaff; --p4: #a0e0ff; --p5: #ecfaff; }
body[data-process=grayscott][data-palette=CIRCUIT], [data-grayscott-palette=CIRCUIT] { --p0: #0e020a; --p1: #801218; --p2: #cc2c12; --p3: #ff6808; --p4: #ffb028; --p5: #fff0c4; }
body[data-process=grayscott][data-palette=OXIDE], [data-grayscott-palette=OXIDE] { --p0: #041012; --p1: #0a4242; --p2: #1a7066; --p3: #b86e2a; --p4: #f6aa3c; --p5: #ffecbe; }
body[data-process=grayscott][data-palette=CITRON], [data-grayscott-palette=CITRON] { --p0: #060a02; --p1: #344a08; --p2: #688e0c; --p3: #b0d218; --p4: #e8f46e; --p5: #fcffe0; }
body[data-process=grayscott][data-palette=MERCURY], [data-grayscott-palette=MERCURY] { --p0: #060709; --p1: #363a42; --p2: #646a78; --p3: #a6b0c0; --p4: #d6deea; --p5: #fafcff; }

/* A swatch is a spot: tissue at rest in the middle, fresh growth at the rim. */
#grayscott-palettes button { --swatch: radial-gradient(circle closest-side, var(--p0) 0, var(--p1) 30%, var(--p2) 52%, var(--p3) 70%, var(--p4) 86%, var(--p5) 100%); }
/* Freshness: rested tissue sits at t = .22 of the ramp, not at its first stop. Six even stops,
   so .22 is one tenth from p1 to p2, and p2…p5 fall at (.4, .6, .8, 1 − .22) / .78. */
#grayscott-image .gradient { background: linear-gradient(90deg, color-mix(in srgb, var(--p1) 90%, var(--p2)) 0, var(--p2) 23.1%, var(--p3) 48.7%, var(--p4) 74.4%, var(--p5) 100%); }
#grayscott-palette-readout::before { background: linear-gradient(90deg, var(--p1), var(--p2), var(--p3), var(--p4), var(--p5)); }

/* ---------- Form ----------
   With the Form tool the slider sets the brush, not the dish: its label takes the accent and a ring. */
#grayscott-controls:has([data-grayscott-tool=form][aria-pressed=true]) #form-label { color: var(--accent); }
#grayscott-controls:has([data-grayscott-tool=form][aria-pressed=true]) #form-label::before { content: ""; display: inline-block; width: 7px; height: 7px; margin: 0 7px 1px 0; border: 1px solid currentColor; border-radius: 50%; }
#form-fk { display: block; margin: 9px 0 0; color: var(--faint); font: 10.5px/1.4 var(--mono); letter-spacing: .04em; }

/* Actions stay pinned while the rail scrolls. */
.actions { position: sticky; bottom: 0; margin: auto -20px 0; padding: 14px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--panel); border-top: 1px solid var(--line); }
.actions::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 18px; background: linear-gradient(transparent, var(--panel)); pointer-events: none; }
.transport { display: contents; }
.transport button { padding: 9px 6px; border: 1px solid var(--line-strong); border-radius: 6px; background: transparent; font-size: 12.5px; }
.transport button:hover { background: var(--surface); }
.export { grid-column: 1/-1; display: flex; justify-content: space-between; padding: 11px 14px; border: 1px solid var(--accent); border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); font-size: 13px; font-weight: 500; }
.export span { color: var(--accent); }
.export:hover { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 38%, transparent); }
.export:hover span { color: inherit; }
.recipe { display: flex; align-items: center; gap: 5px; padding: 4px 0; border: 0; background: none; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
#load-session { justify-content: flex-end; }
.recipe:hover { color: var(--text); }
.status { grid-column: 1/-1; min-height: 17px; margin: 2px 0 0; font: 10.5px/1.6 var(--mono); color: var(--faint); }

/* ---------- View: full screen and panels (docs/design_notes.md, Demo contracts) ----------
   Two switches in the top right of the stage, drawn as icons on the black: Panels hides the rail and the
   benches on the stage, and the stage fills the window; Full screen takes the whole .workspace, rail
   included, until Panels hides it. The field keeps its square and its frame; nothing reloads. When the
   pointer rests, the lines of the stage, the switches and the cursor fade (body[data-idle]). */
.viewport-top:has(.view-tools) { padding-right: 88px; }
.view-tools { position: absolute; top: 11px; right: 14px; display: flex; gap: 4px; pointer-events: auto; }
.view-tools button { position: relative; width: 30px; height: 26px; padding: 0; border: 1px solid #ffffff1f; border-radius: 6px; background: #000000a6; color: var(--hud-strong); font-size: 0; }
.view-tools button:hover { border-color: #ffffff4d; color: #ffffff; }
.view-tools button:focus-visible { outline-color: var(--accent-stage, var(--accent)); outline-offset: 2px; }
.view-tools button::before { content: ""; position: absolute; inset: 0; margin: auto; }
/* Panels: a window with its rail; the rail is filled while the panels show, a hairline once hidden. */
#view-panels::before { width: 16px; height: 12px; border: 1px solid currentColor; border-radius: 2px; background: linear-gradient(currentColor, currentColor) 100% 0 / 5px 100% no-repeat; }
#view-panels[aria-pressed=false]::before { background: linear-gradient(currentColor, currentColor) calc(100% - 4px) 0 / 1px 100% no-repeat; }
/* Full screen: four corners pointing out; in full screen they point in. */
#view-fullscreen::before { width: 14px; height: 14px; --c: currentColor;
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / 5px 1px, linear-gradient(var(--c), var(--c)) 0 0 / 1px 5px,
    linear-gradient(var(--c), var(--c)) 100% 0 / 5px 1px, linear-gradient(var(--c), var(--c)) 100% 0 / 1px 5px,
    linear-gradient(var(--c), var(--c)) 0 100% / 5px 1px, linear-gradient(var(--c), var(--c)) 0 100% / 1px 5px,
    linear-gradient(var(--c), var(--c)) 100% 100% / 5px 1px, linear-gradient(var(--c), var(--c)) 100% 100% / 1px 5px;
  background-repeat: no-repeat; }
#view-fullscreen[aria-pressed=true]::before {
  background:
    linear-gradient(var(--c), var(--c)) 0 4px / 5px 1px, linear-gradient(var(--c), var(--c)) 4px 0 / 1px 5px,
    linear-gradient(var(--c), var(--c)) 100% 4px / 5px 1px, linear-gradient(var(--c), var(--c)) 9px 0 / 1px 5px,
    linear-gradient(var(--c), var(--c)) 0 9px / 5px 1px, linear-gradient(var(--c), var(--c)) 4px 100% / 1px 5px,
    linear-gradient(var(--c), var(--c)) 100% 9px / 5px 1px, linear-gradient(var(--c), var(--c)) 9px 100% / 1px 5px;
  background-repeat: no-repeat; }
/* The stage fills the window: panels hidden, or full screen where the browser has none for elements. */
body:is([data-panels=hidden], [data-fill]) { overflow: hidden; }
body:is([data-panels=hidden], [data-fill]) .workspace { position: fixed; inset: 0; z-index: 50; height: auto; min-height: 0; border: 0; }
.workspace:fullscreen { width: 100%; height: 100%; min-height: 0; border: 0; }
.workspace::backdrop { background: #000; }
body[data-panels=hidden] .workspace { grid-template-columns: minmax(0, 1fr); }
body[data-panels=hidden] :is(.controls, .hud, .readout) { display: none !important; }
/* Reentry and Hyphae make room for their bench on the stage; without it the field is centred as elsewhere. */
body[data-process][data-panels=hidden] .canvas-wrap { inset: 0; --side: min(calc(100cqw - 56px), calc(100cqh - 116px)); }
.viewport-top, .viewport-bottom { transition: opacity .2s; }
body[data-idle] :is(.viewport-top, .viewport-bottom) { opacity: 0; transition: opacity .8s; }
body[data-idle] :is(.viewport, .viewport canvas) { cursor: none; }

/* ---------- Demo: editions ----------
   One link in the masthead and one sentence after the first PNG; both open the editions in a new tab,
   because the Demo keeps no experiment. Quiet: the Demo is a complete tool, not a teaser. */
.masthead-link { padding: 6px 2px; color: var(--muted); font: 11px var(--mono); letter-spacing: .02em; white-space: nowrap; }
.masthead-link::after { content: "↗"; margin-left: 6px; color: var(--faint); transition: color .15s; }
.masthead-link:hover { color: var(--text); }
.masthead-link:hover::after { color: var(--accent); }
.edition-note { grid-column: 1/-1; margin: 0; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font: 11px/1.55 var(--sans); }
.edition-note a { color: var(--text); text-decoration: underline 1px; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.edition-note a:hover { color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .viewport-top, .viewport-bottom, body[data-idle] :is(.viewport-top, .viewport-bottom), .masthead-link::after { transition: none; }
}

/* Story of the running process */
.intro, .notes { width: 100%; max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1.5fr; gap: 20px 64px; }
.intro { align-items: end; padding: 88px 0 40px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 20px; color: var(--faint); font: 11px var(--mono); letter-spacing: .14em; }
h1 { margin: 0; font: 300 clamp(40px,4.4vw,68px)/1.02 var(--display); letter-spacing: -.035em; }
h1 em { font-style: normal; color: var(--accent); }
.intro-copy { margin: 0; color: var(--muted); font-size: 17px; line-height: 1.65; }
.notes { padding: 40px 0 72px; }
.notes > .eyebrow { margin: 5px 0 0; }
.notes > p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.75; }
.notes p span, .notes a { color: var(--text); }
.notes a { text-decoration: underline; text-underline-offset: 3px; }
.notes details { grid-column: 2; font-size: 14px; line-height: 1.75; color: var(--muted); }
.notes summary { list-style: none; display: flex; justify-content: space-between; padding: 14px 0 0; border-top: 1px solid var(--line); color: var(--text); }
.notes summary::-webkit-details-marker { display: none; }
.notes summary span { transition: transform .2s; }
.notes details[open] summary span { transform: rotate(45deg); }
footer { display: flex; justify-content: space-between; gap: 24px; padding: 22px 24px 30px; border-top: 1px solid var(--line); font: 11px var(--mono); color: var(--muted); }
.muted { color: var(--faint); }
.error { position: absolute; inset: 15%; z-index: 3; display: grid; place-content: center; padding: 25px; background: #111114f2; border: 1px solid #4a4a52; color: #ededf0; font-size: 14px; line-height: 1.7; }
.mobile-notice { display: none; }

@media (max-width: 1050px) {
  .brand-studio { display: none; }
  .workspace { grid-template-columns: minmax(0,1fr) 284px; }
  .process-picker small { display: none; }
  .recipe span { display: none; }
  .intro, .notes { grid-template-columns: 1fr; }
  .notes details { grid-column: 1; }
}
@media (max-width: 760px) {
  .masthead { padding: 0 20px; }
  main { padding: 0 20px; }
  .intro { order: 0; display: block; padding: 36px 0 24px; border: 0; }
  h1 { font-size: 42px; }
  .intro-copy { margin-top: 18px; font-size: 15px; }
  .workspace, .process-picker { display: none; }
  .mobile-notice { display: block; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
  .mobile-notice h2 { font: 400 24px/1.2 var(--display); letter-spacing: -.02em; }
  .mobile-notice p { color: var(--muted); font-size: 14px; line-height: 1.7; }
  .notes { display: block; padding: 24px 0; } .notes > .eyebrow { margin-bottom: 14px; } .notes details { margin-top: 20px; }
  footer { padding: 22px 20px; } footer > span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  button, input[type=range]::-webkit-slider-thumb, .notes summary span { transition: none; }
  .live-dot::after { animation: none; }
}

/* ---------- Affinity · particle life ----------
   Accent = species 2 of the running palette, the most legible of the four on the rail; the tab keeps
   NEON's, the identity of the process, as PHOSPHOR in Reentry. Species colours are made for black
   (cyan, lime and yellow reach 1.2:1 on --bg), so the table, swatches and legend that show them sit
   on the stage black in both themes, like the stage itself. */
#process-affinity .process-dot { color: #00f5ff; }
:root[data-theme=light] #process-affinity .process-dot { color: #00797e; }
body[data-process=affinity] #process-affinity[aria-pressed=true] { border-bottom-color: #00f5ff; box-shadow: inset 0 -1px 0 #00f5ff; }
:root[data-theme=light] body[data-process=affinity] #process-affinity[aria-pressed=true] { border-bottom-color: #00797e; box-shadow: inset 0 -1px 0 #00797e; }

/* Species of the running palette (src/js/engines/affinity-renderer.js), for the stage readout, the brush
   species, the cursor and the accent. The controller writes the same --species-0…5 on #affinity-table and
   #affinity-image and --p0…5 on each swatch; those win where present.
   Accent = species 2, on the black stage in both themes; --accent-light is the darker step of its hue,
   at least 4.6:1 on --bg. RUBY, OXIDE, CITRON, ICE and MERCURY keep the accents of their names in the Studio. */
body[data-process=affinity] { --species-0: #ff008c; --species-1: #00f5ff; --species-2: #aaff00; --species-3: #9628ff; --species-4: #ffaa3c; --species-5: #28c85a; --accent-light: #00797e; --accent-ink: #001a1b; }
body[data-process=affinity][data-palette=SIGNS] { --species-0: #ff0080; --species-1: #00fff0; --species-2: #ffe600; --species-3: #b400ff; --species-4: #14c828; --species-5: #ffa0f0; --accent-light: #007a73; --accent-ink: #001a18; }
body[data-process=affinity][data-palette=EMBER] { --species-0: #ff006e; --species-1: #00ffc8; --species-2: #ff8c00; --species-3: #8c3cff; --species-4: #dc8cff; --species-5: #ffe150; --accent-light: #007c62; --accent-ink: #001a14; }
body[data-process=affinity][data-palette=RUBY] { --species-0: #ff8c3c; --species-1: #f0343a; --species-2: #ffd6be; --species-3: #dc146e; --species-4: #ff78d2; --species-5: #ffc346; --accent-light: #de000d; --accent-ink: #180204; }
body[data-process=affinity][data-palette=OXIDE] { --species-0: #e86228; --species-1: #f0a234; --species-2: #3ccdaa; --species-3: #ece2ce; --species-4: #3c69e1; --species-5: #d282f5; --accent-light: #a25d1f; --accent-ink: #180f02; }
body[data-process=affinity][data-palette=CITRON] { --species-0: #fff05a; --species-1: #aace14; --species-2: #46ffa0; --species-3: #14be5a; --species-4: #f5821e; --species-5: #46d2fa; --accent-light: #617601; --accent-ink: #0b1000; }
body[data-process=affinity][data-palette=ICE] { --species-0: #3ce6ff; --species-1: #3092ff; --species-2: #e8f6ff; --species-3: #6e5aff; --species-4: #3cdc8c; --species-5: #eb96ff; --accent-light: #0068e4; --accent-ink: #020a18; }
body[data-process=affinity][data-palette=MERCURY] { --species-0: #f4f7fc; --species-1: #a0aaba; --species-2: #c6b6a0; --species-3: #64728a; --species-4: #699687; --species-5: #a57896; --accent-light: #606f85; --accent-ink: #0b0c0e; }
body[data-process=affinity] { --accent-stage: var(--species-1); --accent: var(--accent-stage); }
:root[data-theme=light] body[data-process=affinity] { --accent: var(--accent-light); --accent-ink: #ffffff; }

.affinity-species[data-species="0"], .affinity-cell[data-col="0"] { --sp: var(--species-0); }
.affinity-species[data-species="1"], .affinity-cell[data-col="1"] { --sp: var(--species-1); }
.affinity-species[data-species="2"], .affinity-cell[data-col="2"] { --sp: var(--species-2); }
.affinity-species[data-species="3"], .affinity-cell[data-col="3"] { --sp: var(--species-3); }
.affinity-species[data-species="4"], .affinity-cell[data-col="4"] { --sp: var(--species-4); }
.affinity-species[data-species="5"], .affinity-cell[data-col="5"] { --sp: var(--species-5); }

/* Table: a small stage. A row is the species that feels, a column the species it feels. Each cell is a
   bar from the zero line: up for attraction in the colour of the column, down for repulsion, dimmed,
   length |v|. The range stays for the keyboard and assistive tech, invisible; the cell takes the drag.
   Two to six species: --h is the cell height, odd so the zero line is one device pixel at (h − 1) / 2;
   ±1 sits 3 px inside the edges, as the controller's gesture expects, so the travel is (h − 7) / 2.
   The table grows from 2 to 4 species and holds its height from 4 to 6 (263–295 px). */
#affinity-table { --n: 4; --h: 55px; --bar: 30px; --value: 11px; position: relative; display: grid; gap: 3px; margin-top: 7px; padding: 7px 7px 6px 6px; background: var(--stage); border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; }
#affinity-table[data-species="2"] { --n: 2; --h: 71px; }
#affinity-table[data-species="3"] { --n: 3; --h: 63px; }
#affinity-table[data-species="5"] { --n: 5; --h: 47px; --bar: 24px; --value: 10px; }
#affinity-table[data-species="6"] { --n: 6; --h: 41px; --bar: 20px; --value: 10px; }
#affinity-table::before { content: attr(aria-label); position: absolute; left: -1px; bottom: 100%; padding-bottom: 11px; color: var(--text); font: 12.5px/1.5 var(--sans); white-space: nowrap; pointer-events: none; }
#affinity-table > [role=row] { display: grid; grid-template-columns: 22px repeat(var(--n), minmax(0, 1fr)); gap: 3px; }
#affinity-table > [role=row]:first-child { height: 18px; }
:is(#affinity-table, #affinity-image) .affinity-species { display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--hud); font: 10.5px/1 var(--mono); }
:is(#affinity-table, #affinity-image) .affinity-species::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--sp); box-shadow: 0 0 8px -1px var(--sp); }
#affinity-table [role=rowheader] { justify-content: flex-start; }
#affinity-table[data-species="6"] [role=columnheader] { gap: 4px; }
/* The row and the column of the pointed or keyboard-focused cell light up, so a cell reads as "row → column". */
#affinity-table:has([data-row="0"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="0"],
#affinity-table:has([data-row="1"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="1"],
#affinity-table:has([data-row="2"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="2"],
#affinity-table:has([data-row="3"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="3"],
#affinity-table:has([data-row="4"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="4"],
#affinity-table:has([data-row="5"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="5"],
#affinity-table:has([data-col="0"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="0"],
#affinity-table:has([data-col="1"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="1"],
#affinity-table:has([data-col="2"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="2"],
#affinity-table:has([data-col="3"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="3"],
#affinity-table:has([data-col="4"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="4"],
#affinity-table:has([data-col="5"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="5"] { color: var(--hud-strong); }
#affinity-table .affinity-species::before { transition: transform .15s; }
#affinity-table:has([data-row="0"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="0"]::before,
#affinity-table:has([data-row="1"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="1"]::before,
#affinity-table:has([data-row="2"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="2"]::before,
#affinity-table:has([data-row="3"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="3"]::before,
#affinity-table:has([data-row="4"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="4"]::before,
#affinity-table:has([data-row="5"]:is(:hover, :has(:focus-visible))) [role=rowheader][data-species="5"]::before,
#affinity-table:has([data-col="0"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="0"]::before,
#affinity-table:has([data-col="1"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="1"]::before,
#affinity-table:has([data-col="2"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="2"]::before,
#affinity-table:has([data-col="3"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="3"]::before,
#affinity-table:has([data-col="4"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="4"]::before,
#affinity-table:has([data-col="5"]:is(:hover, :has(:focus-visible))) [role=columnheader][data-species="5"]::before { transform: scale(1.35); }
/* Reading: the foot of the same screen. At rest it says how to read a cell; on a cell it says that cell. */
#affinity-reading { display: flex; align-items: center; gap: 8px; height: 30px; margin: 0; padding: 0 10px 1px; overflow: hidden; background: var(--stage); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px;
  box-shadow: inset 0 1px 0 #ffffff12; color: var(--hud); font: 10px/1 var(--mono); white-space: nowrap; }
#affinity-reading span { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--hud-strong); }
#affinity-reading .affinity-species { flex: none; width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; background: var(--sp); box-shadow: 0 0 8px -1px var(--sp); }
#affinity-reading b { margin-left: auto; font-weight: 400; color: var(--hud-strong); font-variant-numeric: tabular-nums; }
#affinity-reading[data-sign=neg] b { color: var(--hud); }
.affinity-cell { position: relative; display: block; height: var(--h); margin: 0; border-radius: 4px; overflow: hidden; cursor: ns-resize; touch-action: none; -webkit-user-select: none; user-select: none;
  background: linear-gradient(#ffffff1f, #ffffff1f) 0 calc((var(--h) - 1px) / 2) / 100% 1px no-repeat, #0b0b0e; box-shadow: inset 0 0 0 1px #ffffff0d; transition: box-shadow .15s; }
/* The bar is as wide as its number, so each cell reads as one column, like a fader. */
.affinity-cell::after { content: ""; position: absolute; left: calc(50% - var(--bar) / 2); right: calc(50% - var(--bar) / 2); bottom: calc((var(--h) + 1px) / 2); height: calc(var(--affinity-value, 0) * (var(--h) - 7px) / 2); border-radius: 2px 2px 0 0; background: var(--sp); box-shadow: 0 0 12px -3px var(--sp); transition: height .18s ease-out; }
.affinity-cell[data-sign=neg]::after { top: calc((var(--h) + 1px) / 2); bottom: auto; height: calc(var(--affinity-value, 0) * (7px - var(--h)) / 2); border-radius: 0 0 2px 2px; box-shadow: none;
  background: linear-gradient(var(--sp), var(--sp)) 0 100% / 100% 1px no-repeat, color-mix(in srgb, var(--sp) 30%, transparent); }
.affinity-cell[data-sign=zero]::after { display: none; }
.affinity-cell input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
/* The number stands in the free half, centred in it. */
.affinity-value { position: absolute; left: 0; right: 0; top: calc((var(--h) + 1px) / 2 + ((var(--h) - 1px) / 2 - 14px) / 2); color: var(--hud); font: var(--value)/14px var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; text-align: center; pointer-events: none; transition: color .15s; }
.affinity-cell[data-sign=neg] .affinity-value { top: calc(((var(--h) - 1px) / 2 - 14px) / 2); }
/* On hover two small wedges at the ends say which way the cell moves: up toward, down away. */
.affinity-cell::before { content: ""; position: absolute; inset: 3px 0; opacity: 0; transition: opacity .15s; pointer-events: none;
  background: conic-gradient(from 150deg at 50% 0, #ffffff5c 60deg, transparent 0) 50% 0 / 8px 5px no-repeat,
    conic-gradient(from -30deg at 50% 100%, #ffffff5c 60deg, transparent 0) 50% 100% / 8px 5px no-repeat; }
.affinity-cell:is(:hover, :active)::before { opacity: 1; }
.affinity-cell:hover { box-shadow: inset 0 0 0 1px #ffffff29; }
.affinity-cell:active { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sp) 75%, transparent); }
.affinity-cell:active::after { transition: none; }
.affinity-cell:is(:hover, :active, :has(:focus-visible), [data-linked]) .affinity-value { color: var(--hud-strong); }
.affinity-cell:has(:focus-visible) { outline: 2px solid var(--accent-stage); outline-offset: 0; }

/* Mirror: the axis runs through "its own kind", top left to bottom right, a hairline in each diagonal cell
   that continues through the gaps. The pointed cell and its twin share a ring in their own colours. */
#affinity-table[data-mirror] { background: linear-gradient(to top right, transparent calc(50% - 1px), #ffffff3d 50%, transparent calc(50% + 1px)) 31px 28px / calc(100% - 38px) calc(100% - 34px) no-repeat, var(--stage); }
#affinity-table[data-mirror] .affinity-cell:is([data-row="0"][data-col="0"], [data-row="1"][data-col="1"], [data-row="2"][data-col="2"], [data-row="3"][data-col="3"], [data-row="4"][data-col="4"], [data-row="5"][data-col="5"]) {
  background: linear-gradient(to top right, transparent calc(50% - .5px), #ffffff2e 50%, transparent calc(50% + .5px)), linear-gradient(#ffffff1f, #ffffff1f) 0 calc((var(--h) - 1px) / 2) / 100% 1px no-repeat, #0b0b0e; }
.affinity-cell[data-linked] { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sp) 75%, transparent); }
/* Drift: the table changes every frame, so the bars follow without easing and without glow (no repaint of
   blurred shadows per frame); the frame of the screen takes a trace of the accent. */
#affinity-table[data-drift] .affinity-cell::after { transition: none; box-shadow: none; }
#affinity-table[data-drift], #affinity-table[data-drift] + #affinity-reading { border-color: color-mix(in srgb, var(--accent-stage) 38%, var(--line)); }

/* Actions on the table, one strip above it: Shuffle and Mutate act once, Mirror and Drift stay on and carry
   a lamp, as Trace does under Species. */
#affinity-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
:is(#affinity-actions button, #affinity-trace) { display: flex; align-items: center; justify-content: center; gap: 7px; min-width: 0; padding: 5px 4px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--muted); font-size: 12px; white-space: nowrap; }
:is(#affinity-actions button, #affinity-trace):hover { border-color: var(--hud); background: var(--surface); color: var(--text); }
:is(#affinity-mirror, #affinity-drift, #affinity-trace)::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); transition: background .15s, box-shadow .2s; }
:is(#affinity-mirror, #affinity-drift, #affinity-trace)[aria-pressed=true] { border-color: var(--accent); color: var(--text); }
:is(#affinity-mirror, #affinity-drift, #affinity-trace)[aria-pressed=true]::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
#affinity-trace { margin: 0 0 12px; padding: 5px 14px 5px 12px; }

/* Species count: on the title line of the table, opposite "Attraction", small, in the mono of the table. */
#affinity-controls > #affinity-species-count { flex: 0 0 auto; margin: 12px 0 0 auto; padding: 2px; gap: 2px; border-radius: 7px; }
#affinity-controls > #affinity-species-count::before { content: "Species"; left: auto; right: 100%; top: 50%; bottom: auto; transform: translateY(-50%); padding: 0 8px 0 0; color: var(--faint); font: 10.5px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
#affinity-species-count button { flex: none; width: 24px; padding: 3px 0; font: 11px/16px var(--mono); }

/* Brush: the tool, then the species it sows or recolours, as the table's own dots and numbers. Cut takes
   every species, so the strip steps back while it is chosen; it stays usable for the next Sow. */
#affinity-controls > #affinity-brush-species { margin-top: 6px; }
#affinity-controls > #affinity-brush-species::before { content: none; }
#affinity-brush-species button { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 0; font: 11px/16px var(--mono); }
#affinity-brush-species button::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--sp); box-shadow: 0 0 8px -1px var(--sp); }
#affinity-brush-species button[aria-pressed=true] { box-shadow: inset 0 -2px 0 var(--sp); }
#affinity-controls:has([data-affinity-brush=cut][aria-pressed=true]) #affinity-brush-species { opacity: .45; }
[data-affinity-brush-species="0"] { --sp: var(--species-0); }
[data-affinity-brush-species="1"] { --sp: var(--species-1); }
[data-affinity-brush-species="2"] { --sp: var(--species-2); }
[data-affinity-brush-species="3"] { --sp: var(--species-3); }
[data-affinity-brush-species="4"] { --sp: var(--species-4); }
[data-affinity-brush-species="5"] { --sp: var(--species-5); }
/* Light theme: the species dots are made for black, so the strip of chips is a strip of the stage. */
:root[data-theme=light] #affinity-brush-species { background: var(--stage); border-color: var(--stage); }
:root[data-theme=light] #affinity-brush-species button { color: var(--hud); }
:root[data-theme=light] #affinity-brush-species button:hover { color: var(--hud-strong); }
:root[data-theme=light] #affinity-brush-species button[aria-pressed=true] { background: #ffffff14; border-color: #ffffff29; color: #ffffff; }

/* Brush on the stage: Sow is a ring in the chosen species with a faint fill, Recolor the same ring empty,
   Cut a dashed white ring. */
body[data-process=affinity]:has([data-affinity-brush-species="0"][aria-pressed=true]) { --brush-sp: var(--species-0); }
body[data-process=affinity]:has([data-affinity-brush-species="1"][aria-pressed=true]) { --brush-sp: var(--species-1); }
body[data-process=affinity]:has([data-affinity-brush-species="2"][aria-pressed=true]) { --brush-sp: var(--species-2); }
body[data-process=affinity]:has([data-affinity-brush-species="3"][aria-pressed=true]) { --brush-sp: var(--species-3); }
body[data-process=affinity]:has([data-affinity-brush-species="4"][aria-pressed=true]) { --brush-sp: var(--species-4); }
body[data-process=affinity]:has([data-affinity-brush-species="5"][aria-pressed=true]) { --brush-sp: var(--species-5); }
body[data-process=affinity] #cursor { border-color: var(--brush-sp, #ffffffb0); box-shadow: 0 0 10px -3px var(--brush-sp, transparent); }
body[data-process=affinity]:has([data-affinity-brush=sow][aria-pressed=true]) #cursor { background: color-mix(in srgb, var(--brush-sp, #ffffff) 12%, transparent); }
body[data-process=affinity]:has([data-affinity-brush=cut][aria-pressed=true]) #cursor { border: 1px dashed #ffffffc0; background: none; box-shadow: none; }

/* Palettes: a chip per palette on the stage black, the running number of species in table order and its
   name under them, so palettes compare at a glance. Four to a row: the reel's three, then the Studio's five. */
#affinity-palettes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
#affinity-palettes button { height: 46px; padding: 25px 0 0; border: 0; border-radius: 6px; color: var(--hud); font: 9.5px/1 var(--mono); letter-spacing: .08em; text-align: center;
  background:
    radial-gradient(circle at 20% 15px, var(--p0) 0 3.1px, color-mix(in srgb, var(--p0) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 40% 15px, var(--p1) 0 3.1px, color-mix(in srgb, var(--p1) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 60% 15px, var(--p2) 0 3.1px, color-mix(in srgb, var(--p2) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 80% 15px, var(--p3) 0 3.1px, color-mix(in srgb, var(--p3) 32%, transparent) 4.1px, transparent 7.5px),
    var(--stage);
  box-shadow: inset 0 0 0 1px #ffffff14; }
#affinity-controls:has(#affinity-table[data-species="2"]) #affinity-palettes button { background:
    radial-gradient(circle at 33.33% 15px, var(--p0) 0 3.1px, color-mix(in srgb, var(--p0) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 66.67% 15px, var(--p1) 0 3.1px, color-mix(in srgb, var(--p1) 32%, transparent) 4.1px, transparent 7.5px),
    var(--stage); }
#affinity-controls:has(#affinity-table[data-species="3"]) #affinity-palettes button { background:
    radial-gradient(circle at 25% 15px, var(--p0) 0 3.1px, color-mix(in srgb, var(--p0) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 50% 15px, var(--p1) 0 3.1px, color-mix(in srgb, var(--p1) 32%, transparent) 4.1px, transparent 7.5px),
    radial-gradient(circle at 75% 15px, var(--p2) 0 3.1px, color-mix(in srgb, var(--p2) 32%, transparent) 4.1px, transparent 7.5px),
    var(--stage); }
#affinity-controls:has(#affinity-table[data-species="5"]) #affinity-palettes button { background:
    radial-gradient(circle at 16.67% 15px, var(--p0) 0 2.8px, color-mix(in srgb, var(--p0) 32%, transparent) 3.8px, transparent 6.5px),
    radial-gradient(circle at 33.33% 15px, var(--p1) 0 2.8px, color-mix(in srgb, var(--p1) 32%, transparent) 3.8px, transparent 6.5px),
    radial-gradient(circle at 50% 15px, var(--p2) 0 2.8px, color-mix(in srgb, var(--p2) 32%, transparent) 3.8px, transparent 6.5px),
    radial-gradient(circle at 66.67% 15px, var(--p3) 0 2.8px, color-mix(in srgb, var(--p3) 32%, transparent) 3.8px, transparent 6.5px),
    radial-gradient(circle at 83.33% 15px, var(--p4) 0 2.8px, color-mix(in srgb, var(--p4) 32%, transparent) 3.8px, transparent 6.5px),
    var(--stage); }
#affinity-controls:has(#affinity-table[data-species="6"]) #affinity-palettes button { background:
    radial-gradient(circle at 14.29% 15px, var(--p0) 0 2.5px, color-mix(in srgb, var(--p0) 32%, transparent) 3.4px, transparent 5.5px),
    radial-gradient(circle at 28.57% 15px, var(--p1) 0 2.5px, color-mix(in srgb, var(--p1) 32%, transparent) 3.4px, transparent 5.5px),
    radial-gradient(circle at 42.86% 15px, var(--p2) 0 2.5px, color-mix(in srgb, var(--p2) 32%, transparent) 3.4px, transparent 5.5px),
    radial-gradient(circle at 57.14% 15px, var(--p3) 0 2.5px, color-mix(in srgb, var(--p3) 32%, transparent) 3.4px, transparent 5.5px),
    radial-gradient(circle at 71.43% 15px, var(--p4) 0 2.5px, color-mix(in srgb, var(--p4) 32%, transparent) 3.4px, transparent 5.5px),
    radial-gradient(circle at 85.71% 15px, var(--p5) 0 2.5px, color-mix(in srgb, var(--p5) 32%, transparent) 3.4px, transparent 5.5px),
    var(--stage); }
#affinity-palettes button:hover { color: var(--hud-strong); box-shadow: inset 0 0 0 1px #ffffff33; }
#affinity-palettes button[aria-pressed=true] { color: #ffffff; box-shadow: inset 0 0 0 1px #ffffff4d, 0 0 0 2px var(--panel), 0 0 0 3.5px var(--text); }

/* Legend: the running species as on the stage, numbered as in the table. */
#affinity-image .legend { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; padding: 10px 16px; background: var(--stage); border: 1px solid var(--line); border-radius: 8px; font-size: 0; }
#affinity-image .affinity-species { gap: 8px; font-size: 11px; }
#affinity-image .affinity-species::before { width: 8px; height: 8px; box-shadow: 0 0 10px -1px var(--sp); }

/* Starting point: Field and Dish name themselves, so the help line goes and the room goes to the table. */
body[data-process=affinity] #start-help { display: none; }

/* Stage: the readout and its chip of the running species. */
@container (min-aspect-ratio: 136/100) {
  body[data-process=affinity] .readout[data-model=affinity] { display: block; }
}
#affinity-palette-readout::before { width: 19px; border-radius: 1px; background: linear-gradient(90deg, var(--species-0) 0 4px, transparent 0 5px, var(--species-1) 0 9px, transparent 0 10px, var(--species-2) 0 14px, transparent 0 15px, var(--species-3) 0); }
body:has(#affinity-table[data-species="2"]) #affinity-palette-readout::before { width: 9px; background: linear-gradient(90deg, var(--species-0) 0 4px, transparent 0 5px, var(--species-1) 0); }
body:has(#affinity-table[data-species="3"]) #affinity-palette-readout::before { width: 14px; background: linear-gradient(90deg, var(--species-0) 0 4px, transparent 0 5px, var(--species-1) 0 9px, transparent 0 10px, var(--species-2) 0); }
body:has(#affinity-table[data-species="5"]) #affinity-palette-readout::before { width: 24px; background: linear-gradient(90deg, var(--species-0) 0 4px, transparent 0 5px, var(--species-1) 0 9px, transparent 0 10px, var(--species-2) 0 14px, transparent 0 15px, var(--species-3) 0 19px, transparent 0 20px, var(--species-4) 0); }
body:has(#affinity-table[data-species="6"]) #affinity-palette-readout::before { width: 29px; background: linear-gradient(90deg, var(--species-0) 0 4px, transparent 0 5px, var(--species-1) 0 9px, transparent 0 10px, var(--species-2) 0 14px, transparent 0 15px, var(--species-3) 0 19px, transparent 0 20px, var(--species-4) 0 24px, transparent 0 25px, var(--species-5) 0); }
#affinity-count { font-variant-numeric: tabular-nums; }
@media (max-width: 1050px) {
  #affinity-reading { padding: 0 8px 1px; font-size: 9px; }
  #affinity-palettes button { letter-spacing: .04em; }
  #affinity-table[data-species="6"] { --value: 9px; --bar: 18px; }
  #affinity-actions button { gap: 5px; font-size: 11.5px; }
}
@media (prefers-reduced-motion: reduce) {
  .affinity-cell, .affinity-cell::before, .affinity-cell::after, .affinity-value, #affinity-table .affinity-species::before,
  :is(#affinity-mirror, #affinity-drift, #affinity-trace)::before { transition: none; }
}

/* ---------- Barchan · Werner dunes ----------
   Accent = the bright stop of the running palette; the tab keeps ERG's red, the identity of the process,
   as PHOSPHOR in Reentry (orange is Hyphae's). The rail follows the sister rails above: each group reads
   its visible label from its own aria-label and the palette name sits beside the chips. */
#process-barchan .process-dot { color: #e03e4a; }
:root[data-theme=light] #process-barchan .process-dot { color: #b8202e; }
body[data-process=barchan] #process-barchan[aria-pressed=true] { border-bottom-color: #e03e4a; box-shadow: inset 0 -1px 0 #e03e4a; }
:root[data-theme=light] body[data-process=barchan] #process-barchan[aria-pressed=true] { border-bottom-color: #b8202e; box-shadow: inset 0 -1px 0 #b8202e; }
/* --accent-stage: stop 4 of 5, on the black stage in both themes (8.3:1 or more on the rail).
   --accent-light: darker step of its hue, at least 5.2:1 on --bg. */
body[data-process=barchan] { --accent-stage: #ff8c34; --accent-light: #a84a08; --accent-ink: #1a0c02; }
body[data-process=barchan][data-palette=HALITE] { --accent-stage: #82ded2; --accent-light: #0e6f7a; --accent-ink: #021614; }
body[data-process=barchan][data-palette=SODIUM] { --accent-stage: #fcb230; --accent-light: #8c5a06; --accent-ink: #1a1002; }
body[data-process=barchan] { --accent: var(--accent-stage); }
:root[data-theme=light] body[data-process=barchan] { --accent: var(--accent-light); --accent-ink: #ffffff; }

#barchan-controls { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; }
#barchan-controls > * { flex: 1 0 100%; }
#barchan-controls > :is(.segments, #barchan-palettes) { position: relative; margin-top: 38px; }
#barchan-controls > :is(.segments, #barchan-palettes)::before { content: attr(aria-label); position: absolute; left: 0; bottom: 100%; padding-bottom: 7px; color: var(--text); font: 12.5px/1.5 var(--sans); white-space: nowrap; pointer-events: none; }
#barchan-controls > .segments::before { left: -1px; }
#barchan-controls > .help { margin-top: 16px; }
/* Wind: the arrow is the label, so it reads at the size of the slider labels' text plus a step. */
#barchan-wind button { padding: 6px 4px; font-size: 15px; line-height: 20px; }

/* Palettes: a chip per palette on the stage black, its five stops as dunes from small to large, so the
   ramp reads as size; the first stop is as dark on black as a thin sheet of sand on the stage. */
#barchan-palettes { flex: 0 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 58px; gap: 8px; padding: 4px 0; }
#barchan-palettes button { height: 28px; padding: 0; border: 0; border-radius: 6px; font-size: 0; color: transparent;
  background:
    radial-gradient(circle at 8px 50%, var(--p0) 0 1.6px, transparent 2.3px),
    radial-gradient(circle at 17px 50%, var(--p1) 0 2.2px, color-mix(in srgb, var(--p1) 30%, transparent) 3px, transparent 4.5px),
    radial-gradient(circle at 27px 50%, var(--p2) 0 2.8px, color-mix(in srgb, var(--p2) 30%, transparent) 3.7px, transparent 5.5px),
    radial-gradient(circle at 38px 50%, var(--p3) 0 3.4px, color-mix(in srgb, var(--p3) 30%, transparent) 4.4px, transparent 6.5px),
    radial-gradient(circle at 50px 50%, var(--p4) 0 4px, color-mix(in srgb, var(--p4) 30%, transparent) 5px, transparent 7.5px),
    var(--stage);
  box-shadow: inset 0 0 0 1px #ffffff14; transition: box-shadow .2s; }
#barchan-palettes button:hover { box-shadow: inset 0 0 0 1px #ffffff33; }
#barchan-palettes button[aria-pressed=true] { box-shadow: inset 0 0 0 1px #ffffff4d, 0 0 0 2px var(--panel), 0 0 0 3.5px var(--text); }
#barchan-palette-name { flex: 1 1 0; align-self: flex-end; min-width: max-content; text-align: right; color: var(--text); font: 400 10.5px/36px var(--mono); letter-spacing: .1em; }

/* Legend: the ramp of the running palette, thin as in Reentry; ERG until the controller writes the running one. */
#barchan-image { --barchan-0: #34082c; --barchan-1: #841652; --barchan-2: #e03e4a; --barchan-3: #ff8c34; --barchan-4: #ffc870; }
#barchan-image .legend { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 10px; }
#barchan-image .legend span:nth-child(3) { text-align: center; }
#barchan-image .legend span:nth-child(4) { text-align: right; }
.barchan-ramp { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--barchan-0), var(--barchan-1), var(--barchan-2), var(--barchan-3), var(--barchan-4)); }
:root[data-theme=light] .barchan-ramp { box-shadow: inset 0 0 0 1px var(--line); }

/* Starting point: one start, so the one-button segment goes; ↺ New sea stays with the actions. */
body[data-process=barchan] #starting-point .segments { display: none; }

/* Eight tabs need about 1124 px with the active subtitle and 997 px without it (measured 2026-11-19):
   up to 1260 px the subtitle goes (the panel heading keeps it), up to 1100 px the numbers go too.
   Only a row of eight: the two-tab Demo keeps its look. */
@media (max-width: 1260px) {
  .process-picker:has(> button:nth-of-type(8)) small { display: none; }
}
@media (max-width: 1100px) {
  .process-picker:has(> button:nth-of-type(8)) button { padding: 0 8px; }
  .process-picker:has(> button:nth-of-type(8)) .process-number { display: none; }
}

/* Stage: live dot in the bright stop, the readout where the stage has a wide gutter. */
body[data-process=barchan] .live-dot { background: var(--accent-stage); box-shadow: 0 0 10px var(--accent-stage); }
body[data-process=barchan] .live-dot::after { border-color: var(--accent-stage); }
body[data-process=barchan].is-paused .live-dot { background: var(--hud); box-shadow: none; }
@container (min-aspect-ratio: 136/100) {
  body[data-process=barchan] .readout[data-model=barchan] { display: block; }
}
:is(#barchan-phase, #barchan-sand-readout, #barchan-dunes) { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  #barchan-palettes button { transition: none; }
}
