/**
 * Swift Product Gallery
 *
 * Layout is CSS grid + scroll snap. The gallery is fully usable before the
 * script runs; JS only adds zoom, the lightbox and variation switching.
 */

.spg {
	--spg-gap: 10px;
	--spg-primary: #111;
	--spg-secondary: #fff;
	--spg-thumbs: 4;
	--spg-zoom: 2.5;
	--spg-breakpoint: 768px;
	--spg-thumb-size: 88px;
	--spg-radius: 4px;

	display: grid;
	gap: var(--spg-gap);
	max-width: var(--spg-max-width, 100%);
	margin-inline: 0;
	position: relative;
}

.spg *,
.spg *::before,
.spg *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------- Stage */

.spg__stage {
	position: relative;
	min-width: 0;
	overflow: hidden;
	border-radius: var(--spg-radius);
}

.spg__track {
	display: flex;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.spg__track::-webkit-scrollbar {
	display: none;
}

.spg__track:focus-visible {
	outline: 2px solid var(--spg-primary);
	outline-offset: 2px;
}

.spg__slide {
	flex: 0 0 100%;
	scroll-snap-align: center;
	scroll-snap-stop: always;
	margin: 0;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
}

.spg__image {
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
	object-position: center;
	/* Natural-ratio mode: the image defines its own box, nothing is cropped. */
	object-fit: contain;
	-webkit-user-select: none;
	user-select: none;
	-webkit-user-drag: none;
}

/* Fixed-ratio mode: the box is forced, so the image has to fill it. Driven by
   a class, not by sniffing the style attribute — --spg-ratio arrives in a
   <style> block, so an [style*="--spg-ratio"] test never matches and every
   gallery silently fell back to letterboxing inside a forced box. */
.spg--fixed-ratio .spg__image {
	aspect-ratio: var(--spg-ratio);
	object-fit: cover;
}

.spg--fixed-ratio .spg__thumb img {
	object-fit: cover;
}

.spg__caption {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	padding: 8px 12px;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: var(--spg-secondary);
	background: color-mix(in srgb, var(--spg-primary) 72%, transparent);
	pointer-events: none;
}

/* --------------------------------------------------------- Stacked/grid */

.spg--layout-stacked .spg__track,
.spg--layout-grid .spg__track {
	display: grid;
	overflow: visible;
	scroll-snap-type: none;
	gap: var(--spg-gap);
}

.spg--layout-stacked .spg__track {
	grid-template-columns: 1fr;
}

.spg--layout-grid .spg__track {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.spg--layout-grid .spg__slide:first-child {
	grid-column: 1 / -1;
}

.spg--layout-stacked .spg__slide,
.spg--layout-grid .spg__slide {
	flex: initial;
}

.spg--layout-stacked .spg__arrow,
.spg--layout-grid .spg__arrow {
	display: none;
}

/* ------------------------------------------------------------- Controls */

.spg__arrow,
.spg__fullscreen,
.spg__play {
	position: absolute;
	z-index: 3;
	display: grid;
	place-items: center;
	padding: 0;
	border: 0;
	cursor: pointer;
	color: var(--spg-primary);
	background: color-mix(in srgb, var(--spg-secondary) 88%, transparent);
	border-radius: 50%;
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
	transition: opacity 0.18s ease, transform 0.18s ease;
	-webkit-appearance: none;
	appearance: none;
}

.spg__arrow {
	inline-size: 40px;
	block-size: 40px;
	top: 50%;
	translate: 0 -50%;
}

.spg__arrow--prev {
	inset-inline-start: 10px;
}

.spg__arrow--next {
	inset-inline-end: 10px;
}

.spg--rtl .spg__arrow svg {
	scale: -1 1;
}

.spg__arrow[disabled] {
	opacity: 0.25;
	cursor: default;
}

.spg__fullscreen {
	inline-size: 34px;
	block-size: 34px;
	inset-block-start: 10px;
	inset-inline-end: 10px;
}

/* Hover-reveal mode. Controls stay visible for keyboard users. */
.spg--arrows-hover .spg__arrow,
.spg--arrows-hover .spg__fullscreen {
	opacity: 0;
}

.spg--arrows-hover:hover .spg__arrow,
.spg--arrows-hover:hover .spg__fullscreen,
.spg--arrows-hover :focus-visible.spg__arrow,
.spg--arrows-hover :focus-visible.spg__fullscreen {
	opacity: 1;
}

.spg--arrows-never .spg__arrow {
	display: none;
}

@media (hover: none) {
	/* Touch devices never get :hover — always show. */
	.spg--arrows-hover .spg__arrow,
	.spg--arrows-hover .spg__fullscreen {
		opacity: 1;
	}
}

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

/* ----------------------------------------------------------- Thumbnails */

/* The strip is a scroll-snap carousel driven by its own arrows. The native
   scrollbar is hidden — dragging and wheel scrolling still work. */
.spg__thumbs-wrap {
	min-width: 0;
	display: flex;
	align-items: center;
	gap: 6px;
}

.spg__thumbs {
	display: flex;
	gap: var(--spg-gap);
	overflow: auto;
	scroll-behavior: smooth;
	scroll-snap-type: x proximity;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
	-ms-overflow-style: none;
	min-width: 0;
	flex: 1 1 auto;
}

.spg__thumbs::-webkit-scrollbar {
	display: none;
}

/* Real flex items, not overlays: the arrows reserve their own space so they
   can never cover the first or last thumbnail, and the strip's scroll origin
   stays at 0 — an inline padding gutter would offset it and break the
   "scrolled to the start" test. */
.spg__thumbs-arrow {
	flex: 0 0 auto;
	display: none;
	place-items: center;
	inline-size: 26px;
	block-size: 26px;
	padding: 0;
	border: var(--spg-border-width, 1px) solid var(--spg-border-colour, rgba(0, 0, 0, 0.12));
	border-radius: 50%;
	cursor: pointer;
	color: var(--spg-primary);
	background: var(--spg-secondary);
	transition: opacity 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

/* Only shown once the strip actually overflows. */
.spg__thumbs-wrap.is-scrollable .spg__thumbs-arrow {
	display: grid;
}

/* Dimmed rather than hidden, so the strip does not resize at the ends. */
.spg__thumbs-arrow[disabled] {
	opacity: 0.3;
	cursor: default;
}

.spg--rtl .spg__thumbs-arrow svg {
	scale: -1 1;
}

.spg__thumb {
	position: relative;
	flex: 0 0 calc((100% - (var(--spg-thumbs) - 1) * var(--spg-gap)) / var(--spg-thumbs));
	scroll-snap-align: start;
	display: block;
	border-radius: var(--spg-radius);
	overflow: hidden;
	box-shadow: inset 0 0 0 0 var(--spg-primary);
	transition: box-shadow 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
	opacity: 0.6;
	line-height: 0;
}

.spg__thumb img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: var(--spg-thumb-ratio, 1);
	object-fit: cover;
}

.spg__thumb:hover,
.spg__thumb:focus-visible {
	opacity: 1;
}

.spg__thumb.is-active {
	opacity: 1;
	box-shadow: inset 0 0 0 2px var(--spg-primary);
}

.spg__thumb-play {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	color: var(--spg-secondary);
	background: color-mix(in srgb, #000 28%, transparent);
}

/* ---------------------------------------------------------------- Border */

.spg--bordered .spg__stage,
.spg--bordered .spg__thumb {
	border: var(--spg-border-width, 1px) solid var(--spg-border-colour, #e0e0e0);
}

/* The active outline sits inside the border rather than replacing it. */
.spg--bordered .spg__thumb.is-active {
	border-color: var(--spg-primary);
}

/* --------------------------------------------------- Side thumbnails */

/* Side thumbnails switch the root grid to two columns and turn the strip
   into a vertical carousel. */
.spg--thumbs-left,
.spg--thumbs-right {
	grid-template-columns: var(--spg-thumb-size) minmax(0, 1fr);
	align-items: start;
}

.spg--thumbs-left .spg__thumbs-wrap,
.spg--thumbs-right .spg__thumbs-wrap {
	flex-direction: column;
	align-items: stretch;
}

/* Bound the column to the configured number of thumbnails.
   `max-height: 100%` would have nothing to resolve against here — the grid row
   is sized by its content, so the strip simply grew instead of scrolling. */
.spg--thumbs-left .spg__thumbs,
.spg--thumbs-right .spg__thumbs {
	flex-direction: column;
	overflow-x: hidden;
	overflow-y: auto;
	max-block-size: calc(
		var(--spg-thumbs) * var(--spg-thumb-size) +
		(var(--spg-thumbs) - 1) * var(--spg-gap)
	);
	scroll-snap-type: y proximity;
}

.spg--thumbs-left .spg__thumb,
.spg--thumbs-right .spg__thumb {
	flex: 0 0 auto;
}

/* Vertical strip: the column order already puts the arrows above and below,
   they just need to point that way. */
.spg--thumbs-left .spg__thumbs-arrow,
.spg--thumbs-right .spg__thumbs-arrow {
	align-self: center;
	rotate: 90deg;
}

.spg--thumbs-left .spg__thumbs-wrap {
	grid-column: 1;
	grid-row: 1;
}

.spg--thumbs-left .spg__stage {
	grid-column: 2;
	grid-row: 1;
}

.spg--thumbs-right {
	grid-template-columns: minmax(0, 1fr) var(--spg-thumb-size);
}

.spg--thumbs-right .spg__stage {
	grid-column: 1;
	grid-row: 1;
}

.spg--thumbs-right .spg__thumbs-wrap {
	grid-column: 2;
	grid-row: 1;
}

/* ------------------------------------------------------------ Dots (mobile) */

.spg__dots {
	display: none;
	justify-content: center;
	gap: 6px;
}

.spg__dot {
	inline-size: 7px;
	block-size: 7px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: color-mix(in srgb, var(--spg-primary) 28%, transparent);
	cursor: pointer;
	transition: background 0.15s ease, scale 0.15s ease;
}

.spg__dot.is-active {
	background: var(--spg-primary);
	scale: 1.3;
}

/* ---------------------------------------------------------------- Zoom */

.spg--zoom .spg__slide--image {
	cursor: zoom-in;
}

.spg--zoom-on-hover .spg__slide--image {
	cursor: crosshair;
}

.spg--zoom-on-click .spg__slide.is-zooming {
	cursor: zoom-out;
}

/* Inner — the magnified image replaces the slide in place. */

.spg__zoom-layer {
	position: absolute;
	inset: 0;
	z-index: 2;
	opacity: 0;
	pointer-events: none;
	background-repeat: no-repeat;
	background-color: var(--spg-secondary);
	transition: opacity 0.15s ease;
}

.spg__slide.is-zooming .spg__zoom-layer {
	opacity: 1;
}

/* Outside — a panel beside the gallery, plus a lens over the source region. */

/* The panel is a child of <body>, positioned by JS. Themes very often put
   overflow:hidden on the product container, and an absolutely positioned
   panel inside the gallery would simply be sliced off at that edge. */
.spg__zoom-panel {
	position: fixed;
	z-index: 100000;
	opacity: 0;
	pointer-events: none;
	background-repeat: no-repeat;
	background-color: #fff;
	border: 1px solid rgba(0, 0, 0, 0.12);
	border-radius: 4px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
	transition: opacity 0.12s ease;
}

.spg__zoom-panel.is-visible {
	opacity: 1;
}

.spg__zoom-lens {
	position: absolute;
	z-index: 3;
	opacity: 0;
	pointer-events: none;
	border: 1px solid rgba(255, 255, 255, 0.7);
	transition: opacity 0.12s ease;
}

.spg__slide.is-zooming .spg__zoom-lens {
	opacity: 1;
}

/* Follow — a magnifier tracking the cursor. */

.spg__zoom-follow {
	position: absolute;
	z-index: 4;
	opacity: 0;
	pointer-events: none;
	background-repeat: no-repeat;
	background-color: var(--spg-secondary);
	border: 2px solid rgba(255, 255, 255, 0.85);
	box-shadow: 0 3px 14px rgba(0, 0, 0, 0.28);
	transition: opacity 0.12s ease;
}

.spg__zoom-follow--circle {
	border-radius: 50%;
}

.spg__zoom-follow--square {
	border-radius: var(--spg-radius);
}

.spg__slide.is-zooming .spg__zoom-follow {
	opacity: 1;
}

/* Outside zoom needs room to the side; below the breakpoint there is none,
   so fall back to the inner behaviour rather than overflowing the viewport. */
@media (max-width: 768px) {
	.spg__zoom-panel {
		display: none;
	}
}

/* --------------------------------------------------------------- Video */

.spg__video {
	position: relative;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #000;
	aspect-ratio: var(--spg-ratio, 16 / 9);
}

.spg__video video,
.spg__video iframe {
	width: 100%;
	height: 100%;
	border: 0;
	display: block;
	object-fit: contain;
}

.spg__play {
	inline-size: 62px;
	block-size: 62px;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	translate: -50% -50%;
	opacity: 1 !important;
}

.spg__play:hover {
	scale: 1.06;
}

.spg__video.is-playing .spg__play,
.spg__video.is-playing .spg__video-poster {
	display: none;
}

/* ------------------------------------------------------------ Lightbox */

.spg-lightbox {
	inline-size: 100%;
	block-size: 100%;
	max-inline-size: 100%;
	max-block-size: 100%;
	padding: 0;
	border: 0;
	background: #0b0b0b;
	color: #fff;
	overflow: hidden;
}

.spg-lightbox--light {
	background: #f6f6f6;
	color: #111;
}

.spg-lightbox::backdrop {
	background: rgba(0, 0, 0, 0.92);
}

.spg-lightbox__track {
	display: flex;
	block-size: 100%;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	overscroll-behavior: contain;
}

.spg-lightbox__track::-webkit-scrollbar {
	display: none;
}

.spg-lightbox__item {
	flex: 0 0 100%;
	scroll-snap-align: center;
	display: grid;
	place-items: center;
	padding: 3vmin;
	overflow: auto;
}

.spg-lightbox__item img {
	max-inline-size: 100%;
	max-block-size: 92vh;
	inline-size: auto;
	block-size: auto;
	object-fit: contain;
	cursor: zoom-in;
}

/* Magnification resizes the image (see toggleLightboxZoom) so the item's
   overflow produces a real scroll area that can be panned. */
.spg-lightbox__item img.is-zoomed {
	cursor: grab;
}

.spg-lightbox__item img.is-zoomed:active {
	cursor: grabbing;
}

/* Centred alignment puts the overflow on both sides of a grid item, which
   makes the top and left of a zoomed image unreachable by scrolling. */
.spg-lightbox__item.is-zoomed {
	place-items: start;
	touch-action: pan-x pan-y pinch-zoom;
}

.spg-lightbox__close,
.spg-lightbox__nav {
	position: fixed;
	z-index: 5;
	display: grid;
	place-items: center;
	inline-size: 44px;
	block-size: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	color: inherit;
	background: rgba(127, 127, 127, 0.22);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

.spg-lightbox__close {
	inset-block-start: 16px;
	inset-inline-end: 16px;
}

.spg-lightbox__nav--prev {
	inset-inline-start: 16px;
	inset-block-start: 50%;
	translate: 0 -50%;
}

.spg-lightbox__nav--next {
	inset-inline-end: 16px;
	inset-block-start: 50%;
	translate: 0 -50%;
}

.spg-lightbox__caption {
	position: fixed;
	inset-inline: 0;
	inset-block-end: 0;
	padding: 12px 16px;
	text-align: center;
	font-size: 0.875rem;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
	pointer-events: none;
}

.spg-lightbox__counter {
	position: fixed;
	inset-block-start: 20px;
	inset-inline-start: 20px;
	font-size: 0.8125rem;
	opacity: 0.7;
	font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- State */

.spg.is-loading .spg__stage {
	opacity: 0.45;
	transition: opacity 0.15s ease;
}

.spg.is-loading .spg__stage::after {
	content: "";
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	inline-size: 28px;
	block-size: 28px;
	margin: -14px 0 0 -14px;
	border: 2px solid color-mix(in srgb, var(--spg-primary) 25%, transparent);
	border-top-color: var(--spg-primary);
	border-radius: 50%;
	animation: spg-spin 0.7s linear infinite;
}

@keyframes spg-spin {
	to {
		rotate: 360deg;
	}
}

/* -------------------------------------------------------------- Mobile */

@media (max-width: 768px) {
	.spg--thumbs-left,
	.spg--thumbs-right {
		grid-template-columns: minmax(0, 1fr);
	}

	.spg--thumbs-left .spg__stage,
	.spg--thumbs-right .spg__stage,
	.spg--thumbs-left .spg__thumbs-wrap,
	.spg--thumbs-right .spg__thumbs-wrap {
		grid-column: 1;
	}

	.spg--thumbs-left .spg__stage,
	.spg--thumbs-right .spg__stage {
		grid-row: 1;
	}

	/* Below the breakpoint a side strip becomes a horizontal one, so every
	   vertical-carousel override has to be undone. */
	.spg--thumbs-left .spg__thumbs-wrap,
	.spg--thumbs-right .spg__thumbs-wrap {
		grid-row: 2;
		flex-direction: row;
		align-items: center;
	}

	.spg--thumbs-left .spg__thumbs,
	.spg--thumbs-right .spg__thumbs {
		flex-direction: row;
		overflow-x: auto;
		overflow-y: hidden;
		max-block-size: none;
		scroll-snap-type: x proximity;
	}

	.spg--thumbs-left .spg__thumbs-arrow,
	.spg--thumbs-right .spg__thumbs-arrow {
		rotate: 0deg;
	}

	.spg--mobile-dots .spg__thumbs-wrap {
		display: none;
	}

	.spg--mobile-dots .spg__dots {
		display: flex;
	}

	.spg--layout-grid .spg__track {
		grid-template-columns: minmax(0, 1fr);
	}

	.spg__arrow {
		inline-size: 34px;
		block-size: 34px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.spg__track,
	.spg-lightbox__track {
		scroll-behavior: auto;
	}

	.spg *,
	.spg-lightbox * {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
	}
}
