/* Lightbox container */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 24px;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.78);
    justify-content: center;
    align-items: center;
    z-index: 9050;
}

.lightbox-dialog {
    position: relative;
    width: min(100%, 1280px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.lightbox-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 18px 76px 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    touch-action: pan-y pinch-zoom;
}

/* Lightbox image */
#lightbox-image {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 170px);
    object-fit: contain;
    border-radius: 18px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
    user-select: none;
    -webkit-user-drag: none;
}

/* Navigation buttons */
.lightbox-prev, .lightbox-next, .lightbox-close {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    font-size: 20px;
    color: #fff;
    cursor: pointer;
    z-index: 1060;
    padding: 10px;
    border-radius: 999px;
    width: 52px;
    height: 52px;
    backdrop-filter: blur(10px);
    transition: background-color 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

/* Close button */
.lightbox-close {
    top: 12px;
    right: 12px;
    transform: none;
}

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

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

.lightbox-prev:hover, .lightbox-next:hover, .lightbox-close:hover {
    background: rgba(255, 255, 255, 0.5);
}

.lightbox-prev:focus-visible, .lightbox-next:focus-visible, .lightbox-close:focus-visible, .lightbox-thumb:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.lightbox-prev[hidden], .lightbox-next[hidden] {
    display: none;
}

/*
 * THE RAIL SCROLLS, SO IT CLIPS, ON BOTH AXES.
 *
 * overflow-x: auto makes overflow-y auto too, so anything poking out of the
 * thumbs is cut: the active thumb used to lift 2px and lost the top of its
 * ring. Nothing moves now and the padding leaves room for the focus outline.
 * justify-content: center pushed the first thumbs off the left edge as soon
 * as the rail overflowed, where no scroll could reach them; the auto margins
 * on the first and last thumb centre a short rail and scroll a long one.
 */
.lightbox-thumbs {
    width: min(100%, 1040px);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 4px 4px 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.lightbox-thumbs[hidden] {
    display: none;
}

.lightbox-thumb:first-child {
    margin-left: auto;
}

.lightbox-thumb:last-child {
    margin-right: auto;
}

/*
 * The ring is the button's border, and the photo inside rounds to the
 * border's inner edge: radius minus border. With the same 16px on both the
 * photo's corners stood clear of the ring and the backdrop showed through
 * between them, most visibly along the bottom.
 */
.lightbox-thumb {
    --lb-thumb-r: 16px;
    flex: 0 0 auto;
    width: 76px;
    height: 76px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: var(--lb-thumb-r);
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    overflow: hidden;
    opacity: 0.6;
    transition: opacity 0.18s ease, border-color 0.18s ease;
}

.lightbox-thumb:hover {
    opacity: 0.9;
}

.lightbox-thumb.is-active {
    opacity: 1;
    border-color: #fff;
}

.lightbox-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
    border-radius: calc(var(--lb-thumb-r) - 2px);
    -webkit-user-drag: none;
}

/* The count, and Report or its question, between the photo and the rail. */
.lightbox-bar {
    width: min(100%, 1040px);
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 4px;
    color: var(--tl-night-muted, rgba(255, 255, 255, 0.72));
}

.lightbox-count {
    font-family: var(--tl-font-mono, ui-monospace, monospace);
    font-size: 0.8125rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.lightbox-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.lightbox-ask {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.35;
    color: var(--tl-night-ink, #fff);
    text-align: right;
}

.lightbox-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--tl-night-ink, #fff);
    font-size: 0.8125rem;
    line-height: 1.2;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background-color 0.18s ease, opacity 0.18s ease;
}

.lightbox-action:hover {
    background: rgba(255, 255, 255, 0.24);
}

.lightbox-action:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* The lightbox is dark on both faces, so the answer is the light pill. */
.lightbox-action.is-confirm {
    background: var(--tl-night-ink, #fff);
    color: var(--tl-night, #111);
    font-weight: 600;
}

.lightbox-action.is-confirm:hover {
    background: #fff;
}

.lightbox-action:disabled {
    cursor: default;
    opacity: 0.6;
}

.lightbox-action.is-done:disabled {
    background: transparent;
    opacity: 1;
    color: var(--tl-night-muted, rgba(255, 255, 255, 0.72));
}

.lightbox-dialog:focus {
    outline: none;
}

.lightbox-preloader {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1060;
}

.lightbox-preloader .spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
    .lightbox {
        padding: 14px;
    }

    .lightbox-dialog {
        gap: 8px;
    }

    .lightbox-stage {
        padding: 28px 52px 0;
    }

    #lightbox-image {
        max-height: calc(100vh - 132px);
    }

    .lightbox-prev, .lightbox-next {
        font-size: 30px;
        width: 40px;
        height: 40px;
    }

    .lightbox-prev {
        left: 8px;
    }

    .lightbox-next {
        right: 8px;
    }

    .lightbox-close {
        font-size: 20px;
        top: 8px;
        right: 8px;
        width: 40px;
        height: 40px;
    }

    .lightbox-thumbs {
        gap: 10px;
        width: 100%;
        padding-bottom: 0;
    }

    .lightbox-thumb {
        --lb-thumb-r: 14px;
        width: 60px;
        height: 60px;
    }

    .lightbox-bar {
        padding: 0;
    }

    .lightbox-bar.is-asking {
        flex-wrap: wrap;
    }

    .lightbox-bar.is-asking .lightbox-actions {
        flex-wrap: wrap;
        width: 100%;
    }

    .lightbox-bar.is-asking .lightbox-ask {
        flex: 1 1 100%;
        text-align: left;
    }
}

@media (max-width: 480px) {
    .lightbox-stage {
        padding: 24px 42px 0;
    }

    #lightbox-image {
        max-height: calc(100vh - 118px);
    }

    .lightbox-thumb {
        --lb-thumb-r: 12px;
        width: 54px;
        height: 54px;
    }
}