:root {
  --bg: #0c1118;
  --bg-2: #141c27;
  --ink: #e8eef7;
  --muted: #93a0b4;
  --line: rgba(232, 238, 247, 0.12);
  --accent: #3d9cf0;
  --accent-ink: #061018;
  --danger: #e45a5a;
  --ok: #3ecf8e;
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 156, 240, 0.22), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(62, 207, 142, 0.12), transparent 55%),
    var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(960px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero {
  min-height: calc(100vh - 4rem);
  display: grid;
  align-content: center;
  gap: 1rem;
}

.brand,
.brand-link {
  font-size: 0.85rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1.05;
  font-weight: 650;
}

.lede {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 0.7rem 1.1rem;
  border-radius: 0.55rem;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: rgba(232, 238, 247, 0.35);
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.btn.danger {
  border-color: rgba(228, 90, 90, 0.5);
  color: #ffb4b4;
}

.stage .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

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

.status.live {
  color: var(--ok);
}

.status.warn {
  color: #f0c14d;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.controls label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.controls input,
.controls select {
  width: 10rem;
  padding: 0.65rem 0.75rem;
  border-radius: 0.55rem;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
  font: inherit;
}

.controls select {
  width: auto;
  min-width: 14rem;
  cursor: pointer;
}

.meta {
  align-self: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.shell-wide {
  width: min(1400px, calc(100% - 2rem));
}

.studio-screen {
  position: relative;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 1rem;
  align-items: start;
}

.pane-label {
  margin: 0 0 0.45rem;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.pane-video {
  aspect-ratio: 16 / 9;
}

@media (max-width: 820px) {
  .studio-screen {
    grid-template-columns: 1fr;
  }
}

.video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #06090e;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  overflow: hidden;
}

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

.waiting {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
  background: rgba(6, 9, 14, 0.55);
}

.waiting.hidden,
video.hidden {
  display: none;
}

.hint {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.hint strong {
  color: var(--ink);
  font-weight: 600;
}

.viewer-hud {
  display: none;
}

body.view-fullpage {
  overflow: hidden;
}

body.view-fullpage .shell.stage {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body.view-fullpage .chrome {
  display: none;
}

/* Watch page: fill the viewport when immersive */
body.view-fullpage #videoWrap,
body.view-fullpage .video-wrap#videoWrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  background: #000;
}

body.view-fullpage #remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

body.view-fullpage .viewer-hud#viewerHud {
  display: flex;
}

/* Mobile landscape: edge-to-edge full screen stream */
@media (orientation: landscape) and (max-height: 520px) {
  body.mobile-landscape {
    overflow: hidden;
    background: #000;
  }

  body.mobile-landscape .shell.stage {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }

  body.mobile-landscape .chrome {
    display: none !important;
  }

  body.mobile-landscape #videoWrap,
  body.mobile-landscape .video-wrap#videoWrap {
    position: fixed;
    inset: 0;
    z-index: 60;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    background: #000;
  }

  body.mobile-landscape #remoteVideo,
  body.mobile-landscape #localVideo,
  body.mobile-landscape #streamVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  body.mobile-landscape .viewer-hud {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
  }

  body.mobile-landscape #videoWrap:hover .viewer-hud,
  body.mobile-landscape #videoWrap:focus-within .viewer-hud,
  body.mobile-landscape .viewer-hud:focus-within,
  body.mobile-landscape.show-hud .viewer-hud {
    opacity: 1;
    pointer-events: auto;
  }

  body.mobile-landscape .studio-screen {
    position: fixed;
    inset: 0;
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }

  body.mobile-landscape .studio-broadcast {
    display: none;
  }

  body.mobile-landscape .pane-label {
    display: none;
  }

  body.mobile-landscape .pane-video {
    height: 100dvh;
    border-radius: 0;
  }
}

body.view-fullpage .studio-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100vw;
  height: 100vh;
  margin: 0;
  gap: 0.75rem;
  padding: 0.75rem 0.75rem 3.5rem;
  align-content: stretch;
  align-items: stretch;
  border: 0;
  border-radius: 0;
  background: #000;
  grid-template-columns: 1.6fr 1fr;
}

body.view-fullpage .studio-stream,
body.view-fullpage .studio-broadcast {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.view-fullpage .pane-video {
  aspect-ratio: auto;
  flex: 1;
  min-height: 0;
  height: 100%;
  border-radius: 0.5rem;
}

body.view-fullpage .viewer-hud {
  display: flex;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 820px) {
  body.view-fullpage .studio-screen {
    grid-template-columns: 1fr;
  }
}

.hud-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
}

.hud-status,
.hud-viewers {
  font-size: 0.9rem;
  color: #d7e2f0;
}

.hud-status.live {
  color: var(--ok);
}

.hud-status.warn {
  color: #f0c14d;
}

.hud-actions {
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 560px) {
  .controls input,
  .controls select {
    width: 100%;
  }

  .controls label {
    width: 100%;
  }
}
