/* Broadcaster studio - built phone-first: the camera fills the screen and
   every control sits inside thumb reach above the home indicator. */
:root {
  --bg-primary: #080a10;
  --bg-card: rgba(22, 27, 38, 0.72);
  --border-color: rgba(255, 255, 255, 0.09);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --accent-primary: #6366f1;
  --accent-live: #ef4444;
  --accent-emerald: #10b981;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* A class rule like ".gate { display: flex }" outranks the browser's built-in
   [hidden] { display: none }, so toggling el.hidden would do nothing without
   this. Must stay above the rules that set display. */
[hidden] { display: none !important; }

body {
  background: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  /* dvh, not vh: iOS Safari's collapsing URL bar makes vh overflow. */
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------- Admin gate ---------- */
.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 32px 24px;
  text-align: center;
  backdrop-filter: blur(12px);
}
.gate-icon { font-size: 2.5rem; margin-bottom: 8px; }
.gate-card h1 { font-family: var(--font-heading); font-size: 1.5rem; margin-bottom: 6px; }
.gate-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; }
.gate-card input {
  width: 100%;
  padding: 14px 16px;
  /* 16px minimum stops iOS from zooming the page on focus. */
  font-size: 16px;
  font-family: var(--font-body);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-main);
  margin-bottom: 12px;
}
.gate-card input:focus { outline: none; border-color: var(--accent-primary); }
.gate-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* ---------- Studio ---------- */
.studio {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.preview-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
#preview {
  width: 100%;
  height: 100%;
  /* contain, not cover: the preview must show the real framing viewers see,
     rather than a centre crop that hides how much is out of frame. */
  object-fit: contain;
  display: block;
  background: #000;
}

.preview-overlay {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  pointer-events: none;
}
.preview-overlay.top {
  top: 0;
  padding-top: max(12px, env(safe-area-inset-top));
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.preview-overlay.bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}

.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
}
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.state-pill.live { border-color: rgba(239,68,68,0.5); color: #fca5a5; }
.state-pill.live .state-dot { background: var(--accent-live); animation: pulse 1.4s infinite; }
.state-pill.connecting .state-dot { background: #f59e0b; animation: pulse 0.8s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}

.stat-line {
  display: flex;
  gap: 14px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  font-variant-numeric: tabular-nums;
}

.preview-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(0, 0, 0, 0.8);
  color: var(--text-muted);
  font-size: 0.9rem;
}
.warn-icon { font-size: 2rem; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Controls ---------- */
.controls {
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}
.control-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.btn-ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  /* 56px keeps every control comfortably above the 44px touch minimum. */
  min-height: 56px;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.72rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-ctl:active { transform: scale(0.96); }
.btn-ctl.off { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.ctl-icon { font-size: 1.2rem; line-height: 1; }

.btn-go {
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
  color: #fff;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-go:active { transform: scale(0.985); }
.btn-go:disabled { opacity: 0.55; }
.btn-go.live { background: linear-gradient(135deg, var(--accent-live), #b91c1c); }

.error-box {
  margin-top: 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
}

.hint {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}
.hint b { color: var(--text-main); font-weight: 600; }

.footer-links {
  margin-top: 10px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.footer-links a { color: var(--accent-primary); text-decoration: none; }
.footer-links span { margin: 0 6px; opacity: 0.5; }

/* Landscape: put the camera and the controls side by side so the
   preview keeps a usable height on a rotated phone. */
@media (orientation: landscape) and (max-height: 600px) {
  .studio { flex-direction: row; }
  .preview-wrap { flex: 1 1 auto; min-width: 0; }
  .controls {
    flex: 0 0 220px;
    border-top: none;
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .control-row { grid-template-columns: repeat(3, 1fr); }
  .hint, .footer-links { display: none; }
}

/* Wide screens: the studio is a phone tool, so keep it centred and narrow. */
@media (min-width: 900px) {
  .studio { max-width: 520px; margin: 0 auto; border-inline: 1px solid var(--border-color); }
}
