/* ==========================================================================
   Gallery — public styles
   ========================================================================== */
:root {
    --bg: #15171b;
    --bg-raised: #1c1f24;
    --line: #2b2f37;
    --text: #ece8e1;
    --muted: #9a9ea6;
    --accent: #c9b27c;
    --tile: #22262d;
    --gap: 8px;
    --cols: 4;
    --gutter: clamp(16px, 3.2vw, 48px);
    --max: 1680px;
    --sans: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
    --ease: cubic-bezier(.22, .61, .36, 1);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 90px; }
body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 var(--sans);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body.is-locked { overflow: hidden; }
img, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: 16px; top: -60px; z-index: 200; padding: 10px 14px; background: var(--accent); color: #17140d; border-radius: 4px; text-decoration: none; font-weight: 600; }
.skip:focus { top: 12px; }

/* ---------- Masthead ---------- */
.masthead {
    position: sticky; top: 0; z-index: 50;
    background: rgba(21, 23, 27, .88);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
    backdrop-filter: saturate(140%) blur(14px);
    border-bottom: 1px solid transparent;
    transition: border-color .25s;
}
.masthead.is-scrolled { border-bottom-color: var(--line); }
.masthead__inner {
    max-width: var(--max); margin: 0 auto;
    padding: 0 var(--gutter);
    min-height: 68px;
    display: flex; align-items: center; gap: 32px;
}
.wordmark {
    font-family: var(--serif);
    font-size: 1.75rem; line-height: 1;
    text-decoration: none; white-space: nowrap;
    letter-spacing: -.01em;
}
.filters {
    display: flex; gap: 4px; margin-left: auto;
    overflow-x: auto; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
            mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
    padding: 0 12px;
}
.filters::-webkit-scrollbar { display: none; }
.filter {
    flex: none;
    display: inline-flex; align-items: baseline; gap: 6px;
    padding: 8px 14px; border-radius: 99px;
    color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 500;
    transition: color .2s, background-color .2s;
}
.filter sup { font-size: 11px; font-weight: 400; opacity: .7; }
.filter:hover { color: var(--text); }
.filter[aria-current="page"] { color: var(--bg); background: var(--text); }

/* ---------- Layout ---------- */
.gallery { flex: 1; width: 100%; max-width: var(--max); margin: 0 auto; padding: clamp(24px, 4vw, 56px) var(--gutter) 0; outline: none; }

.section { padding-bottom: clamp(48px, 7vw, 104px); content-visibility: auto; contain-intrinsic-size: auto 900px; }
.section__head {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 6px 24px;
    padding-top: clamp(16px, 2vw, 24px); margin-bottom: clamp(14px, 2vw, 24px);
    border-top: 1px solid var(--line);
}
.section:first-child .section__head { border-top: 0; padding-top: 0; }
.section__title {
    margin: 0; min-width: 0;
    font-family: var(--serif); font-weight: 400;
    font-size: clamp(2rem, 4.2vw, 3.6rem); line-height: 1; letter-spacing: -.02em;
    overflow-wrap: anywhere;
}
.section__title a { text-decoration: none; transition: color .2s; }
.section__title a:hover { color: var(--accent); }
.section__count { color: var(--muted); font-size: 14px; white-space: nowrap; padding-bottom: 4px; }
.section__desc { grid-column: 1 / -1; margin: 4px 0 0; color: var(--muted); max-width: 62ch; }

/* ---------- Grid ---------- */
.grid-wrap { container-type: inline-size; }
.grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: 240px;
    grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols) * .8);
    grid-auto-flow: row dense;
    gap: var(--gap);
}
.tile--wide  { grid-column: span 2; }
.tile--tall  { grid-row: span 2; }
.tile--large { grid-column: span 2; grid-row: span 2; }

.tile {
    position: relative;
    display: block; width: 100%; height: 100%;
    margin: 0; padding: 0; border: 0;
    overflow: hidden; border-radius: 3px;
    background: var(--ph, var(--tile));
    cursor: zoom-in;
    isolation: isolate;
    -webkit-tap-highlight-color: transparent;
}
.tile img, .tile video {
    width: 100%; height: 100%;
    object-fit: cover;
    pointer-events: none;
    transition: transform .9s var(--ease), opacity .5s ease;
}
.tile img { opacity: 0; }
.tile img.is-loaded { opacity: 1; }
.tile:focus-visible { outline-offset: 2px; }

