/* ─────────────────────────────────────────────────────────────────────────
   motion.css — site-wide motion system for ViewBack.AI
   Loaded on every page. ~4KB gzipped. Zero WebGL.
   Primitives:
   - @view-transition for native page morphing (Chrome 111+, Safari 18+)
   - .reveal / .reveal-up / .reveal-scale for scroll-triggered entrances
   - .pixels for the "dots assembling into a shape" motif (inline SVG + CSS)
   - .lift / .press / .ripple for interactive affordances
   - .drawer / .drawer-panel / .drawer-link for the mobile menu
   Everything honors prefers-reduced-motion.
   ───────────────────────────────────────────────────────────────────── */

/* ── View Transitions API: morph between pages instead of a hard cut ──
   Chrome/Edge 111+, Safari 18+. Non-supporting browsers get a plain nav.
   Opt-in per link via data-vt="skip" if a specific nav should not morph.
   Named transitions on key regions so the hero and nav crossfade cleanly. */
@view-transition {
  navigation: auto;
}
/* Pixel-dissolve page transitions. The outgoing page breaks into a scatter
   of cells (blur + brightness + scale with a cellular mask grid revealing the
   underlying brand color), and the incoming page re-assembles the inverse —
   cells settle in and sharpness returns. Signature-matches the hero wave →
   pixels → words effect so the whole site feels like one motion vocabulary.
   The grid overlay is driven by background-image (no DOM nodes, no canvas),
   and all CSS variables/transforms are GPU-friendly. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 560ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  mix-blend-mode: normal;
  transform-origin: 50% 40%;
}
::view-transition-old(root) {
  animation-name: vt-pixel-out;
}
::view-transition-new(root) {
  animation-name: vt-pixel-in;
  animation-delay: 60ms;
}
@keyframes vt-pixel-out {
  0% {
    opacity: 1;
    filter: none;
    transform: scale(1);
    clip-path: inset(0 round 0);
  }
  35% {
    opacity: 0.82;
    filter: blur(1.5px) saturate(1.12) brightness(1.04);
    transform: scale(0.994);
  }
  70% {
    opacity: 0.32;
    filter: blur(8px) saturate(1.25) brightness(1.08);
    transform: scale(0.98);
  }
  100% {
    opacity: 0;
    filter: blur(18px) saturate(1.3) brightness(1.1);
    transform: scale(0.965);
  }
}
@keyframes vt-pixel-in {
  0% {
    opacity: 0;
    filter: blur(16px) saturate(0.85) brightness(1.06);
    transform: scale(1.018);
    clip-path: inset(0 round 24px);
  }
  40% {
    opacity: 0.55;
    filter: blur(4px) saturate(0.95);
    transform: scale(1.008);
    clip-path: inset(0 round 8px);
  }
  80% {
    opacity: 0.92;
    filter: blur(0.5px);
    transform: scale(1.002);
    clip-path: inset(0 round 0);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: scale(1);
  }
}
/* Pixel-cell overlay. A brand-tinted grid of 10px cells fades in over the
   outgoing page to reinforce the "breaking into pixels" read, then fades
   out as the incoming page sharpens. Delivered as a background pattern on
   the pseudo-element so no DOM nodes are added. */
