/**
 * Tracey Muir — motion layer (Site Settings → Motion).
 *
 * Loaded only when animations are enabled. Rules:
 * - Only opacity and transform are animated (no layout properties).
 * - All movement sits inside `prefers-reduced-motion: no-preference`.
 * - Only content that starts below the fold is hidden for a reveal: motion.js adds
 *   .tm-reveal-pending to it. Nothing is hidden if the script does not run.
 * - Reveals use keyframes with `backwards` fill, so once finished the element's
 *   normal styles (and hover transitions) apply again.
 */

body.tm-motion {
	--tm-ease: cubic-bezier(0.22, 1, 0.36, 1);
	--tm-reveal-distance: 14px;
	--tm-reveal-duration: 620ms;
	--tm-hero-duration: 720ms;
	--tm-hero-scale: 1.02;
	--tm-lift: 2px;
	--tm-zoom: 1.02;
	--tm-arrow-shift: 3px;
}

body.tm-motion--standard {
	--tm-reveal-distance: 20px;
	--tm-reveal-duration: 700ms;
	--tm-hero-duration: 800ms;
	--tm-hero-scale: 1.035;
	--tm-lift: 4px;
	--tm-zoom: 1.035;
}

@keyframes tm-fade-up {
	from {
		opacity: 0;
		transform: translateY(var(--tm-reveal-distance));
	}
}

@keyframes tm-fade {
	from {
		opacity: 0;
	}
}

@keyframes tm-settle {
	from {
		opacity: 0;
		transform: scale(var(--tm-hero-scale));
	}
}

/* Hero heading and image: never start invisible, so they count as painted at once (LCP). */
@keyframes tm-rise {
	from {
		transform: translateY(var(--tm-reveal-distance));
	}
}

@keyframes tm-settle-visible {
	from {
		opacity: 0.6;
		transform: scale(var(--tm-hero-scale));
	}
}

@keyframes tm-panel-in {
	from {
		opacity: 0;
		transform: translateY(-6px);
	}
}

/* ---------- Colour feedback (no movement; kept even with reduced motion) ---------- */

.tm-motion .tm-button {
	transition: background-color 0.2s var(--tm-ease), border-color 0.2s var(--tm-ease), color 0.2s var(--tm-ease);
}

.tm-motion .tm-feature-grid__icon,
.tm-motion .tm-feature-grid__title,
.tm-motion .tm-card,
.tm-motion .tm-card__more,
.tm-motion .tm-footer__menu a,
.tm-motion .tm-footer__legal a,
.tm-motion .tm-link-arrow {
	transition: color 0.2s var(--tm-ease), border-color 0.25s var(--tm-ease);
}

.tm-motion a.tm-feature-grid__item:is(:hover, :focus-visible) .tm-feature-grid__icon {
	color: var(--tm-color-secondary);
}

.tm-motion .tm-card:hover {
	border-color: color-mix(in srgb, var(--tm-color-border), var(--tm-color-primary) 22%);
}

