html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #111;
  color: white;
  font-family: Arial, sans-serif;
  touch-action: none;
  user-select: none;
}

#game-canvas {
  display: none;
  width: 100vw;
  height: 100vh;
  background: #181818;
}

/* Back-to-games link — same fixed, pill-shaped "return to the hub"
   pattern the other games under games.lightlol.com use, styled to match
   this game's own dark palette (#111/white) rather than their shared
   theme.css. Hidden once the game actually starts — see startLocalGame()
   in game.js — so it's only ever visible on the lobby/waiting screens. */
.back-home-link {
  position: fixed;
  top: 16px;
  left: 16px;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 999px;
  background: #222;
  border: 1px solid #444;
  z-index: 20;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.back-home-link:hover {
  background: #333;
  border-color: #666;
}

/* ============================================================
   LOBBY
============================================================ */

#lobby-screen, #waiting-screen, #runover-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #333 0%, #111 65%);
  z-index: 10;
  gap: 16px;
}

.game-title {
  font-size: 56px;
  letter-spacing: 6px;
  margin: 0 0 24px;
}

#name-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#name-section label {
  opacity: 0.7;
  font-size: 14px;
}

input[type="text"] {
  font-size: 20px;
  padding: 10px 16px;
  border: 2px solid #555;
  border-radius: 8px;
  background: #222;
  color: white;
  text-align: center;
  outline: none;
  width: 180px;
}

input[type="text"]:focus {
  border-color: #aaa;
}

#join-code {
  text-transform: uppercase;
  letter-spacing: 4px;
}

#lobby-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#join-section {
  display: flex;
  gap: 8px;
  align-items: center;
}

button {
  font-size: 20px;
  padding: 12px 28px;
  border: 0;
  border-radius: 10px;
  background: #e4e4e4;
  color: #111;
  cursor: pointer;
  font-weight: bold;
}

button:active { transform: scale(0.96); }

/* ── Custom dialog modal — replaces the browser's native alert()/
   confirm()/prompt(), which render as bare "games.lightlol.com says..."
   OS dialogs. One overlay reused for all three via showDialog() in
   game.js (see that function for how message/buttons/input get filled
   in and how it resolves) — showAlert()/showConfirm() are thin wrappers
   around it, and the invite-link fallback uses it directly with the
   readonly input shown. */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
}
.dialog-box {
  background: #1c1c1c;
  border: 1px solid #444;
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  width: 88%;
  max-width: 340px;
}
.dialog-message { margin: 0 0 16px; color: #fff; line-height: 1.4; font-size: 15px; }
.dialog-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #111;
  color: #fff;
  font-size: 14px;
  text-align: center;
}
.dialog-actions { display: flex; gap: 10px; justify-content: center; }
.dialog-btn {
  font-size: 15px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: bold;
}
.dialog-btn.primary { background: #5cbf5c; color: #111; }
.dialog-btn.secondary { background: #333; color: #fff; }

/* ── Settings menu — shares .dialog-overlay above for the backdrop;
   these just style the box/buttons that go inside it. ── */
.settings-box { max-width: 300px; }
.settings-title { margin: 0 0 16px; color: #fff; font-size: 18px; }
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.settings-btn {
  font-size: 15px;
  padding: 12px 18px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  background: #333;
  color: #fff;
}
.settings-btn.danger { background: #5a1f1f; color: #ff8f80; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ddd;
  font-size: 15px;
  padding: 4px 2px;
}
.settings-row span { min-width: 52px; }
.settings-row input[type="range"] {
  flex: 1;
  accent-color: #ffb347;
}
.settings-row-check { cursor: pointer; }
.settings-row-check input { width: 18px; height: 18px; accent-color: #ffb347; }
.settings-btn:active { transform: scale(0.97); }

#btn-start {
  background: #5cbf5c;
  color: white;
}

.error-msg {
  color: #ff6b6b;
  font-size: 14px;
  min-height: 20px;
}

/* ============================================================
   CHARACTER SELECT
============================================================ */

#appearance-section {
  display: flex;
  align-items: center;
  gap: 20px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 14px 18px;
}

#appearance-preview {
  width: 96px;
  height: 96px;
  background: radial-gradient(circle at center, #2a2a2a 0%, #161616 70%);
  border-radius: 8px;
  flex-shrink: 0;
  image-rendering: pixelated;
}

#appearance-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

#color-pickers {
  display: flex;
  gap: 14px;
}

#color-pickers label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  opacity: 0.8;
}

