/*
 * Motion layer (CLAUDE.md §6b, Figma "V2 / Motion Spec").
 * "Quiet motion: paper, ink and curtains." Transform and opacity only (plus the
 * spec's clip-path wipe on the lattice). Everything here is gated on html.kb-motion,
 * which the head script sets only with JS on and no reduced-motion preference,
 * so the site is complete and static without it.
 */

:root { --ease-ink: cubic-bezier(.2, .8, .2, 1); }

/* 1. Loader: cream paper, the hanko presses down, the paper lifts ---------------- */
.kb-loader { display: none; }
html.kb-loading .kb-loader {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: grid;
	place-items: center;
	background: var(--cream);
	animation: kb-loader-out 300ms ease-out 580ms forwards; /* 380 press + 200 hold */
	pointer-events: none;
}
html.kb-loading .kb-loader .kb-hanko {
	--hanko-size: 120px;
	animation: kb-press 380ms var(--ease-ink) both;
}
@keyframes kb-press {
	from { opacity: 0; transform: rotate(calc(var(--hanko-tilt) - 7deg)) scale(1.12); }
	to   { opacity: 1; transform: rotate(var(--hanko-tilt)) scale(1); }
}
@keyframes kb-loader-out { to { opacity: 0; visibility: hidden; } }

/* 2. Homepage hero entrance --------------------------------------------------------- */
html.kb-motion { --kb-entrance-delay: 0ms; }
html.kb-motion.kb-loading { --kb-entrance-delay: 580ms; } /* start as the paper lifts */
@media (min-width: 768px) {
	html.kb-motion .kb-hero__panel {
		animation: kb-drop 600ms ease-out both;
		animation-delay: var(--kb-entrance-delay);
	}
	html.kb-motion .kb-hero__panel--r { animation-delay: calc(var(--kb-entrance-delay) + 80ms); }
	html.kb-motion .kb-hero__crest {
		animation: kb-crest 300ms var(--ease-ink) both;
		animation-delay: calc(var(--kb-entrance-delay) + 680ms + 300ms); /* panels land, then 300ms */
	}
}
html.kb-motion :is(.kb-hero__eyebrow, .kb-hero__headline, .kb-hero__statement, .kb-hero__tagline) {
	animation: kb-rise 500ms var(--ease-ink) both;
	animation-delay: calc(var(--kb-entrance-delay) + 200ms);
}
html.kb-motion .kb-hero__headline { animation-delay: calc(var(--kb-entrance-delay) + 260ms); }
html.kb-motion .kb-hero__statement { animation-delay: calc(var(--kb-entrance-delay) + 320ms); }
html.kb-motion .kb-hero__tagline { animation-delay: calc(var(--kb-entrance-delay) + 380ms); }
@keyframes kb-drop { from { opacity: 0; transform: translateY(-12px); } }
@keyframes kb-crest { from { opacity: 0; scale: .8; } } /* `scale` composes with the crest's translateX */
@keyframes kb-rise { from { opacity: 0; transform: translateY(8px); } }

/* 3. Scroll reveals ------------------------------------------------------------------ */
html.kb-motion .kb-reveal {
	opacity: 0;
	transform: translateY(12px);
	transition: opacity 500ms var(--ease-ink), transform 500ms var(--ease-ink);
	transition-delay: var(--kb-stagger, 0ms);
}
html.kb-motion .kb-reveal.is-in { opacity: 1; transform: none; }
/* Lattice: bars draw in left to right. A cream cover slides off to the right (transform only);
   a clip-path start state would leave zero visible area, so IntersectionObserver never fires. */
html.kb-motion .kb-lattice.kb-reveal { position: relative; opacity: 1; transform: none; }
html.kb-motion .kb-lattice.kb-reveal::after {
	content: "";
	position: absolute;
	inset: 0;
	background: var(--cream);
	transform-origin: right;
	transition: transform 700ms var(--ease-ink);
}
html.kb-motion .kb-lattice.kb-reveal.is-in::after { transform: scaleX(0); }

/* 4. Custom cursor (pointer: fine only; set up by motion.js) ------------------------- */
.kb-cursor { display: none; }
html.kb-cursor-on .kb-cursor {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 2000;
	display: block;
	pointer-events: none;
	color: var(--persimmon);
	transition: opacity 150ms ease-out;
}
html.kb-cursor-on .kb-cursor.is-hidden { opacity: 0; }
html.kb-cursor-on .kb-cursor.is-dark { color: var(--persimmon-light); }
.kb-cursor__dot,
.kb-cursor__ring {
	position: absolute;
	top: 0;
	left: 0;
	border-radius: 50%;
	translate: -50% -50%;
}
.kb-cursor__dot { width: 8px; height: 8px; background: currentColor; transition: width 180ms ease-out, height 180ms ease-out; }
.kb-cursor__ring {
	width: 32px;
	height: 32px;
	border: 1.5px solid currentColor;
	opacity: 0;
	scale: .25;
	transition: opacity 180ms ease-out, scale 180ms ease-out, background-color 120ms ease-out;
}
.kb-cursor.is-link .kb-cursor__dot { width: 4px; height: 4px; }
.kb-cursor.is-link .kb-cursor__ring { opacity: 1; scale: 1; }
.kb-cursor.is-down .kb-cursor__ring { scale: .75; background: color-mix(in srgb, currentColor 12%, transparent); }
/* Hide the system cursor while ours is active, except where the native one is needed. */
html.kb-cursor-on,
html.kb-cursor-on * { cursor: none !important; }
html.kb-cursor-on :is(input, textarea, select, [contenteditable="true"], iframe) { cursor: auto !important; }

