.lb-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: color-mix(in srgb, var(--bg) 93%, transparent);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: none;
}

.lb-stage {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: 100%;
}

.lb-canvas {
    position: relative;
    --lb-r: 0.75;
    flex-shrink: 0;
    width: min(calc(100vw - 160px), calc((calc(var(--dvh) * 100) - 140px) * var(--lb-r)));
    aspect-ratio: var(--lb-r);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.lb-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: inherit;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
    cursor: zoom-in;
    will-change: transform;
}

.lb-overlay.lb-zoomed .lb-canvas {
    background: transparent;
    box-shadow: none;
}

.lb-img.zoomed {
    cursor: grab;
}

.lb-img.zoomed.dragging {
    cursor: grabbing;
}

.lb-btn {
    z-index: 2;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: #ffffff;
    mix-blend-mode: difference;
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.15s ease;
}

.lb-btn svg {
    width: 26px;
    height: 26px;
    stroke-width: 2.4;
}

.lb-btn:hover {
    opacity: 1;
}

.lb-close {
    position: absolute;
    top: 18px;
    right: 18px;
}

.lb-prev,
.lb-next {
    flex-shrink: 0;
}

.lb-thumbs {
    display: flex;
    flex-shrink: 0;
    gap: 8px;
    max-width: 100%;
    padding: 14px 16px 20px;
    overflow-x: auto;
    scrollbar-width: none;
    touch-action: pan-x;
}

.lb-thumbs::-webkit-scrollbar {
    display: none;
}

.lb-thumb {
    flex: 0 0 auto;
    width: 48px;
    aspect-ratio: 3 / 4;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: var(--surface-2);
    opacity: 0.5;
    outline: 2px solid transparent;
    outline-offset: 2px;
    cursor: pointer;
    transition: opacity 0.15s ease, outline-color 0.15s ease, box-shadow 0.15s ease;
}

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

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

.lb-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: inherit;
    pointer-events: none;
}

.lb-thumb:hover {
    opacity: 0.85;
}

.lb-thumb.active {
    opacity: 1;
    outline: 0;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px color-mix(in srgb, var(--text) 28%, transparent);
}

.lb-thumb:focus-visible {
    opacity: 1;
    outline-color: var(--accent);
}

@media (max-width: 640px) {
    .lb-stage {
        gap: 0;
    }

    .lb-canvas {
        width: min(100vw, calc((calc(var(--dvh) * 100) - 100px) * var(--lb-r)));
        border-radius: 0;
        box-shadow: none;
    }

    .lb-prev,
    .lb-next {
        position: absolute;
        top: 50%;
        width: 44px;
        height: 44px;
        transform: translateY(-50%);
    }

    .lb-prev {
        left: 10px;
    }

    .lb-next {
        right: 10px;
    }

    .lb-thumbs {
        gap: 6px;
        padding: 12px 12px 18px;
    }

    .lb-thumb {
        width: 42px;
    }
}

.lb-overlay.lb-zoomed .lb-prev,
.lb-overlay.lb-zoomed .lb-next,
.lb-overlay.lb-zoomed .lb-thumbs {
    opacity: 0;
    pointer-events: none;
}

.lb-prev,
.lb-next,
.lb-thumbs {
    transition: opacity 0.18s ease;
}
