.gallery {
    padding: 60px 0;
    background: #fff;
}

.gallery-subtitle {
    text-align: center;
    font-size: 18px;
    color: #666;
    margin-bottom: 30px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.gallery-masonry {
    columns: 4;
    column-gap: 12px;
    margin-top: 40px;
}

/* Специальные стили для динамической галереи */
.gallery-masonry .gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

@media (max-width: 1200px) {
    .gallery-masonry {
        columns: 3;
    }
}

@media (max-width: 768px) {
    /* Старые стили для статической галереи */
    .gallery-masonry.static {
        display: grid;
        grid-template-columns: 1fr 1fr; /* Left and right columns */
        grid-template-rows: repeat(3, auto); /* Three rows for right side */
        gap: 12px;
        max-height: 100vh; /* Fit within viewport height */
        overflow: hidden;
        margin-top: 0; /* Remove margin for tighter fit */
    }
    .gallery-masonry.static .gallery-item:nth-child(1) {
        grid-column: 1 / 2;
        grid-row: 1 / 4; /* First image spans three rows on left */
        max-height: 100vh; /* Full height for left image */
    }
    .gallery-masonry.static .gallery-item:nth-child(2) {
        grid-column: 2 / 3;
        grid-row: 1 / 2; /* Second image in top-right */
        max-height: 33.33vh; /* 1/3 height for right images */
    }
    .gallery-masonry.static .gallery-item:nth-child(3) {
        grid-column: 2 / 3;
        grid-row: 2 / 3; /* Third image in middle-right */
        max-height: 33.33vh; /* 1/3 height for right images */
    }
    .gallery-masonry.static .gallery-item:nth-child(4) {
        grid-column: 2 / 3;
        grid-row: 3 / 4; /* Fourth image in bottom-right */
        max-height: 33.33vh; /* 1/3 height for right images */
        position: relative;
    }
    .gallery-masonry.static .gallery-item:nth-child(n+5) {
        display: none; /* Hide images beyond the fourth */
    }
    .gallery-masonry.static .gallery-item img {
        object-fit: cover; /* Scale images to fit */
        height: 100%; /* Fill container height */
        width: 100%;
    }
    .gallery-masonry.static .gallery-item:nth-child(4)::after {
        content: 'Посмотреть больше';
        /* position: absolute; */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        border-radius: var(--border-radius);
        opacity: 1;
        transition: opacity 0.3s ease;
    }
    .gallery-masonry.static .gallery-item:nth-child(4):hover::after {
        opacity: 0.8;
    }
    .gallery-masonry.static.show-all {
        display: block; /* Revert to block for full gallery */
        columns: 1; /* Single column for all images */
        max-height: none; /* Remove height restriction */
    }
    .gallery-masonry.static.show-all .gallery-item {
        display: block;
        max-height: none; /* Allow natural height */
    }
    .gallery-masonry.static.show-all .gallery-item img {
        height: auto; /* Restore natural image height */
    }
    .gallery-masonry.static.show-all .gallery-item:nth-child(4)::after {
        display: none; /* Hide overlay when showing all */
    }

    /* Стили для динамической галереи на мобильных */
    .gallery-masonry.dynamic {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-top: 20px;
    }

    .gallery-masonry.dynamic .gallery-item {
        margin-bottom: 0;
    }

    .gallery-masonry.dynamic .gallery-item img {
        width: 100%;
        height: 200px;
        object-fit: cover;
    }
}

@media (max-width: 480px) {
    .gallery-masonry {
        grid-template-columns: 1fr 1fr;
        gap: 8px; /* Smaller gap for smaller screens */
    }
}

.gallery-item {
    break-inside: avoid;
    margin-bottom: 12px;
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: #f5f5f5;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(124, 58, 237, 0.15);
}

.gallery-item img {
    width: 100%;
    display: block;
    border-radius: var(--border-radius);
    transition: transform 0.3s ease;
}

.gallery-item:hover img {
    transform: scale(1.02);
}

.gallery-item::after {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(124, 58, 237, 0.1), rgba(124, 58, 237, 0.05));
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: var(--border-radius);
}

.gallery-item:hover::after {
    opacity: 1;
}

.fullscreen-gallery {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.fullscreen-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.fullscreen-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
    transition: opacity 0.3s ease;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.close-fullscreen {
    color: #fff;
    font-size: 32px;
    position: absolute;
    top: 30px;
    right: 30px;
    cursor: pointer;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 3001;
}

.close-fullscreen:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    user-select: none;
    z-index: 3001;
}

.nav-arrow:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.nav-prev {
    left: 30px;
}

.nav-next {
    right: 30px;
}

.image-counter {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    backdrop-filter: blur(10px);
    z-index: 3001;
}

.loading {
    opacity: 0.5;
}