/*
 * CAR-1: carousel. A block style on a Group, a row of items, a Query Loop's
 * post template or a Gallery. Without JavaScript, and inside the editor, it is
 * a row that scrolls sideways.
 *
 * Three looks, each a block style of its own:
 *   is-style-wprk-carousel             arrows and dots under the row
 *   is-style-wprk-carousel-edge        cards that run off the edge of the
 *                                      screen, with a line that shows how far
 *                                      the row has moved
 *   is-style-wprk-carousel-spotlight   one item large in the middle, its
 *                                      neighbours waiting at the sides
 * What the three share is written for every class that begins with
 * is-style-wprk-carousel.
 */

[class*="is-style-wprk-carousel"][class*="is-style-wprk-carousel"] {
	--wprk-carousel-gap: var(--wp--preset--spacing--40);
	--wprk-carousel-per-view: 1;
	box-sizing: border-box;
	display: flex;
	flex-wrap: nowrap;
	gap: var(--wprk-carousel-gap);
	grid-template-columns: none;
	list-style: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	padding-block: 4px;
	padding-inline: 0;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

[class*="is-style-wprk-carousel"]::-webkit-scrollbar {
	display: none;
}

/*
 * A slide's width is the width of its whole box, padding and border with it:
 * a card with padding of its own is then as wide as one without, and the
 * number of cards that was asked for fits.
 *
 * A slide is also the box its own parts are placed in. Without that, a part
 * that is taken out of the flow (the words WordPress adds to "Learn more" for
 * a screen reader, for one) is placed from a box outside the row, the row
 * does not clip it, and the page grows wider than the screen by the slides
 * that are out of view.
 */
[class*="is-style-wprk-carousel"][class*="is-style-wprk-carousel"] > * {
	box-sizing: border-box;
	flex: 0 0 calc((100% - (var(--wprk-carousel-per-view) - 1) * var(--wprk-carousel-gap)) / var(--wprk-carousel-per-view));
	margin: 0;
	max-width: none;
	min-width: 0;
	position: relative;
	scroll-snap-align: start;
	width: auto;
}

@media (min-width: 600px) {
	[class*="is-style-wprk-carousel"][class*="is-style-wprk-carousel"] {
		--wprk-carousel-per-view: 2;
	}
}

@media (min-width: 1024px) {
	[class*="is-style-wprk-carousel"][class*="is-style-wprk-carousel"] {
		--wprk-carousel-per-view: 3;
	}
}

/* One slide at a time, for hero sliders and large quotes. */
[class*="is-style-wprk-carousel"].wprk-carousel--single.wprk-carousel--single {
	--wprk-carousel-gap: 0px;
	--wprk-carousel-per-view: 1;
}

/*
 * The second look: cards that run off the edge. A little more than a whole
 * number of cards fits, so the next one always shows.
 */
.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
	--wprk-carousel-per-view: 1.15;
}

@media (min-width: 600px) {
	.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
		--wprk-carousel-per-view: 2.2;
	}
}

@media (min-width: 1024px) {
	.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
		--wprk-carousel-per-view: 3.2;
	}
}

/*
 * Where the row stands in a section at the section's wide width, it reaches
 * out to both edges of the section, and so of the screen. Its first card still
 * begins where the heading does, and a card that stops, stops there.
 *
 * How far it has to reach is the section's own padding at the side, and half
 * of what the section's inside is wider than the wide width. The section is
 * measured as a container (100cqi is the width of its inside), which is right
 * wherever the section stands and leaves a scrollbar out of the count. A
 * browser without container units keeps the row inside its box.
 */
@supports (width: 1cqi) {
	.wprk-section:has(> .alignwide > .is-style-wprk-carousel-edge, > .alignwide.is-style-wprk-carousel-edge, > .alignfull.is-style-wprk-carousel-edge) {
		container-type: inline-size;
	}

	.wprk-section > .alignwide > .is-style-wprk-carousel-edge.is-style-wprk-carousel-edge,
	.wprk-section > .alignwide.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge,
	.wprk-section > .alignfull.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
		--wprk-carousel-reach: calc(var(--wp--style--root--padding-left, 0px) + max(0px, (100cqi - var(--wp--style--global--wide-size)) / 2));
		max-width: none;
		padding-inline: var(--wprk-carousel-reach);
		scroll-padding-inline: var(--wprk-carousel-reach);
	}

	/* A row inside the wide box goes out by the whole of the reach. */
	.wprk-section > .alignwide > .is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
		margin-inline: calc(0px - var(--wprk-carousel-reach));
	}

	/*
	 * A row that is itself the wide box stands in the section's inside, so it
	 * goes out by the section's padding alone. WordPress centres such a box
	 * with force. A row at full width is at the edges already.
	 */
	.wprk-section > .alignwide.is-style-wprk-carousel-edge.is-style-wprk-carousel-edge {
		margin-inline: calc(0px - var(--wp--style--root--padding-left, 0px)) !important;
	}
}

