:root {
  --bg: #101114;
  --surface: #191b20;
  --surface-2: #22252c;
  --line: #2e323b;
  --fg: #eceef3;
  --dim: #9aa1b1;
  --accent: #ffcc00;
  --accent-fg: #1a1a1a;
  --ok: #3ecf8e;
  --warn: #ffb020;
  --bad: #ff5c5c;
  --radius: 14px;
}

* { box-sizing: border-box; }
/* .prejoin/.room set `display`, which outranks the user-agent rule for [hidden] and leaves
   the pre-join screen covering the room after joining. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
button:disabled { opacity: .45; cursor: default; }
a { color: var(--accent); }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--line); font-weight: 500; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: #2b2f37; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
.btn-danger { background: #e5484d; border-color: #e5484d; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #f04248; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.field {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%),
  linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

label.lbl { display: block; margin: 0 0 6px; color: var(--dim); font-size: 13px; }

/* round toolbar buttons */
.pill {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
}
.pill:hover:not(:disabled) { background: #2f333c; }
.pill.off { background: #e5484d; border-color: #e5484d; color: #fff; }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.pill svg { width: 22px; height: 22px; fill: currentColor; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--fg);
  padding: 10px 16px; border-radius: 10px; z-index: 60; opacity: 0;
  transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ------------------------------------------------------------------ lobby */

.lobby {
  min-height: 100%; display: grid; grid-template-rows: auto 1fr auto;
}
.lobby header { padding: 20px 28px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; letter-spacing: -.02em; font-size: 18px; }
.brand span { color: var(--accent); }
.lobby main { display: grid; place-items: center; padding: 24px; }
.lobby footer { padding: 18px 28px; color: var(--dim); font-size: 13px; }

.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); max-width: 760px; width: 100%; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.card h2 { margin: 0; font-size: 17px; }
.card p { margin: 0; color: var(--dim); font-size: 14px; }

.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--dim); }

.number-out {
  font-size: 26px; font-weight: 700; letter-spacing: .06em; text-align: center;
  padding: 14px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--line);
}
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ------------------------------------------------------------- prejoin */

.prejoin { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.prejoin-box {
  display: grid; grid-template-columns: minmax(320px, 560px) minmax(260px, 320px); gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { .prejoin-box { grid-template-columns: 1fr; } }
.preview {
  position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line);
}
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview .off-note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); }
.preview .ctrls { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; gap: 12px; justify-content: center; }

/* -------------------------------------------------------------------- room */

.room { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.room-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.room-head .title { font-weight: 600; }
.room-head .num { color: var(--dim); font-variant-numeric: tabular-nums; }
.room-head .spacer { flex: 1; }
.quality { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }
.quality i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); display: inline-block; }
.quality.EXCELLENT i, .quality.GOOD i { background: var(--ok); }
.quality.MEDIUM i { background: var(--warn); }
.quality.BAD i, .quality.LOW i { background: var(--bad); }

.stage { display: grid; grid-template-columns: 1fr 0; min-height: 0; transition: grid-template-columns .18s; }
.stage.with-panel { grid-template-columns: 1fr 320px; }

#grid { display: grid; gap: 10px; padding: 12px; align-content: center; justify-content: center; overflow: auto; }
#grid.speaker { grid-template-columns: 1fr; }

.tile {
  position: relative; aspect-ratio: 16/9; background: #05060a; border-radius: 12px;
  overflow: hidden; border: 2px solid transparent; min-width: 0;
}
.tile.vad { border-color: var(--ok); }
.tile.self video { transform: scaleX(-1); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .avatar {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.tile .avatar div {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  background: #4b4fd6; font-size: 30px; font-weight: 600;
}
.tile .name {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 8px; background: rgba(0,0,0,.6); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .name .muted-ico { color: var(--bad); }
.tile .pin {
  position: absolute; right: 8px; top: 8px; opacity: 0; transition: opacity .12s;
  background: rgba(0,0,0,.6); border-radius: 8px; padding: 5px 8px; font-size: 12px;
}
.tile:hover .pin { opacity: 1; }
.tile.pinned .pin { opacity: 1; color: var(--accent); }

.panel { background: var(--surface); border-left: 1px solid var(--line); overflow: auto; min-width: 0; }
.panel header { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; }
.panel header .spacer { flex: 1; }
.panel .body { padding: 12px 16px; display: grid; gap: 14px; }

.plist { display: grid; gap: 2px; }
.prow { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.prow:hover { background: var(--surface-2); }
.prow .ava { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: #4b4fd6; font-size: 13px; font-weight: 600; flex: none; }
.prow .who { flex: 1; min-width: 0; }
.prow .who b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .who small { color: var(--dim); font-size: 12px; }
.prow .flags { display: flex; gap: 6px; color: var(--dim); }
.prow .flags .bad { color: var(--bad); }

.room-foot {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px; border-top: 1px solid var(--line); background: var(--surface); flex-wrap: wrap;
}
.room-foot .left, .room-foot .right { position: absolute; }
#stats {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
  color: var(--dim); white-space: pre-wrap; padding: 8px 16px; border-top: 1px solid var(--line);
  background: var(--surface); display: none;
}
#stats.show { display: block; }
