:root {
  --bg: #090d16;
  --panel: #0f1623;
  --panel-2: #162032;
  --panel-3: #1d2a40;
  --line: #233148;
  --line-focus: #38bdf8;
  --ink: #e2e8f0;
  --muted: #8e9bb0;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-bg: rgba(56, 189, 248, 0.12);
  --success: #34d399;
  --warn: #f59e0b;
  --danger: #ef4444;
  --teamA: #2563eb;
  --teamB: #ea580c;
  --other: #64748b;
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font-main); font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--line-focus); outline-offset: 1px; }

h1, h2, h3, h4 { margin: 0 0 8px 0; color: #f8fafc; font-weight: 600; line-height: 1.25; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
h3 { font-size: 13px; font-weight: 600; }

.muted { color: var(--muted); font-size: 12.5px; }
.mini { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 48px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: #fff; letter-spacing: -0.01em; }
header.top nav { display: flex; gap: 16px; font-size: 13px; font-weight: 500; }
header.top nav a { color: var(--muted); }
header.top nav a:hover { color: var(--ink); text-decoration: none; }
.badge {
  border: 1px solid rgba(52, 211, 153, 0.3); border-radius: 999px; padding: 2px 8px;
  font-size: 11px; font-weight: 500; color: var(--success); background: rgba(52, 211, 153, 0.08);
}

main.workbench {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(380px, 1fr);
  height: calc(100vh - 48px); overflow: hidden;
}

#stage { display: flex; flex-direction: column; min-width: 0; background: #030509; border-right: 1px solid var(--line); }

.videowrap {
  position: relative; flex: 1; min-height: 0; background: #000;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.videowrap video { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; object-fit: contain; }
.videowrap canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.videowrap.calibrating, .videowrap.picking { cursor: crosshair; }
.videowrap.picking canvas { pointer-events: auto; }

#dropzone {
  position: absolute; inset: 24px; border: 2px dashed var(--line); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 32px; background: rgba(9, 13, 22, 0.85);
  backdrop-filter: blur(4px); transition: border-color 0.15s, background-color 0.15s;
}
#dropzone.drag { border-color: var(--accent); background: rgba(56, 189, 248, 0.1); }
#dropzone h2 { font-size: 18px; color: #fff; text-transform: none; letter-spacing: normal; }

.transport-container { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.transport { display: flex; align-items: center; gap: 10px; width: 100%; }

.transport button#playBtn {
  width: 32px; height: 32px; border-radius: var(--radius); background: var(--accent); color: #000;
  border: none; font-size: 12px; font-weight: bold; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.transport button#playBtn:hover { background: #7dd3fc; }

input[type="range"]#seek {
  flex: 1; height: 6px; appearance: none; background: var(--panel-3); border-radius: 3px; cursor: pointer; margin: 0;
}
input[type="range"]#seek::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}
input[type="range"]#seek::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}

#timeLabel { font-family: var(--font-mono); font-size: 12px; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }

select#speedSel {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 3px 6px; font-size: 12px; font-family: var(--font-mono); cursor: pointer;
}

#statLine { font-family: var(--font-mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

#markers { position: relative; height: 8px; flex: 1; background: var(--panel-3); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 500;
  white-space: nowrap; transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--panel-3); border-color: var(--muted); }
.btn.primary { background: var(--accent); color: #041321; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #7dd3fc; border-color: #7dd3fc; }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; background: var(--panel-3); color: var(--muted); border-color: var(--line); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.danger { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn.danger:hover { background: rgba(239, 68, 68, 0.25); border-color: var(--danger); }

input[type="text"], input[type="number"], select {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px; font-size: 13px; width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--line-focus); outline: none;
}

label.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
label.field span { font-size: 12px; font-weight: 500; color: var(--muted); }

#panel { display: flex; flex-direction: column; min-width: 0; background: var(--panel); overflow: hidden; }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: #0b111c; flex-shrink: 0; overflow-x: auto; }
.tabs button {
  flex: 1; min-width: max-content; background: transparent; color: var(--muted); border: none;
  border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer; font-size: 12.5px; font-weight: 500;
  text-align: center; transition: color 0.1s, border-color 0.1s;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--panel); font-weight: 600; }

.tabpane { display: none; padding: 14px; overflow-y: auto; flex: 1; }
.tabpane.active { display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.progress { height: 6px; background: var(--panel-3); border-radius: 3px; overflow: hidden; border: 1px solid var(--line); }
.progress i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.1s ease; }

table.data { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
table.data th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--panel); position: sticky; top: 0; }
table.data tr:hover { background: rgba(255, 255, 255, 0.02); }
table.data tr.sel { background: var(--accent-bg); }
table.data td.num, table.data th.num { text-align: right; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.chip { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 500; border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.chip.pass { color: var(--success); border-color: rgba(52, 211, 153, 0.3); background: rgba(52, 211, 153, 0.08); }
.chip.turnover { color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.08); }
.chip.loose { color: var(--muted); }
.chip.recovery { color: var(--accent); border-color: rgba(56, 189, 248, 0.3); background: var(--accent-bg); }

.timeline { max-height: 200px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-3); color: var(--ink); border: 1px solid var(--line-focus);
  border-radius: var(--radius); padding: 8px 16px; font-size: 13px; font-weight: 500;
  z-index: 100; box-shadow: 0 10px 25px rgba(0,0,0,0.5); pointer-events: none;
}
.toast.err { border-color: var(--danger); background: #2a1215; color: #fca5a5; }

.help { font-size: 12px; color: var(--muted); padding-left: 18px; margin: 4px 0; }
.help li { margin-bottom: 4px; }
p.help { padding-left: 0; }
.help kbd {
  background: var(--panel-3); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 4px; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink);
}

#livePreview { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); background: #000; display: block; aspect-ratio: 16/9; }

.caliblist { font-size: 12px; padding-left: 20px; color: var(--muted); margin: 8px 0; }
.caliblist li { margin: 2px 0; }
.caliblist li.done { color: var(--success); font-weight: 500; }

@media (max-width: 1199px) {
  main.workbench { grid-template-columns: 1fr; height: auto; overflow: visible; }
  #stage { border-right: none; border-bottom: 1px solid var(--line); }
  .videowrap { min-height: 400px; }
  #panel { height: auto; overflow: visible; }
  .tabpane { overflow: visible; }
}

@media (max-width: 720px) {
  header.top .badge { display: none; }
  .videowrap { min-height: 240px; }
  .transport-container { position: sticky; bottom: 0; z-index: 10; border-bottom: 1px solid var(--line); }
}
