/*
 * Nyappu Motion foundation — GAP-029. Spec: docs/visual-direction-v2.md §4 / §5 / §10 / §11 / §12 / §15 工程1.
 * Loaded on every page (the header uses M4). Pages opt in per element; nothing here animates on its own.
 *
 *   M1  .ny-enter              entrance on load (opacity + translateY). Stagger via --ny-stagger-index on the element.
 *   M2  [data-ny-reveal]       scroll reveal, once. nyappu-motion.js adds .is-visible (or .is-instant when already on screen).
 *   M3  .ny-photo-hover        photo scale on hover, desktop pointer only. Put the class on the frame around the <img>.
 *   M4  .nyappu-header__menu   UI transition (menu open / close). Other UI transitions use the tokens below.
 *
 * Rules that hide an initial state live under html.js-motion (M1, a finite animation) and html.js-motion-ready
 * (M2, the scroll reveal) only. html.js-motion is added by an inline head script when IntersectionObserver exists
 * and prefers-reduced-motion is not "reduce", and removed again if nyappu-motion.js never marks html.js-motion-ready.
 * 2026-09-22: M2's hidden start state is applied only once nyappu-motion.js has set up its observer
 * (html.js-motion-ready) — default = visible, JS = enhancement. A target the observer never fires for
 * (e.g. an element taller than the viewport) is shown by the tall-element / timeout failsafes in the JS.
 * Without JS nothing is hidden. Only opacity / transform move (max-height is the single exception, for the menu),
 * so layout never shifts: CLS 0.
 */

:root {
	--ny-motion-ease: cubic-bezier(.2, .7, .2, 1);
	--ny-motion-dur-ui: 200ms;      /* M4: 150–250ms */
	--ny-motion-dur-photo: 300ms;   /* M3 */
	--ny-motion-dur-reveal: 450ms;  /* M2 */
	--ny-motion-dur-enter: 550ms;   /* M1: 500–600ms */
	--ny-motion-move-reveal: 12px;
	--ny-motion-move-enter: 16px;
	--ny-motion-stagger: 90ms;      /* 80–120ms */
}

/* M1 — entrance. Same curve and distance family as M2 so the two read as one hand. */
@keyframes ny-enter {
	from {
		opacity: 0;
		transform: translateY(var(--ny-motion-move-enter));
	}
}
html.js-motion .ny-enter {
	animation: ny-enter var(--ny-motion-dur-enter) var(--ny-motion-ease) both;
	animation-delay: calc(var(--ny-stagger-index, 0) * var(--ny-motion-stagger));
}

/* M2 — scroll reveal. The element keeps its box (opacity, not display), links stay clickable.
   Hidden start state only under html.js-motion-ready (set by nyappu-motion.js after the observer exists). */
html.js-motion-ready [data-ny-reveal] {
	opacity: 0;
	transform: translateY(var(--ny-motion-move-reveal));
	transition:
		opacity var(--ny-motion-dur-reveal) var(--ny-motion-ease),
		transform var(--ny-motion-dur-reveal) var(--ny-motion-ease);
	transition-delay: calc(var(--ny-stagger-index, 0) * var(--ny-motion-stagger));
}
html.js-motion-ready [data-ny-reveal].is-visible {
	opacity: 1;
	transform: none;
}
/* Already inside the first viewport: shown at once, no fade (v2 §10). */
html.js-motion-ready [data-ny-reveal].is-instant { transition: none; }

/* M3 — photo hover. Desktop pointer only; touch devices get no hover state. The frame clips and keeps its radius. */
@media (hover: hover) and (pointer: fine) {
	.ny-photo-hover img { transition: transform var(--ny-motion-dur-photo) var(--ny-motion-ease); }
	.ny-photo-hover:hover img,
	.ny-photo-hover:focus-visible img,
	a:hover > .ny-photo-hover img,
	a:focus-visible > .ny-photo-hover img { transform: scale(1.02); }
}

/* Reduced motion: every pattern off, final state shown immediately (also covers a setting changed mid-session). */
@media (prefers-reduced-motion: reduce) {
	.ny-enter,
	[data-ny-reveal],
	.ny-photo-hover img,
	.nyappu-header__menu {
		animation: none !important;
		transition: none !important;
	}
	.ny-enter,
	[data-ny-reveal] {
		opacity: 1 !important;
		transform: none !important;
	}
}
