/* ==========================================================================
   Lightbox - fullscreen photo viewer shared by the journal, design pages,
   the specimen picker, and piece pages. Native <dialog>, scroll-snap swipe,
   tap-to-zoom. The trigger images stay fully visible without JS; this whole
   surface is enhancement.
   ========================================================================== */

.bb-lightbox {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(30, 30, 32, 0.96);
    color: var(--color-ivory);
    display: none;
    flex-direction: column;
}

.bb-lightbox[open] {
    display: flex;
}

.bb-lightbox::backdrop {
    background: rgba(30, 30, 32, 0.7);
}

.bb-lightbox__chrome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    flex-shrink: 0;
}

.bb-lightbox__counter {
    font-family: var(--font-body);
    font-size: 0.85rem;
    letter-spacing: 0.2em;
    color: var(--color-gold);
    font-variant-numeric: tabular-nums;
}

.bb-lightbox__close {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(196, 162, 101, 0.5);
    border-radius: 50%;
    background: transparent;
    color: var(--color-ivory);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.25s ease;
}

.bb-lightbox__close:hover,
.bb-lightbox__close:focus-visible {
    background: rgba(196, 162, 101, 0.25);
}

.bb-lightbox__close:focus-visible,
.bb-lightbox__nav:focus-visible,
.bb-lightbox__track:focus-visible {
    outline: 2px solid var(--color-gold);
    outline-offset: 2px;
}

.bb-lightbox__track {
    flex: 1;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.bb-lightbox__track::-webkit-scrollbar {
    display: none;
}

.bb-lightbox__cell {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    min-height: 0;
}

.bb-lightbox__image {
    max-width: 96vw;
    max-height: calc(100dvh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: zoom-in;
    display: block;
}

/* Tap to zoom: the image doubles and the cell pans by native scroll. */
.bb-lightbox__cell.is-zoomed {
    align-items: flex-start;
    justify-content: flex-start;
}

.bb-lightbox__cell.is-zoomed .bb-lightbox__image {
    max-width: none;
    max-height: none;
    width: 180vw;
    cursor: zoom-out;
}

.bb-lightbox__foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1rem 1rem;
    flex-shrink: 0;
}

.bb-lightbox__caption {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-style: italic;
    text-align: center;
    color: rgba(246, 243, 238, 0.85);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Arrows ride the image sides, vertically centered on the photo area. */
.bb-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: 1px solid rgba(196, 162, 101, 0.6);
    border-radius: 50%;
    background: rgba(30, 30, 32, 0.55);
    color: var(--color-ivory);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    z-index: 2;
    transition: background 0.25s ease, opacity 0.25s ease;
}

.bb-lightbox__nav--prev { left: max(0.75rem, env(safe-area-inset-left)); }
.bb-lightbox__nav--next { right: max(0.75rem, env(safe-area-inset-right)); }

/* Touch devices navigate by swipe: the arrows would only cover the photo,
   so hide them and let the counter carry the position. */
@media (hover: none) and (pointer: coarse) {
    .bb-lightbox__nav {
        display: none;
    }
}

.bb-lightbox__nav:disabled {
    opacity: 0.3;
    cursor: default;
}

.bb-lightbox__nav:not(:disabled):hover {
    background: rgba(196, 162, 101, 0.25);
}

/* Trigger affordance: images that open the viewer show a zoom cursor. */
.bb-lb-item {
    cursor: zoom-in;
}

button.bb-lb-item {
    border: 0;
    padding: 0;
    background: none;
    text-align: inherit;
    font: inherit;
    color: inherit;
    display: block;
    width: 100%;
}

button.bb-lb-item:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .bb-lightbox__track {
        scroll-behavior: auto;
    }

    .bb-lightbox__close,
    .bb-lightbox__nav {
        transition-duration: 0.01ms;
    }
}
