/* NerdWars page.
   The game renders a 320x180 buffer and scales it by whole numbers, so the
   surrounding frame stays out of its way: no rounding on the canvas itself,
   no filters, nothing that would resample a pixel. */

.nw-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The game panel reaches past the 1100px shell so a wide monitor can hit the
   next whole scale step -- the game only ever draws at 1x, 2x, 3x... of
   320x180, so a few hundred extra pixels is the difference between 960x540
   and 1600x900.

   Done with negative margins rather than `width: 100vw; transform:
   translateX(-50%)`: a transform moves the box visually but leaves its layout
   position where it was, so the page still scrolls sideways to reach a box
   that only *looks* centred. Negative margins actually widen the box.
   The 46vw/820px cap keeps it clear of the scrollbar. */
.nw-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin: 1.4rem 0;
  margin-left: calc(50% - min(46vw, 820px));
  margin-right: calc(50% - min(46vw, 820px));
}

.nw-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.7rem;
}

/* Sits in the bar above the canvas, beside Fullscreen. Deliberately not in
   the online panel: it is about the game, not about the room. */
.nw-music {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin-left: auto;
}

.nw-music input[type="range"] {
  width: 8.5rem;
  accent-color: #8fd6ff;
  cursor: pointer;
}

.nw-music-val {
  min-width: 2.6rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.nw-bar-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.nw-btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink);
  background: var(--brand-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

.nw-btn:hover {
  border-color: #4a5170;
}

.nw-btn:focus-visible {
  outline: 2px solid #59a5ff;
  outline-offset: 2px;
}

/* The mount the game measures itself against. It sets data-nerdwars-focus
   on this element when the player clicks in or out. */
.nw-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  /* 16:9, matching the game's 320x180 buffer, so the box never disagrees
     with what the game wants to draw into it. */
  aspect-ratio: 16 / 9;
  width: 100%;
  cursor: pointer;
}

.nw-stage canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  display: block;
  background: #000;
}

.nw-stage[data-nerdwars-focus="on"] {
  border-color: #4a5170;
  cursor: default;
}

/* Prompt covering the game until it owns the keyboard. Hidden the moment
   the player clicks in. */
.nw-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.6rem;
  text-align: center;
  padding: 1rem;
  background: rgba(8, 9, 15, 0.72);
  transition: opacity 0.2s ease;
}

.nw-stage[data-nerdwars-focus="on"] .nw-veil {
  opacity: 0;
  pointer-events: none;
}

.nw-veil-key {
  font-family: "Bitter", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 1rem;
  color: var(--ink);
}

.nw-veil-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.nw-note,
.nw-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.8rem 0 0;
}

/* ---- controls table ---- */

.nw-keys-wrap {
  overflow-x: auto;
  margin: 0.6rem 0 1rem;
}

.nw-keys {
  border-collapse: collapse;
  width: 100%;
  min-width: 34rem;
  font-size: 0.92rem;
}

.nw-keys th,
.nw-keys td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.nw-keys thead th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nw-keys tbody th {
  font-weight: 700;
}

.nw-keys tbody tr:last-child th,
.nw-keys tbody tr:last-child td {
  border-bottom: 0;
}

.nw-p1 {
  color: #59a5ff;
}

.nw-p2 {
  color: #ff5f5f;
}

.nw-keys kbd {
  display: inline-block;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--brand-soft);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-right: 0.25rem;
  min-width: 1.5rem;
  text-align: center;
}

/* In fullscreen the stage IS the screen: drop the 16:9 box and the framing so
   the game can take every pixel. The prompt goes too, since entering
   fullscreen already hands it the keyboard. */
.nw-stage:fullscreen {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  cursor: default;
}

.nw-stage:fullscreen .nw-veil {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .nw-veil {
    transition: none;
  }
}

/* ---- online lobby ----
   Phase drives visibility: `idle` shows the create/join controls, anything
   with a room shows the lobby, and `playing` hides the whole thing so it
   isn't sitting under a live match. */

.nw-online-lede {
  color: var(--muted);
  margin: 0 0 1rem;
}

#nw-online[data-phase="idle"] [data-when="room"],
#nw-online[data-phase="joining"] [data-when="room"] {
  display: none;
}

#nw-online[data-phase="hosting"] [data-when="idle"],
#nw-online[data-phase="lobby"] [data-when="idle"],
#nw-online[data-phase="playing"] [data-when="idle"] {
  display: none;
}

#nw-online[data-phase="playing"] [data-when="room"] {
  display: none;
}

.nw-online-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.nw-or {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0.2rem;
}

.nw-join-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.nw-input {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  width: 6.5rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
}

.nw-input:focus-visible,
.nw-select:focus-visible {
  outline: 2px solid #59a5ff;
  outline-offset: 2px;
}

.nw-btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.nw-btn-primary:hover {
  background: #ffffff;
}

.nw-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nw-room {
  margin: 0.2rem 0 1rem;
  color: var(--muted);
}

.nw-room strong {
  font-family: "Bitter", Georgia, serif;
  font-size: 1.6rem;
  letter-spacing: 0.3em;
  color: var(--ink);
  margin-left: 0.4rem;
}

.nw-lobby {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.nw-lobby-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.nw-lobby-label {
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 6.5rem;
}

.nw-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* The accent on each button is the character's own colour, sampled from
   their sprite, so the lobby matches the character select in the game. */
.nw-pick {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid var(--pick, var(--line));
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.nw-pick[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--pick, var(--ink));
  border-left-width: 3px;
  background: var(--brand-soft);
}

.nw-select {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
}

.nw-their {
  color: var(--ink);
  font-weight: 700;
}

/* The room now holds up to four, so who is in it is a list rather than a
   single opponent. Seats are always drawn, empty ones included, so the room
   filling up is visible rather than inferred. */
.nw-seats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nw-seat {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
  border-radius: 0.4rem;
  font-size: 0.85rem;
}

.nw-seat.is-empty {
  opacity: 0.45;
  border-style: dashed;
}

.nw-seat.is-you {
  border-color: currentColor;
  box-shadow: inset 0 0 0 1px currentColor;
}

.nw-seat-who {
  color: var(--muted);
}

.nw-seat-char {
  color: var(--ink);
  font-weight: 700;
}

.nw-seat-empty {
  color: var(--muted);
  font-style: italic;
}

.nw-room-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.nw-lobby-buttons {
  margin-top: 0.2rem;
}

.nw-status {
  min-height: 1.2rem;
  margin: 0.9rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.nw-status[data-kind="good"] { color: #8fe08f; }
.nw-status[data-kind="warn"] { color: #ffb066; }
