/* ==========================================================================
   BOMBERMAN DOM — Cyber Battle Arena Theme
   Dark, energetic, DOM-only. Animations use transform/opacity for 60fps.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg-0: #04050d;
  --bg-1: #0a0c1c;
  --panel: rgba(17, 20, 42, 0.72);
  --panel-solid: #101226;
  --panel-border: rgba(139, 92, 246, 0.22);
  --text: #e7e9ff;
  --text-dim: #8b90b8;

  --purple: #a855f7;
  --violet: #7c3aed;
  --blue: #38bdf8;
  --pink: #ec4899;
  --orange: #f97316;
  --red: #ef4444;
  --green: #22c55e;
  --gold: #facc15;

  --grad-primary: linear-gradient(135deg, #7c3aed 0%, #c026d3 50%, #ec4899 100%);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;

  /* Retro pixel-art theme tokens — shared by .page-home, .page-lobby and
     .page-game so no page duplicates them. Other pages don't reference
     --px-* at all. */
  --px-bg-0: #0b0714;
  --px-bg-1: #1c1330;
  --px-panel: rgba(15, 34, 61, 0.62);
  --px-border: #5b7ca3;
  --px-text: #f2f6fb;
  --px-text-dim: #9fb8d4;
  --px-accent: #4fa3e3;
  --px-cta: #ff8c3c;
  --px-cta-text: #241205;
  --px-error: #ff4d6d;
  --px-font-title: "Press Start 2P", var(--font);
  --px-font-body: "VT323", var(--font);

  /* Shared background photo for .page-home, .page-lobby and .page-game —
     one definition so every screen always uses the exact same treatment.
     The trailing solid gradient is an opaque fallback so the pages stay
     clean and on-theme while media/ui/starting-screen.png doesn't exist yet;
     once the photo is in place it fully covers this layer. */
  --pixel-bg-photo:
    linear-gradient(180deg, rgba(5, 4, 10, 0.35) 0%, rgba(5, 4, 10, 0.7) 55%, rgba(5, 4, 10, 0.9) 100%),
    url("/media/ui/starting-screen.png") no-repeat center center / cover,
    linear-gradient(180deg, var(--px-bg-1) 0%, var(--px-bg-0) 70%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg-0);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

/* Ambient arena glow — lives on <body>, never re-rendered by the framework */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -2;
  background:
    radial-gradient(circle at 15% 20%, rgba(124, 58, 237, 0.28), transparent 40%),
    radial-gradient(circle at 85% 15%, rgba(56, 189, 248, 0.16), transparent 35%),
    radial-gradient(circle at 75% 85%, rgba(236, 72, 153, 0.18), transparent 40%),
    radial-gradient(circle at 25% 80%, rgba(249, 115, 22, 0.10), transparent 35%);
  animation: ambientDrift 18s ease-in-out infinite alternate;
  will-change: transform;
}

/* Faint tactical grid overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(139, 92, 246, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 92, 246, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 78%);
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 78%);
}

@keyframes ambientDrift {
  0%   { transform: translate3d(-2%, -1%, 0) scale(1); }
  100% { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}
::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.4);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.6);
}

/* ---------- Page shell ---------- */
.page {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 34px 38px;
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.section-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #f0abfc, #a855f7 60%, #7c3aed);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* ---------- Buttons ---------- */
.btn {
  padding: 12px 26px;
  border-radius: 12px;
  border: none;
  background: var(--grad-primary);
  color: #fff;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow:
    0 6px 20px rgba(124, 58, 237, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow:
    0 10px 28px rgba(236, 72, 153, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------- Inputs ---------- */
.input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid rgba(139, 92, 246, 0.3);
  background: rgba(8, 10, 24, 0.8);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--text-dim);
}

.input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.18);
}

/* ---------- Connection status pill ---------- */
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(13, 15, 32, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.connection-status.connected {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.4);
}

.connection-status.connecting {
  color: var(--gold);
  border-color: rgba(250, 204, 21, 0.4);
}

.connection-status.disconnected,
.connection-status.error {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.4);
}

/* ---------- Error banner ---------- */
.error-message {
  width: 100%;
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  text-align: center;
  font-weight: 600;
}

/* ---------- Controls hint ---------- */
.controls-hint {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 12px;
}

.hint-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hint-sep {
  opacity: 0.6;
}

.hint-label {
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-left: 3px;
}

kbd {
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom-width: 2px;
  font: 700 11px var(--font);
  color: var(--text);
  min-width: 14px;
  text-align: center;
}

/* ==========================================================================
   1. HOME / NICKNAME PAGE — retro pixel-art arcade rebuild
   Fully self-contained: every rule here is scoped under .page-home so the
   shared .page/.btn/.input/etc. tokens used by the other screens are
   untouched. Background photo shared with .page-lobby via --pixel-bg-photo
   below so both screens use the exact same treatment.
   ========================================================================== */
