/* ============================================================================
   SPACE MINER - Deep Space Resource Extraction Prototype
   Sci-Fi Holographic Style with High-Performance Canvas Rendering
   ============================================================================ */

:root {
  --bg-deep: #030712;
  --neon-cyan: #00f5ff;
  --neon-green: #39ff14;
  --neon-amber: #ffaa00;
  --neon-pink: #ff007f;
  --neon-purple: #bd00ff;
  --glass-bg: rgba(6, 18, 32, 0.78);
  --glass-border: rgba(0, 245, 255, 0.28);
  --glass-glow: 0 0 15px rgba(0, 245, 255, 0.25);
  --text-main: #e2f1f8;
  --text-dim: #7aa5bd;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: 'Share Tech Mono', monospace;
  font-size: 14px;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

canvas#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  background-color: transparent;
  cursor: crosshair;
}

/* ============================================================================
   PANTALLA DE CARGA (LOADING SCREEN) CON CINEMÁTICA
   ============================================================================ */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(3, 7, 18, 0.45) 0%, rgba(3, 7, 18, 0.85) 80%);
  pointer-events: auto;
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.loading-overlay.fade-out {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px;
  max-width: 650px;
  width: 90%;
}

.loading-brand {
  position: relative;
  margin-bottom: 45px;
}

.logo-sub {
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--neon-cyan);
  text-transform: uppercase;
  margin-bottom: 8px;
  opacity: 0.85;
}

.logo-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(38px, 8vw, 68px);
  font-weight: 900;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.8), 0 0 40px rgba(0, 245, 255, 0.4);
  line-height: 1.1;
}

.progress-box {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-box.hidden {
  display: none;
}

.progress-bar-container {
  width: 100%;
  height: 12px;
  background: rgba(6, 18, 32, 0.9);
  border: 1px solid var(--neon-cyan);
  border-radius: 6px;
  overflow: hidden;
  padding: 2px;
  box-shadow: 0 0 15px rgba(0, 245, 255, 0.3);
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #00f5ff, #39ff14, #00f5ff);
  background-size: 200% 100%;
  border-radius: 4px;
  box-shadow: 0 0 10px var(--neon-cyan);
  transition: width 0.15s ease-out;
  animation: shineProgress 2s linear infinite;
}

@keyframes shineProgress {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  letter-spacing: 1px;
}

.status-msg {
  color: var(--text-dim);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80%;
  text-align: left;
}

.percent-val {
  font-family: 'Orbitron', monospace;
  font-weight: bold;
  color: var(--neon-cyan);
  font-variant-numeric: tabular-nums;
}

/* Botón Iniciar Misión */
.btn-launch-game {
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.25) 0%, rgba(57, 255, 20, 0.25) 100%);
  border: 2px solid var(--neon-cyan);
  color: #fff;
  padding: 16px 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 25px rgba(0, 245, 255, 0.5), inset 0 0 15px rgba(0, 245, 255, 0.2);
  transition: all 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  animation: pulseLaunch 2s infinite alternate;
}

.btn-launch-game.hidden {
  display: none;
}

.btn-launch-game:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 0 35px rgba(0, 245, 255, 0.8), inset 0 0 25px rgba(57, 255, 20, 0.3);
  border-color: #fff;
}

.btn-launch-game:active {
  transform: scale(0.97);
}

.btn-launch-game .btn-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffffff;
  text-shadow: 0 0 10px var(--neon-cyan);
}

.btn-launch-game .btn-sub {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--neon-green);
}

@keyframes pulseLaunch {
  0% { box-shadow: 0 0 20px rgba(0, 245, 255, 0.4); }
  100% { box-shadow: 0 0 35px rgba(0, 245, 255, 0.85), 0 0 15px rgba(57, 255, 20, 0.5); }
}

/* ============================================================================
   TOP BAR & CONTROLES
   ============================================================================ */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 110; /* Por encima de la pantalla de carga para que los botones funcionen */
  pointer-events: none;
  background: linear-gradient(180deg, rgba(3, 7, 18, 0.85) 0%, rgba(3, 7, 18, 0) 100%);
}

.brand {
  display: flex;
  flex-direction: column;
}

