:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1b1f27;
  --text: #e6e8ee;
  --muted: #8c93a3;
  --accent: #4f8cff;
  --ok: #2ecc71;
  --warn: #f1c40f;
  --err: #e74c3c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid #2a2f3a;
}

#connect-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

#connect-form label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--muted);
  gap: 2px;
}

#connect-form label.check {
  flex-direction: row;
  align-items: center;
  padding-bottom: 6px;
  gap: 4px;
}

#connect-form input[type="text"],
#connect-form input[type="password"] {
  background: #0e1015;
  color: var(--text);
  border: 1px solid #333a48;
  border-radius: 4px;
  padding: 5px 8px;
  min-width: 160px;
}

#url { min-width: 260px !important; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: default; }
#disconnect { background: #3a4150; }
#fullscreen { background: #3a4150; }

.status-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.status {
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  background: #333a48;
}
.status.idle       { background: #333a48; }
.status.connecting { background: var(--warn); color: #111; }
.status.connected  { background: var(--ok); color: #111; }
.status.disconnected { background: #555c6b; }
.status.error      { background: var(--err); }

.stats {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
  background: #000;
  cursor: crosshair;
}
#video:focus { box-shadow: inset 0 0 0 2px var(--accent); }
#stage:fullscreen #video { cursor: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  background: rgba(0, 0, 0, .55);
}
/* display:flex above would otherwise beat the UA rule for [hidden]. */
.overlay[hidden] { display: none; }

#video { touch-action: none; }   /* no browser pan/zoom on the video; we handle touches */
#keyboard { background: #3a4150; }

.kbd {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* CSS fullscreen fallback: hide chrome, stage fills the visual viewport. */
body.pseudo-fs .bar,
body.pseudo-fs .hint { display: none; }
body.pseudo-fs { height: 100dvh; }
body.pseudo-fs #stage { height: 100dvh; }
body.pseudo-fs #video { cursor: none; }

.fs-tools {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  right: max(6px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  opacity: .55;
  z-index: 10;
}
.fs-tools:hover, .fs-tools:active { opacity: 1; }
.fs-tools button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 18px;
  background: rgba(30, 34, 44, .85);
  border: 1px solid #444c5c;
}
.fs-tools[hidden] { display: none; }

@media (max-width: 700px) {
  .bar { padding: 6px 8px; }
  #connect-form input[type="text"],
  #connect-form input[type="password"],
  #url { min-width: 0 !important; width: 100%; }
  #connect-form label { flex: 1 1 100%; }
  .hint { display: none; }
}

.hint {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid #2a2f3a;
}
