/* ===========================================================================
   effects.css — generic motion / transition effects ONLY.

   This file is deliberately free of *styling* (no colours, spacing, fonts,
   layout). It holds reusable effects and behavioural controls we layer on
   top of the themed UI: View Transitions, keyframes, motion preferences,
   and whatever else we dream up later.

   Keep visual styling in the theme / bootstrap. Keep effects here.
   =========================================================================== */


/* ---------------------------------------------------------------------------
   Title modal slide transition (search-result paging)

   When the user pages Next / Previous through search results, the title
   modal content is swapped in place via AJAX. Wrapping that swap in
   document.startViewTransition() lets us slide the old card out and the new
   one in, instead of the jarring flash.

   Why `.modal.show .modal-content` and not just `.modal-content`?
     - view-transition-name must be UNIQUE among rendered elements. Only one
       Bootstrap modal carries `.show` at a time; inactive modals are
       display:none and are ignored by View Transitions. So this is unique.
     - The OLD and NEW snapshots share the SAME name (`title-modal`), which
       is what makes the browser PAIR them into a single slide rather than
       two separate fades.
     - It adds only `view-transition-name`, scoped to the active modal, so a
       theme's own `.modal-content { ... }` rules are left intact.
   --------------------------------------------------------------------------- */

.modal.show .modal-content {
	view-transition-name: title-modal;
}

/* Direction is set by JS via <html data-vt="forward|back"> just before the
   swap, then cleared when the transition finishes. */

@keyframes vt-slide-out-left  { to   { transform: translateX(-100%); opacity: 0; } }
@keyframes vt-slide-in-right  { from { transform: translateX( 100%); opacity: 0; } }
@keyframes vt-slide-out-right { to   { transform: translateX( 100%); opacity: 0; } }
@keyframes vt-slide-in-left   { from { transform: translateX(-100%); opacity: 0; } }

/* FORWARD (Next): old exits to the left, new enters from the right */
html[data-vt="forward"]::view-transition-old(title-modal) {
	animation: 320ms cubic-bezier(.4, 0, .2, 1) both vt-slide-out-left;
}
html[data-vt="forward"]::view-transition-new(title-modal) {
	animation: 320ms cubic-bezier(.4, 0, .2, 1) both vt-slide-in-right;
}

/* BACK (Previous): old exits to the right, new enters from the left */
html[data-vt="back"]::view-transition-old(title-modal) {
	animation: 320ms cubic-bezier(.4, 0, .2, 1) both vt-slide-out-right;
}
html[data-vt="back"]::view-transition-new(title-modal) {
	animation: 320ms cubic-bezier(.4, 0, .2, 1) both vt-slide-in-left;
}

/* Accessibility: users who ask for reduced motion get an instant swap. */
@media (prefers-reduced-motion: reduce) {
	::view-transition-old(title-modal),
	::view-transition-new(title-modal) {
		animation-duration: 1ms;
	}
}
