/*--------------------------------------------------------------
# Problem section — CSS shuffle cards
--------------------------------------------------------------*/

@property --angle {
	syntax: "<angle>";
	initial-value: 0deg;
	inherits: true;
}

.speedup-shuffle-cards {
	--img-w: 200px;
	--duration: 300ms;
	--img-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
	--label-clr-txt: var(--wp--preset--color--text-dark, #47433b);
	--label-clr-bg: var(--wp--preset--color--bg-light, #fcf9f3);

	width: min(100%, 800px);
	margin-inline: auto;
	display: grid;
	min-height: 280px;
	isolation: isolate;
}

.speedup-shuffle-cards input[type="radio"] {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border-width: 0;
}

.speedup-shuffle-card {
	--cards-grid-cols: auto;
	--cards-grid-rows: var(--img-w) auto;
	--cards-grid-gap: 2rem;
	--cards-footer-justify: end;

	grid-area: 1 / 1;
	display: grid;
	place-items: center;
	grid-template-columns: var(--cards-grid-cols);
	grid-template-rows: var(--cards-grid-rows);
	gap: var(--cards-grid-gap);
	z-index: -1;
	width: 100%;
	padding: 0.5rem;
	box-sizing: border-box;
}

@media (min-width: 801px) {
	.speedup-shuffle-card {
		--cards-grid-cols: var(--img-w) auto;
		--cards-grid-rows: auto;
		--cards-grid-gap: 4rem;
	}
}

.speedup-shuffle-card__img {
	width: var(--img-w);
	height: var(--img-w);
	aspect-ratio: 1 / 1;
	rotate: var(--angle, 0deg);
	border-radius: 10px;
	border: 3px solid #fff;
	overflow: hidden;
	transform-origin: center;
	object-fit: cover;
	box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.08);
	display: block;
	max-width: 100%;
	background: var(--wp--preset--color--bg-light, #fcf9f3);
}

/* Straighten stacked images when switching */
.speedup-shuffle-cards input:nth-of-type(1):checked + .speedup-shuffle-card ~ .speedup-shuffle-card > .speedup-shuffle-card__img {
	animation: speedup-shuffle-straighten-1 calc(var(--duration) * 2) forwards;
	animation-timing-function: var(--img-easing);
}

.speedup-shuffle-card:has(~ input:nth-of-type(2):checked) > .speedup-shuffle-card__img,
.speedup-shuffle-cards input:nth-of-type(2):checked + .speedup-shuffle-card ~ .speedup-shuffle-card > .speedup-shuffle-card__img {
	animation: speedup-shuffle-straighten-2 calc(var(--duration) * 2) forwards;
	animation-timing-function: var(--img-easing);
}

.speedup-shuffle-card:has(~ input:nth-of-type(3):checked) > .speedup-shuffle-card__img,
.speedup-shuffle-cards input:nth-of-type(3):checked + .speedup-shuffle-card ~ .speedup-shuffle-card > .speedup-shuffle-card__img {
	animation: speedup-shuffle-straighten-3 calc(var(--duration) * 2) forwards;
	animation-timing-function: var(--img-easing);
}

@keyframes speedup-shuffle-straighten-1 {
	50% {
		--angle: 0deg;
	}
}

@keyframes speedup-shuffle-straighten-2 {
	50% {
		--angle: 0deg;
	}
}

@keyframes speedup-shuffle-straighten-3 {
	50% {
		--angle: 0deg;
	}
}

.speedup-shuffle-cards input:checked + .speedup-shuffle-card {
	z-index: 10 !important;
	--data-opacity: 1;
	--data-y: 0;
	--data-delay: var(--duration);
	--card-events: auto;
	transition: z-index;
	transition-delay: 300ms;
}

.speedup-shuffle-card:has(+ input:checked) {
	z-index: 9;
}

.speedup-shuffle-card:has(+ input + .speedup-shuffle-card + input:checked) {
	z-index: 8;
}

.speedup-shuffle-card__data {
	display: grid;
	gap: 1rem;
	min-width: 0;
	width: 100%;
	text-align: start;
}

.speedup-shuffle-card__num {
	opacity: var(--data-opacity, 0);
	font-size: 0.8rem;
	color: var(--wp--preset--color--text-gray, #6b665c);
	font-variant-numeric: lining-nums;
}

.speedup-shuffle-card__title,
.speedup-shuffle-card__desc {
	transition: var(--duration) ease-in-out;
	transition-delay: var(--data-delay, 0ms);
	opacity: var(--data-opacity, 0);
	translate: 0 var(--data-y, 20px);
	margin: 0;
}

.speedup-shuffle-card__title {
	font-size: clamp(1.25rem, 2vw, 1.6rem);
	font-weight: 700;
	line-height: 1.35;
	color: var(--wp--preset--color--text-dark, #47433b);
}

.speedup-shuffle-card__desc {
	font-size: 0.95rem;
	line-height: 1.7;
	color: var(--wp--preset--color--text-gray, #6b665c);
}

.speedup-shuffle-card__footer {
	display: flex;
	justify-content: var(--cards-footer-justify);
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
}

.speedup-shuffle-card__footer label {
	margin-block-start: auto;
	cursor: pointer;
	pointer-events: var(--card-events, none);
	opacity: var(--data-opacity, 0);
	color: var(--label-clr-txt);
	background-color: var(--label-clr-bg);
	border-radius: 50%;
	width: 32px;
	height: 32px;
	aspect-ratio: 1 / 1;
	display: grid;
	place-content: center;
	transition: background-color 300ms ease-in-out, color 300ms ease-in-out;
	font-size: 0.85rem;
	line-height: 1;
	user-select: none;
}

.speedup-shuffle-cards input:checked:focus-visible + .speedup-shuffle-card > .speedup-shuffle-card__data > .speedup-shuffle-card__footer label,
.speedup-shuffle-card__footer label:hover {
	--label-clr-txt: #fff;
	--label-clr-bg: var(--wp--preset--color--primary, #dd2c00);
}

.speedup-shuffle-card__cta {
	pointer-events: var(--card-events, none);
	opacity: var(--data-opacity, 0);
	transition: opacity var(--duration) ease-in-out, background-color 0.2s ease, color 0.2s ease;
	transition-delay: var(--data-delay, 0ms);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.55rem 1.1rem;
	border-radius: 6px;
	background: var(--wp--preset--color--primary, #dd2c00);
	color: #fff;
	font-size: 0.85rem;
	font-weight: 600;
	text-decoration: none;
	line-height: 1.2;
}

.speedup-shuffle-card__cta:hover {
	filter: brightness(0.92);
	color: #fff;
}

.speedup-shuffle-cards input:checked + .speedup-shuffle-card > .speedup-shuffle-card__img {
	animation: speedup-shuffle-reveal calc(var(--duration) * 2) forwards;
}

@keyframes speedup-shuffle-reveal {
	50% {
		translate: 150% 0;
		--angle: 0deg;
	}
}

@media (min-width: 801px) {
	@keyframes speedup-shuffle-reveal {
		50% {
			translate: 120% 0;
			--angle: 0deg;
		}
	}
}

@media (prefers-reduced-motion: reduce) {
	.speedup-shuffle-card__img,
	.speedup-shuffle-card__title,
	.speedup-shuffle-card__desc,
	.speedup-shuffle-card__cta,
	.speedup-shuffle-card__footer label {
		animation: none !important;
		transition: none !important;
		opacity: 1;
		translate: none;
	}

	.speedup-shuffle-cards input:not(:checked) + .speedup-shuffle-card .speedup-shuffle-card__data > * {
		opacity: 0;
	}
}
