/* ==========================================================================
   NextGEN Gallery
   ========================================================================== */

.ngg-galleryoverview {
    --ngg-gap: clamp(2px, 0.6vw, 8px);
    /* Fallback layout (also beats a lot of NGG float rules) */
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: var(--ngg-gap);
    padding: 0 0 var(--space-md) 0;
    margin: 1.5em 0;
    width: 100%;
}

.ngg-galleryoverview .ngg-gallery-thumbnail-box {
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    flex: 0 0 calc((100% - (var(--ngg-gap) * 4)) / 5) !important;
}

.ngg-galleryoverview .ngg-gallery-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-subtle);
}

.ngg-galleryoverview .ngg-gallery-thumbnail a {
    display: block;
    width: 100%;
    height: 100%;
}

.ngg-galleryoverview .ngg-gallery-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.12s ease;
}

.ngg-galleryoverview .ngg-gallery-thumbnail img:hover {
    opacity: 0.88;
}

.ngg-galleryoverview br,
.ngg-galleryoverview .ngg-clear {
    display: none;
}

@supports (display: grid) {
    .ngg-galleryoverview {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        gap: var(--ngg-gap);
    }

    .ngg-galleryoverview .ngg-gallery-thumbnail-box {
        flex: initial !important;
    }
}

/*
 * Narrow viewports: five equal columns make thumbs too small — use a horizontal
 * swipe strip (scroll-snap). From ~540px up, five columns still read well.
 */
@media (max-width: 33.75rem) {
    .ngg-galleryoverview {
        display: flex !important;
        flex-wrap: nowrap !important;
        grid-template-columns: none !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scroll-padding-inline: var(--space-sm, 0.75rem);
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .ngg-galleryoverview::-webkit-scrollbar {
        display: none;
    }

    .ngg-galleryoverview .ngg-gallery-thumbnail-box {
        /* ~2.2 tiles visible + peek — comfortable tap targets, clear swipe affordance */
        flex: 0 0 calc((100% - (var(--ngg-gap) * 2)) / 2.25) !important;
        max-width: none;
        scroll-snap-align: start;
        scroll-snap-stop: normal;
    }
}

/* ==========================================================================
   NextGEN Fancybox (lightbox only — thumbnails use rules above)
   Classic jQuery Fancybox 1.x (#fancybox-*)
   ========================================================================== */

#fancybox-overlay {
    background: rgba(28, 18, 8, 0.78) !important;
    opacity: 1 !important;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
}

#fancybox-wrap {
    --fb-nav-size: 3rem;
    --fb-nav-bg: rgba(28, 18, 8, 0.52);
    --fb-nav-bg-hover: rgba(28, 18, 8, 0.72);
    --fb-nav-border: rgba(255, 252, 245, 0.22);
    --fb-nav-border-hover: rgba(255, 252, 245, 0.4);
    /* Pull left control out / bring right control in (~½ scrollbar / rounding skew) */
    --fb-arrow-base: 3.75rem;
    --fb-arrow-balance: 0rem;
    /* Fancybox close: rounded-stroke cross for mask (black strokes = visible) */
    --fb-close-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2.25' stroke-linecap='round' d='M7 7l10 10M17 7L7 17'/%3E%3C/svg%3E");
    --fb-close-size: calc(var(--fb-nav-size) * 0.7);
    /* Inside the rounded frame: clear the arc + comfortable padding (not Fancybox’s -15px corner straddle) */
    --fb-close-inset: max(
        0.5rem,
        calc(var(--fb-close-size) * 0.28),
        calc(var(--radius-lg) * 0.5)
    );

    /* Default Fancybox 1.3.4 uses 20px so a -15px close sits in the gutter; we inset inside the image instead */
    padding: 0 !important;
    font-family: var(--font-sans);
    overflow: visible;
    /* JS often sets width to content + mat border; we removed the border — shrink-wrap to the card */
    width: fit-content !important;
    max-width: min(100%, calc(100vw - 1.25rem));
    box-sizing: border-box;
    /* Force horizontal centering even if Fancybox sets a slightly off inline left */
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin-left: 0 !important;
}

/*
 * Constrain + shrink-wrap the outer to the image width. The close button is
 * absolutely positioned on #fancybox-outer (not #fancybox-content); if max-width
 * lived only on #fancybox-content, the outer stayed wider and `right` hugged
 * the wrong edge — uneven vs. the visible rounded card.
 */
