/* IMPORTS */
@import "reset.css";
@import "normalize.css";

/* --- FUENTES (self-hosted, sin dependencias externas) --- */
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/SourceSans3-Variable.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/Fraunces-Variable.woff2") format("woff2");
}

/* --- CONFIGURACIÓN GENERAL --- */
:root {
  /* Paleta de Colores Principal */
  --c-bg-beige: #f8f5ee;
  --c-text-main: #333;
  --c-text-muted: #555;
  
  /* Verdes del Lince */
  --c-green-dark: #0d2210;
  --c-green-primary: #0d5e17;
  --c-green-medium: #65956f;
  --c-green-light: #a8d5b1;
  --c-green-sage: #d6ead5;
  
  /* Gráficas */
  --c-chart-spain: #5b8fa8;
  --c-chart-portugal: #c0644a;
  --c-chart-highlight: #4a8f6a;
}

html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

body {
  font-family: "Source Sans 3", sans-serif;
  margin: 0;
  color: #333;
  background-color: #f8f5ee;
  overflow-x: hidden;
  /* El fondo se ha movido a body::after para solucionar un bug de zoom excesivo en iOS/móviles */
}

/* Pseudo-elemento eliminado (la imagen pasa a ser un banner) */
/* --- I18N LANGUAGE SELECTOR --- */
.lang-selector {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.95rem;
  z-index: 20;
}

.lang-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  transition: color 0.2s ease, border-color 0.2s ease;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.lang-btn:hover {
  color: #fff;
}

.lang-btn.active {
  color: #fff;
  font-weight: 700;
  border-bottom: 2px solid #fff;
}

.lang-separator {
  color: rgba(255, 255, 255, 0.4);
  margin: 0 0.4rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

h1 {
  color: #0d5e17;
}



h1,
h2 {
  font-family: "Fraunces", serif;
  font-weight: 900;
  font-optical-sizing: auto;
}

p {
  line-height: 1.6;
  font-size: 1.1rem;
}

/* --- ESTRUCTURA Y CAPAS PRINCIPALES --- */
/* Esta regla unificada asegura que todos los contenedores principales
   estén por encima del velo de fondo. */
.hero-section,
.main-footer,
#scrolly-container {
  position: relative;
  z-index: 1;
}

/* --- PIE DE PÁGINA --- */
.main-footer {
  width: 100%;
  padding: 0 20px 40px; /* Elimina borde superior y reduce el espacio */
  text-align: center; /* Centrado como se solicita */
}

.footer-copyright {
  margin: 0;
  font-size: 1rem;
  color: var(--c-green-medium);
}

/* --- ESTRUCTURA SCROLLYTELLING --- */
main {
  /* Difuminado suave desde el beige del fondo hacia un verde más presente, regresando a beige al final para el mapa */
  background: linear-gradient(180deg, #f8f5ee 0%, #d6ead5 30%, #a8d5b1 85%, #65956f 100%);
  padding-top: 40px;
  padding-bottom: 80px;
  position: relative;
  z-index: 1;
}

#scrolly-container {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
}

.scroll-text {
  width: 45%;
  padding: 0 5%;
}

.sticky-chart {
  width: 55%;
  position: -webkit-sticky;
  position: sticky;
  top: 10vh;
  height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  max-width: 800px;
}

#chart svg {
  width: 100%;
  height: auto;
  max-width: 800px;
}

.step {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 0;
  opacity: 0.3;
  transition: opacity 0.5s;
}

.step.is-active {
  opacity: 1;
}

.step h2 {
  margin-bottom: 24px;
}

.step p {
  font-size: 1.3rem;
  line-height: 1.6;
}

.status-vulnerable {
  color: var(--c-green-primary) ;
  font-weight: 900;
}

/* --- RESPONSIVE: apila el texto y el gráfico en pantallas estrechas --- */
@media (max-width: 900px) {
  #scrolly-container {
    flex-direction: column;
  }

  .scroll-text,
  .sticky-chart {
    width: 100%;
  }

  .scroll-text {
    /* Magia CSS: el margen negativo hace que el contenedor termine exactamente 
       cuando el Paso 5 se activa. Así la gráfica se "despega" y sube junto con 
       el texto sin solaparse jamás. Ahí acaba la animación. */
    margin-bottom: -52vh;
  }

  main {
    /* Al hacer el #scrolly-container más corto, el main también se acortaba perdiendo 
       su fondo verde oscuro. Añadimos padding al main para recuperar ese espacio visual,
       de modo que el Paso 5 flote sobre el verde y empuje al mapa hacia abajo naturalmente. */
    padding-bottom: 52vh;
  }

  .sticky-chart {
    order: -1; /* el gráfico se ve primero y queda fijo mientras el texto scrollea debajo */
    top: 0;
    height: 45vh;
    margin-bottom: 20px;
  }

  .step {
    min-height: 100vh; /* Ocupa toda la pantalla */
    justify-content: flex-end; /* Empuja el texto hacia abajo (fuera de la gráfica) */
    padding-bottom: 10vh; /* Margen inferior */
    opacity: 0; /* Minimalista: desaparece cuando no está activo */
  }
  
  .step.is-active {
    opacity: 1;
  }
}

@media (max-width: 480px) {
  .scroll-text {
    padding: 0 4%;
  }

  .sticky-chart {
    height: 38vh;
  }

  /* Eliminado override de min-height para que herede el 100vh de 900px */

  .step h2 {
    font-size: 1.3rem;
  }

  .step p {
    font-size: 1rem;
  }
}

/* --- ESTILOS DEL GRÁFICO (D3) --- */
.bar {
  fill: #5b8fa8; /* azul acero apagado — España */
  transition: fill 0.5s;
}

