/*
 * STM Gallery: neutral frontend layout. No colours, fonts or branding: the site
 * template provides those (overrides or its own CSS). Custom properties allow a
 * template to adjust spacing and columns without overriding rules.
 */
.stmgallery {
    --stmgallery-gap: 1rem;
    --stmgallery-card-min: 16rem;
}

.stmgallery-album-list {
    display: grid;
    gap: var(--stmgallery-gap);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--stmgallery-card-min)), 1fr));
    list-style: none;
    margin: 0 0 var(--stmgallery-gap);
    padding: 0;
}

.stmgallery-album-title {
    font-size: 1.125rem;
    margin: 0;
}

.stmgallery-album-date,
.stmgallery-album-meta {
    margin: 0.25rem 0 0;
}

.stmgallery-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--stmgallery-gap);
    align-items: flex-end;
    margin: 0 0 var(--stmgallery-gap);
}

.stmgallery-filter {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stmgallery-filter-actions {
    flex-direction: row;
    align-items: center;
}

.stmgallery-album-meta > * + *::before {
    content: " · ";
}

.stmgallery-photo-grid {
    display: grid;
    gap: var(--stmgallery-gap);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--stmgallery-photo-min, 9rem)), 1fr));
    align-items: start;
    list-style: none;
    margin: var(--stmgallery-gap) 0;
    padding: 0;
}

.stmgallery-photo {
    position: relative;
    margin: 0;
}

/* Original aspect ratio: no cropping, the width and height attributes reserve the space. */
.stmgallery-photo img,
.stmgallery-album-cover,
.stmgallery-photo-figure img {
    display: block;
    width: 100%;
    height: auto;
}

.stmgallery-photo-link {
    display: block;
}

.stmgallery-photo-link:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

.stmgallery-photo-number {
    font-size: 0.875rem;
}

.stmgallery-photo .stmgallery-photo-number {
    position: absolute;
    inset-block-end: 0.25rem;
    inset-inline-start: 0.25rem;
    padding: 0 0.375rem;
    background: rgb(0 0 0 / 0.6);
    color: #fff;
    border-radius: 0.25rem;
    pointer-events: none;
}

.stmgallery-photo-figure {
    margin: 0 0 var(--stmgallery-gap);
}

.stmgallery-photo-figure img {
    max-width: 1600px;
    max-height: 90vh;
    object-fit: contain;
}

.stmgallery-photo-figure figcaption {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-top: 0.5rem;
}

/* Captions (R-12): a full line of plain text below the photo, line breaks kept. The photo
   page's caption is a full line of its wrapping row; in the lightbox's column it only
   takes its own height (a 100 % basis there would be a height). */
.stmgallery-photo-caption,
.stmgallery-lightbox-caption {
    white-space: pre-line;
}

.stmgallery-photo-caption {
    flex: 1 0 100%;
}

.stmgallery-lightbox-caption {
    flex: none;
}

.stmgallery-copyright {
    font-size: 0.875rem;
}

/*
 * Lightbox (Block 6, R-16): the photo in the middle of the screen, the counter and a
 * close button above, arrow buttons at the sides, title and caption centred below, the
 * removal request as a small button. Every click outside the photo, its caption text
 * and the controls closes it (lightbox.js).
 */
/* The whole viewport (inset: 0, not 100vw, so a reserved scrollbar gutter never makes it
   overflow), with its own dark background. */
.stmgallery-lightbox {
    box-sizing: border-box;
    position: fixed;
    inset: 0;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgb(0 0 0 / 0.92);
    color: #fff;
}

.stmgallery-lightbox[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.stmgallery-lightbox::backdrop {
    background: rgb(0 0 0 / 0.9);
}

.stmgallery-lightbox-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.75rem 0.5rem 1rem;
}

/* Photo and caption together in the middle. The caption row takes the height it needs and
   the photo the rest (at most its own size), so a long caption makes the photo smaller,
   never pushes it under the bar or the caption off screen; the photo keeps its
   proportions. A very long caption scrolls within at most 45 % of the screen height. */
.stmgallery-lightbox-figure {
    display: grid;
    grid-template-rows: minmax(0, max-content) max-content;
    align-content: center;
    justify-items: center;
    min-height: 0;
    margin: 0;
    padding: 0 4rem 1rem;
}

.stmgallery-lightbox-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.stmgallery-lightbox figcaption {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    box-sizing: border-box;
    /* A definite width: the row height is measured at the width the text is laid out in. */
    width: min(100%, 70ch);
    max-height: 45dvh;
    overflow-y: auto;
    padding-top: 0.6rem;
    text-align: center;
}

.stmgallery-lightbox-heading {
    font-weight: 700;
}

.stmgallery-lightbox-number:empty,
.stmgallery-lightbox-heading:empty {
    display: none;
}

.stmgallery-lightbox-request {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2.75rem; /* 44 px touch target */
    margin-top: 0.25rem;
    padding: 0 0.8rem;
    border: 1px solid currentColor;
    border-radius: 999px;
    color: inherit;
    font-size: 0.85rem;
    text-decoration: none;
}

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

.stmgallery-lightbox svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.stmgallery-lightbox-request svg {
    width: 1rem;
    height: 1rem;
}

.stmgallery-lightbox-close,
.stmgallery-lightbox-prev,
.stmgallery-lightbox-next {
    display: inline-grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgb(255 255 255 / 0.12);
    color: #fff;
    cursor: pointer;
}

.stmgallery-lightbox-close:hover,
.stmgallery-lightbox-prev:hover,
.stmgallery-lightbox-next:hover {
    background: rgb(255 255 255 / 0.24);
}

.stmgallery-lightbox-prev,
.stmgallery-lightbox-next {
    position: absolute;
    top: 50%;
    translate: 0 -50%;
}

.stmgallery-lightbox-prev {
    left: 0.5rem;
}

.stmgallery-lightbox-next {
    right: 0.5rem;
}

@media (max-width: 599.98px) {
    .stmgallery-lightbox-figure {
        padding: 0 0.5rem 4.25rem;
    }

    .stmgallery-lightbox-prev,
    .stmgallery-lightbox-next {
        top: auto;
        bottom: 0.5rem;
        translate: none;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .stmgallery-lightbox-image {
        transition: opacity 0.15s ease-in;
    }
}

/* Removal and privacy requests: the honeypot field stays out of sight and out of reach. */
.stmgallery-hp {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.stmgallery-request-subject {
    display: flex;
    flex-wrap: wrap;
    gap: var(--stmgallery-gap);
    align-items: center;
}

.stmgallery-request-subject img {
    width: 12rem;
    height: auto;
}

.stmgallery-request-link {
    font-size: 0.875rem;
}
