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

/* The `hidden` attribute is only `display: none` in the browser's own stylesheet,
   so ANY author rule that sets display beats it. Several elements toggled from JS
   carry `display: flex` from a class (.screen, .group, #placeholder), which left
   them visible while marked hidden — the join screen and the running app rendered
   at the same time, and the host controls showed for guests. This has to win. */
[hidden] { display: none !important; }

:root {
  --bg: #0b0d10;
  --panel: #16191f;
  --line: #262b34;
  --text: #e7ebf0;
  --dim: #8b95a3;
  --accent: #4a7dff;
  --danger: #ff6b6b;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

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

/* --------------------------------------------------------------- join */

#join { align-items: center; justify-content: center; padding: 20px; }

.card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }

.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }

.card input {
  background: #0e1116;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}
.card input:focus { outline: none; border-color: var(--accent); }

.card button {
  margin-top: 4px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 11px;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.card button:disabled { opacity: .55; cursor: default; }

.hint { margin: 0; font-size: 12px; color: var(--dim); }
.error { margin: 0; font-size: 13px; color: var(--danger); }

/* -------------------------------------------------------------- stage */

#stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }

#frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: default;
}
#frame.dragging { cursor: grabbing; }

#screen {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: #000;
  /* layout() keeps the natural box size and does the work in transform, so no
     object-fit here. No will-change either: a video is composited anyway, and
     promoting a layer the size of a zoomed 1440p frame only costs memory. */
}

/* Safe mode (?safe=1): plain letterboxed playback, no transform, no probing. */
body.safe #screen {
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  transform: none !important;
  object-fit: contain;
}

#placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  pointer-events: none;
}
#placeholder p { margin: 0; }

#unmuteOverlay {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  z-index: 5;
}

/* ---------------------------------------------------------------- bar */

#bar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.group { display: flex; align-items: center; gap: 6px; }
.group.right { margin-left: auto; gap: 12px; }

#bar button, #bar select {
  background: #0e1116;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 12px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
#bar button:hover:not(:disabled), #bar select:hover { border-color: #3a424f; }
#bar button.active { border-color: var(--accent); color: #cddaff; }
#bar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#bar button:disabled { opacity: .4; cursor: default; }

.readout { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  background: #1e2531;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
  z-index: 10;
}

@media (max-width: 720px) {
  #bar { gap: 6px 10px; padding: 8px 10px; }
  #bar button, #bar select { padding: 6px 10px; font-size: 12px; }
  .group.right { width: 100%; margin-left: 0; justify-content: space-between; }
}
