* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Georgia', 'Times New Roman', serif;
}

#map {
    width: 100%;
    height: 100%;
    font-family: 'Georgia', 'Times New Roman', serif;
}

/* --- TIPOGRAFÍA BASE --- */
.text-content p {
    margin-bottom: 15px;
    text-align: center;
    /* [Optimizado] Una sola sombra más nítida es mucho más performante y mantiene la legibilidad. */
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.text-content p:last-child {
    margin-bottom: 0;
}

/* --- CONTROLES FIJOS (UNIFICADOS) --- */
/* Control de Playback y Audio Toggle comparten ahora un estilo base optimizado */
.playback-control,
.audio-toggle-control {
    position: fixed;
    z-index: 1000;
    background: rgba(26, 26, 26, 0.9);
    border: 1px solid rgba(245, 197, 24, 0.5); /* Borde más sutil */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); /* Sombra más simple */
    /* [Optimizado] ELIMINADO backdrop-filter: blur() por completo en controles fijos. 
       Es la principal causa de lag en móviles. */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f5c518;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; /* Transición solo de colores, mucho más rápida */
}

/* Estilos específicos de Playback */
.playback-control {
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 25px;
    padding: 6px;
    gap: 4px;
    width: auto;
    height: auto;
}

.playback-control button {
    width: 40px;
    height: 40px;
    padding: 0;
    background: #1a1a1a;
    color: inherit;
    border: 2px solid rgba(245, 197, 24, 0.3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; /* [Optimizado] Sin transform */
}

.playback-control button:hover {
    background: #f5c518;
    color: #111111;
    border-color: #f5c518;
    /* [Optimizado] Quitamos box-shadow y transform en hover */
}

/* Estilos específicos de Audio Toggle */
.audio-toggle-control {
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
}

.audio-toggle-control:hover {
    background: #262626;
    /* [Optimizado] Sin transform: scale */
}

.audio-toggle-control.off {
    border-color: #666;
    color: #888;
}

/* --- CONTROL DE OPACIDAD (ABSTENERSE DE USAR BLUR SI ES POSIBLE) --- */
.opacity-control {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(26, 26, 26, 0.9);
    padding: 10px 20px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #f5c518;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6); /* Sombra menos difusa */
    font-family: inherit;
    /* [Optimizado] ELIMINADO backdrop-filter: blur() */
}

.opacity-control label {
    color: #e8e8e8;
    font-size: 14px;
    white-space: nowrap;
    user-select: none;
    letter-spacing: 0.3px;
}

.opacity-control input[type="range"] {
    width: 120px; /* Ligeramente más pequeño para ahorrar layout */
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(245, 197, 24, 0.25);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.opacity-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #f5c518;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #1a1a1a;
}

.opacity-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #f5c518;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #1a1a1a;
}

.opacity-control .value {
    color: #f5c518;
    font-size: 14px;
    font-weight: bold;
    min-width: 42px;
    text-align: center;
    letter-spacing: 0.3px;
}

/* ==================================================================
   POPUP : LA OPTIMIZACIÓN CLAVE ESTÁ AQUÍ
   ================================================================== */
.leaflet-popup-content-wrapper {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    color: #ffffff;
    border: none !important;
    border-radius: 0;
    box-shadow: none !important;
    overflow: visible !important;
    font-family: inherit;
    pointer-events: auto; /* Asegura que los clics funcionen */
}

.leaflet-popup-content {
    overflow: visible !important;
    margin: 0 !important;
    font-family: inherit;
    width: auto !important;
    min-width: 420px;
    max-width: 550px;
    /* [Optimización CRÍTICA] Promocionar a su propia capa GPU para aislar el repintado */
    will-change: transform;
    transform: translateZ(0);
}

.leaflet-popup-tip {
    display: none !important;
}

.leaflet-popup-close-button {
    display: none !important;
}

.leaflet-popup-close-button:hover {
    color: #fff !important;
    text-shadow: 0 2px 4px rgba(245, 197, 24, 0.6); /* [Optimizado] */
}

