.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-base) var(--ease-out);
  padding: var(--sp-4);
  padding-top: max(var(--sp-4), var(--safe-top));
  padding-bottom: max(var(--sp-4), var(--safe-bottom));
}

.lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox__overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.92);
  cursor: zoom-out;
}

.lightbox__content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}

.lightbox__img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - var(--sp-16));
  object-fit: contain;
  border-radius: var(--radius-sm);
  transform: scale(0.94);
  opacity: 0;
  transition:
    transform var(--duration-base) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out);
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox.is-open .lightbox__img {
  transform: scale(1);
}

.lightbox__img.is-loaded {
  opacity: 1;
}

/* shared button base */
.lightbox__close,
.lightbox__prev,
.lightbox__next {
  position: fixed;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  background-color: rgba(0, 0, 0, 0.45);
  border-radius: var(--radius-sm);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color var(--duration-fast), background-color var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.lightbox__close,
.lightbox__prev,
.lightbox__next {
  min-width: 44px;
  min-height: 44px;
}

.lightbox__close:hover,
.lightbox__prev:hover,
.lightbox__next:hover {
  color: var(--clr-white);
  background-color: rgba(0, 0, 0, 0.75);
}

.lightbox__close:focus-visible,
.lightbox__prev:focus-visible,
.lightbox__next:focus-visible {
  outline: 2px solid var(--clr-gold);
  outline-offset: 2px;
}

.lightbox__close {
  top: max(var(--sp-4), var(--safe-top));
  right: max(var(--sp-4), env(safe-area-inset-right, 0px));
  font-size: 1.75rem;
  line-height: 1;
}

.lightbox__prev,
.lightbox__next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox__prev {
  left: max(var(--sp-3), env(safe-area-inset-left, 0px));
}

.lightbox__next {
  right: max(var(--sp-3), env(safe-area-inset-right, 0px));
}

@media (min-width: 768px) {
  .lightbox__prev { left: var(--sp-6); }
  .lightbox__next { right: var(--sp-6); }
}

.lightbox__counter {
  position: fixed;
  bottom: max(var(--sp-5), env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: rgba(255, 255, 255, 0.65);
  background-color: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  pointer-events: none;
}

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