/* Landing page styling.
 *
 * This is the public entry point, not the product UI, so it does not follow
 * the development repository's design tokens — a decision recorded in ADR 0029.
 * The palette is taken from this project's own banner, so the site and the
 * README read as one place.
 *
 * The hero is a fixed dark stage in both colour schemes: it is a showpiece
 * band, and the WebGL visual is composed against a dark ground. Everything
 * below the hero follows the visitor's light/dark preference.
 */

:root {
  color-scheme: light dark;

  --stage-0: #070c16;
  --stage-1: #0d1729;
  --stage-2: #101f38;
  --on-stage: #f4f7fb;
  --on-stage-dim: #a8b6cc;

  --mint: #3fcf8e;
  --sky: #38bdf8;
  --violet: #a78bfa;
  /* The third boundary of the hero visual sits between sky and violet. It has
   * no other use here; the value matches BOUNDARIES in assets/js/hero.js. */
  --iris: #74a0fb;

  --bg: #fbfaf8;
  --bg-alt: #f4f2ef;
  --surface: #ffffff;
  --text: #171513;
  --text-muted: #57534e;
  --line: #e4e1dd;
  --line-strong: #cfcac3;
  --accent: #0f766e;
  --accent-soft: #effcf9;

  /* Severity. Deliberately not derived from the accent: these carry meaning. */
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fbf1dd;
  --info: #3b5f8f;
  --info-soft: #e9f0f8;

  --measure: 68rem;
  --pad: clamp(20px, 5vw, 40px);
  --radius: 14px;

  --font: "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0b;
    --bg-alt: #121213;
    --surface: #161617;
    --text: #f5f4f2;
    --text-muted: #a6a29d;
    --line: #262627;
    --line-strong: #3b3b3d;
    --accent: #5eead4;
    --accent-soft: #0b2b28;

    --danger: #ff8a76;
    --danger-soft: #2e1512;
    --warn: #e2a84a;
    --warn-soft: #2b2010;
    --info: #8fb4e6;
    --info-soft: #14202f;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.85;
  text-wrap: pretty;
  overflow-x: hidden;
}

a { color: var(--accent); text-underline-offset: 3px; }

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

.skip { position: absolute; left: -9999px; }
.skip:focus {
  left: 16px; top: 16px; z-index: 60;
  background: var(--surface); color: var(--text);
  padding: 10px 18px; border: 1px solid var(--line-strong); border-radius: 8px;
}

.wrap { max-width: var(--measure); margin: 0 auto; padding-inline: var(--pad); }

/* =============================================================== the stage */

/* `.hero` only supplies scroll distance; `.hero-stage` is what you look at.
 * Without the flight the two are the same height and the stage never sticks,
 * so every fallback keeps a compact one-screen hero and reaches the content
 * immediately. `overflow` lives on the stage — putting it on the wrapper
 * would stop `position: sticky` working at all. */
.hero {
  position: relative;
  background: var(--stage-0);
  color: var(--on-stage);
  min-height: 100vh;
  min-height: 100svh;
}

/* Two screens of scroll: one to fly through the four boundaries, then the
 * content. Applied by script only once the visual is confirmed running. */
.hero--flight { height: 200svh; }

.hero-stage {
  position: sticky;
  top: 0;
  isolation: isolate;
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Painted with CSS alone, so it stands on its own with JavaScript disabled,
 * with WebGL unavailable, or while the canvas is still initialising. */
.hero-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(80rem 44rem at 72% 18%, rgba(56, 189, 248, .22), transparent 62%),
    radial-gradient(60rem 40rem at 22% 78%, rgba(63, 207, 142, .18), transparent 60%),
    radial-gradient(52rem 36rem at 88% 88%, rgba(167, 139, 250, .20), transparent 62%),
    linear-gradient(165deg, var(--stage-1) 0%, var(--stage-0) 52%, var(--stage-2) 100%);
}

/* A faint grid so the empty half of the stage still reads as constructed. */
.hero-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(148, 190, 235, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 190, 235, .07) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(70% 62% at 50% 42%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(70% 62% at 50% 42%, #000 0%, transparent 78%);
}

#hero-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#hero-canvas.is-live { opacity: 1; }

/* Keeps the headline legible whatever the canvas happens to draw behind it.
 * The structure lives in the right half, so only the left is darkened. */
.hero-veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(100deg,
    rgba(7, 12, 22, .90) 0%,
    rgba(7, 12, 22, .74) 30%,
    rgba(7, 12, 22, .28) 54%,
    rgba(7, 12, 22, 0) 74%);
}

