/*
 * Organization logos (savtek-core): a list per group, one moving row or one still row. A logo is
 * sized by its shape (--savtek-logo-ratio) and its ink (--savtek-logo-scale) so wide and tall,
 * dense and light logos look equally heavy; without a logo the name stands on a tile. A mostly
 * white logo (has-light-logo) becomes an ink silhouette. With several groups their order is their
 * tier; consecutive fourth tiers share a row where the block has the page's wide width.
 */
.savtek-orgs {
	--savtek-logo-base: 6rem;
	--savtek-logo-max-w: 11rem;
	--savtek-logo-max-h: 4rem;
	--savtek-name-size: 1rem;
}

.savtek-orgs__group {
	align-items: center;
	border-bottom: 1px solid var(--wp--custom--border-color);
	display: grid;
	gap: 0.75rem 2rem;
	grid-template-columns: 11rem minmax(0, 1fr);
	padding-block: 1.5rem;
}

.savtek-orgs__group > .savtek-orgs__list:only-child {
	grid-column: 1 / -1;
}

/* Two classes: in page text .savtek-prose h2 would otherwise set the size. */
.savtek-orgs .savtek-orgs__title {
	font-family: var(--wp--preset--font-family--body);
	font-size: 1.0625rem;
	font-weight: 600;
	letter-spacing: 0;
	line-height: 1.3;
	margin: 0;
}

.savtek-orgs__list {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 1rem 1.5rem;
	list-style: none;
	margin: 0;
	padding: 0;
}

.savtek-orgs__item {
	margin: 0;
}

.savtek-orgs__link {
	border-radius: var(--wp--custom--radius-sm);
	color: var(--wp--preset--color--contrast);
	display: block;
	text-decoration: none;
}

.savtek-orgs__logo {
	display: block;
	height: auto;
	max-height: calc(var(--savtek-logo-max-h) * var(--savtek-logo-scale, 1));
	max-width: 100%;
	object-fit: contain;
	width: calc(min(var(--savtek-logo-max-w), var(--savtek-logo-base) * sqrt(var(--savtek-logo-ratio, 2))) * var(--savtek-logo-scale, 1));
}

/* Without sqrt() the logos keep their own width within the limits. */
@supports not (width: calc(1rem * sqrt(2))) {

	.savtek-orgs__logo {
		max-width: min(100%, var(--savtek-logo-max-w));
		width: auto;
	}
}

/*
 * An organization without a logo: its name on a tile as wide as the widest logo and as tall as the
 * tallest, so a name weighs as much as a logo and the tiles line up, until the logo arrives.
 */
.savtek-orgs__name {
	align-items: center;
	border: 1px solid var(--wp--custom--border-color);
	border-radius: var(--wp--custom--radius-sm);
	box-sizing: border-box;
	display: flex;
	font-size: var(--savtek-name-size);
	font-weight: 600;
	justify-content: center;
	line-height: 1.2;
	max-width: 100%;
	min-height: var(--savtek-logo-max-h);
	padding: 0.4rem 0.75rem;
	text-align: center;
	text-wrap: balance;
	transition: border-color var(--wp--custom--transition), color var(--wp--custom--transition);
	width: var(--savtek-logo-max-w);
}

.savtek-orgs__item:is(:hover, :focus-within) .savtek-orgs__name {
	border-color: var(--wp--custom--border-strong);
	color: var(--wp--preset--color--contrast);
}

.savtek-orgs:not(.is-marquee) .has-light-logo .savtek-orgs__logo {
	filter: brightness(0);
	opacity: 0.85;
}

/* The still row: every logo once, centered, wrapping onto more rows when they do not fit. */
.savtek-orgs.is-band .savtek-orgs__list {
	justify-content: center;
}

/*
 * Tiers, when the block shows more than one group: an ink line above them, each group's name on
 * the left of its logos, and from 1100px consecutive fourth-tier groups paired on one row.
 */
