/********** Gallery page **********
   Markup: the gallery page template (gallery-page.cfm in the gallery-r3-frontend skill).
   Behaviour: gallery.js.

   Self-contained: no framework needed. Set the theme tokens below to the site's own colours and
   font. Focus rings are box-shadows, because many site stylesheets remove outlines globally.

   Four Winds Painting: colours and fonts from css/style.css and css/bootstrap.min.css (purple
   #2e1753 headings and buttons, Open Sans body text, Jost headings). The page loads Open Sans at
   400/500 only, so text in the body font stays at 500 or lighter (600 would be faux bold). Site
   rules this file overrides: Bootstrap's a:hover colour (tile titles) and style.css's
   h2 { font-weight: 700 !important } (viewer title). */

:root {
    --gallery-accent: #2e1753;        /* brand colour: active filter, gallery titles, link button text */
    --gallery-text: #525368;          /* body text on the page */
    --gallery-muted: #646577;         /* photo counts, messages */
    --gallery-line: #dedbe6;          /* filter borders, section underline */
    --gallery-tile: #efedf3;          /* tile background while a thumbnail loads */
    --gallery-font: inherit;          /* the site's body font unless set */
    --gallery-heading-font: "Jost", sans-serif;  /* the site's heading font: gallery titles, viewer title */
    --gallery-row: 220px;             /* target row height; each row stretches a little to fill the width */
    --gallery-gap: 8px;
}

.gallery-page,
.gallery-page *,
.gallery-viewer,
.gallery-viewer * {
    box-sizing: border-box;
}

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

.gallery-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.gallery-page {
    padding-bottom: 3rem;
    color: var(--gallery-text);
    font-family: var(--gallery-font);
}

.gallery-message {
    margin: 0;
    padding: 3rem 0;
    text-align: center;
    font-size: 1rem;
    color: var(--gallery-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 var(--gallery-line);
    border-radius: 999px;
    background: #fff;
    color: var(--gallery-text);
    font-size: .875rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none !important;
    transition: background-color .2s, border-color .2s, color .2s;
}

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

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

.gallery-filter:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--gallery-accent) 35%, transparent);
}

.gallery-filter-count {
    min-width: 1.6em;
    padding: .15rem .45rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--gallery-line) 55%, #fff);
    color: var(--gallery-muted);
    font-size: .75rem;
    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 var(--gallery-line);
}

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

.gallery-section-title {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--gallery-accent);
    font-family: var(--gallery-heading-font);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
    text-transform: none;
}

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

.gallery-section-description {
    max-width: 75ch;
    margin: .3rem 0 0;
    color: var(--gallery-text);
    font-size: 1rem;
    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: var(--gallery-tile);
    color: #fff;
    cursor: zoom-in;
}

.gallery-tile img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    object-fit: cover;
    transition: transform .5s ease, opacity .4s ease;
}

/* 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(46, 23, 83, .7), rgba(46, 23, 83, 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;
    color: #fff;                      /* set here: the site's a:hover colour would beat the tile's */
    font-size: .875rem;
    font-weight: 500;
    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 {
    outline: none;
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--gallery-accent);
}

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

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

@media (max-width: 575.98px) {
    :root {
        --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: 1.25rem;
    }

    .gallery-section-description {
        font-size: .875rem;
    }
}


/*** Photo viewer ***/
html.gallery-viewer-open {
    overflow: hidden;
    scrollbar-gutter: stable;
    /* the gutter kept for the scrollbar is outside the viewer (it covers the viewport only), so on
       browsers with space-taking scrollbars it showed as a white strip; this paints it to match */
    background: #1a1425;
}

.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(16, 10, 28, .96);
    color: #f2f4f7;
    font-family: var(--gallery-font);
}

.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: .875rem;
    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;
    margin: 0;
    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 {
    outline: none;
    box-shadow: 0 0 0 2px #fff;
}

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

.gallery-viewer-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    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: 1rem;
}

.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: .75rem;
    font-weight: 500;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.gallery-viewer-title {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: #fff;
    font-family: var(--gallery-heading-font);
    font-size: 1.25rem;
    font-weight: 600 !important;      /* style.css sets every h2 to 700 !important */
    line-height: 1.3;
    text-transform: none;
}

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

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

.gallery-viewer-description a {
    color: #9ac79c;
    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(--gallery-accent);
    font-size: .875rem;
    font-weight: 500;
    text-decoration: none !important;
}

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

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

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

@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: 1rem;
    }
}

@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;
    }
}
