/* ==========================================================================
   SDE base.css — "drafting table" design system

   The board is a physical surface seen at a shallow angle. Everything reads as
   paper, card and cord: matte colour, real shadows, hairline rules. Depth comes
   from elevation and shadow, never from glow. Sites set --accent / --accent-2
   to a pair of print inks; nothing else changes.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens */
:root {
  /* surfaces, warm and paper-like */
  --paper:      #DFDACE;   /* the board itself */
  --paper-2:    #EFEBE2;   /* raised card */
  --paper-3:    #FAF8F3;   /* panel / sheet */
  --paper-4:    #FFFFFF;
  --board-edge: #C9C2B2;

  /* ink */
  --ink:        #1A1815;
  --ink-2:      #4E4840;
  --ink-3:      #7C7469;
  --ink-4:      #A29A8D;

  --rule:       rgba(26, 24, 21, 0.13);
  --rule-2:     rgba(26, 24, 21, 0.24);
  --rule-3:     rgba(26, 24, 21, 0.38);

  /* per-site inks — overridden in css/site.css */
  --accent:     #1F4B73;
  --accent-2:   #7A4A2B;

  /* status inks, muted enough to sit on paper */
  --flag-good:  #3D6647;
  --flag-warn:  #93661C;
  --flag-bad:   #93331E;

  --radius:     4px;
  --radius-sm:  3px;

  /* Elevation: two stacked shadows — a tight contact shadow and a soft cast. */
  --lift-1: 0 1px 1px rgba(26,24,21,.10), 0 2px 5px rgba(26,24,21,.07);
  --lift-2: 0 1px 2px rgba(26,24,21,.12), 0 6px 16px -6px rgba(26,24,21,.16);
  --lift-3: 0 2px 3px rgba(26,24,21,.13), 0 18px 40px -14px rgba(26,24,21,.30);

  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans:  ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text",
           system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono:  ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace;

  --rail-w: 58px;
  --panel-w: 452px;

  /* Paper grain. One tiny inline SVG, no network, no image files. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.86' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

/* ----------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
::selection { background: rgba(31,75,115,.18); }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb {
  background: rgba(26,24,21,.22); border-radius: 7px;
  border: 3.5px solid var(--paper);
}
::-webkit-scrollbar-thumb:hover { background: rgba(26,24,21,.34); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Screen-reader-only, but focusable when tabbed to. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sr-only-focusable:focus {
  position: fixed; top: 12px; left: 12px; z-index: 100;
  width: auto; height: auto; margin: 0; clip: auto; white-space: normal;
  padding: 10px 16px; background: var(--paper-4); color: var(--ink);
  border: 1px solid var(--rule-2); border-radius: var(--radius);
  box-shadow: var(--lift-3);
}

/* ---------------------------------------------------------------- stage */
#stage-wrap {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #E9E4D9, var(--paper) 58%, #D2CCBE 100%);
}
#stage-wrap::after {                 /* grain over the whole surface */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--grain);
  opacity: .16; mix-blend-mode: multiply;
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; }
#stage.is-panning { cursor: grabbing; }
#stage.is-hovering-node { cursor: grab; }
#stage.is-dragging-node { cursor: grabbing; }
#stage:not(.is-panning):not(.is-hovering-node):not(.is-dragging-node) { cursor: default; }