.topbar, .hero-body, .scroll-cue { position: relative; z-index: 3; }

/* The legend for the visual: the four boundaries it draws, in order, with the
 * one the camera is inside lit. All four are present from the first paint, so
 * a visitor who never starts the flight still gets the whole structure. The
 * flight only moves `.is-here`. Absolutely placed, so it never affects the
 * fallback layout. */
.hero-layers {
  position: absolute;
  right: var(--pad);
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: max-content;
  max-width: 14rem;
  text-align: right;
  pointer-events: none;
}

.hero-layers-cap {
  margin: 0 0 14px;
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--on-stage-dim);
  /* Japanese wraps mid-word by default, which splits カタカナ across lines.
   * Ignored where unsupported, which only restores that default. */
  word-break: auto-phrase;
}

.hero-layer-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 11px;
}

/* Threads the dots together, so the four read as one path in order rather
 * than as four unrelated labels. */
.hero-layer-list::before {
  content: "";
  position: absolute;
  right: 3px;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: linear-gradient(180deg,
    var(--mint), var(--sky) 38%, var(--iris) 68%, var(--violet));
  opacity: .4;
}

.hero-layer-list li {
  position: relative;
  padding-right: 19px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--on-stage-dim);
  opacity: .8;
  transition: opacity .35s ease, color .35s ease;
}
.hero-layer-list li::before {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  width: 7px; height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: var(--layer);
}

.hero-layer-list li:nth-child(1) { --layer: var(--mint); }
.hero-layer-list li:nth-child(2) { --layer: var(--sky); }
.hero-layer-list li:nth-child(3) { --layer: var(--iris); }
.hero-layer-list li:nth-child(4) { --layer: var(--violet); }

.hero-layer-list li.is-here {
  opacity: 1;
  color: var(--on-stage);
}
.hero-layer-list li.is-here::before { box-shadow: 0 0 10px var(--layer); }

/* The free column on the right closes well before the hero does: `.lede` is
 * 38rem wide and the legend needs 14rem, so below this the two would meet.
 * The legend rejoins the flow under the copy instead and reads left to right
 * like the rest of it, dots flipped to match. */
@media (max-width: 1060px) {
  .hero-layers {
    /* Relative, not static: it rejoins the flow but keeps the z-index that
     * holds it above `.hero-veil`. */
    position: relative;
    align-self: stretch;
    top: auto;
    right: auto;
    transform: none;
    width: auto;
    max-width: none;
    text-align: left;
    padding: 0 var(--pad) 10px;
  }
  .hero-layers-cap { margin-bottom: 10px; }
  /* Buys the gap the legend needs above the scroll cue without pushing the
   * cue out of the stage, which `overflow: hidden` would clip. */
  .hero-body { padding-bottom: 18px; }
  /* Four rows would push the scroll cue out of the stage, so the four run
   * across and wrap. The thread goes with them; left-to-right order carries
   * the sequence on its own. */
  .hero-layer-list {
    display: flex;
    flex-wrap: wrap;
    gap: 9px 18px;
  }
  .hero-layer-list::before { display: none; }
  .hero-layer-list li { padding-right: 0; padding-left: 19px; }
  .hero-layer-list li::before { right: auto; left: 0; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--measure);
  width: 100%;
  margin: 0 auto;
  padding: 22px var(--pad) 0;
  font-size: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--on-stage);
  text-decoration: none;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: linear-gradient(135deg, var(--mint), var(--sky) 55%, var(--violet));
  box-shadow: 0 0 12px rgba(63, 207, 142, .8);
}

