/* Gallery: Instagram-style profile grid with a lightbox. Builds on site.css tokens. */

.gallery { max-width: 60rem; }

/* ---------- Profile header ---------- */

.gallery-profile {
    display: flex;
    align-items: center;
    gap: clamp(1.5rem, 6vw, 4.5rem);
    padding: clamp(3rem, 8vw, 5rem) 0 clamp(2rem, 5vw, 3rem);
    border-bottom: 1px solid var(--surface-2);
}

.gallery-profile__avatar {
    flex: none;
    width: clamp(5rem, 18vw, 9.5rem);
    aspect-ratio: 1;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 35%;
    box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--lime);
}

.gallery-profile__text {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.gallery-profile__title { font-size: clamp(2.5rem, 9vw, 5.5rem); }

.gallery-profile__count { font-size: var(--text-base); }
.gallery-profile__count strong { font-weight: 600; }

.gallery-profile__bio {
    max-width: 40ch;
    font-size: var(--text-base);
    line-height: 1.45;
}

.gallery-profile__name { font-weight: 600; }

/* ---------- Featured: large portrait cards that scroll sideways ---------- */

.gallery-featured { padding-top: clamp(2rem, 5vw, 3rem); }

.gallery-featured__title {
    margin-bottom: 1rem;
    font-size: clamp(1.5rem, 3.5vw, 2.25rem);
}

.gallery-featured__list {
    --gap: clamp(0.75rem, 1.5vw, 1rem);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - var(--gap) * 2) / 3);
    gap: var(--gap);
    margin: 0;
    padding: 0 0 0.75rem;
    list-style: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
}

.gallery-featured__item { scroll-snap-align: start; }

.gallery-feature {
    position: relative;
    display: block;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border-radius: var(--radius-xl);
    background: var(--surface-2);
}

.gallery-feature img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 700ms var(--ease-out);
}

.gallery-feature:hover img { transform: scale(1.04); }

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

/* Caption over a soft dark fade at the bottom of the card. */
.gallery-feature__caption {
    position: absolute;
    inset: auto 0 0;
    padding: 3rem 1.1rem 1rem;
    background: linear-gradient(to top, rgba(15, 12, 21, 0.7), transparent);
    color: var(--ink-inverse);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 767px) {
    .gallery-featured__list { grid-auto-columns: 72%; }
}

/* ---------- Grid ---------- */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(3px, 0.6vw, 6px);
    margin: clamp(1.5rem, 3vw, 2rem) 0 0;
    padding: 0;
    list-style: none;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.gallery-tile {
    position: relative;
    display: block;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--surface-2);
}

.gallery-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 600ms var(--ease-out);
}

.gallery-tile::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--ink);
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.gallery-tile:hover img { transform: scale(1.04); }
.gallery-tile:hover::after { opacity: 0.18; }

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

.gallery-empty {
    padding: 4rem 0;
    text-align: center;
    color: var(--muted);
}

/* ---------- Viewer: an Instagram-style post ---------- */

.lightbox {
    --panel-w: 21rem;
    --edge: 2rem;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: var(--edge) 4.5rem;
    border: 0;
    background: transparent;
    overflow: hidden;
}

.lightbox::backdrop { background: rgba(15, 12, 21, 0.86); }

.lightbox[open] {
    display: grid;
    place-items: center;
    animation: lightbox-in 240ms var(--ease-out);
}

@keyframes lightbox-in {
    from { opacity: 0; transform: scale(1.02); }
    to   { opacity: 1; transform: none; }
}

/* Photo on the left, author, caption and date on the right. */
.lightbox__post {
    display: grid;
    grid-template-areas:
        "media author"
        "media details";
    grid-template-columns: auto var(--panel-w);
    grid-template-rows: auto minmax(0, 1fr);
    max-height: calc(100dvh - var(--edge) * 2);
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--bg);
    color: var(--ink);
}

.lightbox__author {
    grid-area: author;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--surface-2);
    font-size: 0.9rem;
    font-weight: 600;
}

.lightbox__avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 35%;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--lime);
}

.lightbox__media {
    grid-area: media;
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    background: var(--ink);
}

.lightbox__img {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 9rem - var(--panel-w));
    max-height: calc(100dvh - var(--edge) * 2);
    object-fit: contain;
}

.lightbox__details {
    grid-area: details;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    overflow-y: auto;
}

.lightbox__caption {
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-line;
}

.lightbox__caption:empty { display: none; }

.lightbox__date {
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Round white arrows over the photo's edges, like an Instagram carousel. */
.lightbox__btn {
    position: absolute;
    top: 50%;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0 0 0.15rem;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: var(--ink);
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transform: translateY(-50%);
    box-shadow: 0 2px 10px rgba(15, 12, 21, 0.2);
    transition: background 150ms ease-out;
}

.lightbox__btn:hover { background: #fff; }
.lightbox__btn[hidden] { display: none; }
.lightbox__prev { left: 0.75rem; }
.lightbox__next { right: 0.75rem; }

.lightbox__close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    padding: 0.25rem;
    border: 0;
    background: none;
    color: var(--ink-inverse);
    font: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox__btn:focus-visible,
.lightbox__close:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* Phones: full-screen post with the author above the photo and the caption below. */
@media (max-width: 767px) {
    .lightbox { padding: 0; }
    .lightbox::backdrop { background: var(--bg); }

    .lightbox__post {
        grid-template-areas:
            "author"
            "media"
            "details";
        grid-template-columns: 100%;
        grid-template-rows: auto auto 1fr;
        align-self: stretch;
        width: 100%;
        max-height: none;
        border-radius: 0;
        overflow-y: auto;
    }

    .lightbox__author { padding-right: 3.5rem; }
    .lightbox__img { max-width: 100%; max-height: 75dvh; }
    .lightbox__close { top: 0.85rem; color: var(--ink); }
}

/* Stop the page behind the viewer from scrolling. */
html:has(.lightbox[open]) { overflow: hidden; }