.sde-label-layer {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none; overflow: hidden;
}
/* Labels are typeset tickets, not glowing HUD chips. */
.sde-label {
  position: absolute; top: 0; left: 0;
  will-change: transform, opacity;
  font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.01em;
  color: var(--ink-2);
  background: var(--paper-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  white-space: nowrap;
  box-shadow: var(--lift-1);
}
.sde-label b { color: var(--ink); font-weight: 600; }
.sde-label .k { color: var(--accent); font-weight: 600; }
.sde-label.is-accent { border-color: var(--accent); }
.sde-label.is-accent b { color: var(--accent); }
.sde-label.is-good { border-left: 2px solid var(--flag-good); }
.sde-label.is-warn { border-left: 2px solid var(--flag-warn); }
.sde-label.is-bad  { border-left: 2px solid var(--flag-bad); color: var(--flag-bad); }
.sde-label.is-quiet { background: none; border: 0; box-shadow: none; color: var(--ink-3); }
.sde-label.is-selected {
  border-color: var(--accent); background: var(--paper-4);
  box-shadow: var(--lift-2);
}
.sde-label.is-interactive { pointer-events: auto; cursor: pointer; }
.sde-label.is-interactive:hover { border-color: var(--accent); background: var(--paper-4); }

/* ---------------------------------------------------------------- story */
.story { position: relative; z-index: 3; pointer-events: none; }
.chapter {
  min-height: 100vh;
  display: flex; align-items: center;
  padding: 12vh 0 12vh calc(var(--rail-w) + 40px);
}
.chapter > .panel { pointer-events: auto; }
.chapter.is-right { justify-content: flex-end; padding-right: calc(var(--rail-w) + 40px); }
.chapter.is-wide > .panel { --panel-w: 640px; }

/* ---------------------------------------------------------------- panel */
/* An opaque sheet resting on the board. No blur, no glass. */
.panel {
  width: min(var(--panel-w), calc(100vw - var(--rail-w) - 76px));
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 30px 32px 32px;
  box-shadow: var(--lift-3);
  position: relative;
}
.panel::before {                       /* the sheet's own faint grain */
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background-image: var(--grain); opacity: .09;
  mix-blend-mode: multiply; pointer-events: none;
}
.panel > * { position: relative; }
/* A hairline in the site ink down the binding edge. */
.panel::after {
  content: ""; position: absolute; left: 0; top: 18px; bottom: 18px; width: 2px;
  background: var(--accent); border-radius: 2px; opacity: .85;
}
.panel.is-plain::after { display: none; }

/* ------------------------------------------------------------ typography */
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0 0 14px; }
h1 {
  font-size: clamp(34px, 4.6vw, 63px); line-height: 1.05;
  letter-spacing: -0.018em; font-weight: 480;
}
h2 { font-size: clamp(23px, 2.15vw, 31px); line-height: 1.17; letter-spacing: -0.012em; }
h3 { font-size: 18.5px; line-height: 1.3; letter-spacing: -0.008em; }
h4 {
  font-family: var(--sans); font-size: 12px; font-weight: 620;
  letter-spacing: 0.04em; color: var(--ink-3);
  margin: 0 0 8px; text-transform: none;
}

/* The step marker: a rule, a figure, a name. No neon eyebrow. */
.step {
  display: flex; align-items: baseline; gap: 11px;
  margin: 0 0 18px;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
}
.step .n {
  font-family: var(--serif); font-size: 15px; font-weight: 500;
  color: var(--accent); font-variant-numeric: lining-nums;
}
.step .t { color: var(--ink-3); letter-spacing: 0.01em; }
.step .rule { flex: 1; height: 1px; background: var(--rule-2); transform: translateY(-3px); }

p { margin: 0 0 15px; color: var(--ink-2); }
p:last-child { margin-bottom: 0; }
p strong, li strong { color: var(--ink); font-weight: 600; }
.lead { font-size: 18.5px; line-height: 1.55; color: var(--ink-2); }
.dim { color: var(--ink-3); }
.tiny { font-size: 13px; line-height: 1.55; }
em { font-style: italic; }

code, kbd, .mono { font-family: var(--mono); font-size: 0.885em; }
code {
  background: rgba(26,24,21,.055);
  border: 1px solid var(--rule);
  border-radius: 2px; padding: 0.5px 4px;
  color: var(--ink);
}
kbd {
  background: var(--paper-4); border: 1px solid var(--rule-2);
  border-bottom-width: 2px; border-radius: 3px;
  padding: 1px 5px; font-size: 11px; color: var(--ink-2);
}

ul, ol { margin: 0 0 15px; padding-left: 0; list-style: none; }
ul li, ol li { position: relative; padding-left: 20px; margin-bottom: 7px; color: var(--ink-2); }
ul li::before {
  content: ""; position: absolute; left: 3px; top: 0.78em;
  width: 5px; height: 1.5px; background: var(--ink-4);
}
ol { counter-reset: sde-ol; }
ol li { counter-increment: sde-ol; padding-left: 26px; }
ol li::before {
  content: counter(sde-ol) "."; position: absolute; left: 0; top: 0;
  font-family: var(--serif); font-size: 14.5px; color: var(--accent);
  width: 20px; height: auto; background: none;
}

