/* ==========================================================================
   product-gallery — media gallery for any aspect ratio, plus video and 3D.
   The stage is a native scroll-snap strip (swipe on touch, arrows / thumbs /
   keys elsewhere) with a fixed 4:5 frame. Landscape photos use
   data-fit="contain": the whole picture is shown on a quiet background, so
   nothing is cropped and nothing shifts. <product-gallery> adds the controls.
   Without JS the strip still scrolls and the thumbnails are plain buttons.
   ========================================================================== */
.product-gallery {
  display: grid;
  gap: var(--space-sm);
  grid-template-areas:
    'stage'
    'thumbs';
}

.product-gallery__stage {
  position: relative;
  grid-area: stage;
  min-width: 0;
}

.product-gallery__slides {
  display: flex;
  padding: 0;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  border-radius: var(--radius-lg);
}

.product-gallery__slides::-webkit-scrollbar {
  display: none;
}

.product-gallery__slides:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 4px;
}

.product-gallery__slide {
  position: relative;
  flex: 0 0 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background-color: var(--palette-mist);
  scroll-snap-align: start;
}

.product-gallery__slide > img,
.product-gallery__slide > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--image-focal, 50% 50%);
}

.product-gallery__slide[data-fit='contain'] > img {
  object-fit: contain;
}

/* controls */
.product-gallery__count {
  position: absolute;
  bottom: var(--space-sm);
  left: var(--space-sm);
  z-index: var(--z-base);
  padding: 0.35rem var(--space-xs);
  background-color: var(--palette-white);
  color: var(--palette-ink);
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
}

.product-gallery__nav {
  position: absolute;
  right: var(--space-sm);
  bottom: var(--space-sm);
  z-index: var(--z-base);
  display: flex;
  gap: var(--space-2xs);
}

.product-gallery__nav .arrow-button {
  --color-fg: var(--palette-ink);
  --color-bg: var(--palette-white);

  border-color: var(--palette-ink);
}

.product-gallery__nav .arrow-button[aria-disabled='true'] {
  opacity: 0.4;
  pointer-events: none;
}

.product-gallery__zoom {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  z-index: var(--z-base);
  display: inline-grid;
  place-items: center;
  width: var(--target-min);
  height: var(--target-min);
  padding: 0;
  background-color: var(--palette-white);
  color: var(--palette-ink);
  border: 1px solid var(--palette-ink);
  border-radius: var(--radius-pill);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.product-gallery__zoom:hover {
  background-color: var(--palette-lime);
}

.product-gallery__zoom:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.product-gallery__zoom[hidden] {
  display: none;
}

.product-gallery__tag {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  z-index: var(--z-base);
}

/* video + 3D slides */
.product-gallery__play {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: var(--z-base);
  display: grid;
  place-items: center;
  width: 5rem;
  height: 5rem;
  padding: 0;
  background-color: var(--palette-lime);
  color: var(--palette-ink);
  border: 1px solid var(--palette-ink);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform var(--duration-base) var(--ease-out);
}

.product-gallery__play:hover {
  transform: translate(-50%, -50%) scale(1.08);
}

.product-gallery__play:focus-visible {
  outline: 2px solid var(--palette-white);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px var(--palette-ink);
}

.product-gallery__play .icon {
  width: 1.75rem;
  height: 1.75rem;
}

.product-gallery__note {
  position: absolute;
  right: var(--space-sm);
  bottom: 4.5rem;
  left: var(--space-sm);
  z-index: var(--z-base);
  padding: var(--space-2xs) var(--space-xs);
  background-color: var(--palette-white);
  color: var(--palette-ink);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  text-align: center;
}

.product-gallery__note[hidden] {
  display: none;
}

/* thumbnails */
.product-gallery__thumbs {
  display: flex;
  grid-area: thumbs;
  gap: var(--space-2xs);
  padding: 4px;
  margin: -4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.product-gallery__thumbs::-webkit-scrollbar {
  display: none;
}

.product-gallery__thumb {
  position: relative;
  flex: none;
  width: 4.5rem;
  height: 4.5rem;
  padding: 0;
  overflow: hidden;
  background-color: var(--palette-mist);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--duration-fast) var(--ease-out);
}

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

.product-gallery__thumb:hover,
.product-gallery__thumb[aria-current='true'] {
  opacity: 1;
}

.product-gallery__thumb[aria-current='true'] {
  outline: 2px solid var(--color-fg);
  outline-offset: 2px;
}

.product-gallery__thumb:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.product-gallery__thumb-badge {
  position: absolute;
  inset: auto 0 0;
  padding: 0.125rem 0;
  background-color: var(--palette-ink);
  color: var(--palette-white);
  font-size: 0.625rem;
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caption);
  text-align: center;
  text-transform: uppercase;
}

