/*
 * Tesoro Andino: Rutas de la Cueva — styles.css
 * Hoja de estilos original. Paleta cálida latina (terracota, ocre,
 * verde selva, turquesa, dorado). Responsive desde 320 px, sin scroll
 * horizontal, controles táctiles grandes y respeto por
 * prefers-reduced-motion.
 */

:root {
  --terracota: #c96f4a;
  --terracota-osc: #a3502e;
  --ocre: #d9a441;
  --dorado: #e9c46a;
  --selva: #3e7c4f;
  --turquesa: #2a9d8f;
  --crema: #fdf3e0;
  --papel: #f7e8cd;
  --tinta: #2b1d12;
  --cueva: #241811;
  --sombra: rgba(43, 29, 18, 0.25);
}

* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Gradiente cálido y sutil de fondo (sin azules ni violetas). */
  background: linear-gradient(180deg, var(--crema) 0%, var(--papel) 55%, #f3ddb8 100%);
  background-attachment: fixed;
  color: var(--tinta);
  line-height: 1.6;
  font-size: 1rem;
}

img, canvas { max-width: 100%; }

/* ---------------------- Cabecera ---------------------- */
.cabecera {
  background: linear-gradient(135deg, var(--terracota-osc), var(--terracota) 55%, var(--ocre));
  color: var(--crema);
  padding: 1rem 1rem 1.5rem;
  text-align: center;
}

.cabecera .marca {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.85rem;
  opacity: 0.9;
  margin: 0 0 0.5rem;
}

.cabecera h1 {
  margin: 0.2rem auto 0.6rem;
  font-size: clamp(1.4rem, 4.5vw, 2.3rem);
  max-width: 22ch;
  line-height: 1.25;
}

.cabecera p {
  margin: 0 auto;
  max-width: 60ch;
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
}

/* Migas de pan */
.migas {
  background: var(--papel);
  border-bottom: 1px solid #e3cf9f;
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
}
.migas ol { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.migas li::after { content: "›"; margin-left: 0.35rem; color: var(--terracota-osc); }
.migas li:last-child::after { content: ""; }
.migas a { color: var(--terracota-osc); }

main { display: block; }

.seccion {
  padding: 2rem 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.seccion h2 {
  color: var(--terracota-osc);
  font-size: clamp(1.25rem, 3.5vw, 1.7rem);
  margin: 0 0 0.8rem;
  border-bottom: 3px solid var(--dorado);
  display: inline-block;
  padding-bottom: 0.2rem;
}

.seccion h3 { color: var(--selva); font-size: clamp(1.02rem, 2.6vw, 1.2rem); }

/* ---------------------- Zona de juego ---------------------- */
.zona-juego {
  background: var(--cueva);
  border-radius: 12px;
  padding: 0.8rem;
  box-shadow: 0 6px 18px var(--sombra);
}

.marco-canvas {
  position: relative;
  max-width: 768px;
  margin: 0 auto;
}

#juego {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  image-rendering: pixelated;
  border-radius: 8px;
  background: var(--cueva);
}

/* HUD */
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.7rem 0;
  color: var(--crema);
}

.hud .dato {
  background: rgba(253, 243, 224, 0.12);
  border: 1px solid rgba(233, 196, 106, 0.5);
  border-radius: 8px;
  padding: 0.25rem 0.6rem;
  font-size: 0.9rem;
  min-width: 5.2rem;
  text-align: center;
}

.hud .dato strong { color: var(--dorado); display: block; font-size: 1.05rem; }
#hud-vidas { color: #ff9d8a; letter-spacing: 0.1em; }

.pista-nivel {
  color: var(--papel);
  text-align: center;
  font-size: 0.9rem;
  margin: 0.3rem 0 0.6rem;
  min-height: 1.4em;
  opacity: 0.85;
}

