/* ================================================
   GALERÍA ELEGANTE VERTICAL CON ROTACIÓN SUAVE
   ================================================ */

.galeria {
    --grid-gap: 1.5rem;
    --animation-duration: 0.8s;
    --rotation-duration: 1s;
    --animation-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    
    padding: 4rem 0;
    /* Fondo marmoleado elegante */
    background: 
        linear-gradient(135deg, 
            #fefefe 0%,
            #f8f8f8 25%,
            #f5f3f0 50%,
            #f2f0ed 75%,
            #f0ede8 100%
        ),
        radial-gradient(ellipse 600px 400px at 20% 30%, rgba(139, 115, 85, 0.03) 0%, transparent 60%),
        radial-gradient(ellipse 800px 300px at 80% 70%, rgba(139, 105, 20, 0.02) 0%, transparent 50%),
        radial-gradient(ellipse 400px 600px at 60% 10%, rgba(93, 78, 55, 0.025) 0%, transparent 45%),
        radial-gradient(ellipse 500px 350px at 90% 90%, rgba(107, 91, 71, 0.02) 0%, transparent 55%);
    
    position: relative;
    overflow: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Textura marmoleada adicional */
.galeria::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(45deg, transparent 40%, rgba(139, 115, 85, 0.008) 42%, transparent 44%),
        linear-gradient(-45deg, transparent 38%, rgba(139, 105, 20, 0.006) 40%, transparent 42%),
        linear-gradient(30deg, transparent 45%, rgba(93, 78, 55, 0.007) 47%, transparent 49%),
        radial-gradient(circle at 30% 40%, rgba(139, 115, 85, 0.015) 1px, transparent 1px),
        radial-gradient(circle at 70% 80%, rgba(139, 105, 20, 0.012) 1px, transparent 1px);
    background-size: 
        200px 200px,
        150px 150px,
        180px 180px,
        40px 40px,
        60px 60px;
    pointer-events: none;
    z-index: 0;
}

.galeria::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 50%, transparent 30%, rgba(254, 254, 254, 0.02) 70%);
    pointer-events: none;
    z-index: 0;
}

/* Header */
.galeria-header {
    text-align: center;
    margin-bottom: 4rem;
    position: relative;
    z-index: 1;
}

.galeria-header h2 {
    font-family: var(--font-script);
    font-size: clamp(2.5rem, 6vw, 4rem);
    color: var(--accent-beige);
    margin-bottom: 1rem;
    font-weight: 400;
    text-shadow: 0 2px 10px rgba(139, 115, 85, 0.1);
}

.galeria-subtitle {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-style: italic;
    font-weight: 300;
    opacity: 0.8;
}

.decorative-line {
    width: 80px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-beige), transparent);
    margin: 1.5rem auto;
    border-radius: 1px;
}

/* Contenedor principal de la galería */
.galeria-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--grid-gap);
    max-width: 500px;
    margin: 0 auto;
    padding: 0 2rem;
    position: relative;
    z-index: 1;
    min-height: 600px;
    justify-content: center;
}

/* Items de galería - Disposición vertical */
.galeria-item {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 4 / 5;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    box-shadow: 
        0 8px 32px rgba(139, 115, 85, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1);
    
    /* Performance optimizations */
    will-change: transform, opacity;
    transform: translateZ(0);
    
    /* Estados iniciales */
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    transition: all var(--rotation-duration) var(--animation-ease);
    
    /* Border sutil */
    border: 1px solid rgba(139, 115, 85, 0.1);
}

/* Animaciones de entrada */
.galeria-item.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.galeria-item.entering {
    animation: slideInUp var(--rotation-duration) var(--animation-ease) forwards;
}

.galeria-item.exiting {
    animation: slideOutDown var(--rotation-duration) var(--animation-ease) forwards;
}

/* Hover effects */
.galeria-item:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 
        0 16px 48px rgba(139, 115, 85, 0.25),
        0 4px 16px rgba(0, 0, 0, 0.15);
}

.galeria-item:active {
    transform: translateY(-2px) scale(1.01);
}

/* Imagen */
.galeria-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all var(--animation-duration) var(--animation-ease);
    filter: brightness(0.95) contrast(1.05) saturate(1.1);
}

.galeria-item:hover .galeria-image {
    transform: scale(1.05);
    filter: brightness(1) contrast(1.1) saturate(1.2);
}

/* Overlay */
.galeria-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(44, 44, 44, 0.7) 0%,
        rgba(44, 44, 44, 0.3) 50%,
        rgba(44, 44, 44, 0.8) 100%
    );
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all var(--animation-duration) var(--animation-ease);
    backdrop-filter: blur(2px);
}

.galeria-item:hover .galeria-overlay {
    opacity: 1;
}

.galeria-zoom-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(139, 115, 85, 0.95);
    color: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    transform: scale(0.7) rotate(-180deg);
    transition: all var(--animation-duration) var(--animation-ease);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.galeria-item:hover .galeria-zoom-icon {
    transform: scale(1) rotate(0deg);
}

/* Skeleton loading */
.galeria-item.loading {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.9) 25%,
        rgba(139, 115, 85, 0.1) 50%,
        rgba(255, 255, 255, 0.9) 75%
    );
    background-size: 200% 100%;
    animation: skeleton 2s ease-in-out infinite;
}