/* Contenedor principal del popup */
.popup-nav-wrapper {
    position: relative;
    overflow: visible;
    width: 100%;
    font-family: inherit;
    padding: 0;
    background: transparent;
    transform: translateZ(0); /* [Optimización] */
}

/* Título superpuesto - Solo texto flotante */
.popup-titulo-superpuesto {
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    color: #f5c518;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    padding: 0;
    white-space: nowrap;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9); /* [Optimizado] */
    line-height: 1;
    background: transparent;
    border: none;
}

/* Contenido del popup */
.popup-content {
    width: 100%;
    font-family: inherit;
    color: #ffffff;
    padding: 30px 20px 20px 20px;
    overflow: visible;
    background: transparent;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8); /* [Optimizado] Sombras unificadas y simples */
}

/* ===== ESTILOS BASE UNIFICADOS PARA TODAS LAS FLECHAS ===== */
.popup-nav-arrow,
.carousel-arrow {
    position: absolute;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease; /* [Optimizado] Sin transform */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); /* Menos difusa */
    padding: 0;
    padding-bottom: 2px;
    background: rgba(0, 0, 0, 0.6);
    color: #f5c518;
    border: 1px solid rgba(245, 197, 24, 0.6); /* Menos grosor de borde */
    pointer-events: auto;
    /* [Optimizado] ELIMINADO backdrop-filter: blur() */
}

.popup-nav-arrow:hover,
.carousel-arrow:hover {
    background: rgba(245, 197, 24, 0.3); /* Fondo más sutil */
    border-color: #f5c518;
    color: #fff;
}

/* ===== FLECHAS DE NAVEGACIÓN ENTRE POPUPS ===== */
.popup-nav-arrow {
    top: 50%;
    z-index: 15;
    width: 36px;
    height: 36px;
    font-size: 20px;
    transform: translateY(-50%);
}

.popup-nav-left {
    left: -10px;
}
.popup-nav-right {
    right: -10px;
}

/* ===== CARRUSEL DE IMÁGENES ===== */
.carousel-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    border-radius: 8px;
    font-family: inherit;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7); /* Sombra más simple */
    transform: translateZ(0); /* [Optimización] */
}

.carousel-container {
    position: relative;
    width: 100%;
    height: 230px;
    overflow: hidden;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

.carousel-container img {
    width: 100%;
    height: 230px;
    object-fit: cover;
    display: none;
    border-radius: 8px;
}

.carousel-container img.active {
    display: block;
}

/* Flechas del carrusel */
.carousel-arrow {
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.carousel-arrow-left { left: 8px; }
.carousel-arrow-right { right: 8px; }

/* Títulos de año en imágenes */
.image-year-title {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1.5px;
    z-index: 10;
    pointer-events: none;
    font-family: inherit;
    border: 1px solid rgba(245, 197, 24, 0.4);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    /* [Optimizado] ELIMINADO backdrop-filter */
}

/* Texto del popup */
.text-content {
    font-family: inherit;
    font-size: 14px;
    line-height: 1.8;
    color: #ffffff;
    background: transparent;
    overflow-y: visible;
    word-wrap: break-word;
    letter-spacing: 0.4px;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8); /* [Optimizado] */
}

/* ===== FRASE DESTACADA ===== */
.popup-quote {
    color: #f5c518;
    font-style: italic;
    font-size: 16px;
    line-height: 1.7;
    margin-bottom: 20px;
    padding: 0;
    border: none;
    background: transparent;
    letter-spacing: 0.5px;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9); /* [Optimizado] */
}

/* ===== YOUTUBE AUDIO OCULTO ===== */
.youtube-audio-hidden {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 1px;
    height: 1px;
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
}

