/* =============================================================================
   msmcdSEC documentation site — shared theme
   Dark grey/blue technical-product style. No external fonts, no frameworks.
   ============================================================================= */

:root {
  /* surfaces */
  --bg-0: #070a12;
  --bg-1: #0c111d;
  --bg-2: #111a2b;
  --bg-3: #18233a;
  --line: #233048;
  --line-soft: #1a2438;

  /* text */
  --text-0: #eaeff8;
  --text-1: #a9b6cd;
  --text-2: #66748f;

  /* accents — consistent data-type colour language across all pages */
  --acc:    #4cc2ff;   /* primary / APB / plaintext */
  --cipher: #b07bff;   /* ciphertext */
  --key:    #ffc861;   /* key material / tag */
  --meta:   #3ddc97;   /* metadata, counters, AD */
  --err:    #ff6b81;
  --warn:   #ffc861;
  --ok:     #3ddc97;

  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;

  --rad: 14px;
  --rad-s: 8px;
  --head-h: 58px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 800px at 80% -10%, #0e1a33 0%, transparent 60%),
    radial-gradient(900px 700px at -10% 30%, #0b1426 0%, transparent 55%),
    var(--bg-0);
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--text-0); line-height: 1.25; font-weight: 650; }
h1 { font-size: clamp(1.9rem, 4.5vw, 3.1rem); letter-spacing: -0.02em; }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); letter-spacing: -0.01em; }
h3 { font-size: 1.12rem; }

a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }

/* keyboard focus: an explicit accent ring — the browser default is faint on the
   dark surfaces. Mouse/touch clicks don't trigger :focus-visible, so it only
   shows for keyboard/AT users. */
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

code, .mono {
  font-family: var(--mono);
  font-size: 0.88em;
}
code {
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 0.08em 0.4em;
  color: #cdd9ee;
  white-space: nowrap;
}

