/* =========================================================================
   vie-sous-marine.photo — galerie & diaporama
   Chargé APRÈS atlas.css : surcharge .tile / .grid-photos dans le contexte
   de la classe racine .gallery. Ne modifie pas atlas.css.
   - Galerie « masonry » (colonnes CSS pures) : images entières, non recadrées,
     hauteurs variables, coins arrondis, responsive sans scroll horizontal.
   - Légende d'espèce TOUJOURS visible (plus seulement au survol).
   - Habillage de la lightbox/diaporama (boutons injectés en JS).
   ========================================================================= */

/* ---------- Galerie masonry ---------- */
.gallery {
  column-width: 264px;      /* colonnes fluides : le navigateur en met autant que possible */
  column-gap: 12px;
  margin-top: 4px;
}
@media (max-width: 640px) {
  .gallery { column-width: 46vw; column-gap: 10px; }
}
@media (max-width: 400px) {
  .gallery { column-width: 100%; }
}

/* Une tuile = une image entière + sa légende. On neutralise le carré fixe
   (aspect-ratio 4/3 + object-fit:cover) hérité d'atlas.css. */
.gallery .tile {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  margin: 0 0 12px;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}
.gallery .tile img {
  width: 100%;
  height: auto;             /* hauteur naturelle → aucune image recadrée */
  object-fit: contain;
  display: block;
}
.gallery .tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
  .gallery .tile img { transition: transform .55s cubic-bezier(.2,.7,.2,1); }
  .gallery .tile:hover img { transform: scale(1.04); }
}

/* Légende espèce : dégradé bas TOUJOURS présent (nom commun + latin en italique). */
.gallery .tile figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 30px 13px 11px;
  color: #fff;
  font-family: var(--serif);
  font-size: 14px; line-height: 1.28;
  letter-spacing: -.005em;
  background: linear-gradient(transparent, rgba(6,24,28,.30) 30%, rgba(6,24,28,.86));
  opacity: 1;               /* surcharge le hover-only d'atlas.css */
  transition: none;
  pointer-events: none;
}
.gallery .tile figcaption .sci {
  display: block;
  font-family: var(--sans);
  font-style: italic;
  font-size: 12px;
  opacity: .82;
  margin-top: 1px;
}

/* =========================================================================
   Lightbox / diaporama — habillage des contrôles injectés par lightbox.js
   (le backdrop .lb-backdrop et #lb-img / #lb-cap viennent d'atlas.css/layout).
   ========================================================================= */

/* Boutons de navigation ‹ › */
.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  z-index: 95;
  width: 54px; height: 54px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: rgba(8,26,31,.55);
  color: #eafcf8;
  font-size: 34px; line-height: 1;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  transition: background .18s, transform .18s, opacity .18s;
}
.lb-nav:hover { background: rgba(21,122,140,.85); }
.lb-nav:focus-visible { outline: 2px solid #8fe0e0; outline-offset: 3px; }
.lb-nav:active { transform: translateY(-50%) scale(.92); }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
@media (max-width: 560px) {
  .lb-nav { width: 46px; height: 46px; font-size: 28px; }
  .lb-prev { left: 6px; } .lb-next { right: 6px; }
}

/* Compteur 3 / 24 */
.lb-counter {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 95;
  font-family: var(--mono);
  font-size: 13px; letter-spacing: .08em;
  color: #cfe6e1;
  background: rgba(8,26,31,.5);
  padding: 5px 12px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}

/* Bouton lecture auto */
.lb-play {
  position: fixed; top: 16px; left: 18px;
  z-index: 95;
  display: inline-flex; align-items: center; gap: 7px;
  border: none; border-radius: 20px;
  background: rgba(8,26,31,.5);
  color: #cfe6e1;
  font: inherit; font-size: 13px;
  padding: 6px 13px;
  cursor: pointer;
  transition: background .18s;
}
.lb-play:hover { background: rgba(21,122,140,.8); color: #eafcf8; }
.lb-play:focus-visible { outline: 2px solid #8fe0e0; outline-offset: 3px; }

/* Légende de la lightbox : nom d'espèce + éventuel lien « Voir l'espèce » */
#lb-cap .lb-cap-label { font-family: var(--serif); font-size: 16px; color: #eafcf8; }
#lb-cap .lb-cap-link {
  display: inline-block; margin-left: 12px;
  color: #8fe0e0; font-size: 13.5px; text-decoration: none;
  border-bottom: 1px solid rgba(143,224,224,.4);
}
#lb-cap .lb-cap-link:hover { color: #cfeeee; border-color: #cfeeee; }

/* Fondu doux au changement d'image */
@media (prefers-reduced-motion: no-preference) {
  .lb-backdrop #lb-img { transition: opacity .22s ease; }
  .lb-backdrop.lb-swapping #lb-img { opacity: 0; }
}

/* Masqué quand un seul média dans l'ensemble */
.lb-nav.is-hidden, .lb-counter.is-hidden, .lb-play.is-hidden { display: none; }
