/* ═══════════════════════════════════════════════════════════════════════════
   ZeroDelay — motion layer

   Two rules govern everything here:

   1. Nothing animates that the reader has not scrolled to, and nothing
      animates twice. Reveals are one-shot: the observer drops the element the
      moment it lands, so scrolling back up never re-triggers anything.

   2. Every animation either explains the product or it does not ship. The
      traceroute rail draws downward because a packet travels downward; the
      problem hops flare red because that is where the latency is made. A card
      that merely slides in is doing the least it can do, so those get the
      shared reveal and nothing more.

   The whole file is inert under prefers-reduced-motion (section 7).
   ═════════════════════════════════════════════════════════════════════════ */

/* -- 1. Shared scroll reveal ----------------------------------------------- */
/* .reveal already existed in the markup on 32 elements but had no CSS behind
   it at all - it was dead decoration. This is what it was waiting for. */
.reveal {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity 0.55s cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 0.61, 0.36, 1);
  transition-delay: var(--zd-delay, 0ms);
  will-change: opacity, transform;
}
.reveal.is-in { opacity: 1; transform: none; }

/* Dropped once the element has landed, so a long page does not keep hundreds
   of composited layers alive. */
.reveal.is-done { will-change: auto; }

/* Directional variants. RTL-safe: the inline axis flips with the document. */
.reveal-start { transform: translate(1.5rem, 0); }
.reveal-end   { transform: translate(-1.5rem, 0); }
[dir="rtl"] .reveal-start { transform: translate(-1.5rem, 0); }
[dir="rtl"] .reveal-end   { transform: translate(1.5rem, 0); }
.reveal-scale { transform: scale(0.965); }
.reveal-start.is-in,
.reveal-end.is-in,
.reveal-scale.is-in { transform: none; }

/* -- 2. Traceroute: the "where does latency come from?" section ------------ */
/* This section argues that latency is made at two specific hops, not spread
   evenly across five. So the rail draws top-to-bottom like a trace running,
   each hop lands as the trace reaches it, and only the hops that matter pulse.

   The rail is .hops::before, which already carries the red-amber-cyan
   gradient. Scaling it from the top turns that existing gradient into a
   progress bar the reader watches fill. */
.hops.zd-trace::before {
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.hops.zd-trace.is-in::before { transform: scaleY(1); }

.hops.zd-trace .hop {
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition:
    opacity 0.5s ease-out var(--zd-delay, 0ms),
    transform 0.5s ease-out var(--zd-delay, 0ms);
}
.hops.zd-trace.is-in .hop { opacity: 1; transform: none; }

/* The dot snaps in just after its hop's text, so it reads as the trace
   arriving at that hop rather than the whole row simply fading up. */
.hops.zd-trace .hop-dot {
  transform: scale(0.4);
  opacity: 0;
  transition:
    transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) calc(var(--zd-delay, 0ms) + 90ms),
    opacity 0.28s ease-out calc(var(--zd-delay, 0ms) + 90ms);
}
.hops.zd-trace.is-in .hop-dot { transform: none; opacity: 1; }

/* A pulse ring on the hops that matter, drawn on a pseudo-element so it can
   never affect layout. The two problem hops flare twice and stop; the fix hop
   keeps a slow pulse, because that one is the answer. */
.hops.zd-trace .hop.is-problem .hop-dot::after,
.hops.zd-trace .hop.is-fix .hop-dot::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1px solid currentColor;
  opacity: 0;
  pointer-events: none;
}
.hops.zd-trace.is-in .hop.is-problem .hop-dot::after {
  animation: zd-hop-flare 1.9s ease-out calc(var(--zd-delay, 0ms) + 420ms) 2;
}
.hops.zd-trace.is-in .hop.is-fix .hop-dot::after {
  animation: zd-hop-flare 2.4s ease-out calc(var(--zd-delay, 0ms) + 420ms) infinite;
}
@keyframes zd-hop-flare {
  0%   { opacity: 0.85; transform: scale(1); }
  70%  { opacity: 0;    transform: scale(1.9); }
  100% { opacity: 0;    transform: scale(1.9); }
}

