/*
 * Galeries d'images : mosaïque en colonnes, grille régulière, rangées justifiées, et modale d'agrandissement.
 * Réglages par classes sur le conteneur : .ltg--cols-2 à 6, .ltg--gap-0 à 4. Aucun style en ligne.
 */

.ltg {
    --ltg-cols: 3;
    --ltg-gap: 8px;
    --ltg-row: 220px;
    clear: both;
    margin: 1.5em 0;
}

.ltg--cols-2 { --ltg-cols: 2; }
.ltg--cols-3 { --ltg-cols: 3; }
.ltg--cols-4 { --ltg-cols: 4; }
.ltg--cols-5 { --ltg-cols: 5; }
.ltg--cols-6 { --ltg-cols: 6; }

.ltg--gap-0 { --ltg-gap: 0; }
.ltg--gap-1 { --ltg-gap: 4px; }
.ltg--gap-2 { --ltg-gap: 8px; }
.ltg--gap-3 { --ltg-gap: 16px; }
.ltg--gap-4 { --ltg-gap: 24px; }

.ltg .ltg__item {
    display: block;
    position: relative;
    overflow: hidden;
    border: 0;
    line-height: 0;
    text-decoration: none;
    cursor: zoom-in;
}

.ltg .ltg__img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0;
    transition: transform .25s ease;
}

.ltg .ltg__item:hover .ltg__img,
.ltg .ltg__item:focus-visible .ltg__img {
    transform: scale(1.03);
}

.ltg .ltg__item:focus-visible {
    outline: 3px solid currentcolor;
    outline-offset: 2px;
}

/* Mosaïque : colonnes de hauteurs libres (les images se lisent de haut en bas, colonne après colonne). */
.ltg--columns {
    column-count: var(--ltg-cols);
    column-gap: var(--ltg-gap);
}

.ltg--columns .ltg__item {
    margin-bottom: var(--ltg-gap);
    break-inside: avoid;
}

/* Grille régulière : cases carrées, images recadrées. */
.ltg--grid {
    display: grid;
    grid-template-columns: repeat(var(--ltg-cols), minmax(0, 1fr));
    gap: var(--ltg-gap);
}

.ltg--grid .ltg__item {
    aspect-ratio: 1 / 1;
}

.ltg--grid .ltg__img {
    height: 100%;
    object-fit: cover;
}

/*
 * Rangées justifiées : hauteur de rangée fixe, largeur proportionnelle au format de chaque image.
 * Le format (--ltg-ar) est posé par le script ; sans script, toutes les cases sont carrées.
 * Le pseudo-élément absorbe la place libre de la dernière rangée pour qu'elle ne s'étire pas.
 */
.ltg--justified {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ltg-gap);
}

.ltg--justified::after {
    content: "";
    flex-grow: 1000000;
}

.ltg--justified .ltg__item {
    --ltg-ar: 1;
    flex: var(--ltg-ar) 1 calc(var(--ltg-ar) * var(--ltg-row));
    height: var(--ltg-row);
}

.ltg--justified .ltg__img {
    height: 100%;
    object-fit: cover;
}

@media (max-width: 640px) {
    .ltg { --ltg-row: 140px; }

    .ltg--cols-3,
    .ltg--cols-4,
    .ltg--cols-5,
    .ltg--cols-6 { --ltg-cols: 2; }
}

/* Titre éditorial facultatif. Le repli utilise <details> natif (clavier et absence de JS). */
.ltg-title { margin: 1.5em 0 .5em; font-size: 1.35em; }
.ltg-fold { margin: 1.5em 0; }
.ltg-fold > summary {
    padding: .4em 0;
    font-weight: 600;
    cursor: pointer;
}
.ltg-fold > summary { list-style: none; }
.ltg-fold > summary::-webkit-details-marker { display: none; }
.ltg-fold > summary::before { content: '▸'; display: inline-block; margin-right: .65em; }
.ltg-fold[open] > summary::before { content: '▾'; }
.ltg-fold > summary:hover { text-decoration: underline; }
.ltg-fold > summary:focus-visible { outline: 2px solid currentcolor; outline-offset: 2px; }
.ltg-fold > .ltg { margin: .75em 0 0; }

/* Modale d'agrandissement. */
html.ltg-lock { overflow: hidden; }

.ltg-modal {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    overflow: hidden;
}

