/**
 * AA Marquee — the motion shared by aa/image-marquee and aa/announcement-bar.
 * See inc/marquee.php for the overview and assets/js/marquee.js for the script.
 *
 * Loaded as a dependency of each block's own stylesheet, so it reaches the
 * front end and the editor iframe alike, and only on pages that use a marquee.
 *
 * Nothing here moves until the script adds .is-animated. That is the whole
 * safety model: the pause button needs script, and motion with no way to stop
 * it fails WCAG 2.2.2, so a page without script — or a visitor who asks for
 * reduced motion — gets the at-rest layout instead. At rest, scrolling is a row
 * you can scroll by hand and fading is a plain stacked list with every item
 * readable at once. The editor never gets .is-animated either, so it draws the
 * at-rest version too.
 */

.aa-marquee {
	position: relative;
}


/* -- Scrolling --
   The track carries one set of items plus as many copies as the screen needs,
   and slides by exactly one set plus one gap before starting over, so the last
   frame of the slide is identical to the first. marquee.js measures the set and
   publishes both the distance and a duration derived from the pace. */

.aa-marquee--scroll .aa-marquee__viewport {
	overflow-x: auto;
	overscroll-behavior-x: contain;
}

.aa-marquee--scroll .aa-marquee__viewport:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary, #0C2A4E);
	outline-offset: 2px;
}

/* Moving, the viewport clips instead. `clip` rather than `hidden` so focus
   cannot scroll it and knock the loop out of register (marquee.js moves the
   loop to the focused item instead), and so the vertical axis can stay visible
   for focus rings. Browsers without `clip` drop the second line. */
.aa-marquee--scroll.is-animated .aa-marquee__viewport {
	overflow: hidden;
	overflow: clip visible;
}

.aa-marquee--scroll .aa-marquee__track,
.aa-marquee--scroll .aa-marquee__set {
	display: flex;
	align-items: flex-start;
	width: max-content;
}

/* Between one announcement and the next. */
.aa-marquee--scroll .aa-marquee__set {
	gap: var(--aa-marquee-gap, 16px);
}

/* Between whole copies of the set: the same spacing while the row is simply
   tiled, and whatever room is left over when it wraps — which is what puts the
   copy behind exactly one screen to the right, so the head arrives as the tail
   leaves. The script measures it. */
.aa-marquee--scroll .aa-marquee__track {
	gap: var(--aa-marquee-copy-gap, var(--aa-marquee-gap, 16px));
}

.aa-marquee--scroll .aa-marquee__set {
	flex: none;
}

/* The row's position is written by assets/js/marquee.js, a frame at a time,
   rather than run as a keyframe animation here. Easing a CSS animation to a
   stop means writing its playback rate every frame, and each of those writes
   re-times the animation; a composited animation is rebuilt on each one, and
   while the compositor is busy with a scroll a frame can be painted from the
   element's base transform — the row flashing back to its start and returning.
   Owning the position in script removes that whole class of problem.

   will-change keeps the track on its own layer, so each frame's transform is
   composited rather than repainted. */
.aa-marquee--scroll.is-animated .aa-marquee__track {
	will-change: transform;
}

/* Nothing here pauses the motion either. The button, a pointer resting on the
   block, keyboard focus inside it and a backgrounded tab are all read by the
   script, which eases the row's speed down to nothing and back. `is-paused` is
   left as the state the pause icon is drawn from. */


/* -- Dragging --
   A block that says it can be dragged (data-drag) gets the affordances with it.
   Only while it is moving under its own steam: at rest the viewport is an
   ordinary scroller, and the browser's own dragging and momentum are better
   than anything reimplemented here.

   pan-y leaves vertical scrolling to the page. Without it a gesture that starts
   sideways is swallowed whole and the page feels stuck, which is a far worse
   fault than the row not following a finger. */
.aa-marquee[data-drag].is-animated .aa-marquee__viewport {
	touch-action: pan-y;
	cursor: grab;
}

.aa-marquee[data-drag].is-dragging .aa-marquee__viewport {
	cursor: grabbing;
}

/* Belt and braces with the dragstart above: WebKit takes this hint before it
   starts lifting a picture or a link out of the page. */
.aa-marquee[data-drag] .aa-marquee__viewport img,
.aa-marquee[data-drag] .aa-marquee__viewport a {
	-webkit-user-drag: none;
}

/* Only while a drag is actually happening, so captions stay selectable the
   rest of the time. */
.aa-marquee[data-drag].is-dragging,
.aa-marquee[data-drag].is-dragging * {
	-webkit-user-select: none;
	user-select: none;
}


/* -- Fading --
   At rest the items are a stacked list. Once running they share one grid cell,
   so the block is as tall as the tallest item and nothing shifts as they
   change, and only .is-current is visible.

   visibility, not just opacity: it takes the items that are out of sight out of
   the tab order and the accessibility tree with them, so a link inside an
   invisible announcement cannot be tabbed to or read out. That is also why the
   previous and next buttons exist — they are the only way back to an item that
   has already passed. */

.aa-marquee--fade .aa-marquee__set {
	display: flex;
	flex-direction: column;
	gap: var(--aa-marquee-gap, 8px);
}

.aa-marquee--fade.is-animated .aa-marquee__set {
	display: grid;
	gap: 0;
}

.aa-marquee--fade.is-animated .aa-marquee__set > * {
	grid-area: 1 / 1;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.4s ease, visibility 0.4s;
}

.aa-marquee--fade.is-animated .aa-marquee__set > .is-current {
	opacity: 1;
	visibility: visible;
}


/* -- Controls --
   A group rather than a lone button, because fading adds previous and next.
   They sit over the content by default, which suits photos; a block whose items
   are text places the group beside them instead (see announcement-bar.css).

   Translucent navy rather than faded: lowering opacity would thin the icons
   too, whereas white on 70% navy keeps about 5.5:1 even over a white photo,
   clear of the 3:1 an icon needs. The focus ring is white inside navy so it
   shows on any background. */
.aa-marquee__controls {
	position: absolute;
	z-index: 1;
	inset-block-start: 12px;
	inset-inline-end: 12px;
	display: flex;
	gap: 4px;
}

.aa-marquee__toggle,
.aa-marquee__nav {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: color-mix(in srgb, var(--wp--preset--color--primary, #0C2A4E) 70%, transparent);
	color: #fff;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.aa-marquee__toggle[hidden],
.aa-marquee__nav[hidden] {
	display: none;
}

.aa-marquee__toggle:hover,
.aa-marquee__nav:hover {
	background: color-mix(in srgb, var(--wp--preset--color--primary, #0C2A4E) 90%, transparent);
}

.aa-marquee__toggle:focus-visible,
.aa-marquee__nav:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary, #0C2A4E);
	outline-offset: 2px;
	box-shadow: 0 0 0 2px #fff;
}

.aa-marquee__icon {
	display: block;
	width: 16px;
	height: 16px;
	fill: currentColor;
}

.aa-marquee__icon--play,
.aa-marquee.is-paused .aa-marquee__icon--pause {
	display: none;
}

.aa-marquee.is-paused .aa-marquee__icon--play {
	display: block;
}


/* -- Editor --
   The in-row "+" sits mid-height beside the last item. */
.aa-marquee__set > .block-list-appender {
	flex: none;
	align-self: center;
}