/* -------------------------------------------------------------- callouts */
/* A margin note, ruled rather than boxed-and-glowing. */
.note {
  border-left: 2px solid var(--rule-3);
  padding: 2px 0 2px 15px; margin: 18px 0;
  font-size: 15px; color: var(--ink-2);
}
.note .note-t {
  display: block; font-family: var(--sans); font-size: 11.5px; font-weight: 640;
  letter-spacing: 0.03em; color: var(--ink-3); margin-bottom: 4px;
}
.note.is-key { border-left-color: var(--accent); }
.note.is-key .note-t { color: var(--accent); }
.note.is-warn { border-left-color: var(--flag-warn); }
.note.is-warn .note-t { color: var(--flag-warn); }
.note.is-bad { border-left-color: var(--flag-bad); }
.note.is-bad .note-t { color: var(--flag-bad); }
.note.is-good { border-left-color: var(--flag-good); }
.note.is-good .note-t { color: var(--flag-good); }

/* ----------------------------------------------------------------- tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.tag {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.01em;
  padding: 2.5px 7px; border-radius: 2px;
  border: 1px solid var(--rule-2); color: var(--ink-3);
  background: var(--paper-2);
  white-space: nowrap;
}
.tag.is-on { border-color: var(--accent); color: var(--accent); background: var(--paper-4); }
.tag.is-good { border-color: var(--flag-good); color: var(--flag-good); }
.tag.is-bad  { border-color: var(--flag-bad); color: var(--flag-bad); }
.tag.is-warn { border-color: var(--flag-warn); color: var(--flag-warn); }

/* ----------------------------------------------------------- spec tables */
.spec { width: 100%; border-collapse: collapse; margin: 6px 0 18px; font-size: 14.5px; }
.spec th, .spec td { text-align: left; padding: 8px 10px 8px 0; vertical-align: top; }
.spec th {
  font-family: var(--sans); font-size: 11px; font-weight: 640;
  letter-spacing: 0.045em; color: var(--ink-4);
  border-bottom: 1px solid var(--rule-3); padding-bottom: 6px;
}
.spec td { border-bottom: 1px solid var(--rule); color: var(--ink-2); }
.spec td:first-child { color: var(--ink); font-weight: 550; }
.spec tr:last-child td { border-bottom: 0; }
.spec .num {
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.spec .yes { color: var(--flag-good); }
.spec .no  { color: var(--flag-bad); }

/* --------------------------------------------------------- calculations */
/* Worked arithmetic, set like a ledger. */
.calc {
  font-family: var(--mono); font-size: 13px; line-height: 1.9;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 14px 16px; margin: 6px 0 18px;
  color: var(--ink-2); overflow-x: auto;
  font-variant-numeric: tabular-nums;
}
.calc .row { display: flex; justify-content: space-between; gap: 20px; white-space: nowrap; }
.calc .row.is-total {
  border-top: 1px solid var(--rule-3); margin-top: 8px; padding-top: 8px;
  color: var(--ink); font-weight: 600;
}
.calc .op { color: var(--ink-4); }
.calc .v  { color: var(--accent); font-weight: 600; }
.calc .v.is-2 { color: var(--accent-2); }
.calc .c  { color: var(--ink-4); }

pre.code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.68;
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--radius-sm); padding: 13px 15px; margin: 6px 0 18px;
  overflow-x: auto; color: var(--ink-2);
}
pre.code .kw { color: var(--accent); font-weight: 600; }
pre.code .fn { color: var(--ink); font-weight: 600; }
pre.code .st { color: var(--accent-2); }
pre.code .nu { color: var(--accent-2); }
pre.code .cm { color: var(--ink-4); font-style: italic; }

/* ----------------------------------------------------------------- hero */
.hero { min-height: 100vh; display: flex; align-items: center; padding: 0 0 0 calc(var(--rail-w) + 40px); }
.hero .hero-inner { max-width: 760px; pointer-events: auto; }
.hero .hero-mark {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  margin-bottom: 26px; display: flex; align-items: center; gap: 10px;
}
.hero .hero-mark .sq { width: 7px; height: 7px; background: var(--accent); }
.hero h1 { margin-bottom: 22px; }
.hero .hero-sub { font-size: clamp(16px, 1.45vw, 19.5px); color: var(--ink-2); max-width: 600px; }
.hero .hero-facts {
  display: flex; gap: 0; flex-wrap: wrap; margin-top: 36px;
  border-top: 1px solid var(--rule-2);
}
.hero .hero-fact {
  padding: 16px 26px 0 0; margin-right: 26px;
  border-right: 1px solid var(--rule);
}
.hero .hero-fact:last-child { border-right: 0; }
.hero .hero-fact b {
  display: block; font-family: var(--mono); font-size: 21px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
}
.hero .hero-fact span { font-size: 12.5px; color: var(--ink-3); }