pre {
  background: #0a0f1c;
  border: 1px solid var(--line);
  border-radius: var(--rad-s);
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.55;
}
pre code { background: none; border: none; padding: 0; white-space: pre; color: #c3d2ec; }

.c-kw  { color: #79b8ff; }
.c-cm  { color: #5b6c8c; font-style: italic; }
.c-num { color: #ffc861; }
.c-fn  { color: #3ddc97; }
.c-str { color: #b07bff; }

/* ── header / nav ─────────────────────────────────────────────────────────── */
.site-head {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--head-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg-0) 78%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
  z-index: 100;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-0); font-weight: 700; letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 28px; height: 28px; display: block;
  filter: drop-shadow(0 0 6px rgba(76,194,255,0.45));
}
.brand small { color: var(--text-2); font-weight: 500; }

.site-nav { margin-left: auto; display: flex; gap: 3px; }
.site-nav a {
  color: var(--text-1);
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 0.92rem;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text-0); background: var(--bg-2); text-decoration: none; }
.site-nav a.active { color: var(--acc); background: color-mix(in srgb, var(--acc) 12%, transparent); }

.nav-toggle { display: none; }

/* The full horizontal nav (brand + 8 verbose items) only fits above ~1100px.
   Below that — down through landscape tablets and small laptops — collapse it
   into the ☰ menu, so every nav link stays reachable instead of bleeding off
   the right edge. 1100px matches the site's primary story-layout breakpoint. */
@media (max-width: 1100px) {
  .nav-toggle {
    display: block; margin-left: auto;
    background: var(--bg-2); color: var(--text-0);
    border: 1px solid var(--line); border-radius: 8px;
    font-size: 1.1rem; padding: 4px 12px; cursor: pointer;
  }
  .site-nav {
    display: none;
    position: absolute; top: var(--head-h); right: 10px;
    flex-direction: column;
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: var(--rad-s);
    padding: 8px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  }
  .site-nav.open { display: flex; }
  /* comfortable tap targets in the dropdown menu (>=44px), where these links
     are the primary touch navigation — desktop keeps its denser 38px row */
  .site-nav a { padding: 11px 14px; }
}

main { padding-top: var(--head-h); }

/* ── hero ─────────────────────────────────────────────────────────────────── */
.hero {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(40px, 8vh, 90px) 24px 30px;
  text-align: left;
}
.hero .kicker {
  font-family: var(--mono);
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--acc);
}
.hero p.lead {
  max-width: 680px;
  font-size: 1.08rem;
  color: var(--text-1);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--line);
  color: var(--text-0);
  background: var(--bg-2);
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); border-color: var(--acc); }
.btn.primary {
  background: linear-gradient(135deg, #1b6dff 0%, #15a8e8 100%);
  border-color: transparent;
  box-shadow: 0 6px 26px rgba(27,109,255,0.35);
}

/* ── generic prose sections ──────────────────────────────────────────────── */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }
.prose { max-width: 820px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin: 26px 0;
}
.card {
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 1px solid var(--line-soft);
  border-radius: var(--rad);
  padding: 20px 22px;
}
.card h3 { margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.card p { margin: 0; font-size: 0.95rem; color: var(--text-1); }
.card .tag { margin-bottom: 10px; }

/* ── scroll story layout ─────────────────────────────────────────────────── */
.story {
  display: grid;
  /* viz gets the larger share — the diagram is the page's main content */
  grid-template-columns: minmax(280px, 1fr) minmax(560px, 2fr);
  gap: 32px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 24px;
}

/* both children explicitly share row 1 — otherwise sparse auto-placement puts
   the steps in row 2 and the viz column collapses to its own height, which
   silently kills position: sticky */
.story-steps { grid-column: 1; grid-row: 1; min-width: 0; }
.story-viz   { grid-column: 2; grid-row: 1; min-width: 0; }

.viz-sticky {
  position: sticky;
  /* vertically centred in the viewport; --viz-h is measured by story.js.
     Fallback (no JS / no svh support): pinned below the header. */
  top: calc(var(--head-h) + 14px);
  top: max(calc(var(--head-h) + 12px),
           calc(var(--head-h) + (100svh - var(--head-h) - var(--viz-h, 100svh)) / 2));
  padding: 14px;
  background: linear-gradient(180deg, rgba(17,26,43,0.65) 0%, rgba(12,17,29,0.65) 100%);
  border: 1px solid var(--line-soft);
  border-radius: var(--rad);
  backdrop-filter: blur(6px);
}
.viz-sticky svg { display: block; width: 100%; height: auto; }

.viz-caption {
  min-height: 44px;
  margin-top: 10px;
  padding: 8px 120px 8px 12px; /* right side leaves room for .viz-nav */
  font-size: 0.9rem;
  color: var(--text-1);
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
}
.viz-caption.swap > span:last-child { animation: capIn .4s ease; }
@keyframes capIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

/* chapter prev/next controls, injected by story.js */
.viz-nav {
  position: absolute;
  right: 16px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-2);
}
.viz-nav button {
  width: 27px; height: 24px;
  background: var(--bg-3); color: var(--text-1);
  border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; line-height: 1; font-size: 0.82rem;
  transition: border-color .15s ease, color .15s ease;
}
.viz-nav button:hover { color: #fff; border-color: var(--acc); }

/* fullscreen toggle for the diagram, injected by story.js */
.viz-expand {
  position: absolute; top: 10px; right: 10px; z-index: 6;
  width: 30px; height: 28px;
  background: var(--bg-3); color: var(--text-1);
  border: 1px solid var(--line); border-radius: 7px;
  cursor: pointer; font-size: 0.95rem; line-height: 1;
  transition: border-color .15s ease, color .15s ease;
}
.viz-expand:hover { color: #fff; border-color: var(--acc); }

body.viz-max { overflow: hidden; }
body.viz-max .viz-sticky {
  position: fixed; inset: 10px; z-index: 400;
  display: flex; flex-direction: column;
  background: rgba(7,10,18,0.98);
  box-shadow: 0 30px 90px rgba(0,0,0,0.6);
}
body.viz-max .viz-sticky svg { flex: 1 1 0; min-height: 0; width: 100%; }

/* thin reading-progress bar under the fixed header (story pages) */
.read-progress {
  position: fixed; top: var(--head-h); left: 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, var(--acc), var(--cipher));
  transform-origin: 0 50%; transform: scaleX(0);
  z-index: 99; pointer-events: none;
}
.viz-caption .dot {
  flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 10px var(--acc);
}

.step {
  min-height: 86vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 7vh 6px;
  opacity: 0.3;
  transform: translateY(16px);
  transition: opacity .5s ease, transform .5s ease;
}
.step.is-active { opacity: 1; transform: none; }

.step .step-num {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--acc);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.step h2, .step h3 { margin: 0 0 12px; }
.step p { margin: 0 0 12px; }
.step ul { margin: 0 0 12px; padding-left: 20px; }
.step li { margin-bottom: 6px; }
.step li::marker { color: var(--acc); }

.divider-banner {
  min-height: 40vh;
  display: flex; flex-direction: column; justify-content: center;
}
.divider-banner .rule {
  height: 1px;
  background: linear-gradient(90deg, var(--acc), transparent);
  margin-bottom: 18px;
}
.divider-banner h2 {
  font-size: clamp(1.9rem, 3.4vw, 2.7rem);
  margin: 0 0 10px;
}

/* ── story chapter spacing (desktop) ─────────────────────────────────────── */
/* Chapters get enough vertical space for smooth diagram transitions, while
   scrolling itself stays fully native: no wheel/key interception, no snap. */
@media (min-width: 1101px) and (prefers-reduced-motion: no-preference) {
  html:has(.story) .hero {
    min-height: calc(100vh - var(--head-h));
    min-height: calc(100svh - var(--head-h));
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
  }
  .step,
  .divider-banner {
    min-height: calc(100vh - var(--head-h));
    min-height: calc(100svh - var(--head-h));
    padding-top: 3vh;
    padding-bottom: 3vh;
  }
  html:has(.story) .story + section { padding-top: 28px; }
}

/* scroll hint under the hero actions (story pages) */
.scroll-cue {
  display: flex; align-items: center; gap: 10px;
  margin-top: 40px;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
}
.scroll-cue .chev { color: var(--acc); animation: cueBob 1.8s ease-in-out infinite; }
@keyframes cueBob {
  0%, 100% { transform: translateY(-2px); }
  50%      { transform: translateY(4px); }
}
@media (max-width: 1100px) { .scroll-cue { display: none; } }

/* small fact/warn boxes inside steps */
.note, .warn-box {
  border-radius: var(--rad-s);
  padding: 12px 14px;
  font-size: 0.92rem;
  margin: 12px 0;
  border: 1px solid;
}
.note      { background: rgba(76,194,255,0.06);  border-color: rgba(76,194,255,0.25); }
.warn-box  { background: rgba(255,107,129,0.07); border-color: rgba(255,107,129,0.3); }
.note b, .warn-box b { color: var(--text-0); }

/* enc/dec comparison rows inside steps */
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.duo .pane {
  border: 1px solid var(--line-soft);
  border-radius: var(--rad-s);
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--bg-1);
}
.duo .pane h4 {
  margin: 0 0 6px; font-size: 0.78rem; letter-spacing: 0.1em;
  text-transform: uppercase; font-family: var(--mono);
}
.duo .pane.enc h4 { color: var(--cipher); }
.duo .pane.dec h4 { color: var(--acc); }
.duo .pane p { margin: 0; }
@media (max-width: 520px) { .duo { grid-template-columns: 1fr; } }
/* narrow text column next to the large viz: stack the panes */
@media (min-width: 1101px) and (max-width: 1280px) { .duo { grid-template-columns: 1fr; } }

