/* ==========================================================================
   Cartoine — galerie d'un projet et lightbox
   Rangées justifiées : chaque photo grandit selon son ratio (--ratio = largeur / hauteur),
   l'ordre du BO est respecté de gauche à droite, rien n'est recadré.
   ========================================================================== */
.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.gallery__item {
  flex: var(--ratio) 1 calc(var(--ratio) * 14rem);
}

/* Évite que la dernière rangée, incomplète, s'étire en photos géantes */
.gallery::after {
  content: "";
  flex: 999 1 0;
}

.gallery__link {
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--c-surface);
}

.gallery__img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform var(--dur-slow) var(--ease);
}
.gallery__link:hover .gallery__img { transform: scale(1.03); }
.gallery__link:focus-visible { outline: var(--focus); outline-offset: 3px; }

@media (max-width: 559.98px) {
  .gallery__item { flex-basis: 100%; }
}

/* --- Lightbox ----------------------------------------------------------- */
.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: var(--space-7) var(--space-8);
  border: 0;
  background: rgba(14, 14, 14, .96);
  color: var(--c-clair);
}
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: rgba(14, 14, 14, .9); }

.lightbox__figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  max-height: 100%;
}

.lightbox__img {
  max-width: 100%;
  max-height: calc(100dvh - 9rem);
  width: auto;
  height: auto;
  object-fit: contain;
}

.lightbox__caption {
  max-width: 60ch;
  color: var(--c-texte-2);
  font-size: var(--fs-small);
  text-align: center;
}

.lightbox__counter {
  position: absolute;
  top: var(--space-5);
  left: var(--space-5);
  color: var(--c-label);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-meta);
}

.lightbox__btn {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid rgba(242, 242, 238, .25);
  border-radius: 50%;
  background: rgba(14, 14, 14, .6);
  color: var(--c-clair);
  cursor: pointer;
}
.lightbox__btn:hover { border-color: var(--c-clair); }
.lightbox__btn:focus-visible { outline: var(--focus); outline-offset: 2px; }

.lightbox__btn--close { top: var(--space-4); right: var(--space-4); }
.lightbox__btn--prev  { left: var(--space-4); top: 50%; translate: 0 -50%; }
.lightbox__btn--next  { right: var(--space-4); top: 50%; translate: 0 -50%; }

/* Mobile : moins de marge, flèches en bas (le swipe fait le reste) */
@media (max-width: 767.98px) {
  .lightbox { padding: var(--space-8) var(--space-3); }
  .lightbox__btn--prev,
  .lightbox__btn--next { top: auto; bottom: var(--space-4); translate: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gallery__img { transition: none; }
  .gallery__link:hover .gallery__img { transform: none; }
}
