/* Stages (body[data-stage]):
   start   - the hero and one input, nothing else;
   working - conversation on the left, the result pane waiting on the right;
   ready   - a valid spec: graph, spec and summary tabs. */

:root {
  --bg: #faf9fc;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e75;
  --faint: #a3a3a9;
  --border: #e6e2ec;
  /* A violet next to the Leios site's, a touch bluer and softer. */
  --accent: #7434d4;
  --accent-soft: #f1eafc;
  --on-accent: #ffffff;
  --source: #e9f0ff;
  --source-line: #7aa2e8;
  --tx: #ffffff;
  --tx-line: #8a8a90;
  --conflict: #d8443a;
  --orphan: #d98b12;
  --user: #f1ecfa;
  --error: #fdecec;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 14px;
  --ink: #3a3a3e;
  --ink-line: #b9b9bd;
  --ink-faint: #c4c4c8;
  --contest: #c2413a;
  --up: #2f9e5b;
  --partial: #c98a1b;
  --y-string: #2f7d5b;
  --y-expr: #b0532a;
  --y-number: #9a5b00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --panel: #1d1d20;
    --text: #ececef;
    --muted: #a0a0a8;
    --faint: #6a6a72;
    --border: #313136;
    --accent: #b08af2;
    --accent-soft: #2b2240;
    --on-accent: #1a1022;
    --source: #1d2840;
    --source-line: #5a7fc4;
    --tx: #242428;
    --tx-line: #77777f;
    --conflict: #ff6b61;
    --orphan: #f0a43a;
    --user: #2a2340;
    --error: #3b2224;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35);
    --ink: #d4d4d8;
    --ink-line: #55555c;
    --ink-faint: #4a4a50;
    --contest: #ff7b70;
    --up: #4cc47f;
    --partial: #e0a23a;
    --y-string: #7fcf9f;
    --y-expr: #f0a070;
    --y-number: #e6b45a;
  }
}
:root[data-theme="dark"] {
  --bg: #141416;
  --panel: #1d1d20;
  --text: #ececef;
  --muted: #a0a0a8;
  --faint: #6a6a72;
  --border: #313136;
  --accent: #b08af2;
  --accent-soft: #2b2240;
  --on-accent: #1a1022;
  --source: #1d2840;
  --source-line: #5a7fc4;
  --tx: #242428;
  --tx-line: #77777f;
  --conflict: #ff6b61;
  --orphan: #f0a43a;
  --user: #2a2340;
  --error: #3b2224;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35);
  --ink: #d4d4d8;
  --ink-line: #55555c;
  --ink-faint: #4a4a50;
  --contest: #ff7b70;
  --up: #4cc47f;
  --partial: #e0a23a;
  --y-string: #7fcf9f;
  --y-expr: #f0a070;
  --y-number: #e6b45a;
  }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease), opacity 160ms;
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.quiet:hover { color: var(--text); }
button.icon { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Top bar: only once there is a conversation. */
.topbar {
  /* Above the result pane: the view transition gives it its own layer. */
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  view-transition-name: topbar;
}
.brand { display: flex; align-items: center; gap: 9px; border: none; background: none; padding: 2px 4px; font-weight: 650; font-size: 17px; letter-spacing: -0.01em; view-transition-name: logo; }
.wordmark { display: inline-flex; align-items: baseline; font-weight: 650; letter-spacing: -0.02em; line-height: 1; }
.brand .wordmark { font-size: 21px; }
/* The x of the wordmark is the Crossing mark: two strands that cross, one landing on the accent.
   It is one x-height tall and sits on the baseline (an inline SVG's baseline is its bottom edge). */
.wordmark .mark { width: 1.04ex; height: 1ex; margin: 0 0.05em 0 0.04em; overflow: visible; }
.mark .hub { fill: var(--accent); }
/* On the start page the logo is shown large above the tagline instead of in the top bar; the two share
   a view-transition name, so it moves between them when an experiment starts or the page returns. */
.hero-logo { margin: 0 0 18px; font-size: 64px; color: var(--text); view-transition-name: logo; }
body[data-stage="start"] .brand { visibility: hidden; view-transition-name: none; }
@media (max-width: 520px) { .hero-logo { font-size: 48px; margin-bottom: 12px; } }
body[data-stage="start"] .topbar { border-bottom-color: transparent; }
body[data-stage="start"] #new { visibility: hidden; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.topnav { display: flex; align-items: center; gap: 2px; margin-right: 6px; padding-right: 8px; border-right: 1px solid var(--border); }
.topnav a, .topnav button { transition: color 160ms var(--ease), background 160ms var(--ease); }
.topnav a:hover, .topnav button:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }

/* Network picker: one network for now, the rest announced. */
.network { position: relative; }
.network-button { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.network-button .live, .relay-list .live { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; transition: background 300ms var(--ease); }
.live[data-state="up"] { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 18%, transparent); }
.live[data-state="partial"] { background: var(--partial); }
.live[data-state="down"] { background: var(--contest); }
.relay-list { list-style: none; margin: 0 0 4px; padding: 0 10px; display: grid; gap: 7px; font-size: 13px; }
.relay-list li { display: flex; align-items: center; gap: 8px; }
.relay-list li { color: var(--muted); }
.relay-state { margin-left: auto; padding-left: 12px; color: var(--faint); font-size: 12px; }
.network-button svg { color: var(--faint); transition: transform 200ms var(--ease); }
.network-button[aria-expanded="true"] svg { transform: rotate(180deg); }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  min-width: 260px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: menu-in 160ms var(--ease);
}
.menu[hidden], .shapes[hidden], .pasted[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.97) translateY(-4px); } }
.menu-item { display: grid; gap: 2px; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 7px; }
.menu-item:hover:not(:disabled) { background: var(--bg); }
.menu-item strong { font-weight: 600; font-size: 13.5px; }
.menu-item span { color: var(--muted); font-size: 12px; }
.menu-soon { padding: 8px 10px 6px; margin-top: 4px; border-top: 1px solid var(--border); color: var(--faint); font-size: 12.5px; }

main { flex: 1; min-height: 0; display: grid; }
main > section { min-width: 0; }

/* Start: hero over one centred input. */
body[data-stage="start"] main {
  grid-template-columns: minmax(0, 680px);
  grid-auto-rows: max-content;
  justify-content: center;
  /* Centred while it fits; on a short or narrow screen it scrolls from the top. */
  align-content: safe center;
  overflow-y: auto;
  padding: 24px 16px max(12px, 8vh - 40px);
  gap: 22px;
}
.hero { text-align: center; }

