/* RESET + VARIABLES MEJORADAS RESPONSIVE (basado en diseño de Al-Ándalus) */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif;
    background-color: #ffffff;
    color: #1f2a3e;
    line-height: 1.7;
}

/* Contenedor principal fluido con mejor responsive */
.ds-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

@media (min-width: 768px) {
    .ds-container {
        padding: 2rem 2rem 5rem;
    }
}

@media (min-width: 1200px) {
    .ds-container {
        padding: 2rem 2.5rem 5rem;
    }
}

/* ============================================
   HEADER STICKY CON OCULTAMIENTO EN MÓVIL
   ============================================ */
.ds-header {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid #eaeef2;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Ocultar header al hacer scroll hacia abajo en móviles */
@media (max-width: 1023px) {
    .ds-header.hidden-header {
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
    }
    .ds-header.visible-header {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
}

.logo-area {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-weight: 700;
    font-size: clamp(1.1rem, 4vw, 1.4rem);
    letter-spacing: -0.3px;
    color: #0a1927;
}

.logo-area i {
    font-size: 1.6rem;
    color: #b8865b;
}

.badge-period {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    background: #f2f4f7;
    padding: 0.2rem 0.7rem;
    border-radius: 30px;
    color: #4a5b6e;
    font-weight: 500;
    white-space: nowrap;
}

/* Menú horizontal mini - mejor scroll en móvil */
.toc-mini {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    background: #f8fafc;
    padding: 0.6rem 1rem;
    border-radius: 48px;
    font-size: 0.8rem;
    overflow-x: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.toc-mini a {
    text-decoration: none;
    color: #3c5a6f;
    font-weight: 500;
    transition: color 0.2s;
    white-space: nowrap;
    padding: 0.1rem 0;
}

.toc-mini a:hover {
    color: #b8865b;
}

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.ds-main-flex {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

@media (min-width: 1024px) {
    .ds-main-flex {
        flex-direction: row;
        gap: 3rem;
        position: relative;
    }
    .content-main {
        flex: 1;
        min-width: 0;
    }
    .index-rail {
        display: block;
        width: 280px;
        flex-shrink: 0;
        position: sticky;
        top: 6rem;
        align-self: start;
        background: #fdfdfd;
        border-left: 1px solid #eef2f5;
        padding-left: 2rem;
        margin-top: 0.5rem;
    }
}

@media (max-width: 1023px) {
    .index-rail {
        display: none;
    }
}

/* ============================================
   RAIL TOC (índice lateral)
   ============================================ */
.index-rail .toc-title-rail {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
    color: #8895a3;
    margin-bottom: 1.2rem;
}

.rail-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rail-toc-list li {
    margin-bottom: 0.7rem;
    font-size: 0.85rem;
    line-height: 1.3;
}

.rail-toc-list a {
    text-decoration: none;
    color: #2c3e4e;
    font-weight: 450;
    transition: color 0.2s, padding-left 0.2s;
    display: block;
    padding: 0.2rem 0;
}

.rail-toc-list a:hover {
    color: #b8865b;
    padding-left: 4px;
}

.rail-toc-list .toc-h2 {
    font-weight: 700;
    margin-top: 0.2rem;
}

.rail-toc-list .toc-h3 {
    padding-left: 0.85rem;
    font-size: 0.8rem;
    color: #5a6e7e;
}

/* ============================================
   TIPOGRAFÍA Y CONTENIDO
   ============================================ */
.content-main h1 {
    font-size: clamp(1.8rem, 6vw, 3.2rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    background: linear-gradient(135deg, #1c2e3a 0%, #8b5a2b 100%);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    margin-bottom: 0.75rem;
}

.section-sub {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #b8865b;
    display: inline-block;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: clamp(1.4rem, 4vw, 1.9rem);
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #f0e7db;
    letter-spacing: -0.3px;
}

h3 {
    font-size: clamp(1.2rem, 3.5vw, 1.5rem);
    font-weight: 600;
    margin-top: 1.8rem;
    margin-bottom: 0.75rem;
    color: #2b4b3c;
}

p {
    margin-bottom: 1.2rem;
    color: #2c3e4e;
    font-size: 1rem;
}

@media (min-width: 768px) {
    p {
        font-size: 1.02rem;
    }
}

.critical-note {
    background: #fef9ef;
    border-left: 5px solid #b8865b;
    padding: 1rem 1.2rem;
    margin: 1.5rem 0;
    border-radius: 20px;
    font-size: 0.92rem;
    color: #3b4f5f;
}

.highlight-box {
    background: #eef3fa;
    border-left: 5px solid #1a4d8c;
    padding: 1rem 1.2rem;
    margin: 1.5rem 0;
    border-radius: 20px;
    font-size: 0.92rem;
    color: #1f2a3e;
}

.card-hermitage {
    background: #ffffff;
    border: 1px solid #e7edf2;
    border-radius: 24px;
    padding: 1rem;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    height: 100%;
}

.row-custom {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    margin: 1.5rem 0;
}

.col-card {
    flex: 1 1 calc(50% - 1.2rem);
    min-width: 200px;
}

@media (max-width: 640px) {
    .col-card {
        flex: 1 1 100%;
    }
    html {
        scroll-padding-top: 140px;
        /* menos margen en móvil porque header es más pequeño */
    }
}

hr {
    margin: 2.5rem 0;
    border-color: #e2e8f0;
}

/* ============================================
   BOTÓN FLOTANTE
   ============================================ */
.btnSubir {
    position: fixed;
    bottom: 1.5rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid #d4dce4;
    padding: 0.5rem 1rem;
    border-radius: 40px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #2c3e4e;
    cursor: pointer;
    transition: all 0.25s ease;
    z-index: 99;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.btnSubir:hover {
    background: #b8865b;
    color: white;
    border-color: #b8865b;
}

@media (min-width: 640px) {
    .btnSubir {
        bottom: 2rem;
        right: 2rem;
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
}

/* ============================================
   FOOTER
   ============================================ */
footer {
    margin-top: 3rem;
    text-align: center;
    font-size: 0.75rem;
    color: #7f8c8d;
    border-top: 1px solid #edf2f7;
    padding-top: 2rem;
}

a {
    text-decoration: none;
}

.toc-mini::-webkit-scrollbar {
    height: 3px;
}

.toc-mini::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 10px;
}

.toc-mini::-webkit-scrollbar-thumb {
    background: #b8865b;
    border-radius: 10px;
}

img {
    max-width: 100%;
    height: auto;
}

blockquote {
    font-style: italic;
    border-left: 4px solid #b8865b;
    padding-left: 1.2rem;
    margin: 1.5rem 0;
    color: #4a6272;
}

.sources ul {
    margin-bottom: 1rem;
    padding-left: 1.2rem;
}

.sources li {
    margin-bottom: 0.3rem;
}

.footnote {
    font-size: 0.8rem;
    color: #6c7a89;
    border-top: 1px dashed #e2e8f0;
    padding-top: 1rem;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1rem 0 1.5rem;
    font-size: 0.8rem;
    color: #6c7a89;
    border-bottom: 1px solid #eef2f5;
    padding-bottom: 0.75rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: #f0f4f9;
    padding: 0.3rem 1rem;
    border-radius: 40px;
    font-size: 0.8rem;
    color: #2c3e4e;
    margin-bottom: 1rem;
    transition: background 0.2s;
}

.back-link:hover {
    background: #e2e8f0;
    color: #b8865b;
}

/* ============================================
   IMAGEN - FIGURE (CORREGIDO PARA CENTRAR)
   ============================================ */
.figure-bio {
    margin: 1.8rem auto 2rem auto;
    text-align: center;
    background: #faf8f2;
    border-radius: 12px;
    padding: 1rem 1rem 0.5rem 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    max-width: 100%;
}

.figure-bio img {
    display: block;
    max-width: auto;
    height: auto;
    margin-left: auto;
    margin-right: auto;
    border-radius: 8px;
    border: 1px solid #e2ddd0;
    background: #ffffff;
}

.figure-bio figcaption {
    font-size: 0.9rem;
    color: #4a4a3a;
    margin-top: 0.6rem;
    font-style: italic;
    letter-spacing: 0.01em;
    border-top: 1px solid #e2ddd0;
    padding-top: 0.6rem;
}

.figure-bio figcaption i {
    margin-right: 6px;
    color: #8a7a5a;
}

@media (max-width: 640px) {
    .figure-bio img {
        max-width: 80%;
    }
}

@media (max-width: 480px) {
    .figure-bio img {
        max-width: 100%;
    }
}