@media (min-width: 64em) {
  .product-gallery {
    grid-template-columns: 5.5rem minmax(0, 1fr);
    grid-template-areas: 'thumbs stage';
    gap: var(--space-md);
    align-items: start;
  }

  /* The column follows the stage height (height 0 + min-height 100%) and scrolls
     when there are more thumbnails than room; it never stretches the row. */
  .product-gallery__thumbs {
    flex-direction: column;
    align-self: stretch;
    height: 0;
    min-height: 100%;
    overflow: hidden auto;
  }

  .product-gallery__thumb {
    width: 5.5rem;
    height: 5.5rem;
  }
}

/* enlarged view: the shared drawer--full dialog, edge to edge. The photo fits
   the screen (no margins); controls float on top. See also assets/js/image-zoom.js */
.gallery-zoom {
  --color-bg: var(--palette-ink);
  --color-fg: var(--palette-white);
  --color-focus: var(--palette-green);
}

.gallery-zoom .drawer__inner {
  position: relative;
}

.gallery-zoom .drawer__header {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  background: linear-gradient(rgb(11 11 12 / 0.7), transparent);
  border-bottom: 0;
  pointer-events: none;
}

.gallery-zoom .drawer__header > * {
  pointer-events: auto;
}

.gallery-zoom .drawer__close {
  background-color: rgb(11 11 12 / 0.6);
  border-color: var(--palette-white);
}

.image-zoom {
  position: absolute;
  inset: 0;
}

.image-zoom__viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: zoom-in;
  touch-action: none; /* we handle drag and pinch ourselves */
  user-select: none;
}

.image-zoom__viewport.is-zoomed {
  cursor: grab;
}

.image-zoom__viewport.is-zoomed.is-dragging {
  cursor: grabbing;
}

.image-zoom__viewport:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -4px;
}

.image-zoom__img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  border-radius: 0;
  transform-origin: center;
  will-change: transform;
  -webkit-user-drag: none;
}

.image-zoom__img.is-animating {
  transition: transform var(--duration-base) var(--ease-out);
}

.gallery-zoom__bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-md) var(--space-sm);
  background: linear-gradient(transparent, rgb(11 11 12 / 0.7));
  pointer-events: none;
}

.gallery-zoom__bar > * {
  pointer-events: auto;
}

.gallery-zoom__group {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
}

.gallery-zoom__button {
  display: inline-grid;
  place-items: center;
  width: var(--target-min);
  height: var(--target-min);
  padding: 0;
  background-color: rgb(11 11 12 / 0.6);
  color: var(--palette-white);
  border: 1px solid var(--palette-white);
  border-radius: var(--radius-pill);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.gallery-zoom__button:hover {
  background-color: var(--palette-lime);
  border-color: var(--palette-ink);
  color: var(--palette-ink);
}

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

.gallery-zoom__button[aria-disabled='true'] {
  opacity: 0.4;
  pointer-events: none;
}

.gallery-zoom__count {
  min-width: 3.5rem;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .image-zoom__img.is-animating {
    transition: none;
  }
}
