/* ==========================================================================
   Komprende · Efectos
   Se activan poniendo una clase en el bloque (className), sin tocar ficheros:
     kp-stack   Los hijos directos se apilan al hacer scroll: cada uno entra por
                encima del anterior y el que ya estaba se queda atrás (se reduce
                y se oscurece).
   Ajustes (sobrescribibles desde estilos globales o en el propio bloque):
     --kp-stack-escala   Cuánto se reduce el de atrás (0.06 = 6 %).
     --kp-stack-sombra   Cuánto se oscurece (0.18 = 18 %).
     --kp-stack-asoma    Cuánto asoma el borde del de atrás (px).
   Respeta "reducir movimiento": sin animación y sin apilado.
   ========================================================================== */

.kp-stack {
	--kp-stack-escala: 0.06;
	--kp-stack-sombra: 0.18;
	--kp-stack-asoma: 0px;
	position: relative;
	isolation: isolate;
}
.kp-stack > * {
	position: sticky;
	top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--kp-stack-top, 0px));
	margin-block-start: 0 !important;
	transform-origin: 50% 0;
	will-change: transform;
	/* --kp-stack-p (0 → 1) lo calcula el JS según lo cubierto por el siguiente */
	transform: translateY(calc(var(--kp-stack-p, 0) * var(--kp-stack-asoma) * -1)) scale(calc(1 - var(--kp-stack-p, 0) * var(--kp-stack-escala)));
}
/* Velo que oscurece la tarjeta de atrás sin tocar sus colores */
.kp-stack > *::after {
	content: "";
	position: absolute;
	inset: 0;
	background: #232323;
	opacity: calc(var(--kp-stack-p, 0) * var(--kp-stack-sombra));
	pointer-events: none;
}
/* La que entra proyecta una sombra suave sobre la de atrás */
.kp-stack > * + * { box-shadow: 0 -24px 48px -24px rgba(35, 35, 35, 0.18); }

/* En el editor se ve plano para poder editar cómodamente */
.editor-styles-wrapper .kp-stack > *,
.block-editor-block-list__layout .kp-stack > * { position: relative; top: auto; transform: none; }
.editor-styles-wrapper .kp-stack > *::after { content: none; }

@media (prefers-reduced-motion: reduce) {
	.kp-stack > * { position: relative; top: auto; transform: none; box-shadow: none; }
	.kp-stack > *::after { content: none; }
}

/* === Aparición: fade-in de cada sección al entrar en pantalla (excepto el hero) ===
   En todas las vistas: páginas (secciones dentro del contenido) y plantillas (artículo, legales,
   categoría, 404, búsqueda: secciones directamente en <main>).
   Solo CSS (scroll-driven). Navegadores sin soporte: se ven sin animación.
   Para excluir un bloque: clase «kp-sin-animacion» en Avanzado → Clases CSS adicionales. */
@keyframes kp-aparece { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		:is(main.kp-main > .wp-block-post-content, main.kp-main) > :not(:first-child):not(.wp-block-post-content):not(.kp-sin-animacion) {
			animation: kp-aparece linear both;
			animation-timeline: view();
			animation-range: entry 0px entry 360px;
		}
	}
}

/* === Listas: los elementos entran escalonados y su línea se dibuja de izquierda a derecha ===
   Scroll-driven: cada fila se anima cuando ella misma entra en pantalla, así el escalonado
   sale solo. La línea (antes un borde) se pinta con un fondo de 1 px que crece de 0 a 100 %.
   Para excluir una lista: clase «kp-sin-animacion» en su sección. Dentro de un kp-stack no se aplica
   (al quedarse fija la tarjeta, la animación se congelaría a medias). */
@keyframes kp-entra { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes kp-traza { from { background-size: 0% 1px; } to { background-size: 100% 1px; } }
@media (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		:where(main.kp-main) :is(
			.kp-items > .kp-item, .kp-metodo__lista > li, .kp-area, .kp-pasos__lista > .kp-paso,
			.kp-que-hacemos-principio, .kp-que-hacemos-faq__item, .kp-casos-de-uso-detalle__bloque + .kp-casos-de-uso-detalle__bloque,
			.kp-ayudas-item, .kp-ayudas-fila, .kp-ayudas-paso
		):not(.kp-sin-animacion *):not(.kp-stack *) {
			--kp-trazo-color: rgba(35, 35, 35, 0.15);
			--kp-trazo-pos: left bottom;
			background-image: linear-gradient(var(--kp-trazo-color), var(--kp-trazo-color));
			background-repeat: no-repeat;
			background-position: var(--kp-trazo-pos);
			background-origin: border-box;
			animation: kp-entra linear both, kp-traza linear both;
			animation-timeline: view(), view();
			animation-range: entry 0% cover 30%, entry 60% cover 45%;
		}
		/* Línea abajo */
		:where(main.kp-main) :is(.kp-items > .kp-item, .kp-metodo__lista > li, .kp-area, .kp-que-hacemos-principio,
			.kp-que-hacemos-faq__item, .kp-ayudas-item, .kp-ayudas-fila):not(.kp-sin-animacion *):not(.kp-stack *) { border-bottom-color: transparent; }
		/* Línea arriba */
		:where(main.kp-main) :is(.kp-pasos__lista > .kp-paso, .kp-ayudas-paso,
			.kp-casos-de-uso-detalle__bloque + .kp-casos-de-uso-detalle__bloque):not(.kp-sin-animacion *):not(.kp-stack *) {
			--kp-trazo-pos: left top;
			border-top-color: transparent;
		}
		:where(main.kp-main) .kp-casos-de-uso-detalle__bloque + .kp-casos-de-uso-detalle__bloque:not(.kp-sin-animacion *):not(.kp-stack *) { --kp-trazo-color: rgba(35, 35, 35, 0.12); }
		/* Móvil: «La IA, hoy» y «Por áreas» llevan la línea arriba */
		@media (max-width: 781px) {
			:where(main.kp-main) :is(.kp-items > .kp-item, .kp-area):not(.kp-sin-animacion *):not(.kp-stack *) {
				--kp-trazo-color: rgba(35, 35, 35, 0.12);
				--kp-trazo-pos: left top;
				border-top-color: transparent;
			}
		}
	}
}

