/* ===================================
   EL PUEBLO DEL LIBRO — style.css
   Estética artesanal / zapoteca
=================================== */

:root {
  --adobe:        #c4814a;
  --adobe-claro:  #e8b87a;
  --adobe-oscuro: #8b5a2b;
  --tierra:       #6b3f1f;
  --tierra-clara: #d4a96a;
  --crema:        #f5edd8;
  --crema-2:      #ede0c4;
  --barro:        #9c6b3c;
  --rojo-zap:     #a63220;
  --verde-zap:    #3d6b3a;
  --azul-zap:     #1f4e79;
  --dorado:       #c9922a;
  --negro-suave:  #2a1a0e;
  --blanco-calido:#fef8ed;

  --fuente-titulo: 'Playfair Display', Georgia, serif;
  --fuente-cuerpo: 'Lora', Georgia, serif;
  --fuente-italic: 'Crimson Text', Georgia, serif;

  --radio-nodo: 90px;
  --radio-nodo-sm: 70px;
}

/* ---- Reset y base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  background-color: #d9c4a0;
  font-family: var(--fuente-cuerpo);
  color: var(--negro-suave);
  overflow-x: hidden;
  position: relative;
}

/* ---- Fondo texturizado tipo adobe ---- */
.bg-texture {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, #c8a06888 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, #a0623244 0%, transparent 50%),
    radial-gradient(ellipse at 50% 10%, #e8d0a033 0%, transparent 40%);
  background-color: #d9c4a0;
  z-index: 0;
  pointer-events: none;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.07;
  background-image:
    repeating-linear-gradient(
      45deg,
      var(--tierra) 0px, var(--tierra) 2px,
      transparent 2px, transparent 20px
    ),
    repeating-linear-gradient(
      -45deg,
      var(--rojo-zap) 0px, var(--rojo-zap) 1px,
      transparent 1px, transparent 20px
    );
}

/* ---- Partículas ---- */
.particles {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.particula {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: flotar var(--dur, 8s) ease-in-out infinite var(--delay, 0s);
}

@keyframes flotar {
  0%   { opacity: 0; transform: translateY(0) scale(1); }
  20%  { opacity: 0.6; }
  80%  { opacity: 0.3; }
  100% { opacity: 0; transform: translateY(-80px) scale(0.5); }
}

/* ---- Header ---- */
.pueblo-header {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}

.header-ornament {
  position: absolute;
  top: 1rem;
  width: 60px;
  height: 60px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'%3E%3Cpath d='M30 5 L55 30 L30 55 L5 30 Z' fill='none' stroke='%238b5a2b' stroke-width='2'/%3E%3Cpath d='M30 15 L45 30 L30 45 L15 30 Z' fill='none' stroke='%23c4814a' stroke-width='1.5'/%3E%3Ccircle cx='30' cy='30' r='5' fill='%23c9922a'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.5;
}
.header-ornament.top-left  { left: 1.5rem; }
.header-ornament.top-right { right: 1.5rem; transform: scaleX(-1); }

.titulo-wrapper {
  display: inline-block;
  position: relative;
}

.titulo-decoracion {
  font-family: var(--fuente-italic);
  color: var(--adobe);
  font-size: 1rem;
  letter-spacing: 0.5rem;
  opacity: 0.7;
  margin: 0.25rem 0;
}

.pueblo-titulo {
  font-family: var(--fuente-titulo);
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 900;
  color: var(--tierra);
  text-shadow:
    2px 3px 0 #c4814a55,
    0 1px 12px #8b5a2b33;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.pueblo-subtitulo {
  font-family: var(--fuente-italic);
  font-style: italic;
  font-size: clamp(0.9rem, 2.5vw, 1.15rem);
  color: var(--adobe-oscuro);
  opacity: 0.8;
  margin-top: 0.3rem;
}

/* ---- Mapa principal ---- */
.pueblo-mapa {
  position: relative;
  z-index: 5;
  width: 100%;
  max-width: 750px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  /* altura proporcional al SVG */
  aspect-ratio: 7 / 6.2;
  min-height: 460px;
}

/* SVG camino de fondo */
.hexagono-camino {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* ---- Personaje central ---- */
.personaje-wrapper {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: 90px;
  height: 90px;
  transition: left 0.8s cubic-bezier(.68,-0.55,.27,1.55),
              top  0.8s cubic-bezier(.68,-0.55,.27,1.55);
  will-change: left, top;
}

.personaje-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(2px 4px 6px rgba(90,40,10,0.45));
  animation: personaje-idle 3s ease-in-out infinite;
}

.personaje-placeholder {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  filter: drop-shadow(2px 4px 6px rgba(90,40,10,0.45));
  animation: personaje-idle 3s ease-in-out infinite;
}

.personaje-sombra {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 14px;
  background: radial-gradient(ellipse, rgba(80,30,5,0.35) 0%, transparent 80%);
  border-radius: 50%;
}

@keyframes personaje-idle {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-6px); }
}

.personaje-wrapper.caminando .personaje-img,
.personaje-wrapper.caminando .personaje-placeholder {
  animation: personaje-caminar 0.3s steps(2) infinite;
}

@keyframes personaje-caminar {
  0%   { transform: rotate(-5deg) translateY(-2px); }
  50%  { transform: rotate(5deg)  translateY(2px);  }
  100% { transform: rotate(-5deg) translateY(-2px); }
}