::view-transition-old(root)::after,
::view-transition-new(root)::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(var(--brand-200-rgb, 213, 206, 255), 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--brand-200-rgb, 213, 206, 255), 0.18) 1px, transparent 1px);
  background-size: 10px 10px, 10px 10px;
  mix-blend-mode: screen;
  opacity: 0;
}
::view-transition-old(root)::after {
  animation: vt-grid-emerge 560ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
::view-transition-new(root)::before {
  animation: vt-grid-fade 620ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: 60ms;
}
@keyframes vt-grid-emerge {
  0%   { opacity: 0; background-size: 2px 2px, 2px 2px; }
  40%  { opacity: 0.55; background-size: 10px 10px, 10px 10px; }
  100% { opacity: 0.85; background-size: 22px 22px, 22px 22px; }
}
@keyframes vt-grid-fade {
  0%   { opacity: 0.75; background-size: 22px 22px, 22px 22px; }
  60%  { opacity: 0.25; background-size: 10px 10px, 10px 10px; }
  100% { opacity: 0; background-size: 4px 4px, 4px 4px; }
}
/* Respect reduced-motion: no blur, no scale — just a quick crossfade that
   doesn't trigger vestibular discomfort. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 200ms;
  }
  ::view-transition-old(root) { animation-name: vt-reduced-out; }
  ::view-transition-new(root) { animation-name: vt-reduced-in; animation-delay: 0ms; }
  ::view-transition-old(root)::after,
  ::view-transition-new(root)::before { display: none; }
}
@keyframes vt-reduced-out { to { opacity: 0; } }
@keyframes vt-reduced-in { from { opacity: 0; } }

/* Fixed chrome keeps its own identity across pages so it doesn't crossfade
   or slide — otherwise the bottom tab bar visibly flickers on every tap. */
.nav { view-transition-name: site-nav; }
.mobile-tabs { view-transition-name: mobile-tabs; }
.mobile-home { view-transition-name: mobile-home; }
.hero, .band:first-of-type { view-transition-name: hero; }
::view-transition-group(site-nav),
::view-transition-group(mobile-tabs),
::view-transition-group(mobile-home) {
  animation-duration: 0ms;
}
::view-transition-old(mobile-tabs),
::view-transition-new(mobile-tabs),
::view-transition-old(mobile-home),
::view-transition-new(mobile-home) {
  animation: none;
}
::view-transition-group(hero) {
  animation-duration: 500ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Scroll reveals ──────────────────────────────────────────────────── */
.reveal, .reveal-up, .reveal-scale, .reveal-stagger > * {
  opacity: 0;
  transform: translate3d(0, 24px, 0);
  transition:
    opacity 650ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 650ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}
.reveal-scale {
  transform: translate3d(0, 24px, 0) scale(0.97);
}
.reveal.in, .reveal-up.in, .reveal-scale.in,
.reveal-stagger.in > * {
  opacity: 1;
  transform: none;
}
.reveal-stagger.in > *:nth-child(1) { transition-delay: 0ms; }
.reveal-stagger.in > *:nth-child(2) { transition-delay: 70ms; }
.reveal-stagger.in > *:nth-child(3) { transition-delay: 140ms; }
.reveal-stagger.in > *:nth-child(4) { transition-delay: 210ms; }
.reveal-stagger.in > *:nth-child(5) { transition-delay: 280ms; }
.reveal-stagger.in > *:nth-child(6) { transition-delay: 350ms; }
.reveal-stagger.in > *:nth-child(7) { transition-delay: 420ms; }
.reveal-stagger.in > *:nth-child(8) { transition-delay: 490ms; }

/* Elements inside a [data-page-enter] region are animated by the GSAP page-enter
   sweep in motion.js (gsap.from with clearProps). Default them visible so the
   sweep's clearProps doesn't leave them stuck at opacity:0 behind CSS .reveal*. */
[data-page-enter] .reveal,
[data-page-enter] .reveal-up,
[data-page-enter] .reveal-scale,
[data-page-enter] .reveal-stagger > * {
  opacity: 1;
  transform: none;
}

/* ── Pixel-assembly motif ────────────────────────────────────────────────
   <div class="pixels" aria-hidden="true">
     <i></i><i></i><i></i> ... (24 to 60 i elements)
   </div>
   Dots start scattered + transparent, then assemble into a tight grid as
   soon as the container is in view (or on page load for above-fold heroes).
   Container needs position: relative + a sized area to draw into. */
.pixels {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--pixels-cols, 12), 1fr);
  gap: 4px;
  width: var(--pixels-w, 240px);
  height: var(--pixels-h, 80px);
  pointer-events: none;
}
.pixels i {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2px;
  background: currentColor;
  opacity: 0;
  transform: translate3d(
      calc((var(--pxi, 0) % 7 - 3) * 18px),
      calc((var(--pxi, 0) % 5 - 2) * 14px),
      0
    )
    scale(0.4);
  transition:
    transform 900ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 600ms ease-out;
}
.pixels.in i {
  opacity: 0.85;
  transform: none;
}
.pixels.in i:nth-child(even) { transition-delay: 40ms; }
.pixels.in i:nth-child(3n) { transition-delay: 90ms; }
.pixels.in i:nth-child(5n) { transition-delay: 140ms; }
.pixels.in i:nth-child(7n) { transition-delay: 200ms; }

