/* ---------- Video: every project in one mosaic, filtered by role ----------
   Covers keep their real shape, 16:9 for films and 1:1 for motion graphics, in
   justified rows: each row is one height and fills the width, with flexbox alone.
   After every few tiles a VFX breakdown takes almost the whole screen. */

.page-videos {
    /* Free space under the fixed navbar. */
    --videos-top: var(--header-h);
    /* Between tiles, both ways. */
    --gap: clamp(0.375rem, 0.8vw, 0.75rem);
}

.page-videos [hidden] {
    display: none !important;
}

.videos {
    padding-block: calc(var(--videos-top) + clamp(2rem, 5vw, 4.5rem)) clamp(4rem, 9vw, 8rem);
}

/* Mosaic blocks and breakdowns, one under the other. */
.videos__list {
    display: grid;
    gap: clamp(3rem, 8vw, 7rem);
}

.videos__message {
    margin: 0;
    font: 400 1rem/1.5 var(--f-sans);
    text-transform: uppercase;
}

/* ---------- Title and filters ---------- */
/* The title shares the about and contact pages' style (styles.css). */
.videos__head {
    display: grid;
    gap: clamp(1.5rem, 3vw, 2.5rem);
    margin-bottom: clamp(2rem, 4vw, 3.5rem);
}

