/* Product photo carousel and lightbox for the Happy Snake 3D Art page.
   Uses the same sage, cream, and logo green as the rest of the site. */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* One product, centered. Same width the gallery used on the 3D Art page
   before that page became a two-card grid. */
.product-single {
  width: min(100%, 28rem);
  margin-inline: auto;
}

.gallery {
  position: relative;
  min-width: 0;
}

.gallery-frame {
  aspect-ratio: 3 / 4;
  border-radius: 1rem;
  overflow: hidden;
  background: var(--color-cream);
  box-shadow: inset 0 0 0 1px rgb(104 130 81 / 0.16);
}

.gallery-viewport,
.lightbox-viewport {
  display: flex;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}

.gallery-viewport {
  height: 100%;
  min-width: 0;
}

.gallery-viewport::-webkit-scrollbar,
.lightbox-viewport::-webkit-scrollbar {
  display: none;
}

.gallery-viewport.is-dragging,
.lightbox-viewport.is-dragging,
.gallery-viewport.is-instant,
.lightbox-viewport.is-instant {
  scroll-snap-type: none;
  scroll-behavior: auto;
}

.gallery-viewport.is-dragging,
.lightbox-viewport.is-dragging {
  cursor: grabbing;
}

.gallery-slide {
  position: relative;
  display: block;
  flex: 0 0 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: transparent;
  cursor: zoom-in;
}

.gallery-viewport.is-dragging .gallery-slide {
  cursor: grabbing;
}

.gallery-slide img,
.gallery-thumb img,
.lightbox-slide img {
  -webkit-user-drag: none;
  user-select: none;
}

.gallery-slide img,
.gallery-slide video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Mixed portrait and landscape photos share one frame. contain keeps
     titles and edges intact; cream from the frame shows in the bars. */
  object-fit: contain;
  object-position: center;
}

.gallery-slide img {
  pointer-events: none;
}

.gallery-slide video {
  background: transparent;
}

/* A small source file stays at its intrinsic size. contain still shrinks
   it when the frame is narrower, and the cream frame shows around it. */
.gallery-slide img.gallery-intrinsic,
.gallery-thumb img.gallery-intrinsic {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.gallery-slide img.gallery-intrinsic {
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

.gallery-thumb:has(img.gallery-intrinsic) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-slide:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--color-sage);
}

.gallery-thumbs {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.9rem;
  padding: 0.25rem;
}

.gallery-thumb {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 3 / 4;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0.55rem;
  overflow: hidden;
  background: var(--color-cream);
  box-shadow: inset 0 0 0 1px rgb(104 130 81 / 0.16);
  opacity: 0.72;
  cursor: pointer;
}

.gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.gallery-thumb[aria-current="true"] {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--color-logo-green);
}

.gallery-thumb:focus-visible {
  outline: 2px solid var(--color-sage);
  outline-offset: 3px;
}

@media (hover: hover) {
  .gallery-thumb:hover {
    opacity: 1;
  }
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-cream);
}

.lightbox::backdrop {
  background: rgb(49 64 42 / 0.94);
}

.lightbox[open] {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
  background: rgb(49 64 42 / 0.94);
}

.lightbox-bar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.15rem 0.35rem;
}

.lightbox-count,
.lightbox-close {
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1.2;
  color: var(--color-cream);
}

.lightbox-close {
  margin: 0;
  padding: 0.35rem 0.1rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgb(233 238 226 / 0.55);
  text-underline-offset: 0.28rem;
}

.lightbox-close:focus-visible,
.lightbox-arrow:focus-visible,
.lightbox-dot:focus-visible {
  outline: 2px solid var(--color-cream);
  outline-offset: 3px;
}

.lightbox-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.lightbox-viewport {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  cursor: grab;
}

.lightbox-viewport.is-dragging {
  cursor: grabbing;
}

.lightbox-slide {
  display: flex;
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
  height: 100%;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.lightbox-slide img,
.lightbox-slide video {
  width: auto;
  height: auto;
  max-width: calc(100vw - 1.25rem);
  max-height: calc(100dvh - 9rem);
  object-fit: contain;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.28);
}

.lightbox-arrow {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--color-cream);
  color: var(--color-sage-deep);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.28);
  transform: translateY(-50%);
  cursor: pointer;
}

.lightbox-prev {
  left: 0.65rem;
}

.lightbox-next {
  right: 0.65rem;
}

.lightbox-arrow:disabled {
  opacity: 0.38;
  cursor: default;
}

.lightbox-arrow svg {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
}

.lightbox-dots {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.35rem 1rem 1rem;
}

.lightbox-dot {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.lightbox-dot::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: rgb(233 238 226 / 0.65);
}

.lightbox-dot[aria-current="true"]::before {
  width: 1.35rem;
  background: var(--color-cream);
}

@media (prefers-reduced-motion: reduce) {
  .gallery-viewport,
  .lightbox-viewport {
    scroll-behavior: auto;
  }
}