.tile__caption {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
    padding: 40px 16px 14px;
    background: linear-gradient(transparent, rgba(8, 9, 11, .72));
    font-size: 14px; font-weight: 500; text-align: left;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transform: translateY(6px);
    transition: opacity .3s, transform .3s var(--ease);
    pointer-events: none;
}

/* Video tiles */
.tile--video { cursor: pointer; }
.tile__play {
    position: absolute; inset: 0; z-index: 1;
    display: grid; place-items: center;
    background: rgba(8, 9, 11, .12);
    transition: background-color .25s;
}
.tile__play-icon {
    width: 56px; height: 56px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(236, 232, 225, .16);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    border: 1px solid rgba(236, 232, 225, .5);
    transition: transform .25s var(--ease), background-color .25s;
}
.tile__play-icon svg { margin-left: 3px; }
.tile__duration {
    position: absolute; top: 10px; right: 10px; z-index: 2;
    padding: 2px 8px; border-radius: 4px;
    background: rgba(8, 9, 11, .62);
    font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
}

/* Hover effects only where a real pointer exists; touch screens show captions all the time. */
@media (hover: hover) {
    .tile:hover img, .tile:focus-visible img { transform: scale(1.025); }
    .tile:hover .tile__caption, .tile:focus-visible .tile__caption { opacity: 1; transform: none; }
    .tile--video:hover .tile__play { background: rgba(8, 9, 11, .3); }
    .tile--video:hover .tile__play-icon { transform: scale(1.08); background: rgba(236, 232, 225, .28); }
}
@media (hover: none) {
    .tile__caption { opacity: 1; transform: none; padding: 28px 10px 8px; font-size: 13px; }
}

/* ---------- Empty / loading ---------- */
.empty { padding: clamp(72px, 14vw, 140px) 0; text-align: center; color: var(--muted); }
.empty h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(2rem, 5vw, 2.6rem); color: var(--text); margin: 0 0 8px; }
.empty a { color: var(--accent); }
.skeleton__title { width: min(320px, 60%); height: clamp(2rem, 4.2vw, 3.6rem); border-radius: 4px; background: var(--bg-raised); margin-bottom: clamp(14px, 2vw, 24px); }
.skeleton .grid i { display: block; background: var(--bg-raised); border-radius: 3px; }

.footer {
    max-width: var(--max); width: 100%; margin: 0 auto;
    padding: 28px var(--gutter) 40px;
    color: var(--muted); font-size: 13px;
    border-top: 1px solid var(--line);
}

/* ==========================================================================
   Viewer (lightbox)
   ========================================================================== */
