/* ==========================================================================
   COMPONENT — Brand logo carousel (logo marquee)
   --------------------------------------------------------------------------
   One slow, endless row of brand logos: the homepage "Brändid" band and the
   Meist block "Rahvusvahelised partnerid" (client 16.11 point 2; owner 4.2).
   Markup: template-parts/components/logo-marquee.php; sizes and the loop
   length are explained in inc/logo-marquee.php.

   - Motion is one CSS transform animation on the track (GPU, no script per
     frame): the track holds the row twice and moves left by one copy.
   - It pauses under the pointer and while a logo has keyboard focus.
   - prefers-reduced-motion: nothing moves; the copy is not shown and the row
     is a normal horizontal scroller (the arrows still work).
   - Every logo gets the same AREA inside a height and width cap, measured on
     its ink, so a crest and a long wordmark weigh the same.
   ========================================================================== */

.logo-marquee {
	/* Phones; the variants and 768px+ below set their own. */
	--lm-area: 58px;
	--lm-hmax: 50px;
	--lm-wmax: 140px;
	--lm-gap: 40px;
	--lm-fade: 32px;
	--lm-bg: var(--color-cream);
	--lm-duration: 60s;

	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-areas:
		'view view'
		'prev next';
	gap: var(--space-xs) var(--space-sm);
	align-items: center;
}

.logo-marquee--home {
	--lm-bg: var(--color-surface-light);
}

.logo-marquee--meist {
	--lm-area: 64px;
	--lm-hmax: 56px;
	--lm-wmax: 156px;
	--lm-gap: 48px;
	--lm-bg: var(--color-on-dark-pure);
}

@media (min-width: 768px) {

	.logo-marquee {
		grid-template-columns: auto minmax(0, 1fr) auto;
		grid-template-areas: 'prev view next';
		column-gap: var(--space-sm);
	}

	.logo-marquee--home {
		--lm-area: 70px;
		--lm-hmax: 60px;
		--lm-wmax: 170px;
		--lm-gap: 64px;
		--lm-fade: 64px;
	}

	.logo-marquee--meist {
		--lm-area: 84px;
		--lm-hmax: 72px;
		--lm-wmax: 200px;
		--lm-gap: 80px;
		--lm-fade: 64px;
	}
}

/* --------------------------------------------------------------------------
   VIEWPORT AND TRACK
   -------------------------------------------------------------------------- */

.logo-marquee__viewport {
	grid-area: view;
	min-width: 0;
	/* Room for a focus ring above and below the logos. */
	padding-block: 6px;
	overflow: hidden;
	/* clip, where supported: focus cannot scroll it behind the animation's back. */
	overflow: clip;
	/* The row fades in and out at its ends rather than being cut. */
	-webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--lm-fade), #000 calc(100% - var(--lm-fade)), transparent 100%);
	mask-image: linear-gradient(90deg, transparent 0, #000 var(--lm-fade), #000 calc(100% - var(--lm-fade)), transparent 100%);
	/* Vertical page scrolling stays the browser's; a sideways swipe is the row's. */
	touch-action: pan-y;
	cursor: grab;
}

.logo-marquee.is-dragging .logo-marquee__viewport {
	cursor: grabbing;
}

/* A focused logo is never left under the fade. */
.logo-marquee__viewport:focus-within {
	-webkit-mask-image: none;
	mask-image: none;
}

.logo-marquee__track {
	position: relative;
	display: flex;
	align-items: center;
	width: max-content;
	margin: 0;
	padding: 0;
	list-style: none;
	/* The page colour inside the moving layer, so white logo plates can
	   multiply into it (see .logo-marquee__logo). */
	background-color: var(--lm-bg);
	animation: logo-marquee var(--lm-duration) linear infinite;
	will-change: transform;
}

/* Without the script: still pauses under the pointer and on focus. */
.logo-marquee:hover .logo-marquee__track,
.logo-marquee:focus-within .logo-marquee__track {
	animation-play-state: paused;
}