/* ---- Nodos del pueblo ---- */
.nodo-pueblo {
  position: absolute;
  left: var(--x);
  top:  var(--y);
  transform: translate(-50%, -50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  width: var(--radio-nodo);

  /* Animación de entrada */
  opacity: 0;
  animation: nodo-entrada 0.6s ease-out forwards;
}

.nodo-pueblo:nth-child(3)  { animation-delay: 0.1s; }
.nodo-pueblo:nth-child(4)  { animation-delay: 0.2s; }
.nodo-pueblo:nth-child(5)  { animation-delay: 0.3s; }
.nodo-pueblo:nth-child(6)  { animation-delay: 0.4s; }
.nodo-pueblo:nth-child(7)  { animation-delay: 0.5s; }
.nodo-pueblo:nth-child(8)  { animation-delay: 0.6s; }

@keyframes nodo-entrada {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Contenedor de la imagen del lugar */
.lugar-img-wrapper {
  width: var(--radio-nodo);
  height: var(--radio-nodo);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

.nodo-pueblo:hover .lugar-img-wrapper {
  transform: scale(1.1) translateY(-4px);
}

.lugar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(3px 5px 8px rgba(80,30,5,0.5));
  transition: filter 0.3s ease;
}

.nodo-pueblo:hover .lugar-img {
  filter: drop-shadow(4px 6px 12px rgba(80,30,5,0.7)) brightness(1.05);
}

/* Placeholder si no carga imagen */
.lugar-placeholder {
  width: var(--radio-nodo);
  height: var(--radio-nodo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  filter: drop-shadow(3px 5px 8px rgba(80,30,5,0.5));
  transition: transform 0.25s ease;
}
.nodo-pueblo:hover .lugar-placeholder {
  transform: scale(1.1) translateY(-4px);
}

/* Etiqueta de texto con degradado negro */
.lugar-label {
  margin-top: 4px;
  text-align: center;
  padding: 3px 10px 4px;
  background: linear-gradient(
    to bottom,
    rgba(20, 8, 2, 0.72) 0%,
    rgba(40, 15, 5, 0.88) 100%
  );
  border-radius: 6px;
  backdrop-filter: blur(2px);
  border: 1px solid rgba(200, 150, 80, 0.3);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  max-width: 120px;
}

.lugar-label span {
  font-family: var(--fuente-cuerpo);
  font-size: clamp(0.65rem, 1.8vw, 0.8rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(200,140,60,0.4);
  white-space: nowrap;
  line-height: 1.3;
}

/* Estado activo / seleccionado */
.nodo-pueblo.activo .lugar-img-wrapper,
.nodo-pueblo.activo .lugar-placeholder {
  animation: pulso-activo 1.2s ease-in-out infinite;
}

@keyframes pulso-activo {
  0%, 100% { transform: scale(1.05); }
  50%       { transform: scale(1.18) translateY(-4px); }
}

.nodo-pueblo.activo .lugar-label {
  background: linear-gradient(
    to bottom,
    rgba(180, 100, 20, 0.9) 0%,
    rgba(120, 55, 10, 0.95) 100%
  );
  border-color: rgba(220, 180, 80, 0.7);
  box-shadow: 0 3px 12px rgba(180,100,20,0.5);
}

/* ---- Banda inferior zapoteca ---- */
.banda-inferior {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 28px;
  background: var(--tierra);
  overflow: hidden;
}

.banda-patron {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      90deg,
      var(--rojo-zap)   0px, var(--rojo-zap)   14px,
      var(--adobe)      14px, var(--adobe)      28px,
      var(--dorado)     28px, var(--dorado)     42px,
      var(--verde-zap)  42px, var(--verde-zap)  56px,
      var(--azul-zap)   56px, var(--azul-zap)   70px,
      var(--tierra)     70px, var(--tierra)      84px
    );
  opacity: 0.85;
}

/* ---- Overlay de carga/transición ---- */
.overlay-transicion {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(ellipse at center, #d4a050 0%, #6b3f1f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay-transicion.visible {
  opacity: 1;
  pointer-events: all;
}

.overlay-transicion .overlay-texto {
  font-family: var(--fuente-titulo);
  font-size: 1.6rem;
  color: var(--crema);
  text-shadow: 0 2px 10px rgba(0,0,0,0.4);
  animation: overlay-pulso 1s ease-in-out infinite alternate;
}

@keyframes overlay-pulso {
  from { opacity: 0.7; transform: scale(0.97); }
  to   { opacity: 1;   transform: scale(1.03); }
}

.overlay-ornamento {
  font-size: 2.5rem;
  animation: girar-lento 4s linear infinite;
  opacity: 0.7;
}

@keyframes girar-lento {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* =====================
   RESPONSIVE — móvil
===================== */
@media (max-width: 600px) {
  :root {
    --radio-nodo: 68px;
    --radio-nodo-sm: 55px;
  }

  .pueblo-mapa {
    aspect-ratio: 7 / 7.5;
    min-height: 390px;
  }

  .personaje-wrapper {
    width: 68px;
    height: 68px;
  }

  .lugar-label {
    max-width: 90px;
    padding: 2px 7px 3px;
  }

  .lugar-label span {
    font-size: 0.62rem;
  }

  .pueblo-titulo {
    font-size: 1.8rem;
  }

  .pueblo-subtitulo {
    font-size: 0.85rem;
  }

  .header-ornament {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 400px) {
  :root {
    --radio-nodo: 58px;
  }

  .pueblo-mapa {
    aspect-ratio: 7 / 8;
    min-height: 350px;
  }

  .lugar-label span {
    font-size: 0.58rem;
    white-space: normal;
    word-break: break-word;
  }
}
