/* ==========================================================================
   Product Gallery
   Structure: .starterkit-gallery > __stage (> __main.swiper > __track > __slide)
              + __thumbnails.swiper (> __thumb-track > __thumb-item > __thumbnail)
              + __pagination + __dialog.
   Class and data-* hooks are used by script.js; only presentation lives here.
   ========================================================================== */

/* Tokens ------------------------------------------------------------------ */

.starterkit-gallery,
.woocommerce div.product div.images.starterkit-gallery,
.woocommerce-page div.product div.images.starterkit-gallery {
	/* Overridable from Block settings (inline style): gap, stage radius, surface, image padding. */
	--starterkit-gallery-gap: 16px;
	--starterkit-gallery-surface: var(--sk-color-subtle, #f8fafc);
	--starterkit-gallery-border: var(--sk-color-border, #e2e8f0);
	--starterkit-gallery-ink: var(--sk-color-ink, #111827);
	--starterkit-gallery-focus: var(--sk-color-focus, #005bd3);
	--starterkit-gallery-radius: var(--starterkit-gallery-stage-radius, 14px);
	/* Thumbnails follow the stage radius, capped so small tiles stay crisp. */
	--starterkit-gallery-thumb-radius: min(var(--starterkit-gallery-radius), var(--sk-radius-sm, 8px));
	/* `--starterkit-gallery-thumb-size-custom` comes from the Thumbnail Size Block setting. */
	--starterkit-gallery-thumb-size: var(--starterkit-gallery-thumb-size-custom, 72px);
	--starterkit-gallery-thumb-gap: var(--sk-space-3, 12px);
	--starterkit-gallery-control-size: 40px;
	--starterkit-gallery-inset: var(--sk-space-4, 16px);
	--starterkit-gallery-shadow: var(--sk-shadow-sm, 0 1px 2px rgba(15, 23, 42, .06));
	--starterkit-gallery-transition: .2s ease;

	/* Neutralize WooCommerce's floated 48% gallery column. */
	width: 100% !important;
	max-width: 100% !important;
	float: none !important;
	margin-bottom: 0 !important;
}

.starterkit-gallery.is-starterkit-gallery-owned {
	display: grid;
	gap: var(--starterkit-gallery-gap);
}

/* Stage and main image ---------------------------------------------------- */

.starterkit-gallery__stage {
	position: relative;
	min-width: 0;
	overflow: hidden;
	border: 1px solid var(--starterkit-gallery-border);
	border-radius: var(--starterkit-gallery-radius);
	background: var(--starterkit-gallery-surface);
}

.starterkit-gallery__main {
	position: relative;
	overflow: hidden;
	width: 100%;
	min-width: 0;
	aspect-ratio: 1;
	/* Let Swiper handle horizontal gestures without blocking page scroll. */
	touch-action: pan-y;
}

.starterkit-gallery--ratio-portrait .starterkit-gallery__main {
	aspect-ratio: 3 / 4;
}

.starterkit-gallery--ratio-landscape .starterkit-gallery__main {
	aspect-ratio: 4 / 3;
}

.starterkit-gallery__track {
	display: block;
	height: 100%;
}

.starterkit-gallery__main.swiper .starterkit-gallery__track {
	display: flex;
}

.starterkit-gallery__slide {
	position: relative;
	min-width: 0;
	height: 100%;
}

.starterkit-gallery__main.swiper .starterkit-gallery__slide {
	flex: 0 0 100%;
	width: 100%;
}

/* WooCommerce sizes every gallery image after the first as a 25% inline-block
   (`.woocommerce div.product div.images .woocommerce-product-gallery__image:nth-child(n+2)`),
   which outranks component selectors and also defeated the static-mode hiding below. */
.starterkit-gallery .starterkit-gallery__slide {
	display: block !important;
	width: 100% !important;
}

.starterkit-gallery--collage .starterkit-gallery__slide {
	width: auto !important;
}

/* WooCommerce also sets `div.images img { height: auto }` and `__image a { display: block }`,
   which top-align every image instead of centring it inside the stage. */
.starterkit-gallery .starterkit-gallery__link {
	display: flex !important;
}

.starterkit-gallery .starterkit-gallery__image {
	height: 100% !important;
}

/* Without Swiper only the active image shows; the collage always shows every image. */
.starterkit-gallery.is-static:not(.starterkit-gallery--collage) .starterkit-gallery__slide[aria-hidden="true"] {
	display: none !important;
}

.starterkit-gallery__link {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	min-width: 0;
	min-height: 0;
	text-decoration: none;
}

/* The image is a flex item: without min-*: 0 it would refuse to shrink below its
   intrinsic size and overflow the stage instead of being contained. */
.starterkit-gallery__image {
	display: block;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	min-width: 0;
	min-height: 0;
	max-width: 100%;
	max-height: 100%;
	padding: var(--starterkit-gallery-image-padding, 0);
	object-fit: contain;
}

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

.starterkit-gallery__thumbnails {
	position: relative;
	min-width: 0;
	margin: 0;
	padding: 0;
	overflow: hidden;
}

.starterkit-gallery__thumb-track {
	display: flex;
	gap: var(--starterkit-gallery-thumb-gap);
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	list-style: none;
}

.starterkit-gallery__thumb-item {
	flex: 0 0 var(--starterkit-gallery-thumb-size);
	box-sizing: border-box;
	width: var(--starterkit-gallery-thumb-size);
	height: var(--starterkit-gallery-thumb-size);
	margin: 0;
	padding: 0;
	list-style: none;
}

.starterkit-gallery__thumbnail {
	position: relative;
	display: block;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	padding: 0;
	overflow: hidden;
	border: 1px solid var(--starterkit-gallery-border);
	border-radius: var(--starterkit-gallery-thumb-radius);
	background: var(--starterkit-gallery-surface);
	cursor: pointer;
	appearance: none;
	transition: border-color var(--starterkit-gallery-transition), box-shadow var(--starterkit-gallery-transition);
}

.starterkit-gallery__thumbnail img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	pointer-events: none;
}

/* WooCommerce styles the thumbnail list through `.woocommerce div.product div.images
   .flex-control-thumbs li` (width: 25%; float: left) and `... li img` (opacity: .5, lifted
   only by its own `.flex-active` class, which this gallery does not use). Those selectors
   outrank any component selector, so the overrides are pinned here. */
.starterkit-gallery .starterkit-gallery__thumb-item {
	width: var(--starterkit-gallery-thumb-size) !important;
	float: none !important;
}

.starterkit-gallery .starterkit-gallery__thumbnail img {
	margin: 0 !important;
	opacity: 1 !important;
}

.starterkit-gallery__thumbnail:hover {
	border-color: color-mix(in srgb, var(--starterkit-gallery-ink) 40%, var(--starterkit-gallery-border));
}

/* Active: a 2px ring drawn inside the tile, so the layout never shifts. */
.starterkit-gallery__thumbnail.is-active,
.starterkit-gallery__thumb-item.is-active .starterkit-gallery__thumbnail,
.starterkit-gallery__thumb-item.swiper-slide-thumb-active .starterkit-gallery__thumbnail {
	border-color: var(--starterkit-gallery-ink);
	box-shadow: inset 0 0 0 1px var(--starterkit-gallery-ink);
}

/* Prev / next ------------------------------------------------------------- */

.starterkit-gallery__navigation {
	position: absolute;
	z-index: 2;
	top: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: var(--starterkit-gallery-control-size);
	min-width: 0;
	height: var(--starterkit-gallery-control-size);
	/* Swiper's default arrow offsets the button by half its own size. */
	margin: 0;
	padding: 0;
	border: 1px solid var(--starterkit-gallery-border);
	border-radius: 50%;
	background: var(--sk-color-surface, #fff);
	color: var(--starterkit-gallery-ink);
	box-shadow: var(--starterkit-gallery-shadow);
	cursor: pointer;
	appearance: none;
	opacity: 0;
	transform: translateY(-50%);
	transition: opacity var(--starterkit-gallery-transition), background-color var(--starterkit-gallery-transition);
}

.starterkit-gallery__navigation--prev { left: var(--starterkit-gallery-inset); }
.starterkit-gallery__navigation--next { right: var(--starterkit-gallery-inset); }

/* Revealed on hover and for keyboard users; always shown on touch screens. */
.starterkit-gallery__stage:hover .starterkit-gallery__navigation,
.starterkit-gallery__stage:focus-within .starterkit-gallery__navigation {
	opacity: 1;
}

@media (hover: none) {
	.starterkit-gallery__navigation {
		opacity: 1;
	}
}

.starterkit-gallery__navigation:hover {
	background: var(--starterkit-gallery-surface);
}

.starterkit-gallery__navigation.swiper-button-disabled {
	opacity: 0 !important;
	pointer-events: none;
}

/* Swiper ships its own icon-font arrow; the theme draws a chevron instead. */
.starterkit-gallery__navigation::after {
	content: none;
}

.starterkit-gallery__navigation::before {
	content: "";
	width: 8px;
	height: 8px;
	border-top: 2px solid currentColor;
	border-right: 2px solid currentColor;
	transform: translateX(-2px) rotate(45deg);
}

.starterkit-gallery__navigation--prev::before {
	transform: translateX(2px) rotate(-135deg);
}

/* Pagination -------------------------------------------------------------- */

/* Two classes, to outrank Swiper's `.swiper-pagination-bullets.swiper-pagination-horizontal`
   offsets (bottom: 8px; left: 0; width: 100%) that would shift this in-flow row. */
.starterkit-gallery .starterkit-gallery__pagination {
	position: relative;
	inset: auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	width: auto;
	margin: 0;
}

.starterkit-gallery__pagination .swiper-pagination-bullet {
	width: 6px;
	height: 6px;
	margin: 0 !important;
	border-radius: 999px;
	background: var(--starterkit-gallery-border);
	opacity: 1;
	transition: width var(--starterkit-gallery-transition), background-color var(--starterkit-gallery-transition);
}

.starterkit-gallery__pagination .swiper-pagination-bullet-active {
	width: 18px;
	background: var(--starterkit-gallery-ink);
}

/* Overlays: sale badge and zoom ------------------------------------------- */

.starterkit-gallery__sale-badge,
.starterkit-gallery__zoom {
	position: absolute;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	min-height: 32px;
	padding: 0 12px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	line-height: 1;
}

.starterkit-gallery__sale-badge {
	top: var(--starterkit-gallery-inset);
	left: var(--starterkit-gallery-inset);
	background: var(--color-ecommerce-sale, #d72c0d);
	color: #fff;
}

.starterkit-gallery__zoom {
	right: var(--starterkit-gallery-inset);
	bottom: var(--starterkit-gallery-inset);
	gap: 6px;
	border: 1px solid var(--starterkit-gallery-border);
	background: var(--sk-color-surface, #fff);
	color: var(--starterkit-gallery-ink);
	box-shadow: var(--starterkit-gallery-shadow);
	cursor: pointer;
	appearance: none;
}

.starterkit-gallery__zoom:hover {
	background: var(--starterkit-gallery-surface);
}

.starterkit-gallery__zoom-icon {
	position: relative;
	display: inline-block;
	box-sizing: border-box;
	width: 12px;
	height: 12px;
	border: 2px solid currentColor;
	border-radius: 50%;
}

.starterkit-gallery__zoom-icon::after {
	content: "";
	position: absolute;
	right: -5px;
	bottom: -3px;
	width: 5px;
	height: 2px;
	background: currentColor;
	transform: rotate(45deg);
	transform-origin: left center;
}

/* Focus ------------------------------------------------------------------- */

.starterkit-gallery__navigation:focus-visible,
.starterkit-gallery__zoom:focus-visible,
.starterkit-gallery__dialog-close:focus-visible {
	outline: 2px solid var(--starterkit-gallery-focus);
	outline-offset: 2px;
}

/* These sit inside clipped containers: keep the ring inside. */
.starterkit-gallery__main:focus-visible,
.starterkit-gallery__link:focus-visible,
.starterkit-gallery__thumbnail:focus-visible {
	outline: 2px solid var(--starterkit-gallery-focus);
	outline-offset: -2px;
}

/* Vertical layout (thumbnail rail beside the stage) ----------------------- */

.starterkit-gallery.is-starterkit-gallery-owned.starterkit-gallery--vertical {
	grid-template-columns: var(--starterkit-gallery-thumb-size) minmax(0, 1fr);
	align-items: start;
}

.starterkit-gallery.is-starterkit-gallery-owned.starterkit-gallery--vertical.starterkit-gallery--thumbs-right {
	grid-template-columns: minmax(0, 1fr) var(--starterkit-gallery-thumb-size);
}

.starterkit-gallery--vertical .starterkit-gallery__stage {
	grid-column: 2;
	grid-row: 1;
}

.starterkit-gallery--vertical .starterkit-gallery__thumbnails {
	grid-column: 1;
	grid-row: 1;
	width: var(--starterkit-gallery-thumb-size);
	touch-action: pan-y;
}

.starterkit-gallery--vertical.starterkit-gallery--thumbs-right .starterkit-gallery__stage { grid-column: 1; }
.starterkit-gallery--vertical.starterkit-gallery--thumbs-right .starterkit-gallery__thumbnails { grid-column: 2; }

/* A single image renders no rail, so no column is reserved for one. */
.starterkit-gallery.is-starterkit-gallery-owned.starterkit-gallery--vertical.starterkit-gallery--single {
	grid-template-columns: minmax(0, 1fr);
}

.starterkit-gallery--vertical.starterkit-gallery--single .starterkit-gallery__stage {
	grid-column: 1;
}

.starterkit-gallery--vertical .starterkit-gallery__thumb-track {
	flex-direction: column;
	/* Swiper writes an inline width on its wrapper. */
	width: 100% !important;
}

@media (min-width: 768px) {
	/* The rail follows the stage height instead of growing the grid row: size containment
	 * removes its content from the row's intrinsic height, stretch fills the row the stage
	 * defines, and Swiper (vertical, slidesPerView auto) scrolls the remaining thumbnails.
	 * Without Swiper the rail scrolls natively. */
	.starterkit-gallery--vertical .starterkit-gallery__thumbnails {
		align-self: stretch;
		box-sizing: border-box;
		contain: size;
	}

	.starterkit-gallery--vertical .starterkit-gallery__thumbnails:not(.swiper-initialized) {
		overflow-y: auto;
		scrollbar-width: none;
	}

	.starterkit-gallery--vertical .starterkit-gallery__thumbnails:not(.swiper-initialized)::-webkit-scrollbar {
		display: none;
	}

	/* Thumbnails already show the position beside the stage. */
	.starterkit-gallery--vertical .starterkit-gallery__pagination {
		display: none;
	}

	.starterkit-gallery--collage .starterkit-gallery__navigation {
		display: none;
	}

	/* Desktop collage: each tile carries the stage surface; the stage itself only positions overlays. */
	.starterkit-gallery--collage .starterkit-gallery__stage {
		overflow: visible;
		border: 0;
		border-radius: 0;
		background: none;
	}

	.starterkit-gallery--collage .starterkit-gallery__slide {
		overflow: hidden;
		border: 1px solid var(--starterkit-gallery-border);
		border-radius: var(--starterkit-gallery-radius);
		background: var(--starterkit-gallery-surface);
	}

	/* The lead tile spans two rows; pin its link to the tile so the image fills that height. */
	.starterkit-gallery--collage .starterkit-gallery__slide:first-child .starterkit-gallery__link {
		position: absolute;
		inset: 0;
	}

	.starterkit-gallery--collage .starterkit-gallery__slide:first-child .starterkit-gallery__image {
		aspect-ratio: auto;
	}
}

/* Collage layout ---------------------------------------------------------- */

.starterkit-gallery--collage .starterkit-gallery__main {
	overflow: visible;
	aspect-ratio: auto;
}

.starterkit-gallery--collage .starterkit-gallery__track {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	grid-auto-rows: minmax(180px, 1fr);
	gap: var(--starterkit-gallery-gap);
}

.starterkit-gallery--collage .starterkit-gallery__slide:first-child {
	grid-row: span 2;
}

.starterkit-gallery--collage .starterkit-gallery__image {
	aspect-ratio: 1;
}

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

.starterkit-gallery__dialog {
	max-width: min(90vw, 1100px);
	max-height: 90vh;
	padding: var(--sk-space-5, 24px);
	border: 0;
	border-radius: var(--sk-radius-md, 12px);
	background: var(--starterkit-gallery-surface);
}

.starterkit-gallery__dialog::backdrop {
	background: rgba(15, 23, 42, .78);
}

.starterkit-gallery__dialog img {
	display: block;
	max-width: 100%;
	max-height: 80vh;
	object-fit: contain;
}

.starterkit-gallery__dialog-close {
	position: absolute;
	top: var(--sk-space-2, 8px);
	right: var(--sk-space-2, 8px);
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--starterkit-gallery-ink);
	font-size: 28px;
	line-height: 1;
	cursor: pointer;
}

/* Lightbox arrows (Block setting "Lightbox arrows"). */
.starterkit-gallery__dialog-nav {
	position: absolute;
	top: 50%;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 1px solid var(--starterkit-gallery-border);
	border-radius: 50%;
	background: var(--sk-color-surface, #fff);
	color: var(--starterkit-gallery-ink);
	box-shadow: var(--starterkit-gallery-shadow);
	cursor: pointer;
	transform: translateY(-50%);
}

.starterkit-gallery__dialog-nav::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 10px;
	height: 10px;
	border-top: 2px solid currentColor;
	border-right: 2px solid currentColor;
	transform: translate(-65%, -50%) rotate(45deg);
}

.starterkit-gallery__dialog-nav--prev { left: var(--sk-space-2, 8px); }
.starterkit-gallery__dialog-nav--next { right: var(--sk-space-2, 8px); }
.starterkit-gallery__dialog-nav--prev::before { transform: translate(-35%, -50%) rotate(-135deg); }

.starterkit-gallery__dialog-nav:focus-visible {
	outline: 2px solid var(--starterkit-gallery-focus);
	outline-offset: 2px;
}

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

@media (max-width: 767px) {
	.starterkit-gallery,
	.woocommerce div.product div.images.starterkit-gallery,
	.woocommerce-page div.product div.images.starterkit-gallery {
		--starterkit-gallery-thumb-size: min(var(--starterkit-gallery-thumb-size-custom, 64px), 64px);
		--starterkit-gallery-thumb-gap: var(--sk-space-2, 8px);
		--starterkit-gallery-control-size: 36px;
		--starterkit-gallery-inset: var(--sk-space-3, 12px);
		/* Full-bleed photos on small screens: overrides the inline Block setting. */
		--starterkit-gallery-image-padding: 0px !important;
	}

	/* Every layout stacks: stage, horizontal thumbnail strip, pagination. Same
	 * specificity as the desktop column rules so thumbs-right stacks too. */
	.starterkit-gallery.is-starterkit-gallery-owned.starterkit-gallery--vertical,
	.starterkit-gallery.is-starterkit-gallery-owned.starterkit-gallery--vertical.starterkit-gallery--thumbs-right {
		grid-template-columns: minmax(0, 1fr);
	}

	.starterkit-gallery--vertical .starterkit-gallery__stage,
	.starterkit-gallery--vertical .starterkit-gallery__thumbnails,
	.starterkit-gallery--vertical.starterkit-gallery--thumbs-right .starterkit-gallery__stage,
	.starterkit-gallery--vertical.starterkit-gallery--thumbs-right .starterkit-gallery__thumbnails {
		grid-column: 1;
		grid-row: auto;
	}

	.starterkit-gallery--vertical .starterkit-gallery__thumbnails {
		order: 2;
		width: 100%;
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: none;
	}

	.starterkit-gallery--vertical .starterkit-gallery__thumbnails::-webkit-scrollbar {
		display: none;
	}

	.starterkit-gallery--vertical .starterkit-gallery__thumb-track {
		flex-direction: row;
		width: auto !important;
	}

	.starterkit-gallery--vertical .starterkit-gallery__pagination {
		order: 3;
	}

	/* The collage becomes a one-image slider. */
	.starterkit-gallery--collage .starterkit-gallery__main {
		overflow: hidden;
		aspect-ratio: 1;
	}

	.starterkit-gallery--collage .starterkit-gallery__track {
		display: flex;
		gap: 0;
	}

	.starterkit-gallery--collage .starterkit-gallery__slide {
		flex: 0 0 100%;
	}

	.starterkit-gallery--collage .starterkit-gallery__slide:first-child {
		grid-row: auto;
	}
}

/* Mobile navigation (Block setting "Mobile Navigation"); `both` adds no class. */
@media (max-width: 767px) {
	.starterkit-gallery.starterkit-gallery--mobile-thumbs .starterkit-gallery__pagination {
		display: none;
	}

	.starterkit-gallery.starterkit-gallery--mobile-dots .starterkit-gallery__thumbnails {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.starterkit-gallery *,
	.starterkit-gallery *::before,
	.starterkit-gallery *::after {
		scroll-behavior: auto !important;
		transition-duration: .01ms !important;
		animation-duration: .01ms !important;
	}
}
