:root {
  --bg: #f4f5f7; --panel: #ffffff; --fg: #1c1f24; --muted: #6b7280; --line: #d9dde3;
  --accent: #2563eb; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --chart-fg: #4b5563; --chart-grid: rgba(0,0,0,.08);
  --c1: #2563eb; --c2: #d97706; --c3: #059669; --c4: #db2777; --c5: #7c3aed;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --panel: #1a1d23; --fg: #e5e7eb; --muted: #9ca3af; --line: #2d323b;
    --accent: #60a5fa; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --chart-fg: #9ca3af; --chart-grid: rgba(255,255,255,.08);
    --c1: #60a5fa; --c2: #fbbf24; --c3: #34d399; --c4: #f472b6; --c5: #a78bfa; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
header h1 { font-size: 15px; margin: 0; font-weight: 600; }
nav { display: flex; gap: 4px; }
nav button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
main { padding: 12px 16px 40px; max-width: 1800px; margin: 0 auto; }
button, select, input { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.icon { padding: 2px 6px; min-width: 28px; }
input[type=range] { padding: 0; vertical-align: middle; }
code { font: 12px ui-monospace, Menlo, monospace; word-break: break-all; }
.muted { color: var(--muted); }
.ok { color: var(--ok); font-weight: 600; } .no { color: var(--bad); font-weight: 600; }
.hidden { display: none !important; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.row label { display: inline-flex; gap: 4px; align-items: center; }
.spacer { flex: 1; }
.scroll { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
table.kv th { text-align: left; padding: 2px 10px 2px 0; color: var(--muted); font-weight: 500; white-space: nowrap; vertical-align: top; }
table.kv td { padding: 2px 0; }
.fam-hevc10 td:first-child, .fam-hevc td:first-child { font-weight: 600; }
.status { font-size: 12px; }

/* multiview grid */
#grid { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); }
.tile { background: #000; border: 2px solid transparent; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.tile.selected { border-color: var(--accent); }
.tile .bar { display: flex; gap: 4px; align-items: center; padding: 4px 6px; background: var(--panel); flex-wrap: wrap; font-size: 12px; }
.tile .bar select { padding: 1px 4px; font-size: 12px; }
.badge { border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; font-size: 11px; white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.warn { color: var(--warn); border-color: var(--warn); } .badge.bad { color: var(--bad); border-color: var(--bad); }
.badge.rend-pro { background: var(--c5); color: #fff; border-color: var(--c5); }
.badge.rend-mid { background: var(--c3); color: #fff; border-color: var(--c3); }
.badge.rend-legacy { background: var(--c2); color: #000; border-color: var(--c2); }
.stage { position: relative; aspect-ratio: 16 / 9; background: #000; }
.stage:fullscreen { aspect-ratio: auto; }
.stage video.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* The incoming session (make-before-break) sits BELOW the current one, fully
   "visible" for the browser: with opacity 0 Chrome stalls its rendering
   (measured: only the first frame, then ~2 s gap after the swap). */
.stage video.layer { z-index: 1; }
.stage video.incoming { z-index: 0; pointer-events: none; }
.stage .msg { position: absolute; left: 8px; bottom: 8px; color: #ddd; font-size: 12px; z-index: 2; text-shadow: 0 0 3px #000; }
.stage .clock { position: absolute; right: 6px; bottom: 6px; z-index: 2; font: 600 13px ui-monospace, Menlo, monospace; color: #fff; background: rgba(0,0,0,.6); padding: 1px 6px; border-radius: 4px; }
.stage .freeze { position: absolute; inset: 0; z-index: 3; background: #000; display: flex; flex-direction: column; }
.stage .freeze canvas { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.freeze-info { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 6px; background: rgba(20,20,20,.9); color: #fff; font-size: 13px; }
.freeze-info input { width: 13em; background: #222; color: #fff; }

/* details */
#details .charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px; }
#details canvas { width: 100%; height: 120px; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
#details .nums { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 2px 12px; font-size: 13px; margin-top: 8px; }
#details .nums div span { color: var(--muted); }
#ctrlLog, #eventLog { font: 12px ui-monospace, Menlo, monospace; max-height: 180px; overflow: auto; white-space: pre-wrap; margin: 0; }
pre.json { font: 12px ui-monospace, Menlo, monospace; max-height: 360px; overflow: auto; margin: 0; }

@media (max-width: 700px) {
  header { padding: 6px 10px; }
  main { padding: 8px 8px 40px; }
  #grid { grid-template-columns: 1fr !important; }
}

.badge.ep-local { background: var(--ok); color: #fff; border-color: var(--ok); }
.badge.ep-cloud { background: var(--accent); color: #fff; border-color: var(--accent); }
#endpoints { width: 100%; font: 12px ui-monospace, Menlo, monospace; }
#details .nums div:first-child { grid-column: 1 / -1; }
#proParams label { font-size: 12px; }

/* stats for nerds overlay */
.nerd { position: absolute; left: 6px; top: 6px; z-index: 4; max-width: min(460px, calc(100% - 12px)); max-height: calc(100% - 12px); overflow: auto;
  background: rgba(10,10,10,.78); color: #eee; font: 11px/1.35 ui-monospace, Menlo, monospace; padding: 6px 22px 6px 8px; border-radius: 6px; }
.nerd table { border-collapse: collapse; }
.nerd th { text-align: left; color: #9ca3af; font-weight: 500; padding: 0 8px 0 0; vertical-align: top; white-space: nowrap; }
.nerd td { padding: 0; }
.nerd .dim { color: #9ca3af; } .nerd .warn { color: #fbbf24; font-weight: 700; }
.nerd-bg { background: #b45309; color: #fff; padding: 2px 6px; margin: 0 0 4px; border-radius: 3px; font-weight: 700; }
.nerd-sug { background: #1d4ed8; color: #fff; padding: 2px 6px; margin: 0 0 4px; border-radius: 3px; }
.nerd-sid { margin-top: 4px; } .nerd-sid code { user-select: all; font-size: 10px; }
.nerd button { font: 10px system-ui; padding: 0 5px; background: #333; color: #eee; border-color: #555; }
.nerd-x { position: absolute; right: 3px; top: 3px; }
@media (max-width: 700px) { .nerd { font-size: 10px; max-width: calc(100% - 12px); } }
.tile { container-type: inline-size; }
@container (max-width: 520px) { .nerd { font-size: 9.5px; padding: 4px 18px 4px 6px; } .nerd tr.opt { display: none; } .nerd-sid code { font-size: 9px; } }
