:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #687085;
  --line: #dde1e8;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c93a3a;
  --ok: #2e9e5b;
  --warn: #c98a1a;
  --mine: #e6efff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --card: #1d2129;
    --text: #e6e8ee;
    --muted: #98a0b3;
    --line: #2e3440;
    --accent: #5b8ff0;
    --mine: #23324d;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
main { padding: 16px; max-width: 1200px; margin: 0 auto; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { border: 0; background: none; padding: 8px 12px; border-radius: 6px; }
nav button.active { background: var(--accent); color: var(--accent-text); }
#whoami { margin-left: auto; display: flex; gap: 8px; align-items: center; }
button {
  font: inherit; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
input:not([type]), input[type=text] {
  font: inherit; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); flex: 1; min-width: 0;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 520px; margin: 40px auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.chat { grid-template-columns: 260px 1fr; }
.grid.live { grid-template-columns: 2fr 1fr; }
@media (max-width: 760px) { .grid.chat, .grid.live { grid-template-columns: 1fr; } }
.grid > .card { margin-bottom: 0; }
.tab { display: block; }
.tab[hidden] { display: none; }
.tab > .grid { margin-bottom: 16px; }
progress { width: 100%; height: 10px; }
video { width: 100%; max-height: 60vh; background: #000; border-radius: 8px; }
#live-preview { max-height: 240px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 8px; border-radius: 6px; border: 1px solid transparent;
}
.list li.clickable { cursor: pointer; }
.list li.clickable:hover, .list li.selected { border-color: var(--line); background: var(--bg); }
.list li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--line); }
.state.ready, .state.live { background: var(--ok); color: #fff; }
.state.failed { background: var(--danger); color: #fff; }
.state.processing, .state.uploading, .state.starting { background: var(--warn); color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.online { background: var(--ok); }
.badge { background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 12px; }
.room { display: flex; flex-direction: column; min-height: 480px; }
.room-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.messages { list-style: none; margin: 0; padding: 8px 0; flex: 1; overflow-y: auto; max-height: 55vh; }
.messages li { margin: 6px 0; padding: 6px 10px; border-radius: 8px; background: var(--bg); max-width: 80%; word-wrap: break-word; }
.messages li.mine { margin-left: auto; background: var(--mine); }
.messages li.system { background: none; color: var(--muted); font-size: 12px; text-align: center; max-width: none; }
.messages .who { font-size: 12px; color: var(--muted); }
.messages .raw { display: block; font: 11px/1.3 ui-monospace, monospace; color: var(--muted); word-break: break-all; margin-top: 4px; }
.banner { padding: 8px 12px; border-radius: 6px; background: var(--mine); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; margin-top: 8px; }
.tile { position: relative; }
.tile video { max-height: 40vh; }
.tile .name { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.live-chat { display: flex; flex-direction: column; }
.live-chat .messages { max-height: 40vh; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); min-width: 300px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: .95; }
.fp { font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; }
.fp.big { font-size: 15px; margin: 6px 0; }
.ask { border-color: var(--accent); }
