.image-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 20px;
}

.image-gallery a {
    display: block;
    overflow: hidden;
    position: relative;
    border-radius: var(--border-radius-image, 12px);
    cursor: pointer;
}

/* A photo the visitor may not open: blurred preview only, not a link (photo_card viewable=false). */
.image-gallery .gallery-teaser-card {
    display: block;
    overflow: hidden;
    position: relative;
    border-radius: var(--border-radius-image, 12px);
    cursor: not-allowed;
}

.image-gallery .gallery-teaser-card img,
.image-gallery .gallery-teaser-card img:hover {
    cursor: not-allowed;
    transform: none;
    opacity: 1;
}

/* An empty collection's placeholder tiles (placeholder_cards): not links, no hover. */
.image-gallery .gallery-placeholder-card {
    display: block;
    overflow: hidden;
    border-radius: var(--border-radius-image, 12px);
}

.image-gallery .gallery-placeholder-card img,
.image-gallery .gallery-placeholder-card img:hover {
    cursor: default;
    transform: none;
    opacity: 1;
}

.image-gallery img {
    display: block;
    width: 100%;
    height: 300px;
    object-fit: cover;
    cursor: pointer;
    transition: opacity 0.4s ease, transform 0.3s ease;
}

.image-gallery img:hover {
    transform: scale(1.03);
    opacity: 0.92;
}

/* Keep the preview visible under the spinner while loading */
.image-gallery a.is-loading .gallery-preview-img,
.image-gallery a.is-loading-full .gallery-preview-img {
    opacity: 1;
}

.gallery-spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
    border: 2px solid color-mix(in srgb, var(--color-primary, #FFB3C6) 35%, transparent);
    border-top-color: var(--color-cta, #FF8FAB);
    border-radius: 50%;
    animation: gallery-spin 0.8s linear infinite;
    pointer-events: none;
}

/* Spinner shows for both preview loads and queued full-image loads. */
.image-gallery a.is-loading-full .gallery-spinner,
.image-gallery a.is-loading .gallery-spinner {
    display: block;
}

/* Full image stacks on top of the preview and fades in once loaded. */
.image-gallery .gallery-full-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.3s ease;
}

.image-gallery a.is-loaded .gallery-full-img {
    opacity: 1;
}

@keyframes gallery-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Lightbox background and opening animation */
.lightbox {
    display: flex;
    position: fixed;
    z-index: 9999;
    inset: 0;
    visibility: hidden;
    background: rgba(0, 0, 0, 0);
    -webkit-backdrop-filter: blur(0);
    backdrop-filter: blur(0);
    align-items: center;
    justify-content: center;
    pointer-events: none;
    touch-action: none;
    transition:
        background-color 0.1s ease-out,
        backdrop-filter 0.05s ease-out,
        -webkit-backdrop-filter 0.05s ease-out,
        visibility 0s linear 0.1s;
}

.lightbox.active {
    visibility: visible;
    background: rgba(0, 0, 0, 0.9);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    pointer-events: auto;
    transition:
        background-color 0.1s ease-out,
        backdrop-filter 0.05s ease-out,
        -webkit-backdrop-filter 0.05s ease-out,
        visibility 0s linear 0s;
}

/* Large image */
.lightbox-stage {
    position: relative;
    width: 90%;
    height: 90vh;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.9);
    transform-origin: center;
    transition: opacity 0.1s ease-out, transform 0.2s ease-out;
    will-change: opacity, transform;
    /* All drag gestures are handled in JS (horizontal swipe + pull down). */
    touch-action: none;
}

.lightbox.active .lightbox-stage {
    opacity: 1;
    transform: scale(1);
}

/* Vertical swipe-to-close: fade the backdrop and shrink the image almost
   completely away before returning the lightbox to its hidden state. */
.lightbox.is-closing {
    background: rgba(0, 0, 0, 0);
    -webkit-backdrop-filter: blur(0);
    backdrop-filter: blur(0);
    pointer-events: none;
    transition:
        background-color 0.1s ease-out,
        backdrop-filter 0.05s ease-out,
        -webkit-backdrop-filter 0.05s ease-out;
}

.lightbox.is-closing .lightbox-stage {
    opacity: 0;
    transform: scale(0.1);
    transition: opacity 0.1s ease-out, transform 0.2s ease-out;
}

.lightbox-slide {
    position: absolute;
    inset: 0;
    transition: transform 0.3s ease;
    will-change: transform;
    touch-action: none;
}

/* While dragging, the slides follow the pointer with no transition. */
.lightbox-stage.is-dragging .lightbox-slide {
    transition: none;
}

