/* Testimonials (docs/widgets/testimonials.md), in the design language (spec §3.7). This is Soft, the
   default: white cards with a thin border and a soft shadow, a pale quotation mark, stars in the
   accent. Fonts come from the theme. testimonials-outline.css and testimonials-solid.css change only
   the --hafe-tst-d-* tokens below, so a Style control's own property always wins over the design.

   Cards in a row share its height, with the person at the bottom, so names line up. The carousel is
   the same row, scrolled by the browser and snapped to a card; the script only adds its controls. */
.hafe-tst {
	--hafe-tst-d-bg: var(--hafe-surface);
	--hafe-tst-d-line: var(--hafe-line);
	--hafe-tst-d-shadow: var(--hafe-shadow);
	--hafe-tst-d-radius: var(--hafe-radius);
	--hafe-tst-d-mark: var(--hafe-tint-strong);
	--hafe-tst-d-star: var(--hafe-accent);
	--hafe-tst-d-star-empty: var(--hafe-line);
	--hafe-tst-d-photo-line: transparent;
	--hafe-tst-d-arrow: var(--hafe-surface);
	--hafe-tst-d-arrow-ink: var(--hafe-ink);
	--hafe-tst-d-arrow-line: var(--hafe-line);
	--hafe-tst-d-arrow-hover: var(--hafe-tint);
	--hafe-tst-d-arrow-hover-ink: var(--hafe-accent-ink);
	--hafe-tst-gap-x: var(--hafe-tst-gap, 1.5rem);
	color: var(--hafe-ink);
}

/* In dark, the stars take the lighter accent, and empty ones a mid grey, so both read on dark cards. */
.hafe-scheme-dark .hafe-tst {
	--hafe-tst-d-star: var(--hafe-accent-ink);
	--hafe-tst-d-star-empty: color-mix(in srgb, var(--hafe-ink-soft) 45%, var(--hafe-surface));
}