/* ---------- Movement ---------- */

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

	/* Hero entrance (homepage). The heading is readable from the first frame; it only settles upward. */
	.tm-motion .tm-hero__content > .tm-eyebrow {
		animation: tm-fade var(--tm-hero-duration) var(--tm-ease) backwards;
	}

	.tm-motion .tm-hero__content > .tm-section-title {
		animation: tm-rise var(--tm-hero-duration) var(--tm-ease) backwards;
	}

	.tm-motion .tm-hero__content > .tm-divider {
		animation: tm-fade var(--tm-hero-duration) var(--tm-ease) 150ms backwards;
	}

	.tm-motion .tm-hero__content > .tm-section-description {
		animation: tm-fade-up var(--tm-hero-duration) var(--tm-ease) 180ms backwards;
	}

	.tm-motion .tm-hero .tm-button-group > :nth-child(1) {
		animation: tm-fade-up var(--tm-hero-duration) var(--tm-ease) 260ms backwards;
	}

	.tm-motion .tm-hero .tm-button-group > :nth-child(2) {
		animation: tm-fade-up var(--tm-hero-duration) var(--tm-ease) 340ms backwards;
	}

	.tm-motion .tm-hero__image {
		animation: tm-settle-visible 900ms var(--tm-ease) backwards;
	}

	.tm-motion .tm-hero__note {
		animation: tm-fade-up var(--tm-hero-duration) var(--tm-ease) 420ms backwards;
	}

	/* Scroll reveals (targets listed in motion.js). */
	.tm-js-motion .tm-reveal-pending {
		opacity: 0;
	}

	.tm-js-motion .is-revealed {
		animation: tm-fade-up var(--tm-reveal-duration) var(--tm-ease) var(--tm-reveal-delay, 0ms) backwards;
	}

	/* Large images and book covers: fade with little or no travel. */
	.tm-js-motion :is(.tm-research__media, .tm-image-text__media).is-revealed {
		animation-name: tm-settle;
		animation-duration: 900ms;
	}

	.tm-js-motion .tm-banner__media.is-revealed {
		animation-name: tm-fade;
		animation-duration: 900ms;
	}

	.tm-js-motion .tm-books__cover.is-revealed {
		--tm-reveal-distance: 8px;
	}

	/* Contact banner CTA: short and quick so the button is usable straight away. */
	.tm-js-motion .tm-banner__content.is-revealed {
		animation-duration: 500ms;
	}

	/* Header: smoother dropdown and search panel. Visibility is still controlled by the menu itself. */
	.tm-motion .tm-nav__submenu {
		transition: opacity 0.22s var(--tm-ease), transform 0.22s var(--tm-ease), visibility 0.22s;
	}

	.tm-motion .tm-search-panel:not([hidden]) {
		animation: tm-panel-in 0.22s var(--tm-ease) both;
	}

	/* Hover movement, only for devices that really hover (no sticky hover on touch). */
	@media (hover: hover) {
		.tm-hover-fx .tm-feature-grid__item {
			transition: transform 0.24s var(--tm-ease);
		}

		.tm-hover-fx a.tm-feature-grid__item:hover {
			transform: translateY(calc(-1 * var(--tm-lift) - 1px));
		}

		.tm-hover-fx .tm-card {
			transition: transform 0.28s var(--tm-ease), border-color 0.28s var(--tm-ease);
		}

		.tm-hover-fx .tm-card:hover {
			transform: translateY(calc(-1 * var(--tm-lift) - 1px));
		}

		.tm-hover-fx .tm-card__media img {
			transition: transform 0.6s var(--tm-ease);
		}

		.tm-hover-fx .tm-card:hover .tm-card__media img {
			transform: scale(var(--tm-zoom));
		}

		.tm-hover-fx .tm-books__cover img,
		.tm-hover-fx .tm-book-card__cover img {
			transition: transform 0.3s var(--tm-ease);
		}

		.tm-hover-fx .tm-books__cover a:hover img,
		.tm-hover-fx .tm-book-card__cover:hover img {
			transform: translateY(-4px);
		}
	}

	/* Arrows nudge forward on hover and keyboard focus. */
	.tm-hover-fx :is(.tm-button, .tm-link-arrow) svg {
		transition: transform 0.22s var(--tm-ease);
	}

	.tm-hover-fx :is(.tm-button, .tm-link-arrow):is(:hover, :focus-visible) svg,
	.tm-hover-fx .tm-card:hover .tm-card__more svg {
		transform: translateX(var(--tm-arrow-shift));
	}

	/* Desktop navigation: the current-page underline also draws in under hovered items. */
	@media (min-width: 1320px) {
		.tm-hover-fx .tm-nav__list > .tm-nav__item > .tm-nav__link::after {
			background: var(--tm-nav-active);
			bottom: -8px;
			content: "";
			height: 2px;
			left: 0;
			position: absolute;
			right: 0;
			transform: scaleX(0);
			transform-origin: left center;
			transition: transform 0.22s var(--tm-ease);
		}

		.tm-hover-fx .tm-nav__list > .tm-nav__item > .tm-nav__link:is(:hover, :focus-visible)::after,
		.tm-hover-fx .tm-nav__list > .tm-nav__item.is-open > .tm-nav__link::after,
		.tm-hover-fx .tm-nav__list > .tm-nav__item.is-current > .tm-nav__link::after {
			transform: scaleX(1);
		}
	}
}

/* If reduced motion is switched on after the page loaded, show everything immediately. */
@media (prefers-reduced-motion: reduce) {
	.tm-js-motion :is(.tm-reveal-pending, .is-revealed) {
		animation: none;
		opacity: 1;
	}
}

/* Never print with reveal content hidden. */
@media print {
	.tm-js-motion :is(.tm-reveal-pending, .is-revealed) {
		animation: none;
		opacity: 1;
	}
}