.ltg-modal[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ltg-modal::backdrop { background: rgba(0, 0, 0, .94); }

.ltg-modal .ltg-modal__stage {
    display: flex;
    align-items: center;
    position: relative;
    max-width: calc(100vw - 110px);
    max-height: 90vh;
    gap: 1.5rem;
}

.ltg-modal .ltg-modal__info[hidden],
.ltg-modal .ltg-modal__toggle[hidden] { display: none; }

.ltg-modal .ltg-modal__figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 92vw;
    margin: 0;
}

.ltg-modal .ltg-modal__img {
    display: block;
    width: auto;
    max-width: 92vw;
    height: auto;
    max-height: 80vh;
    margin: 0;
    object-fit: contain;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
    transition: opacity .2s ease;
}

.ltg-modal .ltg-modal__figure.is-loading .ltg-modal__img { opacity: .2; }

.ltg-modal .ltg-modal__caption {
    max-width: 70ch;
    margin: .75rem 0 0;
    font-size: .95rem;
    line-height: 1.4;
    text-align: center;
    color: #fff;
}

.ltg-modal .ltg-modal__caption:empty { display: none; }

.ltg-modal .ltg-modal__toggle {
    margin-top: .65rem;
    padding: .4rem .9rem;
    border: 1px solid #fff;
    border-radius: 3px;
    background: rgba(0, 0, 0, .8);
    color: #fff;
    cursor: pointer;
}

.ltg-modal .ltg-modal__info {
    position: relative;
    box-sizing: border-box;
    width: min(32vw, 360px);
    max-height: 76vh;
    flex: 0 0 auto;
    align-self: flex-start;
    overflow-y: auto;
    padding: .75rem 1.25rem 1.25rem;
    border-left: 1px solid rgba(255, 255, 255, .35);
    background: #171717;
    color: #fff;
    line-height: 1.6;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.ltg-modal--reading .ltg-modal__img { max-width: min(55vw, 960px); }

.ltg-modal .ltg-modal__info-close {
    display: block;
    position: sticky;
    top: 0;
    width: 2rem;
    height: 2rem;
    margin: 0 0 .75rem auto;
    padding: 0;
    border: 0;
    background: #171717;
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
}

.ltg-modal .ltg-modal__info-close:focus:not(:focus-visible) { outline: none; }
.ltg-modal .ltg-modal__info-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ltg-modal .ltg-modal__info:focus { outline: none; }

.ltg-modal .ltg-modal__counter {
    position: absolute;
    right: 0;
    bottom: .75rem;
    left: 0;
    margin: 0;
    font-size: .8rem;
    text-align: center;
    color: #fff;
    opacity: .7;
}

.ltg-modal .ltg-modal__btn {
    position: absolute;
    z-index: 3;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 50%;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.ltg-modal .ltg-modal__btn:hover,
.ltg-modal .ltg-modal__btn:focus-visible { background: rgba(0, 0, 0, .8); }

.ltg-modal .ltg-modal__close { top: .75rem; right: .75rem; }
.ltg-modal .ltg-modal__prev { top: 50%; left: .75rem; transform: translateY(-50%); }
.ltg-modal .ltg-modal__next { top: 50%; right: .75rem; transform: translateY(-50%); }

.ltg-modal[data-single] .ltg-modal__prev,
.ltg-modal[data-single] .ltg-modal__next { display: none; }

@media (max-width: 640px) {
    .ltg-modal .ltg-modal__prev { left: .25rem; }
    .ltg-modal .ltg-modal__next { right: .25rem; }
    .ltg-modal .ltg-modal__stage { max-width: 92vw; }
    .ltg-modal .ltg-modal__info {
        position: absolute;
        inset: auto 0 0;
        z-index: 1;
        width: 100%;
        max-height: 60%;
        padding-top: .75rem;
        border: 0;
        border-top: 1px solid rgba(255, 255, 255, .35);
        background: rgba(0, 0, 0, .92);
    }
    .ltg-modal--reading .ltg-modal__img { max-width: 92vw; }
    /* La légende courte et le bouton passent sous le bandeau : on les masque pour qu'ils ne transparaissent pas derrière le texte. */
    .ltg-modal--reading .ltg-modal__caption,
    .ltg-modal--reading .ltg-modal__toggle { visibility: hidden; }
    .ltg-modal--reading .ltg-modal__prev,
    .ltg-modal--reading .ltg-modal__next { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ltg .ltg__img,
    .ltg-modal .ltg-modal__img { transition: none; }

    .ltg .ltg__item:hover .ltg__img,
    .ltg .ltg__item:focus-visible .ltg__img { transform: none; }
}
