/* La regla @import va PRIMERO */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap');

/* --- ESTILOS GLOBALES Y VARIABLES --- */

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

:root {
    --primary-font: 'Cardo', serif;
    --text-color: #212529;
    --primary-color: #014c9d;
    --bg-white: #ffffff;
    --bg-light-gray: #fcfcfd; /* Fondo más claro para contenedores */
    --border-color: #dee2e6;
}

body {
    background-color: var(--bg-white);
    color: var(--text-color);
    font-family: var(--primary-font);
    margin: 0;
    line-height: 1.6;
}

p {
            line-height: 1.8;
            text-align: justify;
            margin-bottom: 1.5rem;
        }
        
.apparatus {
            font-size: 0.9em;
            color: #555;

        }

/* --- TIPOGRAFÍA Y ESTILOS DE TEXTO --- */

.page-number {
            text-align: center;
            margin-top: 2rem;
            color: #888;
        }

/* --- LAYOUT Y CONTENEDOR PRINCIPAL --- */
.container-wide {
    width: 90%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* --- HEADER Y NAVEGACIÓN --- */
.site-header {
    background-color: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 0;
}
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.site-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
}

/* ESTILOS PARA LA NAVEGACIÓN PRINCIPAL CON ÍCONOS */
.main-nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.main-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    color: var(--text-color);
    background-color: transparent;
    border-radius: 50%;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

.main-nav a:hover {
    color: var(--primary-color);
    background-color: var(--bg-light-gray);
}

.main-nav svg {
    width: 24px;
    height: 24px;
}

/* Botón hamburguesa */
.nav-toggle {
    display: none;
}

.menu-icon {
    display: none;
    width: 30px;
    height: 24px;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    z-index: 1001;
}

.menu-icon-bar {
    display: block;
    width: 100%;
    height: 4px;
    background-color: var(--text-color);
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* === NAVEGACIÓN MÓVIL === */
@media (max-width: 800px) {
  .menu-icon {
    display: flex;
  }

  .main-nav {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-white);
    padding-top: 4.5rem;
    padding-bottom: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    height: 100vh;
    overflow-y: auto;
  }

  .main-nav ul {
    flex-direction: column;
    gap: 0.75rem;
    padding: 0 1.5rem;
  }

  .main-nav a {
    padding: 0.75rem 0;
    border-radius: 0;
    display: block;
  }

  .nav-toggle:checked ~ .nav-overlay {
    display: block;
    opacity: 1;
  }

  .nav-toggle:checked ~ .main-nav {
    display: block;
  }

  .nav-toggle:checked ~ .menu-icon .menu-icon-bar:nth-child(1) {
    transform: translateY(10px) rotate(45deg);
  }

  .nav-toggle:checked ~ .menu-icon .menu-icon-bar:nth-child(2) {
    opacity: 0;
  }

  .nav-toggle:checked ~ .menu-icon .menu-icon-bar:nth-child(3) {
    transform: translateY(-10px) rotate(-45deg);
  }
}

/* --- GRID DE CONTENEDORES DE LA PORTADA --- */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* CORREGIDO: Usa fr en lugar de % para más seguridad con gaps */
  gap: 2.5rem;
  padding: 4rem 0;
}

.info-grid > .info-container:nth-child(n + 5) {
  grid-column: span 2;
}

.info-container {
    background-color: var(--bg-light-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 450px;
    transition: box-shadow 0.3s ease;
}
.info-container:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,0.06);
}

.info-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.info-header h3 {
    margin: 0;
    font-size: 1.4rem;
}

.info-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
    overflow-wrap: break-word; /* Clave para prevenir desbordamiento de texto */
}

.info-content p:first-child { margin-top: 0; }
.info-content p:last-child { margin-bottom: 0; }
.info-content a { color: var(--primary-color); font-weight: 700; text-decoration: none; }
.info-content a:hover { text-decoration: underline; }

