/* Butter Counter (Bricks element), shipped with Butter 0.9.8
 * Typography is never set here: the number and the label follow the standard Bricks Typography
 * settings of the element. Every animated piece (a character, a line or the whole block) carries
 * --p, a number from 0 (not shown) to 1 (shown). JS writes --p, the rules below turn it into motion. */

.btr-ct {
	--btr-ct-o: 0;
	--btr-ct-dist: 40px;
	--btr-ct-blur: 12px;
	--btr-ct-scale: .6;
	--btr-ct-rot: 80deg;
	--btr-ct-ls: 30;
	--btr-ct-gap: .4em;
	--btr-ct-lh: 1.15em;
	position: relative;
}

.btr-ct__box {
	display: block;
}

.btr-ct__row {
	display: block;
	margin: 0;
	white-space: nowrap;
	font-variant-numeric: tabular-nums lining-nums;
}

.btr-ct--prop .btr-ct__row {
	font-variant-numeric: normal;
}

.btr-ct__lbl {
	display: block;
	/* Fallback size only: the Typography setting of each label overrides it. */
	font-size: calc(var(--btr-ct-ls, 30) * 1%);
	font-variant-numeric: normal;
}

.btr-ct__lbl--top {
	margin-bottom: var(--btr-ct-gap-t, .4em);
}

.btr-ct__lbl--bottom {
	margin-top: var(--btr-ct-gap-b, .4em);
}

.btr-ct__ll {
	display: block;
}

.btr-ct__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* One character cell. */
.btr-ct__c {
	display: inline-block;
	white-space: pre;
	backface-visibility: hidden;
}

.btr-ct__c.is-off {
	visibility: hidden;
}

.btr-ct__c.is-gone {
	display: none;
}

/* Roll: every digit is a window onto a strip of 0 to 9 and back to 0. */
.btr-ct__c--d {
	height: var(--btr-ct-lh);
	overflow: hidden;
	vertical-align: top;
}

.btr-ct__strip {
	display: block;
	transform: translate3d(0, calc(var(--btr-pos, 0) * var(--btr-ct-lh) * -1), 0);
	will-change: transform;
}

.btr-ct__strip > i {
	display: block;
	height: var(--btr-ct-lh);
	line-height: var(--btr-ct-lh);
	font-style: normal;
}

/* The roll window needs a fixed line height; plain cells keep the theme line height. */
.btr-ct--count-roll .btr-ct__row {
	line-height: var(--btr-ct-lh);
}

/* Hide the raw numbers until JS has built the counter, with a failsafe if JS never arrives. */
@media (scripting: enabled) {
	.btr-ct:not(.is-ready) .btr-ct__box {
		visibility: hidden;
		animation: btr-ct-failsafe 0s linear 3s forwards;
	}
}

@keyframes btr-ct-failsafe {
	to {
		visibility: visible;
	}
}

/* ---- Transitions: --p runs from 0 to 1 on every .btr-ct__u ---- */
.btr-ct__u {
	--p: 0;
}

.btr-ct--fade .btr-ct__u,
.btr-ct--rise .btr-ct__u,
.btr-ct--drop .btr-ct__u,
.btr-ct--blur .btr-ct__u,
.btr-ct--zoom .btr-ct__u,
.btr-ct--flip .btr-ct__u,
.btr-ct--slant .btr-ct__u {
	opacity: calc(var(--btr-ct-o) + (1 - var(--btr-ct-o)) * var(--p));
}

.btr-ct--rise .btr-ct__u {
	transform: translate3d(0, calc((1 - var(--p)) * var(--btr-ct-dist)), 0);
}

.btr-ct--drop .btr-ct__u {
	transform: translate3d(0, calc((var(--p) - 1) * var(--btr-ct-dist)), 0);
}

.btr-ct--blur .btr-ct__u {
	filter: blur(calc((1 - var(--p)) * var(--btr-ct-blur)));
}

.btr-ct--zoom .btr-ct__u {
	transform: scale(calc(var(--btr-ct-scale) + (1 - var(--btr-ct-scale)) * var(--p)));
}

.btr-ct--flip .btr-ct__u {
	transform: perspective(700px) rotateX(calc((1 - var(--p)) * var(--btr-ct-rot) * -1));
	transform-origin: 50% 100%;
}

.btr-ct--slant .btr-ct__u {
	transform: translate3d(calc((var(--p) - 1) * var(--btr-ct-dist)), 0, 0) skewX(calc((1 - var(--p)) * -18deg));
	transform-origin: 0 100%;
}

.btr-ct--wipe .btr-ct__u {
	clip-path: inset(-.15em calc((1 - var(--p)) * 100%) -.15em 0);
}

/* Finished state when animation is skipped. */
.btr-ct.is-static .btr-ct__u {
	--p: 1;
}

@media (prefers-reduced-motion: reduce) {
	.btr-ct__strip {
		will-change: auto;
	}
}