/* The author, muted, under the start screen and the spec reference only. */
.site-foot { padding: 0 16px 18px; text-align: center; font-size: 12px; color: var(--faint); }
.site-foot a { color: inherit; text-decoration: none; transition: color 160ms var(--ease); }
.site-foot a:hover, .site-foot a:focus-visible { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
body[data-stage="start"] .site-foot { padding: 0; margin-top: -8px; }
body:not([data-stage="start"]):not(.doc-page) .site-foot { display: none; }
.doc-page .site-foot { margin-top: -56px; }

/* The building blocks, drawn by the graph renderer, above the input. */
/* Wider than the input column, centred on it, so the drawings have room. */
.shapes {
  --wide: min(860px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: var(--wide);
  margin: 26px 0 0 50%;
  translate: -50% 0;
  text-align: left;
}
.shape {
  display: grid;
  gap: 2px;
  padding: 10px 12px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  text-align: left;
  animation: rise 420ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 40ms + 80ms);
}
/* A pasted spec with problems, in place of the example cards. */
.pasted {
  --wide: min(760px, calc(100vw - 32px));
  width: var(--wide);
  margin: 26px 0 0 50%;
  translate: -50% 0;
  text-align: left;
}
.pasted-card {
  color: var(--text);
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--conflict) 45%, var(--border));
  border-radius: 12px;
  background: var(--panel);
  animation: rise 360ms var(--ease) backwards;
}
.pasted-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pasted-head strong { font-size: 14px; font-weight: 600; color: var(--conflict); }
.pasted-count { font-size: 12px; color: var(--muted); }
.pasted-spec {
  margin: 0;
  max-height: 300px;
  overflow: auto;
  padding: 8px 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 3%, var(--panel));
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  counter-reset: line;
}
.pasted-line { display: block; padding: 0 12px 0 44px; position: relative; white-space: pre; transition: background 200ms var(--ease); }
.pasted-line::before {
  counter-increment: line;
  content: counter(line);
  position: absolute;
  left: 0;
  width: 32px;
  text-align: right;
  color: var(--faint);
}
.pasted-line.bad { background: color-mix(in srgb, var(--conflict) 12%, transparent); box-shadow: inset 3px 0 0 var(--conflict); }
.pasted-line.bad::before { color: var(--conflict); }
.pasted-why { display: block; padding: 2px 12px 4px 44px; color: var(--conflict); font-family: inherit; white-space: pre-wrap; font-size: 11.5px; }
.pasted-rest { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--conflict); display: grid; gap: 2px; }
.pasted-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pasted-actions button { font-size: 13px; }
.msg.pasted-msg { padding: 0; background: none; border: 0; max-width: 100%; }
.msg.pasted-msg .pasted-spec { max-height: 220px; }
.shape { transition: border-color 240ms var(--ease), transform 240ms var(--ease), box-shadow 240ms var(--ease); }
.shape:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); transform: translateY(-2px); box-shadow: 0 6px 18px -10px color-mix(in srgb, var(--accent) 60%, transparent); }
.shape .mini { height: 92px; display: grid; place-items: center; margin-bottom: 8px; }
.shape .mini svg { width: 100%; height: 92px; }
.shape .mini svg text { display: none; }
.shape .mini svg .group-label { display: none; }
.shape strong { font-size: 13.5px; font-weight: 600; }
.shape span { font-size: 12px; color: var(--muted); line-height: 1.35; }
/* The flow: each column's edges draw in the accent colour once the column
   before has arrived, then the transactions they reach light up. Leaving
   the card fades it all back at once. */
.shape { --step: 260ms; --run: 620ms; }
.shape .mini .flow {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.9;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: opacity 260ms var(--ease), stroke-dashoffset 0s linear 260ms;
}
.shape:hover .mini .flow {
  opacity: 1;
  stroke-dashoffset: 0;
  transition:
    opacity 0s,
    stroke-dashoffset var(--run) cubic-bezier(0.45, 0, 0.25, 1) calc((var(--column, 1) - 1) * var(--step));
}
.shape .mini .box, .shape .mini .utxo, .shape .mini .relay-pin { transition: stroke 260ms var(--ease), fill 260ms var(--ease); }
.shape:hover .mini .node-source .utxo { stroke: var(--accent); fill: var(--accent); transition-delay: 0ms; }
.shape:hover .mini .node-tx .box,
.shape:hover .mini .node-tx .utxo,
.shape:hover .mini .relay-pin {
  stroke: var(--accent);
  transition-duration: 320ms;
  transition-delay: calc((var(--column, 1) - 1) * var(--step) + var(--run) * 0.7);
}
.shape:hover .mini .node-tx .utxo.spent { fill: var(--accent); }
.modifiers { margin: 14px auto 0; max-width: 600px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.modifiers code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); }
.modifiers a { color: var(--accent); text-decoration: none; white-space: nowrap; margin-left: 4px; }
.modifiers a::after { content: " →"; }
@media (max-width: 720px) {
  .shapes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.tagline { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.015em; color: var(--text); }
.subline { max-width: 560px; margin: 8px auto 0; color: var(--muted); font-size: 15px; line-height: 1.45; text-wrap: balance; }
body:not([data-stage="start"]) .hero { display: none; }

/* The site's totals: a quiet pill under the subline, numbers that roll up. */
.tally {
  display: inline-flex; align-items: center; gap: 8px; margin: 14px auto 0;
  padding: 4px 12px 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 12.5px; line-height: 1.4;
  animation: rise 420ms var(--ease) backwards;
}
.tally[hidden] { display: none; }
.tally-items { display: inline-flex; flex-wrap: wrap; justify-content: center; column-gap: 10px; }
.tally-items > span + span::before { content: "·"; margin-right: 10px; color: var(--faint); }
.tally b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tally-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); animation: tally-pulse 2.4s var(--ease) infinite; }
@keyframes tally-pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .tally, .tally-dot { animation: none; } }