.viewer {
    position: fixed; inset: 0; z-index: 100;
    height: 100vh; height: 100dvh;
    display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
    overscroll-behavior: contain;
    background: #0e0f12;
    opacity: 0; transition: opacity .25s ease;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.viewer.is-open { opacity: 1; }
.viewer__top {
    display: flex; align-items: center; gap: 16px;
    padding: 14px clamp(16px, 2.5vw, 28px);
    min-height: 68px;
}
.viewer__caption { margin: 0; flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 16px; }
.viewer__count { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.viewer__title { font-family: var(--serif); font-size: 1.45rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer__close {
    flex: none; width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(236, 232, 225, .08); border: 1px solid rgba(236, 232, 225, .16);
    cursor: pointer; transition: background-color .2s, transform .2s var(--ease);
}
.viewer__close:hover { background: rgba(236, 232, 225, .18); transform: rotate(90deg); }

.viewer__stage {
    position: relative; min-height: 0;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center;
    touch-action: pan-y pinch-zoom;
}
.viewer__frame {
    position: relative; align-self: stretch; min-width: 0; min-height: 0;
    display: grid; place-items: center;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    padding: 0 8px;
}
.viewer__frame > * { grid-area: 1 / 1; }
.viewer__frame img, .viewer__frame video {
    max-width: 100%; max-height: 100%;
    width: auto; height: auto;
    object-fit: contain;
    border-radius: 2px;
    box-shadow: 0 30px 90px rgba(0, 0, 0, .55);
}
.viewer__frame video { background: #000; }
.viewer__frame .is-full { opacity: 0; transition: opacity .3s ease; }
.viewer__frame .is-full.is-loaded { opacity: 1; }
.viewer__frame.is-entering > * { animation: viewer-in .35s var(--ease); }
@keyframes viewer-in { from { opacity: 0; transform: scale(.975); } }

.viewer__nav {
    width: 56px; height: 56px; margin: 0 clamp(4px, 1.5vw, 20px);
    display: grid; place-items: center;
    border-radius: 50%; border: 0; cursor: pointer;
    background: transparent; color: var(--text);
    transition: background-color .2s;
}
.viewer__nav:hover { background: rgba(236, 232, 225, .1); }
.viewer__nav:disabled { opacity: .2; cursor: default; background: none; }

.viewer__strip {
    display: flex; gap: 6px;
    padding: 14px clamp(16px, 2.5vw, 28px) 18px;
    overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent;
    justify-content: safe center;
}
.viewer__thumb {
    flex: none; position: relative;
    width: 64px; height: 48px; padding: 0;
    border: 0; border-radius: 2px; overflow: hidden; cursor: pointer;
    background: var(--ph, var(--tile));
    opacity: .4; transition: opacity .2s;
}
.viewer__thumb img { width: 100%; height: 100%; object-fit: cover; }
.viewer__thumb:hover { opacity: .8; }
.viewer__thumb[aria-current="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--text); }
.viewer__thumb--video::after {
    content: ''; position: absolute; left: 50%; top: 50%;
    border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
    transform: translate(-35%, -50%);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 2200px) { :root { --cols: 6; --max: 2240px; --gap: 10px; } }
@media (min-width: 1500px) and (max-width: 2199px) { :root { --cols: 5; } }
@media (max-width: 1100px) { :root { --cols: 3; } }

/* Phones and small tablets */
@media (max-width: 720px) {
    :root { --cols: 2; --gap: 6px; }
    .masthead__inner {
        flex-direction: column; align-items: stretch; gap: 6px;
        padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 8px; min-height: 0;
    }
    .wordmark { font-size: 1.55rem; }
    .filters { margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); }
    .filter { padding: 9px 14px; font-size: 14px; }
    .section__count { font-size: 13px; }
    .tile__play-icon { width: 46px; height: 46px; }
    .tile__duration { top: 6px; right: 6px; font-size: 11px; padding: 1px 6px; }

    .viewer__top { min-height: 56px; padding: 8px 12px 8px 16px; }
    .viewer__close { width: 42px; height: 42px; }
    .viewer__title { font-size: 1.15rem; }
    .viewer__stage { grid-template-columns: minmax(0, 1fr); }
    .viewer__frame { padding: 0; }
    .viewer__frame img, .viewer__frame video { border-radius: 0; box-shadow: none; }
    /* Arrows float over the media so it can use the full width. */
    .viewer__nav {
        position: absolute; top: 50%; z-index: 2; margin: 0;
        width: 42px; height: 42px; transform: translateY(-50%);
        background: rgba(8, 9, 11, .5);
        -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    }
    .viewer__nav--prev { left: 8px; }
    .viewer__nav--next { right: 8px; }
    .viewer__nav:disabled { display: none; }
    .viewer__strip { padding: 10px 12px 14px; justify-content: flex-start; }
    .viewer__thumb { width: 48px; height: 36px; }
}

/* Small phones */
@media (max-width: 360px) {
    :root { --gap: 4px; --gutter: 12px; }
    .section__head { grid-template-columns: minmax(0, 1fr); }
    .section__count { padding: 0; }
}

/* Phones held sideways and other short screens: give the media all the height. */
@media (max-height: 520px) and (orientation: landscape) {
    .masthead { position: static; }
    .viewer__strip { display: none; }
    .viewer__top { min-height: 0; padding-top: 6px; padding-bottom: 6px; }
    .viewer__close { width: 38px; height: 38px; }
    .viewer__stage { grid-template-columns: auto minmax(0, 1fr) auto; }
    .viewer__nav { position: static; transform: none; margin: 0 6px; }
    .viewer__nav:disabled { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
    html { scroll-behavior: auto; }
}
