/**
 * Logo Wall: customer logos at an even visual weight (divb-hq#367, docs/SPEC-logo-wall.md §7).
 *
 * Each logo is a mask over `currentColor`, sized on the server (`Mf_Lw_Sizing`) and written
 * inline. The count per row is lowered here, from one number the server writes: the widest
 * logo plus its cell's padding (`--mf-lw-wmax`). A cell is never narrower than that, so once
 * the column gets tight the wrap puts fewer cells in a row. Nothing is measured at load.
 *
 * The counts per width are container queries on the outer element: the column the block sits
 * in decides, not the window. Only the thresholds are fixed; the numbers are properties.
 *
 * Host theme (docs/shared/host-theme.md): the list items' reset comes first, at (0,1,2), and
 * the marquee's pause button follows the five-class button rule.
 */

:is(ul, ol).mf-lw__list > li {
	margin: 0;
}

.mf-lw {
	--mf-lw-gap-x: 34px;
	--mf-lw-gap-y: 26px;
	--mf-lw-cols: var(--mf-lw-n, 5);
	container: mf-lw / inline-size;
}

@container mf-lw (max-width: 700px) {

	.mf-lw__list {
		--mf-lw-cols: var(--mf-lw-n-tab, 4);
	}
}

@container mf-lw (max-width: 440px) {

	.mf-lw__list {
		--mf-lw-cols: var(--mf-lw-n-phone, 3);
		--mf-lw-gap-x: 22px;
	}
}

/* The column a count asks for, and the cell: never narrower than the widest logo, so a tight
   column gets fewer logos a row, but never narrower than the floor's column either (two a row,
   or the phone count if lower). Past the floor the logos shrink with their cell, evenly, from
   the `min()` on each logo's width. Half a pixel off keeps rounding from dropping a cell. */
.mf-lw .mf-lw__list {
	--mf-lw-gaps: calc((var(--mf-lw-cols) - 1) * var(--mf-lw-gap-x));
	--mf-lw-col: calc((100% - var(--mf-lw-gaps)) / var(--mf-lw-cols) - 0.5px);
	--mf-lw-floor-gaps: calc((var(--mf-lw-n-min, 2) - 1) * var(--mf-lw-gap-x));
	--mf-lw-floor: calc((100% - var(--mf-lw-floor-gaps)) / var(--mf-lw-n-min, 2) - 0.5px);
	--mf-lw-cell: min(var(--mf-lw-floor), max(var(--mf-lw-wmax, 0px), var(--mf-lw-col)));
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: var(--mf-lw-gap-y) var(--mf-lw-gap-x);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mf-lw__list > li {
	box-sizing: border-box;
	display: flex;
	flex: 0 0 var(--mf-lw-cell);
	justify-content: center;
	align-items: center;
	min-width: 0;
}

.mf-lw__logo {
	display: block;
	max-width: 100%;
	height: auto;
	background: currentcolor;
	mask: var(--mf-lw-src) center / contain no-repeat;
}

/* ---------- colours ---------- */

.mf-lw--muted .mf-lw__logo {
	opacity: 0.62;
}

@media (hover: hover) {

	.mf-lw--muted li:hover .mf-lw__logo {
		opacity: 1;
	}
}

.mf-lw--grey {
	color: var(--mf-lw-grey, #707271);
}

@media (prefers-reduced-motion: no-preference) {

	.mf-lw__logo {
		transition: opacity 0.3s ease;
	}
}

/* ---------- layouts ---------- */

/* Lines: a grid with a hairline round every cell. The last row stays left, so the lines close. */
.mf-lw--lines .mf-lw__list {

	/* A length, not 0: `100% - 0` is not valid inside calc(). */
	/* stylelint-disable-next-line length-zero-no-unit */
	--mf-lw-gap-x: 0px;
	/* stylelint-disable-next-line length-zero-no-unit */
	--mf-lw-gap-y: 0px;
	--mf-lw-line: rgba(0, 0, 0, 0.08);
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--mf-lw-cell), 1fr));
	align-items: stretch;
	border-top: 1px solid var(--mf-lw-line);
	border-left: 1px solid var(--mf-lw-line);
}

.mf-lw--lines .mf-lw__list > li {
	padding: 22px 18px;
	border-right: 1px solid var(--mf-lw-line);
	border-bottom: 1px solid var(--mf-lw-line);
}

/* Tiles: each logo on a surface of its own. */
.mf-lw--tiles .mf-lw__list {
	--mf-lw-gap-x: 12px;
	--mf-lw-gap-y: 12px;
	align-items: stretch;
}

.mf-lw--tiles .mf-lw__list > li {
	min-height: calc(var(--mf-lw-rowh, 34px) + 40px);
	padding: 20px 16px;
	border-radius: 6px;
	background: var(--mf-lw-tile, #f5f3f0);
}

/* Flow, and a marquee nothing has started: as many as fit, the column decides. */
.mf-lw--flow .mf-lw__list,
.mf-lw--marquee .mf-lw__list {
	justify-content: flex-start;
	gap: 22px 40px;
}

.mf-lw--flow .mf-lw__list > li,
.mf-lw--marquee .mf-lw__list > li {
	flex: 0 0 auto;
}

/* ---------- the marquee ---------- */

/* It moves only once its script added `is-running`, which it never does under reduced motion.
   Without the script the copy is not there and the wall is a calm flow. */
.mf-lw--marquee .mf-lw__copy {
	display: none;
}

.mf-lw--marquee.is-running .mf-lw__viewport {
	overflow: hidden;
	mask: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}

.mf-lw--marquee.is-running .mf-lw__track {
	display: flex;
	width: max-content;
}

.mf-lw--marquee.is-running .mf-lw__list {
	flex-wrap: nowrap;
	gap: 0 48px;
	padding-right: 48px;
}

.mf-lw--marquee.is-running .mf-lw__copy {
	display: flex;
}

@media (prefers-reduced-motion: no-preference) {

	.mf-lw--marquee.is-running .mf-lw__track {
		animation: mf-lw-marquee var(--mf-lw-duration, 48s) linear infinite;
	}

	.mf-lw--marquee.is-running .mf-lw__viewport:hover .mf-lw__track,
	.mf-lw--marquee.is-paused .mf-lw__track {
		animation-play-state: paused;
	}
}

@keyframes mf-lw-marquee {

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

.mf-lw__pause {
	--mf-btn-ink: currentcolor;
	--mf-btn-fill: transparent;
	margin-top: 14px;
	padding: 4px 10px;
	border: 1px solid currentcolor;
	border-radius: 6px;
	font: inherit;
	font-size: 13px;
	line-height: 1.4;
	opacity: 0.7;
	cursor: pointer;
}

.mf-lw__pause[hidden] {
	display: none;
}

/* Once per stylesheet: the button's two colours at five classes (host-theme.md). */
.mf-lw__pause.mf-lw__pause.mf-lw__pause.mf-lw__pause.mf-lw__pause {
	background: var(--mf-btn-fill, transparent);
	color: var(--mf-btn-ink, currentcolor);
}
