/* Public portfolio gallery: category filters, media grid, lightbox.
   Uses the site's --c-* tokens so it follows the dark/light theme automatically. */

/* ── Filter bar ─────────────────────────────────────────────────────────── */
.gal-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin: 0 auto 40px;
    max-width: 1180px;
}

.gal-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1px solid var(--c-border);
    border-radius: 999px;
    background: var(--c-surface);
    color: var(--c-text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.gal-filter:hover,
.gal-filter:focus-visible {
    border-color: var(--c-border-hover);
    background: var(--c-surface-hover);
    color: var(--c-text);
    outline: none;
}

.gal-filter[aria-pressed="true"] {
    border-color: transparent;
    background: var(--c-primary);
    color: #fff;
}

.gal-filter-count {
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.76rem;
    font-weight: 700;
}

.gal-filter[aria-pressed="false"] .gal-filter-count {
    background: var(--c-surface-hover);
}

/* ── Sections ───────────────────────────────────────────────────────────── */
.gal-page { max-width: 1320px; margin: 0 auto; }

.gal-section { scroll-margin-top: calc(var(--nav-height, 72px) + 16px); }
.gal-section[hidden] { display: none; }

/* Only "All work" needs separators between categories. */
.gal-sections--all .gal-section + .gal-section {
    margin-top: 64px;
    padding-top: 56px;
    border-top: 1px solid var(--c-border);
}

.gal-section-head { margin-bottom: 22px; }

.gal-section-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 12px;
}

.gal-section-title h2 {
    margin: 0;
    font-size: clamp(1.35rem, 2.4vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

/* An accent rule under the heading, so a category reads as a chapter rather than a caption. */
.gal-section-title h2::after {
    content: "";
    display: block;
    width: 46px;
    height: 3px;
    margin-top: 10px;
    border-radius: 999px;
    background: var(--c-primary);
}

.gal-section-count {
    padding: 3px 11px;
    border-radius: 999px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    color: var(--c-text-secondary);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.gal-section-desc {
    margin: 10px 0 0;
    max-width: 70ch;
    color: var(--c-text-muted);
    font-size: 0.94rem;
    line-height: 1.55;
}

/* A single category is shown on its own; the active filter already names it. */
.gal-section--solo .gal-section-head { display: none; }

/* Subcategory blocks inside a section. The category heading is the loud one; a subcategory is
   deliberately quieter so the page reads as chapters and sub-headings, not a wall of titles. */
.gal-group { margin-top: 30px; }
.gal-group:first-of-type { margin-top: 0; }
.gal-group[hidden] { display: none; }

.gal-group-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 14px;
    color: var(--c-text-secondary);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* A short leading dash instead of another underline, so it cannot compete with the h2 rule. */
.gal-group-title::before {
    content: "";
    flex: 0 0 auto;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: var(--c-primary);
    opacity: 0.75;
}

.gal-group-count {
    color: var(--c-text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0;
}

/* ── Subcategory filter (inside a section) ──────────────────────────────── */
.gal-subfilters {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 16px;
}

.gal-subfilter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--c-border);
    border-radius: 999px;
    background: transparent;
    color: var(--c-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.gal-subfilter:hover,
.gal-subfilter:focus-visible {
    border-color: var(--c-border-hover);
    color: var(--c-text);
    outline: none;
}

.gal-subfilter[aria-pressed="true"] {
    border-color: var(--c-primary);
    background: rgba(59, 130, 246, 0.12);
    color: var(--c-text);
}

.gal-subfilter-count { font-size: 0.74rem; opacity: 0.75; }

/* ── Grid ───────────────────────────────────────────────────────────────── */
.gal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(200px, 22vw, 300px), 1fr));
    gap: 18px;
}

.gal-item {
    position: relative;
    display: block;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--c-border);
    /* 12px: tighter than a content card (16px) because the grid is dense, but not sharp. */
    border-radius: 12px;
    background: var(--c-surface-solid);
    cursor: zoom-in;
    padding: 0;
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.gal-item:hover,
.gal-item:focus-visible {
    transform: translateY(-3px);
    border-color: var(--c-border-hover);
    box-shadow: var(--shadow-md);
    outline: none;
}

.gal-item[hidden] { display: none; }

.gal-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.gal-item:hover img { transform: scale(1.05); }

/* Placeholder tint until the lazy image paints, so the grid never flashes white. */
.gal-item img:not(.is-loaded) { opacity: 0; }
.gal-item img.is-loaded { opacity: 1; transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.4, 0, 0.2, 1); }

.gal-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 26px 14px 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: left;
    line-height: 1.35;
}

.gal-overlay small {
    display: block;
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.76rem;
    font-weight: 500;
}

.gal-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.68);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 700;
    backdrop-filter: blur(6px);
}

