/*
 * Keep lightbox positioning independent of Tailwind's individual `translate`
 * property. Older browsers ignore it, leaving a 50%/50% positioned dialog
 * below and to the right of the viewport center. Radix still portals both
 * elements into document.body and owns focus trapping, dismissal and scrolling.
 */
[data-slot="dialog-overlay"] {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
}

.photo-lightbox[data-slot="dialog-content"] {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  z-index: 50;
  margin: 0;
  box-sizing: border-box;
  /* Reset the individual property so modern browsers do not translate twice. */
  translate: none;
  transform: translate(-50%, -50%);
  /* The first value remains active when dynamic viewport units are unknown. */
  max-height: calc(100vh - 30px);
  max-height: calc(100dvh - 30px);
  overflow: auto;
  overscroll-behavior: contain;
}

.photo-lightbox .lightbox-image {
  height: calc(100vh - 225px);
  height: calc(100dvh - 225px);
}

.photo-lightbox .lightbox-caption {
  min-width: 0;
  overflow-wrap: break-word;
}

/* Keep the same fade/zoom, including the centering transform in every frame. */
.photo-lightbox[data-state="open"] {
  animation: photo-lightbox-enter 200ms ease;
}

.photo-lightbox[data-state="closed"] {
  animation: photo-lightbox-exit 200ms ease;
}

@keyframes photo-lightbox-enter {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes photo-lightbox-exit {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
}

@media (max-width: 760px) {
  .photo-lightbox[data-slot="dialog-content"] {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .photo-lightbox .lightbox-image {
    height: calc(100vh - 230px);
    height: calc(100dvh - 230px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .photo-lightbox[data-state] {
    animation: none;
  }
}
