:root {
  --ground: #EEF0EC;
  --ground-inset: #E3E6E1;
  --ground-deep: #D6DAD4;
  --ink: #15181C;
  --ink-2: #545B63;          /* 5.9:1 on --ground */
  --ink-3: #636970;          /* 4.8:1 on --ground */
  --line: rgba(21, 24, 28, .14);
  --cord: #FF4A1C;           /* the cord only */
  --cord-shade: #C2340F;
  --cord-deep: #8E230A;
  --cord-light: #FFB29A;
  --amber: #F7B500;
  --crimson: #C8102E;
  --paused: #8C939B;
  --metal-1: #F7F8F6;
  --metal-2: #C9CDC8;
  --eyelet: #23272C;
  --groove-dark: #BCC1BA;    /* route only: debossed groove, never red */
  --groove-light: #F7F8F5;
  --notch: #A9AEA7;
  --badge-bg: #15181C; --badge-fg: #EEF0EC; --badge-border: transparent;
  --stop-bg: #15181C; --stop-fg: #EEF0EC; --stop-border: transparent;
  --drop: rgba(21,24,28,.22);
  --rope-edge: 0;            /* 1 px top-edge light on rope, dark mode only */
  --rim: rgba(255,255,255,.5);
  --engr: rgba(0,0,0,.28); --engr-hi: rgba(255,255,255,.55);
  --shadow: 0 1px 0 rgba(21,24,28,.08), 0 6px 14px -8px rgba(21,24,28,.25);
  --f-sans: "Schibsted Grotesk", system-ui, sans-serif;
  --f-mono: "Martian Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #121417; --ground-inset: #1A1D21; --ground-deep: #23272C;
    --ink: #E9ECE8; --ink-2: #A3AAB1; --ink-3: #8C939A; --line: rgba(233,236,232,.14);
    --cord-light: #FF9C7E; --metal-1: #4A5058; --metal-2: #1F2327; --eyelet: #5E656E;
    --groove-dark: #050607; --groove-light: #30353B; --notch: #000;
    --badge-bg: #1A1D21; --badge-fg: #E9ECE8; --badge-border: rgba(255,255,255,.16);
    --stop-bg: #1C2024; --stop-fg: #E9ECE8; --stop-border: rgba(255,255,255,.14);
    --drop: rgba(0,0,0,.55); --rope-edge: .5; --rim: rgba(255,255,255,.18);
    --engr: rgba(233,236,232,.42); --engr-hi: rgba(0,0,0,.6);
    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 6px 14px -8px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #121417; --ground-inset: #1A1D21; --ground-deep: #23272C;
  --ink: #E9ECE8; --ink-2: #A3AAB1; --ink-3: #8C939A; --line: rgba(233,236,232,.14);
  --cord-light: #FF9C7E; --metal-1: #4A5058; --metal-2: #1F2327; --eyelet: #5E656E;
  --groove-dark: #050607; --groove-light: #30353B; --notch: #000;
  --badge-bg: #1A1D21; --badge-fg: #E9ECE8; --badge-border: rgba(255,255,255,.16);
  --stop-bg: #1C2024; --stop-fg: #E9ECE8; --stop-border: rgba(255,255,255,.14);
  --drop: rgba(0,0,0,.55); --rope-edge: .5; --rim: rgba(255,255,255,.18);
  --engr: rgba(233,236,232,.42); --engr-hi: rgba(0,0,0,.6);
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 6px 14px -8px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ground); color: var(--ink);
  font-family: var(--f-sans); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.mono { font-family: var(--f-mono); }
