* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0b0b12;
  color: #e6e6f0;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

#layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

/* Barra de debug: conteo de entidades al pie del canvas (solo con
   debug_entities activo). Hoy desactivada por defecto. */
#debugbar {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 12px;
  letter-spacing: 1px;
  color: #9aa0c0;
  background: rgba(5, 5, 10, 0.72);
  border: 2px solid #2a2a44;
  border-radius: 6px;
  user-select: none;
}

#debugbar b { color: #e6e6f0; }

/* HUD de partida (NIVEL/VIDAS/PUNTOS + powerups + instrucciones) bajo el
   canvas, con el mismo aspecto que la barra de debug. Solo en la pantalla
   del juego: fuera de ella (menú/lobby) no existe. */
#hud {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 13px;
  letter-spacing: 1px;
  color: #9aa0c0;
  background: rgba(5, 5, 10, 0.72);
  border: 2px solid #2a2a44;
  border-radius: 6px;
  user-select: none;
}

#hud b { color: #e6e6f0; }

#hud-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

#hud-powers {
  display: flex;
  gap: 10px;
  color: #6ee7a8;
}

#stage {
  position: relative;
  width: 800px;
  /* Altura AUTOMÁTICA: canvas + (HUD/debug bajo él cuando existen). */
}

#game {
  display: block;
  background: #05050a;
  border: 2px solid #2a2a44;
  border-radius: 6px;
  box-shadow: 0 0 32px rgba(80, 120, 255, 0.15);
}

/* Con la partida EN MARCHA no se ve el cursor sobre el canvas (si el
   navegador permite, además se captura: ver Pointer Lock en game.js). */
#game.no-cursor {
  cursor: none;
}

/* --- Mando táctil (solo tablet/móvil; ver game.js `updateTouch`) --------- */
#touch-controls {
  position: absolute;
  inset: 0;
  /* Sin z-index a propósito: los controles van DETRÁS del #overlay (orden
     del DOM) y solo existen con partida en marcha (overlay oculto). */
  pointer-events: none; /* solo los controles capturan toques */
  touch-action: none;
  user-select: none;
}

#touch-stick,
#touch-fire {
  position: absolute;
  bottom: 5%;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* Anillo del joystick: transparente pero visible (borde 30%, fondo 7%).
   FUERA de la pantalla de juego: su borde derecho toca el borde izquierdo
   del canvas (right: 100% + margen) — no se monta nunca encima. */
#touch-stick {
  right: 100%;
  margin-right: 14px;
  width: 24%;
  max-width: 150px;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.30);
  background: rgba(255, 255, 255, 0.07);
}

#touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.40);
  transform: translate(-50%, -50%);
}

/* Botón de disparo: también FUERA de la pantalla, pegado al borde derecho
   del canvas (left: 100% + margen). Tono ámbar de las balas propias. */
#touch-fire {
  left: 100%;
  margin-left: 14px;
  width: 17%;
  max-width: 110px;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 209, 102, 0.50);
  background: rgba(255, 209, 102, 0.10);
}

/* Diana en el centro del disparo: glyph, sin texto (nada de
   instrucciones pintadas). */
#touch-fire::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.55);
  transform: translate(-50%, -50%);
}

#overlay {
  /* Velo SOLO sobre el canvas: el HUD inferior (stats + instrucciones)
     debe seguir legible en bienvenida/pausa/game over. 604 = 600 + bordes. */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 604px;
  background: rgba(5, 5, 10, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
}

.hidden { display: none !important; }

#overlay h1 {
  margin: 0;
  font-size: 40px;
  letter-spacing: 4px;
  color: #6ee7a8;
  text-align: center;
}

#overlay h1.danger { color: #ff5a6e; }

#overlay p {
  margin: 6px 0 0 0;
  color: #c5c5da;
}

#overlay-record {
  color: #ffd166 !important;
  font-weight: bold;
  letter-spacing: 2px;
  animation: record-pulse 1s ease-in-out infinite alternate;
}

/* Podio de las mejores puntuaciones (TOP 3) */
#overlay-top3 {
  white-space: pre-line;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  line-height: 1.7;
  color: #9aa0c0 !important;
  text-align: center;
}

