:root {
  --bg: #000;
  --board: #07090f;
  --surface: #141a2c;
  --card: #1b2135;
  --ink: #eef1f7;
  --dim: #9aa4bd;
  --faint: #5c6683;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #9db4ff;
  --accent-ink: #0b0e1a;
  --ok: #7fc9a6;
  --warn: #e6b055;
  --bad: #ef7a5a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; }

/* ---------- sign in ---------- */

#login {
  background: var(--board);
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 22px 22px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--dim); font-size: 13px; letter-spacing: .06em; text-transform: uppercase;
  margin-bottom: 18px;
}
.brand svg { width: 22px; height: 22px; fill: rgba(157,180,255,.18); stroke: var(--accent); stroke-width: 1.3; stroke-linejoin: round; }
.brand svg circle { fill: var(--warn); stroke: none; }
.step h1 { font-size: 22px; font-weight: 500; margin: 0 0 6px; }
.muted { color: var(--dim); font-size: 15px; line-height: 1.5; margin: 0 0 18px; }
.muted b { color: var(--ink); font-weight: 500; }
.small { font-size: 13px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  font-size: 18px;                 /* ≥16px so iOS doesn't zoom the page */
  padding: 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  outline: none;
}
#code { font-size: 26px; letter-spacing: .18em; text-align: center; font-variant-numeric: tabular-nums; }
.field input:focus { border-color: var(--accent); }
.btn {
  width: 100%;
  min-height: 52px;
  border-radius: 26px;
  border: 1px solid transparent;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; color: var(--dim); border-color: var(--line); font-weight: 500; min-height: 44px; }
.row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.row .btn { flex: 1 1 140px; }
.error { color: var(--bad); font-size: 14px; margin: 12px 0 0; }

/* ---------- viewer ---------- */

#viewer { background: #000; }
#video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  transition: filter .3s;
}
#viewer.dim #video { filter: brightness(.45); }
#viewer.dim .overlay, #viewer.dim .center { opacity: .55; }

.overlay {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding-left: calc(14px + var(--safe-left));
  padding-right: calc(14px + var(--safe-right));
  transition: opacity .35s, transform .35s;
}
.overlay.top {
  top: 0;
  padding-top: calc(12px + var(--safe-top));
  padding-bottom: 20px;
  justify-content: space-between;
  background: linear-gradient(rgba(0,0,0,.55), rgba(0,0,0,0));
  pointer-events: none;
}
.overlay.bottom {
  bottom: 0;
  padding-bottom: calc(12px + var(--safe-bottom));
  padding-top: 24px;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.6));
}
#viewer.idle .overlay.bottom { opacity: 0; transform: translateY(8px); pointer-events: none; }
#viewer.idle .overlay.top { opacity: .7; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 10px;
  border-radius: 999px;
  background: rgba(20, 26, 44, .7);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 13px; color: var(--dim);
  max-width: 60vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.status.live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(127,201,166,.2); }
.status.live { color: var(--ink); }
.status.connecting .dot, .status.reconnecting .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status.error .dot { background: var(--bad); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--dim);
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
  letter-spacing: .02em;
}

.center {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  padding: 24px;
}
.center > * { pointer-events: auto; }
.unmute {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-width: 200px; min-height: 200px;
  padding: 28px 32px;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(20, 26, 44, .72);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 18px; font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.unmute:active { transform: scale(.97); }
.unmute svg { width: 84px; height: 84px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.unmute svg path:first-child { fill: rgba(157,180,255,.2); }
.unmute .x { stroke: var(--warn); }

.notice {
  max-width: 320px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(20, 26, 44, .75);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  color: var(--dim);
  font-size: 15px; line-height: 1.5; text-align: center;
}

.ctl {
  min-width: 48px; min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(20, 26, 44, .7);
  backdrop-filter: blur(8px);
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ctl svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ctl[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.ctl.text { padding: 0 14px; font-size: 14px; font-weight: 500; color: var(--dim); }
.ctl.muted .wave { display: none; }
.spacer { flex: 1; }

@media (min-width: 720px) {
  .clock { font-size: 18px; }
}
