/**
 * Galerie CSS — Glazam
 * Dépend de tokens.css + typography.css
 * @version 1.6.0
 */

/* ========================================
   VARIABLES
   ======================================== */
:root {
    --gallery-gap:           16px;
    --gallery-col-width:     300px;
    --gallery-radius:        4px;

    --gallery-filter-active: #050B76;
    --gallery-filter-hover:  #27AECC;
    --gallery-bounce:        cubic-bezier(0.34, 1.56, 0.64, 1);

    --gallery-serif: var(--font-serif, var(--font-display, 'Instrument Serif', serif));

    /* ---- Palette des tags : bleu profond → turquoise ---- */
    --tag-01: #061079;
    --tag-02: #0D3089;
    --tag-03: #134896;
    --tag-04: #1A69A7;
    --tag-05: #1E78AF;
    --tag-06: #2187B6;
    --tag-07: #27B1C8;
    --tag-08: #25B9C9;
    --tag-09: #24BAC9;
    --tag-10: #22C5C9;
    --tag-11: #1FD3CB;
    --tag-12: #1DDACB;
}

/* ========================================
   CONTENEUR — pleine largeur
   ======================================== */
.glazam-gallery {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}

/* ========================================
   BARRE DE FILTRES
   (pas d'overflow ici → le halo n'est pas écrêté)
   ======================================== */
.glazam-gallery__filters {
    margin-bottom: 24px;
    padding: 8px 0 12px;
}

.glazam-gallery__filters-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ========================================
   FILTRE — pastille PLEINE + nappe floue au survol
   ======================================== */
.glazam-gallery__filter {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    background-color: var(--tag-01);   /* défaut, surchargé par nth-child */
    border: none;
    border-radius: 100px;
    padding: 11px 22px;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    transition: box-shadow 0.35s ease, transform 0.25s var(--gallery-bounce),
                filter 0.3s ease;

    /* Palette de la nappe au survol (cyan Glazam) */
    --b-1: #27AECC;
    --b-2: #050B76;
    --b-3: #7fd6e8;
    --b-4: #FCDE9C;
    --b-shadow: rgba(39, 174, 204, 0.45);

    animation: glazam-filter-in 0.5s var(--gallery-bounce) backwards;
}

/* Nappe de couleur floue (révélée au survol / sur l'actif) */
.glazam-gallery__filter::before {
    content: '';
    position: absolute;
    inset: -60%;
    z-index: -1;
    background:
        radial-gradient(circle at 22% 40%, var(--b-1) 0 28%, transparent 60%),
        radial-gradient(circle at 78% 62%, var(--b-2) 0 26%, transparent 62%),
        radial-gradient(circle at 55% 28%, var(--b-3) 0 24%, transparent 58%),
        radial-gradient(circle at 38% 78%, var(--b-4) 0 22%, transparent 56%),
        var(--b-1);
    filter: blur(14px);
    opacity: 0;
    transition: opacity 0.35s ease;
    animation: glazam-blob-drift 7s linear infinite;
    animation-play-state: paused;
}

/* Reflet interne */
.glazam-gallery__filter::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: inset 0 2px 8px rgba(255, 255, 255, 0.3),
                inset 0 -2px 5px rgba(0, 0, 0, 0.15);
    opacity: 0.7;
    transition: opacity 0.35s ease;
}

/* Le texte reste au-dessus */
.glazam-gallery__filter > span {
    position: relative;
    z-index: 2;
}

.glazam-gallery__filter-count {
    opacity: 0.7;
    font-size: 0.8em;
    margin-left: 7px;
    font-variant-numeric: tabular-nums;
}

/* ---- Couleurs en dégradé le long de la barre (cycle de 12) ---- */
.glazam-gallery__filter:nth-child(12n + 1)  { background-color: var(--tag-01); }
.glazam-gallery__filter:nth-child(12n + 2)  { background-color: var(--tag-02); }
.glazam-gallery__filter:nth-child(12n + 3)  { background-color: var(--tag-03); }
.glazam-gallery__filter:nth-child(12n + 4)  { background-color: var(--tag-04); }
.glazam-gallery__filter:nth-child(12n + 5)  { background-color: var(--tag-05); }
.glazam-gallery__filter:nth-child(12n + 6)  { background-color: var(--tag-06); }
.glazam-gallery__filter:nth-child(12n + 7)  { background-color: var(--tag-07); }
.glazam-gallery__filter:nth-child(12n + 8)  { background-color: var(--tag-08); }
.glazam-gallery__filter:nth-child(12n + 9)  { background-color: var(--tag-09); }
.glazam-gallery__filter:nth-child(12n + 10) { background-color: var(--tag-10); }
.glazam-gallery__filter:nth-child(12n + 11) { background-color: var(--tag-11); }
.glazam-gallery__filter:nth-child(12n)      { background-color: var(--tag-12); }