a { color: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(300px, 4fr) 8fr;
  grid-template-rows: 52px auto auto;
  grid-template-areas: "top top" "owner field" "rec rec";
  padding: 0 40px; column-gap: 40px;
}
.topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--line); font-size: 13px; min-width: 0; }
.brand { white-space: nowrap; }
.brand b { font-weight: 800; font-size: 16px; letter-spacing: -.01em; margin-right: 12px; }
.brand span { color: var(--ink-2); }
.topmeta { display: flex; gap: 16px; align-items: center; font-family: var(--f-mono); font-size: 11px; color: var(--ink-2); min-width: 0; margin-left: auto; }
.topmeta > span { white-space: nowrap; }
.topmeta .stamp { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.modes { display: flex; gap: 6px; flex: none; }
.modes button { font: 500 11px/1 var(--f-mono); border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 4px; padding: 6px 8px; cursor: pointer; white-space: nowrap; }
.modes button:hover { border-color: var(--ink-2); }
.modes button[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.modes button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.replay { background: var(--ink); color: var(--ground); padding: 4px 8px; border-radius: 4px; font-weight: 600; letter-spacing: .02em; }
.stamp { color: var(--ink); }

.overline { font: 600 12px/1 var(--f-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }

/* ---------- owner column */
.owner { grid-area: owner; display: flex; flex-direction: column; padding: 28px 0 24px; min-width: 0; }
.headline { margin-top: 26px; }
.hl-label { font: 700 15px/1.2 var(--f-sans); letter-spacing: .06em; text-transform: uppercase; transition: opacity .16s ease-out; }
.hl-num { font: 800 clamp(56px, 7vw, 144px)/.95 var(--f-sans); letter-spacing: -.02em; margin-top: 8px; white-space: nowrap; }
.hl-num.roll { animation: roll .12s linear; }
@keyframes roll { from { transform: translateY(-6px); opacity: .4; } to { transform: none; opacity: 1; } }
.hl-sub { margin-top: 12px; font-size: 15px; color: var(--ink-2); }
.hl-note { margin-top: 6px; font-size: 14px; color: var(--crimson); font-weight: 600; }
.facts { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }
.fact { font-size: 15px; line-height: 1.4; }
.fact b { font-family: var(--f-mono); font-weight: 500; }
.fact span { color: var(--ink-2); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font: 500 11px/1.45 var(--f-mono); padding: 5px 9px; border-radius: 4px; border: 1px solid var(--line); color: var(--ink-2); }
.chip.live { color: var(--ink); border-color: var(--ink); }
.chip.calm { background: var(--ground-deep); color: var(--ink); border-color: transparent; }
.badge { display: inline-flex; flex-direction: column; gap: 4px; align-self: flex-start; padding: 10px 12px; border-radius: 4px;
  background: var(--badge-bg); color: var(--badge-fg); border: 1px solid var(--badge-border); text-decoration: none; max-width: 360px; }
.b-main { font: 600 15px/1 var(--f-mono); }
.b-sub { font: 400 10.5px/1.45 var(--f-mono); opacity: .75; }

.stopwrap { margin-top: auto; padding-top: 22px; }
.stop { position: relative; overflow: hidden; width: 100%; max-width: 400px; height: 72px; border-radius: 999px;
  border: 1px solid var(--stop-border); background: var(--stop-bg); color: var(--stop-fg); cursor: pointer; box-shadow: var(--shadow);
  text-align: left; padding: 0 0 0 30px;
  font: 800 20px/1 var(--f-sans); letter-spacing: .04em; text-transform: uppercase; touch-action: none; user-select: none; }
.stop:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.stop-fill { position: absolute; inset: 0; transform-origin: left center; transform: scaleX(0); background: var(--ink-2); opacity: .45; }
.stop-text { position: relative; display: inline-block; }
/* the pull handle: a braided cord entering the pill from its right edge; holding slides it out */
.stop-cord { position: absolute; right: -100px; top: 50%; margin-top: -10px; width: 150px; height: 20px; pointer-events: none; }
.stop-cord svg { display: block; }
.stop[disabled] { cursor: default; }
.stop-hint { margin-top: 10px; max-width: 400px; font: 400 11px/1.45 var(--f-mono); color: var(--ink-2); }

/* ---------- field */
.field { grid-area: field; position: relative; min-width: 0; padding-top: 44px; }
.legend { position: absolute; top: 22px; right: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 18px; max-width: 100%; font: 600 13px/1 var(--f-sans); z-index: 2; }
.lg { display: inline-flex; align-items: center; gap: 8px; }
.lg-cord-edge { stroke: var(--cord-deep); stroke-width: 8; stroke-linecap: round; }
.lg-cord { stroke: var(--cord); stroke-width: 6; stroke-linecap: round; }
.lg-cord-shade { stroke: var(--cord-shade); stroke-width: 6; stroke-dasharray: 2 2; opacity: .55; }
.lg-block { fill: var(--ink); }
.lg-quiet { color: var(--ink-2); font-weight: 500; }
.lg-groove-d { stroke: var(--groove-dark); stroke-width: 4; stroke-linecap: round; }
.lg-groove-l { stroke: var(--groove-light); stroke-width: 2; stroke-linecap: round; }
.clock { margin-top: 18px; display: grid; grid-template-columns: auto 1fr; column-gap: 12px; row-gap: 6px; align-items: center; }
.clock-t { font: 600 22px/1 var(--f-mono); background: var(--ink); color: var(--ground); padding: 7px 10px; border-radius: 4px; min-width: 96px; text-align: right;
  border: 1px solid var(--ink); transition: background-color .3s ease-out, color .3s ease-out; }
.clock-t.done { background: var(--ground); color: var(--ink); }
.clock-l { font: 400 11px/1.4 var(--f-mono); color: var(--ink-2); }
.skip { grid-column: 1 / 3; justify-self: start; font: 600 12px/1 var(--f-mono); padding: 7px 10px; border-radius: 4px;
  border: 1px dashed var(--ink); background: var(--ground); white-space: nowrap; }
.camchip { margin-top: 14px; align-self: flex-start; font: 500 11px/1 var(--f-mono); color: var(--ink); background: var(--ground);
  border: 1px solid var(--line); padding: 5px 8px; border-radius: 4px; }
.field-svg { width: 100%; display: block; overflow: hidden; }

/* SVG text */
.t-label { font: 600 12px var(--f-sans); letter-spacing: .08em; text-transform: uppercase; fill: var(--ink); }
.t-small { font: 400 11px var(--f-mono); fill: var(--ink-2); }
.t-mono { font: 500 12px var(--f-mono); fill: var(--ink); }
.t-money { font: 600 17px var(--f-mono); fill: var(--ground); }
.t-money-s { font: 400 10px var(--f-mono); fill: var(--ground); opacity: .72; }
.t-tiny { font: 400 10px var(--f-mono); fill: var(--ink-3); }
.t-tick { font: 400 9px var(--f-mono); fill: var(--ink-3); }
.t-ink3 { fill: var(--ink-3); }
.t-amber { fill: var(--ink); font-weight: 600; }
.t-ink2 { fill: var(--ink-2); }
.plate rect { rx: 4; }
.plate-open rect { fill: none; stroke: var(--ink-3); }
.plate-open text { fill: var(--ink-2); }
.plate-amber rect { fill: var(--amber); }
.plate-amber text { fill: #15181C; }
.plate-red rect { fill: var(--crimson); }
.plate-red text { fill: #FFFFFF; }
.plate-frozen rect { fill: var(--ink); }
.plate-frozen text { fill: var(--ground); }
.plate text { font: 600 11.5px var(--f-mono); }
.chipsvg rect { fill: var(--ground); stroke: var(--ink); }
.chipsvg text { font: 500 11px var(--f-mono); fill: var(--ink); }
.well { fill: var(--ground-inset); }
.well-edge { fill: none; stroke: rgba(0,0,0,.10); }
.block { fill: var(--ink); }
.coin { fill: var(--ink); stroke: var(--ground); stroke-width: 1.5; }
.coin-tag { font: 500 11px var(--f-mono); fill: var(--ink); }
.groove-d { fill: none; stroke: var(--groove-dark); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.groove-l { fill: none; stroke: var(--groove-light); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ruler-line { stroke: var(--ink-3); stroke-width: 1; }
.ruler-tick { stroke: var(--ink-2); stroke-width: 1; }
.ruler-minor { stroke: var(--ink-3); stroke-width: 1; opacity: .7; }
.travel-out { fill: none; stroke: var(--cord); stroke-linecap: butt; stroke-linejoin: round; }
.travel-in { fill: none; stroke: var(--ground); stroke-linecap: butt; stroke-linejoin: round; }
.pulse-out { fill: none; stroke: var(--cord-light); stroke-linecap: round; stroke-linejoin: round; }
.pulse-in { fill: none; stroke: var(--ground); stroke-linecap: round; stroke-linejoin: round; }
.notch { fill: var(--notch); }
.spool-flash { fill: none; stroke: var(--cord-light); stroke-width: 2.5; }
.react-tag rect { fill: var(--ground); stroke: var(--ink); stroke-width: 1; }
.react-tag text { font: 500 11px var(--f-mono); fill: var(--ink); }
.react-tag text.tag-sub { font-size: 10px; fill: var(--ink-2); }
.drop { fill: var(--drop); }
.flange { stroke: rgba(0,0,0,.18); }
.flange-rim { fill: none; stroke: var(--rim); stroke-width: 1.5; }
.engr { font: 600 9px var(--f-sans); letter-spacing: .2em; fill: var(--engr); }
.engr-hi { font: 600 9px var(--f-sans); letter-spacing: .2em; fill: var(--engr-hi); }
.hub { fill: var(--ground-deep); stroke: rgba(0,0,0,.25); }
.spoke { stroke: var(--eyelet); stroke-width: 3; stroke-linecap: round; opacity: .55; }
.clamp { fill: var(--ink); }
.mouth-in { fill: var(--ground-deep); }
.pleats path { fill: none; stroke: var(--ink-3); stroke-width: 1; opacity: .35; }
.eyelet-rim { fill: none; stroke: var(--rim); stroke-width: 1; }
.rivet { fill: var(--metal-2); stroke: #000; stroke-width: .6; }
.lead { stroke: var(--ink-3); stroke-dasharray: 2 3; }
.rope-shadow { stroke: rgba(21,24,28,.30); }
.rope-edge { opacity: var(--rope-edge); }
.knot-mark { fill: none; stroke: var(--cord-deep); stroke-width: 1.4; stroke-linecap: round; }
.piece-shadow { fill: rgba(21,24,28,.28); }
.tray-edge { stroke: var(--ink-3); stroke-width: 1; }
.tray-tick { stroke: var(--ink-3); stroke-width: 1; }

/* ---------- live additions */
.livetag { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 600; }
.livetag i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); display: inline-block; }
.livetag.stale i { background: transparent; border: 1px solid var(--ink-2); }
.livetag.stale { color: var(--ink-2); }
.stamp.warn { color: var(--ink); font-weight: 600; }
.plate-held rect { fill: var(--ground-deep); }
.plate-held text { fill: var(--ink); }
.stop.locked { cursor: default; opacity: .62; box-shadow: none; }
.stop.locked .stop-cord { opacity: .7; }
.ok-mark { color: var(--ink); font-weight: 600; }

/* ---------- receipts */
.receipts { grid-area: rec; border-top: 1px solid var(--line); padding: 10px 0 14px; }
.r-head { display: grid; grid-template-columns: 1fr; gap: 10px; }
.r-cols { display: grid; grid-template-columns: 36px 1fr 1.7fr 104px; gap: 16px; font-size: 10px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; padding-right: 330px; }
.r-body { display: grid; grid-template-columns: 1fr 310px; gap: 20px; margin-top: 8px; }
.r-list { max-height: 128px; overflow: auto; background: var(--ground-inset); border-radius: 4px; }
.r-list.masked { -webkit-mask-image: linear-gradient(#000 85%, transparent); mask-image: linear-gradient(#000 85%, transparent); }
.r-more { margin-left: 14px; font: 400 11px/1 var(--f-mono); color: var(--ink-2); text-transform: none; letter-spacing: 0; }
.row { font-variant-numeric: tabular-nums; display: grid; grid-template-columns: 36px 1fr 1.7fr 104px; gap: 16px; padding: 6px 12px; border-bottom: 1px solid var(--line);
  font: 400 11.5px/1.45 var(--f-mono); align-items: start; }
.row .id { font-weight: 600; }
.row .what { font-family: var(--f-sans); font-size: 12.5px; line-height: 1.35; }
.row .act { text-align: right; font-weight: 600; }
.row .act small { display: block; font-weight: 400; color: var(--ink-2); font-size: 10px; }
.hashes { display: flex; flex-wrap: wrap; gap: 2px 8px; }
.h { text-decoration: none; border-bottom: 1px solid var(--line); white-space: nowrap; }
.h i { font-style: normal; color: var(--ink-2); margin-right: 3px; }
.h.pending { visibility: hidden; }
.h.print { animation: print .12s ease-out both; }
@keyframes print { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.row.fresh { background: var(--ground); box-shadow: inset 3px 0 0 var(--ink); }
.readback { color: var(--ink-2); font-size: 10px; }
.r-stats { display: flex; flex-direction: column; gap: 7px; font: 400 12px/1.3 var(--f-mono); }
.st b { display: block; font: 600 11px var(--f-sans); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 3px; }
.st .n { color: var(--ink-2); }
.st-note { font-size: 10px; color: var(--ink-3); line-height: 1.4; }

/* ---------- debug switcher */
.debug { position: fixed; right: 12px; bottom: 12px; display: flex; gap: 4px; align-items: center; padding: 6px; border-radius: 6px;
  background: var(--ground); border: 1px solid var(--line); box-shadow: var(--shadow); font: 500 11px var(--f-mono); z-index: 10; }
.debug button { font: inherit; border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 4px; padding: 4px 7px; cursor: pointer; }
.debug button[aria-pressed="true"] { background: var(--ink); color: var(--ground); }
.dbg-l { color: var(--ink-3); margin: 0 2px 0 6px; }
.debug { display: none; }
body.debug-on .debug { display: flex; }

/* ---------- mobile 390 */
@media (max-width: 720px) {
  .app { display: flex; flex-direction: column; padding: 56px 16px 80px; }
  .owner { display: contents; }
  .owner > .overline { display: none; }
  .topbar { order: 0; height: auto; padding: 10px 0; flex-direction: column; align-items: flex-start; gap: 6px; }
  .brand span { display: block; margin-top: 2px; }
  .topmeta { flex-wrap: wrap; gap: 6px 10px; margin-left: 0; }
  .topmeta > span { white-space: normal; }
  .modes { flex-wrap: wrap; }
  /* compact headline bar, fixed (really sticks) */
  /* fixed chrome on a phone: 56 px headline + 64 px STOP bar = 120 px, 14 % of an 844 px screen */
  .headline { position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 8; margin: 0; padding: 6px 16px 0;
    background: var(--ground); border-bottom: 1px solid var(--line);
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; }
  .hl-label { grid-column: 1 / 3; font-size: 11px; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hl-num { grid-column: 1; font-size: 34px; margin-top: 1px; line-height: 1; }
  .hl-sub { grid-column: 2; align-self: center; margin: 0; font-size: 11px; line-height: 1.3; color: var(--ink-2); }
  .hl-note { display: none; }
  .field { order: 1; padding-top: 52px; margin-top: 4px; }
  .facts { order: 2; margin-top: 18px; }
  .receipts { order: 3; margin-top: 18px; }
  .stopwrap { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: 64px; background: var(--ground); padding: 8px 16px;
    border-top: 1px solid var(--line); margin: 0; }
  .stop { max-width: none; height: 47px; font-size: 16px; padding-left: 22px; }
  .stop-hint { order: 2; margin-top: 14px; max-width: none; }
  .legend { top: 0; left: 0; right: auto; flex-direction: column; align-items: flex-start; gap: 6px; font-size: 12px; }
  .clock { order: 1; position: sticky; top: 56px; z-index: 5; margin: 8px 0 0; background: var(--ground); padding: 4px 0; }
  .clock-t { font-size: 16px; padding: 5px 8px; min-width: 80px; }
  .camchip { order: 1; }
  .receipts { border-top: 1px solid var(--line); }
  .r-cols { display: none; }
  .r-body { display: flex; flex-direction: column; }
  .r-list { max-height: 560px; background: transparent; display: flex; flex-direction: column; gap: 8px; }
  .row { grid-template-columns: 40px 1fr; background: var(--ground-inset); border-radius: 4px; border: 0; }
  .row .hashes, .row .what { grid-column: 2; }
  .row .act { grid-column: 2; text-align: left; }
  .debug { bottom: 72px; right: 8px; left: 8px; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
