/**
 * GGS: interazioni morbide (T40), frontend ed editor.
 *
 * Token di movimento. I valori stanno in theme.json →
 * `settings.custom.ggs.motion` (`--wp--custom--ggs--motion--*`): il tema GGS
 * li definisce, il child li cambia nel suo theme.json, "Opzioni tema →
 * Movimento" li scrive nel livello utente. Qui gli alias brevi, con i default
 * per un tema senza quei token:
 *
 *   --ggs-ease           curva morbida in uscita: risposta immediata,
 *                        poi si distende
 *   --ggs-duration-fast  colori, bordi, sottolineature (180ms)
 *   --ggs-duration       pulsanti, card, voci di menu (280ms)
 *   --ggs-duration-slow  sollevamenti, ombre grandi, zoom, pannelli (450ms)
 *
 * Gli alias sono in `:where(:root)` (specificità zero): un
 * `:root { --ggs-… }` del tema o del child vince sempre.
 *
 * Movimento ridotto: tutte le durate diventano brevi (al massimo 120ms) e
 * restano per i cambi di colore; spostamenti e zoom li tolgono i componenti.
 */
:where(:root) {
	--ggs-ease: var(--wp--custom--ggs--motion--ease, cubic-bezier(0.22, 1, 0.36, 1));
	--ggs-duration-fast: calc(var(--wp--custom--ggs--motion--duration-fast, 180ms) * var(--wp--custom--ggs--motion--scale, 1));
	--ggs-duration: calc(var(--wp--custom--ggs--motion--duration, 280ms) * var(--wp--custom--ggs--motion--scale, 1));
	--ggs-duration-slow: calc(var(--wp--custom--ggs--motion--duration-slow, 450ms) * var(--wp--custom--ggs--motion--scale, 1));
}

@media (prefers-reduced-motion: reduce) {

	:where(:root) {
		--ggs-duration-fast: min(calc(var(--wp--custom--ggs--motion--duration-fast, 180ms) * var(--wp--custom--ggs--motion--scale, 1)), 120ms);
		--ggs-duration: var(--ggs-duration-fast);
		--ggs-duration-slow: var(--ggs-duration-fast);
	}
}

/*
 * Transizioni di default di link, pulsanti e campi, in un livello (`@layer`):
 * qualsiasi regola fuori dal livello (tema, blocchi, plugin) vince, a ogni
 * specificità.
 *
 * Solo proprietà economiche, uguali all'entrata e all'uscita (la transizione
 * è sullo stato di riposo). `outline` non è animato: l'anello del focus da
 * tastiera compare subito.
 *
 * Solo nei contenuti: frontend e iframe dell'editor (`body` senza `.wp-admin`)
 * o editor senza iframe (`.editor-styles-wrapper`), non l'interfaccia di
 * WordPress (`enqueue_block_assets` vale anche nella pagina dell'editor).
 */
@layer ggs-interactions {

	:where(body:not(.wp-admin), .editor-styles-wrapper) :where(a, summary, [role="tab"]) {
		transition-duration: var(--ggs-duration-fast);
		transition-property: color, background-color, border-color, text-decoration-color, opacity, box-shadow;
		transition-timing-function: var(--ggs-ease);
	}

	:where(body:not(.wp-admin), .editor-styles-wrapper) :where(
		button,
		[role="button"],
		input:is([type="button"], [type="submit"], [type="reset"]),
		.wp-element-button,
		.wp-block-button__link,
		.button
	) {
		transition-duration: var(--ggs-duration);
		transition-property: color, background-color, border-color, text-decoration-color, opacity, box-shadow;
		transition-timing-function: var(--ggs-ease);
	}

	/* Campi: solo colori (l'ombra di focus di alcuni plugin resta immediata). */
	:where(body:not(.wp-admin), .editor-styles-wrapper) :where(
		input:not([type="button"], [type="submit"], [type="reset"], [type="checkbox"], [type="radio"], [type="range"], [type="hidden"]),
		select,
		textarea
	) {
		transition-duration: var(--ggs-duration-fast);
		transition-property: color, background-color, border-color;
		transition-timing-function: var(--ggs-ease);
	}

	/* Focus da tastiera: stato di focus immediato (anche con `box-shadow`). */
	:where(body:not(.wp-admin), .editor-styles-wrapper) :where(:focus-visible) {
		transition-duration: 0s;
	}
}
