.ngp-gallery {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    margin: 1em 0;
}

@media (max-width: 768px) {
    .ngp-gallery {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (max-width: 480px) {
    .ngp-gallery {
        grid-template-columns: 1fr;
    }
}

/* Tile is the OUTER container holding the clipped media and the caption below.
   Overflow is deliberately NOT hidden on the tile, so captions placed below
   the media remain visible (p16b fix: previously the tile owned the fixed
   aspect-ratio AND overflow:hidden, which clipped any below-image caption). */
.ngp-gallery-tile {
    position: relative;
    background: transparent;
    border-radius: var(--ngp-tile-radius, 6px);
    border: var(--ngp-tile-border-width, 0) solid var(--ngp-tile-border-color, transparent);
}

/* Media wrapper carries the aspect ratio + overflow clipping so the image
   fills its shaped area but a caption rendered below (as a tile sibling of
   this wrapper) is never clipped. */
.ngp-gallery-tile-media {
    position: relative;
    overflow: hidden;
    border-radius: inherit;
    background: transparent;
}

.ngp-gallery-tile-media .ngp-gallery-link,
.ngp-gallery-tile-media .ngp-gallery-img {
    display: block;
    width: 100%;
    height: auto;
    text-decoration: none;
    color: inherit;
}

/* Grid with a fixed tile aspect ratio: the media wrapper locks to that ratio
   and the image fills it. Caption below (outside media) stays in normal flow. */
.ngp-gallery[style*="--ngp-tile-aspect"] .ngp-gallery-tile-media {
    aspect-ratio: var(--ngp-tile-aspect);
}

.ngp-gallery[style*="--ngp-tile-aspect"] .ngp-gallery-tile-media .ngp-gallery-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Letterbox: whole image fits inside the shaped area, transparent bars fill
   the sides that are shorter than the tile. */
.ngp-gallery-letterbox .ngp-gallery-tile-media .ngp-gallery-img {
    object-fit: contain;
    background: transparent;
}

.ngp-gallery-caption {
    margin-top: 6px;
    font-size: 14px;
    line-height: 1.4;
    color: #0B2540;
}

/* Masonry layout (p13). Tiles of varying heights that fit together like a
   Pinterest board. Uses CSS multi-column; break-inside keeps a single tile
   from splitting across columns. */
.ngp-gallery-masonry {
    display: block;
    column-count: 4;
    column-gap: 12px;
    grid-template-columns: none;
}

@media (max-width: 1200px) {
    .ngp-gallery-masonry { column-count: 3; }
}
@media (max-width: 768px) {
    .ngp-gallery-masonry { column-count: 2; }
}
@media (max-width: 480px) {
    .ngp-gallery-masonry { column-count: 1; }
}

.ngp-gallery-masonry .ngp-gallery-tile {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    margin: 0 0 12px 0;
}

.ngp-gallery-masonry .ngp-gallery-tile-media {
    aspect-ratio: auto;
}

.ngp-gallery-masonry .ngp-gallery-tile-media .ngp-gallery-img {
    width: 100%;
    height: auto;
    object-fit: unset;
    display: block;
}

/* Slider layout (p14). One tile visible at a time; prev/next arrows + an
   image-position indicator are injected by the companion JS. */
.ngp-gallery-slider {
    display: block;
    position: relative;
    grid-template-columns: none;
    outline: none;
}

.ngp-gallery-slider .ngp-gallery-tile {
    display: none;
    width: 100%;
    margin: 0;
}

.ngp-gallery-slider .ngp-gallery-tile.ngp-slide-active {
    display: block;
}

.ngp-gallery-slider-arrows {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    padding: 0 12px;
    box-sizing: border-box;
    pointer-events: none;
}

.ngp-gallery-slider-arrow {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 22px;
    background: rgba(11, 37, 64, 0.65);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.ngp-gallery-slider-arrow:hover,
.ngp-gallery-slider-arrow:focus {
    background: #064A85;
    outline: 2px solid #FFC233;
    outline-offset: 2px;
}

.ngp-gallery-slider-indicator {
    text-align: center;
    margin-top: 8px;
    font-size: 14px;
    color: #6b7280;
}

.ngp-gallery-slider:focus {
    outline: 2px solid #FFC233;
    outline-offset: 4px;
}

/* Lightbox (p15). Clicking a .ngp-gallery-lightbox-trigger opens an overlay
   with the full-size image centered and dimmed-page behind. Keyboard, touch,
   and screen-reader support live in the companion JS. */
.ngp-lightbox-active {
    overflow: hidden;
}

.ngp-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 37, 64, 0.85);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2em 5em;
    box-sizing: border-box;
    animation: ngp-lightbox-fade 0.18s ease;
}

.ngp-lightbox-overlay.ngp-lightbox-open {
    display: flex;
}

@keyframes ngp-lightbox-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ngp-lightbox-inner {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ngp-lightbox-img {
    max-width: 100%;
    max-height: calc(100vh - 6em);
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

.ngp-lightbox-close {
    position: absolute;
    top: 1em;
    right: 1em;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.ngp-lightbox-close:hover,
.ngp-lightbox-close:focus {
    background: rgba(255, 255, 255, 0.3);
    outline: 2px solid #FFC233;
    outline-offset: 2px;
}

.ngp-lightbox-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.ngp-lightbox-arrow:hover,
.ngp-lightbox-arrow:focus {
    background: rgba(255, 255, 255, 0.3);
    outline: 2px solid #FFC233;
    outline-offset: 2px;
}

.ngp-lightbox-prev {
    left: 1em;
}

.ngp-lightbox-next {
    right: 1em;
}

.ngp-lightbox-counter {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1em;
    text-align: center;
    color: #fff;
    font-size: 14px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

@media (max-width: 640px) {
    .ngp-lightbox-overlay {
        padding: 1em 0.5em;
    }
    .ngp-lightbox-prev {
        left: 0.5em;
    }
    .ngp-lightbox-next {
        right: 0.5em;
    }
    .ngp-lightbox-img {
        max-height: calc(100vh - 4em);
    }
}

.ngp-gallery-lightbox-trigger {
    cursor: zoom-in;
}

/* ---------------------------------------------------------------
 * p16 -- Hover effects + Loading effects.
 *
 * Hover: keyed on [data-hover="..."] on the gallery wrapper. Hover
 * rules now target the media wrapper (not the tile), so captions
 * rendered below the media are unaffected by hover transforms and
 * overlays. For data-hover="caption_slides_up" the PHP renderer
 * places the caption INSIDE the media wrapper so it can slide up
 * from below while being clipped by the media's overflow:hidden.
 *
 * Loading: single entrance animation per tile on first render.
 * Keyed on [data-loading="..."].
 * ------------------------------------------------------------- */

/* --- Hover: zoom_in --- */
.ngp-gallery[data-hover="zoom_in"] .ngp-gallery-tile-media .ngp-gallery-img {
    transition: transform 0.35s ease;
}
.ngp-gallery[data-hover="zoom_in"] .ngp-gallery-tile-media:hover .ngp-gallery-img,
.ngp-gallery[data-hover="zoom_in"] .ngp-gallery-tile-media:focus-within .ngp-gallery-img {
    transform: scale(1.06);
}

/* --- Hover: fade_dim --- */
.ngp-gallery[data-hover="fade_dim"] .ngp-gallery-tile-media .ngp-gallery-img {
    transition: opacity 0.3s ease;
}
.ngp-gallery[data-hover="fade_dim"] .ngp-gallery-tile-media:hover .ngp-gallery-img,
.ngp-gallery[data-hover="fade_dim"] .ngp-gallery-tile-media:focus-within .ngp-gallery-img {
    opacity: 0.6;
}

/* --- Hover: caption_slides_up ---
   Caption sits inside the media wrapper for this one mode. Hidden by
   default (translated down 100%); slides up to overlay the image on
   hover / keyboard focus. */
.ngp-gallery[data-hover="caption_slides_up"] .ngp-gallery-tile-media .ngp-gallery-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 10px 12px;
    color: #fff;
    background: rgba(11, 37, 64, 0.88);
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
.ngp-gallery[data-hover="caption_slides_up"] .ngp-gallery-tile-media:hover .ngp-gallery-caption,
.ngp-gallery[data-hover="caption_slides_up"] .ngp-gallery-tile-media:focus-within .ngp-gallery-caption {
    transform: translateY(0);
}

/* --- Hover: color_overlay --- */
.ngp-gallery[data-hover="color_overlay"] .ngp-gallery-tile-media::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(6, 74, 133, 0.45);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    border-radius: inherit;
}
.ngp-gallery[data-hover="color_overlay"] .ngp-gallery-tile-media:hover::after,
.ngp-gallery[data-hover="color_overlay"] .ngp-gallery-tile-media:focus-within::after {
    opacity: 1;
}

/* --- Hover: none -- no rule needed --- */

/* --- Loading: fade_in --- */
@keyframes ngp-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.ngp-gallery[data-loading="fade_in"] .ngp-gallery-tile {
    animation: ngp-fade-in 0.45s ease both;
}

/* --- Loading: slide_in_below --- */
@keyframes ngp-slide-in-below {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ngp-gallery[data-loading="slide_in_below"] .ngp-gallery-tile {
    animation: ngp-slide-in-below 0.5s ease both;
}

/* --- Loading: scale_up --- */
@keyframes ngp-scale-up {
    from { opacity: 0; transform: scale(0.88); }
    to   { opacity: 1; transform: scale(1); }
}
.ngp-gallery[data-loading="scale_up"] .ngp-gallery-tile {
    animation: ngp-scale-up 0.45s ease both;
}

/* --- Loading: none -- no rule needed --- */

@media (prefers-reduced-motion: reduce) {
    .ngp-gallery[data-loading] .ngp-gallery-tile {
        animation: none !important;
    }
    .ngp-gallery[data-hover] .ngp-gallery-tile-media .ngp-gallery-img,
    .ngp-gallery[data-hover] .ngp-gallery-tile-media::after,
    .ngp-gallery[data-hover] .ngp-gallery-tile-media .ngp-gallery-caption {
        transition: none !important;
    }
}