/* --- INTRODUCCIÓN EN DOS COLUMNAS (PORTADA) --- */
.intro-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  margin: 4rem auto 2rem auto;
  padding: 2rem;
  background-color: var(--bg-light-gray);
  border-left: 4px solid var(--primary-color);
  border-radius: 4px;
  max-width: 1200px;
  color: var(--text-color);
}
.intro-left {
  font-size: 1.1rem;
  line-height: 1.8;
}
.intro-left h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.intro-left ul {
  padding-left: 1.5rem;
  margin: 1rem 0;
}
.intro-left ul li {
  margin-bottom: 0.5rem;
}
.intro-left a {
  color: var(--primary-color);
  text-decoration: underline dotted;
  transition: color 0.2s ease-in-out;
}
.intro-left a:hover {
  color: #0056b3;
}
.intro-right {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #666;
  background-color: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}
.intro-right h3 {
  margin-top: 0;
  font-size: 1.2rem;
  color: var(--text-color);
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 0.25rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

/* --- PRE-FOOTER Y FOOTER --- */
.pre-footer {
    background-color: var(--bg-light-gray);
    border-top: 1px solid var(--border-color);
    padding: 4rem 0;
    margin-top: 4rem;
}
.pre-footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 3rem;
}
.pre-footer-column h4 {
    font-size: 1.2rem;
    margin-top: 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
    display: inline-block;
}
.pre-footer-column ul {
    list-style: none;
    padding: 0;
}
.pre-footer-column ul li {
    margin-bottom: 0.5rem;
}
.pre-footer-column ul li a {
    color: var(--text-color);
    text-decoration: none;
}
.pre-footer-column ul li a:hover {
    color: var(--primary-color);
}
.site-footer {
    text-align: center;
    padding: 2rem 0;
    font-size: 0.9rem;
    background-color: #212529;
    color: #ccc;
}
.site-footer a {
    color: var(--bg-white);
}

/* --- ESTILOS PARA PÁGINAS DE CONTENIDO (SINGLE/LIST) --- */
.page-content {
    padding: 3rem 0;
}
.content-body {
    background-color: var(--bg-white);
    padding: 2rem;
    margin-top: 2rem;
}
pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* --- COMPONENTES DE PÁGINAS DE LIBROS --- */

.libro-contexto {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    background-color: var(--bg-light-gray);
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
}
.libro-contexto a {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 500;
}
.libro-contexto a:hover {
    text-decoration: underline;
}
.libro-contexto span {
    color: #6c757d;
}
.libro-contexto strong {
    color: var(--text-color);
    font-weight: 600;
}

.chapter-nav {
    border: 1px solid var(--border-color);
    background-color: #fcfcfc;
    border-radius: 8px;
    padding: 1.5rem;
    position: sticky;
    top: 2rem;
}

/* MODIFICADO: h3 ahora alinea el título y el botón */
.chapter-nav h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* NUEVO: Estilos para el botón de colapso */
#toggle-nav-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* NUEVO: Transición para el ícono SVG dentro del botón */
#toggle-nav-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease-in-out;
}

/* MODIFICADO: ul ahora tiene propiedades para la animación */
.chapter-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 1000px; /* Un valor alto para asegurar que todo el contenido quepa */
    overflow: hidden;
    transition: max-height 0.4s ease-in-out;
}

/* NUEVO: Clase para el estado colapsado */
.chapter-nav.collapsed ul {
    max-height: 0;
}

/* NUEVO: Gira el ícono cuando el menú está colapsado */
.chapter-nav.collapsed #toggle-nav-btn svg {
    transform: rotate(-90deg);
}

.chapter-nav a {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-color);
    border-radius: 6px;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
    font-weight: 500;
}
.chapter-nav a:hover {
    background-color: #e9ecef;
    color: var(--text-color);
}
.chapter-nav a.active {
    background-color: var(--primary-color);
    color: var(--bg-white);
    font-weight: 700;
}

