/* ------------------------------------------------------------------
   Blade Ball 2D — RETRO 90s / SYNTHWAVE ARCADE skin.
   The game renders to the fullscreen canvas; everything here is DOM
   chrome layered above it.

   STRICT PALETTE (matches shared/config.js PALETTE):
     background   #0a0a0a on a dark magenta → deep cyan radial wash
     neon pink    #FF00FF  — buttons, arena wall accents
     neon cyan    #00FFFF  — panel borders, court lines, chips
     neon volt    #CCFF00  — status text, host controls, the ball

   Z-INDEX ARCHITECTURE (explicit, so layers never fight for stacking):
     0    #game             the canvas — always the base layer
     4    #crt-overlay      CRT scanlines + vignette over the canvas
     5    #hud-hint         tiny in-match corner hint
     15   #spectator-banner persistent "you're spectating" banner
     10   #ui               menu screens (mutually-exclusive .screen children)
     20   #bracket-overlay  tournament bracket, above everything
   ------------------------------------------------------------------ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --pink: #FF00FF;
  --cyan: #00FFFF;
  --volt: #CCFF00;
  --ink:  #0a0a0a;
  --panel: rgba(6, 3, 12, 0.82);
  --font-title: 'Press Start 2P', 'Courier New', monospace;
  --font-ui: 'VT323', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  /* Near-black wash: dark magenta core bleeding into deep cyan-green dark. */
  background:
    radial-gradient(ellipse at 50% 30%, #1a0620 0%, #0a0a0a 55%, #04100e 100%);
  color: #eafcff;
  font-family: var(--font-ui);
  font-size: 19px; /* VT323 runs small — base size compensates */
  -webkit-font-smoothing: none; /* keep pixel fonts crunchy */
}

.hidden { display: none !important; }

#game {
  position: fixed; inset: 0;
  display: block;
  z-index: 0;
  outline: none; /* it's a focus target (see main.js) but needs no visible ring */
}

/* ---------------- CRT scanlines + vignette ----------------
   Pure CSS overlay: zero per-frame canvas cost. Sits above the canvas
   but below the readable UI layers so menus stay legible. */
#crt-overlay {
  position: fixed; inset: 0; z-index: 4;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg,
      rgba(0, 0, 0, 0.22) 0px, rgba(0, 0, 0, 0.22) 1px,
      transparent 1px, transparent 3px),
    radial-gradient(ellipse at center,
      transparent 55%, rgba(0, 0, 0, 0.35) 100%);
}

#hud-hint {
  position: fixed; z-index: 5;
  right: 16px; bottom: 12px;
  font-size: 17px;
  letter-spacing: 1px;
  color: rgba(0, 255, 255, 0.4);
  text-transform: uppercase;
  pointer-events: none;
}

#spectator-banner {
  position: fixed; z-index: 15;
  top: 14px; left: 50%; transform: translateX(-50%);
  padding: 6px 22px;
  background: rgba(4, 8, 12, 0.88);
  border: 1px solid var(--cyan);
  font-size: 18px; letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
  box-shadow: 0 0 18px rgba(0, 255, 255, 0.35);
  pointer-events: none;
}

/* ================================================================
   Menu overlay shell — Flexbox stage centering whichever .screen is
   active; the screen scrolls independently on short viewports.
   ================================================================ */

#ui {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%,
    rgba(30, 4, 34, 0.92), rgba(3, 10, 12, 0.96));
  padding: 24px;
}

/* Arcade cabinet panel: dark translucent block with a thin glowing
   cyan frame. Sharp corners — nothing rounded in this aesthetic. */
.screen {
  display: flex; flex-direction: column; align-items: center;
  gap: 16px;
  padding: 36px 44px;
  max-width: 900px;
  width: min(94vw, 900px);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--cyan);
  box-shadow:
    0 0 22px rgba(0, 255, 255, 0.25),
    inset 0 0 40px rgba(0, 255, 255, 0.04);
}

