/**
 * Site Text — product photo gallery (visitor side).
 *
 * Loaded only on a product page that has two or more photos. Colours come from the
 * theme's own presets (primary / primary-dark / border), with Suryon's values as the
 * fallback, so the gallery reads as part of the page rather than a bolted-on widget.
 */

.site-text-gallery {
	--stg-accent: var( --wp--preset--color--primary, #008088 );
	--stg-ink: var( --wp--preset--color--primary-dark, #0f3d44 );
	--stg-line: var( --wp--preset--color--border, #dce7e8 );
}

.site-text-gallery > .wp-block-post-featured-image {
	position: relative;
	margin: 0;
}

.site-text-gallery > .wp-block-post-featured-image img {
	transition: opacity 0.18s ease;
}

body:not( .site-text-editing ) .site-text-gallery.is-ready > .wp-block-post-featured-image img {
	cursor: zoom-in;
}

.site-text-gallery.is-swapping > .wp-block-post-featured-image img {
	opacity: 0.35;
}

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

/* Five to a row, then the strip scrolls sideways. overflow-y is stated on purpose:
   overflow-x:auto alone promotes the other axis to auto too (CSS spec), which is the
   flashing-scrollbar trap this theme has already hit twice. */
.stg-thumbs {
	position: relative;
	display: flex;
	gap: 8px;
	margin: 12px 0 0;
	padding: 3px;
	list-style: none;
	overflow-x: auto;
	overflow-y: hidden;
	scrollbar-width: thin;
	scroll-snap-type: x proximity;
}

.stg-thumbs > li {
	flex: 0 0 calc( ( 100% - 32px ) / 5 );
	margin: 0;
	padding: 0;
	list-style: none;
	scroll-snap-align: start;
}

.stg-thumb {
	display: block;
	aspect-ratio: 1;
	border: 1px solid var( --stg-line );
	border-radius: 8px;
	overflow: hidden;
	opacity: 0.72;
	background: #f2f7f7;
	transition: opacity 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.stg-thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 0;
}

.stg-thumb:hover {
	opacity: 1;
	border-color: var( --stg-accent );
}

.stg-thumb.is-active {
	opacity: 1;
	border-color: var( --stg-accent );
	box-shadow: 0 0 0 2px var( --stg-accent );
}

.stg-thumb:focus-visible {
	opacity: 1;
	outline: 2px solid var( --stg-ink );
	outline-offset: 2px;
}

/* ---------------------------------------------------------------- on the main photo */

.stg-nav,
.stg-zoom {
	position: absolute;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.94 );
	color: var( --stg-ink );
	box-shadow: 0 2px 10px rgba( 15, 61, 68, 0.22 );
	cursor: pointer;
	transition: opacity 0.15s ease, background-color 0.15s ease;
}

.stg-nav svg,
.stg-zoom svg {
	width: 18px;
	height: 18px;
}

.stg-nav:hover,
.stg-zoom:hover {
	background: #fff;
}

.stg-nav:focus-visible,
.stg-zoom:focus-visible {
	outline: 2px solid var( --stg-accent );
	outline-offset: 2px;
}

.stg-nav {
	top: 50%;
	transform: translateY( -50% );
	opacity: 0;
}

.stg-prev {
	left: 10px;
}

.stg-next {
	right: 10px;
}

.site-text-gallery:hover .stg-nav,
.site-text-gallery:focus-within .stg-nav {
	opacity: 1;
}

/* Touch screens have no hover: the arrows stay visible. */
@media ( hover: none ) {
	.stg-nav {
		opacity: 1;
	}
}

.stg-zoom {
	left: 10px;
	bottom: 10px;
	width: 32px;
	height: 32px;
}

.stg-count {
	position: absolute;
	right: 10px;
	bottom: 10px;
	z-index: 2;
	padding: 3px 9px;
	border-radius: 999px;
	background: rgba( 15, 61, 68, 0.8 );
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: 0.02em;
	pointer-events: none;
}

/* ---------------------------------------------------------------- enlarged */

html.stg-lb-open {
	overflow: hidden;
}

.stg-lightbox {
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: rgba( 8, 20, 23, 0.94 );
	color: #fff;
}

.stg-lightbox::backdrop {
	background: rgba( 8, 20, 23, 0.94 );
}

.stg-lightbox[open] {
	display: flex;
	align-items: center;
	justify-content: center;
}

.stg-lb-img {
	max-width: calc( 100vw - 150px );
	max-height: calc( 100vh - 120px );
	max-height: calc( 100dvh - 120px );
	object-fit: contain;
	border-radius: 6px;
	background: #fff;
	box-shadow: 0 12px 48px rgba( 0, 0, 0, 0.5 );
}

.stg-lb-btn {
	position: absolute;
	display: grid;
	place-items: center;
	width: 46px;
	height: 46px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.12 );
	color: #fff;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.stg-lb-btn:hover {
	background: rgba( 255, 255, 255, 0.24 );
}

.stg-lb-btn:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.stg-lb-btn svg {
	width: 22px;
	height: 22px;
}

.stg-lb-close {
	top: 16px;
	right: 16px;
}

.stg-lb-prev {
	left: 20px;
	top: 50%;
	transform: translateY( -50% );
}

.stg-lb-next {
	right: 20px;
	top: 50%;
	transform: translateY( -50% );
}

.stg-lb-count {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX( -50% );
	font-size: 14px;
	font-weight: 600;
	opacity: 0.85;
}

@media ( max-width: 600px ) {
	.stg-lb-img {
		max-width: 100vw;
		max-height: calc( 100vh - 150px );
		max-height: calc( 100dvh - 150px );
		border-radius: 0;
	}

	.stg-lb-prev,
	.stg-lb-next {
		top: auto;
		bottom: 12px;
		transform: none;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.site-text-gallery > .wp-block-post-featured-image img,
	.stg-thumb,
	.stg-nav,
	.stg-zoom,
	.stg-lb-btn {
		transition: none;
	}

	.stg-thumbs {
		scroll-snap-type: none;
	}
}
