/* animation.css */

:root {
  /* Motion tokens: change here, applies site-wide */
  --anim-accent: var(
    --swatch--royal-blue
  ); /* flash colour travelling through headings (point this at your highlight variable) */
  --anim-inactive: color-mix(
    in oklab,
    currentColor 12%,
    transparent
  ); /* heading colour before reveal */
  --anim-wave: 0.18; /* heading wave width, as a share of the heading's characters... */
  --anim-wave-min: 6; /* ...but never narrower than this many characters */
  --anim-line-room: 0.2em; /* extra room below masked lines so descenders are never cut */
  --anim-odo-gap: 0.15em; /* room above/below rolling digits so tall glyphs never get cut */
  --anim-draw-feather: 12%; /* soft leading edge of draw reveals (0% = hard edge) */
  --anim-draw-from: 0deg; /* where circles start drawing: 0deg = top, 180deg = bottom */
}

/* Gradient wave instead of a colour tint (Porcelain White headlines). No accent flash: characters
   go from the inactive colour to their own colour through a wide, soft gradient.
   Put the attribute on a heading or on a whole section, or swap the selector for your dark-section class. */
[data-anim-gradient] {
  --anim-accent: currentColor;
  --anim-wave: 0.45;
  --anim-wave-min: 14;
}

/* Start states (only with JS, only when motion is allowed) */
@media (prefers-reduced-motion: no-preference) {
  .js-anim [data-anim='heading']:not(.anim-split) {
    opacity: 0.12; /* matches the inactive colour until the split is ready */
  }
  .js-anim [data-anim='lines']:not(.anim-split),
  .js-anim [data-anim='text']:not(.anim-done) {
    opacity: 0.01; /* not 0: an opacity-0 element only counts for LCP once revealed (2026-11-24) */
  }
  .js-anim [data-anim='lines']:not(.anim-done) .anim-dash,
  .js-anim [data-anim='text']:not(.anim-done) .anim-dash {
    clip-path: inset(0 100% 0 0);
  }
  .js-anim [data-anim='odometer']:not(.anim-done),
  .js-anim [data-anim='draw']:not(.anim-done) {
    opacity: 0;
  }
  /* Feed cards (news, blog, Media Center, related posts) and customer story cards: no text reveal,
     only the card lines draw (Knox, 2026-11-25). animation.js skips these too.
     Same specificity as the start-state rule above, so it must come after it. */
  .js-anim .feed_card [data-anim='lines'],
  .js-anim .feed_card [data-anim='text'],
  .js-anim .stories_card [data-anim='lines'],
  .js-anim .stories_card [data-anim='text'] {
    opacity: 1;
  }
}

/* Heading wave: each character's colour is computed from one --p value on the heading.
     --t goes 0 → 1 as the wave passes a character: inactive → accent (0.5) → its real colour (1). */
[data-anim='heading'].anim-split {
  --w: max(var(--anim-wave-min), var(--n, 1) * var(--anim-wave));
}
.anim-char {
  display: inline !important; /* only colour animates, so keep chars inline for natural kerning */
  --t: clamp(0, (var(--p, 1) * (var(--n, 1) + var(--w, 1)) - var(--i, 0)) / var(--w, 1), 1);
  color: color-mix(
    in oklab,
    currentColor calc(clamp(0, var(--t) * 2 - 1, 1) * 100%),
    color-mix(
      in oklab,
      var(--anim-accent) calc(clamp(0, var(--t) * 2, 1) * 100%),
      var(--anim-inactive)
    )
  );
}

/* Lines: SplitText wraps each line in a mask. Lines only ever rise into place, so clip the bottom
   edge only (with room for descenders) and leave the top and sides free for tall glyphs. */
.anim-line-mask {
  overflow: visible !important;
  clip-path: inset(-1em -1em calc(-1 * var(--anim-line-room)) -1em);
}

/* Em dashes draw left to right: in heading waves with the wave, in lines once their line is up,
     in paragraphs after the fade */
.anim-char.is-dash,
.anim-dash {
  display: inline-block !important;
}
.anim-char.is-dash {
  clip-path: inset(0 calc((1 - var(--t)) * 100%) 0 0);
}

/* Draw: mask reveals driven by --draw (0 → 1), direction from data-anim-dir. The mask is only
     present while drawing. Stops are offset by the feather so 0 is fully hidden and 1 fully shown. */
.anim-drawing {
  --anim-draw-to: to right;
  --anim-draw-edge: calc(var(--draw, 1) * (100% + var(--anim-draw-feather)));
  -webkit-mask-image: linear-gradient(
    var(--anim-draw-to),
    #000 calc(var(--anim-draw-edge) - var(--anim-draw-feather)),
    transparent var(--anim-draw-edge)
  );
  mask-image: linear-gradient(
    var(--anim-draw-to),
    #000 calc(var(--anim-draw-edge) - var(--anim-draw-feather)),
    transparent var(--anim-draw-edge)
  );
}
.anim-drawing[data-anim-dir='left'] {
  --anim-draw-to: to left;
}
.anim-drawing[data-anim-dir='down'] {
  --anim-draw-to: to bottom;
}
.anim-drawing[data-anim-dir='up'] {
  --anim-draw-to: to top;
}

/* From the centre outwards (feather grows with the draw so 0 is fully hidden) */
.anim-drawing[data-anim-dir='center-x'],
.anim-drawing[data-anim-dir='center-y'] {
  --anim-draw-half: calc(var(--draw, 1) * (50% + var(--anim-draw-feather)));
  --anim-draw-soft: calc(var(--draw, 1) * var(--anim-draw-feather));
  -webkit-mask-image: linear-gradient(
    var(--anim-draw-to),
    transparent calc(50% - var(--anim-draw-half)),
    #000 calc(50% - var(--anim-draw-half) + var(--anim-draw-soft)),
    #000 calc(50% + var(--anim-draw-half) - var(--anim-draw-soft)),
    transparent calc(50% + var(--anim-draw-half))
  );
  mask-image: linear-gradient(
    var(--anim-draw-to),
    transparent calc(50% - var(--anim-draw-half)),
    #000 calc(50% - var(--anim-draw-half) + var(--anim-draw-soft)),
    #000 calc(50% + var(--anim-draw-half) - var(--anim-draw-soft)),
    transparent calc(50% + var(--anim-draw-half))
  );
}
.anim-drawing[data-anim-dir='center-y'] {
  --anim-draw-to: to bottom;
}

/* Circle: a conic sweep around the shape */
.anim-drawing[data-anim-dir='circle'] {
  -webkit-mask-image: conic-gradient(
    from var(--anim-draw-from),
    #000 calc(var(--draw, 1) * 1turn),
    transparent 0
  );
  mask-image: conic-gradient(
    from var(--anim-draw-from),
    #000 calc(var(--draw, 1) * 1turn),
    transparent 0
  );
}

/* Odometer: built by the script, real text kept for crawlers and screen readers */
.anim-odo {
  white-space: nowrap;
}
.anim-odo-digit {
  position: relative;
  display: inline-block;
  padding-block: var(--anim-odo-gap);
  margin-block: calc(-1 * var(--anim-odo-gap)); /* keeps the line height exactly as designed */
  overflow-x: visible;
  overflow-y: clip;
}
.anim-odo-size {
  visibility: hidden; /* sizes the column from the final digit */
}
.anim-odo-strip {
  position: absolute;
  top: 0;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;
}
.anim-odo-strip > span {
  display: block;
  padding-block: var(--anim-odo-gap);
}
.anim-odo-extra {
  display: inline-block;
  white-space: pre;
}
.anim-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