/* Not found: an address that names no experiment saved in this browser. */
body[data-missing] .hero, body[data-missing] .composer { display: none; }
.missing { display: grid; justify-items: center; gap: 10px; text-align: center; animation: rise 420ms var(--ease) backwards; }
.missing[hidden] { display: none; }
.missing h1 { margin: 6px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -0.015em; }
.missing p { max-width: 520px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; text-wrap: pretty; }
.missing p code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); overflow-wrap: anywhere; }
.missing-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.missing-start { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.missing-graph { overflow: visible; }
.mg-edge { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; }
.mg-edge.is-lost { stroke: var(--faint); stroke-dasharray: 2 5; }
.mg-tx { fill: var(--accent); }
.mg-utxo { fill: var(--panel); stroke: var(--muted); stroke-width: 1.6; }
.mg-missing { fill: none; stroke: var(--faint); stroke-width: 1.6; stroke-dasharray: 3 3; transform-box: fill-box; transform-origin: center; animation: mg-spin 9s linear infinite; }
.mg-mark { fill: var(--muted); font: 600 11px ui-sans-serif, system-ui, sans-serif; text-anchor: middle; }
@keyframes mg-spin { to { rotate: 1turn; } }
@media (prefers-reduced-motion: reduce) { .missing, .mg-missing { animation: none; } }
body[data-stage="start"] .result,
body[data-stage="start"] .log { display: none; }

/* Working and ready: conversation left, result right. */
body:not([data-stage="start"]) main { grid-template-columns: clamp(300px, 28vw, 400px) minmax(0, 1fr); }
@media (max-width: 860px) {
  body:not([data-stage="start"]) main { grid-template-columns: 1fr; grid-template-rows: minmax(320px, auto) minmax(420px, 1fr); }
}

.chat { display: flex; flex-direction: column; min-height: 0; }
body:not([data-stage="start"]) .chat { border-right: 1px solid var(--border); }
.log { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 10px; }

.composer {
  view-transition-name: composer;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 10px 8px 14px;
  transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease);
}
.composer:focus-within { border-color: var(--accent); }
body:not([data-stage="start"]) .composer { margin: 10px 16px 16px; }
.composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 4px 0;
}
body[data-stage="start"] .composer textarea { font-size: 17px; min-height: 84px; }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; gap: 8px; }

/* One button: a microphone while the input is empty, an arrow once there is
   text. The two glyphs share the slot and swap with a blur and scale. */
.action { margin-left: auto; position: relative; flex: none; color: var(--text); }
.action .glyph {
  grid-area: 1 / 1;
  transition: opacity 250ms ease-in-out, transform 250ms ease-in-out, filter 250ms ease-in-out;
}
.action[data-mode="send"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.action[data-mode="send"].empty:not(.busy) { background: var(--panel); border-color: var(--border); color: var(--faint); }
.action[data-mode="send"] .mic,
.action[data-mode="mic"] .arrow { opacity: 0; transform: scale(0.6); filter: blur(2px); }
.action.busy .arrow { animation: pulse 1s var(--ease) infinite; }
.action.listening { color: var(--contest); border-color: var(--contest); animation: breathe 1.4s ease-in-out infinite; }

/* The rotating example under the input, on the start screen only. */
.example {
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
  border: none;
  background: none;
  padding: 4px 2px;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
}
.example-label { color: var(--accent); font-weight: 600; flex: none; }
.example-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: opacity 280ms var(--ease), transform 280ms var(--ease); }
.example-text.out { opacity: 0; transform: translateY(6px); }
.example:hover .example-text { color: var(--text); }
body:not([data-stage="start"]) .example { display: none; }

/* Messages. */
.msg { padding: 9px 13px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; animation: rise 320ms var(--ease) both; }
.msg.user { background: var(--user); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.model { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.note { color: var(--muted); font-size: 13px; padding: 0 4px; }
.msg.note summary { cursor: pointer; }
.msg.note pre { white-space: pre-wrap; font-size: 12px; margin: 6px 0 0; }
.msg.note ul { margin: 6px 0 0; padding-left: 18px; font-size: 12px; display: grid; gap: 4px; }
.msg.note.warn { border-left: 2px solid var(--partial); padding-left: 10px; }
.msg.error { background: var(--error); }
.msg.budget { background: var(--panel); border: 1px solid var(--border); color: var(--muted); font-size: 14px; white-space: normal; }
.msg.budget strong { color: var(--text); font-weight: 600; }
/* Only shown with the budget message: quiet, in the page's own button style. */
.sponsor {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 13px; text-decoration: none;
  animation: sponsor-in 420ms var(--ease) 240ms both;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease);
}
.sponsor svg { fill: var(--accent); transition: transform 220ms var(--ease); }
.sponsor:hover, .sponsor:focus-visible { color: var(--text); border-color: var(--faint); background: var(--accent-soft); }
.sponsor:hover svg { transform: scale(1.15); }
@keyframes sponsor-in { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .sponsor, .sponsor svg { animation: none; transition: none; } }
.msg .options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.msg.model.streaming:empty::after { content: ""; display: inline-block; width: 28px; height: 8px; background: radial-gradient(circle, var(--faint) 3px, transparent 3.5px) 0 50% / 10px 8px repeat-x; animation: dots 1s steps(4) infinite; }

/* Result pane. */
.result { display: flex; flex-direction: column; min-height: 0; view-transition-name: result; }
.placeholder { flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
body[data-stage="ready"] .placeholder { display: none; }
.placeholder .idle, .placeholder.is-idle .drawing { display: none; }
.placeholder.is-idle .idle { display: block; }
.placeholder.is-idle .build-graph { opacity: 0.35; }
.placeholder.is-idle .build-graph * { animation: none !important; }
body:not([data-stage="ready"]) .tabs,
body:not([data-stage="ready"]) .tab { display: none; }
/* Waiting for a spec: a small UTxO graph that builds itself left to right
   (dots are transactions, rings are outputs), holds, fades, and starts over. */
.build-graph { overflow: visible; }
.build-graph > * { animation: build 2.8s var(--ease) infinite both; animation-delay: calc(var(--i) * 140ms); }
.bg-edge { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 1; }
.bg-utxo { fill: var(--panel); stroke: var(--muted); stroke-width: 1.6; transform-box: fill-box; transform-origin: center; }
.bg-tx { fill: var(--text); transform-box: fill-box; transform-origin: center; }
@keyframes build {
  0% { opacity: 0; stroke-dashoffset: 1; transform: scale(0.4); }
  14% { opacity: 1; stroke-dashoffset: 0; transform: scale(1); }
  72% { opacity: 1; stroke-dashoffset: 0; transform: scale(1); }
  88%, 100% { opacity: 0; stroke-dashoffset: 0; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .build-graph > * { animation: none; opacity: 0.7; }
}

.tabs { display: flex; align-items: center; gap: 2px; padding: 10px 16px 0; border-bottom: 1px solid var(--border); }
.tabs button[role="tab"] { border: none; background: none; border-radius: 0; padding: 8px 12px; color: var(--muted); box-shadow: inset 0 -2px 0 transparent; transition: color 160ms, box-shadow 200ms var(--ease); }
.tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.budget { margin-left: auto; font-size: 12px; color: var(--muted); }
.tabs { position: relative; z-index: 5; }
/* Run: one large button at the bottom right of the result, on every tab. */
.result { position: relative; }
.run-dock[hidden] { display: none; }
.run-dock { animation: rise 260ms var(--ease) both; position: absolute; right: 26px; bottom: 46px; z-index: 6; display: flex; flex-direction: column; align-items: flex-end; }
.run {
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 10px 28px -10px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease), filter 180ms;
}
.run.running {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  transition: background 320ms var(--ease), color 320ms var(--ease), transform 180ms var(--ease);
}
.run-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: waiting-dot 1.6s var(--ease) infinite; }
@keyframes waiting-dot { 50% { opacity: 0.35; transform: scale(0.8); } }
@media (prefers-reduced-motion: reduce) { .run-dot { animation: none; } }
.run span { display: inline-block; transition: transform 200ms var(--ease); }
.run:hover { transform: translateY(-1px); box-shadow: 0 14px 32px -10px color-mix(in srgb, var(--accent) 80%, transparent); }
.run:hover span { transform: translateX(3px); }
.run:active { transform: translateY(0); }
.run:hover { filter: brightness(1.08); }
.run-note { margin: 12px 0 10px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 12.5px; }
.run-start { width: 100%; padding: 8px; border-radius: 8px; }
.run-funds { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.run-events { margin: 10px 0; padding-left: 18px; display: grid; gap: 4px; font-size: 12.5px; }
.run-events li::marker { color: var(--muted); font-weight: 400; }
.run-start:disabled { opacity: 0.55; cursor: not-allowed; }
.run-start:enabled:not(.run-close) { border: none; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 16px; animation: fade 260ms var(--ease) both; }
.tab[hidden] { display: none; }
.graph-wrap { position: relative; flex: 1; min-height: 300px; display: flex; }
.graph { flex: 1; min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); display: flex; flex-direction: column; }
.graph-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; cursor: grab; touch-action: none; user-select: none; }
.graph-stage.dragging { cursor: grabbing; }
.graph-stage svg { display: block; width: 100%; height: 100%; }
.graph .note { padding: 6px 12px 8px; margin: 0; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--border); }
.graph-controls { position: absolute; top: 10px; right: 10px; display: grid; gap: 4px; }
.graph-controls button { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 8px; font-size: 15px; line-height: 1; color: var(--muted); background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); }
.graph-controls button:hover { color: var(--text); }
.graph-tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  max-width: 300px;
  display: grid;
  gap: 3px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--muted);
  pointer-events: none;
  animation: fade 140ms var(--ease);
}
.graph-tip[hidden] { display: none; }
.graph-tip strong { color: var(--text); font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
/* The legend floats in a corner of the graph instead of taking a row. */
.legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  /* Clear of the Run button in the bottom right; three items to a row. */
  max-width: calc(100% - 280px);
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  gap: 4px 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(6px);
  font-size: 11.5px;
  color: var(--muted);
  pointer-events: none;
}
.sw { display: inline-block; width: 14px; height: 10px; margin-right: 5px; border-radius: 3px; vertical-align: -1px; }
.sw.spent { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); vertical-align: 0; }
.sw.unspent { width: 8px; height: 8px; border-radius: 50%; border: 1.2px solid var(--ink); vertical-align: 0; }
.sw.tx { background: var(--panel); border: 1px solid var(--ink-line); }
.sw.conflict { width: 9px; height: 9px; border-radius: 50%; background: var(--contest); vertical-align: 0; }
.sw.orphan { border: 1px dashed var(--ink-line); }
.sw.relay { width: auto; height: auto; font-style: normal; color: var(--muted); vertical-align: 0; }