#fancybox-outer {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-sizing: border-box;
    width: fit-content !important;
    max-width: min(100%, calc(100vw - 1.25rem));
    margin-inline: auto;
    min-width: 0;
    border-radius: var(--radius-lg);
    background: transparent;
    box-shadow: none;
    /* Visible so prev/next controls can sit outside the image frame */
    overflow: visible;
}

#fancybox-outer:has(#fancybox-title.fancybox-title-inside) {
    align-items: stretch;
}

/* Kill default 9-slice mat visually; keep nodes so Fancybox layout stays balanced */
#fancybox-outer .fancybox-bg {
    background-image: none !important;
    background-color: transparent !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#fancybox-content {
    border: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-hover);
    min-width: 0;
    box-sizing: border-box;
    /* Shrink with outer when max-width caps the lightbox below intrinsic image width */
    max-width: 100%;
}

#fancybox-content > img#fancybox-img {
    border-radius: var(--radius-lg);
    display: block;
    max-width: 100%;
    height: auto;
}

/*
 * Caption below (title-inside): one vertical card. Fancybox still injects old
 * 10px-border margins on the title — override those. Image area is only rounded
 * on top so the caption meets a straight edge (no corner “gaps”).
 */
#fancybox-outer:has(#fancybox-title.fancybox-title-inside) #fancybox-content {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

#fancybox-outer:has(#fancybox-title.fancybox-title-inside) #fancybox-content > img#fancybox-img {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Close — smaller than nav; flush inside #fancybox-outer’s top-right (sibling of #fancybox-content) */
#fancybox-close {
    position: absolute !important;
    /* Fancybox 1.x uses ~1102 for #fancybox-left / #fancybox-right; those overlays cover the top-right — stay above them */
    z-index: 1103 !important;
    pointer-events: auto;
    top: var(--fb-close-inset) !important;
    right: var(--fb-close-inset) !important;
    left: auto !important;
    bottom: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    width: var(--fb-close-size) !important;
    height: var(--fb-close-size) !important;
    transform-origin: center;
    background: none !important;
    background-image: none !important;
    background-color: var(--fb-nav-bg) !important;
    background-repeat: no-repeat !important;
    background-position: 0 0 !important;
    border: 1px solid var(--fb-nav-border);
    border-radius: 50% !important;
    box-shadow: none;
    overflow: hidden;
    text-indent: 0 !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 0;
    line-height: 1;
    color: rgba(255, 252, 245, 0.92) !important;
    font-weight: normal;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition:
        background-color 0.12s ease,
        border-color 0.12s ease,
        color 0.12s ease;
}

#fancybox-close img {
    display: none !important;
}

#fancybox-close:hover,
#fancybox-close:focus-visible {
    background-image: none !important;
    background-color: var(--fb-nav-bg-hover) !important;
    border-color: var(--fb-nav-border-hover);
    color: #fff !important;
    outline: none;
}

#fancybox-close::before {
    content: '';
    display: block;
    width: calc(var(--fb-close-size) * 0.375);
    height: calc(var(--fb-close-size) * 0.375);
    flex-shrink: 0;
    background-color: currentColor;
    -webkit-mask: var(--fb-close-x) center / contain no-repeat;
    mask: var(--fb-close-x) center / contain no-repeat;
}

#fancybox-close::after {
    content: none !important;
}

/* Prev / next */
#fancybox-left,
#fancybox-right {
    width: 44% !important;
    outline: none;
}

#fancybox-left-ico,
#fancybox-right-ico {
    position: absolute !important;
    top: 50% !important;
    background-image: none !important;
    background: transparent none !important;
    width: var(--fb-nav-size) !important;
    height: var(--fb-nav-size) !important;
    margin-top: calc(var(--fb-nav-size) / -2) !important;
    border-radius: 50% !important;
    background-color: var(--fb-nav-bg) !important;
    box-shadow: none;
    border: 1px solid var(--fb-nav-border);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition:
        background-color 0.12s ease,
        border-color 0.12s ease;
}

#fancybox-left:hover #fancybox-left-ico,
#fancybox-right:hover #fancybox-right-ico {
    background-color: var(--fb-nav-bg-hover) !important;
    border-color: var(--fb-nav-border-hover);
}

@media (hover: none) {
    #fancybox-close:active {
        background-color: var(--fb-nav-bg-hover) !important;
        border-color: var(--fb-nav-border-hover);
        color: #fff !important;
    }

    #fancybox-left:active #fancybox-left-ico,
    #fancybox-right:active #fancybox-right-ico {
        background-color: var(--fb-nav-bg-hover) !important;
        border-color: var(--fb-nav-border-hover);
    }
}

