@font-face { font-family: 'Space Grotesk'; src: url('/assets/fonts/SpaceGrotesk.woff2?v=9') format('woff2'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('/assets/fonts/PlexMono.woff2?v=9') format('woff2'); font-weight: 400; font-display: swap; }

:root {
  --carbon: #101112; --chalk: #F2F0E9; --graphite: #353A3D; --green: #B8E986;
  --ink2: rgba(242, 240, 233, 0.72); --muted: rgba(242, 240, 233, 0.52); --rule: rgba(242, 240, 233, 0.11); --rule2: rgba(242, 240, 233, 0.2);
  --panel: #151719;
  --rail: 224px; --top: 56px; --dock: 0px;
  --stage-max: clamp(250px, 42vh, 420px); --stage-min: 150px;
  --gut: 40px;
  --sans: 'Space Grotesk', system-ui, sans-serif; --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--carbon); color: var(--chalk); }
body { font: 400 15px/1.55 var(--sans); overflow: hidden; -webkit-font-smoothing: antialiased; }
a { color: var(--chalk); text-decoration-color: var(--rule2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--chalk); }
code, pre, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: rgba(242, 240, 233, 0.06); padding: 1px 5px; border-radius: 3px; }
b { font-weight: 600; }
.g, b.g { color: var(--green); }
.muted { color: var(--muted); }
.wrap { word-break: break-all; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--chalk); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100dvh; }
.rail { border-right: 1px solid var(--rule); display: flex; flex-direction: column; gap: 22px; padding: 22px 18px 18px; overflow-y: auto; background: #0E0F10; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { border-radius: 6px; display: block; }
.wordmark { font: 700 21px/1 var(--sans); letter-spacing: 0.04em; }
.tagline { margin: -8px 0 0; font: 400 12px/1.5 var(--mono); color: var(--muted); }

.stations { list-style: none; margin: 6px 0 0; padding: 0 0 0 0; position: relative; }
.stations::before { content: ''; position: absolute; left: 13px; top: 14px; bottom: 14px; width: 4px; border-radius: 2px; background: var(--graphite); box-shadow: inset 0 1px 0 rgba(255,255,255,0.08); }
.stations a { position: relative; display: grid; grid-template-columns: 32px 1fr; grid-template-rows: auto auto; column-gap: 12px; padding: 10px 8px 10px 0; text-decoration: none; border-radius: 4px; }
.stations .no { grid-row: 1 / 3; align-self: center; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: #1C1F21; border: 1px solid var(--rule2); font: 400 11px/1 var(--mono); color: var(--muted); position: relative; z-index: 1; }
.stations .nm { font: 500 16px/1.2 var(--sans); }
.stations .sub { font: 400 11px/1.4 var(--mono); color: var(--muted); }
.stations a:hover .nm { text-decoration: underline; text-decoration-color: var(--rule2); }
.stations a[aria-current="page"] .no { background: var(--chalk); color: var(--carbon); border-color: var(--chalk); }
.stations a[aria-current="page"] .nm { font-weight: 600; }

.railfoot { margin: auto 0 0; padding: 14px 0 0; border-top: 1px solid var(--rule); font: 400 12px/1.4 var(--mono); }
.railfoot div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.railfoot dt { color: var(--muted); }
.railfoot dd { margin: 0; text-align: right; }
[data-tone="warn"] { color: #E9C986; }

.main { position: relative; min-width: 0; height: 100dvh; overflow: hidden; }
.topbar { position: absolute; inset: 0 0 auto 0; height: var(--top); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--rule); background: var(--carbon); z-index: 4; }
.topbar .brand.mob { display: none; }
.crumb { margin: 0; font: 400 13px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.crumb .sep { margin: 0 8px; opacity: 0.5; }
.crumb [data-k="crumbName"] { color: var(--chalk); }
.tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pill { font: 400 11px/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; padding: 6px 9px; border: 1px solid var(--rule2); border-radius: 999px; color: var(--ink2); white-space: nowrap; }
.pill[data-tone="live"] { border-color: rgba(184, 233, 134, 0.5); color: var(--green); }

.stage { position: absolute; top: var(--top); left: 0; right: 0; height: var(--stage-max); z-index: 1; background: var(--carbon); }
.stage canvas { display: block; width: 100%; height: 100%; }
.sheet { position: absolute; top: calc(var(--top) + var(--stage-min)); left: 0; right: 0; bottom: var(--dock); overflow-y: auto; overscroll-behavior: contain; z-index: 2; padding-top: calc(var(--stage-max) - var(--stage-min)); scrollbar-color: var(--graphite) transparent; }
.plate { position: relative; background: var(--carbon); min-height: 100%; padding: 30px var(--gut) 96px; border-top: 1px solid var(--rule2); box-shadow: 0 -18px 30px rgba(0, 0, 0, 0.45); outline: none; }
.plate::before { content: ''; position: absolute; top: 8px; left: 50%; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: var(--graphite); }
.plate > * { max-width: 1040px; margin-left: auto; margin-right: auto; }

.dock { display: none; }

/* ---------- type & blocks ---------- */
.eyebrow { margin: 0 0 10px; font: 400 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font: 600 44px/1.04 var(--sans); letter-spacing: -0.02em; }
.lead.compact h1 { font-size: 36px; }
h2 { margin: 0 0 14px; font: 500 19px/1.2 var(--sans); display: flex; align-items: center; gap: 12px; }
h2 .no { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--rule2); border-radius: 3px; font: 400 11px/1 var(--mono); color: var(--muted); }
section { padding: 26px 0; border-bottom: 1px solid var(--rule); }
section:last-child { border-bottom: 0; }
.lead { padding-top: 12px; }
.status { margin: 14px 0 0; max-width: 700px; color: var(--ink2); }
.status b { color: var(--chalk); }
.fine { margin: 12px 0 0; font-size: 13px; color: var(--muted); max-width: 760px; }
p { max-width: 760px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

.btn { appearance: none; border: 1px solid var(--chalk); background: var(--chalk); color: var(--carbon); font: 600 14px/1 var(--sans); padding: 13px 18px; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { background: #fff; }
.btn.ghost { background: transparent; color: var(--chalk); border-color: var(--rule2); }
.btn.ghost:hover { border-color: var(--chalk); }
.btn.small { padding: 9px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { cursor: not-allowed; background: #26292B; border-color: #26292B; color: var(--muted); }
.btn.ghost:disabled { background: transparent; border-color: var(--rule); }
.btn[data-on="1"] { font-family: var(--mono); font-weight: 400; }
.link { appearance: none; background: none; border: 0; padding: 0; color: var(--chalk); text-decoration: underline; text-decoration-color: var(--rule2); text-underline-offset: 3px; cursor: pointer; font: inherit; }

/* ruled rows */
.rows { margin: 0; }
.rows > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: baseline; padding: 11px 0; border-bottom: 1px solid var(--rule); }
.rows > div:last-child { border-bottom: 0; }
.rows dt { color: var(--ink2); min-width: 0; }
.rows dd { margin: 0; font: 400 14px/1.4 var(--mono); font-variant-numeric: tabular-nums; text-align: right; min-width: 0; }
.rows > .g dt::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 9px; background: var(--green); border-radius: 1px; vertical-align: 1px; }
.rows > .g dd { color: var(--green); }
.rows.register dd { font-size: 15px; }
.rows.spec > div { grid-template-columns: 190px minmax(0, 1fr); }
.rows.spec dd { text-align: left; font: 400 15px/1.5 var(--sans); }
.rows.spec dd .mono, .rows.spec dd a.mono { font-size: 13.5px; }
.rows.tight > div { padding: 9px 0; }

/* mechanism */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 32px; }
.steps li { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; padding: 14px 10px 14px 0; border-top: 1px solid var(--rule); cursor: default; outline: none; border-radius: 2px; }
.steps li:hover, .steps li:focus-visible { background: linear-gradient(90deg, rgba(242, 240, 233, 0.04), transparent); }
.steps .k { font: 400 12px/1.5 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding-top: 2px; }
.steps .k.g { color: var(--green); }
.steps p { margin: 0; }
.calc { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; align-items: start; }
.boundary p { margin: 0; padding: 16px 18px; border: 1px solid var(--rule2); border-radius: 4px; color: var(--ink2); font-size: 14px; max-width: none; }

/* fields */
.field { display: grid; gap: 7px; }
.field > span { font: 400 12px/1 var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
input { width: 100%; background: var(--panel); border: 1px solid var(--rule2); border-radius: 4px; color: var(--chalk); padding: 12px 12px; font: 400 16px/1.2 var(--mono); }
input:focus { outline: none; border-color: var(--chalk); }
.inrow { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--rule2); border-radius: 4px; }
.inrow:focus-within { border-color: var(--chalk); }
.inrow input { border: 0; background: transparent; font-size: 24px; padding: 14px 12px; min-width: 0; }
.inrow b { padding: 0 14px; font: 500 14px/1 var(--mono); color: var(--ink2); }
.field small { display: flex; justify-content: space-between; gap: 10px; font: 400 12px/1.4 var(--mono); color: var(--muted); }
.check { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--ink2); }
.check input { width: 16px; height: 16px; accent-color: var(--chalk); }

.seg { display: inline-flex; border: 1px solid var(--rule2); border-radius: 4px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { appearance: none; border: 0; background: transparent; padding: 9px 14px; border-radius: 3px; cursor: pointer; font: 500 14px/1 var(--sans); color: var(--ink2); }
.seg button[aria-pressed="true"] { background: var(--graphite); color: var(--chalk); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.seg button:disabled { cursor: not-allowed; opacity: 0.5; }
.seg.small button { font-size: 13px; padding: 8px 12px; }
.seg.tiny button { font: 400 12px/1 var(--mono); padding: 7px 10px; }

/* trade */
.trade { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 36px; padding: 26px 0; border-bottom: 1px solid var(--rule); }
.trade section { padding: 0; border: 0; }
.ticket { display: grid; gap: 18px; align-content: start; }
.ticket > .seg:first-child { width: 100%; }
.ticket > .seg:first-child button { flex: 1; }
.receipt { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 18px 20px; align-self: start; }
.rc-head { display: flex; justify-content: space-between; margin: 0 0 10px; font: 400 12px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; }
.route { list-style: none; margin: 0 0 12px; padding: 0 0 14px; display: flex; flex-wrap: wrap; gap: 6px 0; border-bottom: 1px solid var(--rule); font: 400 12.5px/1 var(--mono); }
.route li { padding: 7px 9px; border: 1px solid var(--rule2); border-radius: 3px; }
.route li + li::before { content: '→'; margin: 0 8px 0 -2px; color: var(--muted); }
.route li + li { border-left: 0; border-radius: 0 3px 3px 0; }
.review { border: 1px dashed var(--rule2); border-radius: 4px; padding: 14px 16px; }
.rv-title { margin: 0 0 6px; font: 500 14px/1.2 var(--sans); }
.txline { margin: 0; font: 400 13px/1.5 var(--mono); color: var(--ink2); overflow-wrap: anywhere; }
.txline:empty { display: none; }
.txline[data-tone="bad"] { color: #E9A986; }
.burnbox .burnrow { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 16px; align-items: end; }

/* ledger */
.burnmeter .track { height: 14px; border-radius: 7px; background: #0A0B0C; border: 1px solid var(--rule2); overflow: hidden; box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.6); }
.burnmeter i { display: block; height: 100%; background: var(--green); min-width: 0; }
.burnmeter p { margin: 10px 0 0; font: 400 14px/1.4 var(--mono); }
#lgFilter { margin-bottom: 14px; }
.empty { margin: 0; padding: 26px 18px; border: 1px dashed var(--rule2); border-radius: 4px; color: var(--muted); font-size: 14px; max-width: none; }
.ltable { width: 100%; border-collapse: collapse; font: 400 13px/1.4 var(--mono); font-variant-numeric: tabular-nums; }
.ltable th { text-align: left; font-weight: 400; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 8px; border-bottom: 1px solid var(--rule2); white-space: nowrap; }
.ltable td { padding: 10px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.ltable .r { text-align: right; }
.ltable .g { color: var(--green); }

/* context */
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.facts li:last-child { border-bottom: 0; }
.facts time { font: 400 12.5px/1.6 var(--mono); color: var(--muted); }
.facts p { margin: 0; }
.facts .src { margin-top: 4px; font: 400 12.5px/1.4 var(--mono); }

/* docs */
.chapters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.chapters a { font: 400 12.5px/1 var(--mono); padding: 8px 10px; border: 1px solid var(--rule2); border-radius: 3px; text-decoration: none; }
.chapters a:hover { border-color: var(--chalk); }
pre { background: #0A0B0C; border: 1px solid var(--rule); border-radius: 4px; padding: 14px 16px; overflow-x: auto; font-size: 12.5px; line-height: 1.6; max-width: 100%; }
pre code { background: none; padding: 0; }
ul.plain { margin: 0; padding-left: 18px; max-width: 760px; }
ul.plain li { margin: 6px 0; }

dialog { background: var(--panel); color: var(--chalk); border: 1px solid var(--rule2); border-radius: 6px; padding: 18px; min-width: min(320px, 90vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog ul { list-style: none; margin: 10px 0 14px; padding: 0; display: grid; gap: 6px; }
dialog li button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--carbon); border: 1px solid var(--rule2); border-radius: 4px; cursor: pointer; }
dialog li img { width: 22px; height: 22px; }
.dlg-title { margin: 0; font-weight: 600; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .steps { grid-template-columns: minmax(0, 1fr); }
  .trade { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  :root { --rail: 0px; --top: 54px; --dock: calc(62px + env(safe-area-inset-bottom)); --stage-max: 250px; --stage-min: 116px; --gut: 24px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .topbar { padding: 0 16px; }
  .topbar .brand.mob { display: inline-flex; }
  .topbar .brand.mob .wordmark { font-size: 18px; }
  .crumb { display: none; }
  .dock { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; height: var(--dock); padding-bottom: env(safe-area-inset-bottom); background: #0E0F10; border-top: 1px solid var(--rule2); z-index: 5; }
  .dock a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-decoration: none; font: 500 11.5px/1 var(--sans); color: var(--ink2); min-width: 0; }
  .dock .no { font: 400 10px/1 var(--mono); color: var(--muted); border: 1px solid var(--rule2); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
  .dock a[aria-current="page"] { color: var(--chalk); }
  .dock a[aria-current="page"] .no { background: var(--chalk); color: var(--carbon); border-color: var(--chalk); }
}
@media (max-width: 640px) {
  :root { --stage-max: 190px; --stage-min: 104px; --gut: 16px; }
  body { font-size: 15px; }
  h1 { font-size: 31px; }
  .lead.compact h1 { font-size: 27px; }
  .tb-right .pill { display: none; }
  .rows.spec > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .rows > div { gap: 10px; }
  .rows dd { font-size: 13px; }
  .rows.register dd { font-size: 13.5px; }
  .calc { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .steps li { grid-template-columns: 70px minmax(0, 1fr); }
  .facts li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .burnbox .burnrow { grid-template-columns: minmax(0, 1fr); }
  .receipt { padding: 14px 14px; }
  .dock a { font-size: 10.5px; }
  /* ledger rows become cards */
  .ltable thead { display: none; }
  .ltable, .ltable tbody, .ltable tr, .ltable td { display: block; width: 100%; }
  .ltable tr { border: 1px solid var(--rule); border-radius: 4px; padding: 8px 12px; margin-bottom: 10px; }
  .ltable td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; white-space: normal; text-align: right; }
  .ltable td[data-l]::before { content: attr(data-l); color: var(--muted); text-align: left; }
  .ltable td:not([data-l]) { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
.rows dd[data-tone="idle"], .rows > .g dd[data-tone="idle"] { color: var(--muted); }
.ticket .seg.small, .ticket #slipSeg { justify-self: start; }
.burnbox .burnrow { margin-top: 16px; }

.railfoot a.ext { color: var(--chalk, #F2F0E9); text-decoration: none; border-bottom: 1px solid var(--rule); }
.railfoot a.ext:hover { border-color: currentColor; }
.xlink { min-width: 36px; justify-content: center; text-decoration: none; }
