* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f2f2f2;
  color: #111;
  overflow: hidden;
}
.hidden { display: none !important; }
.screen { height: 100%; display: flex; }

#menu, #queue { align-items: center; justify-content: center; padding: 16px; }
.card {
  background: #fff;
  border: 3px solid #000;
  padding: 28px 32px;
  width: min(380px, 100%);
  text-align: center;
}
h1 { margin: 0 0 4px; font-size: 2.2rem; letter-spacing: 0.02em; }
h2 { margin: 0 0 8px; font-size: 1.3rem; }
.sub { margin: 0 0 20px; color: #555; }
form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
label { font-weight: 600; font-size: 0.9rem; }
input {
  font: inherit; padding: 10px 12px; border: 2px solid #000; border-radius: 0;
}
button {
  font: inherit; font-weight: 700; padding: 10px 18px; margin-top: 8px;
  background: #000; color: #fff; border: 2px solid #000; cursor: pointer;
}
button:hover { background: #333; }
button.secondary { background: #fff; color: #000; }
button.secondary:hover { background: #eee; }
button:disabled { opacity: 0.5; cursor: default; }
.status { min-height: 1.2em; margin: 14px 0 0; color: #b00020; }

#game { flex-direction: column; align-items: center; padding: 8px 16px; gap: 8px; }
#scoreboard {
  display: flex; align-items: center; gap: 16px; font-weight: 700; font-size: 1.1rem;
  flex-wrap: wrap; justify-content: center;
}
#scoreboard .score { font-variant-numeric: tabular-nums; font-size: 1.4rem; }
#scoreboard .round { font-weight: 500; color: #555; font-size: 0.95rem; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; }

#stage { position: relative; flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#canvas { display: block; background: #fff; }
#overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#overlay .panel {
  pointer-events: auto; background: rgba(255, 255, 255, 0.95); border: 3px solid #000;
  padding: 20px 28px; text-align: center; max-width: min(520px, 92%);
}
#overlay .big { font-size: 3rem; font-weight: 800; line-height: 1; margin: 8px 0; font-variant-numeric: tabular-nums; }
#overlay table { margin: 10px auto; border-collapse: collapse; text-align: left; }
#overlay td { padding: 3px 10px; }
#overlay td:first-child { font-weight: 700; white-space: nowrap; }
kbd { border: 1.5px solid #000; border-bottom-width: 3px; padding: 0 5px; font-family: inherit; font-size: 0.85em; background: #fff; }

#hud { width: min(640px, 100%); display: flex; flex-direction: column; gap: 6px; padding-bottom: 4px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 56px; font-weight: 700; font-size: 0.85rem; }
.bar { position: relative; flex: 1; height: 18px; border: 2px solid #000; background: #fff; }
.fill { height: 100%; width: 0; }
.fill.hp { background: #e53935; }
.fill.ammo { background: #fdd835; }
.ticks { position: absolute; inset: 0; display: flex; pointer-events: none; }
.ticks span { flex: 1; border-right: 2px solid #000; }
.ticks span:last-child { border-right: 0; }

/* Menu and queue screens: Bomberman's lobby look (dark page, pixel title, yellow primary).
   The match itself keeps the light canvas theme. */
body:has(#menu:not(.hidden)), body:has(#queue:not(.hidden)) { background: #16181d; color: #eef0f3; }
#menu .card, #queue .card { background: #22262e; border: 0; border-radius: 12px; padding: 24px; }
#menu h1, #queue h1 {
  font-family: 'Press Start 2P', monospace; font-size: clamp(20px, 5vw, 32px);
  color: #f5b301; text-shadow: 3px 3px 0 #000; margin: 0 0 12px;
}
#queue h1.small { font-size: clamp(16px, 4vw, 22px); }
#menu .sub, #queue .sub { color: #9aa3ae; }
#menu label { font-weight: 400; color: #9aa3ae; }
#menu input { background: #15181d; color: #eef0f3; border: 1px solid #3a404b; border-radius: 8px; }
#menu button, #queue button { border: 0; border-radius: 8px; background: #f5b301; color: #1a1a1a; }
#menu button:hover, #queue button:hover { background: #f5b301; filter: brightness(1.15); }
#queue button.secondary { background: #3a404b; color: #eef0f3; }
#menu .status { color: #ff6b6b; }

/* Back to the plaza or the hub (back-link.js): menu and queue only, never over a match. */
.back-link {
  position: fixed; top: 12px; left: 12px; z-index: 5;
  padding: 8px 14px; border-radius: 999px;
  background: #22262e; color: #eef0f3;
  font-weight: 600; font-size: 0.9rem; text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.back-link:hover, .back-link:focus-visible { background: #2e333d; }
body:has(#game:not(.hidden)) .back-link { display: none; }

/* Touch controls (phones/tablets only) */
#joy, #fire-btn { display: none; }
@media (pointer: coarse) {
  #game { touch-action: none; user-select: none; -webkit-user-select: none; }
  #joy, #fire-btn { display: block; }
  #joy {
    position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px;
    left: 80px; top: calc(100% - 80px);
    border-radius: 50%; border: 3px solid rgba(0, 0, 0, 0.45);
    background: rgba(0, 0, 0, 0.1); opacity: 0.6; pointer-events: none; z-index: 20;
  }
  #joy-knob {
    position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
    border-radius: 50%; background: rgba(0, 0, 0, 0.6);
  }
  #fire-btn {
    position: fixed; right: 20px; bottom: 20px; width: 92px; height: 92px; margin: 0; border-radius: 50%;
    border: 4px solid #000; background: #e53935; color: #fff; z-index: 20; touch-action: none;
  }
  #fire-btn:active { transform: scale(0.94); }
}

/* Touch devices have on-screen controls, so skip the keyboard cheat-sheet. */
@media (pointer: coarse) { #overlay table.keys { display: none; } }
