:root {
  --bg: #0b0c0e;
  --panel: #14161b;
  --panel-2: #1b1e25;
  --line: #272b34;
  --text: #e9ebef;
  --muted: #8b929e;
  --live: #ff2f2f;
  --ok: #3ddc84;
  --warn: #ffb020;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

/* Any author `display` rule beats the browser's [hidden] { display: none },
   which silently breaks every el.hidden = true in the app. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

button:hover:not(:disabled) {
  background: #242832;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.primary {
  background: #2b6cff;
  border-color: #2b6cff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #1d5ae6;
}

button.live {
  background: var(--live);
  border-color: var(--live);
  font-weight: 600;
}

input {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  width: 100%;
}

.mono {
  font-family: var(--mono);
  font-size: 0.75rem;
}

.muted {
  color: var(--muted);
}

/* ---------- backstage ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header.bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

header.bar h1 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.spacer {
  flex: 1;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.up {
  background: var(--ok);
}

.dot.down {
  background: var(--live);
}

.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.9rem;
  padding: 0.9rem;
  align-content: start;
}

.feed {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.feed.on-air {
  border-color: var(--live);
  box-shadow: 0 0 0 1px var(--live), 0 0 24px -6px var(--live);
}

/* The padding-top trick rather than aspect-ratio, which needs Chrome 88 and is
   therefore missing in vMix's embedded browser. Same reasoning as the program
   stage: without it the box is zero-height and the thumbnails vanish. */
.feed .video-wrap {
  position: relative;
  background: #000;
  height: 0;
  padding-top: 56.25%;
}

.feed video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: var(--live);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
}

.hotkey {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--muted);
}

.feed .meta {
  padding: 0.55rem 0.7rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feed .name {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.feed .controls {
  display: flex;
  gap: 0.4rem;
}

.feed .controls button {
  flex: 1;
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--muted);
}

.empty img {
  width: 220px;
  border-radius: var(--radius);
  background: #fff;
  padding: 0.6rem;
  margin-top: 1.2rem;
}

.empty code {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
}

/* ---------- join (phone) ---------- */

.phone {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}

.phone video {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.phone video.mirror {
  transform: scaleX(-1);
}

.phone .overlay {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(1rem, env(safe-area-inset-top)) 1rem
    max(1rem, env(safe-area-inset-bottom));
  pointer-events: none;
}

.phone .overlay > * {
  pointer-events: auto;
}

.tally {
  align-self: flex-start;
  background: var(--live);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
}

.tally.on {
  opacity: 1;
  transform: none;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.65;
  }
}

.phone .tray {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 0.6rem;
}

.phone .tray .state {
  flex: 1;
  font-size: 0.8rem;
  padding-left: 0.3rem;
}

.gate {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 10;
}

.gate .card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.gate h1 {
  font-size: 1.5rem;
  margin: 0;
  line-height: 1.25;
}

.gate p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.gate button {
  padding: 0.9rem;
  font-size: 1rem;
}

.error {
  color: var(--live);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ---------- program output ---------- */

body.program {
  background: #000;
  overflow: hidden;
  cursor: none;
}

/* Sized three ways on purpose. vMix's embedded Chromium is old enough to lack
   the `inset` shorthand, and a fixed-position box with no dimensions collapses
   to 0x0: the page renders, the picture does not, and it looks exactly like a
   compositing failure. Longhand offsets plus explicit viewport units mean it
   cannot happen again. Do not "tidy" these back into `inset: 0`. */
.program-stage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
}

/* Plain and always visible, no opacity animation and no transition. */
.program-stage video,
.program-stage canvas {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.program-stage.fill video {
  object-fit: cover;
}

/* Frame sources, canvas mode only. Off screen rather than display:none,
   because a hidden video is free to stop decoding. */
.sinks {
  position: fixed;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
}

.sinks:not(.active) {
  display: none;
}

.sinks video {
  width: 2px;
  height: 2px;
}

.debug {
  position: fixed;
  top: 1rem;
  left: 1rem;
  margin: 0;
  padding: 0.7rem 0.9rem;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ok);
  white-space: pre;
  z-index: 5;
}
