/* Product gallery — views/sections/product_gallery.php, behaviour in js/sections/product_gallery.js.
   One scroll-snap track for every size: swipe on phones (story-style progress bars), thumbnails beside
   or below from 768 px, or a two-column grid from 1024 px. */

.pd-gallery {
  --pd-ratio: var(--card-ratio, 4 / 5);
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.pd-gallery--ratio-square {
  --pd-ratio: 1 / 1;
}

.pd-gallery--ratio-portrait {
  --pd-ratio: 4 / 5;
}

.pd-gallery--ratio-landscape {
  --pd-ratio: 4 / 3;
}

.pd-gallery__viewport {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
}

.pd-gallery__viewport:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.pd-gallery__track {
  position: relative;
  display: flex;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.pd-gallery__track::-webkit-scrollbar {
  display: none;
}

.pd-gallery__track:focus {
  outline: none;
}

.pd-gallery__slide {
  position: relative;
  flex: 0 0 100%;
  aspect-ratio: var(--pd-ratio);
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.pd-gallery__frame {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
}

button.pd-gallery__open {
  cursor: zoom-in;
}

.pd-gallery__frame :is(picture, img) {
  width: 100%;
  height: 100%;
}

.pd-gallery__frame img {
  object-fit: cover;
}

.pd-gallery--contain .pd-gallery__frame img {
  object-fit: contain;
}

.pd-gallery__slide--empty .pd-gallery__frame {
  display: grid;
  place-items: center;
}

.pd-gallery__slide--empty .pd-gallery__frame img {
  width: 40%;
  height: auto;
}

.pd-gallery__open:focus-visible,
.pd-gallery__play:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--color-focus);
}

.pd-gallery__zoom-hint {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  color: #14151A;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}

.has-many .pd-gallery__zoom-hint {
  bottom: 1.5rem;
}

.pd-gallery__open:hover .pd-gallery__zoom-hint,
.pd-gallery__open:focus-visible .pd-gallery__zoom-hint {
  opacity: 1;
}

/* Videos: a poster with a play button until the visitor asks for the player. */
.pd-gallery__play {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(120% 90% at 30% 20%, #2B2C34 0%, #14151A 70%);
  color: #FFFFFF;
  cursor: pointer;
}

.pd-gallery__play > :is(picture, img) {
  position: absolute;
  inset: 0;
}

.pd-gallery__play-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-2) var(--ease-out);
}

.pd-gallery__play-icon .icon {
  width: 1.6rem;
  height: 1.6rem;
  margin-left: 3px;
}

.pd-gallery__play:hover .pd-gallery__play-icon {
  transform: scale(1.06);
}

.pd-gallery__video-label {
  position: absolute;
  left: 1rem;
  bottom: 1.5rem;
  max-width: calc(100% - 2rem);
  overflow: hidden;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  background: rgba(20, 21, 26, .72);
  color: #FFFFFF;
  font-size: var(--step--1);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pd-gallery__player {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000000;
}

video.pd-gallery__player {
  object-fit: contain;
}

/* Arrows: shown on hover/focus for mouse users from 768 px. */
.pd-gallery__nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .94);
  color: #14151A;
  box-shadow: var(--shadow-md);
  transform: translateY(-50%);
  transition: opacity var(--dur-2) var(--ease-out);
}

.pd-gallery__nav--prev {
  left: 0.75rem;
}

.pd-gallery__nav--next {
  right: 0.75rem;
}

.pd-gallery__nav:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.pd-gallery__nav:disabled {
  opacity: 0 !important;
  pointer-events: none;
}

@media (hover: hover) and (min-width: 768px) {
  .pd-gallery__nav {
    display: grid;
    opacity: 0;
  }

  .pd-gallery__viewport:hover .pd-gallery__nav,
  .pd-gallery__nav:focus-visible {
    opacity: 1;
  }
}

/* Story-style progress bars (phones and tablets). */
.pd-gallery__progress {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.7rem;
  z-index: 3;
  display: flex;
  gap: 4px;
  pointer-events: none;
}

.pd-gallery__segment {
  flex: 1;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .5);
  box-shadow: 0 0 0 0.5px rgba(20, 21, 26, .18);
  transition: background-color var(--dur-2) var(--ease-out);
}

.pd-gallery__segment.is-done {
  background: rgba(255, 255, 255, .92);
}

.pd-gallery__segment.is-active {
  background: var(--color-accent);
}

.pd-gallery__counter {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.pd-gallery__counter.is-visible {
  top: 0.75rem;
  right: 0.75rem;
  z-index: 3;
  width: auto;
  height: auto;
  overflow: visible;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(20, 21, 26, .62);
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  clip-path: none;
}

/* Thumbnails (from 768 px); the active one carries the playhead bar. */
.pd-gallery__thumbs {
  display: none;
  margin: 0;
  padding: 2px;
  list-style: none;
}

.pd-gallery__thumb {
  position: relative;
  display: block;
  width: 76px;
  aspect-ratio: var(--pd-ratio);
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  opacity: 0.66;
  cursor: pointer;
  transition: opacity var(--dur-1) var(--ease-out);
}

.pd-gallery__thumb :is(picture, img) {
  width: 100%;
  height: 100%;
}

.pd-gallery__thumb img {
  object-fit: cover;
}

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

.pd-gallery__thumb::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--dur-3) var(--ease-out);
}

