/* ==========================================================================
   EL CAMINO DEL CHASQUI - ESTILOS VISUALES & UI/UX DE ALTA FIDELIDAD
   Paleta: Oro Inca (#F1C40F, #D4AC0D), Terracota (#C0392B), Pizarra Andina (#1A252F), Turquesa (#16A085)
   ========================================================================== */

:root {
  --gold-primary: #F39C12;
  --gold-bright: #F1C40F;
  --gold-glow: rgba(241, 196, 15, 0.4);
  --inca-red: #C0392B;
  --inca-orange: #E67E22;
  --stone-dark: #121820;
  --stone-medium: #1F2937;
  --stone-border: #374151;
  --cyan-accent: #1ABC9C;
  --undertale-bg: #000000;
  --undertale-border: #FFFFFF;
  --text-primary: #FFFFFF;
  --text-muted: #E5E7EB;
  --font-title: 'Cinzel', serif;
  --font-body: 'Outfit', sans-serif;
  --font-retro: 'VT323', monospace;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--gold-glow);
}

/* Reset y optimización para gaming en pantallas táctiles y escritorio */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b0f15;
  color: var(--text-primary);
  font-family: var(--font-body);
  touch-action: none;
}

/* ==========================================================================
   CONTENEDOR GENERAL DEL JUEGO
   ========================================================================== */
#game-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1b2838 0%, #080c11 100%);
  overflow: hidden;
}

/* Canvas del juego de plataformas 2D con relación de aspecto 16:9 perfecta */
#gameCanvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100vw;
  height: 56.25vw; /* 16:9 exacto */
  max-height: 100vh;
  max-width: 177.78vh; /* 16:9 exacto */
  background-color: #5dade2;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.85);
}

/* ==========================================================================
   HUD SUPERIOR MODERNO (HIGH-FIDELITY GLASSMORPHISM)
   ========================================================================== */
#game-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  pointer-events: none; /* Permite clicks a través excepto en botones */
  z-index: 50;
}

.hud-card {
  pointer-events: auto;
  background: rgba(18, 24, 32, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(241, 196, 15, 0.35);
  border-radius: 16px;
  padding: 8px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.hud-card:hover {
  border-color: rgba(241, 196, 15, 0.7);
}

/* Tarjeta de Zona y Progreso */
.zone-progress-card {
  flex: 1;
  max-width: 440px;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.zone-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--gold-bright);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.5px;
}

.progress-bar-container {
  position: relative;
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  display: flex;
  align-items: center;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e67e22, #f1c40f, #2ecc71);
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(241, 196, 15, 0.6);
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mini-chasqui {
  position: absolute;
  top: -12px;
  left: 0%;
  transform: translateX(-50%);
  font-size: 1.1rem;
  transition: left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.destination-icon {
  position: absolute;
  right: -6px;
  top: -14px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #f1c40f;
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
}

/* Tarjeta de Inventario de Alimentos */
.inventory-card {
  display: flex;
  gap: 16px;
  padding: 8px 18px;
}

.food-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}

.food-icon {
  font-size: 1.3rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  animation: floatSmall 3s ease-in-out infinite alternate;
}

.food-item:nth-child(2) .food-icon {
  animation-delay: 0.5s;
}

.food-item:nth-child(3) .food-icon {
  animation-delay: 1s;
}

.food-count {
  color: #fff;
  min-width: 14px;
  text-align: right;
  font-family: var(--font-body);
}

/* Botones de Control de la UI */
.hud-controls {
  pointer-events: auto;
  display: flex;
  gap: 8px;
}

.hud-btn {
  background: rgba(18, 24, 32, 0.85);
  border: 1px solid rgba(241, 196, 15, 0.4);
  color: var(--gold-bright);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-btn:hover {
  transform: translateY(-2px) scale(1.05);
  border-color: var(--gold-bright);
  background: rgba(241, 196, 15, 0.2);
  box-shadow: var(--shadow-glow);
}

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

/* Hint de Controles en PC */
#desktop-controls-hint {
  position: absolute;
  top: 80px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.45);
  padding: 6px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--gold-bright);
  pointer-events: none;
  z-index: 40;
  animation: fadeInOut 12s forwards;
}

/* ==========================================================================
   CUADRO DE DIÁLOGO FLOTANTE ESTILO UNDERTALE
   ========================================================================== */
.dialogue-container {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 92%;
  max-width: 820px;
  z-index: 100;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.dialogue-container.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(30px);
}

.dialogue-frame {
  background-color: var(--undertale-bg);
  border: 4px solid var(--undertale-border);
  box-shadow: 0 0 0 2px #000, 0 8px 30px rgba(0, 0, 0, 0.95), 0 0 15px var(--gold-glow);
  border-radius: 12px;
  padding: 18px 24px;
  display: flex;
  gap: 22px;
  align-items: center;
  position: relative;
}

