:root {
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #181d24;
  --panel-2: #212833;
  --line: #2c3542;
  --text: #e8ecf1;
  --muted: #94a0b0;
  --accent: #3ddc97;
  --accent-ink: #06281a;
  --danger: #ff5d5d;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; background: var(--panel-2); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.small { padding: 6px 12px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- Lobby ---------- */
.lobby { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: flex; flex-direction: column; gap: 8px;
}
.card h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.card .sub { margin: 0 0 12px; color: var(--muted); }
.card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.card .row { display: flex; gap: 8px; }
.card .primary { margin-top: 16px; padding: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.error { color: var(--danger); margin: 8px 0 0; }

/* ---------- Call ---------- */
.call { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; color: var(--muted); font-size: 14px;
}
.topbar strong { color: var(--text); }

.stage { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 12px; }

.grid {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-wrap: wrap;
  justify-content: center; align-content: center;
  gap: 10px; /* keep in sync with GAP in app.js */
  overflow: hidden;
}

.tile {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  outline: 2px solid transparent;
  transition: outline-color .15s, width .2s, height .2s;
  width: var(--tile-w, 100%);
  height: var(--tile-h, 100%);
  flex: none;
}
.tile.speaking { outline-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.tile.no-video video { visibility: hidden; position: absolute; }

.avatar {
  position: absolute; inset: 0; display: none; place-items: center;
}
.tile.no-video .avatar { display: grid; }
.avatar span {
  width: clamp(56px, 22%, 110px); aspect-ratio: 1; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: clamp(22px, 4vw, 40px); font-weight: 600; color: var(--accent);
}

.nameplate {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  background: rgba(10, 12, 16, .72);
  padding: 4px 10px; border-radius: 8px; font-size: 13px;
  display: flex; gap: 8px; align-items: center;
}
.nameplate .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nameplate .muted-tag { color: var(--danger); font-size: 12px; white-space: nowrap; }

/* ---------- Chat ---------- */
.chat {
  width: 320px; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .body { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.system { color: var(--muted); font-size: 13px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

/* ---------- Controls ---------- */
.controls {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.ctl { position: relative; border: 1px solid var(--line); }
.ctl[aria-pressed="false"].toggle-off { background: #3a2226; border-color: #6b2f35; color: #ffb3b3; }
.ctl[aria-pressed="true"].highlight { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.ctl.danger { background: var(--danger); color: #2b0606; border-color: transparent; font-weight: 600; }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; max-width: min(92vw, 520px);
  overflow-wrap: anywhere; text-align: center; z-index: 10;
}

@media (max-width: 720px) {
  .stage { flex-direction: column; }
  .chat { width: auto; height: 45%; }
  .topbar .count { display: none; }
  .ctl { padding: 9px 12px; font-size: 14px; }
}

/* ---------- Easy link dialog ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.dialog {
  width: min(92vw, 420px); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog form { display: flex; flex-direction: column; gap: 10px; }
.dialog h2 { margin: 0; font-size: 20px; }
.dialog p { margin: 0; }
.dialog label { font-size: 13px; color: var(--muted); }
.row.end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.easy-out {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; overflow-wrap: anywhere; user-select: all; font-size: 13px;
}

/* ---------- Easy mode: opened from a personal link ---------- */
.easy-hello { font-size: 26px; margin: 8px 0 0; }
body.easy .card { max-width: 520px; text-align: center; padding: 36px 28px; }
body.easy .card h1 { font-size: 22px; color: var(--muted); font-weight: 500; }
body.easy .card .sub { display: none; }
body.easy .card .primary { font-size: 28px; padding: 26px 16px; border-radius: 18px; margin-top: 24px; }
body.easy .hint, body.easy .error { font-size: 18px; }
body.easy .controls { gap: 12px; }
body.easy .ctl { font-size: 22px; padding: 18px 26px; border-radius: 16px; flex: 1 1 0; max-width: 260px; white-space: nowrap; }
body.easy #screenBtn, body.easy #chatBtn, body.easy #inviteBtn, body.easy #easyBtn { display: none; }

/* ---------- Members: ring someone into the call ---------- */
.dialog.people { width: min(94vw, 460px); }
.dialog.people[open] { display: flex; flex-direction: column; gap: 12px; }
.people-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.person { display: flex; align-items: center; gap: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.person .who { flex: 1 1 auto; min-width: 0; }
.person .who strong { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .who span { font-size: 14px; color: var(--muted); }
.person.on { border-color: var(--accent); }
.person.on .who span { color: var(--accent); font-weight: 600; }
.person button { font-size: 17px; padding: 12px 18px; }
body.easy .nameplate { font-size: 18px; }
body.easy .toast { font-size: 18px; bottom: 110px; }
@media (max-width: 720px) {
  body.easy .ctl { font-size: 18px; padding: 16px 10px; }
}

/* ---------- Waiting room ---------- */
.wait-card h2 { margin: 0; font-size: 24px; }
.wait-preview { aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; margin: 8px 0; }
.wait-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.wait-card .ghost { margin-top: 8px; }

/* ---------- Admins: people waiting to join ---------- */
.knocks {
  position: fixed; top: 12px; right: 12px; z-index: 5;
  width: min(92vw, 300px); max-height: calc(100dvh - 110px); overflow-y: auto;
  background: var(--panel); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
#knockList { display: flex; flex-direction: column; gap: 12px; }
.knock { display: flex; flex-direction: column; gap: 8px; }
.knock video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; border-radius: 10px; display: block; }
.knock .who { overflow-wrap: anywhere; }
.knock .row { display: flex; gap: 8px; }
.knock .row button { flex: 1; }
.admin-tag { color: var(--accent); font-size: 12px; white-space: nowrap; }
body.easy .knocks { width: min(94vw, 380px); }
body.easy .knock .who { font-size: 20px; }
body.easy .knock .row button { font-size: 20px; padding: 16px 10px; }

/* ---------- Icon buttons ---------- */
.ico { display: inline-flex; }
.ico svg {
  width: 24px; height: 24px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

/* Compact view: round icon-only buttons; the label stays for screen readers and as a tooltip. */
.ctl {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 52px; height: 52px; padding: 0; border-radius: 50%;
}
.ctl .lbl {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.ctl.danger { width: 76px; border-radius: 26px; }
.ctl[aria-pressed="true"]#chatBtn { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Easy view: big buttons with the icon above the word. */
body.easy .ctl {
  width: auto; height: auto; flex-direction: column; gap: 6px;
  padding: 14px 10px; border-radius: 16px;
}
body.easy .ctl .lbl { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
body.easy .ctl .ico svg { width: 34px; height: 34px; }
body.easy .knock .ico svg { width: 28px; height: 28px; }
@media (max-width: 720px) {
  .ctl { width: 48px; height: 48px; padding: 0; }
  .ctl.danger { width: 68px; }
  body.easy .ctl { width: auto; height: auto; padding: 12px 6px; }
}