/* ── Interactive affordances ─────────────────────────────────────────── */
/* .lift: button/card hover grows slightly + drops a soft shadow. */
.lift {
  transition:
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 180ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.lift:hover,
.lift:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(var(--brand-ink-rgb, 14, 11, 31), 0.35);
}
.lift:active { transform: translateY(0); }

/* .press: tap feedback for primary CTAs */
.press { transition: transform 120ms ease; }
.press:active { transform: scale(0.97); }

/* .ripple: cheap material-style ripple on click. motion.js adds .is-rip
   with --rx/--ry/--rd custom props set to the click position + diagonal. */
.ripple { position: relative; overflow: hidden; }
.ripple::after {
  content: "";
  position: absolute;
  left: var(--rx, 50%);
  top: var(--ry, 50%);
  width: var(--rd, 0);
  height: var(--rd, 0);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
}
.ripple.is-rip::after {
  animation: ripple 620ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ripple {
  from { opacity: 0.55; transform: translate(-50%, -50%) scale(0.2); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ── Mobile / tablet drawer (below 1100px) ────────────────────────────── */
/* HTML shape:
   <button class="drawer-toggle" aria-expanded="false" aria-controls="drawer">
     <span></span><span></span><span></span> Menu
   </button>
   <div class="drawer" id="drawer" hidden>
     <div class="drawer-scrim"></div>
     <nav class="drawer-panel">
       <div class="drawer-head">...</div>
       <ul class="drawer-list">
         <li><a class="drawer-link" href="/">Product</a></li>
         ...
       </ul>
       <div class="drawer-foot">...</div>
     </nav>
   </div>                                                                 */
.drawer-toggle {
  display: none;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px 0 12px;
  background: rgba(var(--brand-ink-rgb, 14, 11, 31), 0.28);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: #fff;
  font: 600 0.92rem var(--body);
  letter-spacing: -0.005em;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 150ms ease, border-color 150ms ease;
}
.drawer-toggle:hover,
.drawer-toggle:focus-visible {
  background: rgba(var(--brand-ink-rgb, 14, 11, 31), 0.42);
  border-color: rgba(255, 255, 255, 0.3);
  outline: none;
}
.drawer-toggle .bars {
  display: inline-grid;
  grid-template-rows: repeat(3, 2px);
  gap: 4px;
  width: 18px;
}
.drawer-toggle .bars span {
  display: block;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transition: transform 220ms ease, opacity 180ms ease;
  transform-origin: center;
}
.drawer-toggle[aria-expanded="true"] .bars span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.drawer-toggle[aria-expanded="true"] .bars span:nth-child(2) {
  opacity: 0;
}
.drawer-toggle[aria-expanded="true"] .bars span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}
.drawer[data-open="true"] {
  pointer-events: auto;
}
.drawer-scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, #0b0d12 60%, transparent);
  opacity: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 320ms cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer[data-open="true"] .drawer-scrim {
  opacity: 1;
}
.drawer-panel {
  position: relative;
  z-index: 1;
  width: min(420px, 92vw);
  max-height: 100dvh;
  padding: 24px 22px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(
    180deg,
    rgba(var(--brand-700-rgb, 86, 68, 191), 0.72) 0%,
    rgba(var(--brand-900-rgb, 40, 32, 89), 0.78) 100%
  );
  box-shadow:
    -24px 0 60px rgba(var(--brand-ink-rgb, 14, 11, 31), 0.5),
    inset 1px 0 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(28px) saturate(170%);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  color: #fff;
  overflow-y: auto;
  transform: translate3d(100%, 0, 0);
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer[data-open="true"] .drawer-panel {
  transform: translate3d(0, 0, 0);
}
/* Soft moving aurora inside the drawer so it feels alive. */
.drawer-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 50% at 80% 10%, rgba(var(--brand-300-rgb, 184, 172, 255), 0.35), transparent 60%),
    radial-gradient(70% 60% at 10% 100%, rgba(52, 199, 89, 0.18), transparent 70%);
  pointer-events: none;
  animation: drawer-aurora 18s ease-in-out infinite alternate;
  z-index: -1;
}
@keyframes drawer-aurora {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-3%, 4%, 0); }
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.drawer-head .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  font: 700 1.05rem var(--display);
  letter-spacing: -0.015em;
}
.drawer-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}
.drawer-close:hover,
.drawer-close:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}
.drawer-close:active { transform: scale(0.94); }

