/**
 * Image gallery (sections/image-gallery.liquid).
 *
 * Two layouts off one pair of custom properties, --gallery-columns and
 * --gallery-gap, written on the <image-gallery> element by the section:
 *
 *   masonry  CSS multi-column. Images keep their own aspect ratio and the
 *            columns fill top-to-bottom. No JS, correct on first paint.
 *   grid     equal squares, object-fit: cover, reading left-to-right.
 *
 * Phones force two columns in both layouts. Five columns of photograph on a
 * 390px screen is a row of thumbnails nobody can see, and the column count
 * the merchant picked is a desktop composition decision.
 */
.section-image-gallery {
  display: block;
}

.image-gallery__header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  max-width: 640px;
}

.image-gallery__heading {
  margin: 0;
}

.image-gallery__subheading {
  color: var(--color-muted);
  margin: 0;
}

/* ------------------------------------------------------------------ */
/* Layouts                                                             */
/* ------------------------------------------------------------------ */
.image-gallery__grid--masonry {
  column-count: var(--gallery-columns, 3);
  column-gap: var(--gallery-gap, 16px);
}

/* break-inside is what stops a photograph being sliced across a column
   boundary; without it multi-column will happily cut an image in half. The
   bottom margin is the vertical half of the gap — column-gap only spaces
   the columns, never the items inside one. */
.image-gallery__grid--masonry .image-gallery__item {
  break-inside: avoid;
  margin-bottom: var(--gallery-gap, 16px);
}

.image-gallery__grid--grid {
  display: grid;
  grid-template-columns: repeat(var(--gallery-columns, 3), minmax(0, 1fr));
  gap: var(--gallery-gap, 16px);
}

.image-gallery__grid--grid .image-gallery__image {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.image-gallery__item {
  margin: 0;
  min-width: 0;
}

/* ------------------------------------------------------------------ */
/* Tiles                                                               */
/* ------------------------------------------------------------------ */
/* The tile is a <button>, an <a> or a <span> depending on the lightbox
   setting and whether the block has a link, so everything shared sits on
   the one class and the element type carries no styling of its own. */
.image-gallery__tile {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  border-radius: var(--radius-m);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}

.image-gallery__tile--button {
  cursor: zoom-in;
}

.image-gallery__tile:focus-visible {
  outline: 2px solid var(--color-ink);
  outline-offset: 3px;
}

.image-gallery__image {
  display: block;
  width: 100%;
  height: auto;
}

.image-gallery__tile--placeholder {
  background-color: var(--color-surface);
  aspect-ratio: 4 / 3;
}

.image-gallery__tile--placeholder svg {
  width: 100%;
  height: 100%;
  fill: color-mix(in srgb, var(--color-ink) 12%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
  .image-gallery__image {
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .image-gallery__tile--button:hover .image-gallery__image,
  .image-gallery__tile[href]:hover .image-gallery__image {
    transform: scale(1.03);
  }
}

.image-gallery__caption {
  margin-top: var(--space-2);
  color: var(--color-muted);
}

/* ------------------------------------------------------------------ */
/* Lightbox                                                            */
/* ------------------------------------------------------------------ */
/* Shape shared with the product gallery's lightbox and the cart drawer:
   a top-layer <dialog>, motion driven from assets/overlay-motion.js by way
   of the .is-visible class rather than by @starting-style — see the long
   note at the top of that file for why the CSS-only version does not work
   on these elements. */
.image-gallery__lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  background-color: color-mix(in srgb, var(--color-ink) 92%, transparent);
  color: var(--color-bg);
  overflow: hidden;
}

.image-gallery__lightbox::backdrop {
  background-color: rgba(0, 0, 0, 0.7);
}

.image-gallery__lightbox-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: var(--space-8) var(--space-5) var(--space-7);
}

.image-gallery__stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  /* The stage is the swipe target on touch, so it must not scroll
     horizontally itself while a horizontal drag is being measured. */
  touch-action: pan-y;
}

.image-gallery__slide {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin: 0;
}

.image-gallery__slide.is-active {
  display: flex;
}

.image-gallery__slide-image {
  max-width: 100%;
  max-height: calc(100dvh - 200px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-m);
}

.image-gallery__slide-caption {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 14px;
  text-align: center;
  color: color-mix(in srgb, var(--color-bg) 80%, transparent);
}

.image-gallery__slide-link {
  color: var(--color-bg);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.image-gallery__counter {
  margin-top: var(--space-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--color-bg) 70%, transparent);
}

.image-gallery__lightbox-close,
.image-gallery__lightbox-nav {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid color-mix(in srgb, var(--color-bg) 25%, transparent);
  border-radius: var(--radius-pill);
  background-color: color-mix(in srgb, var(--color-ink) 60%, transparent);
  color: var(--color-bg);
  cursor: pointer;
}

.image-gallery__lightbox-close:hover,
.image-gallery__lightbox-nav:hover {
  background-color: color-mix(in srgb, var(--color-bg) 22%, transparent);
}

.image-gallery__lightbox-close:focus-visible,
.image-gallery__lightbox-nav:focus-visible {
  outline: 2px solid var(--color-bg);
  outline-offset: 2px;
}

.image-gallery__lightbox-close {
  top: var(--space-4);
  right: var(--space-4);
}

.image-gallery__lightbox-nav--prev {
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
}

/* The icon set has one arrow, pointing right; the previous control is that
   same glyph turned around rather than a second SVG to keep in step. */
.image-gallery__lightbox-nav--prev svg {
  transform: rotate(180deg);
}

.image-gallery__lightbox-nav--next {
  right: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
}

@media (prefers-reduced-motion: no-preference) {
  .image-gallery__lightbox {
    transition: opacity var(--motion-overlay) var(--motion-overlay-ease),
      transform var(--motion-overlay) var(--motion-overlay-ease);
  }

  .image-gallery__lightbox[open]:not(.is-visible) {
    opacity: 0;
    transform: scale(0.98);
  }

  .image-gallery__lightbox::backdrop {
    transition: opacity var(--motion-scrim) ease;
  }
}

@media screen and (max-width: 749px) {
  /* Two columns on a phone in both layouts — see the file header. */
  .image-gallery__grid--masonry {
    column-count: 2;
  }

  .image-gallery__grid--grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .image-gallery__lightbox-panel {
    padding: var(--space-7) var(--space-3) var(--space-6);
  }

  /* Side arrows would sit on top of the photograph at this width, so they
     drop to a row under it. */
  .image-gallery__lightbox-nav--prev,
  .image-gallery__lightbox-nav--next {
    top: auto;
    bottom: var(--space-4);
    transform: none;
  }

  .image-gallery__slide-image {
    max-height: calc(100dvh - 260px);
  }
}