/* tags */
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid;
}
.tag.shared { color: var(--meta);   border-color: rgba(61,220,151,0.4);  background: rgba(61,220,151,0.08); }
.tag.enc    { color: var(--cipher); border-color: rgba(176,123,255,0.4); background: rgba(176,123,255,0.08); }
.tag.dec    { color: var(--acc);    border-color: rgba(76,194,255,0.4);  background: rgba(76,194,255,0.08); }
.tag.hw     { color: var(--key);    border-color: rgba(255,200,97,0.4);  background: rgba(255,200,97,0.08); }

/* ── responsive story: viz on top, steps below (phones + portrait tablets) ── */
@media (max-width: 1100px) {
  .story { display: block; }
  .story-viz {
    position: sticky;
    top: var(--head-h);
    z-index: 40;
  }
  .viz-sticky {
    position: static;
    border-radius: 0 0 var(--rad) var(--rad);
    padding: 8px;
    background: rgba(9,13,22,0.92);
  }
  .viz-caption { min-height: 36px; font-size: 0.82rem; margin-top: 6px; padding: 6px 100px 6px 8px; }
  .viz-nav { right: 10px; bottom: 10px; }
  .step { min-height: 72vh; padding-top: 4vh; }

  /* the inline diagram is too dense at phone/portrait-tablet width: drop only
     the per-block descriptive sub-lines (e.g. "Ibex core", "status_ctrl") and
     enlarge the block names. NVM-flash region labels, status LEDs and readouts
     are real content, not decoration — they stay. Full detail in fullscreen. */
  body:not(.viz-max) .story-viz svg .module .sub { display: none; }
  body:not(.viz-max) .story-viz svg .module text.title { font-size: 15px; }
  body:not(.viz-max) .story-viz svg text.readout { font-size: 15px; }
  body:not(.viz-max) .story-viz svg .pkt-label { font-size: 14px; }
}

