.gallery {
    padding: 24px 16px;
    max-width: calc(300px * 4 + 12px * 3);
    margin: 0 auto;
    box-sizing: border-box;
}

.gallery + .gallery {
    margin-top: 48px;
}

.gallery__title {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 600;
    color: #222;
}

.gallery__viewport {
    position: relative;
}

.gallery__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 300px));
    grid-template-rows: repeat(2, auto);
    gap: 12px;
    justify-content: center;
}

.gallery__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    text-decoration: none;
    color: inherit;
    user-select: none;
}

.gallery__item:focus-visible {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
    border-radius: 8px;
}

.gallery__item:hover .gallery__item-caption {
    color: #000;
}

.gallery__item-media {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 8px;
    background: #ddd;
}

.gallery__item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
    user-drag: none;
}

.gallery__item-caption {
    width: 100%;
    margin: 8px 0 0;
    font-size: 1rem;
    font-weight:bold;
    line-height: 1.4;
    color: #333;
    text-align: center;
}

.gallery__item-caption2 {
    width: 100%;
    margin: 8px 0 0;
    font-size: 0.875rem;
    line-height: 1.4;
    color: #333;
    text-align: center;
}

.gallery__nav {
    display: none;
}

/* Мобильная версия */
@media (max-width: 768px) {
    .gallery__viewport {
        padding: 0 40px;
    }

    .gallery__grid {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 12px;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        cursor: grab;
        touch-action: none;
    }

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

    .gallery__grid.is-dragging {
        scroll-snap-type: none;
        scroll-behavior: auto;
        cursor: grabbing;
    }

    .gallery__item {
        flex: 0 0 calc(50% - 6px);
        align-items: center;
        scroll-snap-align: start;
        -webkit-user-drag: none;
        user-drag: none;
    }

    .gallery__item-media {
        width: 100%;
    }

    .gallery__nav {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: calc((100vw - 92px) / 4);
        transform: translateY(-50%);
        z-index: 2;
        width: 36px;
        height: 36px;
        padding: 0;
        border: none;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        color: #222;
        cursor: pointer;
        transition: opacity 0.2s, background 0.2s;
    }

    .gallery__nav:hover:not(:disabled) {
        background: #fff;
    }

    .gallery__nav:disabled {
        opacity: 0.35;
        cursor: default;
    }

    .gallery__nav--prev {
        left: 0;
    }

    .gallery__nav--next {
        right: 0;
    }

    .gallery__nav svg {
        display: block;
        width: 20px;
        height: 20px;
    }
}