/* Caja de Retrato del Personaje / Deidad */
.dialogue-portrait-box {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#portraitCanvas {
  width: 90px;
  height: 90px;
  background-color: #0b1118;
  border: 3px solid var(--gold-bright);
  border-radius: 8px;
  image-rendering: pixelated;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
}

.portrait-name {
  font-family: var(--font-title);
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--gold-bright);
  text-align: center;
  max-width: 100px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Contenido del Diálogo */
.dialogue-content {
  flex: 1;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.typewriter-text {
  font-family: var(--font-retro);
  font-size: 1.7rem;
  line-height: 1.35;
  color: #ffffff;
  letter-spacing: 1px;
  word-spacing: 2px;
  text-shadow: 2px 2px 0 #000000;
  min-height: 3.8em;
}

/* Indicador de Avance de Diálogo */
.dialogue-advance-prompt {
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold-bright);
  margin-top: 8px;
}

.prompt-key {
  background: rgba(241, 196, 15, 0.2);
  border: 1px solid var(--gold-bright);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.72rem;
}

.blinking-arrow {
  color: var(--gold-bright);
  font-size: 1rem;
  animation: blink 0.7s infinite alternate ease-in-out;
}

/* ==========================================================================
   BOTONES TÁCTILES VIRTUALES PARA DISPOSITIVOS MÓVILES
   ========================================================================== */
.touch-controls-layer {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 60;
}

.dpad-group, .action-group {
  display: flex;
  gap: 16px;
  pointer-events: auto;
}

.touch-btn {
  background: radial-gradient(circle, rgba(44, 62, 80, 0.85) 0%, rgba(18, 24, 32, 0.95) 100%);
  border: 2px solid rgba(241, 196, 15, 0.6);
  border-radius: 50%;
  color: #ffffff;
  width: 68px;
  height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active, .touch-btn.active {
  transform: scale(0.92);
  background: radial-gradient(circle, rgba(241, 196, 15, 0.4) 0%, rgba(18, 24, 32, 0.95) 100%);
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px var(--gold-glow);
}

.action-btn {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  background: radial-gradient(circle, rgba(192, 57, 43, 0.85) 0%, rgba(120, 20, 10, 0.95) 100%);
  border-color: #e74c3c;
}

.action-btn .btn-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.action-btn .btn-sub {
  font-size: 1.2rem;
  margin-top: -2px;
}

.dash-btn {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  background: radial-gradient(circle, rgba(241, 196, 15, 0.85) 0%, rgba(180, 130, 0, 0.95) 100%);
  border-color: #f1c40f;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.2), 0 0 20px rgba(241, 196, 15, 0.5);
}

.dash-btn .btn-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.dash-btn .btn-sub {
  font-size: 1.2rem;
  margin-top: -2px;
  color: #1a1a1a;
}

.dash-btn:active, .dash-btn.active {
  transform: scale(0.92);
  background: radial-gradient(circle, rgba(255, 230, 100, 0.9) 0%, rgba(241, 196, 15, 0.85) 100%);
  border-color: #fff3a0;
  box-shadow: 0 0 24px #f1c40f, inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.dialogue-btn {
  width: 80px;
  height: 76px;
  border-radius: 20px;
  background: radial-gradient(circle, rgba(39, 174, 96, 0.9) 0%, rgba(20, 90, 50, 0.95) 100%);
  border-color: #2ecc71;
  font-size: 0.85rem;
  font-weight: 800;
  animation: pulseGlow 1.5s infinite alternate;
}

.dialogue-btn.hidden {
  display: none;
}

/* ==========================================================================
   PANTALLAS MODALES: INICIO Y VICTORIA
   ========================================================================== */
.overlay-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 15, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  padding: 16px;
}

.overlay-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  border: 3px solid var(--gold-bright);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 30px var(--gold-glow);
  padding: 32px 36px;
  max-width: 620px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.sun-disc-header {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sun-halo {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(241, 196, 15, 0.7) 0%, rgba(241, 196, 15, 0) 70%);
  animation: rotateSun 15s linear infinite;
}

.inti-face {
  font-size: 3.5rem;
  z-index: 2;
  filter: drop-shadow(0 0 15px rgba(241, 196, 15, 0.8));
}

.modal-title {
  font-family: var(--font-title);
  font-size: 1.85rem;
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 2px 10px rgba(241, 196, 15, 0.5);
  letter-spacing: 1.5px;
}

.modal-subtitle {
  font-size: 1rem;
  color: #e5e7eb;
  font-weight: 600;
  margin-top: -12px;
}

.intro-description {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: #d1d5db;
  text-align: left;
}

.learning-tag {
  margin-top: 8px;
  color: var(--cyan-accent);
  font-weight: 600;
}

.instructions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  text-align: left;
}

.instruction-col {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 10px 14px;
  border-left: 3px solid var(--gold-bright);
}

.instruction-col h4 {
  font-size: 0.85rem;
  color: var(--gold-bright);
  margin-bottom: 6px;
}

