/**
 * cm-alpha ui-carousel - the row and the rows rules (plan 05.1-06; the entering card and the effects plan 05.1-14; the vertical direction as
 * ROWS plan 05.1-15). The viewport scrolls the track (whole cards, snapped); its padding and negative margin leave room for a card's focus ring
 * (--cm-carousel-ring) without moving the cards; the scrollbar is thin, and hidden while the engine runs. The track is one flex row, or under
 * cm-carousel--vertical on the viewport a GRID of N columns and unit-tall rows; N = --cm-carousel-visible, set HERE on the viewport per container
 * tier (one card, two from a 523px container, the block's --cm-carousel-across from 950px: cm-alpha's zm and zt tiers) and inherited by the
 * track; auto margins on the end cards centre a short row and collapse to zero when the row overflows. A vertical direction: the cards keep their
 * side-by-side places and whole rows travel; every row is one unit tall, --cm-carousel-unit, which the engine measures (the tallest real card's
 * natural height) and sets inline on the viewport with cm-carousel--measured; the viewport is ONE unit plus the ring room tall (border-box: a
 * block without its own box-sizing rule gets the same height), so one row is in view; a short last row keeps its empty slots (sparse
 * auto-placement) and the engine's one row of copies is forced onto a NEW row (the first copy's grid-column-start), so no card shows twice; until
 * the measure the viewport hides its overflow, the rows past the first collapse to 0 and the track clips (a card's padding box outlives its
 * collapsed row), so the first row paints whole, never the set stacked down the page; scrollbar-gutter: stable keeps the measured width the shown width when a stopped viewport shows its scrollbar; 1px of slack
 * under the track so the lap position (rows × unit) is never clamped by a fractional gap. While the engine runs the vertical hand-scroll is
 * off (a wheel or swipe over it scrolls the page; scrollTo still works), back when it stops. The entering cards (cm-carousel__card--entering, set
 * by the engine for one step: the card that arrives on a row, every card of the row that arrives in a vertical direction) fade in over
 * --cm-carousel-fade and, under data-cm-carousel-effect on the track, bounce along the direction's axis (--cm-carousel-dx / -dy from
 * data-cm-carousel-direction) or flip, over --cm-carousel-effect-time; the block prints the two time variables on its wrapper in every
 * arrangement (a grid carries them inertly). While they animate the viewport carries cm-carousel--animating and snapping is off: a transformed
 * card moves its own snap position, and a one-card view would land a few pixels off (the engine scrolls to the exact unit; the snap returns at
 * the release, where the cards already sit). Reduced motion ends every animation (the engine never steps then: belt and braces). While the
 * engine moves the cards itself (plan 05.1-16) the viewport carries cm-carousel--sliding and snapping is off too: a frame-by-frame scroll under
 * mandatory snapping is pulled back to a snap point. A step against the direction (Previous) puts cm-carousel__track--back on the track, which
 * turns --cm-carousel-sign and with it the side the bounce comes from. The controls wrapper (Previous, Pause, Next: three buttons, the
 * viewport's next sibling) is a centred row that shows only while the engine runs, and on the editor canvas, where no engine runs and the
 * three stand inert so their look can be styled by eye (the ONLY place its visibility lives; the wrapper carries no margin: each block keeps
 * the space above on its buttons, whose em is the links' own size). --cm-carousel-gap and --cm-carousel-ring are set by each block
 * on its own wrapper (never here, never at :root); no colour, no font, no words.
 */
