:root {
  color-scheme: dark;
  --bg: #0e1013;
  --panel: #171a1f;
  --line: #2a2f37;
  --text: #e6e8eb;
  --muted: #8b93a0;
  --accent: #4f8cff;
  --error: #ff6b6b;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

#connect-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

#connect-form {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
/* Grid items default to min-width: auto, so a long option would widen its select past the card. */
label > input:not([type=checkbox]), label > select { width: 100%; min-width: 0; }
label.check { display: flex; align-items: center; gap: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}
input[type=checkbox] { padding: 0; accent-color: var(--accent); }
button { cursor: pointer; }
button[type=submit] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .6; cursor: default; }
#status { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--muted); }
#status.error { color: var(--error); }

#stage {
  position: fixed;
  inset: 0;
  background: #000;
  outline: none;
}
#stage[hidden] { display: none; }

#video,
#wc-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}
#video[hidden],
#wc-canvas[hidden] { display: none; }

#toolbar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  background: rgba(23, 26, 31, .92);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  transition: transform .15s ease, visibility 0s .15s;
  visibility: hidden;
  white-space: nowrap;
}
/* Reveal the toolbar: the hotkey (Ctrl+Alt+Shift+M) works anywhere; out of
   fullscreen, hovering the top edge reveals it too. In fullscreen only the
   hotkey works, so a game never pops the menu open on a stray mouse move. */
#stage.show-toolbar #toolbar,
#stage:not(.fs) #toolbar:hover {
  transform: translate(-50%, 0);
  visibility: visible;
  transition: transform .15s ease;
}
/* The thin hover strip along the top edge exists only out of fullscreen. */
#stage:not(.fs) #toolbar::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -14px;
  height: 14px;
}
#toolbar button { padding: 5px 10px; font-size: 13px; background: transparent; }
#toolbar button:hover { background: var(--line); }
#hint { font-size: 12px; color: var(--muted); padding: 0 4px; }

#snip {
  position: absolute;
  inset: 0;
  z-index: 5;
  cursor: crosshair;
  touch-action: none;
}
#snip[hidden] { display: none; }
#snip-rect {
  position: absolute;
  border: 1px solid #fff;
  background: rgba(79, 140, 255, .22);
  /* darken everything outside the selection */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35);
  pointer-events: none;
}
#snip-rect[hidden] { display: none; }
#snip-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  background: rgba(23, 26, 31, .95);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
}

#stats {
  position: absolute;
  top: 8px;
  left: 8px;
  margin: 0;
  padding: 8px 10px;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  background: rgba(0, 0, 0, .7);
  border-radius: 6px;
  pointer-events: none;
}

#reconnect {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0, 0, 0, .72);
  color: var(--text);
}
#reconnect[hidden] { display: none; }
#reconnect p { margin: 0; font-size: 15px; }
#reconnect .spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rp-spin 0.8s linear infinite;
}
@keyframes rp-spin { to { transform: rotate(360deg); } }
#reconnect-cancel {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}

#toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  background: rgba(23, 26, 31, .95);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  pointer-events: none;
}

@media (max-width: 640px) {
  #hint { display: none; }
}