/* ---------------- typography ---------------- */

.title {
  font-family: var(--font-title);
  font-size: clamp(22px, 4.5vw, 44px);
  line-height: 1.35;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow:
    0 0 10px var(--cyan),
    0 0 32px var(--pink);
}
.title span { color: var(--pink); text-shadow: 0 0 12px var(--pink); }

h2 {
  font-family: var(--font-title);
  font-size: clamp(14px, 2.4vw, 20px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0, 255, 255, 0.7);
}

.tagline { color: rgba(234, 252, 255, 0.8); line-height: 1.5; font-size: 20px; }
.hint { color: rgba(0, 255, 255, 0.6); font-size: 18px; max-width: 560px; letter-spacing: 0.5px; }
.fineprint { color: rgba(234, 252, 255, 0.4); font-size: 17px; text-transform: uppercase; letter-spacing: 1px; }
.fineprint b { color: var(--volt); text-shadow: 0 0 8px rgba(204, 255, 0, 0.6); }
.status { color: var(--volt); font-size: 19px; min-height: 22px; letter-spacing: 1px; text-shadow: 0 0 8px rgba(204, 255, 0, 0.5); }
.status.error { color: var(--pink); text-shadow: 0 0 8px rgba(255, 0, 255, 0.5); }

/* ---------------- base button reset (chips lean on this) ---------------- */

button {
  font-family: var(--font-ui);
  font-size: 18px;
  color: var(--cyan);
  background: rgba(4, 8, 12, 0.75);
  border: 1px solid rgba(0, 255, 255, 0.5);
  border-radius: 0;
  padding: 8px 18px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background .12s steps(2), color .12s steps(2), box-shadow .15s ease, transform .06s ease;
}
button:hover { background: rgba(0, 255, 255, 0.14); box-shadow: 0 0 12px rgba(0, 255, 255, 0.4); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

/* ================================================================
   Uniform .btn system — every primary CTA shares the exact same
   min-width/height/padding; variants only change the neon color.
   Blocky, minimalist: dark fill, neon border+text; hover INVERTS
   (solid neon fill, dark text) with a glow.
   ================================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  min-width: 240px;
  height: 52px;
  padding: 0 24px;
  font-family: var(--font-title);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--pink);
  background: rgba(10, 0, 12, 0.8);
  border: 2px solid var(--pink);
  border-radius: 0;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 0, 255, 0.25), inset 0 0 12px rgba(255, 0, 255, 0.08);
}
.btn:hover {
  background: var(--pink);
  color: var(--ink);
  box-shadow: 0 0 22px rgba(255, 0, 255, 0.8), 0 0 46px rgba(255, 0, 255, 0.35);
  transform: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled {
  opacity: 0.3; cursor: not-allowed;
  background: rgba(10, 0, 12, 0.8); color: var(--pink);
  transform: none; box-shadow: none;
}
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.btn-lg { min-width: 300px; }
.btn-sm { min-width: 150px; height: 42px; padding: 0 14px; font-size: 9px; }

/* .btn-primary intentionally identical to .btn — one pink CTA look
   everywhere (uniformity beats hierarchy in this aesthetic). */
.btn-primary {}

/* Host-only controls: volt yellow-green so they're unmistakable. */
.btn-host {
  color: var(--volt);
  border-color: var(--volt);
  box-shadow: 0 0 10px rgba(204, 255, 0, 0.25), inset 0 0 12px rgba(204, 255, 0, 0.08);
}
.btn-host:hover {
  background: var(--volt);
  color: var(--ink);
  box-shadow: 0 0 22px rgba(204, 255, 0, 0.8), 0 0 46px rgba(204, 255, 0, 0.35);
}
.btn-host:disabled { background: rgba(10, 0, 12, 0.8); color: var(--volt); }

/* Secondary/back actions: dimmed pink, same block. */
.btn-ghost { opacity: 0.75; }
.btn-ghost:hover { opacity: 1; }

.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: 100%; align-items: center; }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.form-row { gap: 8px; }

