/* =============================================================================
   The Artifact Wall (gallery.html)
   Loaded after er33t.css and scoped to .gallery-page, so the shared
   .filter-btn / .toolbar / .lightbox rules other pages use stay untouched.
   Markup for tiles and the viewer is built by the gallery section of
   /script.js.
   ========================================================================== */

.gallery-page {
    --wall-gap: 12px;
    --wall-radius: 14px;
    --wall-glass: color-mix(in srgb, var(--bg) 72%, transparent);
}

/* --- Hero ---------------------------------------------------------------- */
.gallery-page .gallery-hero {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    padding: clamp(40px, 6vw, 88px) 0 clamp(28px, 4vw, 48px);
}

.gallery-page .gallery-hero__ambient {
    position: absolute;
    inset: -10% -5%;
    z-index: -1;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 18px;
    align-items: center;
    transform: rotate(-6deg) scale(1.1);
    pointer-events: none;
    mask-image: radial-gradient(ellipse 70% 80% at 75% 45%, #000 0%, transparent 72%);
    -webkit-mask-image: radial-gradient(ellipse 70% 80% at 75% 45%, #000 0%, transparent 72%);
}

.gallery-page .gallery-hero__ambient::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 82%, transparent) 45%, color-mix(in srgb, var(--bg) 40%, transparent) 100%);
}

.gallery-page .gallery-hero__ambient img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: var(--wall-radius);
    opacity: 0;
    filter: saturate(1.1);
    transform: translateY(calc((var(--i) - 2.5) * 6%));
    transition: opacity 1.2s var(--ease);
    transition-delay: calc(var(--i) * 120ms);
    animation: wall-drift 26s ease-in-out infinite alternate;
    animation-delay: calc(var(--i) * -4s);
}

.gallery-page .gallery-hero__ambient img.is-loaded {
    opacity: 0.55;
}

@keyframes wall-drift {
    from { translate: 0 -4%; }
    to { translate: 0 4%; }
}

.gallery-page .gallery-hero__inner {
    display: grid;
    gap: var(--s-6);
    align-items: end;
}

@media (min-width: 900px) {
    .gallery-page .gallery-hero__inner {
        grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    }
}

.gallery-page .gallery-hero__copy h1 {
    margin: var(--s-3) 0 var(--s-4);
    font-size: var(--t-6);
    line-height: 0.95;
    letter-spacing: -0.03em;
    background: linear-gradient(100deg, var(--fg) 30%, var(--signal) 70%, var(--fg) 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: wall-sheen 9s ease-in-out infinite;
}

@keyframes wall-sheen {
    0%, 100% { background-position: 100% 0; }
    50% { background-position: 0 0; }
}

.gallery-page .gallery-hero__copy .lede {
    max-width: 58ch;
    color: var(--fg-muted);
}

.gallery-page .gallery-hero__side {
    display: grid;
    gap: var(--s-4);
    justify-items: start;
}

@media (min-width: 900px) {
    .gallery-page .gallery-hero__side {
        justify-items: end;
    }
}

.gallery-page .gallery-stats {
    display: flex;
    gap: 1px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--wall-radius);
    overflow: hidden;
    background: var(--line);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.gallery-page .gallery-stats > div {
    padding: var(--s-3) var(--s-5);
    background: var(--wall-glass);
}

.gallery-page .gallery-stats dt {
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--fg-subtle);
}

.gallery-page .gallery-stats dd {
    margin: 2px 0 0;
    font-family: var(--mono);
    font-size: var(--t-2);
    font-variant-numeric: tabular-nums;
    color: var(--fg);
}

.gallery-page .gallery-stats > div:first-child dd {
    color: var(--signal);
}

.gallery-page .gallery-surprise {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
}

.gallery-page .gallery-surprise:disabled {
    opacity: 0.5;
    cursor: progress;
}

/* --- Sticky toolbar ------------------------------------------------------ */
.gallery-page .gallery-wall {
    padding-bottom: var(--section-y);
}

.gallery-page .gallery-toolbar__pin {
    height: 1px;
    margin-bottom: -1px;
}