.topbar a.plain {
  color: var(--on-stage-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.topbar a.plain:hover { color: var(--on-stage); border-bottom-color: currentColor; }

.hero-body {
  flex: 1;
  display: flex;
  align-items: center;
  max-width: var(--measure);
  width: 100%;
  margin: 0 auto;
  padding: 48px var(--pad) 32px;
}

.hero-copy { max-width: 48rem; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 22px;
  padding: 6px 14px;
  border: 1px solid rgba(148, 190, 235, .28);
  border-radius: 999px;
  background: rgba(8, 16, 30, .5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--on-stage-dim);
  line-height: 1.6;
}

.hero h1 {
  margin: 0 0 20px;
  font-size: clamp(28px, 4.4vw, 52px);
  line-height: 1.22;
  letter-spacing: -.015em;
  font-weight: 700;
  text-wrap: balance;
}
.hero h1 .grad {
  background: linear-gradient(100deg, var(--mint), var(--sky) 46%, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero .lede {
  margin: 0 0 34px;
  font-size: clamp(15px, 2.1vw, 19px);
  line-height: 1.85;
  color: var(--on-stage-dim);
  max-width: 38rem;
}

.cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 32px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease;
}
.btn-primary {
  background: linear-gradient(100deg, var(--mint), var(--sky) 70%);
  color: #04121f;
  box-shadow: 0 10px 30px -12px rgba(56, 189, 248, .8);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 16px 36px -12px rgba(56, 189, 248, .9); }
.btn-ghost {
  color: var(--on-stage);
  border-color: rgba(180, 205, 235, .34);
  background: rgba(9, 18, 34, .45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.btn-ghost:hover { border-color: rgba(180, 205, 235, .7); transform: translateY(-2px); }

.hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
  font-family: var(--mono);
  color: var(--on-stage-dim);
}
.hero-facts li {
  padding: 4px 12px;
  border: 1px solid rgba(148, 190, 235, .2);
  border-radius: 999px;
  background: rgba(8, 16, 30, .4);
}

.scroll-cue {
  max-width: var(--measure);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--pad) 26px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--on-stage-dim);
  text-decoration: none;
  display: block;
}
.scroll-cue .arrow { display: inline-block; animation: nudge 2.2s ease-in-out infinite; }
@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

@media (max-width: 860px) {
  .hero-veil {
    background: linear-gradient(180deg,
      rgba(7, 12, 22, .82) 0%,
      rgba(7, 12, 22, .70) 55%,
      rgba(7, 12, 22, .40) 100%);
  }
  #hero-canvas.is-live { opacity: .6; }
}

/* ================================================================ sections */

section { padding: clamp(64px, 10vw, 116px) 0; }
.band-alt { background: var(--bg-alt); border-block: 1px solid var(--line); }

.kicker {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}

h2 {
  margin: 0 0 16px;
  font-size: clamp(24px, 3.6vw, 36px);
  line-height: 1.32;
  letter-spacing: -.01em;
  font-weight: 700;
}

.section-lede {
  margin: 0 0 44px;
  max-width: 42rem;
  color: var(--text-muted);
  font-size: clamp(15px, 1.8vw, 17px);
}

.cards {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
}

.card {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.card h3 { margin: 0 0 10px; font-size: 18px; line-height: 1.45; }
.card p { margin: 0; color: var(--text-muted); font-size: 15px; line-height: 1.8; }
.card .num {
  display: block;
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--accent);
}

/* Links that go somewhere get the lift; plain cards do not. */
a.card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
a.card:hover, a.card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 14px 34px -22px rgba(0, 0, 0, .6);
}
a.card h3 { color: var(--accent); }
a.card .go {
  display: block;
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* ------------------------------------------------------------- the pillars */

.pillars { display: grid; gap: 0; border-top: 1px solid var(--line); }
.pillar {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 13rem) minmax(0, 1fr);
  gap: 8px 24px;
  align-items: start;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}
.pillar .idx { font-family: var(--mono); font-size: 12px; color: var(--accent); padding-top: 5px; }
.pillar h3 { margin: 0; font-size: 17px; line-height: 1.6; }
.pillar p { margin: 0; color: var(--text-muted); font-size: 15px; }

@media (max-width: 720px) {
  .pillar { grid-template-columns: 3rem minmax(0, 1fr); }
  .pillar p { grid-column: 2; }
}

/* ------------------------------------------------------------- the diagrams */

.diagram-feature {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  margin-bottom: 20px;
}

.diagram-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 36px;
  padding: 0;
  list-style: none;
}
.diagram-note li {
  padding: 5px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--text-muted);
  background: var(--surface);
}

/* ------------------------------------------------------------------ chips */

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chips li {
  padding: 9px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 14.5px;
  background: var(--surface);
}
.chips li b { font-weight: 600; }

