/*
 * Unlisted /gallery/ page. Loaded only by views/gallery/default.php.
 * Colours, radius, type and spacing come from the tokens in main.css so the
 * gallery follows the rest of the site.
 */

.gallery {
    --gallery-gap: 1rem;
    --gallery-teal: var(--primary-color);
    --gallery-gold: var(--secondary-color);
    --gallery-radius: var(--border-radius);
}

/* ---- Category bar: the site's pill buttons ---------------------------- */

.gallery-nav {
    position: sticky;
    top: 0;
    z-index: 10;
    margin-top: var(--spacing-medium);
    padding-block: 0.75rem;
    background: var(--white);
    border-bottom: 1px solid var(--border-line);
}

.gallery-nav__track {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.gallery-nav__track::-webkit-scrollbar {
    display: none;
}

/* wide screens have room for every category: wrap instead of scrolling */
@media (min-width: 960px) {
    .gallery-nav__track { flex-wrap: wrap; overflow: visible; }
}

.gallery-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex: none;
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--gallery-teal);
    border-radius: 2rem;
    background: var(--white);
    color: var(--gallery-teal);
    font: inherit;
    font-size: var(--font-size-medium-small);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.gallery-chip__count {
    font-size: 0.75rem;
    opacity: 0.7;
}

.gallery-chip:hover,
.gallery-chip[aria-pressed="true"] {
    background: var(--gallery-teal);
    color: var(--primary-font-color);
}

/* ---- Chapters ---------------------------------------------------------- */

.gallery-chapter {
    scroll-margin-top: 5rem;
}

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

.gallery-chapter__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    margin-bottom: var(--spacing-medium);
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-line);
}

.gallery-chapter__title {
    margin: 0;
    color: var(--gallery-teal);
}

.gallery-chapter__head .details {
    margin: 0;
}

/* ---- Grid: square cells, clips first, the lead clip as a 2x2 feature -- */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-flow: row dense;
    gap: var(--gallery-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

@media (min-width: 640px)  { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .gallery-grid { grid-template-columns: repeat(4, 1fr); } }

.gallery-cell {
    aspect-ratio: 1;
    min-width: 0;
    margin: 0;
}

.gallery-cell--feature {
    grid-column: span 2;
    grid-row: span 2;
}

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

.gallery-tile {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: var(--gallery-radius);
    overflow: hidden;
    background: var(--bg-light-100);
    font: inherit;
    cursor: zoom-in;
}

.gallery-cell--video .gallery-tile {
    cursor: pointer;
}

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

.gallery-tile video {
    opacity: 0;
}

.gallery-tile.is-playing video {
    opacity: 1;
}

/* caption bar in the site's translucent teal, as used on the page headers */
.gallery-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    padding: 0.6rem 0.8rem;
    background: var(--primary-color-rgba);
    color: var(--primary-font-color);
    font-size: var(--font-size-small);
    line-height: 1.3;
    text-align: left;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.gallery-cell--feature .gallery-caption {
    transform: none;
    padding: 0.9rem 1.1rem;
    font-size: var(--font-size-regular);
}

.gallery-badge {
    position: absolute;
    top: 0.6rem;
    left: 0.6rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border-radius: 2rem;
    background: var(--gallery-gold);
    color: var(--secondary-font-color);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

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

@media (hover: none) {
    .gallery-cell:not(.gallery-cell--feature) .gallery-caption { display: none; }
}

.gallery-tile:focus-visible,
.gallery-chip:focus-visible,
.gallery-viewer__btn:focus-visible {
    outline: 3px solid var(--gallery-gold);
    outline-offset: 2px;
}

.gallery-tile:focus-visible .gallery-caption {
    transform: none;
}

/* cells fade in as they scroll into view (classes set by gallery.js) */
.gallery-cell.is-pending {
    opacity: 0;
    transform: translateY(12px);
}

.gallery-cell.is-shown {
    opacity: 1;
    transform: none;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* ---- Viewer ------------------------------------------------------------ */

.gallery-viewer {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--white);
    color: var(--font-color);
    font-family: var(--ff);
}

.gallery-viewer::backdrop {
    background: var(--white);
}

.gallery-viewer[open] {
    animation: gallery-fade 0.25s ease;
}

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

.gallery-viewer__stage {
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 1rem;
    height: 100%;
    /* the side padding is wide enough that media never runs under the arrows */
    padding: 1rem max(5rem, 6vw) 1.5rem;
    box-sizing: border-box;
}

.gallery-viewer__bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-line);
    font-size: var(--font-size-medium-small);
}

.gallery-viewer__chapter {
    font-weight: 700;
    color: var(--primary-color);
}

.gallery-viewer__count {
    margin-right: auto;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

/* media is centred inside this box and never grows it, whatever its shape */
.gallery-viewer__media {
    position: relative;
    min-height: 0;
    overflow: hidden;
    touch-action: pan-y;
}

.gallery-viewer__media.is-zoomed {
    touch-action: none;
}

.gallery-viewer__media img,
.gallery-viewer__media video {
    position: absolute;
    inset: 0;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: var(--border-radius);
    background: var(--bg-light-100);
    animation: gallery-fade 0.3s ease;
}

/* click to zoom: gallery.js sets the scale and moves the origin with the pointer */
.gallery-viewer__media img {
    cursor: zoom-in;
    transform-origin: var(--zoom-x, 50%) var(--zoom-y, 50%);
    transition: transform 0.25s ease;
}

.gallery-viewer__media.is-zoomed img {
    cursor: zoom-out;
    transform: scale(var(--zoom, 2));
    transition: transform 0.25s ease, transform-origin 0.08s linear;
}

.gallery-viewer__caption {
    margin: 0;
    text-align: center;
    font-size: var(--font-size-regular);
}

.gallery-viewer__btn {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--primary-color);
    color: var(--primary-font-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.gallery-viewer__btn:hover {
    background: var(--secondary-color);
}

.gallery-viewer__prev,
.gallery-viewer__next {
    position: absolute;
    top: 50%;
    translate: 0 -50%;
}

.gallery-viewer__prev { left: clamp(0.5rem, 2vw, 2rem); }
.gallery-viewer__next { right: clamp(0.5rem, 2vw, 2rem); }

/* narrow portrait screens: full width for the media, arrows move below it */
@media (max-width: 699px) and (min-height: 521px) {
    .gallery-viewer__stage { padding: 0.75rem 1rem 5rem; }
    .gallery-viewer__prev,
    .gallery-viewer__next { top: auto; bottom: 1.25rem; translate: none; }
    .gallery-viewer__prev { left: calc(50% - 3.5rem); }
    .gallery-viewer__next { right: calc(50% - 3.5rem); }
}

/* short screens (phones held sideways): give the height to the media */
@media (max-height: 520px) {
    .gallery-viewer__stage { gap: 0.4rem; padding: 0.4rem 3.75rem; }
    .gallery-viewer__bar { padding-bottom: 0.3rem; }
    .gallery-viewer__btn { width: 2.25rem; height: 2.25rem; }
    .gallery-viewer__prev { left: 0.6rem; }
    .gallery-viewer__next { right: 0.6rem; }
    .gallery-viewer__caption {
        font-size: var(--font-size-small);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-viewer[open],
    .gallery-viewer__media img,
    .gallery-viewer__media video { animation: none; }
    .gallery-viewer__media img,
    .gallery-viewer__media.is-zoomed img,
    .gallery-tile img,
    .gallery-tile video,
    .gallery-caption,
    .gallery-cell.is-shown { transition: none; }
    .gallery-cell.is-pending { opacity: 1; transform: none; }
}