.gal-play {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.gal-play i {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 1.6rem;
    backdrop-filter: blur(6px);
    transition: transform var(--transition), background var(--transition);
}

.gal-item:hover .gal-play i { transform: scale(1.08); background: var(--c-primary); }

.gal-empty-filter {
    padding: 48px 16px;
    color: var(--c-text-muted);
    text-align: center;
}

/* ── Lightbox ───────────────────────────────────────────────────────────── */
/* Both elements, deliberately: style.css sets `html { overflow-x: hidden }`, which stops a plain
   `body { overflow: hidden }` from propagating to the viewport — the page would still scroll
   behind an open viewer. */
html.gal-open,
body.gal-open {
    overflow: hidden;
    overscroll-behavior: none;
}

.gal-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    /* minmax(0, 1fr), never a bare 1fr: an `auto` minimum lets the track grow to the intrinsic
       height of a 4000px photo, which is what pushed the image off-screen. */
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh; /* mobile: excludes the browser's own collapsing chrome */
    overflow: hidden;
    overscroll-behavior: contain;
    background: rgba(6, 6, 12, 0.96);
    backdrop-filter: blur(8px);
}

.gal-lightbox[hidden] { display: none; }

.gal-lb-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 0.88rem;
}

/* Flex, not grid: a percentage max-height on a grid item resolves against its grid AREA, and an
   implicit `auto` row makes that area indefinite — so `max-height: 100%` was silently ignored and
   the browser used the photo's full intrinsic size. A flex item resolves it against the container,
   which minmax(0, 1fr) above has already made definite. */
.gal-lb-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: 0 12px;
}

.gal-lb-stage img,
.gal-lb-stage video {
    /* Two independent caps; the smaller wins. The percentages keep the media inside the row even
       when the caption is tall, and the viewport units are a hard guarantee that survives any
       future layout change. Portrait photos are bounded by the same rule as landscape ones. */
    max-width: min(100%, 94vw);
    max-height: min(100%, 88vh);
    width: auto;
    height: auto;
    border-radius: var(--radius-sm);
    background: #000;
    object-fit: contain; /* never stretch or distort */
}

.gal-lb-caption {
    padding: 14px 18px 22px;
    color: #fff;
    text-align: center;
}

.gal-lb-caption strong { display: block; font-size: 1rem; }
.gal-lb-caption span { color: rgba(255, 255, 255, 0.66); font-size: 0.84rem; }

.gal-lb-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}

.gal-lb-btn:hover,
.gal-lb-btn:focus-visible { background: rgba(255, 255, 255, 0.2); outline: none; }
.gal-lb-btn:disabled { opacity: 0.3; cursor: default; }

.gal-lb-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
}

.gal-lb-prev { left: 10px; }
.gal-lb-next { right: 10px; }

.gal-lb-spinner {
    position: absolute;
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: gal-spin 0.8s linear infinite;
}

.gal-lb-spinner[hidden] { display: none; }

@keyframes gal-spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────────────────────────── */
/* Large screens: cap the column count so tiles never stretch into letterboxes. */
@media (min-width: 1500px) {
    .gal-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; }
}

/* Tablets */
@media (max-width: 1024px) {
    .gal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
    .gal-sections--all .gal-section + .gal-section { margin-top: 48px; padding-top: 42px; }
}

@media (max-width: 760px) {
    .gal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

@media (max-width: 600px) {
    .gal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
    .gal-section-head { margin-bottom: 16px; }
    .gal-section-desc { display: none; }
    .gal-group { margin-top: 22px; }
    .gal-group-title { font-size: 0.84rem; margin-bottom: 10px; }
    /* Keep the sub-filter on one scrollable line rather than stacking into a block of pills. */
    .gal-subfilters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
    .gal-subfilters::-webkit-scrollbar { display: none; }
    .gal-subfilter { flex: 0 0 auto; }
    .gal-sections--all .gal-section + .gal-section { margin-top: 36px; padding-top: 30px; }
    .gal-filters { gap: 7px; margin-bottom: 20px; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
    .gal-filters::-webkit-scrollbar { display: none; }
    .gal-filter { flex: 0 0 auto; padding: 8px 13px; font-size: 0.84rem; }
    .gal-overlay { padding: 20px 9px 8px; font-size: 0.78rem; }
    .gal-overlay small { display: none; }
    .gal-play i { width: 44px; height: 44px; font-size: 1.2rem; }
    .gal-lb-nav { width: 38px; height: 38px; }
    .gal-lb-caption { padding: 10px 14px 18px; }
}

@media (prefers-reduced-motion: reduce) {
    .gal-item, .gal-item img, .gal-play i { transition: none; }
    .gal-item:hover { transform: none; }
    .gal-item:hover img { transform: none; }
    .gal-lb-spinner { animation-duration: 2s; }
}