/* Botonera del juego */
.botonera {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.7rem;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  background: linear-gradient(180deg, #30a898, var(--turquesa));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  font-size: 1rem;
  font-weight: 600;
  min-height: 48px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 6px 14px rgba(43, 29, 18, 0.14);
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover { background: #238b7e; transform: translateY(-1px); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 10px 18px rgba(43, 29, 18, 0.18); }
.btn:active { transform: translateY(2px); box-shadow: none; }

.btn-sec {
  background: var(--terracota);
}
.btn-sec:hover { background: var(--terracota-osc); }

.btn-dorado {
  background: var(--ocre);
  color: var(--tinta);
}
.btn-dorado:hover { background: var(--dorado); }

/* Botón «Compartir» de las pantallas de victoria (dorado festivo). */
.btn-compartir {
  background: linear-gradient(180deg, var(--dorado), var(--ocre));
  color: var(--tinta);
}
.btn-compartir:hover { background: var(--dorado); }

.btn:focus-visible,
.nivel-btn:focus-visible,
.dpad button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--dorado);
  outline-offset: 2px;
}

/* D-pad táctil */
.dpad {
  display: grid;
  grid-template-areas:
    ". arriba ."
    "izquierda abajo derecha";
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
  justify-content: center;
  margin: 0.4rem auto 0.2rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dpad button {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 14px;
  background: var(--terracota);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  touch-action: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.dpad button.activo,
.dpad button:active {
  background: var(--dorado);
  color: var(--tinta);
  transform: translateY(3px);
  box-shadow: none;
}

.dpad .arr { grid-area: arriba; }
.dpad .izq { grid-area: izquierda; }
.dpad .aba { grid-area: abajo; }
.dpad .der { grid-area: derecha; }

/* Controles táctiles: D-pad + botón grande de defensa «🪇 Defensa». */
.controles-tactil {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.3rem;
}

.btn-defensa {
  position: relative;
  overflow: hidden;
  min-width: 132px;
  min-height: 64px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #e0b055, var(--ocre));
  color: var(--tinta);
  font-size: 1.05rem;
  font-weight: 700;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 8px 16px rgba(43, 29, 18, 0.2);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn-defensa .etiqueta { position: relative; z-index: 1; }

/* Icono de maracas (arte aportado por el propietario del sitio). */
.icono-maracas {
  height: 1.75em;
  width: auto;
  vertical-align: -0.5em;
  pointer-events: none;
}

/* Relleno de recarga: crece de 0 a 100% según el cooldown restante. */
.btn-defensa .relleno {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(43, 29, 18, 0.35);
  transition: width 0.1s linear;
  z-index: 0;
}

.btn-defensa.cargando { filter: saturate(0.55) brightness(0.92); }
.btn-defensa.activo,
.btn-defensa:active {
  transform: translateY(3px);
  box-shadow: none;
}

/* ---------------------- Overlays / pantallas ---------------------- */
.pantalla {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(36, 24, 17, 0.92);
  border-radius: 8px;
  z-index: 5;
  padding: 0.6rem;
}

.pantalla.visible { display: flex; }

.tarjeta {
  background: var(--papel);
  border: 3px solid var(--dorado);
  border-radius: 14px;
  padding: 1.2rem 1.4rem;
  max-width: 560px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.tarjeta h2, .tarjeta h3 {
  color: var(--terracota-osc);
  margin-top: 0;
  border: none;
}

.tarjeta .acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1rem;
}

.tarjeta ul { text-align: left; }

/* Selección de niveles */
#lista-niveles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.mundo-titulo {
  grid-column: 1 / -1;
  color: var(--selva);
  font-size: 0.95rem;
  margin: 0.6rem 0 0;
  text-align: left;
}

.nivel-btn {
  background: #fff;
  border: 2px solid var(--turquesa);
  border-radius: 10px;
  padding: 0.55rem 0.6rem;
  font-size: 0.9rem;
  text-align: left;
  color: var(--tinta);
  min-height: 48px;
}

.nivel-btn:hover:not([disabled]) { background: var(--dorado); border-color: var(--ocre); }
.nivel-btn[disabled] { opacity: 0.55; cursor: not-allowed; border-color: #b8a888; }
.nivel-num {
  display: inline-block;
  background: var(--turquesa);
  color: #fff;
  border-radius: 50%;
  width: 1.5em;
  height: 1.5em;
  line-height: 1.5em;
  text-align: center;
  font-weight: 700;
  margin-right: 0.3rem;
}
.nivel-btn[disabled] .nivel-num { background: #b8a888; }
.nivel-btn small { display: block; color: var(--terracota-osc); }

/* ---------------------- Contenido editorial ---------------------- */
.dos-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 700px) {
  .dos-col { grid-template-columns: 1fr 1fr; }
}

.tarjeta-info {
  background: #fff;
  border-left: 5px solid var(--turquesa);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 3px 10px var(--sombra);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tarjeta-info:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(43, 29, 18, 0.18);
}

.tarjeta-info h3 { margin-top: 0; color: var(--terracota-osc); }

.lista-mundos {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
}
@media (min-width: 700px) {
  .lista-mundos { grid-template-columns: 1fr 1fr; }
}
.lista-mundos li {
  background: #fff;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  border-top: 5px solid var(--ocre);
  box-shadow: 0 2px 8px var(--sombra);
}
.lista-mundos li:nth-child(2) { border-top-color: var(--selva); }
.lista-mundos li:nth-child(3) { border-top-color: var(--turquesa); }
.lista-mundos li:nth-child(4) { border-top-color: var(--terracota); }
.lista-mundos h3 { margin: 0 0 0.3rem; }
.lista-mundos p { margin: 0.2rem 0; font-size: 0.95rem; }

/* FAQ */
details {
  background: #fff;
  border: 1px solid #e3cf9f;
  border-radius: 10px;
  margin-bottom: 0.6rem;
  padding: 0.7rem 1rem;
}
details summary {
  font-weight: 700;
  color: var(--terracota-osc);
  cursor: pointer;
}
details p { margin: 0.5rem 0 0; }

/* Enlaces internos sugeridos */
.enlaces-relacionados ul { padding-left: 1.2rem; }
.enlaces-relacionados a { color: var(--turquesa); font-weight: 600; }

/* Región solo para lectores de pantalla */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------- Compartir en redes ---------------------- */
.seccion-compartir { text-align: center; }

.redes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
  margin-top: 1rem;
}

.red {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 52px;
  padding: 0.7rem 1.15rem;
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22), 0 8px 16px rgba(43, 29, 18, 0.15);
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

.red svg { width: 24px; height: 24px; fill: currentColor; flex-shrink: 0; }

.red:hover { transform: translateY(-3px); box-shadow: 0 7px 0 rgba(0, 0, 0, 0.2), 0 14px 24px rgba(43, 29, 18, 0.22); filter: brightness(1.07); }
.red:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22); }

.red-whatsapp  { background: #1faa53; }
.red-x         { background: #14171a; }
.red-telegram  { background: #1f8fce; }
.red-youtube   { background: #c4302b; }
.red-instagram { background: #b83a7d; }
.red-tiktok    { background: #211f20; }

.nota-compartir { font-size: 0.9rem; opacity: 0.85; max-width: 60ch; margin: 0.8rem auto 0; }

/* Aviso flotante («toast») al copiar el enlace. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(150%);
  background: var(--tinta);
  color: var(--crema);
  border: 2px solid var(--dorado);
  border-radius: 12px;
  padding: 0.7rem 1.2rem;
  font-weight: 600;
  max-width: min(92vw, 480px);
  text-align: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 50;
  pointer-events: none;
}

.toast.visible { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Racha de días en la pantalla de inicio. */
.racha {
  margin: 0.4rem 0 0;
  font-weight: 700;
  color: var(--terracota-osc);
  min-height: 1.2em;
}

/* ---------------------- Pie ---------------------- */
.pie {
  background: var(--tinta);
  color: var(--papel);
  text-align: center;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  font-size: 0.9rem;
}
.pie a { color: var(--dorado); }
.pie nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

/* ---------------------- Animaciones ---------------------- */
@keyframes brillo-suave {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233, 196, 106, 0.55); }
  50% { box-shadow: 0 0 18px 4px rgba(233, 196, 106, 0.55); }
}
.btn-jugar-destacado { animation: brillo-suave 2.4s ease-in-out infinite; }

/* Respeta prefers-reduced-motion: desactiva animaciones. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}

/* ---------------------- Ajustes móviles ---------------------- */
@media (max-width: 480px) {
  .seccion { padding: 1.4rem 0.8rem; }
  .hud .dato { min-width: 4.4rem; font-size: 0.8rem; }
  .dpad {
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
  }
  .dpad button { width: 60px; height: 60px; }
  .tarjeta { padding: 1rem; }
}

/* ============================================================
   Modo inmersivo móvil: pantalla completa 9:16
   Overlay fijo que cubre todo el viewport (sin nada de la
   landing visible), HUD compacto de una sola barra y lienzo
   centrado con letterboxing oscuro de textura sutil.
   ============================================================ */
body.inmersivo { overflow: hidden; }

#juego { touch-action: none; }   /* sin zoom/scroll del navegador al jugar */

#overlay-inmersivo {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  width: 100dvw;
  height: 100dvh;
  /* Letterboxing elegante: fondo oscuro con textura sutil de puntos. */
  background:
    radial-gradient(circle at 30% 22%, rgba(233, 196, 106, 0.07) 0 2px, transparent 3px) 0 0 / 44px 44px,
    radial-gradient(circle at 72% 78%, rgba(201, 111, 74, 0.08) 0 2px, transparent 3px) 22px 22px / 44px 44px,
    linear-gradient(180deg, #1b110a 0%, #241811 55%, #170e08 100%);
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#overlay-inmersivo.visible { display: flex; }

/* Barra HUD compacta: salir | vidas/tesoros/puntos/tiempo | pausa/defensa/sonido */
.oi-hud {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.45rem;
  min-height: 52px;
  background: rgba(36, 24, 17, 0.94);
  border-bottom: 1px solid rgba(233, 196, 106, 0.35);
  color: var(--crema);
}

.oi-datos {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}

.oi-dato strong { color: var(--dorado); font-weight: 700; }
#oi-vidas { color: #ff9d8a; letter-spacing: 0.05em; }

.oi-btn {
  flex-shrink: 0;
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: rgba(253, 243, 224, 0.14);
  color: var(--crema);
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

.oi-btn:active { background: var(--dorado); color: var(--tinta); box-shadow: none; }
.oi-btn:focus-visible { outline: 3px solid var(--dorado); outline-offset: 2px; }

.oi-cerrar { background: var(--terracota); color: #fff; font-size: 1.25rem; }
.oi-cerrar:active { background: var(--terracota-osc); color: #fff; }

/* Botón 🪇 compacto de la barra (reutiliza .btn-defensa base, ajustado). */
.oi-defensa {
  position: relative;
  overflow: hidden;
  min-width: 48px;
  min-height: 48px;
  background: linear-gradient(180deg, #e0b055, var(--ocre));
  color: var(--tinta);
  font-size: 1.25rem;
}

.oi-defensa .relleno { background: rgba(43, 29, 18, 0.4); }
.oi-defensa .etiqueta { position: relative; z-index: 1; }

/* Zona del lienzo: centrado, con la proporción 9:16 que fija el JS. */
.oi-lienzo {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
}

#overlay-inmersivo .marco-canvas {
  max-width: none;
  width: auto;
  margin: 0;
}

#overlay-inmersivo #juego {
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  box-shadow: 0 0 0 3px rgba(233, 196, 106, 0.35), 0 14px 36px rgba(0, 0, 0, 0.55);
}

/* Pantallas (inicio, victoria, derrota…) dentro del modo inmersivo. */
#overlay-inmersivo .pantalla { border-radius: 10px; padding: 0.5rem; }
#overlay-inmersivo .tarjeta { padding: 1rem; max-height: 100%; }
#overlay-inmersivo .tarjeta h2 { font-size: 1.15rem; }
#overlay-inmersivo .tarjeta p,
#overlay-inmersivo .tarjeta li { font-size: 0.9rem; }
#overlay-inmersivo .nivel-btn { font-size: 0.85rem; padding: 0.45rem 0.5rem; }
