/* ==========================================================================
   Motion (docs/DESIGN_SYSTEM.md, section 7). ALL motion tokens live here. Purposeful, not decorative: marketing pages get rich
   motion, app pages stay subtle. Rules: animate transform and opacity only (SVG path drawing is the one paint-only exception,
   off the layout path; the aurora moves with transform since v0.14); 60 fps; ambient animation pauses off-screen (.is-offscreen);
   nothing blocks input; non-ambient animations are 560 ms or less; prefers-reduced-motion gives a static, fully usable page.
   ========================================================================== */

:root {
  --dur-1: 90ms; --dur-2: 140ms; --dur-3: 220ms; --dur-4: 360ms; --dur-5: 560ms; --dur-ambient: 18s;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.45, .64, 1);   /* fallback where linear() isn't supported */
  --stagger: 60ms;
}
@supports (transition-timing-function: linear(0, 1)) {
  :root {
    /* A lightly under-damped spring: overshoots about 3.5% and settles. */
    --ease-spring: linear(0, 0.0018, 0.0069 1.15%, 0.0263 2.3%, 0.0561 3.45%, 0.1554 5.75%, 0.2951 8.05%, 0.5131 10.9%, 0.6808 13.2%,
      0.8142 15.5%, 0.9118 17.8%, 0.9752 20.1%, 1.012 22.4%, 1.0301 24.7%, 1.0354 27%, 1.0313 29.3%, 1.0223 32.2%, 1.0111 35%,
      1.0025 38%, 0.9963 42%, 0.9942 46%, 0.995 50%, 0.9977 60%, 1);
  }
}

/* ---------- Keyframes ---------- */
@keyframes ua-spin { to { transform: rotate(360deg); } }
@keyframes ua-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes ua-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes ua-rise { from { opacity: 0; transform: translateY(.75rem); } to { opacity: 1; transform: none; } }
@keyframes ua-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ua-mark-in { from { opacity: 0; transform: scale(.7) translateY(.35rem); } to { opacity: 1; transform: none; } }
@keyframes ua-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes ua-ping { 0% { transform: scale(1); opacity: .6; } 100% { transform: scale(2.4); opacity: 0; } }
@keyframes ua-draw { to { stroke-dashoffset: 0; } }
@keyframes ua-grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes ua-grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes ua-reveal { from { opacity: 0; transform: translateY(1.25rem); } to { opacity: 1; transform: none; } }
@keyframes ua-float { 0%, 100% { transform: translate3d(0, 0, 0); } 50% { transform: translate3d(0, -8px, 0); } }
@keyframes ua-drift { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(3%, -2%, 0) scale(1.05); } }

/* ---------- Page transitions: the View Transitions API (cross-document), with a fade where it isn't supported ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: ua-fade var(--dur-2) var(--ease-out) reverse both; }
::view-transition-new(root) { animation: ua-fade var(--dur-3) var(--ease-out) both; }
/* The shared-element morph: static/js/motion.js gives the clicked listing photo and the detail hero the same name. */
::view-transition-group(listing-photo) { animation-duration: var(--dur-4); animation-timing-function: var(--ease-out); }
::view-transition-old(listing-photo), ::view-transition-new(listing-photo) { height: 100%; object-fit: cover; overflow: clip; border-radius: var(--r-2); }

/* ---------- Entrances: staggered load-in ---------- */
[data-ua-stagger] > * { animation: ua-rise var(--dur-5) var(--ease-out) both; animation-delay: calc(var(--i, 0) * var(--stagger)); }
[data-ua-stagger] > :nth-child(1) { --i: 0; } [data-ua-stagger] > :nth-child(2) { --i: 1; } [data-ua-stagger] > :nth-child(3) { --i: 2; }
[data-ua-stagger] > :nth-child(4) { --i: 3; } [data-ua-stagger] > :nth-child(5) { --i: 4; } [data-ua-stagger] > :nth-child(6) { --i: 5; }
[data-ua-stagger] > :nth-child(7) { --i: 6; } [data-ua-stagger] > :nth-child(8) { --i: 7; }
.ua-app [data-ua-stagger] > * { animation-duration: var(--dur-4); --stagger: 40ms; }  /* app pages stay subtle */

/* ---------- Scroll reveals: CSS scroll-driven where supported, an IntersectionObserver class otherwise ---------- */
[data-ua-reveal] { opacity: 1; }
.ua-js:not(.ua-reveal-native) [data-ua-reveal]:not(.is-visible) { opacity: 0; transform: translateY(1rem); }
.ua-js:not(.ua-reveal-native) [data-ua-reveal].is-visible { opacity: 1; transform: none; transition: opacity var(--dur-5) var(--ease-out), transform var(--dur-5) var(--ease-out); transition-delay: calc(var(--i, 0) * var(--stagger)); }
@supports (animation-timeline: view()) {
  [data-ua-reveal] { animation: ua-reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 15%; }
}

/* ---------- Hero aurora: one subtle, slow colour field, landing hero only; paused when off-screen ----------
   v0.14: three soft gradient blobs that only MOVE (transform), so each is painted once and the browser just re-composites it. The old version animated a custom property that every colour
   stop depended on and ran a 40 px blur, so the whole hero was repainted on every frame (measured in docs/design-audit/motion/). */
