/********** Gallery page **********
   Markup: includes/i_midnight-our-seafood-catch-gallery.cfm. Behaviour: js/gallery.js.
   style.css sets ":focus { outline: none !important }", so focus rings here are box-shadows. */

.gallery-page {
    --gallery-row: 220px;   /* target row height; each row stretches a little to fill the width */
    --gallery-gap: 8px;
    padding-bottom: 3rem;
}

.gallery-message {
    margin: 0;
    padding: 3rem 0;
    text-align: center;
    font-size: var(--fs-base);
    color: var(--muted);
}


/*** Filters ***/
.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .5rem;
    margin: 0 0 2rem;
}

.gallery-filter {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .45rem .6rem .45rem 1rem;
    border: 1px solid #cfd8e6;
    border-radius: 999px;
    background: #fff;
    color: var(--dark);
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.2;
    transition: background-color .2s, border-color .2s, color .2s;
}

.gallery-filter:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.gallery-filter.active,
.gallery-filter.active:hover {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.gallery-filter:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 66, 165, .35);
}

.gallery-filter-count {
    min-width: 1.6em;
    padding: .15rem .45rem;
    border-radius: 999px;
    background: #eef2f8;
    color: #56657a;
    font-size: var(--fs-xs);
    text-align: center;
}

.gallery-filter.active .gallery-filter-count {
    background: rgba(255, 255, 255, .2);
    color: #fff;
}


/*** Gallery sections ***/
.gallery-section:not([hidden]) ~ .gallery-section:not([hidden]) {
    margin-top: 3rem;
}

.gallery-section:not([hidden]) {
    animation: gallery-fade-in .35s ease-out;
}

.gallery-section-header {
    margin-bottom: 1rem;
    padding-bottom: .6rem;
    border-bottom: 1px solid #dde3ec;
}

.gallery-section-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .25rem 1rem;
}

.gallery-section-title {
    margin: 0;
    color: var(--primary);
    font-size: var(--fs-xl);
    font-weight: 700;
}

.gallery-section-count {
    color: var(--muted);
    font-size: var(--fs-sm);
}

.gallery-section-description {
    max-width: 75ch;
    margin: .3rem 0 0;
    color: #4a4a4a;
    font-size: var(--fs-base);
    line-height: 1.6;
}


/*** Photo grid ***
   Justified rows: each tile's share of a row is its width-to-height ratio (--ratio, set per tile),
   so every photo in a row ends up the same height without cropping, whatever shape the
   thumbnails are. Cropped thumbnails simply make an even grid. */
.gallery-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--gallery-gap);
}

/* soaks up the spare space in the last row, so a few photos there keep their normal size */
.gallery-grid::after {
    content: "";
    flex-grow: 1000000;
}

.gallery-tile {
    position: relative;
    display: block;
    flex: var(--ratio) 1 calc(var(--ratio) * var(--gallery-row));
    aspect-ratio: var(--ratio);
    overflow: hidden;
    border-radius: 4px;
    background: #e8edf3;
    color: #fff;
    cursor: zoom-in;
}

.gallery-tile img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .5s ease, opacity .4s ease;
}

/* js/gallery.js fades each thumbnail in once it arrives */
.gallery-js .gallery-tile img:not(.is-loaded) {
    opacity: 0;
}

.gallery-tile::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 22, 55, .65), rgba(0, 22, 55, 0) 50%);
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
}

.gallery-tile-title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    padding: .6rem .75rem;
    overflow: hidden;
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .45);
    white-space: nowrap;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .3s, transform .3s;
}

@media (hover: hover) {
    .gallery-tile:hover img {
        transform: scale(1.04);
    }

    .gallery-tile:hover::after,
    .gallery-tile:hover .gallery-tile-title {
        opacity: 1;
        transform: none;
    }
}

.gallery-tile:focus-visible {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--primary);
}

.gallery-tile:focus-visible::after,
.gallery-tile:focus-visible .gallery-tile-title {
    opacity: 1;
    transform: none;
}

@media (max-width: 991.98px) {
    .gallery-page {
        --gallery-row: 180px;
    }
}

@media (max-width: 575.98px) {
    .gallery-page {
        --gallery-row: 120px;
        --gallery-gap: 4px;
    }

    .gallery-filters {
        margin-bottom: 1.5rem;
    }

    .gallery-section:not([hidden]) ~ .gallery-section:not([hidden]) {
        margin-top: 2rem;
    }

    .gallery-section-title {
        font-size: var(--fs-lg);
    }

    .gallery-section-description {
        font-size: var(--fs-sm);
    }
}


