/* Scoped styles for Product Custom Background (.pcb-*) */

.woocommerce-product-gallery.pcb-has-custom-bg,
#wpgs-gallery.pcb-has-custom-bg {
	--pcb-aspect-ratio: 1 / 1;
	--pcb-pen-padding: clamp(0.75rem, 3vw, 2rem);
	--pcb-bg-radius: 0px;
}

.woocommerce-product-gallery.pcb-has-custom-bg {
	position: relative;
	max-width: 100%;
	box-sizing: border-box;
	container-type: inline-size;
	container-name: pcb-gallery;
}

.woocommerce-product-gallery.pcb-has-custom-bg *,
.woocommerce-product-gallery.pcb-has-custom-bg *::before,
.woocommerce-product-gallery.pcb-has-custom-bg *::after,
#wpgs-gallery.pcb-has-custom-bg *,
#wpgs-gallery.pcb-has-custom-bg *::before,
#wpgs-gallery.pcb-has-custom-bg *::after {
	box-sizing: border-box;
}

/* Fixed background viewport layer (default WooCommerce gallery) */
.woocommerce-product-gallery.pcb-has-custom-bg .pcb-bg-layer {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	aspect-ratio: var(--pcb-aspect-ratio, 1 / 1);
	z-index: 1;
	pointer-events: none;
	overflow: hidden;
	border-radius: var(--pcb-bg-radius);
}

/* When FlexSlider wraps slides in .flex-viewport, fill the stationary viewport */
.woocommerce-product-gallery.pcb-has-custom-bg .flex-viewport {
	position: relative;
	overflow: hidden;
	width: 100%;
	height: auto !important;
	aspect-ratio: var(--pcb-aspect-ratio, 1 / 1);
	transform-style: flat;
	border-radius: var(--pcb-bg-radius);
}

.woocommerce-product-gallery.pcb-has-custom-bg .flex-viewport > .pcb-bg-layer {
	inset: 0;
	height: 100%;
	aspect-ratio: auto;
}

.woocommerce-product-gallery.pcb-has-custom-bg .pcb-bg-layer > .pcb-bg-img,
#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel > .pcb-bg-layer > .pcb-bg-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	object-position: center;
	margin: 0;
	padding: 0;
	border: 0;
	box-shadow: none;
}

/* Pen image slides layered above the fixed background (default WooCommerce gallery) */
.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__wrapper {
	position: relative;
	z-index: 2;
	margin: 0;
	padding: 0;
}

.woocommerce-product-gallery.pcb-has-custom-bg .flex-viewport > .woocommerce-product-gallery__wrapper {
	height: 100%;
}

.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image {
	position: relative;
	aspect-ratio: var(--pcb-aspect-ratio, 1 / 1);
	overflow: hidden;
	margin: 0;
}

.woocommerce-product-gallery.pcb-has-custom-bg .flex-viewport .woocommerce-product-gallery__image {
	height: 100%;
}

.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image > a {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: var(--pcb-pen-padding);
	position: relative;
	z-index: 1;
}

.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image > a > img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	object-position: center;
	margin: 0;
	background: transparent;
}

/* Keep transparent pen zoom layer transparent over custom background */
.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__wrapper .zoomImg {
	background-color: transparent !important;
	z-index: 2;
}

@media (hover: hover) and (pointer: fine) {
	.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image:has(> .zoomImg):hover > a > img {
		opacity: 0;
		transition: opacity 0.12s ease;
	}
}

/* Preserve stacking order for PhotoSwipe trigger, thumbnails, and sale badge */
.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__trigger {
	z-index: 20;
}

.woocommerce-product-gallery.pcb-has-custom-bg .flex-control-thumbs {
	position: relative;
	z-index: 3;
}

/* WooGallery (gallery-slider-for-woocommerce) compatibility */
#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel {
	position: relative;
	overflow: hidden;
	aspect-ratio: var(--pcb-aspect-ratio, 1 / 1);
	container-type: inline-size;
	container-name: pcb-gallery;
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel > .pcb-bg-layer {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 1;
	pointer-events: none;
	overflow: hidden;
	border-radius: var(--pcb-bg-radius);
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel > .spswiper-wrapper {
	position: relative;
	z-index: 2;
	height: 100%;
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .spswiper-slide,
#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-slider-image {
	height: 100%;
	aspect-ratio: var(--pcb-aspect-ratio, 1 / 1);
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-slider-image {
	position: relative;
	display: block;
	padding: var(--pcb-pen-padding);
	background: transparent;
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-slider-lightbox {
	position: absolute;
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-slider-image-tag {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	object-position: center;
	background: transparent;
}

#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-lightbox,
#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-spswiper-arrow,
#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .spswiper-pagination {
	z-index: 20;
}

#wpgs-gallery.pcb-has-custom-bg .gallery-navigation-carousel-wrapper {
	position: relative;
	z-index: 3;
}

.product:has(> .pcb-has-custom-bg) > .onsale {
	z-index: 25;
}

/* Container-aware spacing across small (320px) through ultrawide (2560px) viewports */
@supports (width: 1cqi) {
	.woocommerce-product-gallery.pcb-has-custom-bg,
	#wpgs-gallery.pcb-has-custom-bg {
		--pcb-pen-padding: clamp(0.625rem, 4cqi, 2.25rem);
	}
}

@container pcb-gallery (max-width: 380px) {
	.woocommerce-product-gallery.pcb-has-custom-bg,
	#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel {
		--pcb-pen-padding: clamp(0.5rem, 3cqi, 1rem);
	}
}

@container pcb-gallery (min-width: 800px) {
	.woocommerce-product-gallery.pcb-has-custom-bg,
	#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel {
		--pcb-pen-padding: clamp(1.5rem, 3.5cqi, 2.75rem);
	}
}

/* High-DPI rendering clarity */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
	.woocommerce-product-gallery.pcb-has-custom-bg .pcb-bg-layer > .pcb-bg-img,
	.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image > a > img,
	#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel > .pcb-bg-layer > .pcb-bg-img,
	#wpgs-gallery.pcb-has-custom-bg .wcgs-carousel .wcgs-slider-image-tag {
		image-rendering: auto;
	}
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
	.woocommerce-product-gallery.pcb-has-custom-bg,
	.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__wrapper,
	.woocommerce-product-gallery.pcb-has-custom-bg .woocommerce-product-gallery__image > a > img,
	.woocommerce-product-gallery.pcb-has-custom-bg .pcb-bg-layer,
	#wpgs-gallery.pcb-has-custom-bg .spswiper-wrapper,
	#wpgs-gallery.pcb-has-custom-bg .pcb-bg-layer {
		transition: none !important;
		animation: none !important;
	}
}
