@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/cormorant-garamond-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/cormorant-garamond-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/dm-sans-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/dm-sans-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "DM Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/dm-mono-latin-400-normal.woff2) format("woff2"); }

:root {
  --ink: #0d0b0b;
  --parchment: #f2f4f3;
  --titanium: #aca597;
  --paloma: #fe857a;
  --pomegranate: #8c1d1b;
  --bordeaux: #330302;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ink); color: var(--parchment); font: 400 16px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
body.flash, body.flash .topbar { background: var(--pomegranate); }
p { margin: 0; }
a { color: var(--paloma); }
:focus-visible { outline: 2px solid var(--parchment); outline-offset: 2px; }
.mono, dd, td.num, .count { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--titanium); }
.center { text-align: center; }
.err { color: var(--paloma); }
.err:empty { display: none; }
.lead { font-size: 20px; font-weight: 500; }
.warn { padding: 12px 14px; border-radius: 6px; background: var(--pomegranate); color: var(--parchment); font-weight: 500; }
code { font-family: var(--mono); font-size: 15px; overflow-wrap: anywhere; }

.topbar { position: sticky; top: 0; z-index: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; min-height: 52px; padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); background: var(--ink); border-bottom: 1px solid var(--bordeaux); }
.topbar h1 { margin: 0; font: 500 22px/1 var(--serif); text-align: center; }
.topbar h1:focus { outline: none; }
.link { display: inline-flex; align-items: center; gap: 8px; font: 400 14px var(--mono); color: var(--titanium); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--titanium); flex: none; }
.dot[data-state="live"] { background: var(--paloma); border-color: var(--paloma); }
.dot[data-state="wait"], .dot[data-state="lost"] { border-color: var(--paloma); }
#debug-link { justify-self: end; display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; font-weight: 500; }

main { max-width: 560px; margin: 0 auto; padding: 24px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.screen { display: flex; flex-direction: column; gap: 20px; }

#start { min-height: calc(100dvh - 52px - 64px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); justify-content: space-between; }
.start-copy { margin-top: 18vh; }
.wordmark { margin: 0 0 12px; font: 500 clamp(64px, 20vw, 104px)/1 var(--serif); }
.wordmark:focus { outline: none; }
.start-copy p { max-width: 26ch; font-size: 18px; color: var(--titanium); }
.start-actions { display: grid; gap: 12px; }
.privacy { justify-self: center; display: inline-flex; align-items: center; min-height: 44px; }
.check { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; cursor: pointer; }
.check input { flex: none; width: 24px; height: 24px; margin: 0; accent-color: var(--paloma); }
.check strong { font-weight: 500; }

button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 12px 18px; border: 1px solid var(--titanium); border-radius: 6px; background: transparent; color: var(--parchment); font: 500 16px/1.2 var(--sans); cursor: pointer; }
button:active:not(:disabled), .button:active { background: var(--bordeaux); }
button.primary { background: var(--paloma); border-color: var(--paloma); color: var(--ink); }
button.primary:active:not(:disabled) { background: var(--parchment); border-color: var(--parchment); }
button:disabled { background: var(--bordeaux); border-color: var(--bordeaux); color: var(--titanium); cursor: not-allowed; }
@media (hover: hover) { button:hover:not(:disabled), .button:hover { border-color: var(--parchment); } }
.wide, #fit-clench { width: 100%; }
.actions { display: flex; gap: 12px; margin-top: 8px; }
.actions > * { flex: 1; }
.actions > .primary { flex: 2; order: 1; }
.stack { display: grid; gap: 12px; }
.stack button { justify-content: flex-start; }
#pair-more .stack { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.field label { display: block; margin-bottom: 6px; font-weight: 500; }
.field input { width: 100%; }
.field + .field { margin-top: 16px; }
input:not([type="checkbox"]):not([type="file"]) { min-height: 48px; padding: 10px 12px; border: 1px solid var(--titanium); border-radius: 6px; background: var(--ink); color: var(--parchment); font: 400 16px var(--sans); }
input::placeholder { color: var(--titanium); opacity: 1; }
input[aria-invalid="true"] { border-color: var(--paloma); }
.field input[readonly] { border-color: var(--bordeaux); }
.field .err, .field .muted { margin-top: 6px; }
details { border-top: 1px solid var(--bordeaux); border-bottom: 1px solid var(--bordeaux); }
summary { padding: 10px 0; color: var(--paloma); font-weight: 500; cursor: pointer; }
details[open] { padding-bottom: 16px; }
#privacy { margin-bottom: 16px; }

