/* -- Gallery grid ----------------------------------------------------------- */

.gallery-section {
    margin-bottom: 3em;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Override base.css's .content-editor ul rule (margin-left: 40px; list-style: disc)
   which has higher specificity (1-2-1) than .gallery-grid alone (0-1-0). */
#main-content .content-editor ul.gallery-grid {
    list-style: none;
    margin-left: 0;
    margin-bottom: 0;
}

.gallery-grid li {
    display: block;
}

.gallery-grid figure {
    margin: 0;
    display: flex;
    flex-direction: column;
}

.gallery-grid figcaption {
    font-size: 0.8em;
    padding: 0.3em 0;
    text-align: center;
    color: inherit;
}

.gallery-thumb {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
}

.gallery-thumb img {
    display: block;
    width: 100%;
    height: 180px;
    object-fit: cover;
    transition: opacity 0.2s;
}

.gallery-thumb:hover img,
.gallery-thumb:focus img {
    opacity: 0.8;
}

.gallery-thumb:focus-visible {
    outline: 3px solid #4a9eff;
    outline-offset: 2px;
}

/* -- Lightbox dialog -------------------------------------------------------- */

#gallery-lightbox {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border: none;
    padding: 0;
    background: rgba(0, 0, 0, 0.93);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#gallery-lightbox[open] {
    display: flex;
}

#gallery-lightbox::backdrop {
    background: transparent;
}

#lightbox-img {
    max-width: 90vw;
    max-height: 78vh;
    object-fit: contain;
    display: block;
}

#lightbox-caption {
    color: #fff;
    font-size: 1em;
    padding: 0.75em 1em;
    text-align: center;
    max-width: 90vw;
}

#lightbox-close,
#lightbox-prev,
#lightbox-next {
    position: fixed;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.3em 0.55em;
    transition: background 0.15s, border-color 0.15s;
}

#lightbox-close { top: 1rem; right: 1rem; }
#lightbox-prev  { left: 1rem;  top: 50%; transform: translateY(-50%); }
#lightbox-next  { right: 1rem; top: 50%; transform: translateY(-50%); }

#lightbox-close:hover, #lightbox-prev:hover, #lightbox-next:hover,
#lightbox-close:focus-visible, #lightbox-prev:focus-visible, #lightbox-next:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    border-color: #fff;
    outline: none;
}

/* -- Mobile ----------------------------------------------------------------- */

@media (max-width: 600px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.5rem;
    }

    .gallery-thumb img {
        height: 130px;
    }

    #lightbox-prev,
    #lightbox-next {
        top: auto;
        bottom: 1.5rem;
        transform: none;
    }

    #lightbox-prev { left: 1rem; }
    #lightbox-next { right: 1rem; }
}