/*
 * The third look: a spotlight. One item, large, in the middle of the row; the
 * one before and the one after show at the sides, and wait there dimmed once
 * the script has marked which one is in the middle. On a phone the item takes
 * nearly the whole width.
 *
 * The room at the sides is a share of the box the row stands in. A row that is
 * itself the wide box stands in the section's inside, which is wider than the
 * row: the measure stops at the wide width.
 */
.is-style-wprk-carousel-spotlight.is-style-wprk-carousel-spotlight {
	--wprk-carousel-per-view: 1;
	--wprk-carousel-side: max(1.25rem, (min(100%, var(--wp--style--global--wide-size)) - var(--wprk-carousel-spotlight, 52rem)) / 2);
	padding-inline: var(--wprk-carousel-side);
	scroll-padding-inline: var(--wprk-carousel-side);
}

.is-style-wprk-carousel-spotlight[data-wprk-carousel] > * {
	transition: opacity 0.3s ease;
}

.is-style-wprk-carousel-spotlight[data-wprk-carousel] > :not(.is-current) {
	opacity: 0.4;
}

/* The editor shows the scrollbar so every slide can be reached and edited. */
.editor-styles-wrapper [class*="is-style-wprk-carousel"][class*="is-style-wprk-carousel"] {
	padding-block-end: var(--wp--preset--spacing--20);
	scrollbar-width: thin;
}

.wprk-carousel__controls {
	align-items: center;
	display: flex;
	gap: var(--wp--preset--spacing--20);
	justify-content: center;
	margin-block-start: var(--wp--preset--spacing--40);
}

.wprk-carousel__controls[hidden] {
	display: none;
}

.wprk-carousel__btn {
	align-items: center;
	background: transparent;
	border: 1px solid var(--wprk-border);
	border-radius: 50%;
	color: var(--wprk-heading);
	cursor: pointer;
	display: inline-flex;
	height: 2.75rem;
	justify-content: center;
	padding: 0;
	transition: background-color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
	width: 2.75rem;
}

.wprk-carousel__btn:hover:not(:disabled) {
	background-color: var(--wprk-soft);
	border-color: var(--wprk-heading);
}

.wprk-carousel__btn:disabled {
	cursor: default;
	opacity: 0.35;
}

.wprk-carousel__btn svg {
	fill: none;
	height: 1.25rem;
	stroke: currentColor;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-width: 1.75;
	width: 1.25rem;
}

.wprk-carousel__dots {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
}

.wprk-carousel__dot {
	background: transparent;
	border: 0;
	cursor: pointer;
	height: 1.5rem;
	padding: 0;
	position: relative;
	width: 1.5rem;
}

.wprk-carousel__dot::before {
	background-color: var(--wprk-border);
	border-radius: 50%;
	content: "";
	height: 0.5rem;
	inset: 0;
	margin: auto;
	position: absolute;
	transition: background-color 0.18s ease, transform 0.18s ease;
	width: 0.5rem;
}

.wprk-carousel__dot[aria-current="true"]::before {
	background-color: var(--wprk-heading);
	transform: scale(1.3);
}

/*
 * Off the edge: the line that shows how far the row has moved, with the two
 * arrows at its end. The dark part of the line is as long as the share of the
 * cards that is in view.
 */
.wprk-carousel__controls--edge {
	gap: var(--wp--preset--spacing--30);
	justify-content: flex-start;
}

.wprk-carousel__progress {
	background-color: var(--wprk-border);
	border-radius: 1px;
	flex: 1 1 auto;
	height: 2px;
	min-width: 0;
	overflow: hidden;
}

.wprk-carousel__progress > span {
	background-color: var(--wprk-heading);
	display: block;
	height: 100%;
	transform-origin: 0 50%;
	width: 100%;
}

/* Spotlight: which item of how many, between the two arrows. */
.wprk-carousel__count {
	color: var(--wprk-muted);
	font-size: var(--wp--preset--font-size--small);
	font-variant-numeric: tabular-nums lining-nums;
	min-width: 4em;
	text-align: center;
}

@media (prefers-reduced-motion: reduce) {
	.wprk-carousel__btn,
	.wprk-carousel__dot::before,
	.is-style-wprk-carousel-spotlight[data-wprk-carousel] > * {
		transition: none;
	}
}