.brand-sub {
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--neon-cyan);
  opacity: 0.8;
  font-weight: bold;
}

.brand-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 245, 255, 0.6);
}

.top-controls {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.hud-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--neon-cyan);
  width: 40px;
  height: 40px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--glass-glow);
}

.hud-btn:hover {
  background: rgba(0, 245, 255, 0.2);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.5);
  transform: translateY(-1px);
}

.hud-btn:active {
  transform: scale(0.95);
}

/* ============================================================================
   HUD DEL JUEGO
   ============================================================================ */
#game-hud.hud-hidden {
  display: none !important;
}

.hud-panel {
  position: absolute;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--glass-glow);
  z-index: 10;
  pointer-events: auto;
  transition: all 0.25s ease-out;
}

.hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: bold;
}

.hud-toggle {
  cursor: pointer;
  user-select: none;
}

.hud-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-chevron {
  font-size: 9px;
  color: var(--neon-cyan);
  transition: transform 0.25s ease;
  display: inline-block;
}

.hud-panel.collapsed .hud-chevron {
  transform: rotate(-90deg);
}

.hud-collapsible {
  max-height: 480px;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin-top 0.25s ease;
  opacity: 1;
  margin-top: 10px;
}

.hud-panel.collapsed .hud-collapsible {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

.hud-header .title {
  color: var(--neon-cyan);
}

.status-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(57, 255, 20, 0.15);
  color: var(--neon-green);
  border: 1px solid rgba(57, 255, 20, 0.4);
}

.status-badge.full {
  background: rgba(255, 0, 127, 0.2);
  color: var(--neon-pink);
  border-color: var(--neon-pink);
  animation: pulse 1s infinite alternate;
}

.coord-tag {
  font-size: 10px;
  color: var(--text-dim);
}

/* Cargo Meter */
#cargo-hud {
  top: 66px;
  left: 20px;
  width: 260px;
}

.cargo-meter {
  position: relative;
  width: 100%;
  height: 20px;
  background: rgba(1, 10, 20, 0.85);
  border: 1px solid rgba(0, 245, 255, 0.3);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}

.cargo-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00f5ff 0%, #39ff14 70%, #ffaa00 95%, #ff007f 100%);
  transition: width 0.25s ease-out;
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.7);
}

.cargo-counter {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 0 4px #000;
}

.minerals-mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.minerals-mini-grid::-webkit-scrollbar,
.minerals-grid::-webkit-scrollbar {
  width: 4px;
}

.minerals-mini-grid::-webkit-scrollbar-thumb,
.minerals-grid::-webkit-scrollbar-thumb {
  background: var(--neon-cyan);
  border-radius: 2px;
}

.mineral-mini-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.mineral-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
}

/* Base Global Inventory HUD */
#base-hud {
  top: 66px;
  right: 20px;
  width: 250px;
}

.minerals-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}

.mineral-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  border-left: 3px solid var(--neon-cyan);
}

.mineral-card .name {
  font-size: 10px;
  color: var(--text-dim);
}

.mineral-card .amount {
  font-size: 13px;
  font-weight: bold;
  color: #fff;
}

/* Base Compass / Waypoint */
#base-compass {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  text-align: center;
  background: var(--glass-bg);
  min-width: 150px;
  height: 40px;
  box-sizing: border-box;
  z-index: 120; /* Por encima de #top-bar (110) y de la pantalla de juego */
}

.compass-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--neon-amber);
  margin-bottom: 0;
  white-space: nowrap;
}

.compass-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.arrow-container {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#base-arrow {
  font-size: 16px;
  color: var(--neon-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  transform-origin: center center;
  will-change: transform;
}

.dist-val {
  font-family: 'Orbitron', monospace, sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  min-width: 60px;
  text-align: left;
}

/* ============================================================================
   ACTION PROMPT & NOTIFICATIONS
   ============================================================================ */
.action-prompt {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 245, 255, 0.15);
  border: 1px solid var(--neon-cyan);
  padding: 10px 24px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 0 25px rgba(0, 245, 255, 0.4);
  z-index: 25;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.action-prompt.hidden {
  opacity: 0;
  transform: translate(-50%, 15px);
}

.action-prompt .prompt-icon {
  font-size: 18px;
  color: var(--neon-cyan);
  animation: spin 3s linear infinite;
}

.action-prompt .prompt-msg {
  font-size: 12px;
  letter-spacing: 1.5px;
  font-weight: bold;
  color: #fff;
}

#toast-container {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  background: rgba(6, 18, 32, 0.92);
  border: 1px solid var(--glass-border);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.6);
  animation: slideInRight 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.toast.deposit {
  border-color: var(--neon-green);
  color: var(--neon-green);
}