.hafe-tst__items {
	display: grid;
	grid-template-columns: repeat(var(--hafe-tst-columns, 3), minmax(0, 1fr));
	gap: var(--hafe-tst-gap-x);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* A carousel: one row, as many cards in view as the grid would have columns. Its padding gives the
   cards' shadows and focus rings room inside the scrolling area. */
.hafe-tst--carousel .hafe-tst__items {
	grid-template-columns: none;
	grid-auto-columns: calc((100% - (var(--hafe-tst-columns, 3) - 1) * var(--hafe-tst-gap-x)) / var(--hafe-tst-columns, 3));
	grid-template-rows: auto auto;
	grid-auto-flow: column;
	margin: -0.5rem -0.5rem -2rem;
	padding: 0.5rem 0.5rem 2rem;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-padding-inline: 0.5rem;
	scroll-snap-type: x mandatory;
}

.hafe-tst.is-ready .hafe-tst__items {
	scrollbar-width: none;
}

/* At the edge of the page, the script clips the carousel at its own edges: the list's room for
   shadows would otherwise let the page scroll sideways. */
.hafe-tst.is-flush {
	overflow-x: clip;
}

.hafe-tst.is-ready .hafe-tst__items::-webkit-scrollbar {
	display: none;
}

/* A mouse can drag the cards along (the script turns snapping off while it does): an open hand
   over a card, a closed one from the press until the drag ends, wherever the pointer goes. */
.hafe-tst.is-ready .hafe-tst__items[tabindex] .hafe-tst__card {
	cursor: grab;
}

.hafe-tst.is-ready .hafe-tst__items[tabindex] .hafe-tst__card:active,
.hafe-tst.is-ready.is-dragging .hafe-tst__items,
.hafe-tst.is-ready.is-dragging .hafe-tst__items * {
	cursor: grabbing;
}

.hafe-tst.is-dragging .hafe-tst__items {
	user-select: none;
}

/* Each card takes two rows of the list's grid, shared with the cards beside it (subgrid): the quote,
   then the person. So whatever the length of a quote or a role, every name starts at the same height. */
.hafe-tst__item,
.hafe-tst__card {
	display: grid;
	grid-row: span 2;
	grid-template-rows: subgrid;
	grid-template-columns: minmax(0, 1fr);
	row-gap: 1.25em;
	min-inline-size: 0;
	margin: 0;
	padding: 0;
}

.hafe-tst__item {
	scroll-snap-align: start;
}

.hafe-tst__body {
	display: flex;
	flex-direction: column;
	align-items: var(--hafe-tst-items, flex-start);
	gap: 1em;
}

/* Positioned, so the text hidden for screen readers stays inside the carousel's scrolling area and
   never widens the page. */
.hafe-tst__card {
	position: relative;
	box-sizing: border-box;
	padding: var(--hafe-tst-padding, 1.75em);
	border: var(--hafe-tst-line-width, 1px) solid var(--hafe-tst-line, var(--hafe-tst-d-line));
	border-radius: var(--hafe-tst-radius, var(--hafe-tst-d-radius));
	background: var(--hafe-tst-bg, var(--hafe-tst-d-bg));
	box-shadow: var(--hafe-tst-d-shadow);
	text-align: var(--hafe-tst-align, start);
}

.hafe-tst__mark {
	flex: none;
	inline-size: var(--hafe-tst-mark-size, 2em);
	block-size: auto;
	color: var(--hafe-tst-mark-color, var(--hafe-tst-d-mark));
}

/* The title is text, not a heading: a page of testimonials shouldn't fill its outline with them. */
.hafe-tst .hafe-tst__title {
	margin: 0;
	color: var(--hafe-tst-title-color, var(--hafe-ink));
	font-size: 1.0625em;
	font-weight: 600;
}

/* Themes give blockquotes their own bar, italics and quotation marks; the card is the frame here. */
.hafe-tst .hafe-tst__quote {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: var(--hafe-tst-quote-color, var(--hafe-ink));
	font-style: normal;
	quotes: none;
}

.hafe-tst .hafe-tst__quote::before,
.hafe-tst .hafe-tst__quote::after {
	content: none;
}

.hafe-tst .hafe-tst__quote p {
	margin: 0 0 0.75em;
}

.hafe-tst .hafe-tst__quote p:last-child {
	margin: 0;
}

/* A figcaption, which themes colour as a caption: it takes the card's colour. */
.hafe-tst__author {
	container-type: inline-size;
	color: inherit;
	align-self: start;
	margin: 0;
	padding: 0;
}

.hafe-tst__person {
	display: flex;
	align-items: flex-start;
	justify-content: var(--hafe-tst-items, flex-start);
	gap: 0.75em;
}

.hafe-tst__photo {
	box-sizing: border-box;
	display: block;
	flex: none;
	inline-size: var(--hafe-tst-photo-size, 3em);
	block-size: var(--hafe-tst-photo-size, 3em);
	overflow: hidden;
	border: 1px solid var(--hafe-tst-d-photo-line);
	border-radius: var(--hafe-tst-photo-radius, 50%);
}

.hafe-tst--photo-top .hafe-tst__photo {
	inline-size: var(--hafe-tst-photo-size, 4em);
	block-size: var(--hafe-tst-photo-size, 4em);
}

.hafe-tst__photo img {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	margin: 0;
	object-fit: cover;
}

.hafe-tst__who {
	display: flex;
	flex-direction: column;
	gap: 0.15em;
}

.hafe-tst__name {
	color: var(--hafe-tst-name-color, var(--hafe-ink));
	font-weight: 600;
}

.hafe-tst .hafe-tst__name a {
	color: inherit;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

.hafe-tst__role {
	color: var(--hafe-tst-role-color, var(--hafe-ink-soft));
	font-size: 0.875em;
}

.hafe-tst__rating {
	margin: 0;
	line-height: 0;
}

/* Five stars drawn by a mask, filled to the rating with two flat colours. */
.hafe-tst__stars {
	--hafe-tst-s: var(--hafe-tst-star-size, 1.125em);
	display: inline-block;
	inline-size: calc(var(--hafe-tst-s) * 5);
	block-size: var(--hafe-tst-s);
	background: linear-gradient(90deg, var(--hafe-tst-star, var(--hafe-tst-d-star)) var(--hafe-tst-rating, 0%), var(--hafe-tst-star-empty, var(--hafe-tst-d-star-empty)) 0);
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3l-5.9 3.3 1.3-6.6-4.9-4.6 6.6-.8z'/%3E%3C/svg%3E") 0 0 / var(--hafe-tst-s) var(--hafe-tst-s) repeat-x;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3l-5.9 3.3 1.3-6.6-4.9-4.6 6.6-.8z'/%3E%3C/svg%3E") 0 0 / var(--hafe-tst-s) var(--hafe-tst-s) repeat-x;
}

.hafe-tst:dir(rtl) .hafe-tst__stars {
	transform: scaleX(-1);
}

.hafe-tst__sr {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* The carousel's controls: arrows above, dots below. */
.hafe-tst__nav {
	display: flex;
	justify-content: flex-end;
	gap: 0.5em;
	margin-block-end: 0.75em;
}

.hafe-tst__nav[hidden],
.hafe-tst__dots[hidden],
.hafe-tst__dot[hidden] {
	display: none;
}

/* Hovered and focused too (spec §4). */
.hafe-tst .hafe-tst__button,
.hafe-tst .hafe-tst__button:is(:hover, :focus) {
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	inline-size: 2.75rem;
	block-size: 2.75rem;
	padding: 0;
	border: 1px solid var(--hafe-tst-d-arrow-line);
	border-radius: 50%;
	background: var(--hafe-tst-arrow-bg, var(--hafe-tst-d-arrow));
	box-shadow: none;
	color: var(--hafe-tst-arrow-color, var(--hafe-tst-d-arrow-ink));
	cursor: pointer;
	transition: background-color 0.2s, color 0.2s;
}

.hafe-tst .hafe-tst__button:hover {
	background: var(--hafe-tst-arrow-bg, var(--hafe-tst-d-arrow-hover));
	color: var(--hafe-tst-arrow-color, var(--hafe-tst-d-arrow-hover-ink));
}

.hafe-tst .hafe-tst__button[aria-disabled="true"] {
	opacity: 0.4;
	cursor: default;
}

.hafe-tst__button svg {
	inline-size: 1.25em;
	block-size: 1.25em;
}

.hafe-tst__arrow:dir(rtl) svg {
	transform: scaleX(-1);
}

.hafe-tst__dots {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.25em;
	margin-block-start: 1em;
}

/* Each dot is a 24 px target (WCAG 2.5.8) around a small mark; the current one is a longer pill.
   The pill is always there, clipped to a dot, so changing dots repaints and never resizes. */
.hafe-tst .hafe-tst__dot,
.hafe-tst .hafe-tst__dot:is(:hover, :focus) {
	position: relative;
	inline-size: 1.5rem;
	block-size: 1.5rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	box-shadow: none;
	color: inherit;
	cursor: pointer;
}

.hafe-tst__dot::before {
	content: "";
	position: absolute;
	inset: 0;
	inline-size: 1.25rem;
	block-size: 0.5rem;
	margin: auto;
	background: var(--hafe-tst-dot, var(--hafe-ink-soft));
	clip-path: inset(0 0.375rem round var(--hafe-pill));
	transition: clip-path 0.25s, background-color 0.25s;
}

.hafe-tst__dot[aria-current="true"]::before {
	background: var(--hafe-tst-dot-now, var(--hafe-accent));
	clip-path: inset(0 round var(--hafe-pill));
}

/* Stated here too: some packs take the outline off every focused button, site-wide. */
.hafe-tst .hafe-tst__button:focus-visible,
.hafe-tst .hafe-tst__dot:focus-visible {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 2px;
}

.hafe-tst__items:focus-visible {
	outline: 2px solid var(--hafe-accent);
	outline-offset: -2px;
}

/* High contrast: the system's colours replace backgrounds, so the stars keep their own. */
@media (forced-colors: active) {
	.hafe-tst__stars {
		forced-color-adjust: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hafe-tst__dot::before,
	.hafe-tst .hafe-tst__button {
		transition: none;
	}
}

.hafe-empty {
	margin: 0;
	padding: 1em;
	border: 1px dashed currentColor;
	opacity: 0.7;
}

/* A narrow card (four in a row, say) puts the photo above the name, so names don't break up: beside
   a 3em photo, the name keeps at least 8em. */
@container (max-width: 12em) {
	.hafe-tst__person {
		flex-direction: column;
		align-items: var(--hafe-tst-items, flex-start);
	}
}
