:root {
  --bg: #0e0f13;
  --panel: #181a21;
  --line: #2a2d38;
  --text: #eceef3;
  --muted: #8b90a0;
  --accent: #3ddc84;
  --live: #ff3b4d;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
header .spacer { flex: 1; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}
.brand:hover { color: var(--accent); }
.brand { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; gap: 9px; }
.brand-logo { display: block; width: 28px; height: 28px; }
.brand-accent { color: var(--accent); margin-left: -9px; }
.brand:hover { color: var(--text); }
.brand:hover .brand-logo { filter: brightness(1.1); }
header #buttons { display: flex; gap: 8px; }

.status { color: var(--muted); }
.status.live { color: var(--live); font-weight: 600; }

main { padding: 16px; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
a.button {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
button:hover, a.button:hover { border-color: var(--muted); }
button:disabled { cursor: wait; opacity: 0.85; }
button.busy::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 8px;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* On-stage indicator */
.live-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--live);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.is-live .live-bar { display: flex; }
.is-live::after {
  content: "";
  position: fixed;
  inset: 0;
  border: 6px solid var(--live);
  pointer-events: none;
  z-index: 20;
}
.live-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.live-flash {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.live-flash.show { opacity: 1; }
.live-flash > div {
  display: grid;
  gap: 6px;
  text-align: center;
  padding: 32px 56px;
  border-radius: 20px;
  color: #fff;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.6);
  transform: scale(0.9);
  transition: transform 0.3s;
}
.live-flash.show > div { transform: scale(1); }
.live-flash.on > div { background: var(--live); }
.live-flash.off > div { background: var(--panel); border: 1px solid var(--line); }
.live-flash strong { font-size: clamp(32px, 7vw, 64px); letter-spacing: 0.04em; }
.live-flash span { font-size: 18px; opacity: 0.9; }

.sound-unlock {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10;
  padding: 12px 20px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.5);
}
.sound-unlock[hidden] { display: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06210f; font-weight: 600; }
button.danger { color: var(--live); }

input, select {
  font: inherit;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.error { color: var(--live); min-height: 1.4em; margin: 0; }
.hint { color: var(--muted); font-size: 13px; }
label .hint { font-size: 12px; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 15px; margin: 20px 0 10px; }
h2 small, h2 span { color: var(--muted); font-weight: 400; }
section > h2:first-child { margin-top: 0; }

.card, .gone {
  max-width: 360px;
  margin: 12vh auto;
  display: grid;
  gap: 12px;
  text-align: center;
}

/* Pre-join */
.prejoin {
  max-width: 900px;
  margin: 4vh auto;
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  align-items: center;
}
.prejoin .preview { aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.prejoin .preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.prejoin .form { display: grid; gap: 12px; }
@media (max-width: 700px) { .prejoin { grid-template-columns: 1fr; } }

/* Tiles */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.grid:empty::after { content: "Nobody here yet"; color: var(--muted); }
.grid[data-empty]:empty::after { content: attr(data-empty); }
.guest-page .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  outline: 3px solid transparent;
  transition: outline-color 0.15s;
}
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.me video { transform: scaleX(-1); }
.tile.speaking { outline-color: var(--accent); }
.tile.on-stage:not(.stage .tile) { box-shadow: 0 0 0 2px var(--live) inset; }

.tile .avatar {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-size: clamp(24px, 6vw, 64px);
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
}
.tile.cam-off .avatar { display: grid; }
.tile.cam-off video:not(.pip) { visibility: hidden; }

.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.6);
  font-size: 13px;
}
.tile.mic-off .mic::before { content: "🔇"; }
.tile.producer .name::after { content: " · producer"; color: var(--muted); }
.tile.me .name::after { content: " (you)"; color: var(--muted); }

/* Their shared screen, shown small in the corner of their camera tile */
.tile .pip {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 38%;
  height: auto; /* overrides the full-height .tile video rule */
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
  border: 2px solid var(--accent);
  border-radius: 6px;
  display: none;
}
.tile.sharing .pip { display: block; }

.tile .controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}
.tile .controls:empty { display: none; }
.tile .controls button { padding: 4px 10px; font-size: 13px; background: rgb(0 0 0 / 0.65); }
.tile .controls button.primary { background: var(--accent); }