.savtek-orgs.has-tiers {
	border-top: 1px solid var(--wp--preset--color--contrast);
}

.has-tiers .is-tier-1 {
	--savtek-logo-base: 7rem;
	--savtek-logo-max-w: 14rem;
	--savtek-logo-max-h: 5.5rem;
	--savtek-name-size: 1.125rem;
}

.has-tiers .is-tier-2 {
	--savtek-logo-base: 6rem;
	--savtek-logo-max-w: 12rem;
	--savtek-logo-max-h: 4.5rem;
	--savtek-name-size: 1.0625rem;
}

.has-tiers :is(.is-tier-3, .is-tier-4) {
	--savtek-logo-base: 5rem;
	--savtek-logo-max-w: 9.5rem;
	--savtek-logo-max-h: 3.75rem;
}

/* A light logo grows only within its tier's box, so no logo outweighs a higher tier. */
.has-tiers .savtek-orgs__logo {
	--savtek-logo-cap: min(var(--savtek-logo-scale, 1), 1);
	max-height: calc(var(--savtek-logo-max-h) * var(--savtek-logo-cap));
	width: min(calc(var(--savtek-logo-max-w) * var(--savtek-logo-cap)), calc(var(--savtek-logo-base) * sqrt(var(--savtek-logo-ratio, 2)) * var(--savtek-logo-scale, 1)));
}

/* Only on the page's wide width: beside a page's rail each tier keeps a row of its own. */
@media (min-width: 1100px) {

	.savtek-orgs.has-tiers:not(.savtek-page-layout *) {
		column-gap: 2rem;
		display: grid;
		grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
	}

	.savtek-orgs.has-tiers > :not(.is-tier-4) {
		grid-column: 1 / -1;
	}

	.savtek-orgs.has-tiers:not(.savtek-page-layout *) > .is-tier-4 + .is-tier-4 {
		grid-template-columns: 6rem minmax(0, 1fr);
	}
}

/*
 * Phones: group names above their logos; the logos and name tiles in a grid, two to a row, three
 * in the still row and the tiers, each logo kept short enough that a round one does not tower.
 */