/* ---------------- inputs ---------------- */

input[type="text"] {
  font-family: var(--font-ui);
  font-size: 19px;
  color: #eafcff;
  background: rgba(4, 8, 12, 0.8);
  border: 1px solid rgba(0, 255, 255, 0.5);
  border-radius: 0;
  padding: 9px 14px;
  width: 220px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
input[type="text"]:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 12px rgba(0, 255, 255, 0.4); }
input[type="text"]::placeholder { color: rgba(0, 255, 255, 0.3); }
input[type="range"] { width: 220px; accent-color: var(--pink); }
.count-label {
  font-family: var(--font-title);
  font-size: 16px; color: var(--volt); width: 32px;
  text-shadow: 0 0 8px rgba(204, 255, 0, 0.6);
}

/* Chip-style toggles: cyan family, square, invert when selected. */
.count-btn {
  width: 44px; height: 44px;
  font-size: 19px;
  padding: 0;
  border-radius: 0;
  flex-shrink: 0;
}
.count-btn.selected, .mode-btn.selected {
  background: var(--cyan);
  color: var(--ink);
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(0, 255, 255, 0.6);
}
.mode-btn { font-size: 17px; padding: 9px 16px; }

/* ================================================================
   Form layout — CSS GRID for label/input alignment.
   ================================================================ */

.form-grid {
  display: grid;
  grid-template-columns: minmax(130px, auto) 1fr;
  align-items: center;
  gap: 12px 16px;
  width: 100%;
  max-width: 500px;
  text-align: left;
}
.form-grid label {
  font-size: 17px; letter-spacing: 1px; text-transform: uppercase;
  color: rgba(0, 255, 255, 0.75);
}
.form-grid label small { color: rgba(0, 255, 255, 0.35); font-size: 15px; }
.form-grid input[type="text"] { width: 100%; }
.form-grid .row { justify-content: flex-start; }
.form-grid-compact { max-width: 400px; grid-template-columns: auto 1fr; }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label { margin-top: 6px; }
}

/* ---------------- cosmetic pickers ---------------- */

.cosmetics, .player-card { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.picker-title {
  font-size: 16px; letter-spacing: 2px;
  color: rgba(0, 255, 255, 0.6);
  text-transform: uppercase;
}

.skin-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
/* Square swatches — blocky, not round. */
.skin-swatch {
  width: 30px; height: 30px;
  border-radius: 0;
  padding: 0;
  border: 2px solid rgba(0, 255, 255, 0.3);
  flex-shrink: 0;
}
.skin-swatch.selected {
  border-color: #ffffff;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.7);
  transform: scale(1.15);
}

.weapon-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.weapon-btn { font-size: 16px; padding: 7px 13px; }
.weapon-btn.selected {
  background: var(--cyan);
  color: var(--ink);
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(0, 255, 255, 0.6);
}

.player-cards {
  display: flex; flex-wrap: wrap; gap: 18px; justify-content: center;
}
.player-card {
  background: rgba(4, 8, 12, 0.6);
  border: 1px solid rgba(0, 255, 255, 0.35);
  border-radius: 0;
  padding: 16px 20px;
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.12), inset 0 0 20px rgba(0, 255, 255, 0.03);
}

/* ---------------- room list (Join Lobby) ---------------- */