/* Producer */
.producer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
}
@media (max-width: 900px) { .producer-layout { grid-template-columns: 1fr; } }
.preview-frame { aspect-ratio: 16 / 9; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; } /* stage is sized in vw/vh, so it scales itself */
.links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Stage output (what OBS captures) */
.stage-page { overflow: hidden; }
.stage-page.transparent { background: transparent; }
.stage {
  width: 100vw;
  height: 100vh;
  padding: 2.5vh;
  display: grid;
  gap: 1.5vh;
  place-content: center;
  /* each column is as wide as fits both the screen width and (as 16:9) the screen height */
  grid-template-columns: repeat(var(--cols), min(
    calc((100vw - 5vh - (var(--cols) - 1) * 1.5vh) / var(--cols)),
    calc((100vh - 5vh - (var(--rows) - 1) * 1.5vh) / var(--rows) * 16 / 9)));
  color: var(--muted);
  font-size: 2vh;
}
.stage { --cols: 1; --rows: 1; }
.stage[data-count="2"] { --cols: 2; --rows: 1; }
.stage[data-count="3"], .stage[data-count="4"] { --cols: 2; --rows: 2; }
.stage[data-count="5"], .stage[data-count="6"] { --cols: 3; --rows: 2; }
.stage[data-count="7"], .stage[data-count="8"], .stage[data-count="9"] { --cols: 3; --rows: 3; }
.stage[data-count="10"] { --cols: 4; --rows: 3; }
.stage .tile { border-radius: 1vh; }
.stage .tile .pip { display: none; }

/* A shared screen fills the left; on-stage cameras stack in a column on the right */
.stage-layout { width: 100vw; height: 100vh; }
.screen-slot { display: none; }
.stage-layout.has-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: 1.5vh;
  padding: 2.5vh;
}
.has-screen .screen-slot { display: block; min-height: 0; }
.has-screen .screen-slot video { width: 100%; height: 100%; object-fit: contain; display: block; }
.has-screen .stage {
  width: auto;
  height: auto;
  padding: 0;
  grid-template-columns: repeat(var(--side-cols), var(--side-width));
  --side-cols: 1;
  --side-width: 22vw;
}
.has-screen .stage:is([data-count="5"], [data-count="6"], [data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) {
  --side-cols: 2;
  --side-width: 13vw;
}
.stage .tile .label { font-size: 2.2vh; padding: 0.5vh 1.2vh; left: 1.2vh; bottom: 1.2vh; }
.stage .tile .mic { display: none; }
.stage .tile .name::after { content: none; }
.stage .tile.speaking { outline-color: transparent; }

/* "The producer muted you" / "asking you to unmute" notice */
.mic-notice {
  position: fixed;
  left: 50%;
  top: 80px;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 18px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.6);
  font-weight: 600;
}
.mic-notice[hidden] { display: none; }

