.gallery {
    padding: 2rem;
    min-height: 100vh;
    perspective: 1000px;
    overflow: hidden;
}

.gallery-mosaic {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: minmax(200px, auto);
    gap: 1.5rem;
    padding: 2rem;
    transform-style: preserve-3d;
}

.gallery-item {
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}

.gallery-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    z-index: 1;
    transition: opacity 0.3s ease;
}

.gallery-item:hover {
    transform: translateZ(30px) rotateX(5deg) rotateY(5deg);
    box-shadow: 0 25px 45px rgba(0,0,0,0.4);
}

.gallery-item.featured {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-item.tall {
    grid-row: span 2;
}

/* Wide gallery item that spans the full remaining width */
.gallery-item.wide {
    grid-column: span 3;
}

/* Ensure proper rendering on different screen sizes */
@media (max-width: 992px) {
    .gallery-item.wide {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .gallery-item.wide {
        grid-column: span 1;
    }
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.1);
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    filter: brightness(0.9);
}

.gallery-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, 
        rgba(0,0,0,0.9) 0%,
        rgba(0,0,0,0.5) 30%,
        transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 2rem;
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.gallery-item:hover .gallery-overlay {
    transform: translateY(0);
}

.gallery-item:hover img {
    transform: scale(1);
    filter: brightness(1.1);
}

.gallery-title {
    color: #fff;
    font-size: 1.5rem;
    font-weight: 600;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease 0.1s;
}

.gallery-description {
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease 0.2s;
}

.gallery-item:hover .gallery-title,
.gallery-item:hover .gallery-description {
    opacity: 1;
    transform: translateY(0);
}

.gallery-expand {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: white;
    background: rgba(255,255,255,0.2);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
}

.gallery-item:hover .gallery-expand {
    opacity: 1;
    transform: scale(1);
}

.gallery-expand:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* Modal mejorado */
.gallery-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    padding: 2rem;
    backdrop-filter: blur(10px);
}

.modal-content {
    max-width: 90%;
    max-height: 90vh;
    margin: auto;
    display: block;
    animation: zoomIn 0.3s ease;
    border-radius: 20px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.5);
}

.modal-caption {
    color: white;
    text-align: center;
    padding: 1rem;
}

.modal-close {
    position: absolute;
    right: 2rem;
    top: 2rem;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1001;
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 1rem;
    transition: all 0.3s ease;
}

.modal-nav.prev { left: 2rem; }
.modal-nav.next { right: 2rem; }

.modal-nav:hover {
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 1200px) {
    .gallery-mosaic {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .gallery-mosaic {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .gallery-item {
        min-height: 250px;
    }

    .gallery-overlay {
        /* Mostrar overlay por defecto en móvil */
        bottom: 0;
        height: auto;
        background: linear-gradient(to top, 
            rgba(0,0,0,0.9) 0%,
            rgba(0,0,0,0.5) 50%,
            transparent 100%);
        padding: 1rem;
    }

    .gallery-title {
        font-size: 1.2rem;
        opacity: 1;
        transform: translateY(0);
    }

    .gallery-expand {
        opacity: 1;
        transform: translateY(0);
        top: 0.5rem;
        right: 0.5rem;
    }

    .gallery-item.large,
    .gallery-item.vertical,
    .gallery-item.horizontal {
        grid-column: 1;
        grid-row: auto;
    }

    /* Mejorar interacción táctil */
    .gallery-item:hover {
        transform: none;
    }

    .modal-nav {
        font-size: 1.5rem;
        padding: 0.5rem;
    }

    .modal-nav.prev { left: 0.5rem; }
    .modal-nav.next { right: 0.5rem; }

    .modal-close {
        right: 1rem;
        top: 1rem;
    }
}

@media (max-width: 480px) {
    .gallery {
        padding: 2rem 1rem;
    }

    .gallery-mosaic {
        padding: 0.5rem;
    }

    .gallery-item {
        min-height: 200px;
    }

    .gallery-title {
        font-size: 1.1rem;
    }
}

@keyframes floatAnimation {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Efectos de animación adicionales */
@keyframes shimmer {
    0% {
        background-position: -100% 0;
    }
    100% {
        background-position: 100% 0;
    }
}