@media (max-width: 781px) {

	/* Two classes, after the tiers' sizes. */
	.savtek-orgs .savtek-orgs__group {
		--savtek-name-size: 0.875rem;
		grid-template-columns: minmax(0, 1fr);
		padding-block: 1.1rem;
	}

	.savtek-orgs.is-band {
		--savtek-name-size: 0.875rem;
	}

	.savtek-orgs:not(.is-marquee) .savtek-orgs__list {
		display: grid;
		gap: 0.6rem;
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.savtek-orgs:is(.is-band, .has-tiers) .savtek-orgs__list {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.savtek-orgs:not(.is-marquee) .savtek-orgs__logo {
		max-height: calc(2.5rem * var(--savtek-logo-cap, var(--savtek-logo-scale, 1)));
	}

	.savtek-orgs:not(.is-marquee) .savtek-orgs__name {
		min-height: 3rem;
		padding-inline: 0.5rem;
	}
}

/*
 * The moving row: a compact strip moving left to right at a steady pace (the plugin sets the
 * duration from its length), logos and names in one near-ink tone. The copies before the real list
 * make the loop seamless. Hover, focus and the switch pause it; reduced motion and print stop it.
 */
.savtek-orgs.is-marquee {
	--savtek-logo-base: 4.75rem;
	--savtek-logo-max-w: 9.5rem;
	--savtek-logo-max-h: 3rem;
	--savtek-strip-gap: 2rem;
	align-items: center;
	display: flex;
	gap: 1rem;
	position: relative;
}

.savtek-orgs__viewport {
	flex: 1;
	min-width: 0;
	overflow: clip;
	padding-block: 0.375rem;
}

/* Clipped, so no scroll offset left by a focused logo can open a gap. */
.is-marquee:focus-within .savtek-orgs__viewport {
	overflow: hidden;
}

.is-moving .savtek-orgs__viewport {
	-webkit-mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
	mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
}

/* Standing still: one row from the left edge, under the band's title, wrapping. */
.savtek-orgs__track {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 1rem var(--savtek-strip-gap);
	list-style: none;
	margin: 0;
	padding: 0;
}

.is-moving .savtek-orgs__track {
	animation: savtek-marquee var(--savtek-marquee-duration, 60s) linear infinite reverse;
	flex-wrap: nowrap;
	gap: 0;
	justify-content: flex-start;
	width: max-content;
}

/* A margin, not a gap, so the second half starts exactly halfway. */
.is-moving .savtek-orgs__item {
	flex: none;
	margin-right: var(--savtek-strip-gap);
}

/* Logos in their own colors (A3); only a white logo, invisible on white, becomes a silhouette. */
.is-marquee .savtek-orgs__logo {
	opacity: 0.9;
	transition: opacity var(--wp--custom--transition);
}

.is-marquee .has-light-logo .savtek-orgs__logo {
	filter: brightness(0);
	opacity: 0.6;
}

/* Name tiles at least two lines tall, so they line up. */
.is-marquee .savtek-orgs__name {
	color: var(--wp--preset--color--muted);
	min-height: max(var(--savtek-logo-max-h), calc(2lh + 0.8rem));
}

.is-marquee .savtek-orgs__item:is(:hover, :focus-within) .savtek-orgs__logo {
	opacity: 1;
}

@keyframes savtek-marquee {

	to {
		transform: translateX(-50%);
	}
}

.savtek-orgs.is-marquee:hover .savtek-orgs__track,
.savtek-orgs.is-marquee:focus-within .savtek-orgs__track,
.savtek-orgs.is-marquee:has(.savtek-orgs__pause-input:checked) .savtek-orgs__track {
	animation-play-state: paused;
}

/* The switch: a round label; the checkbox stays focusable but unseen (core shows .screen-reader-text on focus). */
.savtek-orgs__pause-input {
	height: 1px;
	margin: 0;
	opacity: 0;
	position: absolute;
	right: 0;
	width: 1px;
}

.savtek-orgs__pause {
	border: 1px solid var(--wp--custom--border-strong);
	border-radius: 50%;
	color: var(--wp--preset--color--contrast);
	cursor: pointer;
	display: grid;
	flex: none;
	height: 2.25rem;
	order: 2;
	place-items: center;
	width: 2.25rem;
}

.savtek-orgs__pause::before {
	background: linear-gradient(90deg, currentcolor 0 35%, transparent 35% 65%, currentcolor 65%);
	content: "";
	height: 0.7rem;
	width: 0.6rem;
}

.savtek-orgs__pause-input:checked + .savtek-orgs__pause::before {
	background: currentcolor;
	clip-path: polygon(0 0, 100% 50%, 0 100%);
	margin-left: 0.15rem;
}

.savtek-orgs__pause-input:focus-visible + .savtek-orgs__pause {
	outline: 3px solid var(--savtek-ring);
	outline-offset: 2px;
}

@media (max-width: 781px) {

	.savtek-orgs.is-marquee {
		--savtek-logo-base: 3.25rem;
		--savtek-logo-max-w: 8.5rem;
		--savtek-logo-max-h: 2.5rem;
		--savtek-name-size: 0.8125rem;
		--savtek-strip-gap: 1.5rem;
		gap: 0.75rem;
	}
}

@media (prefers-reduced-motion: reduce), print {

	.is-moving .savtek-orgs__track {
		animation: none;
		flex-wrap: wrap;
		gap: 1rem var(--savtek-strip-gap);
		justify-content: center;
		width: auto;
	}

	.is-moving .savtek-orgs__item {
		margin-right: 0;
	}

	.savtek-orgs__item.is-copy,
	.savtek-orgs__pause,
	.savtek-orgs__pause-input {
		display: none;
	}

	.is-moving .savtek-orgs__viewport {
		-webkit-mask-image: none;
		mask-image: none;
	}
}