/* Guest page: bigger text and buttons, a waiting-room banner and a control bar at the bottom */
.guest-page { font-size: 17px; padding-bottom: 96px; }
.guest-page label { font-size: 15px; }
.guest-page .hint, .guest-page label .hint { font-size: 14px; }
.guest-page h2 { font-size: 18px; }
.guest-page .tile .label { font-size: 15px; }
button.big { padding: 14px 20px; font-size: 19px; }
.producer-link { color: var(--muted); font-size: 13px; text-decoration: none; }
.producer-link:hover { color: var(--text); text-decoration: underline; }
.waiting-banner {
  display: grid;
  gap: 4px;
  padding: 14px 20px;
  background: #1d3a2a;
  border-bottom: 1px solid var(--accent);
  text-align: center;
  font-size: 18px;
}
.waiting-banner[hidden] { display: none; }
.controlbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgb(14 15 19 / 0.95);
  border-top: 1px solid var(--line);
}
.controlbar:empty { display: none; }
.controlbar button { padding: 12px 18px; font-size: 17px; font-weight: 600; min-width: 130px; }
.controlbar button.danger { background: var(--live); border-color: var(--live); color: #fff; }
.controlbar button.on { border-color: var(--accent); color: var(--accent); }
.controlbar .leave { margin-left: 16px; }
.controlbar button[hidden] { display: none; }
@media (max-width: 600px) {
  .controlbar button { min-width: 0; padding: 10px 12px; font-size: 15px; }
  .controlbar .leave { margin-left: 0; }
}
.reconnecting {
  padding: 12px 16px;
  background: #f5b400;
  color: #1a1300;
  font-weight: 800;
  text-align: center;
  font-size: 18px;
}
.reconnecting[hidden] { display: none; }

/* Pre-join extras */
.prejoin-title { grid-column: 1 / -1; font-size: 26px; margin: 0; text-align: center; }
.prejoin .preview { position: relative; }
.preview-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  color: var(--text);
}
.preview-note[hidden] { display: none; }
.mic-test { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.mic-test i { display: block; height: 100%; width: calc(min(1, var(--level, 0) * 1.5) * 100%); background: var(--accent); }
.mic-test[hidden], .hint[hidden] { display: none; }
.error { display: grid; gap: 6px; }
.error span { color: var(--text); }
.error button { justify-self: start; }
.gone p { color: var(--muted); margin: 0; }

/* Bouncing mic-level meter next to each name. --level (0–1) is set every frame from the real mic signal. */
.meter {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 16px;
}
.meter i {
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  height: calc(3px + 13px * min(1, var(--level, 0) * var(--gain)));
  opacity: calc(0.35 + min(0.65, var(--level, 0) * 3));
}
.meter i:nth-child(1), .meter i:nth-child(5) { --gain: 0.7; }
.meter i:nth-child(2), .meter i:nth-child(4) { --gain: 1.1; }
.meter i:nth-child(3) { --gain: 1.5; }
.tile.mic-off .meter { display: none; }

/* Producer's "Talk to stage" button and the banner guests on stage see while it's on */
.talk-slot { margin-top: 12px; }
.talkback {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  border: 2px dashed var(--muted);
}
.talkback.on {
  background: var(--live);
  border: 2px solid var(--live);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
.talkback-banner {
  padding: 10px 16px;
  background: #f5b400;
  color: #1a1300;
  font-weight: 800;
  text-align: center;
}
.talkback-banner[hidden] { display: none; }

/* Guests: the producer's mute/unmute notice sits just above the control bar, next to the Unmute button */
.guest-page .mic-notice { top: auto; bottom: 96px; font-size: 18px; padding: 14px 16px 14px 20px; }
@media (max-width: 600px) { .guest-page .mic-notice { bottom: 190px; } }

/* "Ask to go on stage": a yellow badge and outline on the tile, a banner for the producer */
.tile.hand { outline-color: #f5b400; }
.tile.hand::before {
  content: "✋ Wants to go on stage";
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 3px 9px;
  border-radius: 6px;
  background: #f5b400;
  color: #1a1300;
  font-size: 13px;
  font-weight: 800;
}
.stage .tile.hand::before { content: none; }
.hand-banner {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #f5b400;
  color: #1a1300;
  font-weight: 800;
}
.hand-banner[hidden] { display: none; }
.controlbar .hand-btn { border-color: #f5b400; }
.controlbar .hand-btn.on { background: #f5b400; color: #1a1300; }
/* On the producer's tiles the top edge holds the buttons, so the badge sits bottom-right instead */
.producer-layout .tile.hand::before { top: auto; left: auto; bottom: 8px; right: 8px; }

/* Guest page stage: always visible. Closed velvet curtains + a sign when empty, open when someone's on.
   Everything animates with transform/opacity only, and the spotlights are removed once the curtain opens. */
.stage-box {
  position: relative;
  overflow: hidden;
  min-height: clamp(220px, 34vh, 380px);
  padding: 38px 8% 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 0%, #2b2333, #0b0b10 70%);
}
.stage-box .grid { position: relative; z-index: 1; }
.stage-box .grid:empty::after { content: none; }
.valance {
  position: absolute;
  inset: 0 0 auto;
  height: 28px;
  z-index: 4;
  background: repeating-linear-gradient(90deg, #8a1222 0 22px, #5e0a17 22px 44px);
  border-bottom: 3px solid #c99a2e;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.5);
}
.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.5%;
  z-index: 2;
  background:
    linear-gradient(to bottom, rgb(0 0 0 / 0) 55%, rgb(0 0 0 / 0.45)),
    repeating-linear-gradient(90deg, #6a0b19 0, #b01c32 22px, #7d0f1f 44px, #4f0812 60px);
  transition: transform 1.4s cubic-bezier(0.6, 0, 0.3, 1);
  will-change: transform;
}
.curtain.left { left: 0; box-shadow: inset -8px 0 14px rgb(0 0 0 / 0.5); }
.curtain.right { right: 0; box-shadow: inset 8px 0 14px rgb(0 0 0 / 0.5); }
/* Open: pulled back to the sides, leaving a sliver of drape framing the stage */
.stage-box:not(.empty) .curtain.left { transform: translateX(-86%); }
.stage-box:not(.empty) .curtain.right { transform: translateX(86%); }
.stage-sign {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 40px 20px 20px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s;
}
.stage-sign strong {
  font: 700 clamp(26px, 4.5vw, 44px) / 1.1 Georgia, "Times New Roman", serif;
  color: #f6d98a;
  letter-spacing: 0.03em;
  text-shadow: 0 2px 0 #5a3d06, 0 0 24px rgb(246 217 138 / 0.45);
}
.stage-sign span { color: #f3e6c8; font-size: 16px; text-shadow: 0 1px 3px #000; }
.stage-box:not(.empty) .stage-sign { opacity: 0; }
.spot {
  position: absolute;
  top: 10%;
  left: 0;
  width: 42%;
  aspect-ratio: 1;
  z-index: 3;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgb(255 238 190 / 0.32), rgb(255 238 190 / 0) 65%);
  animation: sweep 11s ease-in-out infinite alternate;
  will-change: transform;
}
.spot.two { animation-duration: 15s; animation-delay: -7s; background: radial-gradient(circle, rgb(200 220 255 / 0.22), rgb(200 220 255 / 0) 65%); }
@keyframes sweep {
  from { transform: translate(-15%, -10%); }
  to { transform: translate(155%, 15%); }
}
.stage-box:not(.empty) .spot { display: none; }
@media (prefers-reduced-motion: reduce) {
  .spot { animation: none; }
  .curtain { transition: none; }
}
/* Performers stand centre stage */
.stage-box .grid { display: flex; flex-wrap: wrap; justify-content: center; }
.stage-box .tile { flex: 0 1 400px; min-width: min(100%, 260px); }

/* On stage: the way back to the waiting room is the biggest, clearest button */
.controlbar .back-btn { background: #fff; border-color: #fff; color: #111; font-weight: 800; font-size: 18px; }
.controlbar .back-btn:hover { background: #e8e8e8; }

/* Guest page: shared screens, big enough to read. (The OBS page has its own screen layout.) */
.screens-section[hidden] { display: none; }
.screens { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.screen-view {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: 72vh;
  background: #000;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.screen-view video { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.screen-top { position: absolute; top: 8px; left: 8px; display: flex; gap: 8px; align-items: center; }
.screen-label { padding: 4px 10px; border-radius: 6px; background: rgb(0 0 0 / 0.7); font-weight: 700; }
.on-stream { padding: 4px 10px; border-radius: 6px; background: var(--live); color: #fff; font-weight: 800; font-size: 14px; }
.on-stream[hidden] { display: none; }
.fs-btn { position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 0.7); font-weight: 600; }
.screen-view.mine { aspect-ratio: auto; min-height: 120px; display: grid; place-items: center; background: var(--panel); }
.mine-note { display: grid; gap: 4px; text-align: center; padding: 40px 16px 16px; }
.mine-note span { color: var(--muted); }
/* The big viewer replaces the tiny corner preview on guests' tiles */
.guest-page .tile .pip { display: none !important; }
