/*
 * Motion: gentle entrance animations while scrolling, plus a few hover
 * touches. Turned off under Appearance → Customize → Compleet Trouwen →
 * Animations, and never loaded in the Elementor editor.
 *
 * How it works:
 * - A small script in <head> (ctdc_print_motion_flag() in inc/assets.php)
 *   adds `ct-motion` to <html>, but only for visitors who have not asked for
 *   reduced motion. Every rule that hides content is scoped to that class and
 *   to screens. So content always shows without JavaScript, with reduced
 *   motion, and when printing.
 * - The hero and page-title copy rises in on load, with CSS alone.
 * - Everything else waits off-screen. Each rule that sets a waiting state
 *   also sets `--ct-reveal: 1`. assets/js/motion.js watches every element
 *   with that marker and adds `is-inview` once it scrolls into view. Elements
 *   that arrive together get `--ct-i` (0, 1, 2…), which staggers them.
 *   A new reveal therefore only needs CSS, as long as the element is an
 *   Elementor element or has a `ct-` class.
 */

/* A marker on the element itself; descendants must not inherit it. */
@property --ct-reveal {
	syntax: "<integer>";
	inherits: false;
	initial-value: 0;
}

:root {
	--ct-ease: cubic-bezier(0.22, 1, 0.36, 1);
	--ct-motion-duration: 1s;
	--ct-rise: 28px;
	--ct-stagger: 0.11s;
}