/* Pills, one role at a time. Each is a radio: native keys, its pill shows the state. */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.filter {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    padding: 0 1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font: 400 0.75rem/1 var(--f-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.filter input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

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

/* Same as the site's buttons: accent, lighter on hover. */
.filter:has(:checked) {
    border-color: var(--c-accent);
    background-color: var(--c-accent);
    color: var(--c-ink);
}

.filter:has(:checked):hover {
    border-color: var(--c-accent-hi);
    background-color: var(--c-accent-hi);
}

.filter:has(:focus-visible) {
    outline: 2px solid var(--c-accent-hi);
    outline-offset: 3px;
}

/* ---------- Mosaic: justified rows ----------
   A tile's flex-grow and flex-basis both scale with its aspect ratio, so each row shares
   its free width out in proportion to the tiles' widths: every tile in a row comes out the
   same height and the row fills the width. Filtering lays the tiles out again. */
.mosaic {
    /* The lowest a row gets; most rows grow a little taller to fill the width. */
    --row: clamp(9rem, 19vw, 18rem);

    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
}

/* The last row keeps its tiles at --row while it has room for one more 16:9 tile, instead
   of stretching a few tiles huge. Nearly full, it fills the width like the rows above. */
.mosaic::after {
    content: "";
    flex: 1e6 1 calc(var(--row) * 16 / 9);
}

.tile {
    --ratio: 16 / 9;

    position: relative;
    flex: calc(var(--ratio) * 100) 1 calc(var(--ratio) * var(--row));
    aspect-ratio: var(--ratio);
    overflow: hidden;
    border-radius: 0.25rem;
    background: color-mix(in srgb, var(--c-ink) 6%, var(--c-bg));
}

.tile--square {
    --ratio: 1;
}

.tile > img,
.tile > video {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    object-fit: cover;
}

/* Clips show from their first frame on (video.js marks them); the preview only while hovered. */
.tile > video {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.tile__loop.is-ready,
.tile:is(:hover, :focus-visible) > .tile__preview.is-ready {
    opacity: 1;
}

/* Title and type over the bottom of the cover, on a shade that keeps them legible. */
.tile__caption {
    position: absolute;
    inset: auto 0 0;
    display: grid;
    gap: 0.375rem;
    padding: 3rem clamp(0.75rem, 1.2vw, 1.125rem) clamp(0.75rem, 1.2vw, 1rem);
    background: linear-gradient(rgb(0 0 0 / 0), rgb(0 0 0 / 0.7));
    color: var(--c-ink);
    text-shadow: 0 1px 10px rgb(0 0 0 / 0.4);
}

.tile__title {
    font-family: var(--f-display);
    font-weight: 900;
    font-synthesis: none;
    font-size: clamp(1rem, 1.4vw, 1.5rem);
    line-height: 0.95;
    text-transform: uppercase;
    text-wrap: balance;
}

.tile__meta {
    font: 400 0.6875rem/1.3 var(--f-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tile__meta:empty {
    display: none;
}

/* With a mouse the caption comes up on hover (and keyboard focus); on touch it always shows. */
@media (hover: hover) {
    .tile__caption {
        opacity: 0;
        translate: 0 0.75rem;
        transition: opacity 0.3s ease, translate 0.3s ease;
    }

    .tile:is(:hover, :focus-visible) .tile__caption {
        opacity: 1;
        translate: 0;
    }
}

/* Tiles rise in one after another: on load, and again each time a filter lays them out. */
@media (prefers-reduced-motion: no-preference) {
    .tile {
        animation: tile-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
        animation-delay: calc(min(var(--i, 0), 12) * 50ms);
    }
}

@keyframes tile-in {
    from {
        opacity: 0;
        translate: 0 1.25rem;
    }
}

/* ---------- VFX breakdown: before and after, split by a slider ----------
   Edge to edge and almost a screen tall. The after layer is cut at --split (video.js
   sets it from the slider), so the before layer shows on the left of the line. */
.vfx {
    --split: 50%;

    position: relative;
    height: max(16rem, min(85svh, 56.25vw));
    margin-inline: calc(-1 * var(--page-margin));
    overflow: hidden;
    background: #000000;
}

.vfx__layer {
    position: absolute;
    inset: 0;
}

/* Placeholders: a bare grid for the plate, a flat accent tone for the finished shot.
   A real breakdown puts an <img> or a <video> in each layer (object-fit: cover). */
.vfx__layer--before {
    --grid: color-mix(in srgb, var(--c-text) 10%, transparent);

    background:
        linear-gradient(90deg, var(--grid) 1px, transparent 1px) center / 4rem 4rem,
        linear-gradient(var(--grid) 1px, transparent 1px) center / 4rem 4rem,
        color-mix(in srgb, var(--c-bg) 70%, black);
}

.vfx__layer--after {
    clip-path: inset(0 0 0 var(--split));
    background: color-mix(in srgb, var(--c-accent) 45%, var(--c-bg));
}

.vfx__tag {
    position: absolute;
    top: clamp(1rem, 2.5vw, 1.75rem);
    color: var(--c-ink);
    font: 400 0.75rem/1 var(--f-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.vfx__layer--before .vfx__tag {
    left: var(--page-margin);
}

.vfx__layer--after .vfx__tag {
    right: var(--page-margin);
}

/* The slider covers the picture: invisible, but it takes the drags, the clicks and the keys.
   On touch screens a vertical swipe still scrolls the page. */
.vfx__range {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: ew-resize;
    touch-action: pan-y;
}

/* The line and its knob, on the split. */
.vfx__handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--split);
    width: 2px;
    translate: -50% 0;
    background: var(--c-ink);
    pointer-events: none;
}

.vfx__handle svg {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0.75rem;
    translate: -50% -50%;
    border-radius: 50%;
    background: var(--c-ink);
    fill: none;
    stroke: var(--c-bg);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* The slider itself can't be seen: its focus ring goes on the knob. */
.vfx__range:focus-visible + .vfx__handle svg {
    outline: 2px solid var(--c-ink);
    outline-offset: 3px;
}

/* Title over the bottom left; drags go through it to the slider. */
.vfx__caption {
    position: absolute;
    bottom: clamp(1.25rem, 3vw, 2.5rem);
    left: var(--page-margin);
    color: var(--c-ink);
    text-shadow: 0 2px 16px rgb(0 0 0 / 0.45);
    pointer-events: none;
}

.vfx__title {
    margin: 0;
    font-family: var(--f-display);
    font-weight: 900;
    font-synthesis: none;
    font-size: clamp(2rem, 5vw, 5rem);
    line-height: 0.9;
    text-transform: uppercase;
}

.vfx__note {
    margin: 0.75rem 0 0;
    font: 400 0.75rem/1.3 var(--f-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ---------- Small screens ---------- */
@media (max-width: 47.99em) {
    .page-videos {
        /* The navbar stacks the logo over the links here. */
        --videos-top: 7rem;
    }
}
