:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --surface-2: #26313d;
  --text: #f2f5f8;
  --muted: #9aa7b4;
  --accent: #2f81f7;
  --danger: #e5484d;
  --warn: #f5a524;
  --ok: #3fb950;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ---------- login / ended ---------- */

.card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.card h1 { margin: 0; font-size: 28px; }
.logo { align-self: center; border-radius: 18px; }
.muted { color: var(--muted); margin: 0; }

.card label { display: flex; flex-direction: column; gap: 6px; text-align: start; font-size: 14px; color: var(--muted); }

.card input {
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.card input:focus { border-color: var(--accent); }

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 13px 16px;
  border-radius: 10px;
}
.primary:disabled { opacity: .6; }

.link { color: var(--accent); padding: 8px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- call ---------- */

#call { padding: 0; display: block; position: relative; overflow: hidden; }

.grid {
  position: absolute;
  inset: 0;
  bottom: calc(84px + env(safe-area-inset-bottom));
  top: env(safe-area-inset-top);
  display: grid;
  gap: 6px;
  padding: 6px;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}

.grid[data-count="2"] { grid-template-columns: 1fr; }
.grid[data-count="3"], .grid[data-count="4"],
.grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: 1fr 1fr; }

@media (orientation: landscape) {
  .grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
  .grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
}

/* an odd tile out spans the full row instead of leaving a hole */
@media (orientation: portrait) {
  .grid[data-count="3"] .tile:first-child,
  .grid[data-count="5"] .tile:first-child { grid-column: span 2; }
}

.tile {
  position: relative;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.tile.self.mirror video { transform: scaleX(-1); }

.avatar {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}
.tile.no-video .avatar { display: flex; }
.avatar span {
  width: min(96px, 40%);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 6vmin, 40px);
  font-weight: 600;
}

.label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  font-size: 13px;
}
.label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label svg { width: 14px; height: 14px; fill: var(--danger); flex: none; display: none; }
.tile.muted .label svg { display: block; }

.sig { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sig[data-q="good"] { background: var(--ok); }
.sig[data-q="weak"] { background: var(--warn); }
.sig[data-q="poor"] { background: var(--danger); }
.tile.self .sig { display: none; }

.status {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  font-size: 13px;
  white-space: nowrap;
}
.status:empty { display: none; }

.notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 3;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(38, 49, 61, .95);
  border-left: 3px solid var(--warn);
  font-size: 14px;
}

.unblock {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 14px 22px;
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(84px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
}

.ctl {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.ctl svg { width: 24px; height: 24px; fill: currentColor; }
.ctl .off { display: none; }
.ctl[aria-pressed="false"] { background: #fff; color: #111; }
.ctl[aria-pressed="false"] .on { display: none; }
.ctl[aria-pressed="false"] .off { display: block; }
.ctl.danger { background: var(--danger); width: 64px; }
.ctl:active { filter: brightness(1.25); }

/* ---------- options sheet ---------- */

.sheet {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-body {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sheet-body h2 { margin: 0 0 4px; font-size: 15px; color: var(--muted); font-weight: 500; }

.options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.options button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: start;
  gap: 2px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 2px solid transparent;
}
.options button span { font-size: 13px; color: var(--muted); }
.options button[aria-checked="true"] { border-color: var(--accent); }

.row { padding: 13px 14px; border-radius: 10px; background: var(--surface-2); text-align: center; }
#whoami { font-size: 13px; text-align: center; padding: 4px 0; }
