/* ==========================================================================
   Motion: "Unfold" (The Opening Academy).

   Pieces open from their leaf corner (top-left) with a soft spring: a slight
   tilt and drop that settles flat. The seal above each section head turns a
   quarter in, the yellow rules beside every verse draw out from the centre,
   numbers count up and the portal bars grow.

   Safety:
   - Hidden states exist only under html.toa-motion, which motion.js adds
     after it has opened everything already on screen — nothing visible at
     load is ever hidden, and without JavaScript nothing is hidden at all.
   - Never set on (or under) prefers-reduced-motion: reduce.
   - A failsafe opens everything after 3 seconds.
   - Only transform and opacity are animated. No clip-path on observed
     elements or lazy images.
   ========================================================================== */

:root {
	--toa-unfold-ease: cubic-bezier(.22, 1.28, .36, 1); /* soft spring, ~4% overshoot */
	--toa-unfold-time: 760ms;
	--toa-unfold-step: 80ms;
}

@media (prefers-reduced-motion: no-preference) {
	/* Unfold targets: new markers and the house templates' markers. */
	.toa-motion [data-toa-unfold]:not(.is-open),
	.toa-motion .toa-in:not(.is-open) {
		opacity: 0;
		transform: perspective(900px) rotateX(-12deg) rotateZ(-1.8deg) translateY(34px) scale(.965);
	}
	.toa-motion [data-toa-unfold],
	.toa-motion .toa-in {
		transform-origin: 0 0; /* the leaf corner */
		transition:
			opacity 420ms ease-out calc(var(--i, 0) * var(--toa-unfold-step)),
			transform var(--toa-unfold-time) var(--toa-unfold-ease) calc(var(--i, 0) * var(--toa-unfold-step));
	}
	.toa-motion [data-toa-unfold].is-instant,
	.toa-motion .toa-in.is-instant { transition: none; }

	/* Section head: the seal turns a quarter into place… */
	.toa-motion .toa-head:not(.is-open) .toa-head__seal { transform: rotate(-90deg) scale(.6); opacity: 0; }
	.toa-motion .toa-head .toa-head__seal { transition: transform 900ms var(--toa-unfold-ease) 120ms, opacity 400ms ease-out 120ms; }
	/* …and the verse rules draw out from the centre. */
	.toa-motion .toa-head:not(.is-open) .toa-ayah .toa-ar::before,
	.toa-motion .toa-head:not(.is-open) .toa-ayah .toa-ar::after { transform: scaleX(0); }
	.toa-motion .toa-head .toa-ayah .toa-ar::before,
	.toa-motion .toa-head .toa-ayah .toa-ar::after { transition: transform 700ms cubic-bezier(.2, 0, 0, 1) 380ms; }
	.toa-motion .toa-head .toa-ayah .toa-ar::before { transform-origin: right center; }
	.toa-motion .toa-head .toa-ayah .toa-ar::after { transform-origin: left center; }
	.toa-motion .toa-head--start .toa-ayah .toa-ar::after { transform-origin: right center; }

	/* Portal illustration: progress bars grow once it has opened. */
	.toa-motion .toa-app:not(.is-open) .toa-bars i { transform: scaleY(.08); }
	.toa-motion .toa-app .toa-bars i { transition: transform 700ms var(--toa-unfold-ease); }
	.toa-motion .toa-app .toa-bars i:nth-child(2) { transition-delay: 90ms; }
	.toa-motion .toa-app .toa-bars i:nth-child(3) { transition-delay: 180ms; }
	.toa-motion .toa-app .toa-bars i:nth-child(4) { transition-delay: 270ms; }
	.toa-motion .toa-app .toa-bars i:nth-child(5) { transition-delay: 360ms; }
	.toa-motion .toa-app .toa-bars i:nth-child(6) { transition-delay: 450ms; }
	.toa-motion .toa-app:not(.is-open) .toa-app__toast { opacity: 0; transform: translateY(10px) rotate(-2deg); }
	.toa-motion .toa-app .toa-app__toast { transition: opacity 400ms ease-out 700ms, transform 700ms var(--toa-unfold-ease) 700ms; }

	/* Hover: course rows tip their leaf corner a little. */
	.toa-row { transition: border-color 200ms, box-shadow 200ms, transform 320ms var(--toa-unfold-ease); }
	.toa-row:hover { transform: rotate(-.4deg) translateY(-2px); }
	.toa-tutor__photo { transition: box-shadow 200ms, transform 420ms var(--toa-unfold-ease); }
	.toa-tutor__link:hover .toa-tutor__photo { transform: rotate(-4deg) scale(1.03); }

	/* Hero on load: the leaf plate swings out from behind the picture, the
	   photo eases out of a slow zoom, the badge drops in from above
	   (transform only — nothing on screen is ever hidden, LCP untouched). */
	body.toa .toa-hero__media::before { transform-origin: 100% 100%; animation: toa-plate 1300ms var(--toa-unfold-ease) 150ms both; }
	body.toa .toa-hero__img { animation: toa-breathe 1800ms cubic-bezier(.2, 0, 0, 1) both; }
	body.toa .toa-hero__badge { transform-origin: 100% 0; animation: toa-badge 900ms var(--toa-unfold-ease) 450ms both; }
	body.toa .toa-hero__chip { animation: toa-chip 800ms var(--toa-unfold-ease) both; }
	/* Orbit style: the dashed square frame stays still, the subject cards drift. */
	body.toa .toa-stage--orbit .toa-hero__media::before { animation: none; }
	body.toa .toa-orbit-chip { animation: toa-drift 5s ease-in-out infinite alternate; }
	body.toa .toa-orbit-chip--2 { animation-delay: -1.7s; }
	body.toa .toa-orbit-chip--3 { animation-delay: -3.4s; }
	body.toa .toa-orbit-chip--4 { animation-delay: -2.5s; }
	@keyframes toa-orbit { to { transform: rotate(360deg); } }
	@keyframes toa-drift { from { transform: translateY(-5px); } to { transform: translateY(5px); } }
	@keyframes toa-plate {
		from { transform: translate(0, 0) rotate(0); }
		to { transform: var(--toa-plate, translate(22px, 22px) rotate(3.5deg)); }
	}
	@keyframes toa-breathe {
		from { transform: scale(1.08); }
		to { transform: none; }
	}
	@keyframes toa-badge {
		from { transform: translateY(-16px) scale(.9); }
		to { transform: none; }
	}
	@keyframes toa-chip {
		from { transform: translateX(-14px); }
		to { transform: none; }
	}
	/* Buttons: a small press. */
	body.toa .toa-btn:active { transform: translateY(1px) scale(.98); }

	/* WhatsApp panel unfolds from the tab's corner. */
	.toa-wa__panel { transform-origin: 0 100%; animation: toa-wa-unfold 420ms var(--toa-unfold-ease); }
	@keyframes toa-wa-unfold {
		from { opacity: 0; transform: rotate(-3deg) scale(.94) translateY(8px); }
		to { opacity: 1; transform: none; }
	}
}
