/* Photo gallery grid and full-screen viewer (see gallery.js) */

.gallery {
    margin: var(--spacing-xl) 0;
}

/* Six tracks, three tiles per row; a short last row stretches to fill it. */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

.gallery-grid > .gallery-item {
    grid-column: span 2;
}

@media (min-width: 481px) {
    .gallery-grid > .gallery-item:nth-child(3n+1):nth-last-child(2),
    .gallery-grid > .gallery-item:nth-child(3n+1):nth-last-child(2) + .gallery-item {
        grid-column: span 3;
        aspect-ratio: 3 / 2;
    }

    .gallery-grid > .gallery-item:nth-child(3n+1):last-child {
        grid-column: span 6;
        aspect-ratio: 3 / 1;
    }
}

.gallery-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    line-height: 1.25;
    font-weight: 600;
    color: var(--color-text);
    text-align: center;
    display: table;
    margin: 0 auto var(--spacing-sm);
    padding: 0.1em 0.6em;
    background: rgba(255, 251, 244, 0.92);
    border-radius: 999px;
}

.gallery-grid--single {
    grid-template-columns: 1fr;
}

.gallery-grid--single > .gallery-item {
    grid-column: auto;
}

.gallery-item {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: 20px;
    overflow: hidden;
    background: var(--color-primary-light);
    box-shadow: var(--shadow-sm);
    cursor: zoom-in;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

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

.gallery-grid--single .gallery-item {
    aspect-ratio: 4 / 3;
}

.gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

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

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.gallery-item:focus-visible {
    outline: 3px solid var(--color-primary-dark);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px var(--color-white), var(--shadow-md);
}

.gallery-more:focus-visible,
.lightbox-btn:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
}

.gallery-more {
    display: block;
    margin: var(--spacing-md) auto 0;
    min-height: 48px;
    padding: var(--spacing-xs) var(--spacing-lg);
    border: 2px solid var(--color-primary);
    border-radius: 999px;
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.gallery-more:hover {
    background: #d6eed6;
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .gallery-grid > .gallery-item {
        grid-column: span 1;
    }

    /* An odd last tile (or the 9th before "see all") spans the row instead of leaving a gap. */
    .gallery-grid > .gallery-item:last-child:nth-child(odd),
    .gallery-grid:has(.gallery-item[hidden]) > .gallery-item:nth-child(9) {
        grid-column: span 2;
        aspect-ratio: 2 / 1;
    }
}

/* ---------------------------------------------------------------------- */

.lightbox {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #14111a;
    color: var(--color-white);
}

.lightbox::backdrop {
    background: #14111a;
}

html:has(.lightbox[open]) {
    overflow: hidden;
}

.lightbox-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    width: 100%;
    height: 100%;
    padding: 72px 16px 96px;
}

.lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

/* Counter and arrows share one bar at the bottom, in every state. */
.lightbox-counter {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 5.5rem;
    text-align: center;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.lightbox-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    max-width: 18rem;
    padding: 1.5rem 1.75rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--color-white);
    font-size: 1.05rem;
    line-height: 1.5;
    text-align: center;
}

.lightbox-error::before {
    content: '';
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14) center / 26px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='3'/%3E%3Ccircle cx='9' cy='10' r='1.5'/%3E%3Cpath d='M21 16l-5-5-8 8M3 3l18 18'/%3E%3C/svg%3E");
}

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

.lightbox-btn {
    position: absolute;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: var(--radius-full);
    background: rgba(20, 17, 26, 0.85);
    border: 2px solid rgba(255, 255, 255, 0.7);
    color: var(--color-white);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox-btn:hover {
    background: rgba(60, 55, 70, 0.95);
}

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

.lightbox-close {
    top: 12px;
    right: 12px;
    font-size: 1.25rem;
}

.lightbox-prev,
.lightbox-next {
    bottom: 20px;
    font-size: 2.25rem;
}

.lightbox-prev { left: calc(50% - 5.5rem - 48px); }
.lightbox-next { right: calc(50% - 5.5rem - 48px); }

@media (min-width: 641px) {
    .lightbox-btn {
        width: 56px;
        height: 56px;
    }

    .lightbox-prev { left: calc(50% - 5.5rem - 56px); }
    .lightbox-next { right: calc(50% - 5.5rem - 56px); }
    .lightbox-counter { bottom: 34px; }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .gallery-item img { transition: none; }
    .gallery-item:hover img { transform: none; }
    .gallery-item:hover { transform: none; }
}

.lightbox-btn:focus-visible {
    outline-color: var(--color-white);
}
