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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.05s;
}

#screen .icon {
  font-size: 80vmin;
  line-height: 1;
  text-align: center;
}

#screen .text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 900;
  text-align: center;
  padding: 5vw;
  word-break: break-word;
}

/* ---------- CLI scrolling text effect ---------- */
.fx-cli {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: clamp(0.9rem, 4.2vw, 1.6rem);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 6vw 5vw;
  width: 100%;
  box-sizing: border-box;
}

/* ---------- Matrix rain ---------- */
.fx-matrix {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Glitch text ---------- */
.fx-glitch {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: clamp(2rem, 9vw, 7rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 4vw 2vw;
  position: relative;
  line-height: 1.1;
  text-shadow: 0 0 16px var(--fx-glitch-color, #ff2a00);
  animation: glitch-skew 3.2s infinite steps(1);
}

.fx-glitch::before,
.fx-glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 4vw 2vw auto 2vw;
  width: calc(100% - 4vw);
  text-align: center;
  pointer-events: none;
}

.fx-glitch::before {
  color: #ff00c8;
  mix-blend-mode: screen;
  animation: glitch-a 2.4s infinite linear alternate-reverse;
  clip-path: polygon(0 0, 100% 0, 100% 48%, 0 48%);
}

.fx-glitch::after {
  color: #00e5ff;
  mix-blend-mode: screen;
  animation: glitch-b 2.1s infinite linear alternate-reverse;
  clip-path: polygon(0 52%, 100% 52%, 100% 100%, 0 100%);
}

@keyframes glitch-a {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(-3px, -1px); }
  40%      { transform: translate(2px,  1px); }
  60%      { transform: translate(-2px, 1px); }
  80%      { transform: translate(3px, -1px); }
}
@keyframes glitch-b {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(3px, 1px); }
  40%      { transform: translate(-2px, -2px); }
  60%      { transform: translate(2px, -1px); }
  80%      { transform: translate(-3px, 2px); }
}
@keyframes glitch-skew {
  0%, 85%, 100% { transform: skew(0deg); }
  88%           { transform: skew(1.2deg); }
  91%           { transform: skew(-0.8deg); }
  94%           { transform: skew(0.6deg); }
}

/* ---------- Join overlay (tap-to-join) ---------- */
#overlay {
  position: fixed; inset: 0; width: 100%; height: 100dvh;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(46,202,255,0.09), transparent 65%),
    #060812;
  display: flex; align-items: center; justify-content: center;
  z-index: 100; cursor: pointer;
}

#overlay.hidden { display: none; }

.join-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.5em; padding: 2em; text-align: center; width: min(90vw, 420px);
}

.join-brand {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  font-size: clamp(3.5rem, 16vw, 7rem); font-weight: 900; letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 0 24px rgba(46,202,255,0.55), 0 0 60px rgba(46,202,255,0.25);
}

.join-venue {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(0.72rem, 3.2vw, 0.95rem); letter-spacing: 0.2em;
  text-transform: uppercase; color: rgba(46,202,255,0.65); min-height: 1.2em;
}

.join-cta {
  margin-top: 2em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85rem; letter-spacing: 0.22em; color: rgba(255,255,255,0.45);
  animation: join-pulse 2.4s ease-in-out infinite;
}

@keyframes join-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}

.join-note {
  margin-top: 1.5em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.65rem; color: rgba(46,202,255,0.3); letter-spacing: 0.05em;
}

.join-error {
  margin-top: 0.8em; color: #ff7a7a; font-size: 0.78rem;
  font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.05em;
}

.join-error[hidden] { display: none; }

/* ---------- STANDBY overlay — electric blue ---------- */
#standby {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0;
  padding: env(safe-area-inset-top, 20px) 24px env(safe-area-inset-bottom, 20px);
  /* Custom properties overridable via JS when the operator sets per-event
     colours. Defaults preserve the existing blue cyberpunk look. */
  --standby-bg: #060812;
  --standby-fg: rgba(46,202,255,0.9);
  --standby-accent: rgba(46,202,255,1);
  background:
    radial-gradient(ellipse at 50% 25%, rgba(46,202,255,0.1), transparent 60%),
    radial-gradient(ellipse at 50% 90%, rgba(46,202,255,0.05), transparent 70%),
    var(--standby-bg);
  color: var(--standby-fg);
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  overflow: hidden;
}

.standby-cd {
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.standby-cd-label {
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--standby-accent);
  opacity: 0.8;
}
.standby-cd-value {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: clamp(2rem, 10vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--standby-fg);
  text-shadow: 0 0 18px var(--standby-accent);
}
.standby-cd[hidden] { display: none; }

#standby[hidden] { display: none; }

/* Brand */
.sb-brand {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  font-size: clamp(3rem, 13vw, 5.5rem);
  font-weight: 900; letter-spacing: 0.14em; text-align: center;
  color: #fff;
  text-shadow: 0 0 20px rgba(46,202,255,0.5), 0 0 50px rgba(46,202,255,0.2);
  margin-bottom: 0.15em;
}

