.imagegallery-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: var(--imagegallery-gap, 12px);
}

@media (min-width: 480px) {
    .imagegallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .imagegallery-grid.imagegallery-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .imagegallery-grid.imagegallery-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .imagegallery-grid.imagegallery-cols-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .imagegallery-grid.imagegallery-cols-6 {
        grid-template-columns: repeat(6, 1fr);
    }
}

.imagegallery-tile {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: var(--imagegallery-ratio, 1 / 1);
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: none;
    border: 0;
    border-radius: var(--imagegallery-radius, 10px);
    box-shadow: var(--imagegallery-shadow, none);
    cursor: pointer;
    transition: box-shadow 0.15s ease;
}

.imagegallery-tile:hover,
.imagegallery-tile:focus-visible {
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.2);
}

.imagegallery-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.25s ease;
}

.imagegallery-tile:hover .imagegallery-img,
.imagegallery-tile:focus-visible .imagegallery-img {
    transform: scale(1.05);
}

.imagegallery-title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.4rem 0.6rem;
    background: var(--imagegallery-title-bg, rgba(0, 0, 0, 0.6));
    color: var(--imagegallery-title-text, #fff);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.imagegallery-empty {
    padding: 1rem;
    color: #6c757d;
    font-style: italic;
}

/*
 * Full-screen gallery modal with a transparent black backdrop. Bootstrap's
 * own .modal-fullscreen utility handles the sizing (100vw / 100vh, no
 * margin, no border-radius) and .modal-content is already a flex column
 * (header + body) by default — we only need to swap the background for a
 * translucent black and give the carousel a fixed height to center against.
 */
.imagegallery-modal-content {
    background-color: rgba(0, 0, 0, 0.92);
    border: 0;
}

.imagegallery-modal-body {
    position: relative;
    overflow: auto;
}

.imagegallery-carousel {
    width: 100%;
    height: 100%;
}

.imagegallery-carousel .carousel-inner,
.imagegallery-carousel .carousel-item {
    height: 100%;
}

/*
 * The image is centered with an absolute-position trick (rather than flex
 * on .carousel-item) so it keeps working during Bootstrap's slide
 * transition, when the incoming/outgoing item briefly carries Bootstrap's
 * own display:block instead of our active-state override.
 *
 * Sizing: the image is never stretched — it renders at its natural size up
 * to a maximum of 850px in whichever dimension (width or height) is larger,
 * and shrinks further only if the viewport itself is smaller than that.
 */
.imagegallery-carousel-img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: min(850px, 100%);
    max-height: min(850px, 100%);
    width: auto;
    height: auto;
    object-fit: contain;
}

.imagegallery-carousel-caption {
    right: 10%;
    left: 10%;
    bottom: 1rem;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 6px;
    padding: 0.4rem 1rem;
}
