/* ---------- Photos full screen, one at a time (lightbox_controller.js, gallery_controller.js) ---------- */

/* The page behind stays where it is */
html:has(.lightbox[open]) {
  overflow: hidden;
}

/* Only when open: a display of its own would keep a closed dialog on the page */
.lightbox[open] {
  display: block;
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgb(0 0 0 / 92%);
  color: #fff;
}

.lightbox svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.lightbox__gallery {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.lightbox__stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.lightbox__track {
  display: flex;
  height: 100%;
  overflow-x: auto;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;

  &::-webkit-scrollbar {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    scroll-behavior: auto;
  }
}

/* Flex and not grid: a grid's row grows with a tall photo, so max-height had nothing to hold it to */
.lightbox__slide {
  display: flex;
  flex: 0 0 100%;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 100%;
  padding: var(--space-4);
  scroll-snap-align: start;
  scroll-snap-stop: always;

  img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
}

.lightbox__close,
.lightbox__arrow {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: rgb(0 0 0 / 55%);
  color: #fff;
  cursor: pointer;

  &:hover {
    background: rgb(255 255 255 / 20%);
  }

  &:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
  }

  svg {
    width: 1.5rem;
    height: 1.5rem;
  }
}

.lightbox__close {
  top: var(--space-3);
  right: var(--space-3);
}

.lightbox__arrow {
  top: 50%;
  transform: translateY(-50%);

  &[aria-disabled="true"] {
    opacity: 0.3;
    cursor: default;
  }

  /* On a phone it's a swipe, and the arrows would sit on the photo */
  @media (hover: none) {
    display: none;
  }
}

.lightbox__arrow--previous {
  left: var(--space-3);
}

.lightbox__arrow--next {
  right: var(--space-3);
}

.lightbox__thumbs {
  display: flex;
  gap: var(--space-2);
  justify-content: safe center;
  overflow-x: auto;
  padding: var(--space-3);
  scrollbar-width: none;
}

.lightbox__thumb {
  flex-shrink: 0;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  opacity: 0.6;
  cursor: pointer;

  &[aria-current] {
    border-color: #fff;
    opacity: 1;
  }

  &:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
  }

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
