/* Architectures en mouvement — a blueprint look: paper or slate, fine lines, one accent colour.
   Colour carries meaning: green = success, red = failure, amber = waiting. */

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fbf9f4;
  --surface-2: #efebe1;
  --ink: #1b2230;
  --muted: #5c6574;
  --line: #c4bcab;
  --grid: rgba(27, 34, 48, 0.055);
  --accent: #2459d6;
  --accent-soft: rgba(36, 89, 214, 0.12);
  --ok: #1d8556;
  --fail: #c63d2c;
  --wait: #b97d0c;
  --shadow: 0 1px 2px rgba(27, 34, 48, 0.06), 0 8px 24px rgba(27, 34, 48, 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f131b;
    --surface: #151b26;
    --surface-2: #1b2331;
    --ink: #e6e9ef;
    --muted: #9aa4b5;
    --line: #2f3a4d;
    --grid: rgba(150, 175, 220, 0.06);
    --accent: #7aa2ff;
    --accent-soft: rgba(122, 162, 255, 0.14);
    --ok: #46c58c;
    --fail: #ff6f5e;
    --wait: #f2b53f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f131b;
  --surface: #151b26;
  --surface-2: #1b2331;
  --ink: #e6e9ef;
  --muted: #9aa4b5;
  --line: #2f3a4d;
  --grid: rgba(150, 175, 220, 0.06);
  --accent: #7aa2ff;
  --accent-soft: rgba(122, 162, 255, 0.14);
  --ok: #46c58c;
  --fail: #ff6f5e;
  --wait: #f2b53f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--font);
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
code { font: 0.92em var(--mono); background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }

.wrap { width: min(1120px, 100% - 32px); margin-inline: auto; }

/* ─── Header and footer ─── */

.site-header {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.site-header .wrap { display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 650; letter-spacing: -0.01em; }
.brand svg { width: 28px; height: 28px; }
.site-nav { display: flex; gap: 18px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.site-nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--ink); }
.icon-button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; line-height: 1;
}

.site-footer { border-top: 1px solid var(--line); margin-top: 72px; padding: 28px 0 40px; color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

/* ─── Scene page ─── */

.scene-head { padding: 40px 0 18px; }
.eyebrow { font: 600 0.78rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
h1 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3rem); line-height: 1.1; letter-spacing: -0.02em; margin: 12px 0 12px; }
.lede { font-size: 1.12rem; color: var(--muted); max-width: 70ch; margin: 0; }