/* ===== FLECHAS DESHABILITADAS ===== */
.popup-nav-arrow.disabled,
.popup-nav-arrow:disabled {
    opacity: 0.15;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===== ESTILOS DEL MODAL DE IMAGEN (OPTIMIZADOS) ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    /* [Optimización CRÍTICA] 
       Si el modal sigue dando lag AL ABRIRSE, comenta o elimina la siguiente línea.
       La dejamos porque es una pantalla completa estática, no de scroll continuo. */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    font-family: inherit;
    will-change: opacity, visibility; /* Avisa al navegador del cambio */
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-container {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    cursor: default;
    animation: modalFadeIn 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateZ(0); /* [Optimización] */
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        /* [Optimizado] Mantén las animaciones de la GPU simples */
        transform: scale(0.98) translateZ(0);
    }
    to {
        opacity: 1;
        transform: scale(1) translateZ(0);
    }
}

.modal-image-wrapper {
    position: relative;
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8), 0 0 0 1px #f5c518; /* Borde más fino, sombra más simple */
    background: #1a1a1a;
}

.modal-image-wrapper img {
    display: block;
    max-width: 90vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
}

.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid #f5c518;
    color: #f5c518;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease; /* [Optimizado] */
    z-index: 10;
    font-family: inherit;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.modal-close-btn:hover {
    background: #333333;
}

.modal-year-badge {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(26, 26, 26, 0.9);
    color: #f5c518;
    padding: 6px 20px;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 2px;
    z-index: 10;
    border: 1px solid rgba(245, 197, 24, 0.4);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

/* Flechas independientes para el modal */
.modal-nav-btn {
    position: fixed !important;
    top: 50% !important;
    width: 50px !important;
    height: 50px !important;
    border-radius: 50% !important;
    background: rgba(26, 26, 26, 0.95) !important;
    border: 1px solid #f5c518 !important; /* [Optimizado] */
    color: #f5c518 !important;
    font-size: 26px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10000 !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.7) !important;
    padding: 0 !important;
    font-family: inherit !important;
    transform: translateY(-50%) !important;
    pointer-events: auto !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.2s ease, visibility 0.2s ease, background-color 0.2s ease !important; /* [Optimizado] */
}

.modal-overlay.active ~ .modal-nav-btn {
    opacity: 1 !important;
    visibility: visible !important;
}

.modal-nav-prev { left: 30px !important; }
.modal-nav-next { right: 30px !important; }

.modal-nav-btn:hover {
    background: #333333 !important;
}

.modal-caption {
    color: #e8e8e8;
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

/* ===== RESPONSIVE ===== */
/* [Optimizado] Aplica los mismos principios de simplificación a los media queries */
@media (max-width: 768px) {
    .leaflet-popup-content {
        min-width: 320px;
        max-width: 420px;
    }

    .popup-content { padding: 25px 15px 15px 15px; }
    .popup-titulo-superpuesto { font-size: 16px; }
    .popup-nav-arrow { width: 32px; height: 32px; font-size: 18px; }
    .carousel-container, .carousel-container img { height: 200px; }
    .carousel-arrow { width: 28px; height: 28px; }
    .audio-toggle-control { width: 40px; height: 40px; font-size: 18px; }
    .playback-control button { width: 36px; height: 36px; }

    .modal-nav-btn { width: 42px !important; height: 42px !important; font-size: 22px !important; }
    .modal-nav-prev { left: 15px !important; }
    .modal-nav-next { right: 15px !important; }
    .modal-year-badge { font-size: 16px; }
    .modal-close-btn { width: 36px; height: 36px; }
}

@media (max-width: 480px) {
    .leaflet-popup-content {
        min-width: 280px;
        max-width: 340px;
    }

    .popup-content { padding: 22px 12px 12px 12px; }
    .popup-titulo-superpuesto { font-size: 14px; }
    .popup-nav-arrow { width: 28px; height: 28px; font-size: 16px; }
    .carousel-container, .carousel-container img { height: 170px; }
    .carousel-arrow { width: 24px; height: 24px; }
    .opacity-control input[type="range"] { width: 70px; }
    .playback-control button { width: 32px; height: 32px; }

    .modal-nav-btn { width: 36px !important; height: 36px !important; font-size: 18px !important; }
    .modal-nav-prev { left: 10px !important; }
    .modal-nav-next { right: 10px !important; }
    .modal-year-badge { font-size: 14px; }
    .modal-close-btn { width: 32px; height: 32px; }
}