/* 5. Hover upgrades ------------------------------------------------------------------ */
@media (hover: hover) and (min-width: 768px) {
	/* Service rows and link tiles: cream-deep slides in from the left, title shifts, numeral turns indigo */
	html.kb-motion :is(.kb-practice, .kb-linkrow, .kb-country) { position: relative; isolation: isolate; }
	html.kb-motion :is(.kb-practice, .kb-linkrow, .kb-country)::before {
		content: "";
		position: absolute;
		inset: 0 -16px;
		z-index: -1;
		background: var(--cream-deep);
		transform: scaleX(0);
		transform-origin: left;
		transition: transform 300ms var(--ease-ink);
	}
	html.kb-motion :is(.kb-practice, .kb-linkrow, .kb-country):hover::before { transform: scaleX(1); }
	html.kb-motion :is(.kb-practice__title, .kb-linkrow__title, .kb-country__title) { transition: transform 300ms var(--ease-ink), color var(--t-color) var(--ease-out); }
	html.kb-motion .kb-practice:hover .kb-practice__title { transform: translateX(16px); }
	html.kb-motion :is(.kb-linkrow, .kb-country):hover :is(.kb-linkrow__title, .kb-country__title) { transform: translateX(6px); }
	html.kb-motion .kb-practice__num { transition: color 300ms var(--ease-ink); }
	html.kb-motion .kb-practice:hover .kb-practice__num { color: var(--indigo); }
	/* The homepage band is cream-deep already: use cream there so the slide is visible */
	html.kb-motion .band-cream-deep :is(.kb-practice, .kb-linkrow)::before { background: var(--cream); }
}
/* Photos: 103% inside their frames */
html.kb-motion :is(.kb-founder__photo, .kb-photos__item, .kb-bio__portrait) { overflow: hidden; }
html.kb-motion :is(.kb-founder__photo, .kb-photos__item, .kb-bio__portrait) img { transition: transform 600ms ease-out; }
@media (hover: hover) {
	html.kb-motion :is(.kb-founder__photo, .kb-photos__item, .kb-bio__portrait):hover img { transform: scale(1.03); }
	/* Footer hanko: eases back from 15° to 11° and presses to 98% */
	html.kb-motion .kb-footer__hanko { transition: transform 200ms ease-out; }
	html.kb-motion .kb-footer__hanko:hover { transform: rotate(calc(var(--hanko-tilt) + 4deg)) scale(.98); }
}

/* 6. Button press ---------------------------------------------------------------------- */
html.kb-motion :is(.kb-cta, .kb-arrow-link, .kb-menu-btn, .kb-menu__close, .kb-download) {
	transition-property: color, text-decoration-color, transform;
	transition-duration: var(--t-color), var(--t-color), 160ms;
	transition-timing-function: var(--ease-out), var(--ease-out), var(--ease-ink);
}
html.kb-motion :is(.kb-cta, .kb-arrow-link, .kb-menu-btn, .kb-menu__close, .kb-download):active {
	transform: scale(.98);
	transition-duration: var(--t-color), var(--t-color), 120ms;
}
.kb-cta:active { color: var(--indigo); }
.band-persimmon .kb-cta:active, .on-dark .kb-cta:active { color: var(--cream); }

/* 8. Carousel ticks: 200ms per spec */
.kb-carousel__tick { transition-duration: 200ms; }

/* 9. Page transitions: 200ms fade through cream ------------------------------------- */
@view-transition { navigation: auto; }
html { background: var(--cream); }
::view-transition-old(root) { animation: kb-vt-out 100ms ease-out both; }
::view-transition-new(root) { animation: kb-vt-in 100ms ease-out 100ms both; }
@keyframes kb-vt-out { to { opacity: 0; } }
@keyframes kb-vt-in { from { opacity: 0; } }
.kb-header { view-transition-name: kb-header; } /* the header holds still between pages */
::view-transition-group(kb-header) { animation-duration: 0s; }

@media (prefers-reduced-motion: reduce) {
	@view-transition { navigation: none; }
}
