/*
 * Product card (core/group in a WooCommerce product template): a box with the product image, the sale badge, the
 * stock indicator and the add to cart button, then the title and the price. The box colour, the image's aspect ratio
 * and padding, the badges' colours and type, the title and price type and spacing are the blocks' own settings; the
 * style only places the badges and the cart square in the box's corners, draws the square's icon, shows it on hover
 * and blends white photo backgrounds into the box. Loaded only on pages where a card uses the style
 * (inc/rt-block-styles.php).
 */
.is-style-product-card {
	/* cqi of the box, not %: a % height resolves against the box's height, so the "View cart" tab came out taller
	   than the square */
	--rt-product-card-action-size: clamp(2.75rem, 22.2cqi, 5rem);
	--rt-product-card-badge-offset: clamp(0.625rem, 5.5%, 1.25rem);
	--rt-product-card-bag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 8h14l-1 13H6L5 8z' fill='none' stroke='%23000' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M9 8V6a3 3 0 0 1 6 0v2' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E");
	--rt-product-card-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 12h17M15 7l5 5-5 5' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E");
}

/* The box: the group that holds the product image */
.is-style-product-card :has(> .wc-block-components-product-image) {
	position: relative;
	container-type: inline-size;
}

.is-style-product-card .wc-block-components-product-image img {
	mix-blend-mode: multiply;
}

/* Sale badge (inside the image link) and out of stock badge, top left */
.is-style-product-card .wc-block-components-product-image__inner-container {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.is-style-product-card .wc-block-components-product-sale-badge,
.is-style-product-card .wc-block-components-product-stock-indicator {
	position: absolute;
	inset-block-start: var(--rt-product-card-badge-offset);
	inset-inline-start: var(--rt-product-card-badge-offset);
}

/* The sale badge has no padding setting; the stock indicator's padding is its own */
.is-style-product-card .wc-block-components-product-sale-badge {
	padding: 0.3125rem 0.625rem;
}

/* Only "Out of stock" is shown; an out of stock product hides its sale badge */
.is-style-product-card .wc-block-components-product-stock-indicator:not(.wc-block-components-product-stock-indicator--out-of-stock) {
	display: none;
}

.is-style-product-card :has(> .wc-block-components-product-stock-indicator--out-of-stock) .wc-block-components-product-sale-badge {
	display: none;
}

/* Add to cart: a square in the box's bottom right corner; the label stays for screen readers (the button's aria-label
   names the product), a bag icon for products added right here, an arrow for those that open the product page */
.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button {
	position: absolute;
	inset-block-end: 0;
	inset-inline-end: 0;
	display: block;
	box-sizing: border-box;
	width: var(--rt-product-card-action-size);
	min-width: 0;
	height: auto;
	min-height: 0;
	aspect-ratio: 1;
	margin: 0;
	padding: 0;
	overflow: hidden;
	font-size: 0;
	transition: opacity 0.2s ease;
}

.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button > span {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button::before {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 30%;
	height: 30%;
	background: currentColor;
	-webkit-mask: var(--rt-product-card-arrow) center / contain no-repeat;
	mask: var(--rt-product-card-arrow) center / contain no-repeat;
}

.is-style-product-card .wc-block-components-product-button .ajax_add_to_cart::before {
	-webkit-mask-image: var(--rt-product-card-bag);
	mask-image: var(--rt-product-card-bag);
}

.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

/* After adding, WooCommerce unhides its "View cart" link: a tab beside the square, so the box keeps its size */
.is-style-product-card .wc-block-components-product-button .added_to_cart {
	position: absolute;
	inset-block-end: 0;
	inset-inline-end: var(--rt-product-card-action-size);
	display: flex;
	align-items: center;
	box-sizing: border-box;
	height: var(--rt-product-card-action-size);
	margin: 0;
	padding-inline: var(--wp--preset--spacing--30);
	background: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	text-decoration: underline;
	text-underline-offset: 0.2em;
	white-space: nowrap;
}

/* With a mouse the square appears on hover or focus; touch screens always show it */
@media (hover: hover) {
	.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button {
		opacity: 0;
	}

	.is-style-product-card:hover .wc-block-components-product-button .wc-block-components-product-button__button,
	.is-style-product-card:focus-within .wc-block-components-product-button .wc-block-components-product-button__button,
	.is-style-product-card .wc-block-components-product-button:has(> span:not([hidden])) .wc-block-components-product-button__button {
		opacity: 1;
	}
}

/* The title is underlined while the card is hovered */
.is-style-product-card .wp-block-post-title a {
	text-decoration: none;
	text-underline-offset: 0.2em;
}

.is-style-product-card:hover .wp-block-post-title a,
.is-style-product-card .wp-block-post-title a:focus-visible {
	text-decoration: underline;
}

/* Price on sale: the old price in the quiet grey (4.5:1, unlike muted) and struck through */
.is-style-product-card .wc-block-components-product-price del {
	margin-inline-end: var(--wp--preset--spacing--20);
	color: var(--wp--preset--color--stone);
}

.is-style-product-card .wc-block-components-product-price ins {
	text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
	.is-style-product-card .wc-block-components-product-button .wc-block-components-product-button__button {
		transition: none;
	}
}