@media screen and (prefers-reduced-motion: no-preference) {

	/* =========================================================================
	   1. On load: hero and page-title copy
	   ========================================================================= */

	.ct-motion .ct-hero-copy > .elementor-element,
	.ct-motion .ct-page-header > .ct-wrap > * {
		animation: ct-rise 1.1s var(--ct-ease) backwards;
	}

	.ct-motion .ct-hero-copy > :nth-child(2),
	.ct-motion .ct-page-header > .ct-wrap > :nth-child(2) {
		animation-delay: 0.15s;
	}

	.ct-motion .ct-hero-copy > :nth-child(3),
	.ct-motion .ct-page-header > .ct-wrap > :nth-child(3) {
		animation-delay: 0.3s;
	}

	.ct-motion .ct-hero-copy > :nth-child(n + 4),
	.ct-motion .ct-page-header > .ct-wrap > :nth-child(n + 4) {
		animation-delay: 0.45s;
	}

	/* 404 page: copy rises in, the rings float and the sparkle twinkles. */
	.ct-motion .ct-404-inner > * {
		animation: ct-rise 1.1s var(--ct-ease) backwards;
	}

	.ct-motion .ct-404-inner > :nth-child(2) {
		animation-delay: 0.15s;
	}

	.ct-motion .ct-404-inner > :nth-child(3) {
		animation-delay: 0.25s;
	}

	.ct-motion .ct-404-inner > :nth-child(n + 4) {
		animation-delay: 0.4s;
	}

	.ct-motion .ct-404-rings {
		animation: ct-404-float 5s ease-in-out 1.2s infinite;
	}

	.ct-motion .ct-404-sparkle {
		animation: ct-404-twinkle 2.6s ease-in-out infinite;
	}

	@keyframes ct-404-float {
		0%,
		100% {
			transform: translateY(0) rotate(0deg);
		}

		50% {
			transform: translateY(-8px) rotate(-4deg);
		}
	}

	@keyframes ct-404-twinkle {
		0%,
		100% {
			opacity: 0.25;
			transform: scale(0.6) rotate(0deg);
		}

		50% {
			opacity: 1;
			transform: scale(1.15) rotate(45deg);
		}
	}

	/* =========================================================================
	   2. On scroll: blocks fade up
	   ========================================================================= */

	.ct-motion .ct-site :is(
		.ct-strip,
		.ct-intro > .e-con > .elementor-element,
		.ct-intro > .elementor-widget,
		.ct-review-head > .elementor-element,
		.ct-wrap > .elementor-widget,
		.ct-grid > .elementor-element,
		.ct-grid > .ct-post-card,
		.ct-split > .e-con,
		.ct-split > .elementor-widget:not(.elementor-widget-image),
		.ct-note,
		.ct-center,
		.ct-faq > .e-con > .elementor-element,
		.ct-contact > .e-con,
		.ct-map,
		.ct-reviews > .elementor-element,
		.ct-end > .elementor-element,
		.ct-section--tight > .ct-prose
	):not(.is-inview, .elementor-invisible, .animated),
	.ct-motion #bwp-footer :is(
		:is(.footer-top, .footer-center) > .elementor-container > .elementor-column,
		.ct-footer-fallback
	):not(.is-inview) {
		--ct-reveal: 1;
		opacity: 0;
		transform: translate3d(0, var(--ct-rise), 0);
	}

	/* The keyword strip sits between two rules: fade it without moving it. */
	.ct-site .ct-strip {
		--ct-rise: 0px;
	}

	#bwp-footer {
		--ct-rise: 16px;
	}

	/* =========================================================================
	   3. Photos open up from a slightly smaller frame while settling from a zoom
	   ========================================================================= */

	.ct-motion .ct-site .ct-split > .elementor-widget-image:not(.is-inview) {
		--ct-reveal: 1;
		opacity: 0;
	}

	/* Photos in service cards follow their card. */
	.ct-motion .ct-site :is(.ct-split > .elementor-widget-image.is-inview, .ct-service.is-inview .elementor-widget-image) {
		animation: ct-unveil 1.5s var(--ct-ease) var(--ct-delay, 0s) backwards;
	}

	.ct-motion .ct-site :is(.ct-split > .elementor-widget-image.is-inview, .ct-service.is-inview .elementor-widget-image) img {
		animation: ct-settle 1.5s var(--ct-ease) var(--ct-delay, 0s) backwards;
	}

	/* =========================================================================
	   4. The rule above cards, steps, reviews and notes draws in from the left
	   ========================================================================= */

	.ct-motion .ct-site :is(.ct-step, .ct-card, .ct-review:not(.ct-review--invite), .ct-note) {
		border-top-color: transparent;
		background-image: linear-gradient(var(--ct-rule), var(--ct-rule));
		background-repeat: no-repeat;
		background-origin: border-box;
		background-position: 0 0;
		background-size: 100% 1px;
	}

	.ct-motion .ct-site .ct-step {
		--ct-rule: var(--ct-step-line);
	}

	.ct-motion .ct-site :is(.ct-card, .ct-review, .ct-note) {
		--ct-rule: var(--ct-line);
	}

	.ct-motion .ct-site :is(.ct-step, .ct-card, .ct-review:not(.ct-review--invite), .ct-note):not(.is-inview) {
		--ct-reveal: 1;
		background-size: 0% 1px;
	}

	/* =========================================================================
	   5. The handwritten signature writes itself, left to right
	   ========================================================================= */

	.ct-motion .ct-site .ct-signature:not(.is-inview) {
		--ct-reveal: 1;
		clip-path: inset(0 100% 0 0);
	}

	.ct-motion .ct-site .ct-signature.is-inview {
		animation: ct-write 2.6s linear calc(var(--ct-delay, 0s) + 0.35s) backwards;
	}

	/* =========================================================================
	   6. FAQ questions and price-list rows follow one another
	   ========================================================================= */

	.ct-motion .ct-site :is(.ct-faq-list, .ct-price-list):not(.is-inview) {
		--ct-reveal: 1;
	}

	.ct-motion .ct-site .ct-faq-list:not(.is-inview) .e-n-accordion-item,
	.ct-motion .ct-site .ct-price-list:not(.is-inview) li {
		opacity: 0;
		transform: translate3d(0, 14px, 0);
	}

	.ct-motion .ct-site .ct-faq-list.is-inview .e-n-accordion-item,
	.ct-motion .ct-site .ct-price-list.is-inview li {
		transition: opacity 0.8s var(--ct-ease), transform 0.8s var(--ct-ease);
		transition-delay: calc(var(--ct-delay, 0s) + var(--ct-n, 0) * 0.07s);
	}

	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(2) { --ct-n: 1; }
	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(3) { --ct-n: 2; }
	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(4) { --ct-n: 3; }
	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(5) { --ct-n: 4; }
	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(6) { --ct-n: 5; }
	.ct-site :is(.ct-faq-list .e-n-accordion-item, .ct-price-list li):nth-child(n + 7) { --ct-n: 6; }

	/* An opened FAQ answer fades in. */
	.ct-motion .ct-site .ct-faq-list .e-n-accordion-item[open] > :is(.e-con, [role="region"]) {
		animation: ct-fade-in 0.6s var(--ct-ease) backwards;
	}

	/* =========================================================================
	   7. Revealed: ease in, staggered with the elements that arrived together
	   ========================================================================= */

	.ct-motion :is(.ct-site, #bwp-footer) .is-inview {
		--ct-delay: calc(var(--ct-i, 0) * var(--ct-stagger));
		transition:
			opacity var(--ct-motion-duration) var(--ct-ease) var(--ct-delay),
			transform var(--ct-motion-duration) var(--ct-ease) var(--ct-delay),
			background-size 1.6s var(--ct-ease) var(--ct-delay);
	}

	/* =========================================================================
	   8. Hover and focus
	   ========================================================================= */

	/* The → arrow nudges along its own direction. */
	.ct-site .elementor-widget-button.ct-arrow .elementor-button-text::after {
		transition: transform 0.35s var(--ct-ease);
	}

	.ct-site .elementor-widget-button.ct-arrow .elementor-button:focus-visible .elementor-button-text::after {
		transform: translate3d(4px, 0, 0);
	}

	/*
	 * Service-card photo: a slow zoom that stays inside its frame. Scaling by
	 * 1.05 while clipping 2.381% (0.05 / 2.1) off each side keeps the visible
	 * frame exactly the same size. At rest the clip lies just outside the
	 * photo, so it changes nothing until the zoom starts.
	 */
	.ct-site .ct-service .elementor-widget-image img {
		clip-path: inset(-1px round 5px);
		transition: transform 0.9s var(--ct-ease), clip-path 0.9s var(--ct-ease);
	}

	.ct-site .ct-service:focus-within .elementor-widget-image img {
		transform: scale(1.05);
		clip-path: inset(2.381% round 3.81px);
	}

	@media (hover: hover) {
		.ct-site .elementor-widget-button.ct-arrow .elementor-button:hover .elementor-button-text::after {
			transform: translate3d(4px, 0, 0);
		}

		.ct-site .ct-service:hover .elementor-widget-image img {
			transform: scale(1.05);
			clip-path: inset(2.381% round 3.81px);
		}
	}
}

/* =========================================================================
   Keyframes
   ========================================================================= */

@keyframes ct-rise {
	from {
		opacity: 0;
		transform: translate3d(0, var(--ct-rise), 0);
	}
}

@keyframes ct-fade-in {
	from {
		opacity: 0;
		transform: translate3d(0, -6px, 0);
	}
}

@keyframes ct-unveil {
	from {
		clip-path: inset(7%);
	}

	to {
		clip-path: inset(0);
	}
}

@keyframes ct-settle {
	from {
		scale: 1.12;
	}

	to {
		scale: 1;
	}
}

/*
 * The visible strip grows to 620px at a steady pace, wider than any
 * signature, so the pen speed is the same at every screen width. Overflow
 * room above, below and to the left leaves the script's swashes intact.
 */
@keyframes ct-write {
	from {
		clip-path: inset(-30% 100% -30% -6%);
	}

	to {
		clip-path: inset(-30% calc(100% - 620px) -30% -6%);
	}
}