/* --- États --- */
.glazam-gallery__filter:hover,
.glazam-gallery__filter:focus-visible {
    box-shadow: 0 6px 20px var(--b-shadow);
    transform: translateY(-3px);
}

.glazam-gallery__filter:hover::before,
.glazam-gallery__filter:focus-visible::before,
.glazam-gallery__filter.is-active::before {
    opacity: 1;
    animation-play-state: running;
}

.glazam-gallery__filter:hover::after,
.glazam-gallery__filter:focus-visible::after,
.glazam-gallery__filter.is-active::after { opacity: 1; }

.glazam-gallery__filter:active { transform: scale(0.95); }

.glazam-gallery__filter:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -4px;
}

/* Actif : nappe bleu marine + liseré blanc pour le distinguer */
.glazam-gallery__filter.is-active {
    --b-1: #050B76;
    --b-2: #0D3089;
    --b-3: #134896;
    --b-4: #1A69A7;
    --b-shadow: rgba(5, 11, 118, 0.5);

    box-shadow: 0 0 0 2px #fff,
                0 0 0 4px var(--gallery-filter-active),
                0 6px 20px var(--b-shadow);
}

@keyframes glazam-blob-drift {
    0%   { transform: rotate(0deg)   scale(1.05); }
    50%  { transform: rotate(180deg) scale(1.2); }
    100% { transform: rotate(360deg) scale(1.05); }
}

/* Cascade d'entrée */
.glazam-gallery__filter:nth-child(1)  { animation-delay: 0.03s; }
.glazam-gallery__filter:nth-child(2)  { animation-delay: 0.06s; }
.glazam-gallery__filter:nth-child(3)  { animation-delay: 0.09s; }
.glazam-gallery__filter:nth-child(4)  { animation-delay: 0.12s; }
.glazam-gallery__filter:nth-child(5)  { animation-delay: 0.15s; }
.glazam-gallery__filter:nth-child(6)  { animation-delay: 0.18s; }
.glazam-gallery__filter:nth-child(7)  { animation-delay: 0.21s; }
.glazam-gallery__filter:nth-child(8)  { animation-delay: 0.24s; }
.glazam-gallery__filter:nth-child(9)  { animation-delay: 0.27s; }
.glazam-gallery__filter:nth-child(10) { animation-delay: 0.30s; }
.glazam-gallery__filter:nth-child(11) { animation-delay: 0.33s; }
.glazam-gallery__filter:nth-child(12) { animation-delay: 0.36s; }
.glazam-gallery__filter:nth-child(13) { animation-delay: 0.39s; }
.glazam-gallery__filter:nth-child(14) { animation-delay: 0.42s; }

@keyframes glazam-filter-in {
    from { opacity: 0; transform: translateY(10px) scale(0.92); }
    to   { opacity: 1; transform: none; }
}

/* ========================================
   BOUTON "AU HASARD" — doré, allumé en permanence
   (double classe = passe devant les règles nth-child)
   ======================================== */
.glazam-gallery__filter.glazam-gallery__filter--random {
    background-color: #ffd215;
    text-shadow: 0 1px 2px rgba(160, 90, 0, 0.35);

    --b-1: #ffd215;
    --b-2: #ffa31a;
    --b-3: #fff172;
    --b-4: #ffe81a;
    --b-shadow: rgba(255, 223, 87, 0.5);

    box-shadow: 0 4px 18px var(--b-shadow);
}
.glazam-gallery__filter--random::before {
    opacity: 1;
    animation-play-state: running;
}
.glazam-gallery__filter--random::after {
    opacity: 1;
    box-shadow: inset 0 3px 12px rgba(255, 223, 52, 0.9),
                inset 0 -3px 4px rgba(255, 250, 215, 0.8);
}
.glazam-gallery__filter--random:hover {
    transform: translateY(-3px) scale(1.04);
}

/* ========================================
   GRILLE — MAÇONNERIE PILOTÉE EN JS
   ======================================== */
.glazam-gallery__grid {
    display: flex;
    align-items: flex-start;
    gap: var(--gallery-gap);
}

.glazam-gallery__col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--gallery-gap);
}

.glazam-gallery__sentinel {
    height: 1px;
    width: 100%;
}

/* ========================================
   CARTE PROJET
   ======================================== */
.glazam-gallery__item {
    display: block;
    width: 100%;
    position: relative;
    overflow: hidden;
    border-radius: var(--gallery-radius);
    background: var(--color-border);
    cursor: pointer;
    border: none;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
}

.glazam-gallery__item img {
    width: 100%;
    height: auto;
    display: block;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.7s var(--anim-ease-out, ease);
}

.glazam-gallery__item img.is-loaded { opacity: 1; }

