.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(250, 247, 242, 0.98); /* --color-bg */
  color: var(--color-text);
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

.lightbox:not([open]) {
  display: none;
}

.lightbox::backdrop {
  background: rgba(250, 247, 242, 0.98); /* --color-bg */
}

.lightbox__figure {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

/* Keep 72px free above and below the image for the close button, the counter and the mobile arrows. */
.lightbox__img {
  max-width: 92vw;
  max-height: min(84vh, calc(100vh - 144px));
  max-height: min(84vh, calc(100dvh - 144px));
  width: auto;
  height: auto;
  object-fit: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  opacity: 1;
  transition: opacity 250ms var(--ease);
}

.lightbox__img.is-fading {
  opacity: 0;
}

.lightbox__btn {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease);
}

/* Touch browsers keep :hover on the last tapped element, so dim only on real hover. */
@media (hover: hover) {
  .lightbox__btn:hover {
    opacity: 0.6;
  }
}

.lightbox__btn--close {
  top: 16px;
  right: 16px;
}

/* 24px from the bottom keeps the arrows above the iOS Safari collapsed toolbar zone; they still fit in the 72px band. */
.lightbox__btn--prev,
.lightbox__btn--next {
  bottom: 24px;
}

.lightbox__btn--prev {
  left: calc(50% - 110px);
}

.lightbox__btn--next {
  right: calc(50% - 110px);
}

.lightbox__counter {
  position: absolute;
  left: 50%;
  bottom: 36px;
  margin: 0;
  transform: translateX(-50%);
  font-family: var(--font-head);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Phone landscape also uses the edge arrows: the bottom row takes too much of the short height. */
@media (min-width: 768px), (orientation: landscape) and (max-height: 500px) {
  /* Keep 88px free at each side for the edge arrows (24px offset + 48px button + 16px gap). */
  .lightbox__img {
    max-width: min(92vw, calc(100vw - 176px));
  }

  .lightbox__btn--prev,
  .lightbox__btn--next {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
  }

  .lightbox__btn--prev {
    left: 24px;
  }

  .lightbox__btn--next {
    right: 24px;
  }

  .lightbox__counter {
    bottom: 24px;
  }
}

/* Phone landscape: the arrows sit at the sides, so keep only 32px above and below the image for the counter. */
@media (orientation: landscape) and (max-height: 500px) {
  .lightbox__img {
    max-height: min(84vh, calc(100vh - 64px));
    max-height: min(84vh, calc(100dvh - 64px));
  }

  .lightbox__counter {
    bottom: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__img {
    transition: none;
  }
}
