.xd-image-collage {
    width: 100%;
    background: var(--xd-ic-bg, #f1ecf6);
    padding: 0;
    position: relative;
}

.xd-image-collage::before {
    content: none;
}

.xd-image-collage__grid {
    width: 100%;
    max-width: none;
    margin: 0;
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 128px;
    gap: 6px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.xd-image-collage__grid.gap-small {
    gap: 10px;
}

.xd-image-collage__grid.gap-large {
    gap: 10px;
}

.xd-image-collage__item {
    position: relative;
    overflow: hidden;
    border-radius: 0;
    grid-column: span 3;
    grid-row: span 2;
}

.xd-image-collage__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.xd-image-collage__item:nth-child(1) {
    grid-column: span 4;
    grid-row: span 5;
}

.xd-image-collage__item:nth-child(2) {
    grid-column: span 2;
    grid-row: span 2;
}

.xd-image-collage__item:nth-child(3) {
    grid-column: span 3;
    grid-row: span 2;
}

.xd-image-collage__item:nth-child(4) {
    grid-column: span 3;
    grid-row: span 2;
}

.xd-image-collage__item:nth-child(5) {
    grid-column: span 4;
    grid-row: span 3;
}

.xd-image-collage__item:nth-child(6) {
    grid-column: span 4;
    grid-row: span 3;
}

.xd-image-collage__item:nth-child(7),
.xd-image-collage__item:nth-child(8) {
    grid-column: span 6;
    grid-row: span 3;
}

.xd-image-collage__item::after {
    content: none;
}

.xd-image-collage__item img {
    transition: transform 0.8s ease;
}

.xd-image-collage__item:hover img {
    transform: scale(1.02);
}

.xd-image-collage__item figcaption {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    padding: 0.5rem 0.65rem;
    background: rgba(0, 0, 0, 0.5);
    color: #ffffff;
    border-radius: 12px;
    font-size: 0.85rem;
    text-align: center;
}

@media (max-width: 980px) {
    .xd-image-collage__grid {
        grid-template-columns: repeat(3, 1fr);
        grid-auto-rows: 150px;
    }

    /* Reset desktop nth-child spans — JS drives all placement at this breakpoint */
    .xd-image-collage__item:nth-child(n) {
        grid-column: span 1;
        grid-row: span 2;
    }
}

@media (max-width: 640px) {
    .xd-image-collage__grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 98px;
    }

    /*
     * :nth-child(n) matches all items and has the same specificity as the
     * desktop nth-child rules, but appears later — so it wins and resets them.
     * JS then sets precise grid-column / grid-row via inline styles.
     */
    .xd-image-collage__item:nth-child(n) {
        grid-column: span 1;
        grid-row: span 2;
    }
}
