/* ───────────────────────────────────────────────────────────
   909 Development — motion & atmosphere layer
   Everything here is progressive enhancement on top of app.css:
   the site is complete and readable without it.

   Rules this file follows:
   · animate transform / opacity (and the individual `translate`/`scale`
     properties) — never layout properties
   · one reveal system (IntersectionObserver, motion.js), one pointer
     handler, one canvas — no overlapping animation systems
   · every moving thing is inside a prefers-reduced-motion: no-preference
     block, and hover/pointer effects only exist for hover-capable devices
   ─────────────────────────────────────────────────────────── */

/* ═════════ 1. Atmosphere (fixed, behind everything) ═════════ */

.atmosphere {
  position: fixed; inset: 0; z-index: -1;
  overflow: hidden; pointer-events: none; contain: strict;
}
.atmosphere > * { position: absolute; }

.blob { border-radius: 50%; will-change: transform; }
.blob-a {
  width: 72vmax; height: 72vmax; left: 52%; top: -38vmax;
  background: radial-gradient(closest-side, rgba(165, 21, 31, 0.24), rgba(165, 21, 31, 0.07) 55%, transparent 72%);
}
.blob-b {
  width: 64vmax; height: 64vmax; left: -28vmax; top: 38%;
  background: radial-gradient(closest-side, rgba(116, 130, 168, 0.13), rgba(116, 130, 168, 0.04) 55%, transparent 72%);
}
.grid-lines {
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 72px 72px;
  -webkit-mask-image: radial-gradient(75% 60% at 50% 0%, #000, transparent 78%);
  mask-image: radial-gradient(75% 60% at 50% 0%, #000, transparent 78%);
}
.noise {
  inset: 0; opacity: 0.055;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%27180%27%20height=%27180%27%3E%3Cfilter%20id=%27n%27%20x=%270%27%20y=%270%27%20width=%27100%25%27%20height=%27100%25%27%3E%3CfeTurbulence%20type=%27fractalNoise%27%20baseFrequency=%27.85%27%20numOctaves=%272%27%20stitchTiles=%27stitch%27/%3E%3CfeColorMatrix%20values=%270%200%200%200%201%200%200%200%200%201%200%200%200%200%201%200%200%200%20.6%200%27/%3E%3C/filter%3E%3Crect%20width=%27100%25%27%20height=%27100%25%27%20filter=%27url%28%23n%29%27/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

.scroll-sentinel { position: absolute; top: 0; left: 0; width: 1px; height: 24px; pointer-events: none; }

/* thin progress line while another page is loading (shows slow networks honestly) */
.nav-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 90;
  background: linear-gradient(90deg, var(--crimson), var(--crimson-hi) 70%, #fff);
  box-shadow: 0 0 12px var(--glow-crimson);
  transform: scaleX(0); transform-origin: left; opacity: 0; pointer-events: none;
}
.is-navigating .nav-progress { opacity: 1; transform: scaleX(0.86); transition: transform 9s cubic-bezier(0.1, 0.6, 0.2, 1), opacity var(--dur-fast); }

/* ═════════ 2. Hero ═════════ */

.hero-fx { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 22%, #000 72%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 22%, #000 72%, transparent); }
.hero-grid { position: relative; z-index: 1; }

.beam {
  position: absolute; top: -10%; height: 120%;
  width: 17vw; min-width: 150px;
  background: linear-gradient(90deg, transparent, rgba(211, 43, 59, 0.2) 50%, transparent);
  transform: skewX(-12deg);
  opacity: 0.55;
  translate: calc(var(--px, 0) * 26px) 0;
  transition: translate 0.9s var(--ease-out);
}
.beam-1 { left: 50%; }
.beam-2 { left: 71%; width: 8vw; background: linear-gradient(90deg, transparent, rgba(214, 220, 232, 0.12) 50%, transparent); }
.beam-3 { left: 27%; width: 5vw; opacity: 0.4; }

.hero-particles { position: absolute; inset: 0; width: 100%; height: 100%; }

/* hero headline: each word is its own gradient so the entrance can stagger */
.display-words { background: none; -webkit-background-clip: border-box; background-clip: border-box; color: inherit; }
.display-words .hero-word {
  display: inline-block;
  padding-right: 0.08em; margin-right: -0.04em; /* italic overhang, keeps glyphs from clipping */
  background: var(--chrome-gradient);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.display-words .hero-word:nth-child(1) { --i: 0; }
.display-words .hero-word:nth-child(2) { --i: 1; }
.display-words .hero-word:nth-child(3) { --i: 2; }
.display-words .hero-word:nth-child(4) { --i: 3; }
.display-words .hero-word:nth-child(5) { --i: 4; }
.display-words .hero-word:nth-child(6) { --i: 5; }
.display-words .hero-word:nth-child(7) { --i: 6; }
.display-words .hero-word:nth-child(8) { --i: 7; }
.display-words .hero-word:nth-child(n + 9) { --i: 8; }

.scroll-cue {
  position: absolute; left: 50%; bottom: 4.4rem; z-index: 2; translate: -50% 0;
  display: flex; flex-direction: column; align-items: center; gap: 0.55rem;
  min-width: 44px; padding: 0.25rem 0.5rem;
  color: var(--text-faint); font-size: var(--fs-xs); text-decoration: none;
  transition: opacity var(--dur) var(--ease-out), color var(--dur-fast);
}
.scroll-cue:hover { color: var(--chrome-hi); }
.scroll-cue-line { position: relative; width: 1px; height: 34px; overflow: hidden; background: linear-gradient(var(--line-strong), transparent); }
.scroll-cue-line::after { content: ''; position: absolute; left: 0; top: 0; width: 100%; height: 12px; background: var(--crimson-hi); box-shadow: 0 0 8px var(--glow-crimson); }
.is-scrolled .scroll-cue { opacity: 0; pointer-events: none; }
@media (max-width: 900px), (max-height: 720px) { .scroll-cue { display: none; } }

/* light line between sections */
.glow-rule {
  height: 1px; border: 0; margin: 0;
  background: linear-gradient(90deg, transparent, var(--line-strong) 14%, rgba(211, 43, 59, 0.75) 50%, var(--line-strong) 86%, transparent);
}

/* ═════════ 3. Pointer-driven light (injected + driven by motion.js, desktop only) ═════════ */

.spot-edge, .spot-glow { position: absolute; pointer-events: none; opacity: 0; border-radius: inherit; transition: opacity var(--dur) var(--ease-out); }
.spot-edge {
  inset: -1px; padding: 1px; z-index: 3;
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), rgba(236, 239, 246, 0.7), rgba(211, 43, 59, 0.28) 40%, transparent 68%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.spot-glow {
  inset: 0; z-index: -1;
  background: radial-gradient(380px circle at var(--mx, 50%) var(--my, 50%), rgba(211, 43, 59, 0.2), rgba(214, 220, 232, 0.05) 45%, transparent 68%);
}
.is-tracking > .spot-edge, .is-tracking > .spot-glow { opacity: 1; }

/* ═════════ 4. Everything below only moves if the visitor allows motion ═════════ */

@media (prefers-reduced-motion: no-preference) {

  /* ── background drift ── */
  .blob-a { animation: drift-a 52s ease-in-out infinite alternate; }
  .blob-b { animation: drift-b 68s ease-in-out infinite alternate; }
  @keyframes drift-a { to { transform: translate3d(-9vw, 9vh, 0) scale(1.08); } }
  @keyframes drift-b { to { transform: translate3d(11vw, -8vh, 0) scale(1.1); } }

  /* ── hero entrance (CSS-only, so it runs even before JS) ── */
  .display-words .hero-word {
    background-image:
      linear-gradient(105deg, transparent 36%, rgba(255, 255, 255, 0.95) 50%, transparent 64%),
      var(--chrome-gradient);
    background-size: 260% 100%, 100% 100%;
    background-repeat: no-repeat;
    background-position: 140% 0, 0 0;
    animation:
      word-in 0.9s var(--ease-out) calc(0.05s + var(--i) * 0.085s) both,
      word-shine 1.5s var(--ease-in-out) calc(0.75s + var(--i) * 0.11s) both;
  }
  @keyframes word-in {
    from { opacity: 0; translate: 0 0.55em; filter: blur(10px); }
    to { opacity: 1; translate: 0 0; filter: blur(0); }
  }
  @keyframes word-shine {
    from { background-position: 140% 0, 0 0; }
    to { background-position: -50% 0, 0 0; }
  }
  .hero-copy .lead { animation: rise 0.9s var(--ease-out) 0.5s both; }
  .hero-copy .actions { animation: rise 0.9s var(--ease-out) 0.65s both; }
  .hero .console { animation: rise 1s var(--ease-out) 0.4s backwards, float 9s ease-in-out 1.6s infinite; translate: calc(var(--px, 0) * -14px) calc(var(--py, 0) * -9px); transition: translate 0.8s var(--ease-out); }
  @keyframes float { 50% { transform: translate3d(0, -7px, 0); } }

  .beam { animation: beam-sweep 15s ease-in-out infinite; }
  .beam-2 { animation-duration: 19s; animation-delay: -6s; }
  .beam-3 { animation-duration: 23s; animation-delay: -11s; }
  @keyframes beam-sweep {
    0%, 100% { opacity: 0.25; transform: translate3d(-4vw, 0, 0) skewX(-12deg); }
    50% { opacity: 0.85; transform: translate3d(5vw, 0, 0) skewX(-12deg); }
  }

  .scroll-cue-line::after { animation: cue 2.2s var(--ease-in-out) infinite; }
  @keyframes cue { from { transform: translateY(-110%); } to { transform: translateY(330%); } }

  /* pause the hero's looping effects once it has scrolled out of view */
  .hero.is-offscreen, .hero.is-offscreen *, .hero.is-offscreen *::before, .hero.is-offscreen *::after { animation-play-state: paused !important; }

  /* ── generic entrance for the first block of every page ── */
  .page-head .wrap > *, .plugin-head .wrap > *, .error-page .wrap > *, .auth-panel > * { animation: rise 0.85s var(--ease-out) both; }
  .page-head .wrap > :nth-child(2), .plugin-head .wrap > :nth-child(2), .error-page .wrap > :nth-child(2), .auth-panel > :nth-child(2) { animation-delay: 0.07s; }
  .page-head .wrap > :nth-child(3), .plugin-head .wrap > :nth-child(3), .error-page .wrap > :nth-child(3), .auth-panel > :nth-child(3) { animation-delay: 0.14s; }
  .page-head .wrap > :nth-child(n + 4), .plugin-head .wrap > :nth-child(n + 4), .error-page .wrap > :nth-child(n + 4), .auth-panel > :nth-child(n + 4) { animation-delay: 0.2s; }
  @keyframes rise { from { opacity: 0; translate: 0 22px; } to { opacity: 1; translate: 0 0; } }

  /* ── scroll reveal. Hidden state exists only when JS is running (html.js), and
        the fallback class (set by boot.js after 3.5 s) shows everything regardless. ── */
  html.js:not(.reveal-fallback) [data-reveal]:not([data-done]),
  html.js:not(.reveal-fallback) [data-reveal-group] > *:not([data-done]) {
    opacity: 0; translate: 0 26px;
    transition:
      opacity var(--dur-reveal) var(--ease-out) calc(var(--i, 0) * var(--stagger)),
      translate var(--dur-reveal) var(--ease-out) calc(var(--i, 0) * var(--stagger)),
      scale var(--dur-reveal) var(--ease-out) calc(var(--i, 0) * var(--stagger)),
      filter var(--dur-reveal) var(--ease-out) calc(var(--i, 0) * var(--stagger));
  }
  html.js:not(.reveal-fallback) [data-reveal='blur']:not([data-done]) { filter: blur(7px); }
  html.js:not(.reveal-fallback) [data-reveal='depth']:not([data-done]), html.js:not(.reveal-fallback) [data-reveal-group='depth'] > *:not([data-done]) { scale: 0.965; }
  html.js:not(.reveal-fallback) [data-reveal='line']:not([data-done]) { translate: 0 0; scale: 0 1; }
  html.js:not(.reveal-fallback) [data-reveal].is-in:not([data-done]),
  html.js:not(.reveal-fallback) [data-reveal-group] > .is-in:not([data-done]) { opacity: 1; translate: 0 0; scale: 1; filter: none; }

  /* ── cards: lift (all hover devices), tilt only where motion.js drives --rx/--ry ── */
  @media (hover: hover) {
    /* at rest: no transform at all (crisp text); perspective only applies while hovered/tracked */
    .card, .bundle, .stat { transition: transform 0.55s var(--ease-out), border-color var(--dur) var(--ease-out), box-shadow var(--dur-slow) var(--ease-out); }
    .card:hover, .bundle:hover, .stat:hover { transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-5px); }
    .card.is-tracking, .bundle.is-tracking { transition: transform 0.09s linear, border-color var(--dur) var(--ease-out), box-shadow var(--dur-slow) var(--ease-out); }
    .card:hover .card-media img { transform: scale(1.06); }
    .card:hover .monogram { transform: translateX(6px) skewX(-12deg) scale(1.04); }
    .card:hover .chip { border-color: var(--chrome-lo); color: var(--chrome-hi); }
    .card:hover .rust-badge::before { animation: dot-pulse 1.6s ease-out infinite; }
    .chip { transition: border-color var(--dur-fast), color var(--dur-fast), background-color var(--dur-fast), transform var(--dur) var(--ease-out); }
    .chip-tag:hover, .chip-removable:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.04); }
    .row-link:hover .row-title { color: #fff; }
    .site-footer a { transition: color var(--dur-fast), translate var(--dur) var(--ease-out); }
    .footer-col a:hover { translate: 3px 0; }
  }
  @keyframes dot-pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); } 100% { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0); } }

  /* ── content swap on faq and review form ── */
  .faq details p { animation: faq-open var(--dur-slow) var(--ease-out); }
  @keyframes faq-open { from { opacity: 0; translate: 0 -6px; } to { opacity: 1; translate: 0 0; } }

  /* ── cross-document page transitions (Chrome/Edge/Safari; others just navigate) ── */
  /* Named on the content layer, not on .site-header: an element with a view-transition-name becomes
     its own backdrop root, which would stop the glass layer inside it from blurring the page. */
  .header-inner { view-transition-name: site-header; }
  ::view-transition-old(root) { animation: vt-out 0.16s var(--ease-in-out) both; }
  ::view-transition-new(root) { animation: vt-in 0.34s var(--ease-out) both; }
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in { from { opacity: 0; translate: 0 10px; } }

  /* ── scroll-driven depth (compositor only, no JS) ── */
  @supports (animation-timeline: scroll()) {
    .atmosphere { animation: atmosphere-scroll linear both; animation-timeline: scroll(root); }
    @keyframes atmosphere-scroll { to { transform: translate3d(0, -9vh, 0); } }
    .hero-grid { animation: hero-exit linear both; animation-timeline: scroll(root); animation-range: 0 70vh; }
    @keyframes hero-exit { to { opacity: 0.15; translate: 0 -46px; scale: 0.975; } }
    .hero-fx { animation: fx-exit linear both; animation-timeline: scroll(root); animation-range: 0 80vh; }
    @keyframes fx-exit { to { translate: 0 60px; opacity: 0.4; } }
  }
}

@view-transition { navigation: auto; }

/* ═════════ 5. Lighter on small screens ═════════ */

@media (max-width: 760px) {
  .blob-b, .beam-2, .beam-3, .hero-particles, .grid-lines { display: none; }
  .blob-a { width: 120vmax; height: 120vmax; left: 10%; top: -60vmax; }
  .noise { opacity: 0.04; }
  html.js:not(.reveal-fallback) [data-reveal='blur']:not([data-done]) { filter: none; }
  html.js:not(.reveal-fallback) [data-reveal]:not([data-done]):not(.is-in), html.js:not(.reveal-fallback) [data-reveal-group] > *:not([data-done]):not(.is-in) { translate: 0 18px; }
  .hero .console { animation-name: rise; }
}

/* ═════════ 6. Reduced motion: no animation, nothing hidden, still fully usable ═════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.001ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  [data-reveal], [data-reveal-group] > * { opacity: 1 !important; translate: none !important; scale: 1 !important; filter: none !important; }
  .beam, .hero-particles, .nav-progress, .spot-edge, .spot-glow { display: none; }
  .hero-slash { transform: skewY(-1.2deg) scaleX(1); }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
