/* =====================================================================
 * pages/gallery.css — /gallery filter bar, tiled media grid, video modal.
 *
 * Loaded LAST in the cascade (via $page_css in GalleryController), AFTER
 * the vendored photoswipe.css (which $page_vendor_css emits just before
 * this). Tokens / color-mix / currentColor only — NO hex literals, so the
 * hex audit stays clean (photoswipe.css is the whitelisted vendor sheet).
 *
 * The PhotoSwipe lightbox chrome itself is styled by photoswipe.css; this
 * sheet only owns the on-page grid + the bespoke video modal.
 * ===================================================================== */

/* --- Filter bar ------------------------------------------------------- */
.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
    margin-bottom: var(--space-7);
}

/* Toggle pill. Inactive = outlined; active (and aria-pressed) = filled
   primary. Mirrors the .btn pill shape but is its own control so the
   toggle/active semantics stay self-contained. */
.gallery-filter {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    line-height: 1;
    color: var(--color-primary);
    background-color: transparent;
    border: 2px solid var(--color-border-strong);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background-color var(--transition-base),
                color var(--transition-base),
                border-color var(--transition-base);
}

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

.gallery-filter:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}

.gallery-filter.is-active,
.gallery-filter[aria-pressed="true"] {
    color: var(--color-text-inverse);
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Count chip riding inside the pill. */
.gallery-filter__count {
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    padding: 0.1em 0.5em;
    border-radius: var(--radius-pill);
    background-color: color-mix(in srgb, var(--color-primary) 12%, transparent);
    color: inherit;
}
.gallery-filter.is-active .gallery-filter__count,
.gallery-filter[aria-pressed="true"] .gallery-filter__count {
    background-color: color-mix(in srgb, var(--color-white) 24%, transparent);
}

/* --- Grid ------------------------------------------------------------- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}
@media (min-width: 640px) {
    .gallery-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
    .gallery-grid { grid-template-columns: repeat(4, 1fr); }
}

/* --- Tiles (images + videos share the frame) -------------------------- */
.gallery-item {
    position: relative;
    display: block;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    text-decoration: none;
    transition: transform var(--transition-fast),
                box-shadow var(--transition-base);
}

.gallery-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.gallery-item:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}

/* Filter hide. The author rule on .gallery-item (display:block) would beat
   the UA [hidden] rule, so re-assert display:none explicitly. This is also
   what removes a tile from PhotoSwipe's :not([hidden]) children selector,
   so the lightbox navigates only the visible set. */
.gallery-item[hidden] { display: none; }

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--transition-slow);
}
.gallery-item:hover img { transform: scale(1.05); }

/* --- Video tile chrome ------------------------------------------------ */
/* Placeholder shown when no poster image exists beside the video: a deep
   teal field that reads as a video card without any broken-image box. */
.gallery-video__placeholder {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg,
        var(--color-primary) 0%,
        var(--color-accent) 100%);
}

/* Centred play badge over poster/placeholder. */
.gallery-item__play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-pill);
    background-color: color-mix(in srgb, var(--color-ink) 55%, transparent);
    color: var(--color-white);
    transition: background-color var(--transition-base),
                transform var(--transition-fast);
}
.gallery-item--video:hover .gallery-item__play {
    background-color: var(--color-accent);
    transform: translate(-50%, -50%) scale(1.08);
}
.gallery-item__play svg {
    width: 1.6rem;
    height: 1.6rem;
    /* nudge the triangle to look optically centred in the circle */
    margin-left: 0.15rem;
}

/* Small "Video" label, bottom-left, over a soft scrim. */
.gallery-item__label {
    position: absolute;
    left: var(--space-3);
    bottom: var(--space-3);
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--color-white);
    background-color: color-mix(in srgb, var(--color-ink) 60%, transparent);
    border-radius: var(--radius-sm);
}

/* --- Empty state ------------------------------------------------------ */
.gallery-empty {
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--fs-md);
    padding: var(--space-8) 0;
}
.gallery-empty[hidden] { display: none; }

/* =====================================================================
 * Video modal — bespoke, vanilla-JS. Built once in pages/gallery.js and
 * appended to <body>. Holds a <video controls preload="none"> so the
 * (large) .mp4 is only fetched once the user presses play.
 * ===================================================================== */
.video-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
}
.video-modal[hidden] { display: none; }

.video-modal__backdrop {
    position: absolute;
    inset: 0;
    background-color: color-mix(in srgb, var(--color-ink) 88%, transparent);
}

.video-modal__dialog {
    position: relative;
    z-index: 1;
    width: min(960px, 100%);
}

.video-modal__player video {
    display: block;
    width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-md);
    background-color: var(--color-ink);
    box-shadow: var(--shadow-lg);
}

.video-modal__close {
    position: absolute;
    top: calc(-1 * var(--space-7));
    right: 0;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    color: var(--color-white);
    background-color: color-mix(in srgb, var(--color-white) 14%, transparent);
    border: 0;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background-color var(--transition-base);
}
.video-modal__close:hover {
    background-color: color-mix(in srgb, var(--color-white) 28%, transparent);
}
.video-modal__close:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}
.video-modal__close svg {
    width: 1.4rem;
    height: 1.4rem;
}

/* Body scroll-lock while the modal is open (class toggled by gallery.js). */
.gallery-modal-open { overflow: hidden; }
