/* ============================================================
   animations.css — motion, and the rules for switching it off

   The brief allows exactly four moments of motion:
     1. One orchestrated page-load beat on the homepage hero.
     2. Scroll-triggered fade/rise on section entry (~400ms, eased).
     3. Hover: card lift + outcome-stat reveal, button scale.
     4. The trace node pulse — the one ambient loop on the site.
   Anything beyond that was cut. Resist adding more here.
   ============================================================ */

/* ============================================================
   1. Scroll reveal
   Elements carry [data-reveal] and are revealed by
   scripts/scroll-reveal.js adding .is-revealed.

   Failure modes covered:
     - JS disabled  → @media (scripting: none) below shows everything.
     - JS errors    → scroll-reveal.js has a safety timeout that
                      reveals all remaining elements.
     - Reduced motion → revealed instantly, no transform.
   ============================================================ */

[data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-slow) var(--ease-out),
              transform var(--dur-slow) var(--ease-out);
  will-change: opacity, transform;
}

[data-reveal].is-revealed {
  opacity: 1;
  transform: none;
  will-change: auto;
}

/* Stagger within a group. Steps of 80ms — enough to read as a
   sequence, short enough not to feel like waiting. */
[data-reveal-delay="1"] { transition-delay: 80ms; }
[data-reveal-delay="2"] { transition-delay: 160ms; }
[data-reveal-delay="3"] { transition-delay: 240ms; }
[data-reveal-delay="4"] { transition-delay: 320ms; }

@media (scripting: none) {
  [data-reveal] { opacity: 1; transform: none; }
}

/* ============================================================
   2. Homepage hero load
   Pure CSS, so it runs whether or not JS is available.
   Sequence: headline lines rise → trace draws → pulse departs.
   ============================================================ */

.hero__title .line > span {
  animation: line-rise 900ms var(--ease-out) both;
}

.hero__title .line:nth-child(1) > span { animation-delay: 100ms; }
.hero__title .line:nth-child(2) > span { animation-delay: 200ms; }

@keyframes line-rise {
  from { transform: translateY(105%); }
  to   { transform: translateY(0); }
}

/* The pipeline trace draws itself in, left to right. */
.pipe__flow {
  animation: pipe-draw 1400ms var(--ease-out) 500ms both;
}

@keyframes pipe-draw {
  to { stroke-dashoffset: 0; }
}

/* Nodes light up as the trace reaches them. */
.pipe__nodes circle {
  opacity: 0;
  animation: node-in 400ms var(--ease-out) both;
}

.pipe__nodes circle:nth-child(1) { animation-delay: 620ms; }
.pipe__nodes circle:nth-child(2) { animation-delay: 900ms; }
.pipe__nodes circle:nth-child(3) { animation-delay: 1180ms; }
.pipe__nodes circle:nth-child(4) { animation-delay: 1460ms; }
.pipe__nodes circle:nth-child(5) { animation-delay: 1740ms; }

@keyframes node-in {
  from { opacity: 0; transform: scale(0.4); transform-origin: center; }
  to   { opacity: 1; transform: scale(1); }
}

.pipe__labels text,
.pipe__meta text {
  opacity: 0;
  animation: fade-in 500ms var(--ease-out) 1500ms both;
}

@keyframes fade-in { to { opacity: 1; } }
.pipe__meta text { animation-name: fade-in-dim; }
@keyframes fade-in-dim { to { opacity: 0.7; } }

/* A packet travelling the pipeline. This is the one ambient loop
   in the hero, and it is slow enough to read as a status light
   rather than an animation demanding attention. */
.pipe__pulse {
  opacity: 0;
  animation: pulse-travel 4.5s var(--ease-soft) 2.2s infinite;
}

@keyframes pulse-travel {
  0%        { transform: translateX(0);     opacity: 0; }
  6%        { opacity: 1; }
  88%       { opacity: 1; }
  94%, 100% { transform: translateX(600px); opacity: 0; }
}

/* ============================================================
   3. The trace spine
   Fill height and node position are set by scroll-reveal.js from
   scroll progress. Only the node's pulse is autonomous.
   ============================================================ */

.trace__fill {
  transition: height 120ms linear;
}

@media (min-width: 1200px) {
  .trace__node { transition: top 120ms linear; }

  /* The halo, not the node itself — scaling the node would make the
     spine's position ambiguous. */
  .trace__node::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1px solid var(--signal);
    animation: node-pulse 2.4s var(--ease-soft) infinite;
  }
}

@keyframes node-pulse {
  0%   { transform: scale(0.6); opacity: 0.9; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* "Available for new projects" — same pulse language, footer scale. */
.status__dot {
  position: relative;
}

.status__dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid var(--signal);
  animation: node-pulse 2.4s var(--ease-soft) infinite;
}

.status__dot--muted::after { display: none; }

/* Reading progress on articles. */
.read-progress > span { transition: width 100ms linear; }

/* ============================================================
   4. Hover
   ============================================================ */

.case__link,
.work-card__link,
.post-card__link,
.product,
.quote-card {
  transition: transform var(--dur) var(--ease-out);
}

@media (hover: hover) and (min-width: 768px) {
  .case__link:hover,
  .work-card__link:hover,
  .post-card__link:hover { transform: translateY(-4px); }

  .work-card__link:focus-visible,
  .post-card__link:focus-visible { transform: translateY(-4px); }
}

/* The outcome stat is revealed on hover, per the brief — but it is
   never *only* available on hover. It is visible by default on
   touch, on narrow screens, on keyboard focus, and under reduced
   motion. The hover reveal is an enhancement on top of that. */
@media (hover: hover) and (min-width: 1024px) and (prefers-reduced-motion: no-preference) {
  .case__stat {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity var(--dur) var(--ease-out),
                transform var(--dur) var(--ease-out);
  }

  .case__link:hover .case__stat,
  .case__link:focus-visible .case__stat,
  .case:focus-within .case__stat {
    opacity: 1;
    transform: none;
  }
}

/* ============================================================
   Reduced motion
   base.css already flattens every duration. These rules undo the
   *starting states* that would otherwise leave content invisible
   or mid-transform when the animation never plays.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {

  [data-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .hero__title .line > span { animation: none; transform: none; }

  .pipe__flow { animation: none; stroke-dashoffset: 0; }
  .pipe__nodes circle { animation: none; opacity: 1; transform: none; }
  .pipe__labels text { animation: none; opacity: 1; }
  .pipe__meta text { animation: none; opacity: 0.7; }

  /* The travelling packet is decoration and is dropped entirely.
     The trace still fills with scroll — that is a progress
     indicator, not motion for its own sake, so it stays. */
  .pipe__pulse { animation: none; opacity: 0; }

  .trace__node::after,
  .status__dot::after { animation: none; opacity: 0; }

  .case__stat { opacity: 1; transform: none; }

  .case__link:hover,
  .work-card__link:hover,
  .post-card__link:hover { transform: none; }

  .btn--signal:hover,
  .btn--ghost:hover,
  .carousel__btn:hover:not([disabled]) { transform: none; }

  .carousel__track { scroll-behavior: auto; }
}