.gallery-page .gallery-toolbar {
    position: sticky;
    top: var(--er33t-header-height, 64px);
    z-index: 30;
    /* The phone layout scrolls the controls sideways inside __inner; clip
       here too, or the overflow still widens the mobile layout viewport. */
    overflow-x: clip;
    padding: var(--s-3) 0;
    margin-bottom: var(--s-4);
    border-block: 1px solid transparent;
    transition: background 0.25s ease, border-color 0.25s ease;
}

.gallery-page .gallery-toolbar.is-stuck {
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    border-bottom-color: var(--line);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
}

.gallery-page .gallery-toolbar__inner,
.gallery-page .gallery-toolbar__end {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
}

.gallery-page .gallery-seg {
    display: inline-flex;
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: var(--bg-raised);
}

.gallery-page .gallery-seg--icons {
    flex-wrap: nowrap;
    flex: none;
}

.gallery-page .gallery-seg .filter-btn,
.gallery-page .gallery-seg .sort-btn,
.gallery-page .gallery-seg .edgy-btn,
.gallery-page .gallery-seg .density-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--r-full);
    background: transparent;
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--fg-muted);
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.gallery-page .gallery-seg .density-btn {
    padding: 0 10px;
}

.gallery-page .gallery-seg .density-btn svg {
    fill: currentColor;
}

.gallery-page .gallery-seg button:hover {
    color: var(--fg);
}

.gallery-page .gallery-seg button[aria-pressed='true'] {
    color: var(--signal-ink);
    background: var(--signal);
    box-shadow: 0 0 18px var(--signal-a32);
}

.gallery-page .gallery-seg button:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 2px;
}

.gallery-page .gallery-seg__count {
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

.gallery-page .gallery-seg__count:empty {
    display: none;
}

@media (max-width: 720px) {
    /* Wrap instead of clipping, so every control stays reachable (#679). */
    .gallery-page .gallery-toolbar__inner {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: var(--s-2);
        row-gap: var(--s-2);
    }
    .gallery-page .gallery-toolbar__end {
        width: 100%;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: var(--s-2);
        row-gap: var(--s-2);
    }
    .gallery-page .gallery-seg { flex: 0 1 auto; }
    .gallery-page .gallery-seg .filter-btn,
    .gallery-page .gallery-seg .sort-btn,
    .gallery-page .gallery-seg .edgy-btn {
        padding: 0 10px;
        gap: 4px;
        font-size: 0.65rem;
        letter-spacing: 0.05em;
    }
}

@media (max-width: 390px) {
    .gallery-page .gallery-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }
    .gallery-page .gallery-stats > div {
        min-width: 0;
        padding: var(--s-3) var(--s-2);
    }
    .gallery-page .gallery-toolbar__inner > .gallery-seg {
        width: 100%;
    }
    .gallery-page .gallery-toolbar__inner > .gallery-seg .filter-btn {
        flex: 1 1 0;
        padding: 0 8px;
    }
    .gallery-page .gallery-seg .sort-btn,
    .gallery-page .gallery-seg .edgy-btn {
        padding: 0 7px;
        font-size: 0.61rem;
        letter-spacing: 0.03em;
    }
}

.gallery-page .gallery-notice {
    margin: 0 0 var(--s-4);
    padding: var(--s-3) var(--s-4);
    border: 1px solid var(--line);
    border-left: 3px solid var(--signal);
    border-radius: var(--r-2);
    background: var(--bg-raised);
    color: var(--fg-muted);
}

/* --- Bento grid ---------------------------------------------------------- */
.gallery-page .gallery-grid {
    display: grid;
    gap: var(--wall-gap);
    grid-template-columns: repeat(auto-fill, minmax(min(46%, 220px), 1fr));
    grid-auto-flow: dense;
}

.gallery-page .gallery-grid[data-density='dense'] {
    --wall-gap: 6px;
    --wall-radius: 8px;
    grid-template-columns: repeat(auto-fill, minmax(min(31%, 120px), 1fr));
}

.gallery-page .gallery-item {
    --mx: 50%;
    --my: 50%;
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--wall-radius);
    overflow: hidden;
    border: 0;
    background:
        linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.05) 50%, transparent 70%) 0 0 / 250% 100%,
        var(--bg-inset);
    animation: wall-shimmer 1.6s linear infinite, wall-in 0.6s var(--ease) both;
    animation-delay: 0s, calc(min(var(--i, 0), 24) * 28ms);
    cursor: zoom-in;
    transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