/* The spec editor: a transparent textarea over its highlighted copy. Both
   share font, padding and wrapping so every character lines up. */
.editor { position: relative; flex: 1; min-height: 300px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; }
.editor:focus-within { border-color: var(--accent); }
.editor pre, #spec {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}
.editor pre { pointer-events: none; color: var(--text); }
#spec { resize: none; border: none; outline: none; background: transparent; color: transparent; caret-color: var(--text); }
/* See-through, so the highlighted text underneath stays readable. */
#spec::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); color: transparent; }
.yaml .y-key { color: var(--accent); }
.yaml .y-string { color: var(--y-string); }
.yaml .y-expr { color: var(--y-expr); }
.yaml .y-number, .yaml .y-keyword { color: var(--y-number); }
.yaml .y-comment { color: var(--faint); font-style: italic; }

/* The result's bottom edge lines up with the composer's (its 16px margin). */
body:not([data-stage="start"]) .tab { padding-bottom: 16px; }
.spec-buttons { display: flex; gap: 8px; align-items: flex-start; padding-top: 10px; min-height: 30px; }
#spec-status { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }
/* Copy and download, at the editor's top right. */
.editor-tools { position: absolute; top: 8px; right: 14px; z-index: 2; display: flex; gap: 4px; }
.icon-button { position: relative; width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 8px; color: var(--muted); background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); transition: color 160ms, background 160ms; }
.icon-button:hover { color: var(--text); }
.icon-button svg { grid-area: 1 / 1; transition: opacity 180ms var(--ease), transform 220ms var(--ease); }
#copy .i-done { opacity: 0; transform: scale(0.5); color: var(--up); }
#copy.copied .i-copy { opacity: 0; transform: scale(0.5); }
#copy.copied .i-done { opacity: 1; transform: scale(1); }
/* Lines the check found wrong, behind the highlighted text. */
.spec-marks { position: absolute; inset: 0; overflow: hidden; pointer-events: none; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.spec-marks i { position: absolute; left: 0; right: 0; height: 1.5em; top: calc(12px + var(--line) * 1.5em); background: color-mix(in srgb, var(--contest) 14%, transparent); box-shadow: inset 3px 0 0 var(--contest); animation: fade 200ms var(--ease) both; }
/* The automatic check's verdict: a green tick or a red cross. */
.spec-mark { width: 20px; height: 20px; flex: none; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--faint); transform: scale(0); transition: transform 220ms var(--ease), background 200ms; }
.spec-mark svg { grid-area: 1 / 1; opacity: 0; transition: opacity 160ms; }
.spec-mark[data-state="checking"] { transform: scale(0.6); background: var(--faint); }
.spec-mark[data-state="ok"] { transform: scale(1); background: var(--up); }
.spec-mark[data-state="ok"] .m-ok { opacity: 1; }
.spec-mark[data-state="bad"] { transform: scale(1); background: var(--contest); }
.spec-mark[data-state="bad"] .m-bad { opacity: 1; }
#summary h3 { margin: 4px 0; }
#summary ul { padding-left: 20px; }
#summary .hash { font: 12px ui-monospace, monospace; color: var(--muted); overflow-wrap: anywhere; }

/* Graph: monochrome; contested outputs are the only accented marks.
   Nodes and edges fade in column by column (--column set per node). */