.page-home {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 32px 24px;
  background: var(--pixel-bg-photo);
  font-family: var(--px-font-body);
  color: var(--px-text);
}

/* ---------- CRT scanline overlay ---------- */
.pixel-scanlines {
  position: absolute;
  inset: 0;
  z-index: 0;
  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
  );
}

/* ---------- Centered content column ---------- */
.home-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

.pixel-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-family: var(--px-font-title);
  line-height: 1;
}

.pixel-title-main {
  font-size: clamp(24px, 5.5vw, 40px);
  color: var(--px-text);
  text-shadow: 2px 2px 0 var(--px-accent), 5px 5px 0 #000;
}

.pixel-title-accent {
  font-size: clamp(14px, 3vw, 20px);
  color: var(--px-cta);
  text-shadow: 2px 2px 0 #000;
}

.pixel-tagline {
  margin: 16px 0 0;
  font-family: var(--px-font-body);
  font-size: 20px;
  letter-spacing: 0.06em;
  color: var(--px-text-dim);
}

.page-home .connection-status {
  margin: 16px auto 0;
  border-radius: 0;
  background: var(--px-panel);
  border: 2px solid var(--px-border);
  color: var(--px-text-dim);
  font-family: var(--px-font-body);
  font-size: 14px;
  letter-spacing: 0.08em;
}

.page-home .connection-status.connected {
  color: #4ade80;
  border-color: #4ade80;
}

.page-home .connection-status.connecting {
  color: var(--px-cta);
  border-color: var(--px-cta);
}

.page-home .connection-status.disconnected,
.page-home .connection-status.error {
  color: var(--px-error);
  border-color: var(--px-error);
}

/* ---------- Form ---------- */
.home-form {
  margin-top: 56px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: 320px;
  max-width: 100%;
}

.pixel-input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border-radius: 0;
  border: 3px solid var(--px-border);
  background: var(--px-panel);
  color: var(--px-text);
  font-family: var(--px-font-body);
  font-size: 20px;
  letter-spacing: 0.05em;
  outline: none;
  transition: border-color 0.1s steps(2), box-shadow 0.1s steps(2);
}

.pixel-input::placeholder {
  color: var(--px-text-dim);
}

.pixel-input:focus {
  border-color: var(--px-accent);
  box-shadow: 4px 4px 0 #000;
}

.pixel-input.input-error {
  border-color: var(--px-error);
}

.field-error {
  margin: -4px 0 0;
  font-family: var(--px-font-body);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--px-error);
  text-transform: uppercase;
}

.pixel-cta {
  margin-top: 8px;
  width: 100%;
  min-width: 215px;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #000;
  border-radius: 0;
  background: var(--px-cta);
  color: var(--px-cta-text);
  cursor: pointer;
  font-family: var(--px-font-title);
  font-size: 16px;
  letter-spacing: 0.04em;
  box-shadow: 6px 6px 0 #000;
  transition: transform 0.08s steps(1), box-shadow 0.08s steps(1), filter 0.1s ease;
}

.pixel-cta:hover:not(:disabled) {
  filter: brightness(1.08);
  animation: ctaFlicker 0.3s steps(2) 2;
}

.pixel-cta:active:not(:disabled) {
  transform: translate(6px, 6px);
  box-shadow: 0 0 0 #000;
}

.pixel-cta:focus-visible {
  outline: 2px solid var(--px-accent);
  outline-offset: 3px;
}

.pixel-cta:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

@keyframes ctaFlicker {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.75; }
}

/* ---------- Secondary hint pills ---------- */
.home-hints {
  margin-top: 26px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.hint-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 0;
  border: 2px solid var(--px-border);
  background: var(--px-panel);
  color: var(--px-text);
  font-family: var(--px-font-body);
  font-size: 15px;
  letter-spacing: 0.04em;
}

.hint-pill kbd {
  border-radius: 0;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--px-border);
  color: var(--px-text);
  font-family: var(--px-font-body);
  font-size: 13px;
}

.insert-coin {
  margin: 30px 0 0;
  font-family: var(--px-font-title);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--px-cta);
  text-shadow: 2px 2px 0 #000;
  animation: insertCoinBlink 1.1s steps(1) infinite;
}

@keyframes insertCoinBlink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@media (max-width: 640px) {
  .page-home {
    padding: 24px 16px;
  }

  .home-form {
    width: 100%;
    max-width: 90vw;
  }

  .home-hints {
    gap: 8px;
  }

  .insert-coin {
    font-size: 9px;
  }
}

/* ==========================================================================
   2. LOBBY PAGE — retro pixel-art rebuild (matches the home screen)
   Reuses the shared --px-* tokens and the home page's generic component
   classes (.pixel-scanlines, .pixel-cta, .field-error, .hint-pill, the
   pixel fonts) instead of duplicating them, including the shared
   --pixel-bg-photo background so both screens use the same art.
   ========================================================================== */
.page-lobby {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  padding: 36px 20px 40px;
  background: var(--pixel-bg-photo);
  font-family: var(--px-font-body);
  color: var(--px-text);
}