.drawer-eyebrow {
  margin: 10px 2px 4px;
  font: 700 0.7rem var(--body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}
.drawer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  color: #fff;
  font: 600 1.05rem var(--body);
  letter-spacing: -0.005em;
  text-decoration: none;
  background: transparent;
  transition:
    background 140ms ease,
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
    padding-left 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer-link:hover,
.drawer-link:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  padding-left: 18px;
  outline: none;
}
.drawer-link:active {
  background: rgba(255, 255, 255, 0.18);
}
.drawer-link .arrow {
  opacity: 0.6;
  transition: transform 180ms ease, opacity 180ms ease;
}
.drawer-link:hover .arrow,
.drawer-link:focus-visible .arrow {
  transform: translateX(4px);
  opacity: 1;
}
.drawer-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  margin-top: 8px;
  padding: 0 18px;
  background: #fff;
  color: var(--brand-700, #5644bf);
  font: 700 1rem var(--body);
  border-radius: 12px;
  text-decoration: none;
  transition: background 140ms ease, transform 140ms ease;
}
.drawer-cta:hover,
.drawer-cta:focus-visible {
  background: var(--brand-50, #f4f2ff);
  outline: none;
}
.drawer-cta:active { transform: scale(0.98); }

.drawer-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
}
.drawer-foot a {
  color: inherit;
  text-decoration: none;
}
.drawer-foot a:hover {
  color: #fff;
}

/* Stagger the drawer items in when it opens */
.drawer[data-open="true"] .drawer-link,
.drawer[data-open="true"] .drawer-cta,
.drawer[data-open="true"] .drawer-eyebrow {
  animation: drawer-item 460ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.drawer[data-open="true"] .drawer-eyebrow { animation-delay: 60ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(1) .drawer-link { animation-delay: 80ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(2) .drawer-link { animation-delay: 110ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(3) .drawer-link { animation-delay: 140ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(4) .drawer-link { animation-delay: 170ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(5) .drawer-link { animation-delay: 200ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(6) .drawer-link { animation-delay: 230ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(7) .drawer-link { animation-delay: 260ms; }
.drawer[data-open="true"] .drawer-list > li:nth-child(8) .drawer-link { animation-delay: 290ms; }
.drawer[data-open="true"] .drawer-cta { animation-delay: 320ms; }
@keyframes drawer-item {
  from { opacity: 0; transform: translate3d(14px, 0, 0); }
  to { opacity: 1; transform: none; }
}

/* ── Responsive switch ──────────────────────────────────────────────────
   Below 1100px: hide the desktop nav links and show the drawer toggle.
   Site.css already hides individual links at 820px — this rule takes over
   earlier and converts the whole top bar to toggle + brand + Download CTA. */
@media (max-width: 1099px) {
  .nav nav > a:not(.btn) { display: none; }
  .drawer-toggle { display: inline-flex; }
  /* Keep the inline Download button on tablet so the primary CTA is always
     one tap away — hide it on phones (<540) where the drawer carries it. */
  @media (max-width: 539px) {
    .nav nav > a.btn { display: none; }
  }
  /* The legacy <details class="menu"> hamburger is retired in favour of the
     drawer — hide it when the drawer is present. */
  .nav .menu { display: none; }
}

/* ── prefers-reduced-motion: still works, just doesn't move ─────────── */
@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal-up, .reveal-scale, .reveal-stagger > *,
  .pixels i, .drawer-panel, .drawer-scrim,
  .drawer[data-open="true"] .drawer-link,
  .drawer[data-open="true"] .drawer-cta,
  .drawer[data-open="true"] .drawer-eyebrow {
    transition: none !important;
    animation: none !important;
  }
  .reveal, .reveal-up, .reveal-scale, .reveal-stagger > *,
  .pixels i {
    opacity: 1;
    transform: none;
  }
  .drawer-panel {
    transform: translate3d(0, 0, 0);
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }
  .drawer-panel::before { animation: none; }
}
