/* ---------- gallery (stage + thumbs) ----------
   Reemplaza el grid antiguo. Stage muestra siempre media[index] al
   completo; thumbs sólo aparecen si hay más de un item. */
.gallery {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.gallery > .stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-radius: var(--radius-md);
  overflow: hidden;
  /* sin max-height: las verticales toman su altura natural en lugar de
     achicarse y dejar bandas a los lados. Si la imagen es muy larga,
     pues será larga — preferimos eso al letterboxing. */
  /* Fade entre medios + animación de altura cuando el siguiente media
     tiene aspect ratio distinto. La duración (240ms) está sincronizada
     con FADE_MS en gallery.js; el easing es la curva "standard" de
     Material — suave en ambas direcciones sin sentir lento. */
  opacity: 1;
  transition:
    opacity 240ms var(--curve-standard),
    height 240ms var(--curve-standard);
}
.gallery > .stage.is-fading { opacity: 0; }
.gallery > .stage > img {
  display: block;
  max-width: 100%;
  height: auto;
}
.gallery > .stage > img { cursor: zoom-in; }

.gallery > .thumbs {
  display: flex;
  flex-wrap: nowrap;
  /* safe center: cuando las thumbs caben, se centran; cuando desbordan
     (viewports estrechos), se anclan al inicio en vez de empujar la primera
     fuera del scroll. */
  justify-content: safe center;
  gap: 6px;
  padding: 2px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.gallery > .thumbs::-webkit-scrollbar { height: 6px; }
.gallery > .thumbs::-webkit-scrollbar-thumb {
  background: var(--faint);
  border-radius: 3px;
}
.gallery > .thumbs > .thumb {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  scroll-snap-align: center;
}
.gallery > .thumbs > .thumb:hover { border-color: var(--accent-dim); }
.gallery > .thumbs > .thumb.is-active { border-color: var(--accent); }
.gallery > .thumbs > .thumb > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-stage {
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Mismo patrón de fade+altura que el stage del feed. */
  opacity: 1;
  transition:
    opacity 240ms var(--curve-standard),
    height 240ms var(--curve-standard);
}
.lightbox-stage.is-fading { opacity: 0; }
.lightbox-stage > img {
  max-width: 95vw;
  max-height: 90vh;
  display: block;
  object-fit: contain;
}
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover { background: rgba(0, 0, 0, 0.75); }
.lightbox-close { top: 12px; right: 12px; }
.lightbox-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-counter {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 10px;
  border-radius: var(--radius-lg);
}
body.lightbox-open { overflow: hidden; }
