:root {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #1a222c;
  --line: #2b3642;
  --text: #e7ecf1;
  --muted: #9aa7b5;
  --accent: #0b84f3;
  --danger: #ff6b6b;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/*
  Author CSS `display:` rules beat the UA stylesheet for [hidden].
  Without this, `.remote { display: grid }` stays visible and covers Join.
*/
[hidden] {
  display: none !important;
}

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

button,
input {
  font: inherit;
}

.gate {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.gate h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
}

.gate p {
  margin: 0;
  color: var(--muted);
}

#join-form {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

#join-form input {
  width: 160px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  text-align: center;
}

#join-form button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.error {
  color: var(--danger);
  max-width: 420px;
  margin: 8px auto 0;
  line-height: 1.4;
}

.gate-status {
  color: var(--muted);
  font-size: 13px;
}

.gate-hint {
  max-width: 420px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.remote {
  position: fixed;
  inset: 0;
  height: 100%;
  width: 100%;
  display: block;
  background: #000;
  z-index: 2;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #000;
  overflow: hidden;
}

#frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  user-select: none;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Bottom-right HUD — peek always visible; controls expand above it. */
.hud {
  position: absolute;
  top: auto;
  right: 12px;
  bottom: 10px;
  z-index: 10;
  pointer-events: none;
}

/* One continuous hit target so moving from peek → buttons does not drop hover. */
.hud-hit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: auto;
}

.hud-peek {
  position: relative;
  z-index: 2;
  width: 40px;
  height: 8px;
  margin: 0 10px 2px 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: background 0.15s ease, width 0.15s ease;
}

.hud-peek:hover,
.hud-hit:hover .hud-peek,
.hud.is-open .hud-peek,
.hud.is-pinned .hud-peek {
  background: rgba(255, 255, 255, 0.65);
  width: 56px;
}

.hud-chrome {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.14s ease,
    transform 0.14s ease,
    visibility 0.14s;
}

/* Invisible bridge between peek and chrome so the cursor never “falls through”. */
.hud-hit::before {
  content: "";
  position: absolute;
  right: 0;
  bottom: 100%;
  width: 220px;
  height: 14px;
  pointer-events: none;
}

.hud-hit:hover::before,
.hud.is-open .hud-hit::before,
.hud.is-pinned .hud-hit::before {
  pointer-events: auto;
}

.hud-hit:hover .hud-chrome,
.hud.is-open .hud-chrome,
.hud.is-pinned .hud-chrome,
.hud-hit:focus-within .hud-chrome {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.72);
  border: 1px solid rgba(43, 54, 66, 0.9);
  backdrop-filter: blur(8px);
}

.screens-toggle.is-open {
  background: rgba(255, 255, 255, 0.12);
}

/* Panel opens upward from the bottom bar — chevron points up when closed. */
.screens-toggle .screens-chevron {
  transition: transform 0.15s ease;
  transform-origin: 8px 9.5px;
  transform: rotate(180deg);
}

.screens-toggle.is-open .screens-chevron {
  transform: rotate(0deg);
}

.screens-panel {
  min-width: 196px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(15, 20, 25, 0.88);
  border: 1px solid rgba(43, 54, 66, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 8px;
}

.quality-btns {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.quality-btn {
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  font: 600 10px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.quality-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.quality-btn.is-on {
  color: #fff;
  background: #2563eb;
}

.quality-btn.is-on:hover {
  background: #1d4ed8;
}

.screens-panel-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.screens-panel-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

/* HUD controls are mouse-only — never show a selected/focus ring while typing. */
.hud button:focus,
.hud button:focus-visible {
  outline: none;
}

.overlay:focus,
.overlay:focus-visible {
  outline: none;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
}

.live-btn.is-live .live-dot {
  background: #22c55e;
  animation: live-pulse 1.6s ease-out infinite;
}

.live-btn.is-wait .live-dot {
  background: #f59e0b;
}

.live-btn.is-error .live-dot {
  background: #ef4444;
  animation: none;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

/* Focused → green. Unfocused → warning amber (click to bring Presenter forward). */
.focus-btn {
  color: #fff;
  background: #f59e0b;
}

.focus-btn:hover {
  background: #d97706;
}

.focus-btn.is-focused {
  background: #16a34a;
}

.focus-btn.is-focused:hover {
  background: #15803d;
}

.screen-btn.is-on {
  color: #fff;
  background: #16a34a;
}

.screen-btn.is-on:hover {
  background: #15803d;
}

.monitor-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.monitor-btn {
  position: relative;
  min-width: 34px;
  padding: 0 6px;
  font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.02em;
}

.monitor-btn .monitor-glyph {
  display: grid;
  place-items: center;
  gap: 1px;
}

.monitor-btn .monitor-num {
  font-size: 9px;
  line-height: 1;
  opacity: 0.95;
}

.opt-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #0b84f3;
  border-radius: 50%;
  background: rgba(11, 132, 243, 0.25);
  pointer-events: none;
  z-index: 2;
  will-change: left, top;
}

.opt-ripple {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  pointer-events: none;
  z-index: 3;
  animation: opt-ripple 280ms ease-out forwards;
}

@keyframes opt-ripple {
  from {
    transform: scale(0.4);
    opacity: 1;
  }
  to {
    transform: scale(1.6);
    opacity: 0;
  }
}

.metrics {
  font-size: 11px;
  line-height: 1.2;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(15, 20, 25, 0.82);
  border: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  max-width: 220px;
  text-align: right;
}
