.gallery {
    background-color: transparent;
}

.gallery .section__title {
    font-size: clamp(2.5rem, 5.8vw, 3.25rem);
    font-weight: var(--font-weight-regular);
}

.gallery__grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2xl) var(--space-lg);
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-md);
}

.gallery__item {
    position: relative;
    cursor: pointer;
    display: block;
    flex: 0 0 auto;
    width: calc(33.333% - var(--space-lg));
    max-width: 320px;
    transition: transform var(--transition-normal), z-index 0s;
    color: var(--color-text-muted);
}

.gallery__item:nth-child(6n+1) { transform: rotate(-3deg); }
.gallery__item:nth-child(6n+2) { transform: rotate(2deg); }
.gallery__item:nth-child(6n+3) { transform: rotate(-1.5deg); }
.gallery__item:nth-child(6n+4) { transform: rotate(3deg); }
.gallery__item:nth-child(6n+5) { transform: rotate(-2deg); }
.gallery__item:nth-child(6n+6) { transform: rotate(1deg); }

.gallery__item:hover {
    transform: rotate(0deg) scale(1.05);
    z-index: 10;
}

.gallery__item::after {
    content: '';
    position: absolute;
    inset: -8px -8px -35px -8px;
    background-color: var(--color-bg-surface);
    z-index: -1;
    border-radius: 2px 6px 4px 5px / 5px 4px 6px 2px;
}

.gallery__item::before {
    content: '';
    position: absolute;
    inset: -8px -8px -35px -8px;
    border: 1px solid currentColor;
    border-radius: 2px 6px 4px 5px / 5px 4px 6px 2px;
    pointer-events: none;
    z-index: 3;
}

.gallery__item:nth-child(2n)::before,
.gallery__item:nth-child(2n)::after {
    border-radius: 4px 3px 6px 5px / 5px 6px 3px 4px;
}

.gallery__image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    transition: filter var(--transition-normal);
    filter: sepia(8%) contrast(95%) brightness(102%);
    position: relative;
    z-index: 1;
}

.gallery__item:hover .gallery__image {
    filter: sepia(0%) contrast(100%) brightness(100%);
}

.gallery__overlay {
    position: absolute;
    inset: 0;
    background: var(--color-primary);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition-fast);
    color: var(--color-bg-primary);
    z-index: 2;
}

.gallery__item:hover .gallery__overlay {
    opacity: 0.3;
}

.gallery__dots {
    display: none;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

.lightbox__content {
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 15px 15px 50px 15px;
    background: var(--color-bg-surface);
}

.lightbox__content::before {
    content: '';
    position: absolute;
    inset: -2px;
    border: 1px solid var(--color-text-muted);
    border-radius: 2px 6px 4px 5px / 5px 4px 6px 2px;
    pointer-events: none;
}

.lightbox__image {
    max-width: 100%;
    max-height: calc(85vh - 65px);
    object-fit: contain;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.lightbox__image.is-loaded {
    opacity: 1;
}

.lightbox__close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-bg-surface);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 10;
}

.lightbox__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-bg-surface);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 10;
}

.lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox__nav--prev {
    left: var(--space-md);
}

.lightbox__nav--next {
    right: var(--space-md);
}

.lightbox__counter {
    position: absolute;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    letter-spacing: 0.08em;
}

@media (max-width: 767px) {
    .gallery {
        overflow: hidden;
    }

    .gallery__grid {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: var(--space-md) 0;
        max-width: none;
        justify-content: flex-start;
    }

    .gallery__grid::-webkit-scrollbar {
        display: none;
    }

    .gallery__item {
        flex: 0 0 80% !important;
        width: 80% !important;
        max-width: 320px !important;
        margin: 0 var(--space-md) 45px var(--space-md) !important;
        scroll-snap-align: center;
        transform: rotate(0deg) !important;
    }

    .gallery__item:first-child {
        margin-left: var(--container-padding) !important;
        margin-bottom: 45px !important;
    }

    .gallery__item:last-child {
        margin-right: var(--container-padding) !important;
        margin-bottom: 45px !important;
    }

    .gallery__item:hover {
        transform: rotate(0deg) scale(1) !important;
    }

    .gallery__image {
        aspect-ratio: 1;
    }

    .gallery__overlay {
        display: none;
    }

    .gallery__dots {
        display: flex;
        justify-content: center;
        gap: var(--space-xs);
        margin-top: 0;
        padding: 0 var(--container-padding);
    }

    .gallery__dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        border: 1px solid var(--color-text-muted);
        background: transparent;
        cursor: pointer;
        padding: 0;
        transition: background var(--transition-fast);
    }

    .gallery__dot.is-active {
        background: var(--color-text-heading);
        border-color: var(--color-text-heading);
    }

    .lightbox__nav {
        width: 44px;
        height: 44px;
    }

    .lightbox__nav--prev {
        left: var(--space-xs);
    }

    .lightbox__nav--next {
        right: var(--space-xs);
    }

    .lightbox__close {
        top: var(--space-sm);
        right: var(--space-sm);
        width: 40px;
        height: 40px;
    }
}