.ua-aurora { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; contain: paint; }
.ua-aurora::before, .ua-aurora::after, .ua-aurora > i { content: ""; position: absolute; border-radius: 50%; opacity: .55; will-change: transform; backface-visibility: hidden; }
.ua-aurora::before { left: -8%; top: -20%; width: 58%; height: 96%; background: radial-gradient(closest-side, color-mix(in srgb, var(--p-300) 55%, transparent), transparent); animation: ua-aur-a calc(var(--dur-ambient) * .8) ease-in-out infinite alternate; }
.ua-aurora::after { right: -10%; top: -26%; width: 52%; height: 90%; background: radial-gradient(closest-side, color-mix(in srgb, var(--t-200) 42%, transparent), transparent); animation: ua-aur-b calc(var(--dur-ambient) * 1.05) ease-in-out infinite alternate; }
.ua-aurora > i { left: 24%; bottom: -34%; width: 50%; height: 84%; background: radial-gradient(closest-side, color-mix(in srgb, var(--s-200) 45%, transparent), transparent); animation: ua-aur-c calc(var(--dur-ambient) * .95) ease-in-out infinite alternate; }
[data-bs-theme="dark"] .ua-aurora::before, [data-bs-theme="dark"] .ua-aurora::after, [data-bs-theme="dark"] .ua-aurora > i { opacity: .32; }
.ua-aurora.is-offscreen::before, .ua-aurora.is-offscreen::after, .ua-aurora.is-offscreen > i, .ua-offscreen-pause.is-offscreen { animation-play-state: paused; }
@keyframes ua-aur-a { from { transform: translate3d(-4%, 2%, 0) scale(1) rotate(0deg); } to { transform: translate3d(16%, 9%, 0) scale(1.14) rotate(16deg); } }
@keyframes ua-aur-b { from { transform: translate3d(6%, -3%, 0) scale(1.04) rotate(0deg); } to { transform: translate3d(-18%, 11%, 0) scale(.92) rotate(-14deg); } }
@keyframes ua-aur-c { from { transform: translate3d(-12%, 2%, 0) scale(1) rotate(0deg); } to { transform: translate3d(14%, -8%, 0) scale(1.1) rotate(10deg); } }

/* ---------- Spotlight, magnetic buttons and parallax (fine pointers only; static/js/motion.js sets the variables) ---------- */
.ua-spot { position: relative; isolation: isolate; }
.ua-spot::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none; opacity: 0;
  background: radial-gradient(22rem circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--action) 9%, transparent), transparent 65%);
  transition: opacity var(--dur-3) var(--ease-out);
}
.ua-spot:hover::before { opacity: 1; }
[data-ua-magnetic] { transform: translate3d(var(--tx, 0), var(--ty, 0), 0); transition: transform var(--dur-3) var(--ease-spring); will-change: transform; }
[data-ua-depth] { transform: translate3d(calc(var(--px, 0) * var(--depth, 0) * 1px), calc(var(--py, 0) * var(--depth, 0) * 1px), 0); }
.ua-card--interactive { transition: transform var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out); }
.ua-card--interactive:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }

/* ---------- SVG: path drawing, chart bars, sparkline ---------- */
.ua-spark-line { stroke-dasharray: 1; stroke-dashoffset: 1; }
.ua-spark-area, .ua-spark-dot { opacity: 0; transition: opacity var(--dur-4) var(--ease-out) .3s; }
.ua-js [data-ua-draw].is-drawn .ua-spark-line, .ua-spark.is-flat .ua-spark-line, html:not(.ua-js) .ua-spark-line { stroke-dashoffset: 0; }
.ua-js [data-ua-draw].is-drawn .ua-spark-line { animation: ua-draw var(--dur-5) var(--ease-out) both; stroke-dashoffset: 1; }
.ua-js [data-ua-draw].is-drawn .ua-spark-area, .ua-js [data-ua-draw].is-drawn .ua-spark-dot, html:not(.ua-js) .ua-spark-area, html:not(.ua-js) .ua-spark-dot { opacity: 1; }
.ua-js [data-ua-path].is-drawn { animation: ua-draw var(--dur-5) var(--ease-out) both; }
.ua-chart-bar { transform-box: fill-box; transform-origin: 50% 100%; }
.ua-js [data-ua-chart]:not(.is-visible) .ua-chart-bar { transform: scaleY(0); }
.ua-js [data-ua-chart].is-visible .ua-chart-bar { animation: ua-grow-y var(--dur-5) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 50ms); }
.ua-js [data-ua-chart].is-visible .ua-chart-group { --i: 0; }
.ua-js [data-ua-chart]:not(.is-visible) .ua-hbar { transform: scaleX(0); }
.ua-js [data-ua-chart].is-visible .ua-hbar { animation: ua-grow-x var(--dur-5) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 60ms); }

/* ---------- Micro-interactions ---------- */
.ua-copied { animation: ua-pop var(--dur-3) var(--ease-spring) both; }
.ua-ping { position: relative; }
.ua-ping::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: currentColor; animation: ua-ping 1.6s var(--ease-out) infinite; }
.ua-offscreen-pause { will-change: auto; }

/* ---------- Reduced motion: a static, fully usable page ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
  [data-ua-reveal], [data-ua-stagger] > * { opacity: 1 !important; transform: none !important; animation: none !important; }
  .ua-aurora::before, .ua-aurora::after, .ua-aurora > i { animation: none !important; }
  [data-ua-magnetic], [data-ua-depth] { transform: none !important; }
  .ua-spot::before { display: none; }
  .ua-spark-line { stroke-dashoffset: 0 !important; }
  .ua-spark-area, .ua-spark-dot { opacity: 1 !important; }
  .ua-chart-bar, .ua-hbar { transform: none !important; animation: none !important; }
  @view-transition { navigation: none; }
}
