/* Gallery Lightbox — adaptive frame + arrows on image */

.glbox {
    --glbox-ease: cubic-bezier(.22, .61, .36, 1);
    --glbox-dur: .34s;
    --glbox-pad: clamp(.75rem, 2.5vw, 1.5rem);

    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity var(--glbox-dur) var(--glbox-ease),
        visibility var(--glbox-dur) var(--glbox-ease);
}

.glbox.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.glbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .88);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.glbox__stage {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    padding: var(--glbox-pad);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    outline: none;
}

/* Sized box that smoothly morphs between image aspect ratios */
.glbox__frame {
    position: relative;
    flex: 0 0 auto;
    width: 280px;
    height: 200px;
    max-width: 92vw;
    max-height: 86vh;
    border-radius: 2px;
    overflow: hidden;
    background: rgba(0, 0, 0, .25);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, .06),
        0 12px 40px rgba(0, 0, 0, .55);
    transition:
        width var(--glbox-dur) var(--glbox-ease),
        height var(--glbox-dur) var(--glbox-ease);
    will-change: width, height;
}

.glbox__frame.is-sizing-instant {
    transition: none !important;
}

.glbox__img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: 0;
    opacity: 0;
    transform: scale(.96);
    transition:
        opacity .28s var(--glbox-ease),
        transform .32s var(--glbox-ease);
    will-change: opacity, transform;
}

.glbox__img.is-visible {
    opacity: 1;
    transform: scale(1);
}

.glbox__caption {
    margin: 0;
    max-width: min(36rem, 92vw);
    padding: .15rem .75rem 0;
    color: rgba(255, 255, 255, .92);
    font-size: clamp(.85rem, 2.2vw, .95rem);
    font-weight: 500;
    line-height: 1.45;
    text-align: center;
    text-wrap: balance;
    word-break: break-word;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity var(--glbox-dur) var(--glbox-ease) .05s,
        transform var(--glbox-dur) var(--glbox-ease) .05s;
}

.glbox__caption[hidden] {
    display: none !important;
}

.glbox.is-open .glbox__caption:not([hidden]) {
    opacity: 1;
    transform: translateY(0);
}

.glbox__counter {
    margin: 0;
    padding: .28rem .7rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, .35);
    color: rgba(255, 255, 255, .78);
    font-size: .78rem;
    font-weight: 500;
    letter-spacing: .04em;
    line-height: 1.2;
    text-align: center;
    min-height: 1.4rem;
    user-select: none;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity var(--glbox-dur) var(--glbox-ease) .05s,
        transform var(--glbox-dur) var(--glbox-ease) .05s;
}

.glbox.is-open .glbox__counter {
    opacity: 1;
    transform: translateY(0);
}

.glbox__btn {
    appearance: none;
    border: 0;
    background: rgba(20, 20, 20, .42);
    color: rgba(255, 255, 255, .95);
    width: 2.65rem;
    height: 2.65rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition:
        background .18s ease,
        color .18s ease,
        opacity var(--glbox-dur) var(--glbox-ease),
        box-shadow .18s ease;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    z-index: 2;
}

.glbox.is-open .glbox__btn {
    opacity: 1;
}

.glbox__btn:hover {
    background: rgba(0, 0, 0, .5);
    color: #fff;
}

.glbox__btn:focus-visible {
    background: rgba(0, 0, 0, .55);
    outline: 2px solid rgba(255, 255, 255, .65);
    outline-offset: 2px;
}

.glbox__btn:disabled {
    opacity: .3;
    cursor: default;
    pointer-events: none;
}

.glbox__btn .bi {
    font-size: 1.15rem;
    line-height: 1;
    pointer-events: none;
}

/* Close stays on viewport corner */
.glbox__btn--close {
    position: absolute;
    top: max(.85rem, env(safe-area-inset-top, 0px));
    inset-inline-end: max(.85rem, env(safe-area-inset-right, 0px));
    background: rgba(255, 255, 255, .12);
}

.glbox__btn--close:hover,
.glbox__btn--close:focus-visible {
    background: rgba(255, 255, 255, .22);
}

.glbox__btn--close .bi {
    font-size: 1.05rem;
}

/* Prev/Next live ON the image frame */
.glbox__btn--prev,
.glbox__btn--next {
    position: absolute;
    top: 50%;
    margin-top: -1.325rem;
}

.glbox__btn--prev {
    inset-inline-start: .45rem;
}

.glbox__btn--next {
    inset-inline-end: .45rem;
}

html[dir="rtl"] .glbox__btn--prev .bi,
html[dir="rtl"] .glbox__btn--next .bi {
    transform: scaleX(-1);
}

body.glbox-open {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    overflow: hidden;
}

@media (max-width: 575.98px) {
    .glbox {
        --glbox-pad: .4rem;
    }

    .glbox__frame {
        max-width: 96vw;
        max-height: 78vh;
        max-height: 78dvh;
        border-radius: 0;
    }

    .glbox__btn {
        width: 2.85rem;
        height: 2.85rem;
    }

    .glbox__btn--prev,
    .glbox__btn--next {
        margin-top: -1.425rem;
        background: rgba(0, 0, 0, .42);
    }

    .glbox__btn--prev {
        inset-inline-start: .3rem;
    }

    .glbox__btn--next {
        inset-inline-end: .3rem;
    }

    .glbox__btn--close {
        top: max(.55rem, env(safe-area-inset-top, 0px));
        inset-inline-end: max(.55rem, env(safe-area-inset-right, 0px));
        background: rgba(0, 0, 0, .4);
    }

    .glbox__counter {
        font-size: .72rem;
        background: rgba(0, 0, 0, .4);
    }

    .glbox__caption {
        max-width: 96vw;
        font-size: .82rem;
        padding-inline: .5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .glbox,
    .glbox__frame,
    .glbox__img,
    .glbox__btn,
    .glbox__caption,
    .glbox__counter {
        transition-duration: .01ms !important;
    }

    .glbox__img,
    .glbox__img.is-visible {
        transform: none;
    }
}