#fancybox-left-ico::after,
#fancybox-right-ico::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.55rem;
    height: 0.55rem;
    margin-top: -0.28rem;
    border: 2px solid rgba(255, 252, 245, 0.85);
    border-right: none;
    border-top: none;
}

 #fancybox-left-ico {
    /* Outside the frame; balance offsets so gaps match left vs right */
    left: calc(-1 * (var(--fb-arrow-base) + var(--fb-arrow-balance))) !important;
}

#fancybox-left-ico::after {
    margin-left: -0.2rem;
    transform: rotate(45deg);
}

#fancybox-right-ico {
    right: calc(-1 * (var(--fb-arrow-base) - var(--fb-arrow-balance))) !important;
    left: auto !important;
}

#fancybox-right-ico::after {
    margin-left: -0.35rem;
    transform: rotate(-135deg);
}

/* Title bar when shown */
#fancybox-title {
    align-self: stretch;
    box-sizing: border-box;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--clr-text-muted);
    background: var(--clr-bg-warm) !important;
    border-top: 1px solid var(--clr-border);
    padding: var(--space-xs) var(--space-sm);
}

#fancybox-title.fancybox-title-inside {
    /* Fancybox 1.x inline width/margins assume the mat border; we removed it */
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Loading state */
#fancybox-loading {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

/* --------------------------------------------------------------------------
   Fancybox — tablet & mobile
   -------------------------------------------------------------------------- */

/* Tablet: slightly tighter arrow offset, comfortable defaults */
@media (max-width: 64rem) {

    #fancybox-wrap {
        --fb-arrow-base: 2.50rem;
        --fb-arrow-balance: 0rem;
    }

    #fancybox-outer {
        max-width: min(100%, calc(100vw - 1.5rem));
        
    }

    #fancybox-content,
    #fancybox-content > img#fancybox-img {
        border-radius: var(--radius-md);
    }

    #fancybox-outer:has(#fancybox-title.fancybox-title-inside) #fancybox-content,
    #fancybox-outer:has(#fancybox-title.fancybox-title-inside) #fancybox-content > img#fancybox-img {
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }

    #fancybox-title.fancybox-title-inside {
        border-radius: 0 0 var(--radius-md) var(--radius-md);
    }
}

/* Large phone / small tablet: min ~44px touch targets, safe-area on close */
@media (max-width: 48rem) {
    #fancybox-wrap {
        --fb-nav-size: clamp(2.75rem, 8vw, 3rem);
        --fb-close-size: max(2.5rem, calc(var(--fb-nav-size) * 0.72));
        --fb-arrow-base: 1.85rem;
        --fb-arrow-balance: 0.2rem;
    }

    #fancybox-close {
        top: calc(var(--fb-close-inset) + env(safe-area-inset-top, 0px)) !important;
        right: calc(var(--fb-close-inset) + env(safe-area-inset-right, 0px)) !important;
    }

    #fancybox-left,
    #fancybox-right {
        width: 50% !important;
    }
}

/* Typical mobile width */
@media (max-width: 40rem) {
    #fancybox-wrap {
        --fb-nav-size: 2.75rem;
        --fb-close-size: max(2.75rem, calc(var(--fb-nav-size) * 0.72));
        --fb-arrow-base: 1.35rem;
        --fb-arrow-balance: 0.15rem;
    }

    #fancybox-outer {
        max-width: min(100%, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 1rem));
    }

    #fancybox-title {
        padding-left: max(var(--space-sm), env(safe-area-inset-left, 0px));
        padding-right: max(var(--space-sm), env(safe-area-inset-right, 0px));
    }
}

/* Narrow phones: arrows on the image (not past screen edge), respect notch inset */
@media (max-width: 26.25rem) {
    #fancybox-wrap {
        --fb-nav-size: 2.8125rem;
        --fb-arrow-balance: 0;
    }

#fancybox-left-ico {
        left: max(var(--space-xs), env(safe-area-inset-left, 0px)) !important;
    }

    #fancybox-right-ico {
        right: max(var(--space-xs), env(safe-area-inset-right, 0px)) !important;
    }
}

/* Short viewports (landscape phone): tuck arrows in; keep ≥44px nav */
@media (max-width: 48rem) and (max-height: 28rem) {
    #fancybox-wrap {
        --fb-arrow-base: 1rem;
        --fb-arrow-balance: 0.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #fancybox-close,
    #fancybox-left-ico,
    #fancybox-right-ico {
        transition-duration: 0.01ms !important;
    }
}
