/* Animated PulseDrivers navbar logo
   Loaded site-wide: add 'pd-logo.css' to default_packages in
   info/content_manager.py (after 'main.css' is fine).

   8s loop, no overlap:
     0.00–2.50s  red pulse heartbeat + a left-to-right energy trace
     2.50–3.00s  rest
     3.00–6.00s  diagonal shine sweep across the wordmark only
     6.00–8.00s  rest, then repeat

   Static frame (t=0, or prefers-reduced-motion) is the logo itself.
*/

.pd-logo {
  --pd-logo-red: #d01820;
  --pd-logo-glow: #ff5a5f;
  --pd-logo-pulse-img: url("../images/logo-pulse.png");
  --pd-logo-pulse-img: image-set(
    url("../images/logo-pulse.webp") type("image/webp"),
    url("../images/logo-pulse.png") type("image/png")
  );
  --pd-logo-text-img: url("../images/logo-text.png");
  --pd-logo-text-img: image-set(
    url("../images/logo-text.webp") type("image/webp"),
    url("../images/logo-text.png") type("image/png")
  );
}

.pd-logo-mark {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.pd-logo-base {
  display: block;
  height: 45px;
  width: auto;
}

/* Shared overlay box, aligned to the base image. */
.pd-logo-pulse,
.pd-logo-trace,
.pd-logo-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---- Pulse: glow / brightness heartbeat on the red bars + zigzag ----
   The overlay is the pulse artwork itself (not a pink fill + screen blend,
   which washed the red toward pastel). Peaks boost brightness and
   saturation, and add a larger #d01820 / #ff5a5f glow. */
.pd-logo-pulse {
  background-image: var(--pd-logo-pulse-img);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  animation: pd-logo-heartbeat 8s linear infinite;
}

/* Traveling energy highlight, clipped to the red artwork. */
.pd-logo-trace {
  -webkit-mask-image: var(--pd-logo-pulse-img);
          mask-image: var(--pd-logo-pulse-img);
  -webkit-mask-size: 100% 100%;
          mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
  -webkit-mask-position: center;
          mask-position: center;
  mask-mode: alpha;
  overflow: hidden;
  opacity: 0;
  animation: pd-logo-trace-fade 8s linear infinite;
}

.pd-logo-trace::after {
  content: "";
  position: absolute;
  top: -40%;
  height: 180%;
  width: 38%;
  left: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(208, 24, 32, 0) 18%,
    rgba(208, 24, 32, .55) 38%,
    rgba(255, 90, 95, .85) 50%,
    rgba(208, 24, 32, .7) 64%,
    transparent 100%
  );
  transform: translateX(-140%) skewX(-18deg);
  filter: blur(.45px);
  animation: pd-logo-trace-sweep 8s cubic-bezier(.22, .7, .3, 1) infinite;
}

/* ---- Shine: diagonal light band, clipped to the wordmark only ---- */
.pd-logo-shine {
  -webkit-mask-image: var(--pd-logo-text-img);
          mask-image: var(--pd-logo-text-img);
  -webkit-mask-size: 100% 100%;
          mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
  -webkit-mask-position: center;
          mask-position: center;
  mask-mode: alpha;
  overflow: hidden;
  opacity: 0;
  animation: pd-logo-shine-fade 8s linear infinite;
}

.pd-logo-shine::after {
  content: "";
  position: absolute;
  top: -60%;
  height: 220%;
  width: 34%;
  left: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0) 28%,
    rgba(255, 255, 255, .35) 44%,
    rgba(255, 255, 255, .92) 50%,
    rgba(255, 255, 255, .35) 56%,
    transparent 75%
  );
  transform: translateX(-160%) skewX(-24deg);
  animation: pd-logo-shine-sweep 8s ease-in-out infinite;
}

/* Heartbeat: lub-dub, then a soft decay, fully off by 2.5s.
   Percent of the 8s loop: 1% = 0.08s. */
@keyframes pd-logo-heartbeat {
  0% {
    opacity: 0;
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 transparent);
  }
  /* first beat, lighter */
  1.75% { /* 0.14s */
    opacity: .9;
    filter:
      brightness(1.28) saturate(1.45)
      drop-shadow(0 0 2px var(--pd-logo-glow))
      drop-shadow(0 0 6px var(--pd-logo-red));
  }
  4.25% { /* 0.34s */
    opacity: .2;
    filter:
      brightness(1.05) saturate(1.1)
      drop-shadow(0 0 2px rgba(208, 24, 32, .4));
  }
  /* second beat, stronger */
  5.75% { /* 0.46s */
    opacity: .22;
    filter:
      brightness(1.06) saturate(1.1)
      drop-shadow(0 0 2px rgba(208, 24, 32, .4));
  }
  8.75% { /* 0.70s */
    opacity: 1;
    filter:
      brightness(1.45) saturate(1.6)
      drop-shadow(0 0 3px var(--pd-logo-glow))
      drop-shadow(0 0 7px var(--pd-logo-red));
  }
  16% { /* 1.28s */
    opacity: .4;
    filter:
      brightness(1.18) saturate(1.3)
      drop-shadow(0 0 3px var(--pd-logo-red));
  }
  25% { /* 2.00s */
    opacity: .1;
    filter:
      brightness(1.05) saturate(1.08)
      drop-shadow(0 0 2px rgba(208, 24, 32, .35));
  }
  31.25%, /* 2.50s */
  100% {
    opacity: 0;
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 transparent);
  }
}

@keyframes pd-logo-trace-fade {
  0%,
  4% { opacity: 0; }        /* hold until 0.32s, after the first beat */
  6%,
  26% { opacity: 1; }       /* 0.48–2.08s */
  31.25%,                  /* 2.50s */
  100% { opacity: 0; }
}

@keyframes pd-logo-trace-sweep {
  0%,
  5% { transform: translateX(-140%) skewX(-18deg); } /* start 0.40s */
  28% { transform: translateX(500%) skewX(-18deg); } /* ~2.24s, off the right */
  28.01%,
  100% { transform: translateX(-140%) skewX(-18deg); }
}

@keyframes pd-logo-shine-fade {
  0%,
  36.5% { opacity: 0; }     /* until 2.92s */
  38.75% { opacity: 1; }    /* 3.10s */
  73% { opacity: 1; }       /* 5.84s */
  75%,                      /* 6.00s */
  100% { opacity: 0; }
}

@keyframes pd-logo-shine-sweep {
  0%,
  37.5% { transform: translateX(-160%) skewX(-24deg); } /* 3.00s, off the left */
  75% { transform: translateX(480%) skewX(-24deg); }    /* 6.00s, off the right */
  75.01%,
  100% { transform: translateX(-160%) skewX(-24deg); }
}

/* Compare / preview helper: freeze as the static logo. */
.pd-logo.is-static .pd-logo-pulse,
.pd-logo.is-static .pd-logo-trace,
.pd-logo.is-static .pd-logo-shine,
.pd-logo.is-static .pd-logo-trace::after,
.pd-logo.is-static .pd-logo-shine::after {
  animation: none !important;
  opacity: 0 !important;
  filter: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .pd-logo-pulse,
  .pd-logo-trace,
  .pd-logo-shine,
  .pd-logo-trace::after,
  .pd-logo-shine::after {
    animation: none !important;
    opacity: 0 !important;
    filter: none !important;
  }
}