.toast.warning {
  border-color: var(--neon-pink);
  color: var(--neon-pink);
}

/* Leyenda inferior (HUD Hints) */
#hud-hints {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  z-index: 10;
  pointer-events: none;
  opacity: 0.85;
  white-space: nowrap;
}

#hud-hints .hidden {
  display: none !important;
}

/* ============================================================================
   ANIMACIONES & MEDIA QUERIES
   ============================================================================ */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(50px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Adaptación para pantallas móviles */
@media (max-width: 768px) {
  #top-bar {
    height: 44px;
    padding: 0 10px;
  }

  .brand-sub {
    font-size: 7px;
    letter-spacing: 2px;
  }

  .brand-title {
    font-size: 13px;
    letter-spacing: 1.5px;
  }

  .hud-btn {
    width: 32px;
    height: 32px;
    border-radius: 5px;
  }

  .hud-btn svg {
    width: 15px;
    height: 15px;
  }

  /* Brújula centrada en la barra superior */
  #base-compass {
    top: 6px;
    padding: 3px 8px;
    min-width: 0;
    max-width: 135px;
    height: 32px;
    gap: 6px;
  }

  .compass-label {
    display: none; /* En pantallas móviles el rótulo largo "ESTACIÓN ORBITAL" se oculta, dejando sólo la flecha y distancia */
  }

  .arrow-container {
    width: 18px;
    height: 18px;
  }

  #base-arrow {
    font-size: 14px;
    width: 16px;
    height: 16px;
  }

  .dist-val {
    font-size: 11px;
    min-width: 38px;
  }

  /* Paneles laterales en móvil: pastillas compactas a top: 48px */
  #cargo-hud {
    top: 48px;
    left: 8px;
    width: auto;
    min-width: 0;
    padding: 5px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }

  #cargo-hud:not(.collapsed) {
    width: 210px;
    max-width: 80vw;
    z-index: 50;
  }

  #base-hud {
    top: 48px;
    right: 8px;
    width: auto;
    min-width: 0;
    padding: 5px 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }

  #base-hud:not(.collapsed) {
    width: 200px;
    max-width: 80vw;
    z-index: 50;
  }

  .hud-header {
    font-size: 9px;
    gap: 8px;
  }

  .hud-header-left {
    gap: 4px;
  }

  .status-badge {
    font-size: 8px;
    padding: 1px 4px;
  }

  .coord-tag {
    font-size: 8px;
    margin-left: 2px;
  }

  .cargo-meter {
    height: 14px;
    margin-bottom: 6px;
  }

  .cargo-counter {
    font-size: 8px;
  }

  .minerals-mini-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    max-height: 180px;
  }

  .mineral-mini-pill {
    padding: 2px 4px;
    font-size: 9px;
  }

  .minerals-grid {
    grid-template-columns: 1fr;
    gap: 3px;
    max-height: 200px;
  }

  .mineral-card {
    padding: 3px 6px;
  }

  .mineral-card .name {
    font-size: 8px;
  }

  .mineral-card .amount {
    font-size: 10px;
  }

  #hud-hints {
    font-size: 8px;
    bottom: 6px;
    letter-spacing: 0.6px;
  }
}

/* En teléfonos muy estrechos (vertical < 400px), acortar título si es necesario */
@media (max-width: 420px) {
  .brand-sub {
    display: none;
  }

  .brand-title {
    font-size: 11px;
    letter-spacing: 1px;
  }

  .top-controls {
    gap: 6px;
  }

  #cargo-hud, #base-hud {
    top: 48px;
    padding: 4px 6px;
  }

  .status-badge {
    font-size: 7px;
    padding: 1px 3px;
  }
}