.gallery-page .gallery-item.is-loaded {
    animation: wall-in 0.6s var(--ease) both;
    animation-delay: calc(min(var(--i, 0), 24) * 28ms);
    background: var(--bg-inset);
}

@keyframes wall-shimmer {
    to { background-position: -150% 0, 0 0; }
}

@keyframes wall-in {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.gallery-page .gallery-grid[data-density='cozy'] .gallery-item--feature {
    grid-column: span 2;
    grid-row: span 2;
}

/* Rim light + spotlight that follow the pointer. */
.gallery-page .gallery-item::before,
.gallery-page .gallery-item::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-page .gallery-item::before {
    background: radial-gradient(420px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.12), transparent 45%);
}

.gallery-page .gallery-item::after {
    padding: 1px;
    background: radial-gradient(260px circle at var(--mx) var(--my), var(--signal), transparent 60%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

.gallery-page .gallery-item:hover,
.gallery-page .gallery-item:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--signal-a16);
    z-index: 3;
}

.gallery-page .gallery-item:hover::before,
.gallery-page .gallery-item:hover::after,
.gallery-page .gallery-item:focus-visible::after {
    opacity: 1;
}

.gallery-page .gallery-item:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 2px;
}

.gallery-page .gallery-media {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 22%;
    opacity: 0;
    filter: blur(14px);
    transform: scale(1.06);
    transition: opacity 0.6s var(--ease), filter 0.8s var(--ease), transform 0.8s var(--ease);
}

.gallery-page .gallery-item--text-heavy .gallery-media,
.gallery-page .gallery-item--wide-aspect .gallery-media {
    object-fit: contain;
    object-position: center;
    background: radial-gradient(circle at 50% 35%, rgba(0, 255, 65, 0.06), rgba(5, 6, 8, 0.94));
}

@media (max-width: 720px) {
    .gallery-page .gallery-item--feature .gallery-media {
        object-position: center 18%;
    }
}

.gallery-page .gallery-item.is-loaded .gallery-media {
    opacity: 1;
    filter: none;
    transform: none;
}

.gallery-page .gallery-item.is-loaded:hover .gallery-media {
    transform: scale(1.045);
}

/* Meta fades up from a bottom scrim on hover. */
.gallery-page .gallery-overlay {
    position: absolute;
    inset: auto 0 0 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: 36px var(--s-3) var(--s-3);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.3s var(--ease);
}

.gallery-page .gallery-item:hover .gallery-overlay,
.gallery-page .gallery-item:focus-visible .gallery-overlay {
    opacity: 1;
    transform: none;
}

@media (hover: none) {
    .gallery-page .gallery-overlay {
        opacity: 1;
        transform: none;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
    }
    .gallery-page .gallery-date { display: none; }
}

.gallery-page .gallery-type {
    padding: 2px 8px;
    border-radius: var(--r-full);
    background: rgba(0, 0, 0, 0.55);
    font-family: var(--mono);
    font-size: 0.56rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--fg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.gallery-page .gallery-date {
    font-family: var(--mono);
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.78);
}

.gallery-page .gallery-likes-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: var(--r-full);
    background: rgba(0, 0, 0, 0.62);
    border: 1px solid rgba(255, 92, 107, 0.35);
    font-family: var(--mono);
    font-size: 0.58rem;
    font-variant-numeric: tabular-nums;
    color: var(--fg);
}

.gallery-page .gallery-likes-badge[hidden] {
    display: none;
}

.gallery-page .gallery-likes-badge .heart-icon {
    width: 11px;
    height: 11px;
    fill: var(--danger);
    stroke: var(--danger);
}

.gallery-page .gallery-grid[data-sort='top'] .gallery-item.has-likes .gallery-overlay {
    opacity: 1;
    transform: none;
}

.gallery-page .gallery-grid[data-density='dense'] .gallery-overlay,
.gallery-page .gallery-grid[data-density='dense'] .play-overlay {
    display: none;
}