/* ------------------------------------------------------------------ steps */

.steps { margin: 0 0 32px; padding: 0; list-style: none; counter-reset: step; }
.steps li {
  position: relative;
  padding: 0 0 22px 46px;
  counter-increment: step;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 2px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1;
}
.steps li::after {
  content: "";
  position: absolute;
  left: 15px; top: 36px; bottom: 4px;
  border-left: 1px dashed var(--line-strong);
}
.steps li:last-child { padding-bottom: 0; }
.steps li:last-child::after { display: none; }
.steps b { display: block; font-size: 16px; }
.steps span { color: var(--text-muted); font-size: 15px; }

.callout {
  margin: 36px 0 0;
  padding: 20px 24px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
  font-size: 15px;
}
.callout p { margin: 0; }
.callout p + p { margin-top: 10px; }

/* ------------------------------------------------------------------ footer */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 56px 0 72px;
  color: var(--text-muted);
  font-size: 14px;
}
.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin: 0 0 24px;
}
.site-footer .license { margin: 0; }

/* ============================================== motion & reveal (opt-in) */

.js .reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .7s ease, transform .7s ease;
}
.js .reveal.shown { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .js .reveal { opacity: 1; transform: none; }
  .scroll-cue .arrow { animation: none; }
  #hero-canvas { opacity: 1; transition: none; }
}

/* ====================================================== traceability demo */

/* Five sites one requirement ID has to reach, drawn as a chain that either
 * carries through or parts at the point that went wrong. The connectors are
 * scaled pseudo-elements rather than SVG, so the whole thing reflows from a
 * row to a column on narrow screens without any path maths. */

.trace {
  --sev: var(--accent);
  margin: 8px 0 0;
}

.trace-chain {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0 26px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.station {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color .25s ease, box-shadow .25s ease;
}

/* The connector to the next station.
 *
 * Connected is the default. A chain drawn at zero would say the requirement
 * is broken, which is the opposite of the truth, so the undrawn state is
 * reached only when script has said it intends to animate (`is-armed`) — and
 * `is-live` then draws it. No script, no observer, reduced motion: connected. */
.station:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  width: 26px;
  height: 2px;
  margin-top: -1px;
  background: var(--accent);
  transform: scaleX(1);
  transform-origin: left center;
  transition: transform .34s ease, background-color .18s ease;
}
.trace.is-armed .station:not(:last-child)::after { transform: scaleX(0); }
.trace.is-armed.is-live .station:not(:last-child)::after { transform: scaleX(1); }

.trace.is-armed.is-live .station:nth-child(1)::after { transition-delay: .05s; }
.trace.is-armed.is-live .station:nth-child(2)::after { transition-delay: .19s; }
.trace.is-armed.is-live .station:nth-child(3)::after { transition-delay: .33s; }
.trace.is-armed.is-live .station:nth-child(4)::after { transition-delay: .47s; }

/* A cut connector snaps rather than eases: this should read as a fault. */
.station.is-cut::after {
  transform: scaleX(.42);
  background: var(--danger);
  transition: transform .18s cubic-bezier(.2, .9, .3, 1), background-color .18s ease;
  transition-delay: 0s;
}

.station.is-broken {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.st-head { display: flex; align-items: baseline; gap: 8px; }
.st-idx {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.st-name { font-size: 14px; font-weight: 600; }

.st-body {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  flex: 1;
}
.st-body .chg { color: var(--danger); font-weight: 600; }
.st-body .gone { color: var(--danger); text-decoration: line-through; opacity: .65; }

.st-src { font-size: 11.5px; line-height: 1.5; color: var(--text-muted); }

/* ---------------------------------------------------------- the readout */

.readout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 22px 0 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--surface);
  transition: border-left-color .2s ease;
}
.trace.is-failing .readout { border-left-color: var(--danger); }

.ro-rule {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--danger);
  letter-spacing: .02em;
}
.ro-rule.ok { color: var(--accent); }

