* { box-sizing: border-box; }

/* Without this, the `hidden` attribute silently stops working on any element whose own rule sets
   `display` (e.g. `#stage`/`#play-controls` below use `display: flex` for layout) -- a real,
   confirmed-live bug: the browser's own `[hidden] { display: none }` UA-stylesheet rule loses to
   ANY normal author declaration for the same property, regardless of selector specificity (origin
   beats specificity in the cascade), so `#play-controls { display: flex }` was overriding its own
   `hidden` attribute and leaving the Play/stats-toggle buttons showing on the connect screen and
   during actual gameplay. `!important` here forces `[hidden]` to always win, which is exactly what
   the attribute is supposed to mean everywhere in this file -- toggle it in JS/HTML and trust it,
   with no per-element `#id[hidden]` overrides to remember for every current or future element.
   Standard practice for this reason (most CSS resets include this exact rule). */
[hidden] { display: none !important; }

:root {
  --electric-blue: #00e5ff;
  --electric-blue-hover: #33ebff;
}

html, body {
  margin: 0;
  height: 100%;
  background: #111;
  color: #eee;
  font-family: system-ui, sans-serif;
}

#connect-panel {
  max-width: 28rem;
  margin: 4rem auto;
  padding: 1.5rem;
  background: #1b1b1b;
  border-radius: 0.5rem;
}

#connect-panel h1 {
  margin-top: 0;
  font-size: 1.25rem;
}

#connect-panel .hint {
  color: #999;
  font-size: 0.85rem;
  margin-top: -0.5rem;
}

#connect-panel label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: #ccc;
}

#connect-panel input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem;
  background: #0c0c0c;
  border: 1px solid #333;
  color: #eee;
  border-radius: 0.25rem;
}

#connect-panel button {
  width: 100%;
  padding: 0.6rem;
  background: #3b82f6;
  border: none;
  color: white;
  font-weight: 600;
  border-radius: 0.25rem;
  cursor: pointer;
}

#connect-panel button:hover { background: #2563eb; }

#status {
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: #f59e0b;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
}

/* width/height: 100% (not max-width/max-height) so the canvas actually fills #stage instead of
   only ever being capped by it -- #stage already tracks the real viewport (100vw/100vh, fullscreen
   or not), so without this the canvas just sat at its own native stream resolution, centered in
   whatever extra space #stage's flex centering left around it (a real, confirmed-live bug: a
   uniform black border on all four sides, worst in fullscreen since that's when the gap between
   the stream's negotiated resolution and the actual screen is largest). object-fit: contain is
   what actually preserves aspect ratio here -- it scales the canvas's rendered bitmap (whatever
   drawImage() painted) to fit the box, letterboxing/pillarboxing only the two sides that need it
   instead of stretching the picture, matching the native Windows client's own
   Renderer::letterboxed_viewport behavior (see PERFORMANCE.md). Supported for <canvas> in
   Chromium, which this client already requires. */
#screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Touches go to the host; the browser mustn't pan/zoom. */
  touch-action: none;
}

/* Real Pointer Lock already hides the OS cursor unconditionally per spec once engaged (the
   #local-cursor <img> in index.html/app.js is what's actually visible now, drawn independent of
   this) -- this class/rule is harmless, defensive redundancy for the rare case that doesn't
   hold, not load-bearing. */
#screen.pointer-locked {
  cursor: none;
}

#stats {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  margin: 0;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.6);
  color: var(--electric-blue);
  font-size: 0.6rem;
  line-height: 1.3;
  border-radius: 0.25rem;
  pointer-events: none;
  white-space: pre;
}

/* Above #gate-overlay (15), below #play-controls (30). */
#keyboard-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.5rem;
  background: rgba(42, 42, 42, 0.8);
  color: #aaa;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}
#keyboard-btn svg {
  width: 100%;
  height: 100%;
}