.gallery-page .play-overlay {
    position: absolute;
    top: var(--s-2);
    left: var(--s-2);
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.gallery-page .play-overlay svg {
    display: block;
    width: 28px;
    height: 28px;
    padding: 7px;
    border-radius: var(--r-full);
    background: rgba(0, 0, 0, 0.55);
    fill: var(--fg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.gallery-page .gallery-item:hover .play-overlay {
    opacity: 0;
}

.gallery-page .gallery-item .like-btn {
    position: absolute;
    right: var(--s-2);
    bottom: var(--s-2);
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    min-width: 30px;
    justify-content: center;
    padding: 0 9px;
    border: 0;
    border-radius: var(--r-full);
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-family: var(--mono);
    font-size: 0.64rem;
    font-variant-numeric: tabular-nums;
    color: var(--fg);
    cursor: pointer;
    transition: color 0.18s ease, transform 0.2s var(--ease), background 0.18s ease;
}

.gallery-page .gallery-item .like-btn:hover {
    transform: scale(1.08);
    background: rgba(0, 0, 0, 0.75);
}

.gallery-page .like-count:empty {
    display: none;
}

.gallery-page .gallery-grid[data-density='dense'] .like-btn:not(.liked):not(:has(.like-count:not(:empty))) {
    opacity: 0;
}

.gallery-page .gallery-grid[data-density='dense'] .gallery-item.has-likes .like-btn,
.gallery-page .gallery-grid[data-density='dense'][data-sort='top'] .like-btn,
.gallery-page .gallery-grid[data-density='dense'] .gallery-item:hover .like-btn {
    opacity: 1;
}

@media (max-width: 720px) {
    .gallery-page .gallery-item .like-btn {
        min-height: 26px;
        min-width: 26px;
        padding: 0 7px;
        font-size: 0.6rem;
    }
}

.gallery-page .heart-icon {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

.gallery-page .liked {
    color: var(--danger);
}

.gallery-page .liked .heart-icon {
    fill: currentColor;
    animation: heart-pop 0.45s var(--ease);
}

@keyframes heart-pop {
    40% { transform: scale(1.35); }
}

.gallery-page .like-burst {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 6;
    width: 96px;
    height: 96px;
    margin: -48px 0 0 -48px;
    pointer-events: none;
    animation: like-burst 0.8s var(--ease) forwards;
}

.gallery-page .like-burst svg {
    width: 100%;
    height: 100%;
    fill: var(--danger);
    filter: drop-shadow(0 0 24px rgba(255, 92, 107, 0.7));
}

@keyframes like-burst {
    0% { opacity: 0; transform: scale(0.3); }
    25% { opacity: 1; transform: scale(1.1); }
    45% { transform: scale(0.95); }
    100% { opacity: 0; transform: scale(1.4) translateY(-24px); }
}

.gallery-page .gallery-missing {
    display: grid;
    place-content: center;
    height: 100%;
    font-family: var(--mono);
    font-size: 0.66rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--fg-subtle);
}

/* --- Load more / progress ------------------------------------------------ */
.gallery-page .gallery-controls {
    margin-top: var(--s-7);
    text-align: center;
}

.gallery-page .gallery-progress {
    margin: 0 0 var(--s-3);
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--fg-subtle);
}

.gallery-page .gallery-footnote {
    max-width: 62ch;
    margin: var(--s-7) auto 0;
    text-align: center;
    font-size: var(--t--1);
    color: var(--fg-subtle);
}

/* --- Viewer -------------------------------------------------------------- */
.gallery-page .lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    grid-template-columns: 64px minmax(0, 1fr) 64px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    align-items: center;
    padding: 0;
    gap: 0;
    background: rgba(3, 4, 6, 0.9);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    overflow: hidden;
}

.gallery-page .lightbox.active {
    display: grid;
    animation: viewer-in 0.35s var(--ease);
}

@keyframes viewer-in {
    from { opacity: 0; }
}

/* Ambient mode: the current artifact, blown up and blurred, lights the room. */
.gallery-page .lightbox-ambient {
    position: absolute;
    inset: -15%;
    z-index: -1;
    background-size: cover;
    background-position: center;
    filter: blur(80px) saturate(1.6);
    opacity: 0.45;
    transition: background-image 0.5s ease;
}

.gallery-page .lightbox-bar {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
}

.gallery-page .lightbox-meta {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin: 0;
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--fg-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.gallery-page .lightbox-counter {
    display: inline-block;
    min-width: var(--counter-min-ch, 8ch);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    color: var(--fg);
}

.gallery-page .lightbox-chip {
    padding: 2px 8px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-full);
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.gallery-page .lightbox-actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

.gallery-page .lightbox-action,
.gallery-page .lightbox-close,
.gallery-page .lightbox-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--r-full);
    background: rgba(255, 255, 255, 0.06);
    color: var(--fg);
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-decoration: none;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.2s var(--ease);
}