.glazam-gallery__item:hover img,
.glazam-gallery__item:focus-visible img {
    transform: scale(1.05);
}

.glazam-gallery__item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(56, 29, 42, 0.7) 0%, rgba(56, 29, 42, 0) 45%);
    opacity: 0;
    transition: opacity 0.4s var(--anim-ease-out, ease);
    pointer-events: none;
}

.glazam-gallery__item:hover::after,
.glazam-gallery__item:focus-visible::after {
    opacity: 1;
}

.glazam-gallery__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 18px 20px;
    font-family: var(--gallery-serif);
    font-size: 1.15rem;
    line-height: 1.2;
    color: #fff;
    text-align: left;
    transform: translateY(8px);
    opacity: 0;
    transition: transform 0.4s var(--anim-ease-out, ease), opacity 0.4s var(--anim-ease-out, ease);
    pointer-events: none;
}

.glazam-gallery__item:hover .glazam-gallery__caption,
.glazam-gallery__item:focus-visible .glazam-gallery__caption {
    transform: translateY(0);
    opacity: 1;
}

.glazam-gallery__item:focus-visible {
    outline: 2px solid var(--gallery-filter-hover);
    outline-offset: 3px;
}

.glazam-gallery__item {
    animation: glazam-gallery-in 0.45s var(--anim-ease-out, ease) both;
    animation-delay: calc(var(--i, 0) * 40ms);
}

@keyframes glazam-gallery-in {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========================================
   ÉTATS : chargement / vide
   ======================================== */
.glazam-gallery__skeleton {
    width: 100%;
    height: 240px;
    border-radius: var(--gallery-radius);
    background: linear-gradient(100deg,
        var(--color-border) 30%,
        rgba(0, 0, 0, 0.04) 50%,
        var(--color-border) 70%);
    background-size: 200% 100%;
    animation: glazam-gallery-shimmer 1.4s ease-in-out infinite;
}
.glazam-gallery__skeleton:nth-child(3n)   { height: 320px; }
.glazam-gallery__skeleton:nth-child(4n+1) { height: 200px; }

@keyframes glazam-gallery-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

.glazam-gallery__empty {
    text-align: center;
    color: var(--color-muted);
    font-size: 1rem;
    padding: 60px 0;
}

/* ========================================
   LIGHTBOX
   ======================================== */
.glazam-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 32, 44, 0.94);
    padding: 5vh 4vw;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.glazam-lightbox.is-open { opacity: 1; }
.glazam-lightbox[hidden] { display: none; }

.glazam-lightbox__figure {
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.glazam-lightbox__img {
    max-width: 100%;
    max-height: 82vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--gallery-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.glazam-lightbox__caption {
    font-family: var(--gallery-serif);
    font-size: 1.3rem;
    color: #fff;
    text-align: center;
}

.glazam-lightbox__caption:empty { display: none; }

.glazam-lightbox__close,
.glazam-lightbox__nav {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.glazam-lightbox__close:hover,
.glazam-lightbox__nav:hover {
    background: var(--gallery-filter-hover);
}

.glazam-lightbox__close {
    top: 20px;
    right: 24px;
    width: 44px;
    height: 44px;
    font-size: 28px;
    line-height: 1;
}

.glazam-lightbox__nav {
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    font-size: 32px;
    line-height: 1;
}

.glazam-lightbox__nav--prev { left: 24px; }
.glazam-lightbox__nav--next { right: 24px; }

.glazam-lightbox__close:focus-visible,
.glazam-lightbox__nav:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1024px) {
    :root { --gallery-col-width: 260px; }
}

@media (max-width: 767px) {
    :root { --gallery-gap: 10px; }
    .glazam-gallery__filters-inner { gap: 8px; }
    .glazam-gallery__filter {
        font-size: 0.82rem;
        padding: 9px 16px;
    }
    .glazam-gallery__caption { font-size: 0.95rem; padding: 12px 14px; }

    .glazam-lightbox__nav {
        width: 44px;
        height: 44px;
        font-size: 26px;
    }
    .glazam-lightbox__nav--prev { left: 10px; }
    .glazam-lightbox__nav--next { right: 10px; }
    .glazam-lightbox__close { top: 12px; right: 14px; }
}

/* ========================================
   MOUVEMENT RÉDUIT
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .glazam-gallery__item,
    .glazam-gallery__item img,
    .glazam-gallery__caption,
    .glazam-gallery__item::after,
    .glazam-gallery__filter,
    .glazam-gallery__filter::before,
    .glazam-lightbox,
    .glazam-gallery__skeleton {
        animation: none !important;
        transition: none !important;
    }
    .glazam-gallery__item img { opacity: 1 !important; }
    .glazam-gallery__filter:hover,
    .glazam-gallery__item:hover .glazam-gallery__caption,
    .glazam-gallery__item:hover img {
        transform: none;
    }
}