.bar.highlight {
  fill: #4a8f6a; /* verde salvia — año destacado */
}

.bar-portugal {
  fill: #c0644a; /* terracota cálida — Portugal */
  transition: fill 0.5s;
}

.chart-legend rect {
  stroke: none;
}

.chart-legend text {
  font-family: "Source Sans 3", sans-serif;
  font-size: 1.1em;
  fill: #555;
}

.bar-label {
  text-anchor: middle; /* Centra el texto horizontalmente */
  font-size: 1.3em;
  font-weight: 700;
  fill: #555; /* Un color de texto un poco más suave */
}

.axis-label {
  font-size: 1.3em; /* Aumentado de 1.1em a 1.3em */
  fill: #555;
}

/* Separación específica para el título del eje Y */
.y-axis-label {
  font-size: 1.3em;
  fill: #555;
  /* Sin transform para evitar conflictos con la rotación */
}

.tick text {
  font-family: "Source Sans 3", sans-serif;
  font-size: 1.8em;
}

/* --- SECCIÓN MAPA GEOGRÁFICO --- */
.map-section {
  width: 100%;
  margin: 60px 0;
  position: relative;
  z-index: 1;
}

.map-title {
  text-align: center;
  font-family: "Fraunces", serif;
  font-weight: 900;
  font-size: clamp(1.8rem, 4vw, 2.5rem); /* Igualado al tamaño de .hero-intro h2 */
  color: var(--c-green-primary)
  margin-bottom: 8px;
  padding: 0 20px;
}

.map-subtitle {
  text-align: center;
  max-width: 700px;
  margin: 0 auto 24px;
  font-size: clamp(1.2rem, 3vw, 1.4rem);
  padding: 0 20px;
}

#map {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  height: 560px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* Lynx illustration overlay inside the map */
.map-lynx-overlay {
  position: absolute;
  bottom: 12px;
  left: 20px; /* changed from right: 1500px to stick to the left edge safely */
  width: 200px;
  max-width: 30%; /* ensure it doesn't take over small screens */
  height: auto;
  opacity: 0.75;
  pointer-events: none; /* no bloquea clics ni interacciones del mapa */
  z-index: 2;
}

@media (max-width: 700px) {
  #map {
    height: 420px;
  }

  .map-lynx-overlay {
    width: 100px;
    bottom: 8px;
    left: 8px;
  }
}

/* --- HERO SECTION (HEADER + BANNER) --- */
.hero-section {
  position: relative;
  width: 100%;
  min-height: 100vh;
  background-color: #0d2210;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 80px 8% 60px;
  margin-bottom: 40px;
  color: #fff;
  text-align: left;
  overflow: hidden;
}

/* Background image pushed to the right without leaving a gap on the left */
.hero-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%; /* Normal width so the image does not enlarge */
  height: 100%;
  background-image: url("../images/lince_fondo.jpg.webp");
  background-size: cover;
  background-position: right -20vw center; /* Push image to the right */
  z-index: 0;
}

/* Gradient overlay */
.hero-section::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Solid color up to 25% to completely hide the gap/cut left by shifting the image, then fades */
  background: linear-gradient(to right, rgba(13, 34, 16, 1) 0%, rgba(13, 34, 16, 1) 25%, rgba(13, 34, 16, 0.85) 45%, rgba(13, 34, 16, 0) 75%);
  z-index: 1;
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 55%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.hero-content h1 {
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  color: #fff;
  margin: 0;
  line-height: 1.1;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.hero-subtitle {
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  color: #e6f0e5;
  margin: 0;
  font-weight: 300;
  text-shadow: 0 1px 5px rgba(0,0,0,0.5);
}

.hero-intro h2 {
  color: #a8d5b1;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  margin: 0 0 1rem 0;
}

.hero-intro p {
  font-size: clamp(1.1rem, 2vw, 1.25rem);
  line-height: 1.6;
  color: #f8f5ee;
  margin: 0;
  column-count: 2;
  column-gap: 30px;
}

/* --- REFERENCIAS --- */
.references-section {
  max-width: 1200px;
  margin: 80px auto 20px; /* Reducido el margen inferior */
  padding: 40px 20px 10px; /* Reducido el padding inferior */
  border-top: 2px solid var(--c-green-sage);
  text-align: left;
}

.references-section h2 {
  font-size: 1.8rem;
  color: #0d5e17;
  margin-bottom: 20px;
  margin-top: 0;
}

.references-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

.references-list li {
  margin-bottom: 16px;
  font-size: 0.95rem;
  color: #555;
  line-height: 1.5;
}

/* --- ANIMACIONES Y UI --- */
.scroll-indicator {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  margin: 0 auto;
  z-index: 3;
  display: flex;
  justify-content: center;
  color: #fff;
  animation: bounce 2s infinite;
}

.scroll-indicator svg {
  width: 32px;
  height: 32px;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@media (max-width: 900px) {
  .hero-section::before {
    width: 100%;
    background-position: center;
  }
  .hero-section::after {
    /* More opaque on smaller screens so text is readable over the image */
    background: linear-gradient(to bottom, rgba(13, 34, 16, 0.8) 0%, rgba(13, 34, 16, 0.95) 100%);
  }
  .hero-content {
    max-width: 100%;
    margin-top: 40px;
  }
  .hero-section {
    align-items: center;
    padding-top: 100px;
  }
}

@media (max-width: 768px) {
  .hero-content h1 {
    font-size: clamp(2rem, 8vw, 3rem);
  }
  .hero-intro p {
    column-count: 1;
  }
}