dl { margin: 0; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; }
.facts dt { color: var(--titanium); }
.facts dd { margin: 0; font-family: var(--sans); overflow-wrap: anywhere; }
.facts dd .mono { color: var(--titanium); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 16px 0; border-top: 1px solid var(--bordeaux); border-bottom: 1px solid var(--bordeaux); }
.stats dt { font-size: 14px; color: var(--titanium); }
.stats dd { margin: 0; font-size: 24px; line-height: 1.2; overflow-wrap: anywhere; }
.state { font-weight: 500; }
#train .stats { grid-template-columns: 1.5fr 1fr 1fr; }
#train .stats dd { font-size: 20px; overflow-wrap: normal; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 0; border-bottom: 1px solid var(--bordeaux); text-align: left; font-weight: 400; }
thead th { padding-top: 0; font-size: 14px; color: var(--titanium); }
.num { text-align: right; padding-right: 16px; }
.flag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 14px; }
.flag.ok, .flag.off { color: var(--titanium); padding-left: 0; }
.flag.flat, .flag.railed, .flag.noisy { background: var(--pomegranate); color: var(--parchment); }
.result th { color: var(--titanium); }
.result td.num { padding-right: 0; font-size: 18px; }
.result .sub { display: block; font: 400 14px var(--sans); color: var(--titanium); }

.instruction { font-size: 18px; }
.run { display: flex; flex-direction: column; gap: 8px; }
.prompt { display: flex; align-items: center; justify-content: center; min-height: 3.2em; margin-top: 24px; font: 500 clamp(36px, 11vw, 72px)/1.1 var(--sans); text-align: center; overflow-wrap: anywhere; }
.prompt.rest { color: var(--titanium); }
#acc-word { font-size: clamp(30px, 9vw, 56px); }
.count { font-size: 20px; color: var(--titanium); text-align: center; }
.count .sec { font-size: 40px; color: var(--parchment); }

.gate { display: flex; align-items: center; justify-content: center; min-height: 168px; padding: 24px 16px; border: 1px solid var(--bordeaux); border-radius: 8px; font: 500 32px/1.25 var(--sans); text-align: center; color: var(--titanium); overflow-wrap: anywhere; }
.gate[data-state="idle"] { color: var(--parchment); }
.gate[data-state="cue"] { background: var(--bordeaux); border-color: var(--paloma); color: var(--paloma); }
.gate[data-state="act"] { background: var(--pomegranate); border-color: var(--pomegranate); color: var(--parchment); }
#live-label { font-size: 20px; font-weight: 500; }

.log { margin: 0; padding: 12px; max-height: 40vh; overflow: auto; border-radius: 6px; background: var(--bordeaux); color: var(--titanium); font: 400 13px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.log:empty { display: none; }

#debug { gap: 12px; }
#debug h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font: 500 22px/1.2 var(--serif); }
.status { font-size: 14px; color: var(--titanium); }
.status.bad { color: var(--paloma); }
.card { padding: 14px; border-radius: 8px; background: var(--bordeaux); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row + .row { margin-top: 8px; }
.row label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; white-space: nowrap; }
.card button:disabled { background: transparent; border-style: dashed; border-color: var(--titanium); }
.row input:not([type="checkbox"]):not([type="file"]) { flex: 1 1 10em; min-width: 0; }
.row input[type="number"] { flex: 0 0 5em; width: 5em; }
.row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--paloma); }
#pid { flex: 0 1 7em; }
.small { font-size: 14px; }
.card .muted { color: var(--titanium); }
.dstats { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; color: var(--titanium); }
.dstats b { font: 400 14px var(--mono); color: var(--parchment); }
.card .log { margin-top: 10px; max-height: 110px; background: var(--ink); font-size: 12px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 7em minmax(0, 1fr) 3.5em; align-items: center; gap: 8px; font-size: 14px; }
.bar .track { height: 12px; overflow: hidden; border-radius: 6px; background: var(--ink); }
.bar .fill { width: 0; height: 100%; background: var(--paloma); }
.bar.null .fill { background: var(--titanium); }
.bar .p { font-family: var(--mono); text-align: right; }
.badge { padding: 2px 8px; border: 1px solid var(--titanium); border-radius: 4px; font: 400 13px var(--mono); color: var(--titanium); }
.badge.cool { border-color: var(--paloma); color: var(--paloma); }
.badge.cue { background: var(--ink); border-color: var(--paloma); color: var(--paloma); }
.badge.act { background: var(--pomegranate); border-color: var(--pomegranate); color: var(--parchment); }
.delivery { min-height: 44px; margin-bottom: 10px; padding: 10px; border-radius: 6px; background: var(--ink); }
.events { max-height: 220px; margin: 10px 0 0; padding: 0; overflow: auto; list-style: none; font: 400 12px/1.4 var(--mono); overflow-wrap: anywhere; }
.events li { padding: 4px 0; border-top: 1px solid var(--ink); color: var(--titanium); }
.events li b { color: var(--parchment); font-weight: 400; }
