/*
 * A language's flag stirs while its link is hovered or keyboard-focused:
 * a faint breeze, not a gesture.
 *
 * The cloth is seven strips, each nested in and hinged on the one before
 * (--i is the depth, 0 at the hoist). A strip only shears about its hinge,
 * so the surface stays unbroken, the hoist stays put and the fly moves most.
 *
 * Two numbers drive it. --vt-flag-wave is a slow sine, offset strip by strip
 * so the ripple travels from hoist to fly; it is paused at rest. --vt-fly is
 * the amplitude, eased from 0 to 1 and back, so the wave fades in and out
 * and never restarts or snaps. The same number grows a 5px stub of pole
 * under the hoist corner. Transforms only. Front end only, on every page.
 */
@property --vt-fly {
	syntax: "<number>";
	inherits: true;
	initial-value: 0;
}

@property --vt-flag-wave {
	syntax: "<number>";
	inherits: false;
	initial-value: 0;
}

@layer components {

	/* Nothing at rest, and nothing at all unless --vt-fly is raised below. */
	.vt-flag__pole {
		stroke: var(--ink);
		stroke-opacity: 0.6;
		transform-origin: 0.5px 13px;
		scale: 1 var(--vt-fly, 0);
	}

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

		.vt-flag {
			transition: --vt-fly 700ms ease-out;
		}

		.vt-flag__seg {
			transform-origin: calc(var(--i) * 3px) 6.5px;
			transform: skewY(calc(var(--vt-fly) * var(--vt-flag-wave) * (0.9deg + var(--i) * 1deg)));
			animation: vt-flag-wave 2.8s calc(var(--i) * -0.4s) infinite paused;
		}

		@media (hover: hover) and (pointer: fine) {

			.vt-footer__lang:hover .vt-flag {
				--vt-fly: 1;
				transition: --vt-fly 600ms ease-in-out;
			}

			.vt-footer__lang:hover .vt-flag__seg {
				animation-play-state: running;
			}
		}

		.vt-footer__lang:focus-visible .vt-flag {
			--vt-fly: 1;
			transition: --vt-fly 600ms ease-in-out;
		}

		.vt-footer__lang:focus-visible .vt-flag__seg {
			animation-play-state: running;
		}

		/* One sine, in four quarters. */
		@keyframes vt-flag-wave {

			0% {
				--vt-flag-wave: 0;
				animation-timing-function: cubic-bezier(0.61, 1, 0.88, 1);
			}

			25% {
				--vt-flag-wave: 1;
				animation-timing-function: cubic-bezier(0.12, 0, 0.39, 0);
			}

			50% {
				--vt-flag-wave: 0;
				animation-timing-function: cubic-bezier(0.61, 1, 0.88, 1);
			}

			75% {
				--vt-flag-wave: -1;
				animation-timing-function: cubic-bezier(0.12, 0, 0.39, 0);
			}

			100% {
				--vt-flag-wave: 0;
			}
		}
	}
}
