:root {
  --paper: #fefefe;
  --ink: #1e1e1e;
  --dim: #6b6b6b;
  --rule: #1e1e1e;
  --pink: #f386a1;
  --hatch: #f6c3d0;
  --band: #f386a1;
  --band-ink: #3a3a3a;
  --band-label: #1e1e1e;
  --window: #dedede;
  --band-rule: solid;
  --bad: #c2334f;
  color-scheme: light;
  --sans: "Inter Tight", ui-sans-serif, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --term: "VT323", "JetBrains Mono", ui-monospace, monospace;
  --pad: clamp(16px, 4vw, 48px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --paper: #1e1e1e;
  --ink: #fefefe;
  --dim: #a9a9a9;
  --rule: #fefefe;
  --hatch: #6b3a49;
  --band: #161616;
  --band-ink: #fefefe;
  --band-label: #fefefe;
  --band-rule: dashed;
  --window: #2e2e2e;
  --bad: #ff8fa8;
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1e1e1e;
  --ink: #fefefe;
  --dim: #a9a9a9;
  --rule: #fefefe;
  --hatch: #6b3a49;
  --band: #161616;
  --band-ink: #fefefe;
  --band-label: #fefefe;
  --band-rule: dashed;
  --window: #2e2e2e;
  --bad: #ff8fa8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.35; }

/* ---- top bar: small white tags, black one for status ---- */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 0; pointer-events: none; }
.top > * { pointer-events: auto; }
.tag { display: inline-block; border: 0; min-height: 0; color: var(--ink); background: var(--paper); padding: 6px 8px; font-size: 18px; font-weight: 500; letter-spacing: 0.03em; }

.top-right { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.tag.mono { font-family: var(--mono); font-size: 12px; font-weight: 400; padding: 9px 8px; color: var(--dim); }
.cost:empty { display: none; }
.pill { display: inline-block; font-family: var(--mono); font-size: 12px; padding: 4px 8px; background: var(--window); color: var(--ink); letter-spacing: 0.02em; }
.pill:empty { display: none; }
.pill.ok { background: var(--ink); color: var(--paper); }
.top .pill { padding: 9px 8px; }
.top .pill.ok::before { content: "● "; color: var(--pink); }
.top .pill.warn::before { content: "○ "; color: var(--pink); }

.tag.invert { background: var(--ink); color: var(--paper); cursor: pointer; min-width: 64px; }
.tag.invert:hover { background: var(--pink); color: #1e1e1e; }

/* ---- hero: a huge tight grotesk name ---- */
.hero { padding: clamp(48px, 10vw, 120px) var(--pad) clamp(32px, 6vw, 72px); text-align: center; }
.kicker { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 0 0 clamp(16px, 3vw, 32px); font-size: 17px; letter-spacing: 0.05em; }
.leader { flex: 0 1 140px; border-bottom: 2px dotted var(--ink); transform: translateY(-4px); }
h1 { margin: 0 auto; max-width: 12ch; font-size: clamp(64px, 13vw, 168px); font-weight: 500; line-height: 0.82; letter-spacing: -0.045em; text-wrap: balance; }

.transport { display: flex; justify-content: center; gap: clamp(20px, 5vw, 64px); margin-top: clamp(32px, 6vw, 64px); flex-wrap: wrap; }
.transport button { background: none; border: 0; padding: 4px 0; min-height: 44px; font-family: var(--sans); font-size: clamp(28px, 4.5vw, 56px); font-weight: 500; letter-spacing: -0.02em; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.12em; color: var(--ink); cursor: pointer; }
.transport button:hover { text-decoration-color: var(--pink); }
.msg { min-height: 1.4em; margin: 16px 0 0; font-family: var(--mono); font-size: 13px; color: var(--dim); }
.transport button.primary::before { content: "▶ "; font-size: 0.6em; vertical-align: 0.15em; text-decoration: none; display: inline-block; margin-right: 0.2em; }

main { display: flex; flex-direction: column; }

/* ---- retro window: title bar + grey body ---- */
.window { margin: 0 var(--pad); border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 2px; background: var(--paper); }
.window-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--ink); color: var(--paper); font-family: var(--term); font-size: 20px; line-height: 1; padding: 4px 6px; list-style: none; cursor: default; }
.window-title::-webkit-details-marker { display: none; }
.window-body { padding: 12px; }
#pos { font-family: var(--term); font-size: 20px; font-variant-numeric: tabular-nums; }

.status { display: flex; gap: 12px; align-items: center; min-height: 0; font-family: var(--term); font-size: 18px; color: var(--dim); }
.status:has(#trk:empty) { margin-bottom: 0; }
#trk:not(:empty) { margin-bottom: 10px; }
.meter { width: 80px; height: 6px; background: var(--window); overflow: hidden; display: none; }
.meter:has(i[style*="width"]) { display: inline-block; }
.meter i { display: block; height: 100%; width: 0; background: var(--ink); }

.grid { counter-reset: bar; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--ink); border-left: 1px solid var(--ink); }
.bar { position: relative; display: flex; gap: 6px; min-height: clamp(52px, 7vw, 72px); padding: 8px 10px; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); font-family: var(--term); font-size: clamp(20px, 2.4vw, 28px); line-height: 1; background: var(--paper); transition: background 0.06s; }
.bar span { flex: 1; }
.bar::after { counter-increment: bar; content: counter(bar); position: absolute; right: 6px; bottom: 4px; font-family: var(--mono); font-size: 9px; color: var(--dim); }
.bar.phrase { background: repeating-linear-gradient(45deg, var(--paper) 0 3px, var(--hatch) 3px 4px); }
.bar.now { background: var(--pink); color: #1e1e1e; }
.bar.now::after { color: #1e1e1e; }

/* ---- label-over-rule columns ---- */
.label { display: block; font-family: var(--mono); font-size: 12px; font-weight: 400; letter-spacing: 0.06em; color: var(--ink); padding: 0; margin-bottom: 14px; }
.col { position: relative; display: flex; flex-direction: column; gap: 10px; padding-left: 10px; border-left: 1px solid var(--rule); min-width: 0; }
.col .label { margin-bottom: 4px; }

.crop { position: relative; margin: clamp(40px, 7vw, 80px) var(--pad) 0; padding: 28px 0 8px; }
.crop::before, .crop::after { content: ""; position: absolute; top: 0; width: 10px; height: 10px; border-top: 1px solid var(--ink); }
.crop::before { left: 0; border-left: 1px solid var(--ink); }
.crop::after { right: 0; border-right: 1px solid var(--ink); }

.phrase { display: grid; grid-template-columns: 2fr 1.4fr 1fr; gap: 32px clamp(16px, 3vw, 40px); }
.phrase p { margin: 0; }
.lede { font-size: clamp(20px, 2.2vw, 26px); line-height: 1.15; letter-spacing: -0.01em; }
#phraseDesc, .harmony .src, .judge { color: var(--dim); font-size: 15px; line-height: 1.4; }
.harmony { font-size: 17px; line-height: 1.35; display: flex; flex-direction: column; gap: 6px; }
.harmony .fn { background: var(--ink); color: var(--paper); font-family: var(--term); font-size: 19px; padding: 1px 4px; line-height: 1.45; -webkit-box-decoration-break: clone; box-decoration-break: clone; }

/* ---- controls: pink band ---- */
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 36px clamp(16px, 3vw, 40px); margin-top: clamp(40px, 7vw, 80px); padding: clamp(32px, 5vw, 56px) var(--pad); background: var(--band); color: var(--band-ink); }
.controls .col { border-left: 1px var(--band-rule) var(--band-ink); }
.controls .label { color: var(--band-label); }
.controls .wide { grid-column: span 2; }
fieldset { margin: 0; padding: 0 0 0 10px; border: 0; border-left: 1px var(--band-rule) var(--band-ink); }
legend { float: left; width: 100%; }

input, select, textarea, button { font: inherit; color: var(--ink); border-radius: 0; }
select, input[type=number], textarea { width: 100%; min-height: 44px; padding: 8px 10px; background: var(--paper); border: 1px solid var(--ink); appearance: none; -webkit-appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: right 16px center, right 11px center; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { font-family: var(--mono); font-size: 13px; line-height: 1.45; resize: vertical; }
input[type=number] { font-family: var(--mono); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

button { cursor: pointer; background: var(--ink); color: var(--paper); border: 1px solid var(--ink); padding: 8px 14px; min-height: 44px; font-weight: 500; }
button:hover { background: var(--paper); color: var(--ink); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
label.choice { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; }
#latencyVal { font-family: var(--mono); font-size: 12px; }

input[type=radio], input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 0; flex: none; background: var(--paper); border: 1px solid var(--ink); display: grid; place-items: center; cursor: pointer; }
input[type=radio] { border-radius: 50%; }
input[type=radio]:checked::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
input[type=checkbox]:checked { background: var(--ink); }
input[type=checkbox]:checked::after { content: "✓"; color: var(--paper); font-size: 13px; line-height: 1; }

input[type=file] { font-family: var(--mono); font-size: 12px; max-width: 100%; margin: -6px 0 0 28px; }
input[type=file]::file-selector-button { font: inherit; background: var(--paper); border: 1px solid var(--ink); padding: 6px 10px; margin-right: 8px; cursor: pointer; }

input[type=range] { appearance: none; -webkit-appearance: none; width: 100%; height: 32px; background: transparent; padding: 0; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type=range]::-moz-range-track { height: 1px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -7px; background: var(--ink); border: 0; border-radius: 0; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; background: var(--ink); border: 0; border-radius: 0; }

label.switch { flex-direction: row; align-items: center; gap: 12px; min-height: 44px; font-size: 17px; cursor: pointer; }
label.switch input { width: 46px; height: 26px; border-radius: 0; position: relative; display: block; background: var(--paper); }
label.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: var(--ink); transition: transform 0.12s; }
label.switch input:checked { background: var(--ink); }
label.switch input:checked::after { content: ""; transform: translateX(20px); background: var(--pink); }
.hint { margin: 0; font-size: 14px; line-height: 1.4; opacity: 0.8; }

details > summary { cursor: pointer; font-size: 15px; min-height: 32px; display: flex; align-items: center; }
details[open] { display: flex; flex-direction: column; gap: 8px; }
.error { color: var(--bad); font-size: 13px; white-space: pre-wrap; }
.error:empty { display: none; }



.log { margin-top: clamp(40px, 7vw, 80px); }
.log > summary { cursor: pointer; padding: 6px; }
#log { margin: 0; max-height: 220px; overflow: auto; background: var(--window); font-family: var(--term); font-size: 17px; line-height: 1.15; white-space: pre-wrap; color: var(--ink); }

footer { padding-bottom: 48px; max-width: 60ch; }
footer p { margin: 0; padding-left: 10px; border-left: 1px solid var(--ink); font-size: 14px; color: var(--dim); }
footer .label { margin-left: 0; }

/* ---- phone ---- */
@media (max-width: 760px) {
  .tag { font-size: 16px; }
  .kicker { font-size: 14px; }
  h1 { font-size: 23vw; line-height: 0.8; }
  .transport { gap: 24px; }
  .transport button { font-size: 32px; }
  .leader { flex-basis: 40px; }
  .bar { flex-direction: column; gap: 2px; font-size: 19px; padding: 6px 6px 14px; }
  .phrase { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr; }
  .controls .wide { grid-column: auto; }
  .window { margin: 0 12px; }
}
@media (min-width: 761px) and (max-width: 1040px) {
  .controls { grid-template-columns: repeat(2, 1fr); }
  .phrase { grid-template-columns: 1fr 1fr; }
  .phrase .wide { grid-column: span 2; }
}