.scroll-cue {
  position: fixed; left: calc(var(--rail-w) + 40px); bottom: 30px; z-index: 4;
  display: flex; align-items: center; gap: 9px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-4);
  pointer-events: none;
}
.scroll-cue i { width: 22px; height: 1px; background: var(--ink-4); display: block; }
.scroll-cue { transition: opacity .4s ease; }
body.is-past-hero .scroll-cue { opacity: 0; }

/* ------------------------------------------------------------------ rail */
.rail {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w);
  z-index: 8; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0;
  pointer-events: none;
  border-right: 1px solid var(--rule);
  background: linear-gradient(90deg, rgba(250,248,243,.72), rgba(250,248,243,.28));
}
.sde-rail-dot {
  position: relative; pointer-events: auto;
  width: var(--rail-w); height: 21px; display: grid; place-items: center;
}
.sde-rail-dot i {
  width: 14px; height: 1.5px; background: var(--rule-3); display: block;
  transition: background .25s ease, width .3s cubic-bezier(.2,.8,.3,1);
}
.sde-rail-dot:hover i { background: var(--ink-3); width: 19px; }
.sde-rail-dot.is-past i { background: var(--ink-4); }
.sde-rail-dot.is-on i { background: var(--accent); width: 26px; height: 2px; }
.sde-rail-tip {
  position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%) translateX(-4px);
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  background: var(--paper-4); border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm); padding: 3px 8px; white-space: nowrap;
  opacity: 0; pointer-events: none; box-shadow: var(--lift-2);
  transition: opacity .18s ease, transform .22s cubic-bezier(.2,.8,.3,1);
}
.sde-rail-dot:hover .sde-rail-tip, .sde-rail-dot:focus-visible .sde-rail-tip {
  opacity: 1; transform: translateY(-50%) translateX(0);
}