.ro-exit {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.ro-note { flex: 1 1 20rem; font-size: 14px; color: var(--text-muted); line-height: 1.65; }

.sev {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.sev.e  { color: var(--danger); background: var(--danger-soft); }
.sev.ok { color: var(--accent); background: var(--accent-soft); }

/* ---------------------------------------------------------- the controls */

/* Only useful with scripting; without it the chain still reads intact. */
.trace-controls { display: none; }
.js .trace-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 20px 0 0;
}

.tc-label {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-right: 2px;
}

.trace-controls button {
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease, color .18s ease;
}
.trace-controls button:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.trace-controls button[aria-pressed="true"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}
.trace-controls .tc-reset { margin-left: auto; }
.trace-controls .tc-reset:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.trace-controls button:disabled { opacity: .4; cursor: default; }

/* ---------------------------------------------------------- the limits */

h3.sub { font-size: 19px; margin: 52px 0 10px; }

.limits { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.limits li {
  padding: 15px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 0 9px 9px 0;
  font-size: 15px;
  line-height: 1.75;
}

@media (max-width: 900px) {
  .trace-chain { grid-template-columns: 1fr; gap: 22px 0; }
  .station:not(:last-child)::after {
    left: 50%; top: 100%;
    width: 2px; height: 22px;
    margin: 0 0 0 -1px;
    transform: scaleY(0);
    transform-origin: top center;
  }
  .station:not(:last-child)::after { transform: scaleY(1); }
  .trace.is-armed .station:not(:last-child)::after { transform: scaleY(0); }
  .trace.is-armed.is-live .station:not(:last-child)::after { transform: scaleY(1); }
  .station.is-cut::after { transform: scaleY(.42); }
  .trace-controls .tc-reset { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .station::after { transition: none !important; transition-delay: 0s !important; }
}

/* ==================================================== embedded diagram */

.diagram-live { margin: 0 0 26px; }

.diagram-slot {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

/* Until a diagram is mounted the slot is just the link, so it must not
 * reserve the height of one. */
.diagram-slot.is-mounted { background: #0b1220; }

/* Starting height only: the script measures the diagram and sets the real one,
 * so the frame never carries a scrollbar of its own. This value just avoids a
 * jump while it loads. */
.diagram-frame {
  display: block;
  width: 100%;
  height: 560px;
  border: 0;
}

.diagram-open {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 14px;
  padding: 22px 24px;
  text-decoration: none;
  color: inherit;
  transition: background-color .18s ease;
}
.diagram-open:hover { background: var(--bg-alt); }
.diagram-open strong { font-size: 17px; color: var(--accent); }
.diagram-open span { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }
.diagram-slot.is-mounted .diagram-open { display: none; }

.diagram-live figcaption {
  margin: 12px 2px 0;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .diagram-frame { height: 500px; }
}

/* ---------------------------------------------------------------- tables */

/* Wide content scrolls inside its own container so the page body never
 * scrolls sideways. */
.tablewrap {
  overflow-x: auto;
  margin: 26px 0 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.tablewrap table { width: 100%; border-collapse: collapse; line-height: 1.7; }
.tablewrap th,
.tablewrap td { text-align: left; border-bottom: 1px solid var(--line); }
.tablewrap tbody tr:last-child td { border-bottom: 0; }

/* ================================================= the site's own record */

.prlog { font-size: 14.5px; }
.prlog th, .prlog td { padding: 11px 16px; vertical-align: top; }
.prlog thead th {
  background: var(--bg-alt);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.prlog td a { font-family: var(--mono); font-weight: 600; }
.prlog td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-muted); }

/* ================================================== reading a document */

/* These styles carry the documents themselves. The content is overwhelmingly
 * tables — 117 of them across the seven documents — so tables get the most
 * attention here, not the prose. */

body.reading { background: var(--bg); }

.doc-bar {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.doc-bar .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  padding-block: 14px;
}
.doc-bar .brand { color: var(--text); }
.doc-bar nav { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 14px; }

.doc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 40px;
  padding-block: clamp(32px, 6vw, 60px) clamp(48px, 8vw, 88px);
}

@media (min-width: 1060px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr) 15rem; }
  .doc-toc { order: 2; }
  #doc { order: 1; }
}

/* ------------------------------------------------------------------- toc */

.doc-toc { align-self: start; }
@media (min-width: 1060px) {
  .doc-toc { position: sticky; top: 76px; }
}
/* Japanese, so no uppercase or wide tracking — those are for Latin labels. */
.toc-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
  list-style-position: inside;
}
.toc-title::marker { color: var(--accent); }
.toc-box[open] .toc-title { margin-bottom: 6px; }

/* Beside the text there is nothing to collapse for, so the control goes away. */
@media (min-width: 1060px) {
  .toc-title { cursor: default; list-style: none; padding-top: 0; }
  .toc-title::marker, .toc-title::-webkit-details-marker { display: none; content: ""; }
}
.doc-toc ol {
  margin: 0;
  padding: 0 0 0 0;
  list-style: none;
  counter-reset: toc;
  border-left: 1px solid var(--line);
}
.doc-toc li { counter-increment: toc; }
.doc-toc a {
  display: block;
  padding: 5px 0 5px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
  text-decoration: none;
}
.doc-toc a:hover, .doc-toc a:focus-visible { color: var(--accent); border-left-color: var(--accent); }

/* ----------------------------------------------------------------- prose */

.prose { max-width: 44rem; font-size: 16.5px; line-height: 1.95; }
.prose > :first-child { margin-top: 0; }

.prose h1 {
  font-size: clamp(27px, 4vw, 36px);
  line-height: 1.3;
  letter-spacing: -.015em;
  margin: 0 0 24px;
  text-wrap: balance;
}
.prose h2 {
  font-size: clamp(20px, 2.6vw, 25px);
  line-height: 1.4;
  margin: 56px 0 14px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  text-wrap: balance;
}
.prose h3 { font-size: 18px; line-height: 1.5; margin: 36px 0 10px; }
.prose h4 { font-size: 16px; margin: 28px 0 8px; color: var(--text-muted); }

.prose p, .prose ul, .prose ol { margin: 18px 0; }
.prose li { margin: 7px 0; }
.prose li > ul, .prose li > ol { margin: 7px 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 52px 0; }
.prose img { max-width: 100%; height: auto; }

/* The anchor mark stays out of the way until the heading is approached. */
.prose h1 .anchor, .prose h2 .anchor, .prose h3 .anchor,
.prose h4 .anchor, .prose h5 .anchor, .prose h6 .anchor {
  margin-left: .4em;
  font-family: var(--mono);
  font-weight: 400;
  color: var(--line-strong);
  text-decoration: none;
  opacity: 0;
  transition: opacity .15s ease;
}
.prose h1:hover .anchor, .prose h2:hover .anchor, .prose h3:hover .anchor,
.prose h4:hover .anchor, .anchor:focus-visible { opacity: 1; }
.prose .anchor:hover { color: var(--accent); }

.prose code {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: .87em;
}
.prose pre {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 16px 18px;
  overflow-x: auto;
  line-height: 1.7;
  margin: 22px 0;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: 13.5px; }

.mermaid-note { font-size: 14.5px; color: var(--text-muted); margin-top: -10px; }

.prose blockquote {
  margin: 24px 0;
  padding: 2px 22px;
  border-left: 3px solid var(--line-strong);
  color: var(--text-muted);
}

.prose a.offsite::after {
  content: "↗";
  font-size: .8em;
  margin-left: .25em;
  color: var(--text-muted);
}

/* ---------------------------------------------------- tables in the prose */

.prose .tablewrap { margin: 24px 0; }
.prose table { font-size: 15px; }
.prose th, .prose td { padding: 10px 15px; }
.prose thead th {
  background: var(--bg-alt);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
}
.prose td > code { white-space: nowrap; }
.prose .tablewrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------- GFM callouts */

.prose blockquote.alert {
  border-left-width: 3px;
  border-radius: 0 9px 9px 0;
  padding: 16px 22px;
  color: var(--text);
  background: var(--surface);
}
.alert-label {
  margin: 0 0 6px !important;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.prose blockquote.alert > :last-child { margin-bottom: 0; }

.alert-note      { border-left-color: var(--info); background: var(--info-soft) !important; }
.alert-note      .alert-label { color: var(--info); }
.alert-tip       { border-left-color: var(--accent); background: var(--accent-soft) !important; }
.alert-tip       .alert-label { color: var(--accent); }
.alert-important { border-left-color: var(--accent); background: var(--accent-soft) !important; }
.alert-important .alert-label { color: var(--accent); }
.alert-warning   { border-left-color: var(--warn); background: var(--warn-soft) !important; }
.alert-warning   .alert-label { color: var(--warn); }
.alert-caution   { border-left-color: var(--danger); background: var(--danger-soft) !important; }
.alert-caution   .alert-label { color: var(--danger); }

/* --------------------------------------------------------------- details */

.prose details {
  margin: 22px 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  padding: 0 20px;
}
.prose details[open] { padding-bottom: 6px; }
.prose summary { cursor: pointer; padding: 14px 0; font-weight: 600; }
.prose summary::marker { color: var(--accent); }

/* -------------------------------------------------------------- fallback */

.doc-fallback { max-width: 40rem; }
.doc-fallback h1 { font-size: clamp(26px, 4vw, 34px); margin: 0 0 18px; }
.doc-fallback p { margin: 0 0 14px; color: var(--text-muted); }

/* ============================================ the document as an artefact */

/* These pages carry the project's own documents. The content is already
 * dense; what it lacked was any sense of where you are, how much there is,
 * and where to go next. Everything added here answers one of those, and every
 * figure shown is counted from the rendered document rather than written by
 * hand. */

/* ------------------------------------------------------------- progress */

.read-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 40;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--mint), var(--sky) 55%, var(--violet));
}