.lobby-content {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.lobby-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.lobby-sub {
  margin: 0;
}

.lobby-sub strong {
  color: var(--px-cta);
}

.player-count-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.player-count {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.04em;
}

.player-count strong {
  color: var(--px-accent);
}

.count-dots {
  display: flex;
  gap: 8px;
}

.count-dot {
  width: 14px;
  height: 14px;
  border: 2px solid var(--px-border);
  background: transparent;
}

.count-dot.filled {
  background: #4ade80;
  border-color: #4ade80;
}

/* Timer block */
.lobby-timer {
  width: 100%;
  text-align: center;
  padding: 14px 18px;
  border: 3px solid var(--px-border);
  background: var(--px-panel);
}

.timer-label {
  display: block;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--px-text-dim);
  margin-bottom: 2px;
}

.timer-value {
  display: inline-block;
  font-family: var(--px-font-title);
  font-size: 20px;
  color: var(--px-text);
}

.lobby-timer.idle .timer-value {
  font-family: var(--px-font-body);
  font-size: 18px;
  color: var(--px-text-dim);
}

.lobby-timer.armed {
  border-color: var(--px-accent);
}

.lobby-timer.armed .timer-value {
  color: var(--px-accent);
}

.lobby-timer.countdown {
  border-color: var(--px-cta);
}

.lobby-timer.countdown .timer-value {
  font-size: 34px;
  color: var(--px-cta);
  /* 1s duration = one pop per countdown tick (page re-renders each second) */
  animation: timerPop 1s ease;
}

@keyframes timerPop {
  0%   { transform: scale(1.18); }
  45%  { transform: scale(1); }
  100% { transform: scale(1); }
}

/* Player roster — horizontal row, wraps on small screens */
.players-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 152px;
  padding: 14px 10px 12px;
  border: 3px solid var(--px-border);
  background: var(--px-panel);
}

.player-card.you {
  border-color: var(--px-cta);
}

.player-card.empty-slot {
  opacity: 0.6;
  border-style: dashed;
}

.sprite-wrap {
  position: relative;
  width: 100%;
  height: 110px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.player-sprite {
  height: 100%;
  width: auto;
  image-rendering: pixelated;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.5));
}

.sprite-placeholder {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--px-border);
  color: var(--px-text-dim);
  font-family: var(--px-font-title);
  font-size: 20px;
}

.sprite-shadow {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 12px;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.55) 0%, transparent 70%);
}

.card-role {
  font-family: var(--px-font-title);
  font-size: 9px;
  letter-spacing: 0.05em;
  color: var(--px-cta);
  text-shadow: 1px 1px 0 #000;
}