/* -------------------------------------------------------------- readout */
/* The instrument card: live measurements, set like a lab readout. */
.readout {
  position: fixed; top: 22px; right: 22px; z-index: 6;
  width: 262px; pointer-events: none;
  display: flex; flex-direction: column; gap: 9px;
}
.readout > * { pointer-events: auto; }
.card {
  background: var(--paper-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius);
  padding: 13px 14px 14px;
  box-shadow: var(--lift-2);
}
.card-t {
  font-family: var(--sans); font-size: 11px; font-weight: 640;
  letter-spacing: 0.04em; color: var(--ink-3);
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 8px; margin-bottom: 11px;
  border-bottom: 1px solid var(--rule);
}
.card-t .state { font-family: var(--mono); font-weight: 500; color: var(--ink-4); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.metrics.is-1 { grid-template-columns: 1fr; }

.sde-metric { min-width: 0; }
.sde-metric-label {
  font-size: 11px; color: var(--ink-3); margin-bottom: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sde-metric-value {
  font-family: var(--mono); font-size: 19px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.015em; line-height: 1.2;
  font-variant-numeric: tabular-nums;
  transition: color .3s ease;
}
.sde-metric-unit { font-size: 11px; color: var(--ink-4); font-weight: 500; }
.sde-metric-hint { font-size: 10.5px; color: var(--ink-4); margin-top: 1px; }
.sde-metric.is-good .sde-metric-value { color: var(--flag-good); }
.sde-metric.is-warn .sde-metric-value { color: var(--flag-warn); }
.sde-metric.is-bad  .sde-metric-value { color: var(--flag-bad); }
.sde-metric.is-idle .sde-metric-value { color: var(--ink-4); }

/* ------------------------------------------------------------------ bars */
.sde-bar { margin-bottom: 10px; }
.sde-bar:last-child { margin-bottom: 0; }
.sde-bar-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--ink-3); margin-bottom: 4px;
}
.sde-bar-val { font-family: var(--mono); color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.sde-bar-track {
  height: 4px; border-radius: 2px; overflow: hidden;
  background: rgba(26,24,21,.10);
}
.sde-bar-track i {
  display: block; height: 100%; width: 100%; transform-origin: left;
  transform: scaleX(0); background: var(--accent);
}
.sde-bar.is-good .sde-bar-track i { background: var(--flag-good); }
.sde-bar.is-warn .sde-bar-track i { background: var(--flag-warn); }
.sde-bar.is-bad  .sde-bar-track i { background: var(--flag-bad); }
.sde-bar.is-good .sde-bar-val { color: var(--flag-good); }
.sde-bar.is-warn .sde-bar-val { color: var(--flag-warn); }
.sde-bar.is-bad  .sde-bar-val { color: var(--flag-bad); }

/* -------------------------------------------------------------- controls */
.sde-group { margin-bottom: 14px; }
.sde-group:last-child { margin-bottom: 0; }
.sde-group-title {
  font-size: 11px; font-weight: 640; letter-spacing: 0.04em;
  color: var(--ink-3); margin-bottom: 9px;
}
.sde-group-body { display: flex; flex-direction: column; gap: 12px; }

.sde-ctl { display: block; }
.sde-ctl.is-disabled { opacity: .4; pointer-events: none; }
.sde-ctl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; gap: 12px; }
.sde-ctl-label { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sde-ctl-value {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.sde-ctl-hint { font-size: 11px; color: var(--ink-4); margin-top: 5px; line-height: 1.45; }

.sde-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 20px; background: none; cursor: pointer; display: block;
  --fill: 50%;
}
.sde-range::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill), rgba(26,24,21,.14) var(--fill) 100%);
}
.sde-range::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(26,24,21,.14); }
.sde-range::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--accent); }
/* A physical machined thumb: white cap, ink ring, contact shadow. */
.sde-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%; margin-top: -6px;
  background: var(--paper-4); border: 1.5px solid var(--accent);
  box-shadow: var(--lift-1);
  transition: transform .14s cubic-bezier(.2,.8,.3,1);
}
.sde-range::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  border: 1.5px solid var(--accent); background: var(--paper-4);
}
.sde-range:hover::-webkit-slider-thumb { transform: scale(1.14); }
.sde-range:active::-webkit-slider-thumb { transform: scale(1.06); }

.sde-toggle { display: flex; align-items: center; gap: 10px; width: 100%; padding: 0; text-align: left; }
.sde-toggle-track {
  flex: none; width: 34px; height: 19px; border-radius: 10px;
  background: rgba(26,24,21,.13); border: 1px solid var(--rule-2);
  position: relative; transition: background .22s ease, border-color .22s ease;
}
.sde-toggle-track i {
  position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--paper-4); box-shadow: var(--lift-1);
  transition: transform .26s cubic-bezier(.3,1.3,.5,1);
}
.sde-toggle.is-on .sde-toggle-track { background: var(--accent); border-color: var(--accent); }
.sde-toggle.is-on .sde-toggle-track i { transform: translateX(15px); }
.sde-toggle-label { font-size: 12.5px; color: var(--ink-2); }
.sde-toggle.is-on .sde-toggle-label { color: var(--ink); }

.sde-seg-row {
  display: flex; gap: 0; border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm); overflow: hidden; background: var(--paper-2);
}
.sde-seg {
  flex: 1; padding: 6px 8px;
  font-family: var(--mono); font-size: 11px;
  color: var(--ink-3); white-space: nowrap;
  border-right: 1px solid var(--rule);
  transition: background .16s ease, color .16s ease;
}
.sde-seg:last-child { border-right: 0; }
.sde-seg:hover { background: var(--paper-3); color: var(--ink-2); }
.sde-seg.is-on { background: var(--accent); color: var(--paper-4); font-weight: 600; }