.gallery-page .lightbox-close {
    position: static;
    padding: 0;
    width: 40px;
}

.gallery-page .lightbox-action svg,
.gallery-page .lightbox-close svg,
.gallery-page .lightbox-nav svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.gallery-page .lightbox-action .heart-icon {
    width: 16px;
    height: 16px;
}

.gallery-page .lightbox-action:hover,
.gallery-page .lightbox-close:hover,
.gallery-page .lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--signal-a32);
}

.gallery-page .lightbox-action.liked {
    color: var(--danger);
    border-color: rgba(255, 92, 107, 0.4);
}

.gallery-page .lightbox-share.is-done {
    color: var(--signal);
    border-color: var(--signal-a32);
}

.gallery-page .lightbox-action:focus-visible,
.gallery-page .lightbox-close:focus-visible,
.gallery-page .lightbox-nav:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 2px;
}

.gallery-page .lightbox-nav {
    grid-row: 2;
    justify-self: center;
    width: 48px;
    height: 48px;
    padding: 0;
}

.gallery-page .lightbox-nav svg {
    width: 20px;
    height: 20px;
}

.gallery-page .lightbox-prev { grid-column: 1; }
.gallery-page .lightbox-next { grid-column: 3; }

.gallery-page .lightbox-content {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    min-height: 0;
    padding: var(--s-2) 0;
    touch-action: pan-y pinch-zoom;
}

.gallery-page #lightbox-media {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    place-items: center;
    width: 100%;
    height: 100%;
    min-height: 0;
    container-type: size;
    transition: transform 0.3s var(--ease);
}

.gallery-page #lightbox-media > * {
    grid-area: 1 / 1;
}

.gallery-page #lightbox-media img,
.gallery-page #lightbox-media video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    object-fit: contain;
}

.gallery-page #lightbox-media .lightbox-full {
    position: relative;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.gallery-page #lightbox-media .lightbox-full.is-loaded {
    opacity: 1;
}

/* Once the aspect ratio is known (set by script.js), both copies fill the
   same contained box, so the swap from placeholder to original is seamless. */
.gallery-page #lightbox-media[style*='--ar'] img.lightbox-full,
.gallery-page #lightbox-media[style*='--ar'] img.lightbox-placeholder {
    width: min(100%, calc(100cqh * var(--ar)));
    height: auto;
    aspect-ratio: var(--ar);
}

.gallery-page #lightbox-media .lightbox-placeholder {
    filter: blur(4px);
}

.gallery-page #lightbox-media[data-direction='next'] .lightbox-full,
.gallery-page #lightbox-media[data-direction='next'] .lightbox-placeholder {
    animation: slide-from-right 0.35s var(--ease);
}

.gallery-page #lightbox-media[data-direction='prev'] .lightbox-full,
.gallery-page #lightbox-media[data-direction='prev'] .lightbox-placeholder {
    animation: slide-from-left 0.35s var(--ease);
}

@keyframes slide-from-right {
    from { translate: 40px 0; }
}

@keyframes slide-from-left {
    from { translate: -40px 0; }
}

.gallery-page .lightbox-caption {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-self: center;
    width: min(100% - 24px, 68ch);
    margin: var(--s-1) auto 0;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: rgba(14, 16, 20, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--s-1) var(--s-2);
}

.gallery-page .lightbox-caption[hidden] {
    display: none;
}

.gallery-page .lightbox-caption__label {
    font-family: var(--mono);
    font-size: 0.58rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--signal);
}