/* Invisible but focusable (display:none can't take focus); 16px font stops mobile focus-zoom. */
#keyboard-proxy {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  font-size: 16px;
  border: 0;
  padding: 0;
}

/* See index.html's own comment -- position is set directly in app.js (getBoundingClientRect()-
   derived, viewport coordinates), not here; this just fixes the positioning mode and keeps it
   out of the way of real pointer events. */
#local-cursor {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 10;
}

/* See index.html's own comment -- purely visual, toggled in lockstep with #enter-fullscreen-btn.
   Sits above the canvas/local cursor but below that button (z-index 30) so it stays fully
   readable/clickable rather than getting dimmed along with everything else. pointer-events: none
   so it's never a click target itself -- clicking "through" it onto the dimmed canvas is
   harmless (inputActive() already blocks anything from being sent while gated regardless). */
#gate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 15;
  pointer-events: none;
}

/* Wraps #enter-fullscreen-btn + #stats-toggle-btn + #snapshot-btn (+ #phone-mode-btn on touch devices) -- shown/hidden together as one
   unit (see index.html's own comment and app.js's updateEnterFullscreenPrompt()), fixed/centered
   exactly where #enter-fullscreen-btn used to position itself directly. */
#play-controls {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 30;
}

/* Deliberately large/impossible to miss. This is the *only* way fullscreen + Pointer Lock ever
   engage, and the only thing gating input from reaching the game at all (see index.html's own
   comment) -- shown immediately on connect, and again any time either drops without the session
   ending. The pulse (glow + slight scale, looping) is purely to draw the eye to it on first
   render; paused on hover so the button reads as settled/responsive right when it matters, i.e.
   the moment before an actual click. */
#enter-fullscreen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 2.5rem;
  background: var(--electric-blue);
  color: #001b26;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  animation: play-button-pulse 1.8s ease-in-out infinite;
}
#enter-fullscreen-btn svg {
  width: 1.75rem;
  height: 1.75rem;
  /* Optical centering: a play triangle's own visual weight leans left of its bounding box, so a
     geometrically centered icon reads as slightly off-center to the eye. */
  margin-left: 0.2rem;
}
#enter-fullscreen-btn:hover {
  background: var(--electric-blue-hover);
  animation-play-state: paused;
}
@keyframes play-button-pulse {
  0%, 100% {
    box-shadow: 0 0.25rem 1rem rgba(0, 229, 255, 0.5);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0.25rem 2rem rgba(0, 229, 255, 0.9);
    transform: scale(1.04);
  }
}

/* Stats-overlay on/off switch -- see index.html's own comment and app.js's statsOverlayVisible
   click handler. Grey/inactive by default look; `.on` (toggled in app.js, applied by default in
   the markup since the panel starts visible) switches the icon to the same electric blue used
   everywhere else. The SVG's stroke="currentColor" is what makes a plain `color` swap here enough
   to recolor the icon -- no separate active/inactive asset needed.
   #snapshot-btn (Download Snapshot, see app.js's downloadSessionLog()) shares the base, svg and
   hover rules below so it matches this button's look exactly; it's a one-shot action rather than
   a toggle, so it has no `.on` state and the `.on` rules further down stay stats-only. */
#stats-toggle-btn,
#snapshot-btn,
#phone-mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.5rem;
  background: #2a2a2a;
  color: #777;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}
#stats-toggle-btn svg,
#snapshot-btn svg,
#phone-mode-btn svg {
  width: 100%;
  height: 100%;
}
#stats-toggle-btn:hover,
#snapshot-btn:hover,
#phone-mode-btn:hover {
  background: #383838;
}
#stats-toggle-btn.on,
#phone-mode-btn.on {
  background: rgba(0, 229, 255, 0.15);
  color: var(--electric-blue);
  box-shadow: 0 0 0.5rem rgba(0, 229, 255, 0.4);
}
#stats-toggle-btn.on:hover,
#phone-mode-btn.on:hover {
  background: rgba(0, 229, 255, 0.25);
}