.sde-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-2); background: var(--paper-3);
  color: var(--ink); font-size: 12.5px; font-weight: 550;
  box-shadow: var(--lift-1);
  transition: background .16s ease, border-color .16s ease, transform .1s ease, box-shadow .16s ease;
  white-space: nowrap;
}
.sde-btn:hover { background: var(--paper-4); border-color: var(--rule-3); }
.sde-btn:active { transform: translateY(1px); box-shadow: none; }
.sde-btn:disabled { opacity: .38; pointer-events: none; box-shadow: none; }
.sde-btn.is-primary { background: var(--accent); border-color: var(--accent); color: var(--paper-4); }
.sde-btn.is-primary:hover { filter: brightness(1.12); }
.sde-btn.is-danger { border-color: var(--flag-bad); color: var(--flag-bad); }
.sde-btn.is-danger:hover { background: var(--flag-bad); color: var(--paper-4); }
.sde-btn.is-ghost { background: none; box-shadow: none; border-color: var(--rule); color: var(--ink-3); }
.sde-btn.is-ghost:hover { color: var(--ink); border-color: var(--rule-2); }
.sde-btn-row { display: flex; gap: 7px; flex-wrap: wrap; }
.sde-btn-row .sde-btn { flex: 1; }

.sde-field {
  width: 100%; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-2); background: var(--paper-4);
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
}
.sde-field::placeholder { color: var(--ink-4); }

/* ------------------------------------------------------------------ dock */
.dock {
  position: fixed; left: calc(var(--rail-w) + 40px); right: 300px; bottom: 22px;
  z-index: 7; pointer-events: none;
  display: flex; justify-content: flex-start;
}
.sde-dock-panel {
  pointer-events: auto;
  width: min(860px, 100%);
  background: var(--paper-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius);
  box-shadow: var(--lift-3);
  padding: 15px 18px 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px 22px; align-items: end;
  opacity: 0; transform: translateY(10px);
  transition: opacity .26s cubic-bezier(.2,.8,.3,1), transform .26s cubic-bezier(.2,.8,.3,1);
}
.sde-dock-panel.is-in { opacity: 1; transform: none; }
.sde-dock-panel.is-leaving { opacity: 0; transform: translateY(-6px); position: absolute; inset: auto auto 0 0; width: min(860px, 100%); }
.sde-dock-panel .dock-title {
  grid-column: 1 / -1;
  font-size: 11px; font-weight: 640; letter-spacing: 0.04em; color: var(--ink-3);
  display: flex; align-items: center; gap: 10px; margin-bottom: -4px;
}
.sde-dock-panel .dock-title::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.sde-dock-panel .dock-span { grid-column: 1 / -1; }

/* ------------------------------------------------------------------- log */
/* Events as a running margin log, not popup toasts. */
.log {
  position: fixed; right: 22px; bottom: 22px; z-index: 6;
  width: 262px; pointer-events: none;
  display: flex; flex-direction: column-reverse; gap: 5px;
}
.log-line {
  background: var(--paper-3); border: 1px solid var(--rule);
  border-left: 2px solid var(--ink-4);
  border-radius: var(--radius-sm); padding: 7px 10px;
  font-size: 12px; color: var(--ink-2);
  box-shadow: var(--lift-1);
  opacity: 0; transform: translateX(10px);
  transition: opacity .24s ease, transform .28s cubic-bezier(.2,.8,.3,1);
}
.log-line.is-in { opacity: 1; transform: none; }
.log-line b { color: var(--ink); font-weight: 600; }
.log-line .t { font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); margin-right: 6px; }
.log-line.is-good { border-left-color: var(--flag-good); }
.log-line.is-warn { border-left-color: var(--flag-warn); }
.log-line.is-bad  { border-left-color: var(--flag-bad); }
.log-line.is-key  { border-left-color: var(--accent); }

/* ---------------------------------------------------------------- legend */
.sde-legend { display: flex; flex-wrap: wrap; gap: 7px 15px; }
.sde-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-3); }
.sde-legend-item i { width: 14px; height: 3px; border-radius: 1px; flex: none; }
.sde-legend-item i.is-dashed {
  height: 0; border-top: 2px dashed currentColor; background: none !important;
}

