/* styles/gallery.css */

/* --- Controls row (reuses your .btn) --- */
.gallery-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 10px 0 18px;
}

/* --- Masonry grid (columns) --- */
.gallery-grid {
    columns: 1;
    column-gap: 14px;
}

@media (min-width: 700px) {
    .gallery-grid {
        columns: 2;
    }
}

@media (min-width: 1024px) {
    .gallery-grid {
        columns: 3;
    }
}

/* each block avoids breaking across columns */
.gallery-block {
    break-inside: avoid;
    margin: 0 0 14px;
}

/* thumbnails */
.gallery-block img {
    width: 100%;
    display: block;
    border-radius: var(--radius);
    border: 1px solid var(--surface-border);
    box-shadow: 0 10px 22px rgba(0, 0, 0, .22);
    transition: transform .25s ease, opacity .25s ease;
}

.gallery-block img:hover {
    transform: scale(1.02);
    opacity: 0.98;
}

/* captions */
.gallery-cap {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--surface-3);
    color: var(--nav-ink);
    border: 1px solid var(--surface-border);
    border-radius: calc(var(--radius) - 2px);
    font-size: .95rem;
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    grid-template-rows: 60px 1fr 60px;
    background: color-mix(in oklab, #000 65%, transparent);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--ease);
    z-index: 999;
}

.lightbox[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-stage {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
    display: grid;
    align-items: center;
    justify-items: center;
    gap: .75rem;
    color: var(--nav-ink);
    text-align: center;
}

#lightbox-img {
    max-width: min(1100px, 90vw);
    max-height: 72vh;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
    border: 1px solid var(--surface-border);
    background: var(--surface-2);
}

#lightbox-cap {
    font-size: .95rem;
    line-height: 1.4;
    opacity: .9;
    padding: 6px 10px;
    background: var(--surface-3);
    border: 1px solid var(--surface-border);
    border-radius: calc(var(--radius) - 2px);
}

/* lightbox buttons */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    background: var(--accent);
    color: var(--accent-ink);
    border: 1px solid color-mix(in oklab, var(--accent) 65%, black);
    border-radius: 999px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.lightbox-close {
    grid-column: 3;
    grid-row: 1;
    margin: 8px;
    font-size: 1.6rem;
    line-height: 1;
}

.lightbox-prev {
    grid-column: 1;
    grid-row: 2;
    margin-left: 8px;
    font-size: 1.2rem;
}

.lightbox-next {
    grid-column: 3;
    grid-row: 2;
    margin-right: 8px;
    font-size: 1.2rem;
}

/* ===== Lightbox: mobile-friendly layout, centered image/caption, visible controls ===== */

.lightbox {
    display: none;
    /* hidden until opened */
}

.lightbox[aria-hidden="false"] {
    display: grid;
    place-items: center;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .70);
    /* darker for contrast on phones */
    z-index: 1000;
}

/* Stage centers everything */
.lightbox-stage {
    display: grid;
    justify-items: center;
    /* center caption under image */
    gap: 10px;
    max-width: 92vw;
    max-height: 86vh;
    margin: 0;
}

/* Image scales to viewport */
#lightbox-img {
    max-width: 92vw;
    max-height: 72vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

/* Caption: readable & centered */
#lightbox-cap {
    text-align: center;
    color: #fff;
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 85ch;
    opacity: .95;
}

/* Controls: visible, large tap targets, kept above the image */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .18);
    text-decoration: none;
    cursor: pointer;
    z-index: 1001;
    /* above the image */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-close {
    /* top-right X */
    top: 14px;
    right: 14px;
    font-size: 26px;
    line-height: 1;
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    font-size: 26px;
    line-height: 1;
}

.lightbox-prev {
    left: 10px;
}

.lightbox-next {
    right: 10px;
}

/* Hover/active feedback (desktop) */
@media (hover:hover) {

    .lightbox-close:hover,
    .lightbox-prev:hover,
    .lightbox-next:hover {
        background: rgba(0, 0, 0, .6);
    }
}

/* Phone tweaks: bigger targets and spacing */
@media (max-width: 720px) {

    .lightbox-close,
    .lightbox-prev,
    .lightbox-next {
        width: 48px;
        height: 48px;
        font-size: 28px;
    }

    .lightbox-prev {
        left: 6px;
    }

    .lightbox-next {
        right: 6px;
    }
}

/* Ensure gallery blocks behave nicely in masonry */
.gallery-block {
    break-inside: avoid;
    margin: 0 0 12px;
}

.gallery-cap {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--nav-ink);
    padding: 8px 4px 0;
    text-align: center;
    /* match lightbox caption centering */
}

/* ===== FIX: iOS centering + safe areas + pinned controls ===== */

.lightbox[aria-hidden="false"] {
    position: fixed;
    inset: 0;
    /* use dynamic viewport height to avoid iOS “crooked” centering */
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* respect iPhone notch / home indicator */
    padding:
        max(env(safe-area-inset-top), 12px) max(env(safe-area-inset-right), 12px) max(env(safe-area-inset-bottom), 12px) max(env(safe-area-inset-left), 12px);
    background: rgba(0, 0, 0, .72);
    z-index: 1000;
}

.lightbox-stage {
    display: grid;
    justify-items: center;
    gap: 10px;
    width: min(92vw, 1200px);
    max-height: calc(100dvh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    margin: 0;
    transform: translateZ(0);
    /* reduce iOS jitters */
}

#lightbox-img {
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 220px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

#lightbox-cap {
    text-align: center;
    color: #fff;
    opacity: .95;
    font-size: .95rem;
    line-height: 1.5;
    max-width: 85ch;
}

/* Controls: use fixed so they anchor to the viewport, not content flow */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: fixed;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .18);
    z-index: 1001;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Close (top-right) with safe-area padding */
.lightbox-close {
    top: max(env(safe-area-inset-top), 12px);
    right: max(env(safe-area-inset-right), 12px);
    font-size: 26px;
    line-height: 1;
}

/* Prev/Next centered vertically, tucked inside safe areas */
.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    font-size: 26px;
    line-height: 1;
}

.lightbox-prev {
    left: max(env(safe-area-inset-left), 10px);
}

.lightbox-next {
    right: max(env(safe-area-inset-right), 10px);
}

/* Smaller phones: give arrows a touch more inset */
@media (max-width: 420px) {
    .lightbox-prev {
        left: max(env(safe-area-inset-left), 6px);
    }

    .lightbox-next {
        right: max(env(safe-area-inset-right), 6px);
    }
}