.cm-carousel {
    --cm-carousel-visible: 1;
    overflow-x: auto;
    overflow-y: hidden;
    padding: var(--cm-carousel-ring);
    margin: calc(var(--cm-carousel-ring) * -1);
    scroll-snap-type: x mandatory;
    scroll-padding: var(--cm-carousel-ring);
    scrollbar-width: thin;
}
.cm-carousel--running { scrollbar-width: none; }
.cm-carousel--running::-webkit-scrollbar { display: none; }
.cm-carousel__track {
    --cm-carousel-sign: 1;
    display: flex;
    align-items: stretch;
    gap: var(--cm-carousel-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}
.cm-carousel__card {
    flex: 0 0 calc((100% - (var(--cm-carousel-visible) - 1) * var(--cm-carousel-gap)) / var(--cm-carousel-visible));
    min-width: 0;
    scroll-snap-align: start;
}
.cm-carousel__card:first-child { margin-left: auto; }
.cm-carousel__card:last-child { margin-right: auto; }
.cm-carousel__track--back { --cm-carousel-sign: -1; }
.cm-carousel__controls { display: none; }
.cm-carousel--running + .cm-carousel__controls,
.editor-styles-wrapper .cm-carousel + .cm-carousel__controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0 var(--cm-carousel-gap); }
@container (min-width: 523px) {
    .cm-carousel { --cm-carousel-visible: 2; }
}
@container (min-width: 950px) {
    .cm-carousel { --cm-carousel-visible: var(--cm-carousel-across); }
}
/* The rows (Top to bottom / Bottom to top): after the row rules, same specificity, so source order decides */
.cm-carousel--vertical {
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    scroll-snap-type: y mandatory;
    height: calc(var(--cm-carousel-unit) + 2 * var(--cm-carousel-ring));
}
.cm-carousel--vertical.cm-carousel--running { overflow-y: hidden; }
.cm-carousel--vertical:not(.cm-carousel--measured) { overflow-y: hidden; }
.cm-carousel--vertical:not(.cm-carousel--measured) .cm-carousel__track { grid-template-rows: auto; grid-auto-rows: 0; row-gap: 0; padding-bottom: 0; overflow: hidden; } /* a card's padding box outlives its collapsed row: the track clips it */
.cm-carousel--vertical .cm-carousel__track {
    display: grid;
    grid-template-columns: repeat(var(--cm-carousel-visible), minmax(0, 1fr));
    grid-auto-rows: var(--cm-carousel-unit);
    padding-bottom: 1px;
}
.cm-carousel--vertical .cm-carousel__card { min-height: 0; }
.cm-carousel--vertical .cm-carousel__card:first-child, .cm-carousel--vertical .cm-carousel__card:last-child { margin: 0; }
.cm-carousel--vertical .cm-carousel__card:not(.cm-carousel__card--clone) + .cm-carousel__card--clone { grid-column-start: 1; }
.cm-carousel--animating, .cm-carousel--sliding { scroll-snap-type: none; }
/* The direction's axis signs for the bounce (times --cm-carousel-sign: 1 on the track, -1 for a step against the direction) */
.cm-carousel__track[data-cm-carousel-direction="rtl"] { --cm-carousel-dx: -1; --cm-carousel-dy: 0; }
.cm-carousel__track[data-cm-carousel-direction="ltr"] { --cm-carousel-dx: 1; --cm-carousel-dy: 0; }
.cm-carousel__track[data-cm-carousel-direction="btt"] { --cm-carousel-dx: 0; --cm-carousel-dy: -1; }
.cm-carousel__track[data-cm-carousel-direction="ttb"] { --cm-carousel-dx: 0; --cm-carousel-dy: 1; }
@keyframes cm-carousel-fade { from { opacity: 0; } }
@keyframes cm-carousel-bounce {
    0% { transform: translate(calc(var(--cm-carousel-dx) * var(--cm-carousel-sign) * 6%), calc(var(--cm-carousel-dy) * var(--cm-carousel-sign) * 6%)); }
    60% { transform: translate(calc(var(--cm-carousel-dx) * var(--cm-carousel-sign) * -2%), calc(var(--cm-carousel-dy) * var(--cm-carousel-sign) * -2%)); }
    100% { transform: none; }
}
@keyframes cm-carousel-flip-h { from { transform: perspective(900px) rotateY(90deg); } to { transform: perspective(900px) rotateY(0); } }
@keyframes cm-carousel-flip-v { from { transform: perspective(900px) rotateX(90deg); } to { transform: perspective(900px) rotateX(0); } }
/* The entering card (every card of the arriving row in a vertical direction): the fade alone, or the fade with the track's effect */
.cm-carousel__card--entering { animation: cm-carousel-fade var(--cm-carousel-fade) ease-out both; }
.cm-carousel__track[data-cm-carousel-effect="bounce"] > .cm-carousel__card--entering { animation: cm-carousel-fade var(--cm-carousel-fade) ease-out both, cm-carousel-bounce var(--cm-carousel-effect-time) ease-out both; }
.cm-carousel__track[data-cm-carousel-effect="flip-h"] > .cm-carousel__card--entering { animation: cm-carousel-fade var(--cm-carousel-fade) ease-out both, cm-carousel-flip-h var(--cm-carousel-effect-time) ease-out both; }
.cm-carousel__track[data-cm-carousel-effect="flip-v"] > .cm-carousel__card--entering { animation: cm-carousel-fade var(--cm-carousel-fade) ease-out both, cm-carousel-flip-v var(--cm-carousel-effect-time) ease-out both; }
@media (prefers-reduced-motion: reduce) {
    .cm-carousel__card--entering, .cm-carousel__track[data-cm-carousel-effect] > .cm-carousel__card--entering { animation: none; }
}