/* ------------------------------------------------------- index (a11y) */
/* The DOM mirror of the board: every node and edge, keyboard-reachable. */
.index-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 320px; z-index: 20;
  background: var(--paper-3); border-left: 1px solid var(--rule-2);
  box-shadow: -18px 0 44px -24px rgba(26,24,21,.4);
  transform: translateX(100%); transition: transform .3s cubic-bezier(.2,.8,.3,1);
  display: flex; flex-direction: column;
}
.index-panel.is-open { transform: none; }
.index-head {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.index-head h3 { margin: 0; font-size: 16px; }
.index-body { overflow-y: auto; padding: 10px 12px 20px; flex: 1; }
.index-group { margin-bottom: 16px; }
.index-group > h4 { padding: 0 6px; }
.index-item {
  display: block; width: 100%; text-align: left;
  padding: 7px 9px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--ink-2); border: 1px solid transparent;
}
.index-item:hover { background: var(--paper-2); }
.index-item.is-on { background: var(--paper-4); border-color: var(--accent); color: var(--ink); }
.index-item .meta { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); }

/* --------------------------------------------------------------- toolbar */
.toolbar {
  position: fixed; top: 22px; left: calc(var(--rail-w) + 40px); z-index: 6;
  display: flex; gap: 7px; align-items: center; pointer-events: auto;
}
.toolbar .sde-btn { padding: 6px 11px; font-size: 12px; }