@keyframes record-pulse {
  from { opacity: 0.65; }
  to   { opacity: 1.0; }
}

#credit {
  margin-top: 4px;
  text-align: right;
  font-size: 11px;
  letter-spacing: 1px;
  color: #7a7a92;
  user-select: none;
}

/* Partículas que emanan del título de bienvenida */
.title-particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform, opacity;
  box-shadow: 0 0 6px currentColor;
  animation: title-particle-anim 1.8s ease-out forwards;
}

@keyframes title-particle-anim {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.6); }
  20%  { opacity: 1; }
  75%  { opacity: 0.85; }
  100% { opacity: 0; transform: translate(var(--dx, 0px), var(--dy, -30px)) scale(1.5); }
}

/* --- Paneles de navegación: menú de modo y lobby ------------------------- */
.panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(5, 5, 10, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  border-radius: 6px;
}

.panel h1 {
  margin: 0;
  font-size: 40px;
  letter-spacing: 4px;
  color: #6ee7a8;
  text-align: center;
}

.panel h2 {
  margin: 0 0 4px 0;
  font-size: 24px;
  letter-spacing: 3px;
  color: #7ad7ff;
  text-align: center;
}

.panel-sub { margin: 0; color: #c5c5da; }
.panel-hint { margin: 0; color: #7a7a92; font-size: 13px; letter-spacing: 1px; }

/* Tarjetas de elección de modo (ratón o teclas 1/2) */
.cards { display: flex; gap: 16px; }

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 250px;
  padding: 22px 16px;
  background: #05050a;
  border: 2px solid #2a2a44;
  border-radius: 8px;
  color: #e6e6f0;
  font: inherit;
  letter-spacing: 2px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover, .card:focus-visible {
  border-color: #6ee7a8;
  box-shadow: 0 0 18px rgba(110, 231, 168, 0.25);
  outline: none;
}

.card:disabled {
  opacity: 0.35;
  cursor: default;
}

.card:disabled:hover { border-color: #2a2a44; box-shadow: none; }

.card .card-name { font-size: 18px; font-weight: bold; color: #6ee7a8; }
.card .card-desc { font-size: 12px; color: #9aa0c0; letter-spacing: 1px; }

/* Lobby: filas de partidas en curso */
#lobby-list {
  width: 460px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: #05050a;
  border: 2px solid #2a2a44;
  border-radius: 6px;
  color: #e6e6f0;
  font: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}

.lobby-row:hover, .lobby-row:focus-visible {
  border-color: #7ad7ff;
  outline: none;
}

.lobby-row .state-waiting { color: #6ee7a8; }
.lobby-row .state-playing { color: #ffd166; }
.lobby-row .players-n { color: #9aa0c0; }

/* Botones de los paneles */
.panel-actions { display: flex; gap: 12px; margin-top: 6px; }

.btn {
  padding: 10px 22px;
  background: #05050a;
  border: 2px solid #6ee7a8;
  border-radius: 6px;
  color: #6ee7a8;
  font: inherit;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover, .btn:focus-visible {
  background: rgba(110, 231, 168, 0.12);
  outline: none;
}

.btn-ghost { border-color: #2a2a44; color: #9aa0c0; }
.btn-ghost:hover, .btn-ghost:focus-visible { background: rgba(154, 160, 192, 0.1); }

/* Fila del lobby con acciones (mi partida: START/Salir; resto: UNIRSE).
   Izquierda: aforo + estado (sin números de sala); derecha: hint/botones. */
.lobby-row .row-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lobby-row .row-hint {
  margin-left: auto;
  color: #7d82a6;
  font-size: 12px;
  letter-spacing: 1px;
  white-space: nowrap;
}

.btn-mini {
  padding: 5px 12px;
  background: #05050a;
  border: 2px solid #6ee7a8;
  border-radius: 6px;
  color: #6ee7a8;
  font: inherit;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-mini:hover, .btn-mini:focus-visible {
  background: rgba(110, 231, 168, 0.12);
  outline: none;
}

.btn-mini-ghost { border-color: #2a2a44; color: #9aa0c0; }
.btn-mini-ghost:hover, .btn-mini-ghost:focus-visible { background: rgba(154, 160, 192, 0.1); }

.lobby-row .row-actions { display: flex; gap: 8px; }