/* === Foto a sangre: paralaje suave ===
   La imagen se amplía un 15 % y se desplaza más despacio que el scroll dentro de su marco. */
@keyframes kp-paralaje {
	from { transform: scale(1.15) translateY(-6%); }
	to   { transform: scale(1.15) translateY(6%); }
}
@media (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		.kp-foto-sangre:not(.kp-sin-animacion) { overflow: clip; }
		.kp-foto-sangre:not(.kp-sin-animacion) img {
			will-change: transform;
			animation: kp-paralaje linear both;
			animation-timeline: view();
			animation-range: cover 0% cover 100%;
		}
	}
}

/* === «Por qué Komprende»: tarjetas ===
   Entrada escalonada (fila de arriba antes; dentro de cada fila, la segunda algo después)
   y hover sutil: la tarjeta sube 6 px con sombra suave y el icono crece un 8 %.
   La entrada usa «translate» y el hover «transform», así no se pisan. */
@keyframes kp-tarjeta-entra { from { opacity: 0; translate: 0 24px; } to { opacity: 1; translate: 0 0; } }
@media (min-width: 782px) and (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		.kp-tarjetas:not(.kp-sin-animacion) > .kp-tarjeta {
			animation: kp-tarjeta-entra linear both;
			animation-timeline: view();
			animation-range: cover 0px cover 400px;
		}
		.kp-tarjetas:not(.kp-sin-animacion) > .kp-tarjeta:nth-child(even) { animation-range: cover 180px cover 560px; }
	}
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
	.kp-tarjetas > .kp-tarjeta {
		transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
	}
	.kp-tarjetas > .kp-tarjeta .kp-tarjeta__icono img {
		transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
		transform-origin: left top;
	}
	.kp-tarjetas > .kp-tarjeta:hover {
		transform: translateY(-6px);
		box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.55);
	}
	.kp-tarjetas > .kp-tarjeta:hover .kp-tarjeta__icono img { transform: scale(1.08); }
}

/* === Banda «Ayudas y subvenciones»: paralaje del fondo ===
   Los degradados pasan a una capa (::before) un 80 % más alta que la sección, que se
   desplaza más despacio que el scroll. Posiciones recalculadas para que, a mitad de
   recorrido, la luz quede exactamente donde estaba (95 % → 75 %, 5 % → 25 % de la capa). */
@keyframes kp-paralaje-fondo { from { transform: translateY(-15%); } to { transform: translateY(15%); } }
@media (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		.kp-banda-ayudas.kp-banda-ayudas:not(.kp-sin-animacion) {
			position: relative;
			overflow: clip;
			isolation: isolate;
			background: var(--kp-tinta) !important;
		}
		.kp-banda-ayudas:not(.kp-sin-animacion)::before {
			content: "";
			position: absolute;
			left: 0;
			right: 0;
			top: -40%;
			height: 180%;
			z-index: -1;
			pointer-events: none;
			background:
				radial-gradient(648px 648px at 10% 75%, rgba(191, 140, 76, 1) 0%, rgba(191, 140, 76, 0.55) 45%, rgba(191, 140, 76, 0) 100%),
				radial-gradient(864px 864px at 95% 25%, rgba(35, 35, 35, 0.9) 0%, rgba(35, 35, 35, 0.5) 45%, rgba(35, 35, 35, 0) 100%);
			will-change: transform;
			animation: kp-paralaje-fondo linear both;
			animation-timeline: view();
			animation-range: cover 0% cover 100%;
		}
		@media (max-width: 899px) {
			.kp-banda-ayudas:not(.kp-sin-animacion)::before {
				background: radial-gradient(420px 420px at 0% 77.8%, rgba(191, 140, 76, 0.9) 0%, rgba(191, 140, 76, 0.45) 45%, rgba(191, 140, 76, 0) 100%);
			}
		}
	}
}

/* === Banda «Komprende Subvenciones» (Ayudas y Diagnóstico): paralaje de la foto ===
   La fotografía sube algo más rápido que el scroll y se desliza sobre el fondo de la banda.
   Centrada en su posición de diseño cuando la banda está a media pantalla (±60 px).
   Solo escritorio: en móvil la foto va en el flujo, debajo del texto. Usa «translate», no «transform». */
@keyframes kp-paralaje-foto { from { translate: 0 60px; } to { translate: 0 -60px; } }
@media (min-width: 900px) and (prefers-reduced-motion: no-preference) {
	@supports (animation-timeline: view()) {
		.kp-ayudas-banda:not(.kp-sin-animacion) .kp-ayudas-banda__imagen {
			will-change: translate;
			animation: kp-paralaje-foto linear both;
			animation-timeline: view();
			animation-range: cover 0% cover 100%;
		}
	}
}
