/*
 * Culinary Pirates: Choreografie beim Laden und beim Scrollen (seit 1.2.0)
 *
 * Jede Art von Element hat ihre eigene Bewegung, statt dass alles gleich
 * „von unten einblendet“. Die Verben stammen aus der Bildsprache: stempeln,
 * anpinnen, schneiden, wischen.
 *   Hauptzeilen     Wörter steigen gekippt aus einer Maske (nur h1, Plakatzeilen und die
 *                   Überschrift der Anfrage: functions.php teilt nur diese in Wörter)
 *   Stimme          kursive Überschriften wischen als ganze Zeile auf
 *   Labels          Wischen von links, das X dreht sich ein
 *   Fotos im Rahmen fallen wie angepinnte Abzüge und federn in ihre Schräglage
 *   Bildleiste      die sichtbaren Rahmen werden von rechts ausgeteilt
 *   Stempel         werden mit kleinem Überschwingen aufgestempelt
 *   Gründe          „Nº“ steigt auf, der Eintrag folgt
 *   Ablauf          Verben werden aufgestempelt, der Pinselstrich zieht sich zum nächsten Schritt
 *   Kacheln         Vorhang nach oben
 *   Formularkarte   gleitet herauf
 *   Hero            Wörter im Grund blenden mit dem Text auf; Rauch steigt, solange das Video läuft (sections.css)
 * Kopfzeile und Footer stehen still.
 *
 * Bedingungen: Alles hier gilt nur am Bildschirm, nur mit JavaScript (html.cp-js),
 * nur wenn keine reduzierte Bewegung gewünscht ist (html.cp-motion, gesetzt im
 * <head>) und nur bei „prefers-reduced-motion: no-preference“. Ohne JavaScript,
 * bei „Bewegung reduzieren“, im Druck oder wenn theme.js nicht rechtzeitig
 * startet, stehen alle Inhalte sofort da (Absicherung in functions.php,
 * cp_theme_head_early). Bewegt werden nur transform, opacity und clip-path
 * (und die Einzel-Eigenschaften translate, rotate, scale). Das Posterbild des
 * Heros (größtes Element, LCP) wird nie ein- oder ausgeblendet.
 *
 * theme.js setzt .is-inview, sobald ein Element ins Fenster kommt. Elemente, die
 * schon über dem Fenster liegen (Sprung per Anker, Zurück-Navigation) oder den
 * Tastaturfokus bekommen, erhalten zusätzlich .is-instant: Sie stehen ohne
 * Übergang da. Der Versatz (--cp-i) zählt nur Elemente, die gemeinsam ins
 * Fenster kommen.
 *
 * Wichtig für Selektoren: Die Listen hier und in assets/js/theme.js (MOTION)
 * müssen übereinstimmen. CSS blendet aus, theme.js setzt .is-inview.
 */

:root {
	--cp-ease-word: cubic-bezier(0.2, 0.85, 0.25, 1);
	--cp-ease-spring: cubic-bezier(0.34, 1.5, 0.55, 1);
	--cp-ease-snap: cubic-bezier(0.7, 0, 0.2, 1);
}

/* Wörter der Hauptzeilen (functions.php teilt sie in .cp-w > .cp-w__i) */
.cp-words .cp-w__i {
	display: inline-block;
}

@keyframes cp-word-in {
	from {
		transform: translate3d(0, 118%, 0) rotate(6deg);
	}

	to {
		transform: none;
	}
}

@keyframes cp-word-rise {
	from {
		transform: translate3d(0, 0.32em, 0) rotate(2.5deg);
	}

	to {
		transform: none;
	}
}

@keyframes cp-wipe-in {
	from {
		clip-path: inset(-0.2em 100% -0.2em 0);
	}

	to {
		clip-path: inset(-0.2em -0.2em -0.2em 0);
	}
}

@keyframes cp-stamp-in {
	0% {
		opacity: 0;
		transform: scale(1.45) rotate(-8deg);
	}

	55% {
		opacity: 1;
	}

	100% {
		opacity: 1;
		transform: none;
	}
}

@keyframes cp-fade-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

@keyframes cp-lift {
	from {
		translate: 0 1.5rem;
	}
}

@keyframes cp-drift-up {
	from {
		translate: 0 1.75rem;
	}

	to {
		translate: 0 -1.75rem;
	}
}

@keyframes cp-drift-down {
	from {
		translate: 0 -1.25rem;
	}

	to {
		translate: 0 1.75rem;
	}
}

