/* Author: Tobalt — https://tobalt.lt */

.tobalt-juosta {
	position: relative;
	overflow: hidden;
	display: flex;
	align-items: center;
	background: var(--juosta-bg, #005083);
	color: var(--juosta-fg, #ffffff);
	font-size: 0.95rem;
	line-height: 1.4;
}

/* `max-content`: be jo flex vaikai susispaustų iki tėvo pločio ir animacija
   neturėtų ko stumti. */
.tobalt-juosta__track {
	display: flex;
	gap: 3rem;
	width: max-content;
	padding: 0.6rem 1.5rem;
	animation: tobalt-juosta-scroll var(--juosta-speed, 40s) linear infinite;
}

.tobalt-juosta__item {
	color: inherit;
	text-decoration: none;
	white-space: nowrap;
}

.tobalt-juosta__item:hover,
.tobalt-juosta__item:focus-visible {
	text-decoration: underline;
}

.tobalt-juosta:hover .tobalt-juosta__track,
.tobalt-juosta:focus-within .tobalt-juosta__track,
.tobalt-juosta.is-paused .tobalt-juosta__track {
	animation-play-state: paused;
}

/*
 * The button is FIRST in the markup (see class-render.php — a keyboard user
 * would otherwise tab through every scrolling link before reaching it) AND
 * visually first: `.tobalt-juosta__track` is `width: max-content` with
 * nowrap items, so it CANNOT shrink — at any realistic item count it is
 * wider than the visible band. An `order` here that placed this button
 * after the track would put it past the clip edge of `overflow: hidden`,
 * outside the visible band, at every configuration except a single item on
 * a wide viewport (measured: 10 items @1440px put the button at
 * x=[6556,6640], far past the [0,1440] band — invisible; the WCAG 2.2.2
 * pause control would be there in the DOM and in the accessibility tree,
 * but not on screen for a mouse user). Do NOT add `order` back without
 * re-measuring the button's bounding rect against the band's at multiple
 * item counts and viewport widths.
 */
.tobalt-juosta__pause {
	flex: 0 0 auto;
	margin-inline: 0.5rem;
	padding: 0.2rem 0.7rem;
	background: transparent;
	color: inherit;
	border: 1px solid currentColor;
	border-radius: 3px;
	font-size: 0.8rem;
	cursor: pointer;
}

.tobalt-juosta__pause:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* Perkėlimas per -50% paliktų tarpo pločio šuolį ties siūle, nes `gap` veikia
   ir tarp dviejų rinkinių — atimame pusę tarpo. */
@keyframes tobalt-juosta-scroll {
	from { transform: translateX(0); }
	to   { transform: translateX(calc(-50% - 1.5rem)); }
}

/*
 * `animation: none` alone is NOT enough here: the track would sit pinned at
 * `translateX(0)` inside `overflow: hidden` + `white-space: nowrap`, so a
 * reduced-motion visitor could see only the first item or two and could
 * NEVER reach the rest — the accessibility accommodation would remove
 * information instead of preserving it, and it also fails WCAG 1.4.10
 * Reflow at 320px / 400% zoom for everyone, motion preference aside.
 * Fix: turn the band into a plain horizontally scrollable list (still no
 * animation) and hide the duplicate item set — it exists only to hide the
 * seam of the now-disabled marquee loop, so showing it here would just be
 * every headline twice. DO NOT "tidy" `overflow-x: auto` back to `hidden`.
 */
@media (prefers-reduced-motion: reduce) {
	.tobalt-juosta { overflow-x: auto; }
	.tobalt-juosta__track { animation: none; }
	.tobalt-juosta__item[aria-hidden="true"] { display: none; }
}

@media (max-width: 767.98px) {
	.tobalt-juosta { font-size: 0.85rem; }
	.tobalt-juosta__track { gap: 2rem; animation-duration: calc(var(--juosta-speed, 40s) * 0.7); }
	@keyframes tobalt-juosta-scroll {
		from { transform: translateX(0); }
		to   { transform: translateX(calc(-50% - 1rem)); }
	}
}
