/* ============================================================
   Image Lightbox - full screen image viewer for article images
   ============================================================ */

/* Article images are clickable */
.prose img {
    cursor: zoom-in;
}

/* Image whose file is missing: a placeholder of the standard size replaces it,
   so a dead URL never leaves a broken icon with alt text across the layout */
.image-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: var(--content-img-width, 720px);
    aspect-ratio: var(--content-img-ratio, 16 / 9);
    margin: 20px auto;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px dashed var(--border-primary);
    border-radius: 8px;
    color: var(--text-secondary);
    text-align: center;
}

.image-fallback svg {
    width: 32px;
    height: 32px;
    opacity: 0.55;
}

.image-fallback__text {
    font-size: 14px;
    font-style: italic;
}

/* Page behind the viewer must not scroll */
body.lightbox-open {
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox[hidden] {
    display: none;
}

.lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(2px);
}

.lightbox__figure {
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 56px 72px 72px;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    overflow: auto;
}

.lightbox__img {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    cursor: zoom-in;
    transition: opacity 0.15s ease;
}

.lightbox.is-loading .lightbox__img {
    opacity: 0.35;
}

/* Click the image to inspect it at full resolution */
.lightbox.is-zoomed .lightbox__figure {
    align-items: flex-start;
    justify-content: flex-start;
}

.lightbox.is-zoomed .lightbox__img {
    max-width: none;
    max-height: none;
    cursor: zoom-out;
}

.lightbox__caption {
    position: relative;
    z-index: 1;
    max-width: 80ch;
    text-align: center;
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.lightbox__caption[hidden] {
    display: none;
}

.lightbox__btn {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.lightbox__btn:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.45);
}

.lightbox__btn:focus-visible {
    outline: 2px solid var(--brand-primary, #3b82f6);
    outline-offset: 2px;
}

.lightbox__btn[hidden] {
    display: none;
}

.lightbox__btn svg {
    width: 24px;
    height: 24px;
}

.lightbox__close {
    top: 16px;
    right: 16px;
}

.lightbox__nav {
    top: 50%;
    transform: translateY(-50%);
}

.lightbox__nav:hover {
    transform: translateY(-50%) scale(1.06);
}

.lightbox__prev {
    left: 16px;
}

.lightbox__next {
    right: 16px;
}

.lightbox__counter {
    position: absolute;
    z-index: 2;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.lightbox__counter[hidden] {
    display: none;
}

@media (max-width: 768px) {
    .lightbox__figure {
        padding: 56px 12px 76px;
    }

    .lightbox__img {
        max-height: calc(100vh - 150px);
    }

    .lightbox__btn {
        width: 40px;
        height: 40px;
    }

    .lightbox__btn svg {
        width: 20px;
        height: 20px;
    }

    .lightbox__prev {
        left: 8px;
    }

    .lightbox__next {
        right: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lightbox__btn,
    .lightbox__img {
        transition: none;
    }

    .lightbox__nav:hover {
        transform: translateY(-50%);
    }
}
