/* Rabin Craft — Craft Backdrop (includes/backdrops.php, includes/backdrop-tiles.php). Stands alone; no script.

   A section with a backdrop (.mkit-has-backdrop) is its own stacking context, so its pattern layer
   (.mkit-backdrop, z-index -1) sits above the section's background and below its content. The layer has up
   to three sublayers: a colour shown through a pattern mask (--_kNm, --_kNs, --_kNc), or a soft gradient
   (--_kNb). The whole layer has an opacity (--_ko) and a fade (--_kf).

   Colours (on the section or any ancestor): --mkit-backdrop-1 (default the Page colour accent),
   --mkit-backdrop-2, --mkit-backdrop-3.

   Motion (classes on the section): mkit-bd-scroll (moves as the section passes through the screen) or
   mkit-bd-drift (moves slowly on its own); a direction, mkit-bd-down, -left, -right or -diagonal (up
   without one); a speed, mkit-bd-slow or mkit-bd-quick. Only transform moves, so the pattern is drawn once
   and the graphics chip slides it: tiled patterns by whole tiles (--_tx, --_ty), so a loop never jumps;
   rings and aurora breathe; rays turn about their source (--_kt). Still for anyone who asks for less
   motion. */

.mkit-has-backdrop {
	position: relative;
	isolation: isolate;
}

/* The colours are named where the pattern's properties are set (the section, or the layer itself when it
   is placed by class), so the properties that use them resolve */
.mkit-has-backdrop,
.mkit-backdrop {
	/* Unless set, the main colour is the brand accent leaning towards the section's text colour, so it shows
	   on a dark section as well as a light one */
	--_kc1: var(--mkit-backdrop-1, color-mix(in srgb, var(--mkit-page-accent, var(--mkit-accent, #7c3aed)) 60%, currentColor));
	--_kc2: var(--mkit-backdrop-2, #06b6d4);
	--_kc3: var(--mkit-backdrop-3, #f59e0b);
}

.mkit-backdrop {
	position: absolute;
	inset: 0;
	z-index: -1;
	overflow: hidden;
	pointer-events: none;
	opacity: var(--_ko, .25);
	-webkit-mask-image: var(--_kf, none);
	mask-image: var(--_kf, none);
}

.mkit-backdrop > i {
	position: absolute;
	/* Larger than the section by the distance it moves (none when still); rays are twice the size (--_ki) */
	inset: calc(var(--_ki, 0px) - var(--_ty, 0px) * var(--_ny, 0)) calc(var(--_ki, 0px) - var(--_tx, 0px) * var(--_nx, 0));
	transform-origin: var(--_kt, 50% 50%);
	-webkit-mask-repeat: repeat;
	mask-repeat: repeat;
}

.mkit-backdrop > i:nth-child(1) {
	background: var(--_k1b, var(--_k1c, transparent));
	-webkit-mask-image: var(--_k1m, none);
	mask-image: var(--_k1m, none);
	-webkit-mask-size: var(--_k1s, auto);
	mask-size: var(--_k1s, auto);
	-webkit-mask-composite: var(--_k1w, source-over);
	mask-composite: var(--_k1x, add);
}

.mkit-backdrop > i:nth-child(2) {
	background: var(--_k2b, var(--_k2c, transparent));
	-webkit-mask-image: var(--_k2m, none);
	mask-image: var(--_k2m, none);
	-webkit-mask-size: var(--_k2s, auto);
	mask-size: var(--_k2s, auto);
	-webkit-mask-composite: var(--_k2w, source-over);
	mask-composite: var(--_k2x, add);
}

.mkit-backdrop > i:nth-child(3) {
	background: var(--_k3b, var(--_k3c, transparent));
	-webkit-mask-image: var(--_k3m, none);
	mask-image: var(--_k3m, none);
	-webkit-mask-size: var(--_k3s, auto);
	mask-size: var(--_k3s, auto);
	-webkit-mask-composite: var(--_k3w, source-over);
	mask-composite: var(--_k3x, add);
}

/* ---- Motion */

:is(.mkit-bd-scroll, .mkit-bd-drift) > .mkit-backdrop {
	--_mx: 0;
	--_my: -1;
	--_kd: var(--_tty, 20s);
}

.mkit-bd-down > .mkit-backdrop {
	--_mx: 0;
	--_my: 1;
}

.mkit-bd-left > .mkit-backdrop {
	--_mx: -1;
	--_my: 0;
	--_kd: var(--_ttx, 20s);
}

.mkit-bd-right > .mkit-backdrop {
	--_mx: 1;
	--_my: 0;
	--_kd: var(--_ttx, 20s);
}

.mkit-bd-diagonal > .mkit-backdrop {
	--_mx: 1;
	--_my: -1;
	--_kd: max(var(--_ttx, 3s), var(--_tty, 3s));
}

.mkit-bd-slow > .mkit-backdrop {
	--_sp: 1.7;
	--_sn: .5;
}

.mkit-bd-quick > .mkit-backdrop {
	--_sp: .55;
	--_sn: 2;
}

@keyframes mkit-bd-slide {
	to {
		transform: translate(calc(var(--_tx, 0px) * var(--_nx) * var(--_mx)), calc(var(--_ty, 0px) * var(--_ny) * var(--_my)));
	}
}

@keyframes mkit-bd-breathe {
	from {
		animation-timing-function: ease-in-out;
	}
	50% {
		transform: scale(1.12);
		animation-timing-function: ease-in-out;
	}
}

@keyframes mkit-bd-turn {
	from {
		animation-timing-function: ease-in-out;
	}
	50% {
		transform: rotate(calc(8deg * (var(--_mx) - var(--_my))));
		animation-timing-function: ease-in-out;
	}
}

/* Drift: one step per loop, so the end matches the start */
.mkit-bd-drift > .mkit-backdrop {
	--_nx: 1;
	--_ny: 1;
}

.mkit-bd-drift > .mkit-backdrop > i {
	animation-name: var(--_ka, none);
	animation-duration: calc(var(--_kd) * var(--_sp, 1));
	animation-timing-function: linear;
	animation-iteration-count: infinite;
}

/* The aurora's three fields breathe out of step */
.mkit-bd-drift > .mkit-backdrop > i:nth-child(2) {
	animation-delay: calc(var(--_kd) * var(--_sp, 1) * -.35);
}

.mkit-bd-drift > .mkit-backdrop > i:nth-child(3) {
	animation-delay: calc(var(--_kd) * var(--_sp, 1) * -.7);
}

/* Scroll: about 120px over the section's pass through the screen; nothing runs while the page is still.
   Where the browser has no scroll timelines, the pattern simply stays put. */
@supports (animation-timeline: view()) {
	.mkit-bd-scroll {
		view-timeline: --mkit-bd block;
	}

	.mkit-bd-scroll > .mkit-backdrop {
		--_nx: calc(var(--_tnx, 1) * var(--_sn, 1));
		--_ny: calc(var(--_tny, 1) * var(--_sn, 1));
	}

	.mkit-bd-scroll > .mkit-backdrop > i {
		animation-name: var(--_ka, none);
		animation-duration: auto;
		animation-timing-function: linear;
		animation-fill-mode: both;
		animation-timeline: --mkit-bd;
	}
}

@media (prefers-reduced-motion: reduce) {
	.mkit-backdrop > i {
		animation: none !important;
	}
}

/* Decoration only: gone in forced colours and in print */
@media (forced-colors: active), print {
	.mkit-backdrop {
		display: none;
	}
}