@keyframes logo-marquee {

	from {
		transform: translate3d(0, 0, 0);
	}

	to {
		transform: translate3d(-50%, 0, 0);
	}
}

/* --------------------------------------------------------------------------
   ITEMS
   -------------------------------------------------------------------------- */

.logo-marquee__item {
	flex: none;
	/* Half the gap on each side, so the two copies are exactly equal. */
	padding-inline: calc(var(--lm-gap) / 2);
}

.logo-marquee__link {
	display: flex;
	align-items: center;
	justify-content: center;
	/* Every item the same height: the row's centre line never wobbles. */
	height: calc(var(--lm-hmax) + 12px);
	border-radius: var(--radius-sm);
	text-decoration: none;
	-webkit-user-drag: none;
	user-select: none;
}

.logo-marquee__link:focus-visible {
	outline: 2px solid var(--focus-ring-color);
	outline-offset: 4px;
}

/*
 * The mark: exactly the logo's ink, sized so every mark has the same area
 * (area² = height x width), within the variant's caps. The first height is
 * the fallback for a browser without sqrt().
 */
.logo-marquee__mark {
	position: relative;
	display: block;
	flex: none;
	height: min(var(--lm-hmax), calc(var(--lm-wmax) / var(--r)));
	height: min(calc(var(--lm-area) / sqrt(var(--r))), var(--lm-hmax), calc(var(--lm-wmax) / var(--r)));
	aspect-ratio: var(--r);
	overflow: hidden;
	transition: transform var(--transition-base);
}

/* The whole image, shifted and scaled so its ink box fills the mark. */
.logo-marquee__logo {
	position: absolute;
	top: var(--iy);
	left: var(--ix);
	width: var(--iw);
	max-width: none;
	height: auto;
	/* A logo delivered on a white plate loses the plate on a tinted band. */
	mix-blend-mode: multiply;
	pointer-events: none;
}

.logo-marquee__link:hover .logo-marquee__mark {
	transform: scale(1.04);
}

/* A brand without a logo is shown as its name. */
.logo-marquee__name {
	font-family: var(--font-heading);
	font-style: normal;
	font-size: 18px;
	line-height: 24px;
	white-space: nowrap;
	color: var(--color-ink);
}

/* --------------------------------------------------------------------------
   ARROWS (shown by the script; without it there is nothing to drive them)
   -------------------------------------------------------------------------- */

.logo-marquee__nav {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 1px solid var(--color-rose);
	border-radius: var(--radius-pill);
	background-color: transparent;
	color: var(--color-ink);
	cursor: pointer;
	transition:
		color var(--transition-base),
		border-color var(--transition-base);
}

.logo-marquee__nav[hidden] {
	display: none;
}

.logo-marquee__nav:hover {
	border-color: var(--color-primary);
	color: var(--color-primary);
}

.logo-marquee__nav svg {
	display: block;
}

.logo-marquee__nav--prev {
	grid-area: prev;
	justify-self: end;
}

.logo-marquee__nav--next {
	grid-area: next;
	justify-self: start;
}

/* --------------------------------------------------------------------------
   REDUCED MOTION — a still row the reader scrolls
   -------------------------------------------------------------------------- */

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

	.logo-marquee__viewport {
		overflow-x: auto;
		overflow-y: hidden;
		-webkit-mask-image: none;
		mask-image: none;
		scroll-snap-type: x proximity;
		scrollbar-width: thin;
		touch-action: auto;
		cursor: auto;
	}

	.logo-marquee__track {
		animation: none;
		transform: none;
		will-change: auto;
	}

	.logo-marquee__item[aria-hidden='true'] {
		display: none;
	}

	.logo-marquee__item {
		scroll-snap-align: start;
	}

	.logo-marquee__link:hover .logo-marquee__mark {
		transform: none;
	}
}
