:root {
  /* crash-test lab: dummy-marker yellow on cool graphite */
  --bg: #0a0d12; --panel: #10141b; --card: #151a23; --line: #232a36; --text: #e4e8ee; --dim: #8791a1;
  --accent: #f2c200; --accent-ink: #14120a; --accent2: #ffd84a; --ok: #43c98f; --err: #ff6b5e;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  /* chart ink (dark categorical steps, validated against the card surface #151a23) */
  --viz-grid: #232a35; --viz-base: #39414e; --viz-tick: #8791a1; --viz-cursor: #f2c200;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--body); }
#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
#panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; padding: 14px 14px 30px; min-width: 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 4px 14px; }
.brand h1 { margin: 0; font: 600 24px/1 var(--display); letter-spacing: .5px; text-transform: uppercase; }
.brand span { color: var(--dim); font-size: 12px; }
.brand div { display: flex; flex-direction: column; }
/* build stamp: lets you tell on the phone which version you are actually looking at */
.brand .build { font: 10px/1.4 var(--mono); color: #6b7480; letter-spacing: .3px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font: 600 15px/1.2 var(--display); text-transform: uppercase; letter-spacing: 1.2px; color: #cfd4db; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 700 12px/1 var(--mono); }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--dim); margin-bottom: 9px; font-size: 12px; }
.field.range { display: grid; grid-template-columns: 1fr 64px; grid-template-rows: auto auto; column-gap: 8px; }
.field.range span { grid-column: 1 / 3; }
.field.range output { text-align: right; color: var(--text); font: 12px var(--mono); }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.field select { width: 100%; }
select { min-width: 0; max-width: 100%; }
select, button, .btn { font: inherit; color: var(--text); background: #1d222b; border: 1px solid #2c3340; border-radius: 8px; padding: 7px 9px; }
select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .btn { cursor: pointer; text-align: center; }
button:hover:not(:disabled), .btn:hover { background: #252b36; }
button:disabled { opacity: .45; cursor: default; }
button.primary { width: 100%; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font: 600 16px/1.2 var(--display); letter-spacing: .8px; text-transform: uppercase; padding: 10px; }
button.primary:hover:not(:disabled) { background: var(--accent2); }
button.primary.danger { background: #3a1f1f; border-color: #7a2d2d; color: var(--text); }
input[type=range] { accent-color: var(--accent); width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 2px 0 10px; color: var(--dim); }
.checks label { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.checks input { accent-color: var(--accent); }
.hint { color: var(--dim); font-size: 12px; margin: 2px 0 10px; }
.progress { height: 5px; background: #0d1015; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .15s; }
.status { color: var(--dim); font: 11.5px/1.5 var(--mono); margin-top: 6px; min-height: 18px; font-variant-numeric: tabular-nums; white-space: pre-line; }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.info-grid div { background: #0f1217; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.info-grid b { display: block; font: 500 14px/1.3 var(--mono); }
.info-grid small { color: var(--dim); }
.compact h2 { margin-bottom: 8px; }
#result video { width: 100%; border-radius: 8px; margin-top: 10px; background: #000; }
#result a { display: block; margin-top: 8px; color: var(--accent2); }

#viewport { position: relative; overflow: hidden; background: #000; min-height: 0; }
#view { width: 100%; height: 100%; display: block; touch-action: none; }
#hud { position: absolute; top: 12px; left: 12px; background: rgba(10,12,16,.62); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 8px 11px; font: 12px/1.5 var(--mono); pointer-events: none; white-space: pre; color: #dfe3e8; }
#toast { position: absolute; top: 12px; right: 12px; background: rgba(10,12,16,.75); border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 8px 12px; max-width: 360px; }
#timeline { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 10px; background: rgba(10,12,16,.7); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 7px 10px; }
#timeline .icon { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border-radius: 50%; background: var(--accent); border: 0; color: var(--accent-ink); }
#timeLabel { width: 84px; font: 12px var(--mono); color: #cfd4db; }
.scrub { position: relative; flex: 1; height: 22px; display: flex; align-items: center; }
.scrub::before { content: ""; position: absolute; left: 0; right: 0; height: 4px; background: #2a2f38; border-radius: 2px; }
#buffered { position: absolute; left: 0; height: 4px; width: 0; background: #5c5220; border-radius: 2px; }
#scrub { position: relative; margin: 0; background: transparent; }
#timeline select { padding: 5px 6px; }
.live { display: flex; gap: 5px; align-items: center; color: var(--dim); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  #viewport { grid-row: 1; height: 58vh; }
  #panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
  #timeLabel { width: 58px; }
  .live { display: none; }
}

@media (prefers-reduced-motion: reduce) { .progress div { transition: none; } }

.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.presets button { padding: 6px 2px; font-size: 12px; }
.presets button.active { border-color: var(--accent); color: var(--accent); }

.analysis { position: relative; }
.an-wrap { position: relative; }
.an-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.an-gridline { stroke: var(--viz-grid); stroke-width: 1; }
.an-base { stroke: var(--viz-base); stroke-width: 1; }
.an-tick { fill: var(--viz-tick); font: 9px var(--mono); font-variant-numeric: tabular-nums; }
.an-label { fill: var(--text); font: 600 10px var(--mono); }
.an-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.an-peak { stroke: var(--card); stroke-width: 2; }
.an-cursor { stroke: var(--viz-cursor); stroke-width: 1; }
.an-cross { stroke: var(--dim); stroke-width: 1; }
.an-wrap rect:focus-visible { outline: none; stroke: var(--accent); stroke-width: 1; }
.an-line.s1 { stroke: var(--s1); } .an-line.s2 { stroke: var(--s2); } .an-line.s3 { stroke: var(--s3); } .an-line.s4 { stroke: var(--s4); }
.an-line.s5 { stroke: var(--s5); } .an-line.s6 { stroke: var(--s6); } .an-line.s7 { stroke: var(--s7); } .an-line.s8 { stroke: var(--s8); }
.an-peak.s1 { fill: var(--s1); } .an-peak.s2 { fill: var(--s2); } .an-peak.s3 { fill: var(--s3); } .an-peak.s4 { fill: var(--s4); }
.an-peak.s5 { fill: var(--s5); } .an-peak.s6 { fill: var(--s6); } .an-peak.s7 { fill: var(--s7); } .an-peak.s8 { fill: var(--s8); }
.an-key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; margin-right: 6px; vertical-align: middle; background: var(--s1); }
.an-key.s2 { background: var(--s2); } .an-key.s3 { background: var(--s3); } .an-key.s4 { background: var(--s4); } .an-key.s5 { background: var(--s5); }
.an-key.s6 { background: var(--s6); } .an-key.s7 { background: var(--s7); } .an-key.s8 { background: var(--s8); }
.an-table { margin-top: 8px; display: grid; gap: 2px; font-size: 12px; }
.an-row { display: grid; grid-template-columns: 1fr 44px 58px 58px; gap: 6px; align-items: center; padding: 3px 0; border-top: 1px solid var(--line); }
.an-row span:not(:first-child) { text-align: right; font: 12px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.an-row span:first-child { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-head { border-top: 0; color: var(--dim); }
.an-head span, .an-head span:not(:first-child) { color: var(--dim); font: 11px var(--body); }
.an-tip { position: absolute; top: 4px; left: 0; pointer-events: none; background: #0c0f14; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 11px; white-space: nowrap; z-index: 2; }
.an-tip-time { color: var(--dim); font: 10px var(--mono); margin-bottom: 3px; }
.an-tip-row { display: flex; align-items: center; gap: 4px; line-height: 1.5; }
.an-tip-row b { font: 600 11px var(--mono); color: var(--text); min-width: 44px; }
.an-tip-row span { color: var(--dim); }

.toggle { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; margin: 0 0 9px; }
.toggle input { accent-color: var(--accent); }
