@import "https://codepen.io/cbolson/pen/rNEdgKo.css" layer(template);
@layer template, demo;
*,::before,::after{
margin: 0;
}
@property --angle {
syntax: "<angle>";
initial-value: 0deg;
inherits: true;
}
/* Hide radio buttons */
.carousels 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;
}
.carousels{
--img-w: 200px;
--duration: 300ms;
--img-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
width: min(100% - 4rem, 800px);
margin-inline: auto;
display: grid;

counter-reset: my-counter;
}

.carousel{
--cards-grid-cols: auto;
--cards-grid-rows: var(--img-w) auto;
--cards-grid-gap: 2rem;
--cards-footer-justify: center;

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);

}

@media (600px < width){
.carousel{
	--cards-grid-cols: var(--img-w) auto;
	--cards-grid-rows: auto;
	--cards-grid-gap: 4rem;
	--cards-footer-justify: start;
}
}


.carousel-img{
width: 200px;
height: 200px;
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 / .05);
}



input:nth-of-type(1):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-1 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(2):checked) > .carousel-img,
input:nth-of-type(2):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-2 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(3):checked) > .carousel-img,
input:nth-of-type(3):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-3 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(4):checked) > .carousel-img,
input:nth-of-type(4):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-4 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(5):checked) > .carousel-img,
input:nth-of-type(5):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-5 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(6):checked) > .carousel-img,
input:nth-of-type(6):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-6 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
.carousel:has(~input:nth-of-type(7):checked) > .carousel-img,
input:nth-of-type(7):checked + .carousel ~ .carousel > .carousel-img{
animation: straighten-img-7 calc(var(--duration) * 2) forwards;
animation-timing-function: var(--img-easing);
}
/* as CSS can't remove animations, we change the animation according to which checkbox is checked  - all animations are the same (would be simpler with SCSS) */
@keyframes straighten-img-1 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-2 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-3 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-4 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-5 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-6 { 50%{ --angle: 0deg;} }
@keyframes straighten-img-7 { 50%{ --angle: 0deg;} }


/* stacking order - these are updated according to which card is selected */
.carousel{
z-index: -1;
}
input:checked + .carousel{
z-index:10 !important;
}
/* next card checked - place behind */
.carousel:has(+input:checked){
z-index:9;
}
/* next card +1 checked - place behind */
.carousel:has(+input + .carousel + input:checked){
z-index:8;
}
/* next card +2 checked - place behind */
.carousel:has(+input + .carousel +input + .carousel + input:checked){
z-index:7;
}
/* next card +3 checked - place behind */
.carousel:has(+input + .carousel +input + .carousel +input + .carousel + input:checked){
z-index:6;
}
/* next card +4 checked - place behind */
.carousel:has(+input + .carousel +input + .carousel +input + .carousel +input + .carousel + input:checked){
z-index:5;
}
/* next card +5 checked - place behind */
.carousel:has(+input + .carousel +input + .carousel +input +input + .carousel +input + .carousel +input + .carousel + input:checked){
z-index:4;
}
/* next card +6 checked - place behind */
.carousel:has(+input + .carousel +input + .carousel +input  + .carousel +input +input + .carousel +input + .carousel +input + .carousel + input:checked){
z-index:3;
}

.carousel-data{
display: grid;
gap: 1rem;
}
.carousel-data > .carousel-num{
opacity: var(--data-opacity, 0);
font-size: 1.3rem;
color: #666;
}
.carousel-data > p{
font-size: 0.9rem;

}
.carousel-data > h2,
.carousel-data > p{
transition: var(--duration) ease-in-out;
transition-delay: var(--data-delay,0ms);
opacity: var(--data-opacity, 0);
translate: 0 var(--data-y, 20px);
}
.carousel-data > footer{
display: flex;
justify-content: var(--cards-footer-justify);
gap: 2rem;
}
.carousel-data > footer label{
margin-block-start: auto;
cursor: pointer;
pointer-events: var(--card-events, none);
opacity: var(--data-opacity, 0);
transition: color var(--duration) ease-in-out;
color: var(--label-clr-txt,#000);
background-color:var(--label-clr-bg,#EEE);
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;
}


input:checked:focus-visible + .carousel > .carousel-data > footer label,
.carousel-data > footer label:hover{
--label-clr-txt: #FFF;
--label-clr-bg: steelblue;
}

input:checked + .carousel{
--data-opacity: 1;
--data-y: 0;
--data-delay: var(--duration);
--card-events: auto;
transition: z-index;
transition-delay: 300ms;
/*z-index: 1;*/
}

input:checked +.carousel > .carousel-img{
animation: reveal-img calc(var(--duration) * 2) forwards;
}

@keyframes reveal-img{
50%{
	translate: -150% 0;
	--angle: 0deg;
}
}