:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #222631;
  --line: #2c3140;
  --text: #e9ecf2;
  --muted: #9aa3b5;
  --accent: #4f8cff;
  --accent-2: #3a74e6;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
code { background: var(--panel-2); padding: 2px 7px; border-radius: 6px; font-size: 0.9em; }
.muted { color: var(--muted); }
.error { color: #ff8a8e; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #2a2f3c; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-lg { padding: 14px 22px; font-size: 1.05rem; }
input {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(79,140,255,.25); }
.brand.small { font-size: .95rem; }

/* Landing */
.landing { display: grid; place-items: center; padding: 16px; }
.landing-card { max-width: 560px; width: 100%; }
.landing h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); line-height: 1.05; margin: 28px 0 14px; }
.lead { color: var(--muted); font-size: 1.1rem; line-height: 1.5; margin-bottom: 28px; }
.join-form { display: flex; gap: 10px; margin-top: 18px; }

/* Lobby */
.lobby { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 40px; align-items: center; padding: 40px; max-width: 1200px; margin: 0 auto; }
.lobby-preview { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; }
.lobby-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.lobby-preview-controls { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; justify-content: center; gap: 12px; }
.media-error { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
.lobby-side { display: flex; flex-direction: column; gap: 14px; }
.lobby-side h2 { margin: 10px 0 0; font-size: 1.8rem; }
.lobby-side form { display: flex; flex-direction: column; gap: 12px; }
.round { width: 48px; height: 48px; border-radius: 50%; border: none; background: rgba(40,44,56,.85); font-size: 1.2rem; cursor: pointer; }
.round.off, .ctrl.off { background: var(--danger) !important; }

/* Call layout */
.call { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.room-meta { color: var(--muted); font-size: .92rem; }
.rec-banner { margin-left: auto; display: flex; align-items: center; gap: 8px; background: rgba(229,72,77,.15); color: #ff9a9d; padding: 6px 12px; border-radius: 999px; font-size: .88rem; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.stage { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.grid { flex: 1; display: grid; gap: 10px; padding: 10px; min-height: 0; grid-auto-rows: minmax(0, 1fr); }
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
.grid[data-count="7"], .grid[data-count="8"], .grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }

.tile { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 0; min-width: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.self video { transform: scaleX(-1); }
.tile.self.screen video { transform: none; object-fit: contain; }
.tile.screen video { object-fit: contain; }
.tile .label { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.55); padding: 4px 10px; border-radius: 8px; font-size: .85rem; display: flex; gap: 6px; align-items: center; }
.tile .avatar { position: absolute; inset: 0; display: none; place-items: center; background: var(--panel); }
.tile .avatar span { width: 84px; height: 84px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 2rem; font-weight: 700; }
.tile.no-video .avatar { display: grid; }
.tile.speaking { outline: 3px solid var(--ok); outline-offset: -3px; }
.tile .state { opacity: .9; }

/* Chat */
.chat { width: 320px; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
.chat-head { padding: 12px 14px; font-weight: 600; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg .who { font-size: .8rem; color: var(--muted); }
.chat-msg .txt { white-space: pre-wrap; word-wrap: break-word; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.icon { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }

/* Controls */
.controls { display: flex; justify-content: center; gap: 10px; padding: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.ctrl { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 72px; padding: 8px 10px; border-radius: 12px; border: none; background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit; }
.ctrl span { font-size: 1.25rem; }
.ctrl small { font-size: .72rem; color: var(--muted); }
.ctrl:hover { background: #2a2f3c; }
.ctrl.active { background: var(--accent); }
.ctrl.active small, .ctrl.off small, .ctrl.danger small { color: #fff; }
.ctrl.recording { background: var(--danger); }
.ctrl.recording small { color: #fff; }
.ctrl.danger { background: var(--danger); }
.badge { position: absolute; top: 6px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 10; box-shadow: 0 8px 30px rgba(0,0,0,.4); }

@media (max-width: 860px) {
  .lobby { grid-template-columns: 1fr; padding: 16px; gap: 20px; }
  .grid[data-count] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); grid-auto-rows: auto; overflow-y: auto; }
  .grid[data-count] .tile { aspect-ratio: 16/9; }
  .grid[data-count="2"], .grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); grid-auto-rows: minmax(0, 1fr); }
  .grid[data-count="2"] .tile, .grid[data-count="3"] .tile, .grid[data-count="4"] .tile { aspect-ratio: auto; }
  .grid[data-count="2"] { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0 0 76px 0; width: auto; z-index: 5; }
  .ctrl { min-width: 0; padding: 8px; }
  .ctrl small { display: none; }
  .join-form { flex-direction: column; }
}