.sb-venue {
  font-size: clamp(0.68rem, 3vw, 0.9rem); letter-spacing: 0.2em;
  text-transform: uppercase; color: rgba(46,202,255,0.55);
  margin-bottom: 1.8em; min-height: 1em;
}

.sb-custom-text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  font-weight: 900; font-size: clamp(1.6rem, 9vw, 4rem);
  letter-spacing: 0.08em; text-transform: uppercase; text-align: center;
  color: #fff; text-shadow: 0 0 20px rgba(46,202,255,0.4);
  margin: 0.2em 0 0.5em; line-height: 1.05; word-break: break-word;
}
.sb-custom-text[hidden] { display: none; }

.sb-image {
  display: block; margin: 0 auto 1em; max-width: 80vw; max-height: 28vh;
  object-fit: contain; border-radius: 10px;
}
.sb-image[hidden] { display: none; }

/* Count */
.sb-count-row {
  display: flex; flex-direction: column; align-items: center; gap: 0.2em;
  margin-bottom: 1.4em;
}

.sb-count-num {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  font-size: clamp(3rem, 14vw, 6rem); font-weight: 900; line-height: 1;
  color: #fff; text-shadow: 0 0 24px rgba(46,202,255,0.4);
  font-variant-numeric: tabular-nums;
}

.sb-count-label {
  font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: rgba(46,202,255,0.4);
}

/* Status chips */
.sb-status-row {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  margin-bottom: 1.6em; align-items: center;
}

.sb-chip {
  font-size: 0.62rem; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 100px;
  border: 1px solid rgba(46,202,255,0.18);
  background: rgba(46,202,255,0.05); color: rgba(46,202,255,0.45);
  white-space: nowrap;
}

.sb-chip.status-green {
  color: #22c55e; border-color: rgba(34,197,94,0.35);
  background: rgba(34,197,94,0.07);
  text-shadow: 0 0 8px rgba(34,197,94,0.5);
}

.sb-chip.status-amber {
  color: #f59e0b; border-color: rgba(245,158,11,0.35);
  background: rgba(245,158,11,0.07);
  text-shadow: 0 0 8px rgba(245,158,11,0.5);
}

.sb-chip-motion {
  display: inline-flex; align-items: center; gap: 4px;
}

#standby-motion-btn {
  font: inherit; font-size: 0.82em; background: transparent;
  color: rgba(46,202,255,0.65); border: none; padding: 0;
  cursor: pointer; letter-spacing: inherit; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
#standby-motion-btn[hidden] { display: none; }

/* Ticker */
.sb-ticker {
  width: 100%; height: 1.8em; overflow: hidden; position: relative;
  border-top: 1px solid rgba(46,202,255,0.1);
  border-bottom: 1px solid rgba(46,202,255,0.1);
  margin-bottom: 1.8em;
}

#standby-ticker-track {
  position: absolute; left: 100%; top: 50%;
  transform: translate(0,-50%); white-space: nowrap;
  font-size: clamp(0.72rem, 3vw, 0.9rem); letter-spacing: 0.08em;
  color: rgba(46,202,255,0.55);
  animation: sb-ticker 28s linear infinite; will-change: transform;
}

@keyframes sb-ticker {
  from { transform: translate(0,-50%); }
  to   { transform: translate(-100%,-50%); }
}

/* Action buttons */
.sb-actions {
  display: flex; gap: 12px; justify-content: center;
}

.sb-action-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(46,202,255,0.6); background: rgba(46,202,255,0.06);
  border: 1px solid rgba(46,202,255,0.2); border-radius: 100px;
  padding: 8px 18px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.sb-action-btn:active {
  background: rgba(46,202,255,0.14); color: rgba(46,202,255,0.9);
}

/* iOS A2HS hint */
#ios-a2hs-bar {
  margin-top: 1.2em; font-size: 0.68rem; letter-spacing: 0.06em;
  color: rgba(46,202,255,0.4); text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
#ios-a2hs-bar[hidden] { display: none; }
#ios-a2hs-bar strong { color: rgba(46,202,255,0.65); font-weight: 600; }

/* Wipe-out transition on deactivate (300ms) */
#standby.standby--wiping {
  animation: standby-wipe 0.3s steps(12, end) forwards;
}

@keyframes standby-wipe {
  0%   { opacity: 1;    transform: skewX(0deg);    filter: none; }
  20%  { opacity: 0.7;  transform: skewX(1.2deg);  filter: hue-rotate(20deg); }
  50%  { opacity: 0.35; transform: skewX(-1.5deg); filter: brightness(1.5); }
  80%  { opacity: 0.1;  transform: skewX(0deg);    filter: brightness(2) blur(2px); }
  100% { opacity: 0;    transform: skewX(0deg);    filter: none; }
}

/* Connection status indicator */
#status {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  pointer-events: none;
}

#status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #444;
  transition: background 0.3s;
}

#status-dot.connected {
  background: #22c55e;
}

#status-dot.disconnected {
  background: #ef4444;
  animation: blink 1s infinite;
}