/* Driven from script rather than `animation-timeline: scroll()`.
 *
 * The CSS route was tried first and abandoned: `@supports (animation-timeline:
 * scroll())` answers yes because the property parses, but the timeline came up
 * inactive (currentTime null) and the bar never moved — on a fixed element and
 * on a sticky one alike, with the page plainly scrollable. A feature query that
 * reports support for something that does not work is not a usable guard, and
 * these pages already need script to render the document at all, so there is
 * no dependency saved by insisting on the CSS path. */
.doc-ready .read-progress { transition: transform .08s linear; }
@media (prefers-reduced-motion: reduce) {
  .read-progress { display: none; }
}

/* -------------------------------------------------------------- readout */

.doc-head {
  margin: 0 0 34px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}

.doc-pos {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--text-muted);
}
.doc-pos b {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.doc-pos span { font-variant-numeric: tabular-nums; }

.doc-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 26px;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
}
.doc-facts .fact { display: flex; align-items: baseline; gap: 8px; }
.doc-facts dt { color: var(--text-muted); letter-spacing: .08em; }
.doc-facts dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* ------------------------------------------------------ numbered sections */

.prose h2 { display: flex; align-items: baseline; gap: 14px; }
.h-num {
  flex: none;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.toc-num {
  display: inline-block;
  width: 2em;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--line-strong);
  font-variant-numeric: tabular-nums;
}
.doc-toc a:hover .toc-num,
.doc-toc a:focus-visible .toc-num { color: var(--accent); }

