@use "../shared/added";
@use "../shared/arrows";

// Shared with the slider through gpu slider's own sheet.
@import "../../node_modules/gpuslider/lib/style";

.ewps-morph {
	container-type: inline-size;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	min-width: 0;
	position: relative;
}

.ewps-morph-media {
	overflow: clip;
	position: relative;

	.gs {
		aspect-ratio: var(--ewps-aspect, 4 / 5);
		position: relative;
		width: 100%;
	}

	.gs-slide > a {
		display: block;
		height: 100%;
	}

	// The stack's grid has to end at the height of the image shape.
	.gs-track {
		grid-template-rows: minmax(0, 1fr);
		height: 100%;
	}

	.gs-slide {
		height: 100%;
	}

	.gs-media {
		display: block;
		height: 100%;
		object-fit: var(--ewps-fit, cover);
		user-select: none;
		width: 100%;
	}
}

.ewps-morph-dots {
	bottom: 0.625rem;
	display: flex;
	gap: 0.25rem;
	left: 0.625rem;
	pointer-events: none;
	position: absolute;
	right: 0.625rem;
	z-index: 3;

	span {
		background: #fff;
		box-shadow: 0 0 2px rgb(0 0 0 / 40%);
		flex: 1;
		height: 2px;
		max-width: 2.5rem;
		opacity: 0.5;
		transition: opacity 0.2s;

		&.is-on {
			opacity: 1;
		}
	}
}

// The details come up over the image, line after line.
.ewps-morph-details {
	background: rgb(15 15 15 / 72%);
	backdrop-filter: blur(10px);
	bottom: 0;
	color: #fff;
	font-size: 0.8125em;
	left: 0;
	line-height: 1.4;
	max-height: 45%;
	overflow: hidden;
	padding: 0.75rem 0.75rem 1.25rem;
	pointer-events: none;
	position: absolute;
	right: 0;
	transform: translateY(101%);
	transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
	z-index: 2;

	p {
		margin: 0;
	}

	dl {
		display: grid;
		gap: 0.125rem 0.75rem;
		grid-template-columns: auto 1fr;
		margin: 0.5rem 0 0;

		div {
			display: contents;
		}
	}

	dt {
		opacity: 0.7;
	}

	dd {
		margin: 0;
	}

	> * {
		opacity: 0;
		transform: translateY(0.5rem);
		transition: opacity 0.3s 0.12s, transform 0.4s 0.12s cubic-bezier(0.2, 0.8, 0.2, 1);
	}
}

.ewps-morph.is-active .ewps-morph-details {
	transform: none;

	> * {
		opacity: 1;
		transform: none;
	}

	> :nth-child(2) {
		transition-delay: 0.2s;
	}
}

// Touch has no hover: the details are below the image, as text.
@media (hover: none) {

	.ewps-morph-details {
		background: none;
		backdrop-filter: none;
		color: inherit;
		padding: 0.5rem 0 0;
		position: static;
		transform: none;

		> * {
			opacity: 1;
			transform: none;
		}
	}

	.ewps-morph-dots {
		bottom: auto;
		top: 0.625rem;
	}
}

@media (prefers-reduced-motion: reduce) {

	.ewps-morph-details,
	.ewps-morph-details > * {
		transition-duration: 0.01ms;
		transition-delay: 0s;
	}
}

.ewps-morph-caption {
	display: flex;
	flex-direction: column;
	gap: 0.375rem;

	> .wp-element-button {
		align-self: flex-start;
		margin-top: 0.25rem;
	}
}

.ewps-morph-title {
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	display: -webkit-box;
	font-size: 1em;
	font-weight: 600;
	margin: 0;
	overflow: hidden;

	a {
		color: inherit;
		text-decoration: none;
	}

	a:hover {
		text-decoration: underline;
	}
}

.ewps-morph-price {
	font-size: 0.9375em;
}

.ewps-swatches {
	border: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.375rem;
	margin: 0;
	padding: 0;
}

.ewps-swatch {
	appearance: none;
	background: none;
	border: 1px solid color-mix(in srgb, currentcolor 30%, transparent);
	border-radius: 2px;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: 0.875em;
	line-height: 1;
	min-height: 2rem;
	min-width: 2rem;
	padding: 0.375rem 0.625rem;
	transition: border-color 0.15s;

	&.has-image {
		border-radius: 50%;
		height: 2rem;
		overflow: hidden;
		padding: 0;
		width: 2rem;

		img {
			display: block;
			height: 100%;
			object-fit: var(--ewps-fit, cover);
			width: 100%;
		}
	}

	&:hover {
		border-color: currentcolor;
	}

	&[aria-pressed="true"] {
		border-color: currentcolor;
		box-shadow: 0 0 0 1px currentcolor;
	}

	&:focus-visible {
		outline: 2px solid currentcolor;
		outline-offset: 2px;
	}
}


// In a list of products: the wrapper is inside the theme's link.
.ewps-morph.is-in-loop {
	margin-bottom: 0.75em;
}

// Themes have strong rules for the images of a list of products: the card keeps
// its shape, whichever way the photo goes.
.ewps-morph.is-in-loop .gs .gs-track .gs-media {
	height: 100%;
	width: 100%;
}

// Blocksy and OceanWP print a card's image themselves.
li.product:has(> .ewps-morph-link) > figure,
li.product:has(.ewps-morph-link) .woo-entry-image,
li.product:has(.ewps-morph-link) .image-wrap {
	display: none;
}

.wc-block-components-product-image:has(.ewps-morph) .wc-block-components-product-image__inner-container {
	pointer-events: none;
}
