:root {
  --bg-0: #1e1f22;
  --bg-1: #2b2d31;
  --bg-2: #313338;
  --bg-3: #383a40;
  --text: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --red: #f23f43;
  --radius: 10px;
  --font: "gg sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--bg-0); color: var(--text); font-family: var(--font); font-size: 15px; overflow: hidden; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.icon { width: 20px; height: 20px; fill: currentColor; flex: none; }
.icon.big { width: 56px; height: 56px; opacity: .5; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Landing ---------- */
.home { height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 50% -10%, #3b3f8f55, transparent), var(--bg-0); }
.card { width: min(440px, 100%); background: var(--bg-2); border-radius: 14px; padding: 32px;
  box-shadow: 0 20px 60px #0008; }
.card h1 { font-size: 28px; letter-spacing: -.02em; }
.sub { color: var(--muted); margin: 6px 0 22px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.input { width: 100%; background: var(--bg-0); border: 1px solid transparent; color: var(--text);
  padding: 11px 12px; border-radius: 8px; font: inherit; margin-bottom: 16px; transition: border-color .15s; }
.input:focus { outline: none; border-color: var(--accent); }
.tabs { display: flex; background: var(--bg-0); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; padding: 9px; border-radius: 7px; color: var(--muted); font-weight: 600; transition: background .2s, color .2s; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--bg-3); color: var(--text); }
.tab-panel { display: none; animation: fade .2s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.hint { color: var(--muted); margin-bottom: 14px; line-height: 1.45; }
.error { color: var(--red); min-height: 20px; margin-top: 12px; font-size: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px;
  border-radius: 8px; font-weight: 600; transition: background .15s, transform .1s; }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: #0009; backdrop-filter: blur(6px); color: #fff; }
.btn.secondary:hover { background: #000c; }

/* ---------- Room ---------- */
.room { height: 100%; display: flex; flex-direction: column; }
.room-header { height: 52px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border-bottom: 1px solid var(--bg-0); }
.room-id { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-radius: 8px;
  font-size: 17px; font-weight: 600; letter-spacing: .12em; transition: background .15s; }
.room-id:hover { background: var(--bg-3); }
.room-id .icon { width: 17px; height: 17px; color: var(--muted); }
.room-body { flex: 1; min-height: 0; display: flex; }

.sidebar { width: 260px; flex: none; background: var(--bg-1); display: flex; flex-direction: column; }
.sidebar-title { padding: 16px 16px 8px; color: var(--muted); font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.count { background: var(--bg-0); border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.user-list { list-style: none; flex: 1; overflow-y: auto; padding: 4px 8px; }
.user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; transition: background .15s; }
.user:hover { background: var(--bg-3); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; color: #fff; }
.user-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-name small { color: var(--muted); }
.status { display: flex; gap: 6px; }
.status .icon { width: 16px; height: 16px; color: var(--red); }
.status .on { color: var(--green); }
.status .off-neutral { color: var(--muted); opacity: .6; }
.status .live { color: #fff; background: var(--red); border-radius: 4px; padding: 1px 3px; width: 20px; height: 16px; }

.controls { padding: 12px; background: #232428; display: flex; flex-direction: column; gap: 8px; }
.ctrl-row { display: flex; gap: 8px; }
.ctrl-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 12px;
  background: var(--bg-3); border-radius: 8px; font-weight: 600; transition: background .15s, color .15s; width: 100%; }
.ctrl-btn:hover { background: #43454c; }
.ctrl-btn.grow { flex: 1; }
.ctrl-btn.muted { background: #f23f4326; color: var(--red); }
.ctrl-btn.live { background: var(--green); color: #fff; }
.danger-btn { width: auto; color: var(--red); }
.chev { width: 16px; height: 16px; margin-left: auto; transition: transform .2s; }
.menu-wrap { position: relative; }
.menu-wrap.open .chev { transform: rotate(180deg); }
.menu { position: absolute; bottom: calc(100% + 8px); left: 0; right: 0; background: #111214; border-radius: 10px;
  padding: 6px; box-shadow: 0 8px 24px #000a; animation: fade .15s ease; }
.menu-title { padding: 6px 10px; font-size: 12px; color: var(--muted); font-weight: 600; }
.menu-item { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 6px; }
.menu-item:hover { background: var(--accent); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: var(--red); color: #fff; }
.menu-item.active { color: var(--green); }

.stage { flex: 1; min-width: 0; position: relative; background: var(--bg-0); padding: 14px; display: flex; }
.grid { flex: 1; min-width: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  grid-auto-rows: 1fr; align-content: stretch; }
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="2"], .grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="0"] { display: flex; }
.grid.focused { display: block; }
.grid.focused .tile { display: none; }
.grid.focused .tile.focus { display: block; width: 100%; height: 100%; cursor: default; }

.tile { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  min-height: 0; border: 2px solid transparent; transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile-label { position: absolute; left: 10px; bottom: 10px; background: #000a; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.tile-hint { position: absolute; right: 10px; top: 10px; background: #000a; padding: 4px 8px; border-radius: 6px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.tile:hover .tile-hint { opacity: 1; }
.tile.focus .tile-hint { display: none; }

.focus-bar { position: absolute; top: 26px; left: 26px; z-index: 5; display: flex; align-items: center; gap: 12px; }
.focus-title { background: #000a; padding: 6px 12px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.empty { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px; }
.empty h2 { color: var(--text); font-size: 20px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: #111214; padding: 10px 18px;
  border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; box-shadow: 0 8px 24px #000a; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .room-body { flex-direction: column-reverse; }
  .sidebar { width: 100%; max-height: 45%; }
  .grid, .grid[data-count="2"], .grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.brand { line-height: 0; margin-bottom: 4px; }
.brand img { display: block; height: 44px; width: auto; }
