/* Slideshow galleries.
   Authored in markdown as a fenced div:

       ::: gallery
       ![Caption for the first slide](media/foo_01.png)

       ![Caption for the second slide](media/foo_02.png)
       :::

   Without JS the figures just stack down the page like any other image.
   gallery.js adds the .gallery--ready class and the slideshow behaviour. */

.gallery figure {
    margin: 0;
}

.gallery figcaption {
    text-align: center;
    font-size: 0.85em;
    opacity: 0.75;
    padding: 0.6em 0.25em 0;
}

.gallery--ready {
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75em;
    margin: 1.5em 0;
}

.gallery--ready:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Stack every slide in the same grid cell so the frame is as tall as the
   tallest image and advancing does not shift the rest of the page. */
.gallery-frame {
    display: grid;
    align-items: center;
}

.gallery-frame>figure {
    grid-area: 1 / 1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease-in-out;
}

.gallery-frame>figure.is-active {
    opacity: 1;
    visibility: visible;
}

.gallery-frame img {
    cursor: zoom-in;
}

.gallery-controls {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-top: 0.75em;
}

.gallery-btn {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2em;
    line-height: 1;
    color: var(--accent-color);
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25em 0.7em;
    cursor: pointer;
}

.gallery-btn:hover {
    background-color: var(--accent-color);
    color: var(--background-color);
}

.gallery-counter {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85em;
    opacity: 0.75;
    white-space: nowrap;
}

.gallery-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em;
    flex: 1;
    justify-content: center;
}

.gallery-dot {
    width: 0.7em;
    height: 0.7em;
    padding: 0;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.gallery-dot.is-active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Fullscreen view ---------------------------------------------------- */

.gallery-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--background-color);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2em 1em;
    gap: 1em;
}

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

.gallery-lightbox img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    cursor: zoom-out;
}

.gallery-lightbox figcaption,
.gallery-lightbox .gallery-counter {
    text-align: center;
    font-size: 0.9em;
    opacity: 0.8;
}

.gallery-lightbox .gallery-controls {
    margin-top: 0;
}

.gallery-close {
    position: absolute;
    top: 0.75em;
    right: 0.75em;
}

@media (prefers-reduced-motion: reduce) {
    .gallery-frame>figure {
        transition: none;
    }
}