/* ---------------------------------------------------------------- status */
/* Live-region text: visible, because it is genuinely useful on camera. */
.status {
  position: fixed; left: calc(var(--rail-w) + 40px); top: 62px; z-index: 5;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  background: var(--paper-3); border: 1px solid var(--rule);
  border-radius: var(--radius-sm); padding: 5px 10px;
  box-shadow: var(--lift-1); max-width: 460px;
  opacity: 0; transition: opacity .25s ease;
}
.status.is-on { opacity: 1; }
.status b { color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- loader */
.loader {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; background: var(--paper);
  transition: opacity .5s ease, visibility .5s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader-inner { text-align: left; width: 240px; }
.loader-mark { font-family: var(--serif); font-size: 17px; color: var(--ink); margin-bottom: 14px; }
.loader-steps { font-family: var(--mono); font-size: 11.5px; color: var(--ink-4); }
.loader-steps div { display: flex; justify-content: space-between; padding: 2px 0; }
.loader-steps div.is-done { color: var(--ink-2); }
.loader-steps div.is-done::after { content: "done"; color: var(--flag-good); }
.loader-steps div::after { content: "…"; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1280px) { :root { --panel-w: 410px; } .readout { width: 236px; } }
@media (max-width: 1080px) {
  :root { --rail-w: 42px; }
  .readout, .log { display: none; }
  .chapter, .hero { padding-left: calc(var(--rail-w) + 22px); padding-right: 22px; }
  .dock { left: calc(var(--rail-w) + 22px); right: 22px; }
  .toolbar, .scroll-cue, .status { left: calc(var(--rail-w) + 22px); }
}
@media (max-width: 760px) {
  :root { --panel-w: 100%; --rail-w: 0px; }
  body { font-size: 15.5px; }
  .rail, .scroll-cue { display: none; }
  .chapter { min-height: auto; padding: 10vh 16px 46vh; }
  .hero { padding: 0 16px; min-height: 92vh; }
  .panel { padding: 22px 20px; }
  .dock { left: 10px; right: 10px; bottom: 10px; }
  .sde-dock-panel { grid-template-columns: 1fr; padding: 13px; width: 100%; }
  .index-panel { width: 100%; }
  .toolbar { top: 10px; left: 10px; }
  .status { left: 10px; right: 10px; top: 52px; max-width: none; }
  .hero .hero-facts { flex-direction: column; }
  .hero .hero-fact { border-right: 0; border-bottom: 1px solid var(--rule); padding: 10px 0; margin: 0; width: 100%; }
}

/* ----------------------------------------------------------- motion modes */
/* Reduced: no travel, no ambient, entrances collapse to their end state. */
body.motion-reduced [data-reveal],
body.motion-static [data-reveal] { opacity: 1 !important; transform: none !important; transition: none !important; }
body.motion-static * { animation: none !important; }
body.motion-static .sde-dock-panel { transition: none; }

[data-reveal] {
  opacity: 0; transform: translateY(14px);
  transition: opacity .6s cubic-bezier(.2,.8,.3,1), transform .6s cubic-bezier(.2,.8,.3,1);
}
[data-reveal].is-revealed { opacity: 1; transform: none; }
[data-reveal][data-delay="1"] { transition-delay: .07s; }
[data-reveal][data-delay="2"] { transition-delay: .14s; }
[data-reveal][data-delay="3"] { transition-delay: .21s; }
[data-reveal][data-delay="4"] { transition-delay: .28s; }

/* -------------------------------------------------------------- utilities */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.is-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: 10px; } .mt-2 { margin-top: 18px; } .mt-3 { margin-top: 26px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 10px; } .mb-2 { margin-bottom: 18px; }

/* Clean mode: strip chrome for an unobstructed shot of the board. */
body.is-clean .readout, body.is-clean .dock, body.is-clean .rail,
body.is-clean .panel, body.is-clean .log, body.is-clean .scroll-cue,
body.is-clean .toolbar, body.is-clean .status, body.is-clean .hero-inner {
  opacity: 0 !important; pointer-events: none !important;
}
.readout, .dock, .rail, .panel, .log, .scroll-cue, .toolbar, .hero-inner {
  transition: opacity .4s cubic-bezier(.2,.8,.3,1);
}
@media print { .rail, .dock, .readout, .log, .toolbar, #stage-wrap { display: none; } }

/* ------------------------------------------------------------- challenges */
/* A worksheet inside the narrative panel: brief, editor, grader results. */
.challenge { margin-top: 6px; }
.ch-head { margin-bottom: 10px; }
.ch-kicker {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.02em;
  color: var(--accent-2); margin-bottom: 4px; font-weight: 600;
}
.ch-head h3 { margin-bottom: 0; }
.ch-brief { font-size: 14.5px; color: var(--ink-2); margin-bottom: 12px; }
.ch-brief code { font-size: 12px; }

.ch-signature {
  font-family: var(--mono); font-size: 12px; color: var(--ink-3);
  padding: 6px 10px; margin-bottom: -1px;
  background: var(--paper-2);
  border: 1px solid var(--rule-2); border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.ch-signature span { color: var(--accent); font-weight: 600; }
.ch-signature code { background: none; border: 0; padding: 0; color: var(--ink); }

.ch-editor {
  display: block; width: 100%; resize: vertical;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  color: var(--ink); background: var(--paper-4);
  border: 1px solid var(--rule-2);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 10px 12px;
  tab-size: 2; white-space: pre; overflow-x: auto;
  box-shadow: inset 0 1px 3px rgba(26,24,21,.06);
}
.ch-editor:focus { outline: none; border-color: var(--accent); }

.ch-toolbar { display: flex; gap: 7px; align-items: center; margin-top: 10px; }
.ch-runhint {
  margin-left: auto; font-family: var(--mono); font-size: 10.5px;
  color: var(--ink-4);
}

.ch-error {
  margin-top: 10px; padding: 9px 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  color: var(--flag-bad);
  border: 1px solid var(--flag-bad); border-left-width: 2px;
  border-radius: var(--radius-sm);
  background: rgba(147,51,30,.05);
  white-space: pre-wrap;
}

.ch-results { margin-top: 12px; }
.ch-cases { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.ch-case {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; color: var(--ink-2);
  padding: 5px 9px; border-radius: var(--radius-sm);
  background: var(--paper-2); border: 1px solid var(--rule);
}
.ch-case i { font-style: normal; font-family: var(--mono); font-size: 12px; flex: none; }
.ch-case b { font-weight: 560; color: var(--ink); }
.ch-case span { color: var(--ink-3); font-size: 12px; }
.ch-case.is-ok i { color: var(--flag-good); }
.ch-case.is-ok { border-left: 2px solid var(--flag-good); }
.ch-case.is-fail i { color: var(--flag-bad); }
.ch-case.is-fail { border-left: 2px solid var(--flag-bad); }

.ch-metrics { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 10px; }
.ch-metric { font-size: 12px; color: var(--ink-3); }
.ch-metric b {
  display: block; font-family: var(--mono); font-size: 16px;
  color: var(--ink); font-variant-numeric: tabular-nums;
}

.ch-verdict {
  padding: 9px 12px; font-size: 14px; font-weight: 550;
  border-radius: var(--radius-sm); border: 1px solid var(--rule-2);
  color: var(--ink-2);
}
.ch-verdict.is-pass {
  border-color: var(--flag-good); color: var(--flag-good);
  background: rgba(61,102,71,.06);
}
.ch-verdict.is-fail {
  border-color: var(--flag-warn); color: var(--flag-warn);
  background: rgba(147,102,28,.05);
}