svg text { fill: var(--text); font: 12px system-ui, sans-serif; }
svg text.amount { fill: var(--muted); font-size: 10.5px; }
svg text.relay { fill: var(--muted); font-size: 10.5px; letter-spacing: 0.01em; }
svg .box { fill: var(--panel); stroke: var(--ink-line); stroke-width: 1; }
svg .orphan .box { stroke-dasharray: 4 3; }
svg .orphan .label { fill: var(--muted); }
svg .edge { stroke: var(--ink-faint); stroke-width: 1.1; fill: none; }
svg .edge.conflict { stroke: var(--contest); stroke-width: 1.5; }
svg .edge.reference { stroke-dasharray: 3 3; }
svg .utxo { stroke: var(--ink); stroke-width: 1.2; }
svg .utxo.spent { fill: var(--ink); }
svg .utxo.unspent { fill: var(--panel); }
svg .utxo.contested { fill: var(--contest); stroke: var(--panel); stroke-width: 1.5; }
svg .group-label { fill: var(--muted); font-size: 11px; letter-spacing: 0.02em; }
svg .node-source, svg .node-tx, svg .edge { animation: fade 420ms var(--ease) both; animation-delay: calc(var(--column, 0) * 45ms); }

/* A run on the graph: each box takes its transaction's state. Colours ease
   in, and a tx waiting for a block breathes gently. */