.pd-gallery__thumb[aria-current="true"]::after {
  transform: scaleX(1);
}

.pd-gallery__thumb:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.pd-gallery__thumb-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 21, 26, .38);
  color: #FFFFFF;
}

@media (min-width: 768px) {
  .pd-gallery__progress {
    display: none;
  }

  .pd-gallery__thumbs {
    display: flex;
    gap: 0.6rem;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .pd-gallery__thumbs li {
    flex: none;
  }

  .has-many .pd-gallery__zoom-hint,
  .pd-gallery__video-label {
    bottom: 0.75rem;
  }
}

/* Thumbnails below that run past the strip get arrows that scroll it (CSS scroll buttons where the browser
   has them; elsewhere the strip just scrolls). Each arrow shows only while there is more to see that way. */
@supports selector(::scroll-button(*)) {
  @media (min-width: 768px) {
    .pd-gallery--thumbs-below {
      position: relative;
      anchor-scope: --pd-thumbs;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs {
      anchor-name: --pd-thumbs;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(*) {
      position: absolute;
      position-anchor: --pd-thumbs;
      top: anchor(center);
      z-index: 3;
      width: 36px;
      height: 36px;
      padding: 0;
      border: 0;
      border-radius: 50%;
      background: rgba(255, 255, 255, .94) center / 18px 18px no-repeat;
      box-shadow: var(--shadow-md);
      font: 600 1.5rem/34px var(--font-body);
      text-align: center;
      cursor: pointer;
      translate: 0 -50%;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(left) {
      content: "" / "Scroll thumbnails left";
      left: calc(anchor(left) + 0.4rem);
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2314151A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 18-6-6 6-6'/%3E%3C/svg%3E");
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(right) {
      content: "" / "Scroll thumbnails right";
      right: calc(anchor(right) + 0.4rem);
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2314151A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(*):disabled {
      opacity: 0;
      visibility: hidden;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(*):focus-visible {
      outline: 2px solid var(--color-focus);
      outline-offset: 2px;
    }
  }

  @media (min-width: 768px) and (prefers-reduced-motion: no-preference) {
    .pd-gallery--thumbs-below .pd-gallery__thumbs {
      scroll-behavior: smooth;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(*) {
      transition: opacity var(--dur-2) var(--ease-out), visibility var(--dur-2);
    }
  }

  /* High contrast drops the white disc: plain arrows in the system text colour. */
  @media (min-width: 768px) and (forced-colors: active) {
    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(left) {
      content: "‹" / "Scroll thumbnails left";
      background-image: none;
    }

    .pd-gallery--thumbs-below .pd-gallery__thumbs::scroll-button(right) {
      content: "›" / "Scroll thumbnails right";
      background-image: none;
    }
  }
}

@media (min-width: 1024px) {
  .pd-gallery--thumbs-side.has-many {
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: start;
  }

  .pd-gallery--thumbs-side .pd-gallery__viewport {
    grid-column: 2;
    grid-row: 1;
  }

  .pd-gallery--thumbs-side .pd-gallery__thumbs {
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    max-height: min(80vh, 760px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Grid: every image at once, the first one large. */
  .pd-gallery--grid .pd-gallery__viewport {
    overflow: visible;
    border-radius: 0;
    background: none;
  }

  .pd-gallery--grid .pd-gallery__track {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    overflow: visible;
    scroll-snap-type: none;
  }

  .pd-gallery--grid .pd-gallery__slide {
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--color-surface-2);
  }

  .pd-gallery--grid .pd-gallery__slide:first-child {
    grid-column: 1 / -1;
  }

  .pd-gallery--grid :is(.pd-gallery__nav, .pd-gallery__counter.is-visible) {
    display: none;
  }
}

/* Full-screen viewer (RR.modal + .pd-lightbox). */
.modal.pd-lightbox {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  border-radius: 0;
  background: #0E0F12;
  color: #FFFFFF;
}

.pd-lightbox .modal__header {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  min-height: 0;
  padding: 0.5rem;
  border: 0;
}

.pd-lightbox .modal__header .btn {
  --btn-fg: #FFFFFF;
  --btn-bg-hover: rgba(255, 255, 255, .12);
  --btn-fg-hover: #FFFFFF;
}

.pd-lightbox .modal__body {
  display: flex;
  padding: 0;
  overflow: hidden;
}

.pd-lightbox__inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.pd-lightbox__stage {
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 3.5rem 1rem 0.5rem;
  cursor: zoom-in;
}

.pd-lightbox__img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
}

.pd-lightbox__stage.is-zoomed {
  place-items: start;
  overflow: auto;
  padding: 0;
  cursor: zoom-out;
}

.pd-lightbox__stage.is-zoomed .pd-lightbox__img {
  max-width: none;
  max-height: none;
}

.pd-lightbox__stage.is-dragging {
  cursor: grabbing;
}

.pd-lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
}

.pd-lightbox__btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #FFFFFF;
  transition: background-color var(--dur-1) var(--ease-out);
}

.pd-lightbox__btn:hover {
  background: rgba(255, 255, 255, .2);
}

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

.pd-lightbox__zoom[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.pd-lightbox__count {
  min-width: 4.5rem;
  color: rgba(255, 255, 255, .8);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: center;
}

@media (max-width: 767.98px) {
  .modal.pd-lightbox {
    width: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }
}