#color-pickers input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 1px solid #444;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

@media (max-width: 480px) {
  #appearance-section { flex-direction: column; }
}

/* ============================================================
   WAITING ROOM
============================================================ */

#waiting-screen h2 {
  font-size: 32px;
  letter-spacing: 4px;
  margin: 0;
}

#room-code-display {
  color: #ffd700;
  font-size: 40px;
}

#player-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  text-align: center;
}

#player-list li {
  font-size: 18px;
  padding: 6px 16px;
  background: #2a2a2a;
  border-radius: 6px;
}

.hint {
  opacity: 0.65;
  font-size: 14px;
  margin: 4px 0;
}
.hint.small { font-size: 12px; max-width: 280px; margin-left: auto; margin-right: auto; }

#waiting-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#waiting-header-row h2 { margin: 0; }

/* Round icon button — same shape/size as the shared .tbl-icon-btn the
   card games use (34px square, 8px radius, single glyph via currentColor),
   recolored to this game's own dark palette + gold accent (matches
   #room-code-display) instead of the card games' --tbl-* theme vars,
   since Wizards Tower doesn't load that cross-origin stylesheet. */
.wt-icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  background: #222;
  border: 1px solid #444;
  border-radius: 8px;
  color: #ccc;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.wt-icon-btn:hover, .wt-icon-btn:active { border-color: #ffd700; color: #ffd700; }
.wt-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ============================================================
   DEATH PANEL (spectating) + RUN OVER
============================================================ */

/* Sits over the top edge of the canvas without blocking the view — the
   card itself is opaque enough to read but the rest of the screen stays
   interactive-free (pointer-events: none) so it never eats the settings
   gear or the canvas below. Faded in by game.js after the fall animation
   (see the "playerDied" handler) via the .show class. */
#death-screen {
  position: fixed;
  /* Below the HUD's floor label and zoom control (both live in the top
     ~100px of the canvas, centered) rather than on top of them. */
  top: 112px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  max-width: min(92vw, 520px);
}
#death-screen.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.death-card {
  pointer-events: auto;
  background: rgba(14, 14, 18, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px 18px 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
}
.death-title {
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #f0d5d5;
}
.death-sub {
  font-size: 13px;
  color: #bbb;
}
.death-stats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 2px 0;
}
.death-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 54px;
}
.death-stat .v {
  font-size: 20px;
  font-weight: bold;
  color: #fff;
}
.death-stat .k {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #888;
}
.death-items {
  font-size: 12px;
  color: #9fc9ff;
  max-width: 460px;
}
.death-items:empty { display: none; }
.death-spectate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}
.death-btn {
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #2a2a33;
  color: #fff;
  border: 1px solid #555;
}
.death-btn:hover { background: #3a3a45; }
.death-hint {
  font-size: 11px;
  color: #777;
}

#runover-screen h2 {
  font-size: 40px;
  margin: 0 0 4px;
  text-align: center;
  padding: 0 16px;
}
.runover-floor {
  font-size: 16px;
  color: #bbb;
  margin-bottom: 12px;
}
.runover-table {
  display: grid;
  grid-template-columns: auto repeat(4, minmax(60px, auto));
  gap: 6px 22px;
  align-items: center;
  margin-bottom: 20px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  max-width: 92vw;
  overflow-x: auto;
}
.runover-table .h {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #888;
}
.runover-table .n {
  font-weight: bold;
  text-align: left;
}
.runover-table .c {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Portrait used to be flat-out blocked here (a #rotate-warning overlay
   forced via @media (orientation: portrait)). Removed — the game now
   renders correctly at any aspect ratio (see draw()'s letterboxed
   uniform scale in game.js), so there was nothing left worth blocking. */