/* ── fullscreen diagram on phones/tablets: fill the height and pan sideways ──
   The story-viz ancestor is a positioned, z-indexed element → it traps the
   fixed panel in its (z:40) stacking context, below the z:100 header. Drop
   that context while maxed so the panel (and its close button) sit on top. */
@media (max-width: 1100px) {
  body.viz-max .story-viz { position: static; z-index: auto; }
  body.viz-max .viz-sticky { overflow: auto; -webkit-overflow-scrolling: touch; }
  /* render the diagram as tall as the screen → big enough to read, the panel
     scrolls horizontally to reach the rest of it. An SVG with a viewBox ignores
     width:auto (it defaults to 100%), so width is derived from the height via
     --vb-ratio (numeric viewBox width/height), set per page by story.js. */
  body.viz-max .viz-sticky svg {
    flex: none;
    height: calc(100svh - 130px);
    width: calc((100svh - 130px) * var(--vb-ratio, 1.71));
    max-width: none;
  }
  body.viz-max .viz-expand { position: fixed; top: 18px; right: 18px; z-index: 401; }
}

/* =============================================================================
   SVG diagram language
   ============================================================================= */

svg .module rect.body {
  fill: #121a2c;
  stroke: #2a3954;
  stroke-width: 1.2;
  transition: fill .45s ease, stroke .45s ease, filter .45s ease;
}
svg .module text { fill: #93a3bf; transition: fill .45s ease; }
svg .module text.title { fill: #c6d2e6; font-weight: 600; font-size: 12.5px; }
svg .module .sub { font-size: 10px; fill: #5d6d8b; }

svg .module.on rect.body {
  fill: #16243f;
  stroke: var(--mod-color, var(--acc));
  filter: drop-shadow(0 0 9px color-mix(in srgb, var(--mod-color, var(--acc)) 55%, transparent));
}
svg .module.on text.title { fill: #ffffff; }
svg .module.on text { fill: #b9c7de; }

svg .module.dim rect.body { fill: #0e1422; stroke: #1c2538; }
svg .module.dim text { fill: #46546e; }
svg .module.dim text.title { fill: #5d6c88; }

/* external (outside SEC boundary) modules */
svg .module.ext rect.body { stroke-dasharray: 5 4; }

/* wires */
svg path.wire {
  fill: none;
  stroke: #243350;
  stroke-width: 1.6;
  transition: stroke .45s ease, filter .45s ease;
}
svg path.wire.ctrl { stroke-dasharray: 5 5; }
svg path.wire.lit {
  stroke: var(--wire-color, var(--acc));
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--wire-color, var(--acc)) 80%, transparent));
}

/* packets */
svg .pkt { filter: drop-shadow(0 0 6px currentColor); }
svg .pkt.plain  { color: var(--acc);    fill: var(--acc); }
svg .pkt.cipher { color: var(--cipher); fill: var(--cipher); }
svg .pkt.keyw   { color: var(--key);    fill: var(--key); }
svg .pkt.metaw  { color: var(--meta);   fill: var(--meta); }
svg .pkt.errw   { color: var(--err);    fill: var(--err); }

/* signal-name labels travelling with packets (spec: label) */
svg .pkt-label {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  paint-order: stroke;
  stroke: #070a12;
  stroke-width: 3px;
  stroke-linejoin: round;
}
svg .pkt-label.plain  { fill: var(--acc); }
svg .pkt-label.cipher { fill: var(--cipher); }
svg .pkt-label.keyw   { fill: var(--key); }
svg .pkt-label.metaw  { fill: var(--meta); }
svg .pkt-label.errw   { fill: var(--err); }

/* FIFO slots */
svg rect.slot {
  fill: #0d1525;
  stroke: #243350;
  stroke-width: 1;
  transition: fill .3s ease, stroke .3s ease;
}
svg rect.slot.full {
  fill: var(--slot-color, var(--acc));
  stroke: var(--slot-color, var(--acc));
  fill-opacity: 0.75;
  filter: drop-shadow(0 0 4px var(--slot-color, var(--acc)));
}

/* NVM regions */
svg rect.region {
  fill: #0e1626;
  stroke: #26344f;
  stroke-width: 1;
  transition: fill .45s ease, stroke .45s ease, filter .45s ease;
}
svg .region-label { font-size: 10.5px; fill: #6c7c99; font-family: var(--mono); }
svg rect.region.hot {
  stroke: var(--region-color, var(--key));
  fill: color-mix(in srgb, var(--region-color, var(--key)) 16%, #0e1626);
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--region-color, var(--key)) 50%, transparent));
}
svg rect.region.written {
  fill: color-mix(in srgb, var(--region-color, var(--key)) 26%, #0e1626);
  stroke: color-mix(in srgb, var(--region-color, var(--key)) 70%, #26344f);
}
svg rect.region.flash { animation: regionFlash 0.9s ease infinite alternate; }
@keyframes regionFlash {
  from { fill-opacity: 0.5; } to { fill-opacity: 1; }
}

/* status LEDs */
svg circle.led {
  fill: #1a2336;
  stroke: #2a3954;
  stroke-width: 1;
  transition: fill .3s ease, filter .3s ease;
}
svg circle.led.on {
  fill: var(--led-color, var(--ok));
  stroke: var(--led-color, var(--ok));
  filter: drop-shadow(0 0 5px var(--led-color, var(--ok)));
}
svg .led-label { font-size: 8.5px; fill: #5d6d8b; font-family: var(--mono); }

/* readouts (FSM state, counter value) */
svg text.readout {
  font-family: var(--mono);
  font-size: 12px;
  fill: var(--acc);
  transition: fill .3s ease;
}

/* boundary box */
svg rect.boundary {
  fill: rgba(13,19,33,0.45);
  stroke: #2c3c5c;
  stroke-width: 1.4;
  stroke-dasharray: 0;
}
svg text.boundary-label {
  font-family: var(--mono); font-size: 11px; fill: #58698a; letter-spacing: 0.12em;
}

/* irq bolt */
svg .irq { opacity: 0.18; transition: opacity .3s ease; }
svg .irq.on { opacity: 1; filter: drop-shadow(0 0 8px var(--warn)); }

/* ascon "processing" pulse */
svg .churn rect.body { animation: churnPulse 0.8s ease-in-out infinite alternate; }
@keyframes churnPulse {
  from { stroke-width: 1.2; } to { stroke-width: 3; }
}

/* =============================================================================
   tables (reference page)
   ============================================================================= */
.table-wrap { overflow-x: auto; margin: 18px 0; border: 1px solid var(--line-soft); border-radius: var(--rad-s); }
table.reg {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  min-width: 640px;
}
table.reg th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--bg-2);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.reg td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.reg tr:last-child td { border-bottom: none; }
table.reg tr:hover td { background: rgba(76,194,255,0.03); }
table.reg td.addr { font-family: var(--mono); color: var(--key); white-space: nowrap; }
table.reg td.rw { font-family: var(--mono); color: var(--text-2); white-space: nowrap; }
table.reg td .regname { font-family: var(--mono); color: var(--text-0); font-size: 0.86rem; }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 4px;
  vertical-align: 1px;
  white-space: nowrap;
}
.badge.verify { background: rgba(255,200,97,0.12); color: var(--warn); border: 1px solid rgba(255,200,97,0.35); }
.badge.ok     { background: rgba(61,220,151,0.1);  color: var(--ok);   border: 1px solid rgba(61,220,151,0.3); }
.badge.danger { background: rgba(255,107,129,0.1); color: var(--err);  border: 1px solid rgba(255,107,129,0.3); }

/* sticky in-page toc (reference + fsm pages) */
.docpage { display: grid; grid-template-columns: 210px 1fr; gap: 40px; max-width: 1180px; margin: 0 auto; padding: 30px 24px 80px; }
.toc { position: sticky; top: calc(var(--head-h) + 20px); align-self: start; font-size: 0.88rem; }
.toc a { display: block; color: var(--text-2); padding: 4px 0 4px 12px; border-left: 2px solid var(--line-soft); }
.toc a:hover { color: var(--acc); text-decoration: none; }
.toc a.here { color: var(--text-0); border-left-color: var(--acc); }
@media (max-width: 900px) { .docpage { grid-template-columns: 1fr; } .toc { display: none; } }

/* let the 1fr content column shrink below its content's min-content width, so
   wide children (tables in overflow-auto wraps, full-width inline SVGs) scroll
   or scale instead of forcing horizontal page overflow on narrow viewports */
.doc-body { min-width: 0; }
.doc-body section { scroll-margin-top: calc(var(--head-h) + 18px); margin-bottom: 54px; }

/* ── FSM page ────────────────────────────────────────────────────────────── */
.fsm-layout { max-width: 1340px; margin: 0 auto; padding: 24px; }
.fsm-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.fsm-controls button {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: all .15s ease;
}
.fsm-controls button:hover { color: var(--text-0); border-color: var(--acc); }
.fsm-controls button.sel { color: #fff; background: color-mix(in srgb, var(--acc) 22%, var(--bg-2)); border-color: var(--acc); }

.fsm-stage { display: grid; grid-template-columns: minmax(0, 7fr) minmax(280px, 3fr); gap: 20px; }
@media (max-width: 1100px) { .fsm-stage { grid-template-columns: 1fr; } }

.fsm-map {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--rad);
  padding: 10px;
}
.fsm-map svg { width: 100%; height: auto; display: block; }

.fsm-detail {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--rad);
  padding: 18px 20px;
  position: sticky;
  top: calc(var(--head-h) + 16px);
  align-self: start;
  min-height: 220px;
}
.fsm-detail h3 { font-family: var(--mono); font-size: 1rem; margin: 0 0 4px; color: var(--key); }
.fsm-detail .fsm-lane-tag { font-size: 0.75rem; color: var(--text-2); font-family: var(--mono); margin-bottom: 10px; }
.fsm-detail dl { margin: 12px 0 0; font-size: 0.9rem; }
.fsm-detail dt { color: var(--text-2); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; font-family: var(--mono); margin-top: 10px; }
.fsm-detail dd { margin: 2px 0 0; color: var(--text-1); }

/* FSM SVG nodes */
svg .fstate rect {
  fill: #121b2e;
  stroke: #2a3954;
  stroke-width: 1.1;
  cursor: pointer;
  transition: all .3s ease;
}
svg .fstate text { fill: #9fb0ca; font-family: var(--mono); font-size: 9.5px; pointer-events: none; }
svg .fstate:hover rect { stroke: var(--acc); }
svg .fstate.sel rect { stroke: var(--key); fill: #1c2740; filter: drop-shadow(0 0 7px rgba(255,200,97,0.4)); }
svg .fstate.sel text { fill: #fff; }
svg .fstate.path-on rect {
  stroke: var(--flow-color, var(--acc));
  fill: color-mix(in srgb, var(--flow-color, var(--acc)) 14%, #121b2e);
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--flow-color, var(--acc)) 45%, transparent));
}
svg .fstate.path-on text { fill: #e8eef9; }
svg path.fedge { fill: none; stroke: #243350; stroke-width: 1.3; transition: all .3s ease; marker-end: url(#arrh); }
svg path.fedge.path-on { stroke: var(--flow-color, var(--acc)); filter: drop-shadow(0 0 4px color-mix(in srgb, var(--flow-color, var(--acc)) 60%, transparent)); }
svg text.lane-title { font-family: var(--mono); font-size: 10px; fill: #51618233; fill: #516182; letter-spacing: 0.14em; }

/* ── footer ──────────────────────────────────────────────────────────────── */
.site-foot {
  margin-top: 80px;
  border-top: 1px solid var(--line-soft);
  padding: 30px 24px 44px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-2);
}
.site-foot a { color: var(--text-2); text-decoration: underline; }

/* enc-vs-dec comparison (crypto page).
   Desktop: a 3-column table. Mobile: stacked blocks where each row becomes its
   own labelled mini-card with explicit Encrypt / Decrypt sub-labels, so the
   meaning survives the collapse (a plain 1-col grid would lose which is which). */
.compare-section { max-width: 1180px; margin: 30px auto 0; padding: 0 24px; }
/* collapsible recap tables: default-closed so a long story page doesn't repeat
   itself, one click for readers who want the side-by-side */
details.compare-toggle { margin: 16px 0 0; }
details.compare-toggle > summary {
  cursor: pointer; color: var(--acc); font-size: 0.92rem;
  padding: 8px 0; list-style: none; user-select: none; width: fit-content;
}
details.compare-toggle > summary::-webkit-details-marker { display: none; }
details.compare-toggle > summary::before { content: "▸ "; }
details.compare-toggle[open] > summary::before { content: "▾ "; }
details.compare-toggle[open] > summary { color: var(--text-2); }
details.compare-toggle > summary:hover { color: var(--text-0); }
.compare2 {
  margin: 18px 0 0;
  border: 1px solid var(--line-soft); border-radius: var(--rad); overflow: hidden;
  font-size: 0.9rem;
}
.compare2 .crow { display: grid; grid-template-columns: 170px 1fr 1fr; gap: 1px; background: var(--line-soft); }
.compare2 .crow + .crow { margin-top: 1px; }
.compare2 .crow > div { background: var(--bg-1); padding: 12px 16px; }
.compare2 .crow.head > div { background: var(--bg-2); font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.compare2 .crow.head .cenc { color: var(--cipher); }
.compare2 .crow.head .cdec { color: var(--acc); }
.compare2 .ckey { color: var(--text-0); font-weight: 600; font-size: 0.86rem; }
.compare2 .cboth { grid-column: span 2; color: var(--meta); }
.compare2 .cl { display: none; }   /* inline Encrypt/Decrypt labels: mobile only */
@media (max-width: 760px) {
  .compare2 .crow { grid-template-columns: 1fr; gap: 0; }
  .compare2 .crow.head { display: none; }
  .compare2 .crow + .crow { margin-top: 0; }
  .compare2 .crow > div + div { border-top: 1px solid var(--line-soft); }
  .compare2 .crow { border-bottom: 2px solid var(--line); }
  .compare2 .ckey { background: var(--bg-2); font-family: var(--mono); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.08em; color: var(--text-2); }
  .compare2 .cboth { grid-column: auto; }
  .compare2 .cl { display: block; font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }
  .compare2 .cenc .cl { color: var(--cipher); }
  .compare2 .cdec .cl { color: var(--acc); }
  .compare2 .cboth .cl { color: var(--meta); }
}

/* long SVA assertions inside the verification security cards: keep them on one
   line but scroll within the card instead of bleeding past its padding */
#assertions .card code {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  padding: 6px 8px;
  -webkit-overflow-scrolling: touch;
}

/* reduced motion: kill loops, keep highlights */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  svg .churn rect.body, svg rect.region.flash { animation: none; }
  .step { transform: none; transition: opacity .4s ease; }
  .scroll-cue .chev { animation: none; }
  .viz-caption.swap > span:last-child { animation: none; }
}
