:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --surface: #151922;
  --surface-2: #1e2430;
  --border: #2a3140;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --success: #4ade80;
  --danger: #f87171;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(108, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 120, 80, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.role-badge {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.player-panel,
.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.player-panel {
  padding: 16px;
}

.video-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
}

video#movie {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.92rem;
}

.stat-row span:first-child {
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover {
  background: #252c3a;
  border-color: #3a4356;
}

button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #0b1020;
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent-hover);
}

button:active {
  transform: translateY(1px);
}

.invite-hint {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--success);
}

.public-url-hint {
  color: #8eb4ff;
  word-break: break-all;
  font-size: 0.85rem;
  margin: 6px 0 0;
}

.call-panel {
  display: grid;
  gap: 12px;
}

.call-videos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.call-videos video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: #000;
  border: 1px solid var(--border);
}

.webrtc-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.guest-note {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(108, 140, 255, 0.08);
  border: 1px solid rgba(108, 140, 255, 0.18);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.unlock-playback {
  width: 100%;
  margin-top: 10px;
}

.room-gate[hidden] {
  display: none !important;
}

.room-gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(6px);
  z-index: 100;
}

.room-gate-card {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.room-gate-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.room-gate-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.room-gate-card input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.room-gate-error {
  min-height: 1.2em;
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 0.88rem;
}

.room-gate-status {
  min-height: 1.2em;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.joined-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 12px 20px;
  border-radius: 10px;
  background: rgba(74, 222, 128, 0.15);
  border: 1px solid rgba(74, 222, 128, 0.4);
  color: var(--success);
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}

.download-panel {
  margin-bottom: 16px;
  padding: 20px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.download-panel h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.download-film-name {
  margin: 0 0 4px;
  font-weight: 600;
}

.download-film-size {
  margin: 0 0 12px;
  color: var(--muted);
}

.download-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.download-progress-wrap {
  margin-top: 16px;
}

.download-progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.download-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.download-progress-text {
  margin: 10px 0 4px;
  font-size: 0.9rem;
}

.download-eta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.local-file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

a.button {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

a.button.primary {
  background: var(--accent);
  border: 1px solid transparent;
  color: #0b1020;
  font-weight: 600;
}

.badge-recommended {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--success);
  vertical-align: middle;
}

.stream-fallback {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.stream-fallback summary {
  cursor: pointer;
  color: var(--text);
}

.guest-phase {
  margin: 12px 0 0;
  font-weight: 600;
  color: var(--accent-hover);
}

.audio-panel {
  display: grid;
  gap: 10px;
}

.volume-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--muted);
}

.volume-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
}

.audio-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

#pushToTalk.ptt-active {
  background: var(--accent);
  color: #0b1020;
  border-color: transparent;
}

/* ---------- Theater / movie-room layout ---------- */

.theater-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.theater-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stage {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -12%, rgba(140, 24, 36, 0.20), transparent 62%),
    #0a0507;
  border: 1px solid #241017;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  padding: 0 clamp(14px, 2.6vw, 40px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen video#movie {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

/* Velvet curtain drapes flanking the screen */
.screen::before,
.screen::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: clamp(14px, 2.6vw, 40px);
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 65%),
    repeating-linear-gradient(90deg, #2a070b 0, #5c1119 7px, #360a10 14px);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.7);
}

.screen::before {
  left: 0;
}

.screen::after {
  right: 0;
  transform: scaleX(-1);
}

.unlock-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.unlock-overlay[hidden] {
  display: none;
}

.crew {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  padding: 14px clamp(14px, 2.6vw, 40px);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.45));
  border-top: 1px solid rgba(140, 24, 36, 0.25);
}

.feed {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 16 / 10;
  background: #05070d;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.feed-self {
  justify-self: end;
}

.feed-remote {
  justify-self: start;
}

.feed video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.feed-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  background: #05070d;
}

.feed-placeholder[hidden] {
  display: none;
}

.feed-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.deck {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.mode-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.deck-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.deck-row button {
  white-space: nowrap;
}

#pushToTalk {
  min-width: 120px;
}

#fullscreen.is-active {
  background: var(--accent);
  color: #0b1020;
  border-color: transparent;
}

/* Fullscreen (native) + CSS fallback: fill viewport, keep feeds visible */
.stage.theater-active {
  position: fixed;
  inset: 0;
  z-index: 1000;
  max-width: none;
  border: none;
  border-radius: 0;
}

.stage:fullscreen {
  border: none;
  border-radius: 0;
  background: #000;
}

.stage:fullscreen .screen,
.stage.theater-active .screen {
  aspect-ratio: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.stage:fullscreen .crew,
.stage.theater-active .crew {
  flex: 0 0 auto;
}

.stage:fullscreen .feed,
.stage.theater-active .feed {
  max-width: min(26vw, 360px);
}

/* Chat mode: webcam-first layout */
.stage.mode-chat .screen {
  display: none;
}

.stage.mode-chat .crew {
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  gap: 14px;
}

.stage.mode-chat .feed {
  max-width: none;
  aspect-ratio: 16 / 10;
}

.stage.mode-chat .deck {
  grid-column: 1 / -1;
  order: 3;
  padding-top: 6px;
}

.setup {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}

.setup > section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.setup-wide {
  grid-column: 1 / -1;
}

.setup-hidden {
  display: none !important;
}

.theater-mode .theater-header {
  display: none;
}

.discussion-setting input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.resume-countdown {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  min-width: 5rem;
  padding: 20px 28px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(108, 140, 255, 0.45);
  color: var(--text);
  font-size: 3rem;
  font-weight: 700;
  text-align: center;
  line-height: 1;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.resume-countdown[hidden] {
  display: none;
}

.download-panel.setup-wide {
  margin-bottom: 0;
  background: var(--surface-2);
  border-color: rgba(108, 140, 255, 0.35);
}

@media (max-width: 720px) {
  .crew {
    grid-template-columns: 1fr 1fr;
  }

  .feed-self {
    order: 1;
    justify-self: center;
  }

  .feed-remote {
    order: 2;
    justify-self: center;
  }

  .deck {
    order: 3;
    grid-column: 1 / -1;
  }
}