/* The packet itself, riding the rail once the trace has drawn. It stalls
   twice on the way down, at the two hops the copy beside it blames. The delay
   is shown rather than only described.

   --zd-rail (total travel) and --zd-stall-1 / --zd-stall-2 (the offsets of the
   two is-problem dots) are all measured from script. They cannot be constants:
   the hop copy wraps differently at every width, so a hardcoded fraction puts
   the pause in the gap between hops instead of on one. */
.hops.zd-trace .zd-packet {
  position: absolute;
  inset-inline-start: 11px;
  inset-block-start: 14px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px 2px rgba(var(--accent-rgb), 0.75);
  opacity: 0;
  pointer-events: none;
}
.hops.zd-trace.is-in .zd-packet {
  animation: zd-packet-run 2.8s cubic-bezier(0.5, 0, 0.5, 1) 0.5s infinite;
}
/* The two flat stretches (26→38% and 56→68%) are the stalls. They hold the
   packet exactly on a problem hop, which is why the offsets are measured
   rather than interpolated. */
@keyframes zd-packet-run {
  0%   { opacity: 0; transform: translateY(0); }
  6%   { opacity: 1; transform: translateY(0); }
  26%  { transform: translateY(var(--zd-stall-1, 100px)); }
  38%  { transform: translateY(var(--zd-stall-1, 100px)); }
  56%  { transform: translateY(var(--zd-stall-2, 200px)); }
  68%  { transform: translateY(var(--zd-stall-2, 200px)); }
  94%  { opacity: 1; transform: translateY(var(--zd-rail, 400px)); }
  100% { opacity: 0; transform: translateY(var(--zd-rail, 400px)); }
}

/* -- 3. Section headings --------------------------------------------------- */
/* The eyebrow labels what follows, so it arrives first and the heading comes
   after it. Reading order, rendered. */
.rule-head.reveal .eyebrow {
  display: inline-block;
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  transition: opacity 0.45s ease-out 60ms, transform 0.45s ease-out 60ms;
}
.rule-head.reveal.is-in .eyebrow { opacity: 1; transform: none; }

/* -- 4. Cards: features, plans, FAQ ---------------------------------------- */
/* Grids of peers. They stagger by DOM order (delay set from script) so the eye
   is led across the grid instead of the whole row landing at once. */
.card.reveal { transform: translate3d(0, 20px, 0) scale(0.99); }
.card.reveal.is-in { transform: none; }

.faq-item.reveal { transform: translate3d(0, 12px, 0); }
.faq-item.reveal.is-in { transform: none; }

/* -- 5. Download call to action -------------------------------------------- */
/* One slow breath. It is the last thing on the page and the only thing asking
   for a click, so it is allowed to keep moving. */
.card-ambient.is-in .ambient-mark {
  animation: zd-breathe 6s ease-in-out infinite;
}
@keyframes zd-breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50%      { opacity: 0.9;  transform: scale(1.04); }
}

/* -- 6. Numeric counters --------------------------------------------------- */
/* Counted up by script; this only stops the digits reflowing the line as the
   value widens. */
.zd-count { font-variant-numeric: tabular-nums; }

/* -- 7. Reduced motion ----------------------------------------------------- */
/* Everything above collapses to "already visible": no transitions, no
   keyframes, no packet - and nothing is lost, because every animation here
   decorates content that is present either way. */
@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal-start,
  .reveal-end,
  .reveal-scale,
  .card.reveal,
  .faq-item.reveal,
  .hops.zd-trace .hop,
  .hops.zd-trace .hop-dot,
  .rule-head.reveal .eyebrow {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .hops.zd-trace::before { transform: none !important; transition: none !important; }
  .hops.zd-trace .zd-packet { display: none; }
  .hops.zd-trace.is-in .hop.is-problem .hop-dot::after,
  .hops.zd-trace.is-in .hop.is-fix .hop-dot::after,
  .card-ambient.is-in .ambient-mark { animation: none !important; }
}
