/*
 * Hero logo animation.
 * Targets the SVG image of the Divi Image module that has the CSS class "hero-logo".
 * Works together with hero-logo.js, which inlines the SVG next to the <img>
 * and tags each path (shield / title letters / tagline letters / specks).
 *
 * Entry  : the shield outline is drawn, then filled; letters stamp in; specks settle.
 * Scroll : --p (0 → 1) is set on the SVG by the script; letters and specks scatter,
 *          the whole logo pushes in and fades out.
 */

@media (prefers-reduced-motion: no-preference) {

  /* ---------- Before the script has swapped the <img> for the inline SVG ---------- */

  /* Hide the original image so there is no flash before the animation starts.
     If the script never runs, the image is revealed after 3s. */
  .hero-logo img[src$=".svg"] {
    opacity: 0;
    animation: cit-logo-fallback 0.01s linear 3s forwards;
  }

  /* Once swapped, the <img> only keeps the layout space. */
  .hero-logo .cit-logo-host img.cit-logo-src {
    animation: none;
    opacity: 0;
    visibility: hidden;
  }

  .cit-logo-host {
    position: relative;
  }

  @keyframes cit-logo-fallback {
    to { opacity: 1; }
  }

  /* ---------- Inline SVG ---------- */
  .cit-logo {
    --p: 0;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    will-change: transform, opacity;

    /* scroll: push in + fade out */
    scale: calc(1 + var(--p) * 0.12);
    opacity: clamp(0, calc(1.1 - var(--p) * 1.2), 1);
  }

  .cit-logo:not(.is-in) {
    opacity: 0;
  }

  .cit-logo path {
    fill: var(--cit-logo-fill, #fff);
    transform-box: fill-box;
    transform-origin: 50% 50%;
  }

  /* ---------- Shield + tower + mug ---------- */
  .cit-logo .cit-shape {
    stroke: var(--cit-logo-fill, #fff);
    stroke-width: 2.5;
    stroke-dasharray: 1 1;
    stroke-opacity: 0;
  }

  .cit-logo.is-in .cit-shape {
    animation: cit-shape-in 2s cubic-bezier(0.65, 0, 0.35, 1) backwards;
  }

  @keyframes cit-shape-in {
    0%   { stroke-dashoffset: 1; stroke-opacity: 1; fill-opacity: 0; }
    60%  { stroke-dashoffset: 0; stroke-opacity: 1; fill-opacity: 0; }
    100% { stroke-dashoffset: 0; stroke-opacity: 0; fill-opacity: 1; }
  }

  /* ---------- Title letters ---------- */
  .cit-logo .cit-title {
    --q: clamp(0, calc((var(--p) - var(--d)) * 2.2), 1);
    translate: calc(var(--q) * var(--dx) * 1px) calc(var(--q) * var(--dy) * 1px);
    rotate: calc(var(--q) * var(--r) * 1deg);
    opacity: calc(1 - var(--q));
  }

  .cit-logo.is-in .cit-title {
    animation: cit-title-in 0.85s cubic-bezier(0.2, 0.9, 0.25, 1.15) var(--ed) backwards;
  }

  @keyframes cit-title-in {
    from { opacity: 0; transform: translateY(46px) scale(1.4) rotate(var(--ir)); }
    55%  { opacity: 1; }
    to   { opacity: 1; transform: none; }
  }

  /* ---------- Tagline letters ---------- */
  .cit-logo .cit-tag {
    --q: clamp(0, calc((var(--p) - var(--d)) * 2.2), 1);
    translate: calc(var(--q) * var(--dx) * 1px) calc(var(--q) * var(--dy) * 1px);
    rotate: calc(var(--q) * var(--r) * 1deg);
    opacity: calc(1 - var(--q));
  }

  .cit-logo.is-in .cit-tag {
    animation: cit-tag-in 0.6s ease-out var(--ed) backwards;
  }

  @keyframes cit-tag-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
  }

  /* ---------- Ink specks ---------- */
  .cit-logo .cit-speck {
    --q: clamp(0, calc(var(--p) * 2.2), 1);
    translate: calc(var(--q) * var(--dx) * 1px) calc(var(--q) * var(--dy) * 1px);
    rotate: calc(var(--q) * var(--r) * 1deg);
    opacity: calc(1 - var(--q));
  }

  .cit-logo.is-in .cit-speck {
    animation: cit-speck-in 0.5s ease-out var(--ed) backwards;
  }

  @keyframes cit-speck-in {
    from { opacity: 0; transform: scale(0.2); }
    to   { opacity: 1; transform: none; }
  }

  /* ---------- Default entry ("fill"; the script adds .cit-logo--fill) ----------
     Empty frame + mug (outline), then the white rises from the bottom;
     then the title letters fade in one after another, then the tagline.
     The "draw" entry above is used instead when the module also has "hero-logo--draw". */

  .cit-logo .cit-outline {
    fill: none;
    stroke: var(--cit-logo-fill, #fff);
    stroke-width: 3;
    stroke-opacity: 0;
  }

  .cit-logo.is-in .cit-outline {
    animation: cit-outline-in 2.7s linear backwards;
  }

  @keyframes cit-outline-in {
    0%   { stroke-opacity: 0; }
    18%  { stroke-opacity: 1; }
    96%  { stroke-opacity: 1; }
    100% { stroke-opacity: 0; }
  }

  /* The rising liquid (wavy clip-path on .cit-fill) is driven by hero-logo.js. */
  .cit-logo--fill.is-in .cit-title,
  .cit-logo--fill.is-in .cit-tag {
    animation: cit-fade-in 0.5s ease-out var(--ed) backwards;
  }

  .cit-logo--fill.is-in .cit-speck {
    animation: cit-fade-in 0.6s ease-out var(--ed) backwards;
  }

  @keyframes cit-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}