.room-list {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 32vh;
  overflow-y: auto;
  padding-right: 4px;
}
.room-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  background: rgba(4, 8, 12, 0.6);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 0;
  padding: 9px 16px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s, box-shadow .15s;
}
.room-row:hover { background: rgba(0, 255, 255, 0.08); box-shadow: 0 0 12px rgba(0, 255, 255, 0.3); }
.room-row.selected { border-color: var(--cyan); background: rgba(0, 255, 255, 0.12); box-shadow: 0 0 16px rgba(0, 255, 255, 0.4); }
.room-row .rname {
  font-size: 20px; letter-spacing: 1px; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-row .rmode {
  font-size: 15px; letter-spacing: 1px;
  padding: 2px 8px;
  border: 1px solid rgba(0, 255, 255, 0.4);
  color: rgba(0, 255, 255, 0.8);
  white-space: nowrap;
  text-transform: uppercase;
}
.room-row .rmode.tournament { border-color: rgba(204, 255, 0, 0.5); color: var(--volt); }
.room-row .rcount { font-size: 17px; color: rgba(234, 252, 255, 0.6); white-space: nowrap; }
.room-row .rlock { font-size: 15px; color: var(--pink); letter-spacing: 1px; }
.room-row.in-game { opacity: 0.45; cursor: not-allowed; }

/* ---------------- lobby waiting room ---------------- */

#lobby-members {
  list-style: none;
  width: min(85vw, 480px);
  display: flex; flex-direction: column; gap: 8px;
  max-height: 34vh;
  overflow-y: auto;
}
#lobby-members li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: rgba(4, 8, 12, 0.6);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 0;
  padding: 8px 16px;
}
/* Square identity chip, matching the square swatches. */
#lobby-members .dot { width: 14px; height: 14px; border-radius: 0; box-shadow: 0 0 8px currentColor; }
#lobby-members .mname {
  text-align: left; font-size: 20px; letter-spacing: 1px; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#lobby-members .mhost { font-size: 15px; color: var(--volt); letter-spacing: 1px; text-shadow: 0 0 6px rgba(204, 255, 0, 0.6); }
#lobby-members .mready { color: rgba(234, 252, 255, 0.3); font-size: 16px; letter-spacing: 1px; }
#lobby-members .mready.yes { color: var(--volt); text-shadow: 0 0 6px rgba(204, 255, 0, 0.6); }

/* ================================================================
   Tournament bracket overlay — full-screen layer (z=20).
   ================================================================ */

#bracket-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 2, 8, 0.93);
  padding: 24px;
}

.bracket-panel {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  max-width: 94vw;
  max-height: 90vh;
  padding: 30px 38px;
  background: var(--panel);
  border: 1px solid var(--cyan);
  border-radius: 0;
  box-shadow: 0 0 26px rgba(0, 255, 255, 0.3), inset 0 0 40px rgba(0, 255, 255, 0.04);
}
.bracket-panel h2 { color: var(--volt); text-shadow: 0 0 14px rgba(204, 255, 0, 0.7); }

.bracket-tree {
  display: flex;
  flex-direction: row;
  gap: 36px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 90vw;
  padding: 12px 4px 20px;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 14px;
  min-width: 172px;
}
.bracket-round-label {
  font-family: var(--font-title);
  font-size: 9px; letter-spacing: 1px;
  text-align: center;
  color: rgba(0, 255, 255, 0.5);
  text-transform: uppercase;
}

.bracket-match {
  display: flex; flex-direction: column;
  border: 1px solid rgba(0, 255, 255, 0.35);
  border-radius: 0;
  overflow: hidden;
  background: rgba(4, 8, 12, 0.6);
}
.bracket-match.active { border-color: var(--pink); box-shadow: 0 0 16px rgba(255, 0, 255, 0.5); }
.bracket-slot {
  padding: 6px 10px;
  font-size: 18px; letter-spacing: 1px; text-transform: uppercase;
  color: rgba(234, 252, 255, 0.55);
  border-bottom: 1px solid rgba(0, 255, 255, 0.15);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bracket-slot:last-child { border-bottom: none; }
.bracket-slot.winner { color: var(--volt); background: rgba(204, 255, 0, 0.08); text-shadow: 0 0 6px rgba(204, 255, 0, 0.5); }
.bracket-slot.bye { color: rgba(234, 252, 255, 0.25); font-style: italic; }

.bracket-champion {
  font-family: var(--font-title);
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--volt);
  text-shadow: 0 0 18px rgba(204, 255, 0, 0.8);
}
