:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #222631;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --accent: #4f8cff;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --speak: #3ddc97;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Join ---------- */
.screen { min-height: 100%; }
#join-screen { display: grid; place-items: center; padding: 24px; }
.join-card {
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); gap: 24px;
  width: min(960px, 100%); background: var(--panel); border-radius: 20px; padding: 24px;
}
@media (max-width: 760px) { .join-card { grid-template-columns: 1fr; padding: 16px; } }

.preview { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.preview-controls { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; gap: 10px; justify-content: center; }

.round {
  border: 0; border-radius: 999px; padding: 10px 16px; background: rgba(40, 44, 56, .85); cursor: pointer;
}
.round:not(.on), .ctl.off { background: var(--danger); }

#join-form { display: flex; flex-direction: column; gap: 14px; }
#join-form h1 { margin: 0 0 4px; font-size: 1.4rem; }
#join-form label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
#join-form input:not([type="checkbox"]) {
  background: var(--panel-2); border: 1px solid #2d3240; border-radius: 10px; padding: 11px 12px; color: var(--text);
}
#join-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#join-form .check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
.primary {
  border: 0; border-radius: 10px; padding: 12px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: .6; cursor: progress; }
.error { color: #ff8a8d; min-height: 1.2em; margin: 0; font-size: .9rem; }
.note { color: var(--muted); font-size: .85rem; margin: 0; }

/* ---------- Call ---------- */
#call-screen { height: 100dvh; display: flex; flex-direction: column; }
.grid {
  flex: 1; display: grid; gap: 8px; padding: 8px; min-height: 0;
  grid-auto-rows: 1fr;
}
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="5"] { grid-template-columns: repeat(6, 1fr); }
.grid[data-count="5"] .tile { grid-column: span 2; }
.grid[data-count="5"] .tile:nth-child(4) { grid-column: 2 / span 2; }
@media (max-width: 700px) and (orientation: portrait) {
  .grid[data-count="2"] { grid-template-columns: 1fr; }
  .grid[data-count="5"] { grid-template-columns: 1fr 1fr; }
  .grid[data-count="5"] .tile, .grid[data-count="5"] .tile:nth-child(4) { grid-column: auto; }
  .grid[data-count="5"] .tile:last-child { grid-column: 1 / -1; }
}

/* Spotlight: one pinned tile big, the rest in a strip */
.grid.spotlight { grid-template-columns: repeat(4, 1fr) !important; grid-template-rows: 1fr 140px; grid-auto-rows: 140px; }
.grid.spotlight .tile { grid-column: auto !important; }
.grid.spotlight .tile.pinned { grid-column: 1 / -1 !important; grid-row: 1; }

.tile {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 0;
  outline: 3px solid transparent; transition: outline-color .15s; cursor: pointer;
}
.tile.speaking { outline-color: var(--speak); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.local video { transform: scaleX(-1); }
.tile.local.screen video { transform: none; }
.tile .avatar { position: absolute; inset: 0; display: none; place-items: center; background: var(--panel); }
.tile .avatar span {
  width: 88px; height: 88px; border-radius: 50%; background: var(--panel-2); display: grid; place-items: center;
  font-size: 2rem; font-weight: 600;
}
.tile.no-video .avatar { display: grid; }
.tile.no-video video { visibility: hidden; }

.tile .label {
  position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 16px);
  background: rgba(0, 0, 0, .55); padding: 4px 10px; border-radius: 999px; font-size: .85rem;
}
.tile .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted-icon { color: #ff8a8d; font-size: .75rem; }
.q-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.q-dot.good { background: var(--ok); }
.q-dot.fair { background: var(--warn); }
.q-dot.poor { background: var(--danger); }

.overlay-status {
  position: absolute; top: 8px; left: 8px; right: 8px; text-align: center; font-size: .8rem; pointer-events: none;
}
.overlay-status:not(:empty) { background: rgba(0, 0, 0, .6); border-radius: 8px; padding: 4px 8px; }

.controls {
  display: flex; justify-content: center; gap: 10px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); flex-wrap: wrap;
}
.ctl {
  border: 0; border-radius: 12px; padding: 12px 18px; background: var(--panel-2); cursor: pointer; min-width: 72px;
}
.ctl.active { background: var(--accent); }
.ctl.danger { background: var(--danger); }

.banner { background: var(--warn); color: #1b1300; text-align: center; padding: 8px; font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--panel-2);
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); max-width: 90vw;
}