.card-name {
  font-size: 18px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.card-name.dim {
  color: var(--px-text-dim);
}

.card-meta {
  font-size: 13px;
  color: var(--px-text-dim);
  text-align: center;
}

.card-status {
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 2px 10px;
  border: 2px solid var(--px-border);
}

.card-status.ready {
  color: #4ade80;
  border-color: #4ade80;
}

.card-status.waiting {
  color: var(--px-cta);
  border-color: var(--px-cta);
}

.slot-waiting {
  font-size: 13px;
  letter-spacing: 0.05em;
  color: var(--px-text-dim);
  animation: insertCoinBlink 1.1s steps(1) infinite;
}

/* Card entrance — plays once per player via a tracked "seen" set in app.js,
   never replays on unrelated re-renders (e.g. timer ticks). */
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

.card-enter {
  animation: cardEnter 0.35s steps(3);
}

.lobby-status-btn {
  width: 100%;
  max-width: 420px;
}

@media (max-width: 640px) {
  .page-lobby {
    padding: 24px 14px 32px;
  }

  .player-card {
    width: 124px;
    padding: 10px 8px 10px;
  }

  .sprite-wrap {
    height: 84px;
  }

  .card-name {
    font-size: 16px;
  }
}

/* Player color identities (lobby avatar background) */
.p1 .card-avatar {
  background: linear-gradient(145deg, #60a5fa, #2563eb);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}
.p2 .card-avatar {
  background: linear-gradient(145deg, #f472b6, #db2777);
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.5);
}
.p3 .card-avatar {
  background: linear-gradient(145deg, #fb923c, #ea580c);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.5);
}
.p4 .card-avatar {
  background: linear-gradient(145deg, #4ade80, #16a34a);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}

/* ==========================================================================
   3. GAME PAGE — retro pixel-art rebuild (matches home + lobby)
   Reuses the shared --px-* tokens, --pixel-bg-photo, .pixel-scanlines,
   .pixel-title(-main/-accent) and kbd instead of duplicating them. Visual
   rebuild only — board/tile logic, movement, bombs, sockets untouched.
   ========================================================================== */
.page-game {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  padding: 28px 20px 36px;
  background: var(--pixel-bg-photo);
  font-family: var(--px-font-body);
  color: var(--px-text);
  /* Whole map must stay visible: cell size adapts to viewport.
     17/15 (not 15/13) accounts for the border-tile frame: 15 grid cols + 2
     left/right border cols, 13 grid rows + 2 top/bottom border rows.
     800px budgets for page padding + the player sidebar + the comms sidebar
     + their gaps, so the board keeps its full size with both columns present.
     200px vertical budget covers page padding + header + content gap only —
     the arena column holds nothing but the (optional) banner and the board. */
  --cell: min(54px, calc((100vw - 800px) / 17), calc((100vh - 200px) / 15));
}

.game-content {
  position: relative;
  z-index: 1;
  width: min(1650px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.game-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
}

.game-header .pixel-title {
  flex-direction: row;
  align-items: baseline;
  gap: 10px;
}

.game-header .pixel-title-main {
  font-size: 32px;
}

.game-header .pixel-title-accent {
  font-size: 20px;
}

.page-game .controls-hint {
  color: var(--px-text-dim);
  font-family: var(--px-font-body);
  font-size: 14px;
}

.page-game kbd {
  border-radius: 0;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--px-border);
  border-bottom-width: 2px;
  color: var(--px-text);
  font-family: var(--px-font-body);
  font-size: 13px;
}

/* Three columns, board centered: [player sidebar | arena | comms] */
.game-layout {
  display: flex;
  gap: 18px;
  align-items: stretch;
  justify-content: center;
}

.player-column {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.arena-column {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.side-column {
  flex: 0 0 300px;
  display: flex;
}

.side-column .chat-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.side-column .chat-messages {
  flex: 1;
  height: auto;
  min-height: 200px;
}

.arena-waiting {
  color: var(--px-text-dim);
  padding: 40px;
  text-align: center;
  font-size: 18px;
}

/* HUD — one consolidated card per player: avatar, name, hearts, stats */
.hud {
  display: flex;
  flex-direction: column;
  gap: 12px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.hud-player {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 2px solid var(--px-border);
  background: var(--px-panel);
  font-family: var(--px-font-body);
  font-size: 15px;
}

.hud-player.current {
  border-color: var(--px-cta);
  box-shadow: 0 0 0 1px var(--px-cta);
}

.hud-player.dead {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.hud-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  object-position: top center;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}

.hud-card-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hud-card-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.hud-player-num {
  flex: 0 0 auto;
  padding: 2px 6px;
  font-family: var(--px-font-title);
  font-size: 10px;
  color: #fff;
  background: var(--px-border);
  text-shadow: 1px 1px 0 #000;
}

.hud-player.p1 .hud-player-num {
  background: linear-gradient(145deg, #60a5fa, #2563eb);
}
.hud-player.p2 .hud-player-num {
  background: linear-gradient(145deg, #f472b6, #db2777);
}
.hud-player.p3 .hud-player-num {
  background: linear-gradient(145deg, #fb923c, #ea580c);
}
.hud-player.p4 .hud-player-num {
  background: linear-gradient(145deg, #4ade80, #16a34a);
}

.hud-name {
  min-width: 0;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
}

.hud-you-tag {
  font-family: var(--px-font-title);
  font-size: 8px;
  letter-spacing: 0.05em;
  color: var(--px-cta);
  text-shadow: 1px 1px 0 #000;
}

.hud-lives {
  font-size: 17px;
  letter-spacing: 2px;
  color: var(--px-error);
}

.hud-player.dead .hud-lives {
  color: var(--px-text-dim);
}

.hud-card-stats {
  display: flex;
  gap: 8px;
}

/* Shared stat-pill building block, used inside each HUD card */
.player-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 2px solid var(--px-border);
  background: rgba(6, 10, 18, 0.5);
  font-size: 13px;
}

.hud-card-stats .stat-chip {
  flex: 1 1 0;
  justify-content: center;
  padding: 6px 6px;
}

.stat-label {
  color: var(--px-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 700;
}

.stat-value {
  font-family: var(--px-font-title);
  font-size: 13px;
  color: var(--px-accent);
}

/* Small, subtle controls reminder pinned under the player sidebar */
.controls-card {
  margin-top: auto;
  padding: 10px 12px;
  border: 2px solid var(--px-border);
  background: rgba(6, 10, 18, 0.5);
}

.controls-card-title {
  font-family: var(--px-font-title);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--px-text-dim);
  margin-bottom: 8px;
}

.controls-card .controls-hint {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

/* ---------- The arena grid ---------- */

/* Shared sprite-sheet lookup: media/tiles/tileset.png is an 8x4 grid of tiles.
   background-size expresses the sheet as a multiple of the element's own size,
   so --bx/--by (set per-element as 0-100% along each axis) pick a tile out of
   the sheet regardless of how big --cell is actually rendered at. */
.tile-sprite {
  background-image: url("../media/tiles/tileset.png");
  background-size: 800% 400%;
  background-repeat: no-repeat;
  background-position: var(--bx, 0%) var(--by, 0%);
  /* Nearest-neighbor only — this is pixel art, never smoothed/blurred. */
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
}

.map-frame {
  display: flex;
  flex-direction: column;
  /* stretch (not center): the top/bottom border rows need a real width to
     flex-grow their tiles into — this matches them to .map-middle's natural
     width (the widest child, driven by the game grid). */
  align-items: stretch;
  width: fit-content;
  margin: 0 auto;
}

.map-middle {
  display: flex;
  flex-direction: row;
}

.map-border-col {
  display: flex;
  flex-direction: column;
}

.map-border-row {
  display: flex;
  flex-direction: row;
}

/* Border tiles flex-grow to fill the exact frame width/height rather than
   using a fixed --cell size — the border is pure framing (not gameplay
   cells), so a handful of tiles stretched to fill the span reads as one
   continuous glass wall instead of many tiny repeated windows. Percentage-
   based background-position/-size on .tile-sprite scales with it for free. */
.map-border-row .border-tile {
  flex: 1 1 0;
  min-width: 0;
  height: var(--cell, 40px);
}

.map-border-col .border-tile {
  flex: 1 1 0;
  min-height: 0;
  width: var(--cell, 40px);
}

/* Steel corner posts — the four frame corners only, joining the glass walls.
   Fixed at exactly one cell so they line up with the left/right border
   columns and the grid itself. */
.map-border-row .corner-tile {
  flex: 0 0 var(--cell, 40px);
  width: var(--cell, 40px);
  height: var(--cell, 40px);
}

.corner-tile {
  position: relative;
  z-index: 1;
}

.game-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(15, var(--cell, 40px));
  grid-template-rows: repeat(13, var(--cell, 40px));
  gap: 2px;
  margin: 0 auto;
  padding: 8px;
  background: var(--px-bg-0);
  border-radius: 0;
  border: 3px solid var(--px-border);
  box-shadow: 6px 6px 0 #000;
}

.cell {
  position: relative;
  width: var(--cell, 40px);
  height: var(--cell, 40px);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pillar lattice / destructible obstacles — transparent sprite layered
   over the cell's own floor tile (two-pass layering: floor, then overlay). */
.cell-overlay {
  position: absolute;
  inset: 0;
}

/* Bombs — pulsing and dangerous */
.cell.bomb {
  z-index: 1;
}

.bomb-token {
  position: absolute;
  inset: 0;
  margin: auto;
  width: calc(var(--cell, 40px) * 0.85);
  height: calc(var(--cell, 40px) * 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 40px) * 0.6);
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.8));
  animation: bombPulse 0.45s ease-in-out infinite alternate;
  z-index: 2;
}

@keyframes bombPulse {
  from { transform: scale(0.82); }
  to   { transform: scale(1.08); }
}

/* Explosions — fiery blast */
.cell.explosion {
  background: radial-gradient(circle, #fff7d6 0%, #fde047 25%, #f97316 55%, #dc2626 80%, #7f1d1d 100%) !important;
  border-radius: 6px;
  z-index: 2;
  box-shadow: 0 0 18px rgba(249, 115, 22, 0.75);
  animation: explosionFlash 0.12s ease-in-out infinite alternate;
}

@keyframes explosionFlash {
  from { opacity: 0.8; }
  to   { opacity: 1; }
}

/* Power-ups — glowing pickups */
.power-up {
  position: absolute;
  inset: 0;
  margin: auto;
  width: calc(var(--cell, 40px) * 0.66);
  height: calc(var(--cell, 40px) * 0.66);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 40px) * 0.4);
  line-height: 1;
  z-index: 1;
  animation: powerPulse 0.9s ease-in-out infinite alternate;
}

.power-up.bombs {
  background: rgba(245, 158, 11, 0.18);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6), inset 0 0 0 1px rgba(245, 158, 11, 0.8);
}

.power-up.flames {
  background: rgba(239, 68, 68, 0.18);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6), inset 0 0 0 1px rgba(239, 68, 68, 0.8);
}

.power-up.speed {
  background: rgba(34, 197, 94, 0.18);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.6), inset 0 0 0 1px rgba(34, 197, 94, 0.8);
}

@keyframes powerPulse {
  from { transform: scale(0.9); }
  to   { transform: scale(1.08); }
}

/* Player tokens */
.player-token {
  position: absolute;
  inset: 0;
  margin: auto;
  width: calc(var(--cell, 40px) * 0.74);
  height: calc(var(--cell, 40px) * 0.74);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 40px) * 0.38);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  z-index: 3;
}

.player-token.p1 {
  background: linear-gradient(145deg, #60a5fa, #2563eb);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.7), inset 0 2px 2px rgba(255, 255, 255, 0.35);
}
.player-token.p2 {
  background: linear-gradient(145deg, #f472b6, #db2777);
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.7), inset 0 2px 2px rgba(255, 255, 255, 0.35);
}
.player-token.p3 {
  background: linear-gradient(145deg, #fb923c, #ea580c);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.7), inset 0 2px 2px rgba(255, 255, 255, 0.35);
}
.player-token.p4 {
  background: linear-gradient(145deg, #4ade80, #16a34a);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.7), inset 0 2px 2px rgba(255, 255, 255, 0.35);
}

.player-token.current-player {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
}

.player-token.sprite-token.current-player {
  outline: none;
}

.player-token.sprite-token {
  inset: auto;
  left: 50%;
  bottom: 0;
  margin: 0;
  transform: translateX(-50%);
  width: calc(var(--cell, 40px) * 1.7);
  height: calc(var(--cell, 40px) * 1.7);
  border-radius: 0;
  background: var(--sprite);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center bottom;
  box-shadow: none;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
}

/* CFO-tp.png carries a lot of built-in transparent padding around the art
   (1024x1536 canvas, character only fills roughly 602x1214 of it), so a
   plain "contain" fit renders it visibly smaller than the edge-to-edge
   walk-up frames. This zooms/repositions the background so the character's
   actual pixels — not the padded canvas — fill the token the same way. */
.player-token.sprite-token.idle-token {
  background-size: 84.35% 126.53%;
  background-position: 47.85% 27.03%;
}

/* Left reuses the right-facing art, mirrored — no separate frames needed. */
.player-token.sprite-token.sprite-flip {
  transform: translateX(-50%) scaleX(-1);
}

/* CMO's walk frames weren't cropped to a shared canvas/padding like CFO's
   (each direction came off a different source canvas — the up frames alone
   are a padded 1024x1536 portrait matching CMO-tp.png's, while down/side are
   tightly-cropped squares), so a plain "contain" fit made her shrink and
   grow between directions instead of staying one consistent size. These
   values were derived from each frame's actual opaque-pixel bounding box so
   her on-screen height matches CFO's corresponding direction (see
   .idle-token above for the same technique). */
.player-token.sprite-token.sprite-fit-cmo-up {
  background-size: 76.86% 115.28%;
  background-position: 50% 3.6%;
}

.player-token.sprite-token.sprite-fit-cmo-down {
  background-size: 114.36% 114.36%;
  background-position: 50% 13.37%;
}

.player-token.sprite-token.sprite-fit-cmo-side {
  background-size: 83.09% 83.09%;
  background-position: 50% 119.5%;
}

/* CLO's side-walk frames use the same 326x326 canvas as her up/down frames,
   but crop much closer to the character (~95% of the canvas height vs
   CFO's side frames at ~79%), so a plain "contain" fit renders her walking
   sideways noticeably taller than facing up/down and taller than CFO's own
   side view. Derived the same way as the CMO overrides above. */
.player-token.sprite-token.sprite-fit-clo-side {
  background-size: 82.39% 82.39%;
  background-position: 50% 111.47%;
}

/* Invincibility flash (transform/opacity only) */
.player-token.invincible {
  animation: invincibleFlash 0.25s infinite alternate;
}

@keyframes invincibleFlash {
  0%   { opacity: 0.25; }
  100% { opacity: 1; }
}

/* ==========================================================================
   4. CHAT PANEL
   ========================================================================== */
.chat-panel {
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  background: rgba(13, 15, 32, 0.8);
  border: 1px solid var(--panel-border);
}

.chat-title {
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--pink);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text);
}

.chat-messages {
  height: 180px;
  overflow-y: auto;
  border-radius: 10px;
  background: rgba(6, 7, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.chat-message {
  max-width: 85%;
  margin-bottom: 8px;
  padding: 7px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
  align-self: flex-start;
}

.chat-message strong {
  color: var(--blue);
}

.chat-message.own {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(236, 72, 153, 0.3));
  border-color: rgba(168, 85, 247, 0.4);
}

.chat-message.own strong {
  color: #f0abfc;
}

.chat-message.system {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
  text-align: center;
  padding: 2px 6px;
}

.chat-empty {
  margin: auto;
  color: var(--text-dim);
  text-align: center;
  font-size: 13px;
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
}

.chat-send {
  flex: 0 0 auto;
  padding: 10px 18px;
  font-size: 12px;
}

/* ---------- Lobby + Game retro terminal reskin ----------
   Scoped under .page-lobby and .page-game (both share this exact treatment)
   so the base ChatPanel() component/classes above stay theme-neutral. */
.page-lobby .chat-panel,
.page-game .chat-panel {
  width: 100%;
  border-radius: 0;
  border: 3px solid var(--px-border);
  background: var(--px-panel);
}

.page-lobby .chat-title,
.page-game .chat-title {
  border-left: 3px solid var(--px-cta);
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--px-text);
}

.page-lobby .chat-messages,
.page-game .chat-messages {
  border-radius: 0;
  background: rgba(6, 10, 18, 0.75);
  border: 2px solid var(--px-border);
}

.page-lobby .chat-message,
.page-game .chat-message {
  border-radius: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--px-border);
  color: #b7f7c0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  flex: 0 0 auto;
}

.page-lobby .chat-message strong,
.page-game .chat-message strong {
  color: var(--px-accent);
}

.page-lobby .chat-message.own,
.page-game .chat-message.own {
  background: rgba(255, 140, 60, 0.12);
  border-color: var(--px-cta);
}

.page-lobby .chat-message.own strong,
.page-game .chat-message.own strong {
  color: var(--px-cta);
}

.page-lobby .chat-message.system,
.page-game .chat-message.system {
  color: var(--px-text-dim);
}

.page-lobby .chat-empty,
.page-game .chat-empty {
  color: var(--px-text-dim);
  font-size: 15px;
}

.page-lobby .chat-input,
.page-game .chat-input {
  border-radius: 0;
  border: 2px solid var(--px-border);
  background: rgba(6, 10, 18, 0.6);
  color: var(--px-text);
  font-family: var(--px-font-body);
  font-size: 17px;
}

.page-lobby .chat-input::placeholder,
.page-game .chat-input::placeholder {
  color: var(--px-text-dim);
}

.page-lobby .chat-input:focus,
.page-game .chat-input:focus {
  border-color: var(--px-accent);
  box-shadow: none;
  outline: none;
}

.page-lobby .chat-send,
.page-game .chat-send {
  border-radius: 0;
  border: 2px solid #000;
  background: var(--px-cta);
  color: var(--px-cta-text);
  font-family: var(--px-font-title);
  font-size: 11px;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.08s steps(1), box-shadow 0.08s steps(1);
}

.page-lobby .chat-send:hover:not(:disabled),
.page-game .chat-send:hover:not(:disabled) {
  filter: brightness(1.08);
}

.page-lobby .chat-send:active:not(:disabled),
.page-game .chat-send:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 #000;
}

/* ==========================================================================
   5. WINNER / GAME OVER PAGE — retro pixel-art rebuild (matches lobby + game)
   Reuses --px-* tokens, --pixel-bg-photo, .pixel-scanlines, .pixel-title,
   .game-header (top-left title) and .pixel-cta instead of duplicating them.
   Presentational only — winner/loser data comes straight from game state.
   ========================================================================== */
.page-winner {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  padding: 28px 20px 36px;
  background: var(--pixel-bg-photo);
  font-family: var(--px-font-body);
  color: var(--px-text);
}

.winner-content {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Fills the space below the top-left title and centers the podium in it,
   both horizontally and vertically — a focused podium screen, not a stack. */
.podium {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  width: 100%;
  padding: 20px 0;
}

.podium-winner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.podium-winner-label {
  margin: 0;
  font-family: var(--px-font-title);
  font-size: 16px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--px-cta);
  text-shadow: 2px 2px 0 #000;
  animation: winnerLabelPulse 1.6s steps(2) infinite;
}

.podium-winner-label.draw {
  color: var(--px-error);
}

@keyframes winnerLabelPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Winner card — same bordered-panel language as the HUD/player cards,
   scaled up ~2x with an orange celebratory glow. */
.winner-card {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 22px 34px;
  border: 4px solid var(--px-cta);
  background: var(--px-panel);
  animation: winnerFloat 2.4s ease-in-out infinite alternate;
}

@keyframes winnerFloat {
  from { transform: translateY(0); box-shadow: 0 0 18px rgba(255, 140, 60, 0.35), 6px 6px 0 #000; }
  to   { transform: translateY(-6px); box-shadow: 0 0 34px rgba(255, 140, 60, 0.6), 6px 10px 0 #000; }
}

.winner-card.draw {
  border-color: var(--px-error);
  animation: none;
  box-shadow: 6px 6px 0 #000;
}

.winner-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  object-position: top center;
  background: var(--panel-solid);
  border: 2px solid rgba(255, 255, 255, 0.3);
  flex: 0 0 auto;
}

.winner-card-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.winner-card-name-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.winner-name {
  font-size: 30px;
  letter-spacing: 0.03em;
}

.winner-card .hud-player-num {
  font-size: 13px;
  padding: 3px 8px;
}

.winner-card .hud-you-tag {
  font-size: 11px;
}

/* Player color identities — same palette as the in-game HUD cards */
.podium .p1 .hud-player-num { background: linear-gradient(145deg, #60a5fa, #2563eb); }
.podium .p2 .hud-player-num { background: linear-gradient(145deg, #f472b6, #db2777); }
.podium .p3 .hud-player-num { background: linear-gradient(145deg, #fb923c, #ea580c); }
.podium .p4 .hud-player-num { background: linear-gradient(145deg, #4ade80, #16a34a); }

/* Losers row — same card language, greyed out, smaller, wraps to fit any
   player count (2/3/4) and stays centered regardless. */
.losers-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.loser-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 2px solid var(--px-border);
  background: var(--px-panel);
  opacity: 0.55;
  filter: grayscale(0.85);
}

.loser-card.you {
  opacity: 0.65;
  border-color: var(--px-text-dim);
}

.loser-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  image-rendering: pixelated;
  object-position: top center;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex: 0 0 auto;
}

.loser-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.loser-placement {
  font-family: var(--px-font-title);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--px-text-dim);
}

.loser-name {
  font-size: 16px;
}

.loser-name .hud-you-tag {
  margin-left: 4px;
  font-size: 8px;
}

.winner-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.winner-action-btn {
  width: auto;
  min-width: 200px;
  height: 52px;
  font-size: 12px;
}

@media (max-width: 640px) {
  .page-winner {
    padding: 20px 12px 28px;
  }

  .winner-card {
    flex-direction: column;
    text-align: center;
    gap: 12px;
    padding: 18px 22px;
  }

  .winner-avatar {
    width: 72px;
    height: 72px;
  }

  .winner-name {
    font-size: 22px;
  }

  .winner-action-btn {
    width: 100%;
    min-width: 0;
  }
}

/* ==========================================================================
   6. GAMEPLAY FEEDBACK OVERLAYS (outside the framework root)
   ========================================================================== */

/* FPS meter — shown during battle only, updated directly (no re-renders).
   Pixel corner badge, matching the game page's retro rebuild. */
.fps-meter {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 50;
  padding: 5px 10px;
  border-radius: 0;
  background: var(--px-panel);
  border: 2px solid var(--px-border);
  color: var(--px-accent);
  font: 700 12px/1 var(--px-font-body), Consolas, monospace;
  letter-spacing: 0.08em;
  pointer-events: none;
}

/* Red vignette flash when the local player takes a hit */
.damage-vignette {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 120px 40px rgba(239, 68, 68, 0.55);
}

.damage-vignette.active {
  animation: damageFlash 0.45s ease-out;
}

@keyframes damageFlash {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Spectator banner when the local player is eliminated — floats as an
   overlay entirely above the board (clear of its top border) instead of
   sitting in flow, so it never pushes the map down or shrinks it. */
.eliminated-banner {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, calc(-100% - 10px));
  z-index: 10;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 16px;
  border-radius: 0;
  text-align: center;
  font-family: var(--px-font-title);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--px-error);
  text-shadow: 2px 2px 0 #000;
  background: var(--px-panel);
  border: 3px solid var(--px-error);
  box-shadow: 4px 4px 0 #000;
  pointer-events: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .page-game {
    --cell: min(54px, calc((100vw - 110px) / 17), calc((100vh - 260px) / 15));
  }

  .game-layout {
    flex-direction: column;
  }

  /* Board first, sidebars stacked below it */
  .arena-column {
    order: -1;
  }

  .player-column,
  .side-column {
    flex: 1 1 auto;
    order: 1;
  }

  .hud {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .hud-player {
    flex: 1 1 220px;
  }

  .controls-card {
    margin-top: 0;
  }

  .side-column .chat-messages {
    flex: none;
    height: 160px;
    min-height: 0;
  }
}

/* ---------- Sound mixer widget (persistent, all pages) ---------- */
.sound-mixer-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  border: 2px solid #000;
  background: var(--px-panel, rgba(15, 34, 61, 0.62));
  color: var(--px-text, #f2f6fb);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000;
  backdrop-filter: blur(2px);
  transition: transform 0.08s steps(1), box-shadow 0.08s steps(1);
}

.sound-mixer-toggle:hover {
  filter: brightness(1.1);
}

.sound-mixer-toggle:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #000;
}

.sound-mixer-toggle.muted {
  color: var(--px-error, #ff4d6d);
}

.sound-mixer-panel {
  position: fixed;
  right: 16px;
  bottom: 70px;
  z-index: 200;
  width: 220px;
  padding: 14px;
  border: 2px solid var(--px-border, #5b7ca3);
  background: rgba(11, 7, 20, 0.92);
  box-shadow: 5px 5px 0 #000;
  display: none;
  flex-direction: column;
  gap: 12px;
  font-family: var(--px-font-body, inherit);
}

.sound-mixer-panel.open {
  display: flex;
}

.sound-mixer-title {
  font-family: var(--px-font-title, inherit);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--px-cta, #ff8c3c);
  text-shadow: 1px 1px 0 #000;
}

.sound-mixer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sound-mixer-label {
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--px-text-dim, #9fb8d4);
  white-space: nowrap;
}

.sound-mixer-slider {
  flex: 1;
  accent-color: var(--px-cta, #ff8c3c);
}

.sound-mixer-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--px-cta, #ff8c3c);
}

@media (max-width: 640px) {
  .sound-mixer-toggle {
    right: 12px;
    bottom: 12px;
    width: 42px;
    height: 42px;
  }

  .sound-mixer-panel {
    right: 12px;
    bottom: 64px;
    width: 190px;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 22px 18px;
  }

  .page-game {
    padding: 20px 12px 28px;
  }

  .hud-name {
    max-width: 90px;
  }

  .controls-hint {
    gap: 12px;
  }

  .hud-player {
    flex: 1 1 100%;
  }
}

/* Accessibility: honor reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
