.saner-gallery {
  --sg-columns: 3;
  --sg-gap: 30px;
  --sg-duration: 1.2s;
  width: 100%;
}

.saner-gallery .sg-grid {
  display: grid;
  grid-template-columns: repeat(var(--sg-columns), minmax(0, 1fr));
  gap: var(--sg-gap);
}

.saner-gallery .sg-item { min-width: 0; margin: 0; padding: 0; }
.saner-gallery .sg-card { display: block; color: inherit; }
.saner-gallery .sg-image { display: block; width: 100%; height: auto; border-radius: 0; }
.saner-gallery .sg-card:focus-visible { outline: 3px solid #087f8c; outline-offset: 4px; }

/* Only the outer item is positioned. The inner card handles the reveal. */
.saner-gallery.sg-layout .sg-grid { display: block; position: relative; }
.saner-gallery.sg-layout .sg-item { position: absolute; top: 0; left: 0; }
.saner-gallery.sg-layout .sg-card { aspect-ratio: 3 / 2; overflow: hidden; }
.saner-gallery.sg-layout .sg-card.sg-portrait { aspect-ratio: auto; height: var(--sg-tall-height); }
.saner-gallery.sg-layout .sg-image { height: 100%; object-fit: cover; object-position: center; }
.saner-gallery .sg-card.sg-animate {
  transition: opacity var(--sg-duration) ease, transform var(--sg-duration) cubic-bezier(.2, .65, .3, 1);
  transform-origin: center;
}
.saner-gallery .sg-card.sg-pending { opacity: 0; transform: scale(.5); }
.saner-gallery .sg-card.sg-pending:focus { opacity: 1; transform: none; }

@media (max-width: 1024px) { .saner-gallery { --sg-columns: 2; } }
@media (max-width: 767px) { .saner-gallery { --sg-columns: 1; } }
@media (prefers-reduced-motion: reduce) {
  .saner-gallery .sg-card.sg-animate { transition: none; }
  .saner-gallery .sg-card.sg-pending { opacity: 1; transform: none; }
}

/* Native dialog provides focus trapping, Escape, and an inert background. */
dialog.sg-lightbox {
  box-sizing: border-box;
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 64px 64px 30px;
  border: 0;
  background: rgba(0, 0, 0, .94);
  color: #fff;
}
dialog.sg-lightbox::backdrop { background: #000; }
dialog.sg-lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.sg-lightbox .sg-full { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 160px); object-fit: contain; }
.sg-lightbox .sg-caption { max-width: 900px; margin: 16px 0 0; color: #fff; text-align: center; white-space: pre-line; }
.sg-lightbox .sg-status { position: absolute; top: 20px; left: 24px; }
.sg-lightbox .sg-control { position: absolute; padding: 10px 14px; border: 1px solid #777; border-radius: 4px; background: #151515; color: #fff; font: inherit; cursor: pointer; }
.sg-lightbox .sg-control:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.sg-lightbox .sg-close { top: 14px; right: 18px; }
.sg-lightbox .sg-prev { left: 8px; top: 50%; }
.sg-lightbox .sg-next { right: 8px; top: 50%; }
.sg-lightbox .sg-control[hidden] { display: none; }
@media (max-width: 767px) {
  dialog.sg-lightbox { padding: 64px 44px 20px; }
  .sg-lightbox .sg-control { padding: 8px; }
}