@media screen and (prefers-reduced-motion: no-preference) {

	/* ------------------------------------------------------------ Beim Laden: Video-Hero
	 * Reihenfolge: Überschrift, Pinselstrich, Leistungssatz, Stempel. Text und Aktionen stehen
	 * nach rund 1,2 s. (Bis 1.2.0 stempelte sich hier der Sticker auf, die Klingen fuhren danach
	 * unter ihm heraus.) Die Zier des Heros (Wörter, Gewürzpfanne, Pinselstrich, Kante) steht
	 * von Anfang an: Eine Deckkraft-Einblendung ließ in Chrome Gewürzpfanne und Pinselstrich
	 * unsichtbar (Bild hinter opacity: 0 nicht gezeichnet, nach dem Ende der Animation kein
	 * neues Zeichnen; QA.md Befund 81) und die Wörter, die nur 8 % Deckkraft haben, blitzten
	 * während der Einblendung weiß auf (Befund 82).
	 */

	html.cp-js.cp-motion .cp-vhero__title.cp-words .cp-w {
		clip-path: inset(-0.7em -0.3em -0.16em -0.3em);
		display: inline-block;
	}

	html.cp-js.cp-motion .cp-vhero__title.cp-words .cp-w__i {
		animation: cp-word-in 640ms var(--cp-ease-word) backwards;
		animation-delay: calc(80ms + var(--w, 0) * 60ms);
		transform-origin: 0 100%;
	}

	html.cp-js.cp-motion .cp-vhero__title::after {
		animation: cp-wipe-in 420ms var(--cp-ease-snap) 560ms backwards;
	}

	html.cp-js.cp-motion .cp-vhero__copy .cp-lead {
		animation: cp-fade-in 420ms ease 660ms backwards;
	}

	html.cp-js.cp-motion .cp-vhero__copy .wp-block-button {
		animation: cp-stamp-in 420ms var(--cp-ease-spring) 740ms backwards;
	}

	html.cp-js.cp-motion .cp-vhero__copy .wp-block-button + .wp-block-button {
		animation-delay: 810ms;
	}

	html.cp-js.cp-motion .cp-vhero__copy .wp-block-button.is-style-cp-link {
		animation: cp-fade-in 420ms ease 810ms backwards;
	}

	/* ------------------------------------------------------------ Beim Laden: Seitenköpfe
	 * Nur CSS, ohne auf theme.js zu warten. Der Titel ist ab dem ersten Bild
	 * lesbar (Wörter richten sich auf, ohne Maske und ohne Ausblenden). Das Foto
	 * (oft das größte Element) bewegt sich nicht.
	 */
	html.cp-js.cp-motion .cp-pagehero .cp-eyebrow {
		animation: cp-wipe-in 520ms var(--cp-ease-snap) backwards;
	}

	html.cp-js.cp-motion :is(.cp-pagehero h1, .cp-pagehead h1).cp-words .cp-w__i {
		animation: cp-word-rise 640ms var(--cp-ease-word) backwards;
		animation-delay: calc(60ms + var(--w, 0) * 60ms);
		transform-origin: 0 100%;
	}

	html.cp-js.cp-motion .cp-pagehero__copy .cp-lead {
		animation: cp-fade-in 450ms ease 320ms backwards;
	}

	html.cp-js.cp-motion .cp-pagehero__copy .wp-block-button {
		animation: cp-stamp-in 480ms var(--cp-ease-spring) 440ms backwards;
	}

	/* Anfrageseite: Die Formularkarte steht von Anfang an da und hebt sich nur kurz an (nie unsichtbar). */
	html.cp-js.cp-motion .cp-anfrage :is(.cp-form-card, .cp-contact__aside) {
		animation: cp-lift 450ms var(--cp-ease-word) 120ms backwards;
	}

	/* ------------------------------------------------------------ Beim Scrollen
	 * Ausgangszustand: solange das Element nicht .is-inview trägt.
	 */

	/* Ohne Übergang: Element lag schon über dem Fenster oder bekam den Fokus */
	html.cp-js.cp-motion .is-instant,
	html.cp-js.cp-motion .is-instant *,
	html.cp-js.cp-motion .is-instant::before,
	html.cp-js.cp-motion .is-instant::after,
	html.cp-js.cp-motion .is-instant *::before,
	html.cp-js.cp-motion .is-instant *::after {
		transition-duration: 0s !important;
		transition-delay: 0s !important;
	}

	/* Hauptzeilen h2 (Plakat, Anfrage): Wörter steigen gekippt aus der Maske */
	html.cp-js.cp-motion main h2.cp-words .cp-w {
		clip-path: inset(-0.7em -0.3em -0.2em -0.3em);
		display: inline-block;
	}

	html.cp-js.cp-motion main h2.cp-words .cp-w__i {
		transform-origin: 0 100%;
		transition: transform 720ms var(--cp-ease-word);
		transition-delay: calc(var(--w, 0) * 55ms);
	}

	html.cp-js.cp-motion main h2.cp-words:not(.is-inview) .cp-w__i {
		transform: translate3d(0, 118%, 0) rotate(6deg);
	}

	/* Stimme: Die kursive Zeile wischt als Ganzes auf, wie mit dem Pinsel geschrieben */
	html.cp-js.cp-motion main .cp-head--voice h2 {
		transition: clip-path 650ms var(--cp-ease-snap);
	}

	html.cp-js.cp-motion main .cp-head--voice h2:not(.is-inview) {
		clip-path: inset(-0.25em 100% -0.3em -0.1em);
	}

	html.cp-js.cp-motion main .cp-head--voice h2.is-inview {
		clip-path: inset(-0.25em -0.2em -0.3em -0.1em);
	}

	/* Labels: Wischen von links, das X dreht sich ein (in Seitenköpfen: siehe oben) */
	html.cp-js.cp-motion .cp-eyebrow:not(:is(.cp-vhero, .cp-pagehero) .cp-eyebrow) {
		transition: clip-path 760ms var(--cp-ease-snap);
	}

	html.cp-js.cp-motion .cp-eyebrow:not(:is(.cp-vhero, .cp-pagehero) .cp-eyebrow):not(.is-inview) {
		clip-path: inset(-0.3em 100% -0.3em 0);
	}

	html.cp-js.cp-motion .cp-eyebrow:not(:is(.cp-vhero, .cp-pagehero) .cp-eyebrow).is-inview {
		clip-path: inset(-0.3em -0.3em -0.3em 0);
	}

	html.cp-js.cp-motion .cp-eyebrow::before {
		transition: transform 760ms var(--cp-ease-spring) 160ms;
	}

	html.cp-js.cp-motion .cp-eyebrow:not(:is(.cp-vhero, .cp-pagehero) .cp-eyebrow):not(.is-inview)::before {
		transform: rotate(-180deg) scale(0.3);
	}

	/* Einleitungen und Absätze neben Überschriften: blenden nach der Überschrift auf (ohne Weg) */
	html.cp-js.cp-motion :is(.cp-section__head > p:not(.cp-eyebrow), .cp-section__head > * > p:not(.cp-eyebrow), .cp-split__sticky > p:not(.cp-eyebrow), .cp-crew__copy > p:not(.cp-eyebrow), .cp-cta__copy > p:not(.cp-eyebrow), .cp-anfrage-start__copy > p:not(.cp-eyebrow), .cp-social-row) {
		transition: opacity 600ms ease;
		transition-delay: calc(240ms + var(--cp-i, 0) * 80ms);
	}

	html.cp-js.cp-motion :is(.cp-section__head > p:not(.cp-eyebrow), .cp-section__head > * > p:not(.cp-eyebrow), .cp-split__sticky > p:not(.cp-eyebrow), .cp-crew__copy > p:not(.cp-eyebrow), .cp-cta__copy > p:not(.cp-eyebrow), .cp-anfrage-start__copy > p:not(.cp-eyebrow), .cp-social-row):not(.is-inview) {
		opacity: 0;
	}

	/*
	 * Fotos im Rahmen: fallen wie angepinnte Abzüge und federn in ihre
	 * Schräglage (die bleibt in der Eigenschaft rotate, die Bewegung nutzt transform).
	 * :not(#individual-image) hebt die Spezifität über die Regel der Galerie in sections.css.
	 */
	html.cp-js.cp-motion :is(.cp-frame, .cp-crew__media, .cp-cta__media, .cp-gallery figure.wp-block-image:not(#individual-image)) {
		transition:
			opacity 380ms ease calc(var(--cp-i, 0) * 95ms),
			transform 1000ms var(--cp-ease-spring) calc(var(--cp-i, 0) * 95ms),
			rotate var(--cp-dur-ui) var(--cp-ease-out),
			translate var(--cp-dur-ui) var(--cp-ease-out),
			box-shadow var(--cp-dur-ui) var(--cp-ease-out);
	}

	html.cp-js.cp-motion :is(.cp-frame, .cp-crew__media, .cp-cta__media, .cp-gallery figure.wp-block-image:not(#individual-image)):not(.is-inview) {
		opacity: 0;
		transform: translate3d(0, -42px, 0) rotate(-9deg) scale(1.06);
	}

	/* Bildleiste: Die sichtbaren Rahmen werden von rechts ausgeteilt (theme.js zählt nur diese) */
	html.cp-js.cp-motion .cp-gallery--strip figure.wp-block-image:not(#individual-image) {
		transition:
			opacity 300ms ease calc(var(--cp-i, 0) * 85ms),
			transform 720ms var(--cp-ease-word) calc(var(--cp-i, 0) * 85ms),
			rotate var(--cp-dur-ui) var(--cp-ease-out),
			translate var(--cp-dur-ui) var(--cp-ease-out),
			box-shadow var(--cp-dur-ui) var(--cp-ease-out);
	}

	html.cp-js.cp-motion .cp-gallery--strip figure.wp-block-image:not(#individual-image):not(.is-inview) {
		transform: translate3d(70px, 0, 0) rotate(10deg);
	}

	/* Rezeptkarten: Foto im Papierrahmen fällt herein, ohne Ausblenden (kann auf der Rezeptübersicht das größte Bild sein) */
	html.cp-js.cp-motion .cp-recipes .wp-block-post-featured-image {
		transition:
			transform 1000ms var(--cp-ease-spring) calc(var(--cp-i, 0) * 110ms),
			rotate var(--cp-dur-ui) var(--cp-ease-out),
			translate var(--cp-dur-ui) var(--cp-ease-out);
	}

	html.cp-js.cp-motion .cp-recipes .wp-block-post-featured-image:not(.is-inview) {
		transform: translate3d(0, -30px, 0) rotate(-6deg);
	}

	/* Stempel außerhalb von Hero, Seitenkopf, Kopfzeile, Kacheln und Menü */
	html.cp-js.cp-motion .wp-block-buttons > .wp-block-button:not(.is-style-cp-link):not(:is(.cp-vhero, .cp-panel, .cp-header, .cp-overlay, .cp-pagehero, .cp-footer) *) {
		transition: opacity 260ms ease calc(320ms + var(--cp-i, 0) * 100ms), transform 520ms var(--cp-ease-spring) calc(320ms + var(--cp-i, 0) * 100ms);
	}

	html.cp-js.cp-motion .wp-block-buttons > .wp-block-button:not(.is-style-cp-link):not(:is(.cp-vhero, .cp-panel, .cp-header, .cp-overlay, .cp-pagehero, .cp-footer) *):not(.is-inview) {
		opacity: 0;
		transform: scale(1.45) rotate(-8deg);
	}

	/* Textlinks: blenden auf */
	html.cp-js.cp-motion .wp-block-buttons > .wp-block-button.is-style-cp-link:not(:is(.cp-vhero, .cp-panel, .cp-header, .cp-overlay, .cp-pagehero, .cp-footer) *) {
		transition: opacity 500ms ease 360ms;
	}

	html.cp-js.cp-motion .wp-block-buttons > .wp-block-button.is-style-cp-link:not(:is(.cp-vhero, .cp-panel, .cp-header, .cp-overlay, .cp-pagehero, .cp-footer) *):not(.is-inview) {
		opacity: 0;
	}

	/* Gründe: „Nº“ steigt auf, der Eintrag folgt (Versatz nur, wenn mehrere zugleich ins Fenster kommen) */
	html.cp-js.cp-motion .cp-reasons > *::before {
		transition: opacity 450ms ease calc(var(--cp-i, 0) * 110ms), transform 800ms var(--cp-ease-word) calc(var(--cp-i, 0) * 110ms);
	}

	html.cp-js.cp-motion .cp-reasons > *:not(.is-inview)::before {
		opacity: 0;
		transform: translate3d(0, 1.5rem, 0) rotate(-8deg);
	}

	html.cp-js.cp-motion .cp-reasons > * > * {
		transition: opacity 450ms ease calc(140ms + var(--cp-i, 0) * 110ms);
	}

	html.cp-js.cp-motion .cp-reasons > *:not(.is-inview) > * {
		opacity: 0;
	}

	/* Ablauf: Verben werden aufgestempelt, der Pinselstrich zieht sich (Wischen, nicht Strecken) */
	html.cp-js.cp-motion ol.cp-steps > li {
		transition: opacity 360ms ease calc(var(--cp-i, 0) * 160ms);
	}

	html.cp-js.cp-motion ol.cp-steps > li:not(.is-inview) {
		opacity: 0;
	}

	html.cp-js.cp-motion ol.cp-steps > li strong {
		transform-origin: 0 100%;
		transition: transform 520ms var(--cp-ease-spring) calc(var(--cp-i, 0) * 160ms);
	}

	html.cp-js.cp-motion ol.cp-steps > li:not(.is-inview) strong {
		transform: scale(1.25) rotate(-4deg);
	}

	/* Der Stempel mit dem Symbol wird mit dem Verb aufgedrückt (sections.css) */
	html.cp-js.cp-motion ol.cp-steps > li::before,
	html.cp-js.cp-motion ol.cp-steps > li::after {
		transition: transform 520ms var(--cp-ease-spring) calc(var(--cp-i, 0) * 160ms);
	}

	html.cp-js.cp-motion ol.cp-steps > li:not(.is-inview)::before,
	html.cp-js.cp-motion ol.cp-steps > li:not(.is-inview)::after {
		transform: scale(1.4) rotate(calc(var(--cp-step-tilt) - 10deg));
	}

	html.cp-js.cp-motion ol.cp-steps > li strong::after {
		clip-path: inset(-40% -2% -40% 0);
		transition: clip-path 600ms var(--cp-ease-snap) calc(240ms + var(--cp-i, 0) * 160ms);
	}

	html.cp-js.cp-motion ol.cp-steps > li:not(.is-inview) strong::after {
		clip-path: inset(-40% 100% -40% 0);
	}

	/*
	 * Zeilen: FAQ, Leistungsdetails blenden als Gruppe auf. Die FAQ-Einträge fragen das
	 * Attribut ab, nicht die Klasse: Beim Auf- und Zuklappen schreibt WordPress ihre
	 * Klassen neu (theme.js, reveal).
	 */
	html.cp-js.cp-motion :is(.cp-faq .wp-block-accordion-item, .cp-detail) {
		transition: opacity 400ms ease;
	}

	html.cp-js.cp-motion .cp-faq .wp-block-accordion-item:not([data-cp-inview]),
	html.cp-js.cp-motion .cp-detail:not(.is-inview) {
		opacity: 0;
	}

	/*
	 * Kacheln: Vorhang nach oben (Fokusrahmen und Schatten liegen außerhalb und bleiben frei).
	 * Vorne schnell, hinten weich: Was clip-path noch verdeckt, nimmt kein Antippen an, und
	 * unten sitzt der Schalter der geschlossenen Kachel.
	 */
	html.cp-js.cp-motion .cp-panels {
		transition: clip-path 700ms var(--cp-ease-word);
	}

	html.cp-js.cp-motion .cp-panels:not(.is-inview) {
		clip-path: inset(-24px -24px 100% -24px);
	}

	html.cp-js.cp-motion .cp-panels.is-inview {
		clip-path: inset(-24px);
	}

	/* Formularkarte und Infokasten (Startseite): gleiten herauf (ohne Drehung: kein Überstand am schmalen Rand) */
	html.cp-js.cp-motion :is(.cp-form-card, .cp-contact__aside):not(.cp-anfrage *) {
		transition: opacity 400ms ease 80ms, transform 650ms var(--cp-ease-word) 80ms;
	}

	html.cp-js.cp-motion :is(.cp-form-card, .cp-contact__aside):not(.cp-anfrage *):not(.is-inview) {
		opacity: 0;
		transform: translate3d(0, 40px, 0);
	}

	/* ------------------------------------------------------------ An den Scroll gekoppelt
	 * Nur wo der Browser Scroll-Zeitleisten kennt (sonst bleibt alles stehen) und
	 * bewusst zurückhaltend: kein Parallax über ganze Abschnitte. Alles folgt dem
	 * Scrollen der Nutzerin oder des Nutzers und steht still, wenn niemand scrollt.
	 */
	@supports (animation-timeline: view()) {
		/* Crew: die beiden Rahmen gleiten gegeneinander */
		html.cp-js.cp-motion .cp-polaroids > :first-child {
			animation: cp-drift-up linear both;
			animation-range: cover 0% cover 100%;
			animation-timeline: view();
		}

		html.cp-js.cp-motion .cp-polaroids > :nth-child(2) {
			animation: cp-drift-down linear both;
			animation-range: cover 0% cover 100%;
			animation-timeline: view();
		}
	}
}
