:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1f242c;
  --line: #2b313b;
  --text: #e8ebef;
  --muted: #8f99a6;
  --accent: #4f8cff;
  --ok: #2fbf71;
  --warn: #f0a63a;
  --live: #e5383b;
  --radius: 10px;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: grid; gap: 12px; }

button, select, input, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}
input, select, textarea { width: 100%; }
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #4a5260; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: #ff8a8c; }
button.ghost { background: transparent; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
label.check input { width: auto; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.topbar { display: flex; gap: 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.topbar .title { font-weight: 650; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.live { background: var(--live); } .dot.bad { background: var(--live); }

/* level meter */
.meter { --level: 0; --peak: 0; position: relative; height: 10px; border-radius: 5px; background: #0a0c0f; overflow: hidden; border: 1px solid var(--line); }
.meter::before { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, var(--ok) 0 70%, var(--warn) 70% 88%, var(--live) 88%);
  clip-path: inset(0 calc((1 - var(--level)) * 100%) 0 0); }
.meter::after { content: ""; position: absolute; top: 0; bottom: 0; width: 2px; left: calc(var(--peak) * 100%); background: #fff8; }
.meter.clip { box-shadow: 0 0 0 1px var(--live); }

/* overlay (device setup) */
.overlay { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; padding: 16px; z-index: 50; overflow: auto; }
.overlay .panel { width: min(520px, 100%); }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; background: #2a313b; padding: 10px 16px; border-radius: 8px; z-index: 100; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.banner { padding: 12px 14px; border-radius: 8px; background: #3a2a10; border: 1px solid var(--warn); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Chat */
.chat { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; height: 100%; }
.chat .tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.chat .tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat .log { overflow-y: auto; display: grid; align-content: start; gap: 6px; padding-right: 4px; min-height: 120px; }
.chat .msg { background: var(--panel-2); border-radius: 8px; padding: 6px 10px; }
.chat .msg .meta { font-size: 12px; color: var(--muted); }
.chat .msg.control { border-left: 3px solid var(--warn); }
.chat form { display: flex; gap: 6px; margin-top: 8px; }
.tabs .badge { background: var(--live); color: #fff; border-radius: 99px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

video { width: 100%; background: #000; border-radius: 8px; display: block; aspect-ratio: 16 / 9; object-fit: contain; }

@media (max-width: 640px) { body { font-size: 16px; } }