.stage-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
figure.stage-card { margin: 0; }
/* On a phone the scene keeps a readable size and scrolls sideways inside its card; the page itself never does. */
.stage-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
#stage {
  display: block; width: 100%; height: auto; min-width: 760px;
  background: var(--surface);
  font-family: var(--font);
}
.stage-grid { fill: url(#grid); }
.grid-line { fill: none; stroke: var(--grid); stroke-width: 1; }

.controls-bar {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.transport, .scene-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls-bar button, .controls-bar select {
  font: 500 0.9rem var(--font); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; cursor: pointer;
}
.controls-bar button:hover { border-color: var(--accent); }
.controls-bar button:focus-visible, .controls-bar select:focus-visible, .icon-button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.controls-bar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 108px; }
:root[data-theme="dark"] .controls-bar button.primary { color: #0f131b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .controls-bar button.primary { color: #0f131b; } }
.controls-bar button[aria-pressed="true"]:not(.primary) { background: var(--accent-soft); border-color: var(--accent); }
.controls-bar button[data-tone="fail"][aria-pressed="true"] { background: color-mix(in srgb, var(--fail) 16%, transparent); border-color: var(--fail); }
.controls-bar button[data-tone="wait"][aria-pressed="true"] { background: color-mix(in srgb, var(--wait) 18%, transparent); border-color: var(--wait); }
.controls-bar button[data-tone="ok"][aria-pressed="true"] { background: color-mix(in srgb, var(--ok) 16%, transparent); border-color: var(--ok); }
.speed { font-size: 0.9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }

.narration {
  list-style: none; margin: 0; padding: 12px 16px; border-top: 1px solid var(--line);
  font-size: 0.95rem; min-height: 7.2em;
}
.narration li { color: var(--muted); padding: 1px 0; }
.narration li.latest { color: var(--ink); font-weight: 520; }
.narration li[data-tone="fail"].latest { color: var(--fail); }
.narration li[data-tone="ok"].latest { color: var(--ok); }
.narration .at { font: 0.8rem var(--mono); color: var(--muted); display: inline-block; min-width: 4.5em; }

.reduced-note { display: none; font-size: 0.9rem; color: var(--muted); margin: 10px 0 0; }
.reduced-motion .reduced-note { display: block; }

.scene-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; margin-top: 28px; }
@media (max-width: 820px) { .scene-body { grid-template-columns: 1fr; } }
.scene-body h2 { font-size: 1.15rem; margin: 0 0 10px; }
.watch li { margin: 6px 0; }
.counters-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.counters { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: 0.93rem; }
.counters dt { color: var(--muted); }
.counters dd { margin: 0; font: 600 0.95rem var(--mono); text-align: right; }
.counters dd[data-tone="ok"] { color: var(--ok); }
.counters dd[data-tone="fail"] { color: var(--fail); }
.counters dd[data-tone="wait"] { color: var(--wait); }

.read-more { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.read-more a {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); font-size: 0.93rem;
}
.read-more a:hover { border-color: var(--accent); }
.read-more a.next { margin-left: auto; background: var(--accent-soft); border-color: var(--accent); }

/* ─── SVG primitives ─── */

.node .node-body { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; transition: stroke 0.25s, fill 0.25s; }
.node .node-rim { fill: none; stroke: var(--line); stroke-width: 1.5; }
.node-label { fill: var(--ink); font-size: 15px; font-weight: 600; }
.node-sub { fill: var(--muted); font: 12px var(--mono); }
.node:not([data-state="idle"]) .node-body { stroke-width: 2.5; }
.node[data-state="active"] .node-body { stroke: var(--accent); fill: var(--accent-soft); }
.node[data-state="ok"] .node-body { stroke: var(--ok); fill: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.node[data-state="fail"] .node-body { stroke: var(--fail); fill: color-mix(in srgb, var(--fail) 12%, var(--surface)); }
.node[data-state="wait"] .node-body { stroke: var(--wait); fill: color-mix(in srgb, var(--wait) 14%, var(--surface)); }
.node[data-state="off"] { opacity: 0.45; }

.link { fill: none; stroke: var(--line); stroke-width: 2; }
.link-dashed { stroke-dasharray: 6 6; }
.link[data-state="active"] { stroke: var(--accent); }
.link[data-state="fail"] { stroke: var(--fail); stroke-dasharray: 4 6; }
.link[data-state="off"] { opacity: 0.35; }
.arrow-head { fill: var(--muted); }

.packet-head { fill: var(--accent); }
.packet-trail { fill: var(--accent); opacity: 0.3; }
.packet[data-tone="ok"] circle { fill: var(--ok); }
.packet[data-tone="fail"] circle { fill: var(--fail); }
.packet[data-tone="wait"] circle { fill: var(--wait); }
.packet[data-tone="muted"] circle { fill: var(--muted); }

.queue-cell { fill: var(--surface-2); stroke: var(--line); }
.queue-cell[data-filled="1"] { fill: var(--accent); stroke: var(--accent); }
.queue[data-state="full"] .queue-cell[data-filled="1"] { fill: var(--wait); stroke: var(--wait); }
.queue-label, .meter-label, .chart-label, .scene-label { fill: var(--muted); font: 12px var(--mono); }
.scene-title { fill: var(--ink); font-size: 13px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }

.meter-track { fill: var(--surface-2); stroke: var(--line); }
.meter-fill { fill: var(--accent); transition: width 0.2s; }
.meter[data-state="fail"] .meter-fill { fill: var(--fail); }
.meter[data-state="wait"] .meter-fill { fill: var(--wait); }
.meter[data-state="ok"] .meter-fill { fill: var(--ok); }

.chart-frame { fill: var(--surface-2); stroke: var(--line); }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart-line-0 { stroke: var(--accent); }
.chart-line-1 { stroke: var(--fail); }
.chart-line-2 { stroke: var(--ok); }

.outcome-cell { fill: var(--surface-2); stroke: var(--line); }
.outcome-cell[data-tone="ok"] { fill: var(--ok); stroke: var(--ok); }
.outcome-cell[data-tone="wait"] { fill: var(--wait); stroke: var(--wait); }
.outcome-cell[data-tone="fail"] { fill: var(--fail); stroke: var(--fail); }
.outcome-cell[data-tone="muted"] { fill: var(--muted); stroke: var(--muted); }

.conveyor { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 2 4; stroke-linecap: round; opacity: 0.75; }
.worker-bar { fill: var(--accent); }
.worker-bar[data-state="wait"] { fill: var(--wait); }
.copy-shadow { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }

.replay-cursor { fill: var(--wait); }
.badge.checklist text { font-size: 11px; }
.card-delta { font: 600 13px var(--mono); fill: var(--ink); }
.card-delta[data-tone="ok"] { fill: var(--ok); }
.card-delta[data-tone="fail"] { fill: var(--fail); }
.event-card .node-label { font-size: 14px; }
.event-card .node-sub { font-size: 10.5px; }

.zone { fill: none; stroke: var(--line); stroke-dasharray: 3 5; }
.badge rect { fill: var(--surface-2); stroke: var(--line); }
.badge text { fill: var(--ink); font: 600 12px var(--mono); }
.badge[data-state="ok"] rect { stroke: var(--ok); fill: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.badge[data-state="fail"] rect { stroke: var(--fail); fill: color-mix(in srgb, var(--fail) 14%, var(--surface)); }
.badge[data-state="wait"] rect { stroke: var(--wait); fill: color-mix(in srgb, var(--wait) 16%, var(--surface)); }

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

/* ─── Home ─── */

.hero { padding: 56px 0 24px; }
.hero h1 { font-size: clamp(2.2rem, 1.4rem + 3.4vw, 3.8rem); max-width: 18ch; }
.hero .lede { font-size: 1.2rem; }
.hero-stage { margin-top: 32px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-top: 24px; }
.card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.card h3 { margin: 0; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.card .eyebrow { font-size: 0.7rem; }
.section-title { margin: 56px 0 6px; font-size: 1.5rem; letter-spacing: -0.01em; }
.section-lede { color: var(--muted); margin: 0; max-width: 70ch; }
.families { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 20px; }
.family { padding: 16px 18px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.family h3 { margin: 0 0 4px; font-size: 1rem; }
.family p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.prose { max-width: 72ch; }
.prose h2 { margin-top: 36px; }
.cell-inner { fill: var(--surface-2); stroke: none; }
.route-row { fill: var(--surface-2); stroke: var(--line); }
.route-name { fill: var(--ink); font: 600 13px var(--mono); }

.legend-dot { fill: var(--accent); }

/* Opening of the home page and previews of the cards */
.opening .packet-head { fill: var(--accent); }
.opening .station { cursor: pointer; }
.opening .station:focus-visible .node-body { stroke: var(--accent); stroke-width: 3; }
.opening-caption { padding: 12px 18px 16px; color: var(--muted); font-size: 0.95rem; }
.family a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 2px; }
.family a:hover { color: var(--accent); }
.defs-only { position: absolute; }
.thumb { width: 100%; height: auto; aspect-ratio: 200 / 90; margin-bottom: 4px; border-radius: 8px; background: var(--surface-2); }
.thumb rect, .thumb circle, .thumb path, .thumb polygon { fill: none; stroke: var(--muted); stroke-width: 1.6; }
.thumb .accent-stroke { stroke: var(--accent); }
.thumb .ok-stroke { stroke: var(--ok); }
.thumb .fail-stroke { stroke: var(--fail); }
.thumb .wait-stroke { stroke: var(--wait); }
.thumb .dashed { stroke-dasharray: 4 4; }
.thumb circle.accent { fill: var(--accent); stroke: none; }
.thumb circle.ok { fill: var(--ok); stroke: none; }
.thumb circle.fail { fill: var(--fail); stroke: none; }
.thumb circle.wait { fill: var(--wait); stroke: none; }
.thumb .fill-wait { fill: var(--wait); stroke: none; }
.thumb-head { fill: var(--muted); }
