/* ==========================================================================
   INFINITE SCROLL HORIZONTAL COLLAGE GALLERY
   ========================================================================== */

/* Main Gallery Wrapper */
.custom-gallery-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    padding: 20px 0;
    overflow: hidden;
}

/* Scroll Window Window Container */
.custom-gallery-scroll {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar Firefox */
    scroll-behavior: smooth;
}

.custom-gallery-scroll::-webkit-scrollbar {
    display: none; /* Hide scrollbar Chrome/Safari */
}

/* Track configured as a 2-Row CSS Grid Collage */
.gallery-track {
    display: grid;
    grid-template-rows: repeat(2, 170px); /* Two 170px rows */
    grid-auto-columns: minmax(200px, auto); /* Dynamic column sizing */
    grid-auto-flow: column dense; /* Auto-packs items into empty slots */
    gap: 12px;
    width: max-content;
    will-change: transform;
}

/* Infinite Marquee Animation Driven by JS Class */
.gallery-track.is-animating {
    animation: infiniteCollageScroll 35s linear infinite;
}

@keyframes infiniteCollageScroll {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-50%); /* Moves exactly halfway across duplicated track */
    }
}

/* Base Collage Item */
.gallery-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 12px;
}

/* Asymmetrical Collage Pattern Rules (Repeats every 5 items) */
.gallery-item:nth-child(5n + 1) {
    grid-row: span 2;  /* Tall image spanning both rows */
    width: 270px;
}

.gallery-item:nth-child(5n + 2) {
    grid-row: span 1;  /* Top row item */
    width: 210px;
}

.gallery-item:nth-child(5n + 3) {
    grid-row: span 1;  /* Bottom row item */
    width: 230px;
}

.gallery-item:nth-child(5n + 4) {
    grid-row: span 2;  /* Wide feature square spanning both rows */
    width: 340px;
}

.gallery-item:nth-child(5n + 5) {
    grid-row: span 1;  /* Compact row filler */
    width: 190px;
}

/* Navigation Arrow Buttons */
.gallery-scroll-btn {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: #1e40af;
    color: #ffffff;
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.gallery-scroll-btn:hover {
    background: #1d4ed8;
    transform: scale(1.08);
}

.gallery-scroll-btn:active {
    transform: scale(0.95);
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .gallery-track {
        grid-template-rows: repeat(2, 130px); /* Slightly shorter row height for mobile */
        gap: 8px;
    }

    .gallery-item:nth-child(5n + 1) { width: 190px; }
    .gallery-item:nth-child(5n + 2) { width: 150px; }
    .gallery-item:nth-child(5n + 3) { width: 160px; }
    .gallery-item:nth-child(5n + 4) { width: 240px; }
    .gallery-item:nth-child(5n + 5) { width: 130px; }

    .gallery-scroll-btn {
        display: none; /* Hide arrow buttons on touch devices */
    }
}