/* --------------------------------------------------------- prev and next */

.doc-move {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 14px;
  margin: 56px 0 0;
  padding: 28px 0 0;
  border-top: 1px solid var(--line);
}

.move {
  display: block;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color .18s ease, transform .18s ease;
}
.move:hover, .move:focus-visible { border-color: var(--accent); transform: translateY(-2px); }
.move.next { text-align: right; }

.move-label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.move-title { display: block; font-size: 16px; font-weight: 600; color: var(--accent); }

/* A single next link should sit on the right, where the pair would put it. */
.doc-move .move.next:only-child { grid-column: 2; }
@media (max-width: 560px) {
  .doc-move .move.next:only-child { grid-column: 1; }
  .move.next { text-align: left; }
}

/* --------------------------------------------- a simplified diagram swapped */

/* The document carries a small mermaid sketch of a diagram that exists here in
 * full, interactive form. Rendering mermaid would cost nearly a megabyte for
 * this one block, and showing its source shows the reader markup. Point at the
 * real thing instead, and fold the definition away rather than drop it. */
.diagram-swap { margin: 24px 0; }

.diagram-swap-link {
  display: block;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color .18s ease, transform .18s ease;
}
.diagram-swap-link:hover, .diagram-swap-link:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.diagram-swap-link strong { display: block; font-size: 17px; color: var(--accent); margin-bottom: 8px; }
.diagram-swap-link > span { display: block; font-size: 14.5px; line-height: 1.75; color: var(--text-muted); }
.diagram-swap-link .go {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-muted);
}

.diagram-swap figcaption { margin: 10px 0 0; }
.diagram-swap details { margin: 0; border: 0; background: none; padding: 0; }
.diagram-swap summary {
  padding: 4px 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}
.diagram-swap details pre { margin: 10px 0 0; font-size: 12.5px; }
