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

:root {
  --bg:      #14142c;
  --panel:   #1a1a32;
  --border:  #2a2a4e;
  --cyan:    #00ffff;
  --magenta: #ff00ff;
  --text:    #c0c0e0;
  --dim:     #4a4a70;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
}

/* ── Layout ──────────────────────────────────────────────── */

#lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#game {
  display: none;
  position: relative;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

#canvas {
  display: block;
  margin: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ── Lobby panel ─────────────────────────────────────────── */

.lobby-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem 2.5rem;
  min-width: 360px;
  max-width: 520px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.logo {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  color: var(--cyan);
  text-shadow: 0 0 12px var(--cyan);
  text-align: center;
}

.logo span {
  color: var(--magenta);
  text-shadow: 0 0 12px var(--magenta);
}

/* ── Forms ───────────────────────────────────────────────── */

.form-group {
  display: flex;
  gap: 0.5rem;
}

input[type="text"] {
  flex: 1;
  background: #1d1d38;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
}

select {
  background: #1d1d38;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

button {
  background: transparent;
  border: 1px solid var(--cyan);
  border-radius: 4px;
  color: var(--cyan);
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: rgba(0, 255, 255, 0.08);
  box-shadow: 0 0 8px var(--cyan);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Room list ───────────────────────────────────────────── */

.room-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 200px;
  overflow-y: auto;
}

.room-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #181830;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
}

.room-name { flex: 1; font-weight: bold; }

.room-info {
  font-size: 0.8rem;
  color: var(--dim);
  white-space: nowrap;
}

.no-rooms {
  color: var(--dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.5rem;
}

/* ── Open lobby bar ──────────────────────────────────────── */

.open-lobby-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 255, 255, 0.06);
  border: 1px solid var(--cyan);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.open-lobby-label {
  flex: 1;
  font-weight: bold;
  color: var(--cyan);
}

/* ── Create form ─────────────────────────────────────────── */

.create-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.create-form input { flex: 1; min-width: 120px; }

/* ── Practice bar ────────────────────────────────────────── */

.practice-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.practice-bar span {
  flex: 1;
  font-size: 0.9rem;
  color: var(--dim);
  white-space: nowrap;
}

/* ── Player list (lobby + HUD) ───────────────────────────── */

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.ready-tag {
  background: rgba(0,255,0,0.15);
  border: 1px solid #00ff00;
  color: #00ff00;
  font-size: 0.7rem;
  padding: 0 0.4rem;
  border-radius: 3px;
}

.player-list li.dead { opacity: 0.4; text-decoration: line-through; }

/* ── HUD overlay ─────────────────────────────────────────── */

#hud {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(20, 20, 44, 0.7);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  min-width: 140px;
  pointer-events: none;
  z-index: 10;
}

/* ── Countdown ───────────────────────────────────────────── */

.countdown {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8rem;
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 40px var(--cyan), 0 0 80px var(--cyan);
  animation: pulse 0.8s ease-out;
  pointer-events: none;
  z-index: 20;
}

@keyframes pulse {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1.4); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ── Audio control ───────────────────────────────────────── */

#audio-ctrl {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  background: rgba(20, 20, 44, 0.88);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#audio-icon {
  display: none; /* hidden; track buttons replace it */
}

#track-btns {
  display: flex;
  gap: 0.3rem;
}

.track-btn {
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  border-radius: 4px;
  min-width: 0;
  transition: all 0.15s;
}

.track-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0,255,255,0.06);
  box-shadow: none;
}

.track-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0, 255, 255, 0.1);
  box-shadow: 0 0 6px var(--cyan);
}

#vol-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#vol-label {
  font-size: 0.7rem;
  color: var(--dim);
  user-select: none;
}

#vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  cursor: pointer;
}

#vol-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  cursor: pointer;
  border: none;
}

/* ── SFX toggles ─────────────────────────────────────────── */

#sfx-row {
  display: flex;
  gap: 0.3rem;
}

.sfx-toggle {
  border: 1px solid rgba(255, 60, 60, 0.7);
  color: rgba(255, 80, 80, 0.9);
  background: rgba(255, 60, 60, 0.08);
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  border-radius: 4px;
  min-width: 0;
  transition: all 0.15s;
}

.sfx-toggle:hover:not(.active) {
  background: rgba(255, 60, 60, 0.15);
  box-shadow: 0 0 6px rgba(255, 60, 60, 0.3);
}

.sfx-toggle.active {
  border-color: rgba(0, 210, 80, 0.8);
  color: rgba(0, 230, 80, 0.95);
  background: rgba(0, 210, 80, 0.1);
  box-shadow: 0 0 6px rgba(0, 210, 80, 0.4);
}

.sfx-toggle.active:hover {
  background: rgba(0, 210, 80, 0.18);
}

/* ── Mobile D-pad ─────────────────────────────────────────── */

#dpad {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  grid-template-columns: 72px 20px 72px;
  grid-template-rows: 72px 20px 72px;
  z-index: 50;
  pointer-events: auto;
}

#dpad-up    { grid-area: up; }
#dpad-left  { grid-area: left; }
#dpad-right { grid-area: right; }
#dpad-down  { grid-area: down; }

.dpad-btn {
  background: rgba(0, 255, 255, 0.12);
  border: 2px solid rgba(0, 255, 255, 0.5);
  border-radius: 12px;
  color: rgba(0, 255, 255, 0.9);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.1s;
}

.dpad-btn:active {
  background: rgba(0, 255, 255, 0.35);
  box-shadow: 0 0 14px rgba(0, 255, 255, 0.5);
}

/* ── Mobile overrides (touch devices) ───────────────────── */

@media (hover: none) and (pointer: coarse) {
  :root {
    --text:   #e8e8ff;
    --dim:    #9090b8;
    --border: #5050a0;
  }

  /* Larger tap targets */
  button {
    padding: 0.65rem 1.1rem;
    font-size: 1rem;
  }

  input[type="text"], select {
    font-size: 1rem;
    padding: 0.65rem 0.75rem;
  }

  /* Move audio ctrl to top-right so it doesn't clash with D-pad */
  #audio-ctrl {
    bottom: auto;
    top: 0.5rem;
  }

  /* Move exit button to top-left */
  #exit-btn {
    bottom: auto;
    top: 0.5rem;
  }

  /* HUD moves to top-left below exit btn */
  #hud {
    top: 3.5rem;
    right: auto;
    left: 0.5rem;
  }

}

/* ── In-game exit button ─────────────────────────────────── */

#exit-btn {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  border-color: rgba(255, 0, 255, 0.5);
  color: rgba(255, 0, 255, 0.7);
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  z-index: 15;
}

#exit-btn:hover {
  border-color: var(--magenta);
  color: var(--magenta);
  background: rgba(255, 0, 255, 0.08);
  box-shadow: 0 0 8px var(--magenta);
}

/* ── Game over ───────────────────────────────────────────── */

.game-over {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 20;
  pointer-events: none;
}

.game-over h2 {
  font-size: 3.5rem;
  color: var(--cyan);
  text-shadow: 0 0 30px var(--cyan);
  margin-bottom: 0.5rem;
}

.game-over p { font-size: 1.2rem; margin: 0.25rem 0; }
.game-over .subtext { color: var(--dim); font-size: 0.9rem; margin-top: 1rem; }