.galeria-item.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--accent-beige);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

/* Modal mejorado */
.galeria-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    backdrop-filter: blur(0px);
}

.galeria-modal[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    backdrop-filter: blur(10px);
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(44, 44, 44, 0.95);
    transition: opacity 0.4s ease;
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    z-index: 2;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.galeria-modal[aria-hidden="false"] .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.modal-close {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(139, 115, 85, 0.15);
    border: 2px solid var(--accent-beige);
    color: var(--accent-beige);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.modal-close:hover,
.modal-close:focus {
    background: var(--accent-beige);
    color: var(--bg-dark);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 4px 20px rgba(139, 115, 85, 0.4);
}

.modal-close svg {
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
}

.modal-image-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

#modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 8px 24px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
}

/* Navegación del modal mejorada */
.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(139, 115, 85, 0.15);
    border: 2px solid var(--accent-beige);
    color: var(--accent-beige);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    opacity: 0.8;
    backdrop-filter: blur(10px);
}

.modal-nav:hover,
.modal-nav:focus {
    background: var(--accent-beige);
    color: var(--bg-dark);
    opacity: 1;
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 4px 20px rgba(139, 115, 85, 0.4);
}

.modal-nav svg {
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
}

.modal-nav:hover svg {
    transform: scale(1.2);
}

.modal-prev {
    left: 2rem;
}

.modal-next {
    right: 2rem;
}

.modal-footer {
    text-align: center;
    margin-top: 1.5rem;
}

.modal-counter {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: rgba(44, 44, 44, 0.9);
    border: 2px solid var(--accent-beige);
    border-radius: 25px;
    color: var(--accent-beige);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Animaciones */
/* Animaciones mejoradas - más suaves y elegantes */
@keyframes slideInUp {
    0% {
        opacity: 0;
        transform: translateX(-100px) scale(0.8);
        filter: blur(5px);
    }
    50% {
        opacity: 0.7;
        transform: translateX(0) scale(1.05);
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
        filter: blur(0);
    }
}

@keyframes slideOutDown {
    0% {
        opacity: 1;
        transform: translateX(0) scale(1);
        filter: blur(0);
    }
    50% {
        opacity: 0.3;
        transform: translateX(100px) scale(0.9);
        filter: blur(3px);
    }
    100% {
        opacity: 0;
        transform: translateX(150px) scale(0.7);
        filter: blur(8px);
    }
}

/* Fade in/out mejorado para cambios de imagen */
@keyframes fadeOut {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1) rotateY(0deg);
        filter: brightness(1) blur(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-30px) scale(0.8) rotateY(-15deg);
        filter: brightness(0.5) blur(4px);
    }
}

@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.8) rotateY(15deg);
        filter: brightness(0.5) blur(4px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1) rotateY(0deg);
        filter: brightness(1) blur(0);
    }
}

/* Estados especiales para la rotación con nuevas clases */
.galeria-item.rotation-slide-out {
    animation: slideOutDown 0.3s cubic-bezier(0.4, 0.0, 0.6, 1) forwards;
}

.galeria-item.rotation-slide-in {
    animation: slideInUp 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.galeria-item.rotation-fade-out {
    animation: fadeOut 0.7s ease-out forwards;
}

.galeria-item.rotation-fade-in {
    animation: fadeIn 0.9s ease-out forwards;
}

/* Responsive */
@media (max-width: 480px) {
    .galeria {
        padding: 2rem 0;
    }
    
    .galeria-grid {
        padding: 0 1rem;
        gap: 1rem;
        max-width: 320px;
    }
    
    .galeria-item {
        aspect-ratio: 3 / 4;
        border-radius: 8px;
    }
    
    .modal-nav {
        width: 44px;
        height: 44px;
    }
    
    .modal-prev {
        left: 1rem;
    }
    
    .modal-next {
        right: 1rem;
    }
}

@media (min-width: 768px) {
    .galeria-grid {
        max-width: 500px;
    }
    
    .galeria-item {
        max-width: 450px;
    }
}

@media (min-width: 1024px) {
    .galeria-grid {
        max-width: 550px;
    }
    
    .galeria-item {
        max-width: 500px;
        aspect-ratio: 4 / 5;
    }
}

/* Accesibilidad */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Focus visible */
.galeria-item:focus,
.modal-close:focus,
.modal-nav:focus {
    outline: 3px solid var(--accent-beige);
    outline-offset: 3px;
}

/* Touch optimizations */
@media (pointer: coarse) {
    .galeria-overlay {
        opacity: 0.3;
    }
    
    .galeria-item:active .galeria-overlay {
        opacity: 1;
    }
    
    .modal-nav {
        opacity: 1;
        background: rgba(139, 115, 85, 0.25);
    }
    
    .galeria-zoom-icon {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
}

/* Reducir animaciones si se prefiere */
@media (prefers-reduced-motion: reduce) {
    .galeria-item,
    .galeria-image,
    .galeria-overlay,
    .galeria-zoom-icon,
    .galeria-modal,
    .modal-close,
    .modal-nav,
    .modal-content {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}