svg .node-tx .box, svg .node-source .utxo { transition: stroke 480ms var(--ease), fill 480ms var(--ease), stroke-width 480ms var(--ease); }
svg [data-run] .box { stroke-dasharray: none; }
svg [data-run="queued"] .box { stroke-dasharray: 3 3; }
svg [data-run="sending"] .box { stroke: var(--accent); }
svg [data-run="accepted"] .box {
  stroke: var(--accent);
  stroke-width: 1.6;
  fill: color-mix(in srgb, var(--accent) 7%, var(--panel));
  animation: waiting 1.8s var(--ease) infinite;
}
svg [data-run="landed"] .box { stroke: var(--up); stroke-width: 1.6; fill: color-mix(in srgb, var(--up) 10%, var(--panel)); }
svg [data-run="rejected"] .box { stroke: var(--contest); stroke-width: 1.6; fill: color-mix(in srgb, var(--contest) 9%, var(--panel)); }
svg [data-run="dropped"] .box { stroke: var(--partial); stroke-width: 1.6; fill: color-mix(in srgb, var(--partial) 9%, var(--panel)); }
svg [data-run="rejected"] .label { fill: var(--contest); }
svg .node-source[data-run="landed"] .utxo { stroke: var(--up); fill: var(--up); }
svg .node-source[data-run="accepted"] .utxo { stroke: var(--accent); fill: var(--accent); }
svg .relay-dot { fill: none; stroke: var(--ink-line); stroke-width: 1; transition: fill 400ms var(--ease), stroke 400ms var(--ease); }
svg .relay-dot.is-mempool { fill: var(--accent); stroke: var(--accent); }
svg .relay-dot.is-ledger { fill: var(--up); stroke: var(--up); }
svg .relay-dot.is-rejected { fill: var(--contest); stroke: var(--contest); }
svg .relay-dot.is-dropped { fill: none; stroke: var(--contest); stroke-width: 1.4; }
.relay-steps { display: flex; gap: 7px; align-items: baseline; }
.relay-steps .relay-chip { flex: none; transform: translateY(-1px); }
.relay-chip { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--ink-line); }
.relay-chip.is-mempool { background: var(--accent); border-color: var(--accent); }
.relay-chip.is-ledger { background: var(--up); border-color: var(--up); }
.relay-chip.is-rejected { background: var(--contest); border-color: var(--contest); }
.relay-chip.is-dropped { border-color: var(--contest); }
svg .run-link { cursor: pointer; animation: fade 320ms var(--ease) both; }
svg .run-link circle { fill: var(--panel); stroke: var(--ink-line); stroke-width: 1; transition: fill 160ms var(--ease), stroke 160ms var(--ease); }
svg .run-link path { fill: none; stroke: var(--muted); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; transition: stroke 160ms var(--ease); }
svg .run-link:hover circle { fill: var(--accent); stroke: var(--accent); }
svg .run-link:hover path { stroke: var(--on-accent); }
.run-links { margin: 6px 0; font-size: 12.5px; color: var(--muted); }
.run-links a { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; text-decoration: none; }
.run-links a:hover { text-decoration: underline; }
.legend [hidden] { display: none; }
@media (max-width: 900px) { .legend { grid-template-columns: repeat(2, auto); max-width: calc(100% - 20px); bottom: 64px; } }
.sw.run-accepted { border: 1.6px solid var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); }
.sw.run-landed { border: 1.6px solid var(--up); background: color-mix(in srgb, var(--up) 10%, var(--panel)); }
.sw.run-rejected { border: 1.6px solid var(--contest); background: color-mix(in srgb, var(--contest) 9%, var(--panel)); }
.sw.run-dropped { border: 1.6px solid var(--partial); background: color-mix(in srgb, var(--partial) 9%, var(--panel)); }
@keyframes waiting { 50% { stroke-opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  svg [data-run="accepted"] .box { animation: none; }
  svg .node-tx .box, svg .node-source .utxo { transition: none; }
}

/* Details of one transaction or funding output: a panel that slides in over
   the right of the graph, without resizing it. */
.detail {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 66px;
  z-index: 5;
  width: min(360px, calc(100% - 20px));
  overflow-y: auto;
  padding: 14px 16px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 320ms var(--ease), transform 400ms var(--ease);
}
.detail.open { opacity: 1; transform: none; }
.detail[hidden] { display: none; }
.detail header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.detail-title { display: grid; gap: 3px; min-width: 0; }
.detail-title strong { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.detail-title > span:not(.detail-badge) { color: var(--muted); font-size: 12px; }
.detail-badge { justify-self: start; margin-top: 3px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--bg); color: var(--muted); transition: background 320ms var(--ease), color 320ms var(--ease); }
.detail-badge.is-accepted, .detail-badge.is-sending { background: var(--accent-soft); color: var(--accent); }
.detail-badge.is-landed { background: color-mix(in srgb, var(--up) 14%, var(--panel)); color: var(--up); }
.detail-badge.is-rejected { background: color-mix(in srgb, var(--contest) 14%, var(--panel)); color: var(--contest); }
.detail-badge.is-dropped { background: color-mix(in srgb, var(--partial) 16%, var(--panel)); color: var(--partial); }
.detail-nav { display: flex; gap: 2px; flex-shrink: 0; }
.detail-nav button { width: 28px; height: 28px; padding: 0; border: none; border-radius: 7px; background: none; color: var(--muted); font-size: 17px; line-height: 1; transition: background 160ms var(--ease), color 160ms var(--ease); }
.detail-nav button:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.detail-nav button:disabled { opacity: 0.35; }
.detail section { padding: 10px 0 2px; border-top: 1px solid var(--border); margin-top: 10px; display: grid; gap: 6px; }
.detail h4 { margin: 0 0 2px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.detail-row { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.detail-label { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.detail-value { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; }
.detail-value a, .detail-value code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.detail-value a { color: var(--accent); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }
.detail-race { color: var(--muted); font-size: 12px; }
.detail-muted { margin: 0; color: var(--muted); }
.chip { padding: 1px 7px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; transition: border-color 160ms var(--ease), color 160ms var(--ease); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.detail-copy { padding: 0 4px; border: none; background: none; color: var(--faint); font-size: 13px; transition: color 160ms var(--ease); }
.detail-copy:hover { color: var(--text); }
.detail-send { padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; display: grid; gap: 4px; transition: border-color 320ms var(--ease); }
.detail-send.is-accepted { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.detail-send.is-rejected { border-color: color-mix(in srgb, var(--contest) 45%, var(--border)); }
.detail-send-head { display: flex; justify-content: space-between; gap: 8px; }
.detail-send-head span { color: var(--muted); font-size: 12px; }
.detail-send.is-rejected .detail-send-head span { color: var(--contest); }
.detail-send p { margin: 0; }
.detail-send summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.detail-send pre { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11.5px; color: var(--muted); }
svg .selected .box { stroke: var(--accent); stroke-width: 2.2; }
svg .node-source.selected .utxo { stroke: var(--accent); stroke-width: 2.5; }
svg .node-tx, svg .node-source { cursor: pointer; }
@media (max-width: 720px) { .detail { left: 10px; width: auto; } }
@media (prefers-reduced-motion: reduce) { .detail { transition: none; transform: none; } }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { 0%, 100% { transform: scale(0.8); opacity: 0.5; } 50% { transform: scale(1); opacity: 1; } }
@keyframes breathe { 50% { box-shadow: 0 0 0 6px rgb(216 68 58 / 0.15); } }
@keyframes dots { from { width: 0; } to { width: 28px; } }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: 280ms; animation-timing-function: var(--ease); }
::view-transition-group(composer), ::view-transition-group(logo), ::view-transition-group(result) { animation-duration: 420ms; animation-timing-function: var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
}

/* ---- Spec reference page ---------------------------------------------------- */

a.quiet-link, .topbar a.quiet-link { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
a.quiet-link:hover { color: var(--text); }
a.brand { color: inherit; text-decoration: none; }
body.doc-page { display: block; overflow: auto; height: auto; min-height: 100vh; }
.doc-page .topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); }
.doc-layout { display: grid; grid-template-columns: 200px minmax(0, 760px); gap: 48px; justify-content: center; padding: 32px 24px 96px; }
.doc-layout.single { grid-template-columns: minmax(0, 760px); }
.toc { position: sticky; top: 76px; align-self: start; font-size: 13.5px; }
.toc-title { font-weight: 600; margin: 0 0 10px; }
.toc-title span { color: var(--faint); font-weight: 400; margin-left: 4px; }
.toc ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); }
.doc { line-height: 1.6; font-size: 15px; }
.doc h1 { font-size: 30px; letter-spacing: -0.02em; margin: 0 0 12px; }
.doc h2 { font-size: 21px; letter-spacing: -0.01em; margin: 48px 0 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.doc h3 { font-size: 15.5px; margin: 26px 0 8px; }
.doc section, .doc h3 { scroll-margin-top: 64px; }
.doc .lede { font-size: 17px; color: var(--text); }
.doc .doc-note { color: var(--muted); font-size: 13.5px; }
.doc code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.doc pre.code { font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; }
.doc a { color: var(--accent); }
.doc .muted { color: var(--faint); }
.doc .primitives { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.doc .primitives dt { font-weight: 600; }
.doc .primitives dd { margin: 0; color: var(--muted); }
.doc .rules li, .doc .steps li { margin-bottom: 6px; }
.doc .table-wrap { overflow-x: auto; margin: 8px 0 4px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.doc th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.doc th, .doc td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc td:first-child { white-space: nowrap; }
.doc .pattern { margin-top: 18px; }

/* Reading aids, after the Rust book: numbered contents that follow the
   reader, listings with a file name and buttons, notes, chapter endings. */
.toc ol { counter-reset: chapter; }
.toc li { counter-increment: chapter; }
.toc a::before { content: counter(chapter) ". "; color: var(--faint); font-variant-numeric: tabular-nums; }
.toc a { display: block; padding: 2px 0 2px 10px; margin-left: -10px; border-left: 2px solid transparent; transition: color 160ms, border-color 160ms; }
.toc a.active { color: var(--text); border-left-color: var(--accent); }
.doc .listing { margin: 14px 0 18px; }
.doc .listing pre.code { margin: 0; border-radius: 0 0 8px 8px; }
.doc .listing figcaption { margin-top: 8px; text-align: center; font-size: 13px; color: var(--muted); font-style: italic; }
.listing-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; background: var(--bg); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.listing-bar span { margin-right: auto; }
.listing-bar button { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.doc .listing-bar a.listing-open { padding: 3px 9px; border-radius: 6px; background: var(--accent); color: var(--on-accent); text-decoration: none; font: 600 12px system-ui, sans-serif; }
.doc pre.code .line { display: block; }
.doc pre.code .line.added { background: color-mix(in srgb, var(--accent) 12%, transparent); box-shadow: inset 2px 0 0 var(--accent); margin: 0 -16px; padding: 0 16px; }
.doc pre.code.terminal { background: color-mix(in srgb, var(--text) 4%, var(--panel)); }
.doc pre.code.terminal .prompt { color: var(--faint); user-select: none; }
.doc .callout { margin: 14px 0; padding: 10px 14px; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; background: var(--accent-soft); font-size: 14px; }
.doc .next-chapter { display: block; margin-top: 28px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; text-align: right; text-decoration: none; color: var(--text); font-weight: 600; transition: border-color 160ms; }
.doc .next-chapter:hover { border-color: var(--accent); }
.doc .next-chapter span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.doc .pattern p { margin: 4px 0; }
.doc .emits { color: var(--muted); font-size: 13.5px; }
.toc-toggle { display: none; }
.short { display: none; }
@media (max-width: 860px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 64px; gap: 16px; }
  /* The contents fold into a bar under the top bar that names where you are. */
  .toc { position: sticky; top: var(--topbar-height, 57px); z-index: 4; margin: 0 -16px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
  .toc-title { display: none; }
  .toc-toggle {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px;
    padding: 8px 12px; border-radius: 10px; text-align: left; font-size: 14px;
  }
  .toc-toggle-label { color: var(--muted); }
  .toc-current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .toc-current:not(:empty)::before { content: "· "; color: var(--faint); font-weight: 400; }
  .toc-toggle svg { color: var(--faint); transition: transform 200ms var(--ease); }
  .toc.is-open .toc-toggle svg { transform: rotate(180deg); }
  .toc ol {
    position: absolute; left: 16px; right: 16px; top: calc(100% - 4px);
    max-height: min(70vh, 520px); overflow-y: auto; padding: 8px 10px 8px 22px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
    opacity: 0; transform: translateY(-6px); visibility: hidden; pointer-events: none;
    transition: opacity 180ms var(--ease), transform 220ms var(--ease), visibility 0s linear 220ms;
  }
  .toc.is-open ol { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition: opacity 180ms var(--ease), transform 220ms var(--ease); }
  .toc a { padding: 9px 0 9px 10px; font-size: 15px; }
  .doc h1 { margin-top: 20px; }
  .doc section, .doc h3 { scroll-margin-top: calc(var(--topbar-height, 57px) + 68px); }
}
@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .toc ol, .toc.is-open ol, .toc-toggle svg { transition: none; transform: none; }
}

/* Phones: shorter labels, the graph's legend in the flow under it, the Run
   button pinned to the bottom, and a spec editor that wraps long lines. */
@media (max-width: 600px) {
  .long, .network-button .protocol { display: none; }
  .short { display: inline; }
  .topbar { padding: 8px 10px; }
  .topnav { margin-right: 2px; padding-right: 4px; }
  .topnav a, .topnav button, .network-button { padding: 6px 8px; }
  .tabs { padding: 6px 10px 0; }
  .tabs button[role="tab"] { padding: 8px 10px; }
  /* Wraps under itself rather than pushing the page wider than the screen. */
  .budget { min-width: 0; padding-left: 6px; font-size: 11.5px; line-height: 1.3; text-align: right; }
  .tab { padding: 10px 10px 12px; }
  .graph-wrap { flex-direction: column; min-height: 0; }
  .graph { min-height: 360px; }
  .legend { position: static; max-width: none; margin-top: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); background: none; backdrop-filter: none; }
  .run-dock { position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  body[data-stage="ready"] .result { padding-bottom: 76px; }
  .editor pre, #spec { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; }
  .editor { min-height: 360px; }
  .run-dock .run { padding: 10px 16px; }
  body:not([data-stage="start"]) main { grid-template-rows: auto minmax(420px, 1fr); }
  body:not([data-stage="start"]) .log { max-height: 45vh; }
}
/* The narrowest phones: the crossing mark alone says txflow. */
@media (max-width: 420px) {
  .topbar .brand .wordmark { font-size: 0; }
  .topbar .brand .mark { width: 20px; height: 20px; margin: 0; top: 0; }
  .topnav a, .topnav button, .network-button { padding: 6px 5px; }
}
svg .edge.send { stroke-dasharray: 2 3; }
svg .relay-pin { fill: none; stroke: var(--ink); stroke-width: 1.5; }
/* Drawn small, so strokes keep their screen width and dots grow. */
.shape .mini svg * { vector-effect: non-scaling-stroke; }
.shape .mini .edge { stroke: var(--ink-line); stroke-width: 1.2; }
.shape .mini .edge.conflict { stroke: var(--contest); }
.shape .mini .box { stroke: var(--ink-line); stroke-width: 1.1; }
.shape .mini .utxo { r: 6px; }
.shape .mini .utxo.unspent { stroke-width: 1.2; }
.shape .mini .relay-pin { r: 7px; stroke-width: 1.3; }

/* ---- Saved experiments: a drawer from the left ------------------------------ */

.topbar-left { display: flex; align-items: center; gap: 6px; }
#library-toggle { width: 34px; height: 34px; color: var(--muted); border-color: transparent; background: none; }
#library-toggle:hover { color: var(--text); }
.library {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  width: min(300px, 86vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform 260ms var(--ease);
}
body.library-open .library { transform: none; }
.library-backdrop { position: fixed; inset: 0; z-index: 25; background: rgb(0 0 0 / 0.12); opacity: 0; transition: opacity 260ms var(--ease); }
body.library-open .library-backdrop { opacity: 1; }
.library-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.library-head strong { font-size: 14px; }
#library-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; display: grid; gap: 2px; align-content: start; flex: 1; }
#library-list li { display: flex; align-items: center; border-radius: 9px; }
#library-list li:hover, #library-list li.current { background: var(--bg); }
#library-list li.current .library-item strong { color: var(--accent); }
.library-item { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; border: none; background: none; padding: 8px 10px; }
.library-item strong { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-item span { font-size: 12px; color: var(--muted); }
.library-action {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--faint);
  opacity: 0;
  transition: opacity 160ms var(--ease), color 160ms var(--ease), background 160ms var(--ease);
}
.library-delete { margin-right: 4px; }
#library-list li:hover .library-action, .library-action:focus-visible { opacity: 1; }
.library-action:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.library-delete:hover { color: var(--contest); }
#library-list li.renaming .library-item, #library-list li.renaming .library-action { display: none; }
.library-name-input {
  flex: 1;
  min-width: 0;
  margin: 4px;
  padding: 7px 9px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: 600 13.5px/1.3 inherit;
  font-family: inherit;
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: rise 200ms var(--ease);
}
.library-empty { margin: 0; padding: 4px 16px 16px; color: var(--muted); font-size: 13px; }
.graph-stage .node-tx:hover .box { stroke: var(--accent); }
.graph-stage .utxo:hover { stroke: var(--accent); stroke-width: 2; }
.library[hidden], .library-backdrop[hidden] { display: none; }

/* Theme toggle: one icon per choice, swapped with a short fade and turn. */
.theme-toggle { position: relative; width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); border-color: transparent; background: none; }
.theme-toggle:hover { color: var(--text); }
.theme-icon { grid-area: 1 / 1; opacity: 0; transform: rotate(-40deg) scale(0.7); transition: opacity 220ms var(--ease), transform 320ms var(--ease); }
.theme-toggle[data-theme="system"] .is-system,
.theme-toggle[data-theme="light"] .is-light,
.theme-toggle[data-theme="dark"] .is-dark { opacity: 1; transform: none; }
.doc-page .topbar-right { display: flex; align-items: center; gap: 6px; }
@media (prefers-reduced-motion: reduce) { .theme-icon { transition: none; } }
.sw.relays { display: inline-flex; gap: 2px; width: auto; height: auto; vertical-align: 0; }
.sw.relays b { width: 5px; height: 5px; border-radius: 50%; border: 1px solid var(--ink-line); }
.sw.relays b:first-child { background: var(--up); border-color: var(--up); }
.sw.relays b:nth-child(2) { background: var(--accent); border-color: var(--accent); }

/* Runs that survive a reload: a spinner in the library, a history in the run panel. */
.library-spinner { display: none; }
#library-list li.running .library-spinner {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border: 1.6px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.5px;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #library-list li.running .library-spinner { animation: none; border-color: var(--accent); background: var(--accent); width: 7px; height: 7px; }
}
.run-history { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.run-history strong { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.run-history li { display: flex; align-items: center; gap: 4px; border-radius: 7px; }
.run-history li.current { background: var(--accent-soft); }
.run-history-item {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 5px 8px;
  border: none;
  background: none;
  text-align: left;
  font-size: 12.5px;
}
.run-history-item:enabled:hover { color: var(--accent); }
.run-history-item:disabled { opacity: 0.55; cursor: default; }
.run-history-state { font-weight: 600; }
.run-history-state.is-done { color: var(--up); }
.run-history-state.is-failed, .run-history-state.is-lost { color: var(--contest); }
.run-history-facts { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-history-link { padding: 4px 8px; color: var(--muted); text-decoration: none; }
.run-history-link:hover { color: var(--accent); }

/* The run view in the details panel: a checklist of the run's steps. */
.run-checklist { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 9px; }
.run-checklist li { display: grid; grid-template-columns: 16px minmax(0, 1fr); column-gap: 8px; row-gap: 1px; align-items: baseline; }
.run-checklist i { grid-row: span 2; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--ink-line); translate: 0 2px; transition: background 300ms var(--ease), border-color 300ms var(--ease); }
.run-checklist b { font-weight: 600; font-size: 13px; }
.run-checklist span { grid-column: 2; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.run-checklist span a { color: var(--accent); text-decoration: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.run-checklist .is-now i { border-color: var(--accent); border-right-color: transparent; animation: spin 900ms linear infinite; }
.run-checklist .is-done i { border-color: var(--up); background: var(--up); }
.run-checklist .is-failed i { border-color: var(--contest); background: var(--contest); }
.run-checklist .is-todo b { color: var(--muted); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .run-checklist .is-now i { animation: none; border-color: var(--accent); background: var(--accent-soft); } }
.detail .run-note { margin: 12px 0 0; }
.detail .run-start { margin-top: 12px; }
.detail details { margin-top: 10px; font-size: 12.5px; }
.detail details p { margin: 4px 0 0; overflow-wrap: anywhere; }
.detail .run-links { margin: 0; font-size: 12.5px; }
.detail .run-links a { color: var(--accent); text-decoration: none; }
.slot-line.is-busy { color: var(--partial); }
.detail .run-history { margin-top: 14px; }
.detail .run-history ol { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }

/* ---- How it works: one experiment, start to finish ---------------------------- */

.how-layout { max-width: 760px; margin: 0 auto; padding: 40px 24px 96px; }
.how .eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: 0.02em; }
.how h1 { text-wrap: balance; }
.how h2 { display: flex; align-items: center; gap: 10px; }
.how section { scroll-margin-top: 72px; }
.step-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 650; flex: none; }
.how-steps { list-style: none; padding: 0; margin: 22px 0 8px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; counter-reset: step; }
.how-steps li { counter-increment: step; }
.how-steps a { display: grid; gap: 1px; height: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); text-decoration: none; transition: border-color 160ms var(--ease), transform 160ms var(--ease); }
.how-steps a:hover { border-color: var(--accent); transform: translateY(-1px); }
.how-steps b::before { content: counter(step) "  "; color: var(--accent); }
.how-steps span { color: var(--muted); font-size: 13px; }
.how .ask { margin: 12px 0; padding: 12px 16px; border-radius: 14px 14px 14px 4px; background: var(--user); font-size: 15.5px; line-height: 1.5; }
.how-notes { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 16px 0; font-size: 14.5px; }
.how-notes dt { padding-top: 1px; }
.how-notes dd { margin: 0; color: var(--muted); }
.how-graph { position: relative; height: 280px; margin: 14px 0 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; display: flex; }
.how-graph .graph-stage { flex: 1; }
.how-legend { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; font-size: 14px; color: var(--muted); }
.how-legend li { display: flex; gap: 10px; align-items: baseline; }
.how-legend .sw { flex: none; }
.how-legend b { color: var(--text); font-weight: 600; }
.how .run-steps { padding-left: 20px; }
.how .run-steps li { margin-bottom: 8px; }
.how .state { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 13.5px; white-space: nowrap; }
.how .state.accepted { border: 1.4px solid var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); }
.how .state.landed { border: 1.4px solid var(--up); background: color-mix(in srgb, var(--up) 10%, var(--panel)); }
.how .state.rejected { border: 1.4px solid var(--contest); background: color-mix(in srgb, var(--contest) 9%, var(--panel)); }
.how .state.dropped { border: 1.4px dashed var(--ink-line); color: var(--muted); }
.how-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 18px; color: var(--muted); font-size: 14px; }
.how .how-open { display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 14px; text-decoration: none; transition: transform 160ms var(--ease), box-shadow 160ms var(--ease); }
.how .how-open:hover { transform: translateY(-1px); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 30%, transparent); }
.how-variants { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.how-variant { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.how-variant h3 { margin: 0; font-size: 15px; }
.how-variant p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.how .how-diff { margin: 0; padding: 8px 10px; font-size: 11.5px; overflow-x: auto; }
.how .how-diff .line { display: block; white-space: pre; }
.how .how-diff .line.removed { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--contest) 60%, transparent); }
.how .how-diff .line.added { margin: 0 -10px; padding: 0 10px; background: color-mix(in srgb, var(--accent) 12%, transparent); box-shadow: inset 2px 0 0 var(--accent); }
.how-mini { height: 110px; display: grid; place-items: center; }
.how-mini svg { width: 100%; height: 110px; }
.how-mini svg text, .how-mini svg .group-label { display: none; }
.how-mini svg * { vector-effect: non-scaling-stroke; }
.how-variant .how-open { align-self: flex-start; margin-top: auto; padding: 6px 11px; font-size: 13px; }
.how-next { padding-left: 20px; }
.how-next li { margin-bottom: 6px; }
@media (max-width: 860px) {
  .how-variants { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .how-layout { padding: 24px 16px 64px; }
  .how-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .how-notes { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .how-notes dd { margin-bottom: 10px; }
  .how-graph { height: 220px; }
  .hide-narrow, #new { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .how-steps a, .how .how-open { transition: none; }
  .how-steps a:hover, .how .how-open:hover { transform: none; }
}

/* How it works: a run played on the race's graph, with the step it is at
   marked in the list above it. */
.how-run { margin: 18px 0 6px; }
.how-run figcaption { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13.5px; min-height: 2.6em; }
.how-run #run-caption { transition: color 240ms var(--ease); }
.how-run #run-replay { flex: none; padding: 4px 10px; font-size: 13px; }
.how .run-steps li { transition: color 240ms var(--ease); }
.how .run-steps li::marker { transition: color 240ms var(--ease); }
.how .run-steps li.is-current { color: var(--text); }
.how .run-steps li.is-current::marker { color: var(--accent); }
.how .run-steps li.is-current b { color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .how .run-steps li, .how .run-steps li::marker, .how-run #run-caption { transition: none; }
}
