/* ============================================================
   Galerie photos — grille responsive + visionneuse plein écran
   ============================================================ */

.galerie {
  max-width: 72rem;
  margin: 0 auto;
  padding: 7.5rem 1rem 4rem;
}

.galerie__status {
  text-align: center;
  font-style: italic;
  color: var(--encre-douce);
  padding: 2rem 1rem;
}

.galerie__status a { color: var(--or-fonce); }

/* ===== Grille ===== */
.galerie__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

@media (min-width: 700px) {
  .galerie__grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
  }
}

.galerie__item {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: var(--creme);
  cursor: pointer;
  overflow: hidden;
}

/* Petit anneau doré qui tourne tant que la vignette charge */
.galerie__item::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--or-pale);
  border-top-color: var(--or);
  border-radius: 50%;
  animation: galerie-spin 0.9s linear infinite;
}

.galerie__item.is-loaded::before { display: none; }

@keyframes galerie-spin {
  to { transform: rotate(360deg); }
}

.galerie__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease, opacity 0.4s ease;
  opacity: 0;
}

.galerie__item img.loaded { opacity: 1; }

.galerie__item:hover img,
.galerie__item:focus-visible img { transform: scale(1.04); }

.galerie__item:focus-visible {
  outline: 2px solid var(--or);
  outline-offset: 2px;
}

/* ===== Visionneuse ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20, 18, 14, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  /* le balayage vertical reste possible pour fermer, on gère le reste en JS */
  touch-action: pan-y;
}

.lightbox[hidden] { display: none; }

.lightbox__figure {
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 0.2s ease;
}

.lightbox__close,
.lightbox__download,
.lightbox__arrow {
  position: fixed;
  z-index: 210;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.lightbox__close:hover,
.lightbox__download:hover,
.lightbox__arrow:hover { background: rgba(196, 162, 77, 0.6); }

.lightbox__close:focus-visible,
.lightbox__download:focus-visible,
.lightbox__arrow:focus-visible {
  outline: 2px solid var(--or);
  outline-offset: 2px;
}

/* à gauche de la croix */
.lightbox__download {
  top: max(0.8rem, env(safe-area-inset-top));
  right: calc(0.8rem + 48px + 0.6rem);
}

/* chargement de l'original : l'icône laisse place à un anneau qui tourne */
.lightbox__download.is-busy svg { visibility: hidden; }

.lightbox__download.is-busy::after {
  content: "";
  position: absolute;
  inset: 13px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: galerie-spin 0.9s linear infinite;
}

/* photo prête, le téléphone attend un nouveau toucher */
.lightbox__download.is-ready {
  background: var(--or);
  animation: lightbox-pulse 1.2s ease-in-out infinite;
}

@keyframes lightbox-pulse {
  50% { box-shadow: 0 0 0 8px rgba(196, 162, 77, 0.35); }
}

.lightbox__close {
  top: max(0.8rem, env(safe-area-inset-top));
  right: 0.8rem;
  font-size: 2rem;
}

.lightbox__arrow {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox__arrow--prev { left: 0.6rem; }
.lightbox__arrow--next { right: 0.6rem; }

/* Sur mobile, on navigue au balayage : flèches discrètes */
@media (max-width: 640px) and (pointer: coarse) {
  .lightbox__arrow { display: none; }
}

.lightbox__counter {
  position: fixed;
  z-index: 210;
  bottom: max(0.9rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  letter-spacing: 0.15em;
}

@media (prefers-reduced-motion: reduce) {
  .galerie__item img,
  .lightbox__img { transition: none; }
  /* anneau statique plutôt qu'animation */
  .galerie__item::before,
  .lightbox__download.is-busy::after,
  .lightbox__download.is-ready { animation: none; }
}