.chapter-title {
  display: block;
  width: 220px;
  max-width: 100%;
  line-height: 1.2;
  word-wrap: break-word;
  text-align: left;
}

.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin: 1.5rem 0;
    padding: 0 0.5rem;
}
.chapter-navigation .nav-link {
    font-weight: 600;
    text-decoration: none;
}
.chapter-navigation .nav-link.prev {
    text-align: left;
}
.chapter-navigation .nav-link.next {
    text-align: right;
}

/* --- ESTILOS DE COMPONENTES ADICIONALES --- */

/* Mapa */
#corpus-map-container {
    position: relative;
}
#corpus-map {
    height: 650px;
    width: 100%;
    background-color: var(--bg-light-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
#map-legend {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 800;
}
#map-legend ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
}
#map-legend li {
    margin-bottom: 0.25rem;
}

/* Modal */
.expand-icon {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
}
.expand-icon:hover {
    color: var(--primary-color);
}
.modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.modal-container.is-visible {
    display: flex;
    opacity: 1;
}
.modal-content {
    background-color: var(--bg-white);
    padding: 2rem 3rem;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    height: 80vh;
    position: relative;
    display: flex;
    flex-direction: column;
}
.modal-close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 2.5rem;
    line-height: 1;
    color: #aaa;
    cursor: pointer;
}
.modal-close-btn:hover {
    color: var(--text-color);
}
#modal-title {
    margin-top: 0;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}
#modal-body {
    overflow-y: auto;
    flex-grow: 1;
}
body.modal-open {
    overflow: hidden;
}

/* Sección Fuentes y Descargas */
.fuentes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 3rem;
}
.fuentes-grid h3, .fuentes-grid h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}
.fuentes-grid p {
    margin-top: 0.25rem;
    margin-bottom: 1rem;
}

/* Formulario de Contacto */
.contact-container {
    max-width: 600px;
    margin: 40px auto;
    padding: 30px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
#mailchimp-form-embed input[type="email"],
#mailchimp-form-embed input[type="text"] {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 5px;
}
#mailchimp-form-embed input[type="submit"] {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}
#mailchimp-form-embed input[type="submit"]:hover {
    background-color: #0056b3;
}
.contact-alternative {
    text-align: center;
    margin-top: 25px;
    font-size: 0.9em;
    color: #666;
}
.contact-alternative a {
    color: #007bff;
}

/* Galería de Visualizaciones */
.visualization-wrapper {
  max-width: 800px;
  margin: 2rem auto;
  padding: 1rem;
  background-color: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}
.responsive-iframe-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding-top: 125%;
}
.responsive-iframe-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* --- AJUSTES FINALES Y UNIFICADOS DE ESPACIADO --- */
/* CONSOLIDADO: Bloque único para evitar conflictos */
.site-header {
  margin-bottom: 0.5rem;
}
.libro-header-link,
.libro-contexto { /* Unificando con el nuevo breadcrumb */
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
  color: var(--text-color);
}
.page-content header {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.page-content h1 {
  font-size: 3rem; /* Restaurado desde el original */
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.page-content .subtitle {
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
  color: #666;
}

/* Botón Discord */
.discord-desktop-only {
    display: none;
}
@media screen and (min-width: 768px) {
    .discord-desktop-only {
        display: block;
    }
}

/* --- MEDIA QUERIES GLOBALES PARA RESPONSIVIDAD --- */
@media (max-width: 800px) {
  .info-grid,
  .fuentes-grid,
  .intro-grid {
    grid-template-columns: 1fr;
  }

  .info-grid > .info-container:nth-child(n + 5) {
    grid-column: auto;
  }

  .intro-right {
    margin-top: 2rem;
  }
  .intro-left h2 {
    font-size: 1.6rem;
  }

  .page-content h1 {
    font-size: 2.2rem; /* Ajuste para móviles */
  }
}