/*
 * Item 39 — Texto animado. texto.js divide o texto em .ar-txt-p (letras, palavras ou linhas) e dá a
 * cada parte --i; a animação de cada preset começa em atraso + i × passo.
 * Ao aparecer: as animações ficam pausadas até .ar-txt-ativo. Na rolagem: o atraso negativo
 * (calculado com --ar-txt-prog) põe cada parte no ponto certo.
 */

.ar-texto-yes {
	--ar-txt-dur: 700ms;
	--ar-txt-passo: 35ms;
	--ar-txt-atraso: 0ms;
	--ar-txt-curva: cubic-bezier(0.22, 1, 0.36, 1);
	--ar-txt-base: rgba(127, 127, 127, 0.25);
}

.ar-txt-palavra,
.ar-txt-p {
	display: inline-block;
}

.ar-txt-palavra {
	white-space: nowrap;
}

/* Máscara: a parte surge de baixo da linha; a folga evita cortar acentos e descendentes. */
.ar-txt-mascara {
	overflow: hidden;
	padding-block: 0.12em;
	margin-block: -0.12em;
	vertical-align: top;
}

.ar-texto-yes .ar-txt-p {
	animation-duration: var(--ar-txt-dur);
	animation-timing-function: var(--ar-txt-curva);
	animation-fill-mode: both;
	animation-delay: calc(var(--ar-txt-atraso) + var(--i, 0) * var(--ar-txt-passo));
	animation-play-state: paused;
}

/* No Editor de texto com Optimized Markup, o alvo (.ar-txt-ativo) é o próprio widget. */
.ar-txt-gatilho-aparecer .ar-txt-ativo .ar-txt-p,
.ar-txt-gatilho-aparecer.ar-txt-ativo .ar-txt-p {
	animation-play-state: running;
}

.ar-txt-gatilho-rolar .ar-txt-p {
	animation-delay: calc(var(--ar-txt-atraso) + var(--i, 0) * var(--ar-txt-passo) - var(--ar-txt-prog, 0) * var(--ar-txt-total, 1000ms));
}

/* Antes de repetir: some sem animação, para recomeçar do zero ao voltar. */
.ar-txt-reinicio .ar-txt-p {
	animation: none !important;
	opacity: 0;
}

.ar-txt-escrever .ar-txt-p { animation-name: ar-txt-escrever; animation-timing-function: linear; }
.ar-txt-foco .ar-txt-p { animation-name: ar-txt-foco; }
.ar-txt-salto .ar-txt-p { animation-name: ar-txt-salto; }
.ar-txt-girar .ar-txt-p { animation-name: ar-txt-girar; transform-origin: 50% 100%; }
.ar-txt-centro .ar-txt-p { animation-name: ar-txt-centro; }
.ar-txt-por-baixo .ar-txt-p,
.ar-txt-cortina .ar-txt-p { animation-name: ar-txt-subir; }
.ar-txt-palavras .ar-txt-p { animation-name: ar-txt-palavras; }
.ar-txt-lateral .ar-txt-p { animation-name: ar-txt-lateral; }

@keyframes ar-txt-escrever {
	0% { opacity: 0; }
	1%, 100% { opacity: 1; }
}

@keyframes ar-txt-foco {
	from { opacity: 0; filter: blur(12px); }
	to { opacity: 1; filter: blur(0); }
}

@keyframes ar-txt-salto {
	0% { opacity: 0; transform: translateY(0.6em) scale(0.9); }
	60% { opacity: 1; transform: translateY(-0.14em) scale(1.02); }
	100% { opacity: 1; transform: none; }
}

@keyframes ar-txt-girar {
	from { opacity: 0; transform: perspective(500px) rotateX(-90deg); }
	to { opacity: 1; transform: none; }
}

@keyframes ar-txt-centro {
	from { opacity: 0; transform: scale(0.4); }
	to { opacity: 1; transform: none; }
}

@keyframes ar-txt-subir {
	from { transform: translateY(115%); }
	to { transform: none; }
}

@keyframes ar-txt-palavras {
	from { opacity: 0; transform: translateY(0.45em); filter: blur(5px); }
	to { opacity: 1; transform: none; filter: blur(0); }
}

@keyframes ar-txt-lateral {
	from { opacity: 0; transform: translateX(-0.9em); }
	to { opacity: 1; transform: none; }
}

/* Embaralhar: o texto.js troca as letras; aqui só a largura fixa de cada letra e o "apagado". */
.ar-txt-embaralhar .ar-txt-p {
	animation: none;
	text-align: center;
}

.ar-txt-embaralhar .ar-txt-p.ar-txt-espera {
	opacity: 0.35;
}

/* Preencher: o texto inteiro ganha a cor da esquerda para a direita. */
.ar-txt-preencher .ar-txt-alvo,
.ar-txt-preencher.ar-txt-alvo {
	background: linear-gradient(90deg, currentColor 50%, var(--ar-txt-base) 50%) 100% 0 / 200% 100% no-repeat;
	-webkit-background-clip: text;
	background-clip: text;
	-webkit-text-fill-color: transparent;
	animation: ar-txt-preencher calc(var(--ar-txt-dur) * 2) var(--ar-txt-curva) var(--ar-txt-atraso) both paused;
}

.ar-txt-preencher .ar-txt-alvo *,
.ar-txt-preencher.ar-txt-alvo * {
	-webkit-text-fill-color: transparent;
}

.ar-txt-gatilho-aparecer.ar-txt-preencher .ar-txt-alvo.ar-txt-ativo,
.ar-txt-gatilho-aparecer.ar-txt-preencher.ar-txt-alvo.ar-txt-ativo {
	animation-play-state: running;
}

.ar-txt-gatilho-rolar.ar-txt-preencher .ar-txt-alvo,
.ar-txt-gatilho-rolar.ar-txt-preencher.ar-txt-alvo {
	animation-delay: calc(var(--ar-txt-prog, 0) * var(--ar-txt-dur) * -2);
}

@keyframes ar-txt-preencher {
	from { background-position: 100% 0; }
	to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
	.ar-texto-yes .ar-txt-p,
	.ar-txt-preencher .ar-txt-alvo,
	.ar-txt-preencher.ar-txt-alvo {
		animation: none !important;
		opacity: 1 !important;
		transform: none !important;
		filter: none !important;
	}
}