.lightbox-slide img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    touch-action: none;
}

/* While the full image loads, hide it and show the blurred preview
   under the spinner instead of the previous image. */
.lightbox-slide .lightbox-full {
    transition: opacity 0.3s ease;
}

.lightbox-slide.is-loading .lightbox-full {
    opacity: 0;
}

.lightbox-slide .lightbox-preview {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lightbox-slide.is-loading .lightbox-preview {
    opacity: 1;
}

.lightbox-spinner {
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border-width: 3px;
}

.lightbox-slide.is-loading .lightbox-spinner {
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    .lightbox,
    .lightbox-stage,
    .lightbox-slide,
    .lightbox-slide img {
        transition: none;
    }
}

/* Buttons */
.lightbox button {
    position: absolute;
    z-index: 10;
    border: none;
    background: none;
    color: white;
    font-size: 50px;
    cursor: pointer;
    padding: 10px 20px;
    line-height: 1;
    opacity: 1;
    transition: opacity 0.4s ease;
    touch-action: none;
}

.lightbox.is-idle .lightbox-prev,
.lightbox.is-idle .lightbox-next {
    opacity: 0.5;
}

.lightbox.is-super-idle .lightbox-prev,
.lightbox.is-super-idle .lightbox-next {
    opacity: 0.1;
}

.lightbox button:hover,
.lightbox.is-idle .lightbox button:hover,
.lightbox.is-super-idle .lightbox button:hover {
    color: #ccc;
    opacity: 1;
}

.lightbox-close {
    top: 20px;
    right: 25px;
    font-size: 45px !important;
}

.lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 12px;
}

.lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 12px;
}

/* Collection headers */
.private-gallery-collection-header,
.gallery-collection-header {
    max-width: 1200px;
    margin: 40px auto 0;
    padding: 0 20px;
    box-sizing: border-box;
    color: var(--color-text);
    font-family: var(--font-bold);
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.private-gallery-collection-header + .image-gallery,
.gallery-collection-header + .image-gallery {
    margin-top: 12px;
}

/* Gallery block heading and intro, above the photos */
.gallery-block-head {
    max-width: 1200px;
    margin: 40px auto 0;
    padding: 0 20px;
    box-sizing: border-box;
    color: var(--color-text);
}

.gallery-block-heading {
    margin: 0;
    font-family: var(--font-bold);
    font-weight: normal;
    font-size: 1.6rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.gallery-block-intro {
    margin: 10px 0 0;
    font-family: var(--font-normal);
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.gallery-block-intro > :first-child {
    margin-top: 0;
}

.gallery-block-intro > :last-child {
    margin-bottom: 0;
}

.gallery-block-head + .image-gallery,
.gallery-block-head + .gallery-preview {
    margin-top: 20px;
}

/* A collection's written description, under its name (gallery block "Show collection descriptions") */
.gallery-collection-description {
    max-width: 1200px;
    margin: 8px auto 0;
    padding: 0 20px;
    box-sizing: border-box;
    color: var(--color-text);
    font-family: var(--font-normal);
    line-height: 1.6;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.gallery-collection-description + .image-gallery {
    margin-top: 16px;
}

/* Locked photo cards for timed releases */
.gallery-locked-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 300px;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--border-radius-image, 12px);
    box-sizing: border-box;
    color: #fff;
    text-align: center;
    overflow: hidden;
    user-select: none;
    cursor: default;
    transition: transform 0.2s var(--easing), border-color 0.2s var(--easing);
}

.gallery-locked-card:hover {
    border-color: rgba(214, 129, 151, 0.4);
}

.gallery-locked-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.gallery-locked-bg.is-loaded {
    opacity: 1;
}

.locked-card-backdrop {
    position: absolute;
    inset: 0;
    backdrop-filter: brightness(80%);
    -webkit-backdrop-filter: brightness(80%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.locked-card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
}

.locked-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    /* Fixed white on the black card: the theme accent can be too dark to read here. */
    color: #fff;
    margin-bottom: 2px;
}

.locked-card-timer {
    font-size: 0.78rem;
    /* Fixed white on the black card: the theme accent can be too dark to read here. */
    color: #fff;
    padding: 3px 10px;
    font-weight: 500;
}

/* Mobile */
@media (max-width: 600px) {
    .image-gallery {
        grid-template-columns: repeat(2, 1fr);
    }

    .lightbox button {
        font-size: 35px;
    }

    .lightbox-stage {
        width: 95%;
        height: 85vh;
    }
}
