:root {
  --accent: #53fc18;
  --live: #ff2d2d;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --glass: rgba(0, 0, 0, 0.45);
  --glass-strong: rgba(18, 18, 20, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --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);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

#preview {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
#preview.mirrored { transform: scaleX(-1); }

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
  pointer-events: none;
}
#overlay > * { pointer-events: auto; }

/* ── Top bar ─────────────────────────────── */
.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #888; }
.status-pill.live { background: var(--live); }
.status-pill.live .dot { background: #fff; animation: pulse 1.4s infinite; }
.status-pill.practice .dot { background: #ffd43b; }
.status-pill.connecting .dot { background: #4dabf7; animation: pulse 0.9s infinite; }
.timer { font-weight: 600; opacity: 0.9; }

.top { flex-wrap: nowrap; }
.keyz-pill { margin-left: auto; color: var(--muted); }
.keyz-pill[aria-pressed="true"] { background: var(--accent); color: #000; }
.fits-input { height: auto; padding: 10px 12px; font-size: 16px; font-weight: 500; resize: none; font-family: inherit; }

.viewers-pill svg { width: 16px; height: 16px; fill: currentColor; }
.viewers-pill.tick { animation: nudge 0.35s ease-out; }

@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes nudge { 40% { transform: scale(1.06); } }

.banner {
  align-self: center;
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(255, 170, 0, 0.9);
  color: #111;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  max-width: 92%;
}

/* ── Chat ─────────────────────────────────── */
/* Box position/size come from the saved layout (percent of screen), set inline by app.js. */
.chat {
  position: absolute;
  left: 3%;
  top: 48%;
  width: 80%;
  height: 40%;
  --chat-font: 15px;
  pointer-events: none !important;
}

/* Lines fade out as they rise through the top part of the box. */
.chat-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 38%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 38%);
}

.chat-lines {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 6px 4px;
  will-change: transform;
}

.msg {
  padding: 2px 0;
  font-size: var(--chat-font);
  line-height: 1.3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 8px rgba(0, 0, 0, 0.6);
  overflow-wrap: anywhere;
  animation: fade-in 0.25s ease-out;
}
.msg .badge {
  display: inline-block;
  vertical-align: 0.05em;
  margin-right: 0.25em;
  padding: 0 0.3em;
  border-radius: 3px;
  font-size: 0.68em;
  font-weight: 800;
  line-height: 1.5;
  color: #000;
  text-shadow: none;
  text-transform: uppercase;
}
.badge.sub { background: var(--accent); }
.badge.mod { background: #4dabf7; }
.badge.og { background: #ffd43b; }
.badge.vip { background: #f783ac; }
.msg .name { font-weight: 700; }
.msg .text { color: var(--text); }

@keyframes fade-in { from { opacity: 0; } }

/* ── Scene builder (chat layout editing) ── */
.chat-frame { display: none; }

.chat.editing { pointer-events: auto !important; touch-action: none; cursor: move; }
.chat.editing .chat-clip { -webkit-mask-image: none; mask-image: none; }
.chat.editing .chat-frame {
  display: block;
  position: absolute;
  inset: 0;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  background: rgba(83, 252, 24, 0.08);
}
/* Show where the fade starts while editing. */
.chat.editing .chat-frame::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  border-top: 1px dotted rgba(83, 252, 24, 0.6);
}
.frame-label {
  position: absolute;
  top: 6px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: #000;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.resize-handle {
  position: absolute;
  right: -14px;
  bottom: -14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.5);
  touch-action: none;
  cursor: nwse-resize;
}
.resize-handle::after {
  content: "";
  position: absolute;
  inset: 11px;
  border-right: 3px solid #000;
  border-bottom: 3px solid #000;
}

.layout-bar {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  z-index: 5;
}
.layout-row { display: flex; align-items: center; gap: 10px; }
.layout-row strong { flex: 1; font-size: 16px; }
.layout-row + .layout-row { margin-top: 10px; font-size: 14px; color: var(--muted); }
.layout-row input { flex: 1; accent-color: var(--accent); }
.layout-row output { min-width: 36px; text-align: right; color: var(--text); font-weight: 700; }
.layout-done { flex: 0 0 auto; height: 40px; padding: 0 18px; font-size: 15px; }
.layout-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* While editing, hide everything that isn't the chat box or the editor bar. */
body.layout-editing .top,
body.layout-editing .banner,
body.layout-editing .controls { visibility: hidden; }

.scene h3 { font-size: 15px; margin: 6px 0 4px; }
.scene .note { margin: 0 0 10px; }
.scene-btn { width: 100%; background: rgba(83, 252, 24, 0.15); color: var(--accent); }

/* ── Controls ─────────────────────────────── */
.controls {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: opacity 0.2s;
}
.controls.hidden-ui { opacity: 0; pointer-events: none; }

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn[aria-pressed="true"] { background: var(--live); }

.go-btn {
  flex: 1;
  max-width: 190px;
  height: 50px;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.02em;
}
.go-btn.live { background: var(--live); color: #fff; }
.go-btn.armed { background: #fff; color: var(--live); }
.go-btn:disabled { opacity: 0.6; }

.text-btn {
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--glass);
  font-weight: 600;
  font-size: 14px;
}
.text-btn.active { background: #ffd43b; color: #000; }
.text-btn.danger { color: #ff8787; }

/* ── Start gate ───────────────────────────── */
.start-gate {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(circle at 50% 40%, #13220c, #000 70%);
  color: var(--muted);
  font-size: 15px;
}
.start-logo { color: var(--accent); font-size: 34px; font-weight: 900; letter-spacing: -0.02em; }

/* ── Settings sheet ───────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-panel {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 16px 16px calc(var(--safe-bottom) + 20px);
  border-radius: 20px 20px 0 0;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  -webkit-user-select: text;
  user-select: text;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 20px; }

.field { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field span { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.field output { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.number-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #111;
  color: var(--text);
  font-size: 17px; /* 16px+ stops iOS zooming in on focus */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.section-title { font-size: 15px; margin: 18px 0 2px; }

.rec-jobs:empty { display: none; }
.rec-job { margin: 8px 0; font-size: 13px; color: var(--muted); }
.rec-job .bar { height: 6px; margin-top: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.rec-job .bar > span { display: block; height: 100%; background: var(--accent); transition: width 0.4s; }
.rec-job.failed { color: #ff8787; }
.rec-list { list-style: none; margin: 6px 0 0; padding: 0; }
.rec-list li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.rec-list li.empty { color: var(--muted); }
.rec-meta { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.rec-meta .when { font-weight: 600; }
.rec-meta .info { color: var(--muted); font-size: 13px; }
.rec-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rec-actions a {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.rec-actions a.primary { background: var(--accent); color: #000; }
.rec-status { color: var(--muted); font-size: 13px; margin-top: 6px; }
.rec-status.failed { color: #ff8787; }

.toggle { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

.costs h3 { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; margin: 18px 0 6px; }
.costs-scope { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.costs-scope.live { color: var(--accent); }
.cost-total { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.cost-total #costTotal { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cost-rate { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.costs dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.costs dt { color: var(--muted); }
.costs dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.costs h4 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.cost-history { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.cost-history li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.cost-history li.empty { color: var(--muted); }
.cost-history .when { color: var(--muted); }
.cost-history .tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 6px; background: rgba(255, 255, 255, 0.12); }
.cost-history .tag.live { background: var(--live); }
.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.health h3 { font-size: 15px; margin: 18px 0 6px; }
.health dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.health dt { color: var(--muted); }
.health dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.heard { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.heard span:last-child { color: var(--text); }
.error { color: #ff8787; font-size: 13px; }

#logoutBtn { margin-top: 18px; }

/* ── Login ────────────────────────────────── */
.login-body { display: grid; place-items: center; overflow: auto; padding: 16px; }
.login-card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.login-card img { border-radius: 18px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #111;
  color: var(--text);
  font-size: 16px;
}
.login-card .go-btn { width: 100%; max-width: none; }