/* --- Recording button (audience-side video capture) --- */
#rec-btn {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  pointer-events: auto;
  transition: transform 100ms, background 200ms, border-color 200ms;
}
#rec-btn[hidden] { display: none; }
#rec-btn:active { transform: scale(0.95); }
#rec-btn .rec-icon {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ff3a2a;
  box-shadow: 0 0 0 0 rgba(255, 58, 42, 0.7);
}
#rec-btn.is-recording {
  background: rgba(255, 58, 42, 0.85);
  border-color: rgba(255, 200, 200, 0.6);
}
#rec-btn.is-recording .rec-icon {
  background: #fff;
  animation: rec-pulse 1.2s ease-in-out infinite;
}
#rec-btn.is-recording .rec-time { display: inline; }
#rec-btn .rec-time {
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
#rec-btn.is-busy { opacity: 0.6; pointer-events: none; }
#rec-btn.is-error {
  background: rgba(40, 0, 0, 0.85);
  border-color: rgba(255, 100, 100, 0.6);
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---------- Countdown overlay ---------- */
#countdown {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  padding: 6vw;
  text-align: center;
  gap: 4vh;
}
#countdown[hidden] { display: none; }

#countdown .countdown-label {
  font-size: clamp(1.2rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.9;
  word-break: break-word;
  max-width: 90vw;
}

#countdown .countdown-time {
  font-size: clamp(4rem, 22vw, 14rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px currentColor;
}

#countdown.finished .countdown-time {
  animation: countdown-pulse 0.8s ease-in-out infinite;
}
@keyframes countdown-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ---------- End Roll fullscreen takeover ---------- */
/* Fullscreen seconds-only countdown for the final stretch of a standby
   countdown. Each whole-second tick flashes the configured colour and
   fades to black under the white seconds text. */
#end-roll {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#end-roll[hidden] { display: none; }
#end-roll-flash {
  position: absolute;
  inset: 0;
  background: var(--er-color, #ff5b2e);
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
}
#end-roll-flash.tick {
  animation: er-flash 1s linear forwards;
}
@keyframes er-flash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}
#end-roll-num {
  position: relative;
  z-index: 1;
  color: #fff;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: clamp(8rem, 50vw, 30rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 32px rgba(0,0,0,0.6);
  user-select: none;
}

/* ---------- Timecode preroll countdown ---------- */
/* Same flash-the-whole-screen treatment as the end roll, but driven by the
   timecode show payload and shown before the show's first cue. */
#tc-preroll {
  position: fixed;
  inset: 0;
  z-index: 255;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#tc-preroll[hidden] { display: none; }
#tc-preroll-flash {
  position: absolute;
  inset: 0;
  background: var(--pr-color, #ff5b2e);
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
}
#tc-preroll-flash.tick {
  animation: er-flash 1s linear forwards;
}
#tc-preroll-num {
  position: relative;
  z-index: 1;
  color: #fff;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: clamp(8rem, 50vw, 30rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 32px rgba(0,0,0,0.6);
  user-select: none;
}


/* ---------- Grid picker (location=grid) ---------- */
#grid-picker {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: rgba(8, 8, 10, 0.96);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #ffd7a8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#grid-picker .gp-title {
  font-weight: 900;
  font-size: clamp(1.2rem, 5vw, 1.7rem);
  letter-spacing: 0.18em;
  margin-bottom: 0.3em;
  text-align: center;
}
#grid-picker .gp-sub {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  opacity: 0.6;
  margin-bottom: 1.8em;
  letter-spacing: 0.06em;
}
#grid-picker .gp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  width: min(80vmin, 400px);
  aspect-ratio: 1;
}
#grid-picker .gp-cell {
  background: rgba(255, 91, 46, 0.08);
  border: 1.5px solid rgba(255, 91, 46, 0.45);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
#grid-picker .gp-cell:active {
  transform: scale(0.95);
  background: rgba(255, 91, 46, 0.35);
  border-color: rgba(255, 91, 46, 1);
}

/* ---------- Operator HUD overlay ---------- */
#hud {
  position: fixed;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 8px;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
  max-width: calc(100vw - 24px);
  flex-wrap: wrap;
}
#hud[hidden] { display: none; }

#hud.hud--bottom-right { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: 12px; }
#hud.hud--bottom-left  { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 12px; }
#hud.hud--top-right    { top: 16px; right: 12px; }
#hud.hud--top-left     { top: 16px; left: 12px; }

.hud-item { display: flex; align-items: center; gap: 3px; }
.hud-item[hidden] { display: none; }

.hud-bar {
  display: inline-block;
  width: 3px;
  border-radius: 2px;
  background: #666;
}
.hud-bar[data-bar="1"] { height: 5px; }
.hud-bar[data-bar="2"] { height: 8px; }
.hud-bar[data-bar="3"] { height: 11px; }
.hud-bar[data-bar="4"] { height: 14px; }

.hud-perm {
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.3);
  transition: background 0.25s, color 0.25s;
}
.hud-perm--on {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}
