:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #22262f;
  --border: #2c313c;
  --text: #e8eaf0;
  --muted: #9aa1b1;
  --accent: #4f7cff;
  --accent-2: #3b63e0;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: #ff8a8d; min-height: 1.2em; margin: 0; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 26px; margin: 8px 0; }
h2 { font-size: 22px; margin: 0 0 4px; }

.screen { min-height: 100%; }
#home, #left, #prejoin { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }

input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 18px;
  font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #2a2f3a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .6; cursor: default; }
.row { display: flex; gap: 8px; }

.home-card {
  width: 100%; max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo img { width: 32px; height: 32px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* prejoin */
.prejoin { width: 100%; max-width: 980px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; align-items: center; }
.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: 14px; left: 0; right: 0; display: flex; justify-content: center; gap: 12px; }
.prejoin-side { display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 760px) { .prejoin { grid-template-columns: 1fr; } }

/* round control buttons */
.round {
  position: relative;
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
  flex: none;
}
.round svg { width: 22px; height: 22px; }
.round:hover { background: #2f3542; }
.round.off { background: var(--danger); border-color: var(--danger); }
.round.active { background: var(--accent); border-color: var(--accent); }
.round.danger { background: var(--danger); border-color: var(--danger); width: 64px; border-radius: 26px; }
.dot { position: absolute; top: 8px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel-2); }

/* call */
#call { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 48px; }
.room-name { font-weight: 600; }
.badge { background: #4a3a10; color: #ffcf5c; padding: 2px 10px; border-radius: 99px; font-size: 12px; }
.stage { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 12px; }
.grid {
  flex: 1; min-width: 0;
  display: grid; gap: 10px;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-auto-rows: 1fr;
  align-content: center;
}
.tile {
  position: relative; background: var(--panel); border-radius: var(--radius); overflow: hidden;
  min-height: 0; aspect-ratio: 16/9; max-height: 100%; width: 100%;
  border: 2px solid transparent; transition: border-color .15s;
  justify-self: center; align-self: center;
}
.tile.speaking { border-color: var(--ok); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video, .tile.contain video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.avatar {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.avatar span {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  font-size: 34px; font-weight: 700; color: #fff;
}
.label {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  background: rgba(0,0,0,.55); padding: 3px 10px; border-radius: 8px; font-size: 13px;
  display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.label svg { width: 14px; height: 14px; color: #ff8a8d; flex: none; }
.grid.has-screen { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
.grid.has-screen .tile.screen { aspect-ratio: auto; height: 100%; }
.grid.has-screen .strip { display: flex; gap: 10px; overflow-x: auto; height: 120px; }
.grid.has-screen .strip .tile { width: 200px; flex: none; height: 100%; aspect-ratio: auto; }
.grid.has-screen .strip .avatar span { width: 48px; height: 48px; font-size: 20px; }

.controls { display: flex; justify-content: center; gap: 12px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); flex-wrap: wrap; }

.chat {
  width: 320px; flex: none; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--border); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg .who { font-size: 12px; color: var(--muted); }
.msg .who b { color: var(--text); font-weight: 600; margin-right: 6px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form .btn { padding: 0 14px; }
@media (max-width: 760px) {
  .chat { position: fixed; inset: 0; width: auto; border-radius: 0; z-index: 20; }
  .round { width: 46px; height: 46px; }
  .round.danger { width: 56px; }
  .controls { gap: 8px; }
  .grid { gap: 6px; }
  .tile { aspect-ratio: auto; height: 100%; }
}

.unlock { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 30; }
.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: #2b3040; color: var(--text); padding: 10px 16px; border-radius: 10px; z-index: 40;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: calc(100% - 32px);
}