/*** Photo viewer ***/
html.gallery-viewer-open {
    overflow: hidden;
    scrollbar-gutter: stable;
}

.gallery-viewer {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: rgba(6, 12, 22, .96);
    color: #f2f4f7;
    font-family: "Open Sans", sans-serif;
}

.gallery-viewer[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    animation: gallery-fade-in .2s ease-out;
}

.gallery-viewer::backdrop {
    background: transparent;
}

.gallery-viewer svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.gallery-viewer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
}

.gallery-viewer-counter {
    color: rgba(255, 255, 255, .7);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
}

.gallery-viewer-actions {
    display: flex;
    gap: .5rem;
}

.gallery-viewer-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .1);
    color: #fff;
    cursor: pointer;
    transition: background-color .2s;
}

.gallery-viewer-btn:hover {
    background: rgba(255, 255, 255, .22);
}

.gallery-viewer-btn:focus-visible {
    box-shadow: 0 0 0 2px #fff;
}

.gallery-viewer-btn[hidden] {
    display: none;
}

.gallery-viewer-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 0 5rem;
}

.gallery-viewer-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: 2px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
    user-select: none;
    -webkit-user-drag: none;
    transition: opacity .2s, transform .25s ease-out;
}

/* only dims if the next photo takes a moment, so already-loaded photos switch without a flicker */
.gallery-viewer-stage.is-loading .gallery-viewer-img {
    opacity: .3;
    transition-delay: .3s;
}

.gallery-viewer-stage.is-dragging .gallery-viewer-img {
    transition: none;
}

.gallery-viewer-spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
}

.gallery-viewer-stage.is-loading .gallery-viewer-spinner {
    display: block;
    animation: gallery-spin .8s linear infinite, gallery-fade-in .2s .3s both;
}

.gallery-viewer-error {
    margin: 0;
    color: rgba(255, 255, 255, .75);
    font-size: var(--fs-base);
}

.gallery-viewer-prev,
.gallery-viewer-next {
    position: absolute;
    top: 50%;
    width: 52px;
    height: 52px;
    margin-top: -26px;
}

.gallery-viewer-prev {
    left: 1rem;
}

.gallery-viewer-next {
    right: 1rem;
}

.gallery-viewer-prev svg,
.gallery-viewer-next svg {
    width: 26px;
    height: 26px;
}

.gallery-viewer-caption {
    width: 100%;
    max-width: 760px;
    max-height: 32vh;
    margin: 0 auto;
    padding: .9rem 1.25rem 1.25rem;
    overflow-y: auto;
    text-align: center;
}

.gallery-viewer-gallery {
    margin: 0 0 .15rem;
    color: rgba(255, 255, 255, .6);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.gallery-viewer-title {
    margin: 0;
    color: #fff;
    font-size: var(--fs-lg);
    font-weight: 600;
    text-transform: none;
}

.gallery-viewer-description {
    margin-top: .35rem;
    color: rgba(255, 255, 255, .82);
    font-size: var(--fs-sm);
    line-height: 1.6;
}

.gallery-viewer-description p {
    margin: 0 0 .5em;
    font-size: inherit;
}

.gallery-viewer-description a {
    color: #9cc3ff;
    text-decoration: underline !important;
}

.gallery-viewer-link {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin-top: .8rem;
    padding: .5rem 1.1rem;
    border-radius: 999px;
    background: #fff;
    color: var(--primary);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.gallery-viewer-link:hover {
    background: #e3ecfb;
    color: var(--primary);
}

.gallery-viewer-link:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .5);
}

.gallery-viewer-link svg {
    width: 16px;
    height: 16px;
}

.gallery-viewer [hidden] {
    display: none !important;
}

@media (max-width: 767.98px) {
    .gallery-viewer-bar {
        padding: .5rem .75rem;
    }

    .gallery-viewer-stage {
        padding: 0;
    }

    /* over the photo's edges on small screens, where swiping is the usual way to move */
    .gallery-viewer-prev,
    .gallery-viewer-next {
        width: 40px;
        height: 40px;
        margin-top: -20px;
        background: rgba(0, 0, 0, .35);
    }

    .gallery-viewer-prev {
        left: .4rem;
    }

    .gallery-viewer-next {
        right: .4rem;
    }

    .gallery-viewer-caption {
        padding: .6rem 1rem 1rem;
    }

    .gallery-viewer-title {
        font-size: var(--fs-base);
    }
}

@keyframes gallery-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes gallery-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-page *,
    .gallery-viewer,
    .gallery-viewer * {
        animation: none !important;
        transition: none !important;
    }

    .gallery-tile:hover img {
        transform: none;
    }
}