.instruction-col p {
  font-size: 0.78rem;
  color: #d1d5db;
  line-height: 1.4;
}

.btn-primary-golden {
  background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
  border: 2px solid #f1c40f;
  color: #111827;
  font-family: var(--font-title);
  font-size: 1.05rem;
  font-weight: 900;
  padding: 14px 28px;
  border-radius: 14px;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 8px 20px rgba(243, 156, 18, 0.4);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  width: 100%;
  max-width: 380px;
}

.btn-primary-golden:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 25px rgba(241, 196, 15, 0.6);
  background: linear-gradient(135deg, #f1c40f 0%, #f39c12 100%);
}

.btn-primary-golden:active {
  transform: translateY(1px) scale(0.98);
}

/* Pantalla de Victoria Específica */
.victory-card {
  max-width: 680px;
  border-color: #f1c40f;
  background: linear-gradient(135deg, #1c2738 0%, #0d131d 100%);
}

.victory-sun-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.cuzco-temple-icon {
  font-size: 2.8rem;
  filter: drop-shadow(0 0 15px rgba(241, 196, 15, 0.8));
}

.victory-sun-banner h2 {
  font-family: var(--font-title);
  font-size: 1.8rem;
  color: var(--gold-bright);
  letter-spacing: 2px;
}

.victory-speech {
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(241, 196, 15, 0.5);
  border-radius: 14px;
  padding: 16px 20px;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: #fff;
  font-style: italic;
  text-align: justify;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.6);
}

.victory-stats-box {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-heading {
  font-size: 0.9rem;
  color: var(--gold-bright);
  font-family: var(--font-title);
}

.victory-items-tally {
  display: flex;
  justify-content: space-around;
  gap: 12px;
}

.tally-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tally-icon {
  font-size: 1.8rem;
}

.tally-title {
  font-size: 0.8rem;
  color: #9ca3af;
}

.tally-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: #f1c40f;
}

.total-score-badge {
  font-size: 0.95rem;
  color: #e5e7eb;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.total-score-badge strong {
  color: #2ecc71;
  display: block;
  font-size: 1.1rem;
  margin-top: 2px;
}

/* ==========================================================================
   ANIMACIONES CLAVE
   ========================================================================== */
@keyframes blink {
  0% { opacity: 0.2; transform: translateY(-2px); }
  100% { opacity: 1; transform: translateY(2px); }
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 5px rgba(46, 204, 113, 0.4); }
  100% { box-shadow: 0 0 20px rgba(46, 204, 113, 0.8); }
}

@keyframes floatSmall {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px); }
}

@keyframes rotateSun {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes modalPop {
  0% { transform: scale(0.9) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-10px); }
  10% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; }
  100% { opacity: 0; pointer-events: none; }
}

/* ==========================================================================
   RESPONSIVIDAD Y MEDIA QUERIES
   ========================================================================== */
/* Dispositivos Móviles y Pantallas Angostas */
@media (max-width: 768px) {
  #game-hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 8px;
  }

  .zone-progress-card {
    padding: 6px 10px;
  }

  .zone-badge {
    font-size: 0.72rem;
  }

  .inventory-card {
    padding: 6px 10px;
    gap: 10px;
  }

  .food-item {
    font-size: 0.82rem;
  }

  .food-icon {
    font-size: 1rem;
  }

  .hud-btn {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }

  #desktop-controls-hint {
    display: none; /* Se oculta en móviles para no estorbar */
  }

  .dialogue-container {
    bottom: 12px;
    width: 95%;
  }

  .dialogue-frame {
    padding: 12px 14px;
    gap: 12px;
  }

  #portraitCanvas {
    width: 64px;
    height: 64px;
  }

  .portrait-name {
    font-size: 0.65rem;
    max-width: 70px;
  }

  .typewriter-text {
    font-size: 1.35rem;
    min-height: 4em;
  }

  .touch-controls-layer {
    bottom: 12px;
    padding: 0 12px;
  }

  .touch-btn {
    width: 58px;
    height: 58px;
    font-size: 1.3rem;
  }

  .action-btn {
    width: 66px;
    height: 66px;
  }

  .dash-btn {
    width: 66px;
    height: 66px;
  }

  .modal-card {
    padding: 20px 18px;
    max-height: 94vh;
    overflow-y: auto;
  }

  .modal-title {
    font-size: 1.45rem;
  }

  .instructions-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .victory-speech {
    font-size: 0.88rem;
    padding: 12px 14px;
  }
}

/* En dispositivos puramente de escritorio sin pantalla táctil, ocultar botones flotantes si no hay toque */
@media (hover: hover) and (pointer: fine) and (min-width: 1024px) {
  /* Si el usuario tiene mouse/teclado y pantalla amplia, mantenemos los botones con opacidad sutil para que no estorben pero sigan siendo interactivos */
  .touch-controls-layer {
    opacity: 0.45;
    transition: opacity 0.2s;
  }
  .touch-controls-layer:hover {
    opacity: 0.95;
  }
}