.gallery-page .lightbox-caption__text {
    flex: 1 1 220px;
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--fg);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.gallery-page .lightbox-caption.is-expanded .lightbox-caption__text {
    display: block;
    -webkit-line-clamp: unset;
    max-height: 22svh;
    overflow-y: auto;
}

.gallery-page .lightbox-caption__toggle {
    border: 0;
    padding: 2px 6px;
    border-radius: 4px;
    background: transparent;
    font-family: var(--mono);
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    color: var(--signal);
    cursor: pointer;
}

.gallery-page .lightbox-caption__toggle[hidden] {
    display: none;
}

.gallery-page .lightbox-caption__toggle:hover,
.gallery-page .lightbox-caption__toggle:focus-visible {
    text-decoration: underline;
    outline: 1px solid var(--signal);
}

.gallery-page .lightbox-hint {
    grid-column: 1 / -1;
    grid-row: 4;
    margin: 0;
    padding: var(--s-2) 0 var(--s-3);
    text-align: center;
    font-family: var(--mono);
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    color: var(--fg-subtle);
}

.gallery-page .lightbox-hint kbd {
    display: inline-block;
    min-width: 20px;
    margin: 0 2px;
    padding: 1px 5px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    font-family: inherit;
    color: var(--fg-muted);
}

@media (max-width: 720px) {
    .gallery-page .lightbox {
        grid-template-columns: 0 minmax(0, 1fr) 0;
    }
    .gallery-page .lightbox-nav {
        display: none;
    }
    .gallery-page .lightbox-action__label {
        display: none;
    }
    .gallery-page .lightbox-action {
        padding: 0;
        width: 40px;
    }
    .gallery-page .lightbox-action.lightbox-like {
        width: auto;
        padding: 0 12px;
    }
    .gallery-page .lightbox-date {
        display: none;
    }
    .gallery-page .lightbox-bar {
        padding: var(--s-2) var(--s-3);
    }
    .gallery-page .lightbox-hint::before {
        content: 'Swipe to browse · swipe down to close';
    }
    .gallery-page .lightbox-hint {
        font-size: 0;
    }
    .gallery-page .lightbox-hint kbd {
        display: none;
    }
    .gallery-page .lightbox-hint::before {
        font-size: 0.64rem;
    }
    .gallery-page #lightbox-media img,
    .gallery-page #lightbox-media video {
        border-radius: 8px;
    }
}

@media (max-width: 360px) {
    /* Keep the full counter and all four actions visible on narrow phones. */
    .gallery-page .lightbox-bar {
        gap: 4px;
        padding-inline: 8px;
    }
    .gallery-page .lightbox-actions { gap: 4px; }
    .gallery-page .lightbox-chip {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }
}

/* Shared-element morph between tile and viewer (View Transitions API). */
::view-transition-group(artifact) {
    animation-duration: 0.42s;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

::view-transition-old(artifact),
::view-transition-new(artifact) {
    height: 100%;
    object-fit: cover;
}

/* --- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    .gallery-page .gallery-hero__ambient img,
    .gallery-page .gallery-hero__copy h1,
    .gallery-page .gallery-item,
    .gallery-page .gallery-item.is-loaded,
    .gallery-page .lightbox.active,
    .gallery-page .liked .heart-icon,
    .gallery-page #lightbox-media .lightbox-full,
    .gallery-page #lightbox-media .lightbox-placeholder {
        animation: none !important;
    }
    .gallery-page .gallery-item,
    .gallery-page .gallery-media,
    .gallery-page #lightbox-media {
        transition: none;
    }
    .gallery-page .gallery-item:hover,
    .gallery-page .gallery-item.is-loaded:hover .gallery-media {
        transform: none;
    }
    .gallery-page .gallery-media {
        filter: none;
        transform: none;
    }
}

/* Keep lightbox controls clear of the consent bar while it is shown (#674). */
body.gallery-page:has(.er33t-analytics-consent) .lightbox { padding-bottom: 88px; }
@media (max-width: 640px) {
    body.gallery-page:has(.er33t-analytics-consent) .lightbox { padding-bottom: 84px; }
}
.gallery-page .lightbox-counter { font-variant-numeric: tabular-nums; }
