.gallery-grid {
    display: grid;
    grid-auto-flow: dense;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.75rem;
    margin-top: 2rem;
}

.gallery-item,
.gallery-tile {
    min-width: 0;
}

.gallery-item {
    position: relative;
}

.gallery-item:nth-child(6n+1),
.gallery-item:nth-child(6n+4) {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-tile {
    position: relative;
    display: block;
    width: 100%;
    min-height: 170px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    aspect-ratio: 1;
    padding: 0;
}

.gallery-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item__actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 3;
}

.gallery-item__actions .entry-action-button {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
}

.gallery-item__actions .entry-action-button:hover,
.gallery-item__actions .entry-action-button:focus-visible {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--bg);
}

.gallery-tile__caption {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding: 0.65rem;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    font-weight: 700;
    text-align: left;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.78);
}

.lightbox.is-open {
    display: flex;
}

.lightbox__panel {
    width: min(100%, 920px);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    border-radius: 8px;
    background: var(--surface);
}

.lightbox__panel img {
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
    background: #000;
}

.lightbox__body {
    padding: 1rem;
}

.lightbox__close {
    float: right;
}

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

    .gallery-item,
    .gallery-item:nth-child(6n+1),
    .gallery-item:nth-child(6n+4) {
        grid-column: span 1;
        grid-row: span 1;
    }
}
