/**
 * Optimal Nexus - Compact ECG Pulse Animation
 * Positioned to the right of hero text
 */

/* CSS Variables for breathing glow */
:root {
  --ekg-breath-strength: 0.55;   /* base breathing intensity (0.35–0.7 sweet spot) */
  --ekg-breath-duration: 4.2s;   /* match/echo pulse cycle */
  --ekg-flare-boost: 1.8;        /* extra brightness when hero enters/re-enters */
}

/* Hero container with flex layout */
.onx-hero {
  position: relative;
  padding: 96px 24px 72px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  max-width: var(--onx-max, 1200px);
  margin: 0 auto;
}

/* Hero content (text) */
.onx-hero__content {
  position: relative;
  z-index: 3;
  flex: 1;
  max-width: 700px;
}

.onx-hero h1 {
  font-size: clamp(2.25rem, 4vw, 3rem);
  line-height: 1.15;
  margin: 0 0 12px;
  text-align: left;
}

.onx-hero__sub {
  color: var(--onx-muted);
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
  margin: 0 0 28px;
  text-align: left;
}

/* Compact ECG container - DOUBLED SIZE */
.onx-hero-ekg {
  position: relative;
  width: 440px;
  height: 160px;
  margin-left: 40px;
  overflow: hidden;
  flex-shrink: 0;
}

/* Red baseline with gradient - DOUBLED THICKNESS */
.onx-hero-ekg::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  background: linear-gradient(90deg,
    rgba(229, 0, 0, 0) 0%,
    rgba(229, 0, 0, 0.35) 10%,
    rgba(229, 0, 0, 0.55) 50%,
    rgba(229, 0, 0, 0.35) 90%,
    rgba(229, 0, 0, 0) 100%);
  border-radius: 9999px;
  filter: drop-shadow(0 0 6px rgba(229, 0, 0, 0.45));
}

/* Moving ECG pulse spike with white flash - DOUBLED SIZE */
.onx-hero-ekg::after {
  content: "";
  position: absolute;
  top: 50%;
  left: -20%;
  transform: translateY(-50%);
  width: 12px;
  height: 8px;
  background: linear-gradient(180deg, #ff2a2a, #b00000);
  border-radius: 9999px;
  box-shadow:
    0 0 50px rgba(229, 0, 0, 0.9),
    0 0 120px rgba(229, 0, 0, 0.45),
    0 0 200px rgba(229, 0, 0, 0.25);
  animation:
    onx-ekg-move 4.2s linear infinite,
    onx-ekg-beat 1.2s cubic-bezier(0.22, 0.61, 0.36, 1) infinite,
    onx-ekg-flash 4.2s linear infinite;
  will-change: transform, height, left, filter, box-shadow;
}

/* Gentler heartbeat curve: ramp-up, rounded peak, glide-down, small rebound */
@keyframes onx-ekg-beat {
  0%   { height: 8px; }
  10%  { height: 10px; }
  14%  { height: 90px; }      /* main rise (gentler than before) */
  16%  { height: 120px; }     /* soft rounded peak */
  18%  { height: 20px; }      /* glide down, not a cliff */
  22%  { height: 50px; }      /* rebound hump (curved) */
  28%  { height: 12px; }
  100% { height: 8px; }
}

/* Horizontal movement animation */
@keyframes onx-ekg-move {
  0%   { left: -20%; }
  100% { left: 120%; }
}

/* White flash "pop" effect near mid track */
@keyframes onx-ekg-flash {
  0%, 86% {
    box-shadow:
      0 0 50px rgba(229, 0, 0, 0.9),
      0 0 120px rgba(229, 0, 0, 0.45),
      0 0 200px rgba(229, 0, 0, 0.25);
    filter: brightness(1);
  }
  88% {
    box-shadow:
      0 0 60px rgba(255, 255, 255, 0.95),
      0 0 100px rgba(255, 255, 255, 0.6),
      0 0 140px rgba(229, 0, 0, 0.5);
    filter: brightness(1.8);
  }
  92% {
    box-shadow:
      0 0 55px rgba(255, 255, 255, 0.7),
      0 0 90px rgba(255, 255, 255, 0.4),
      0 0 130px rgba(229, 0, 0, 0.4);
    filter: brightness(1.4);
  }
  96%, 100% {
    box-shadow:
      0 0 50px rgba(229, 0, 0, 0.9),
      0 0 120px rgba(229, 0, 0, 0.45),
      0 0 200px rgba(229, 0, 0, 0.25);
    filter: brightness(1);
  }
}

/* ========================================
   Breathing Glow Animation
   ======================================== */

/* Attach breathing animation to hero wrapper */
.onx-hero-breathe .onx-hero-ekg::before,
.onx-hero-breathe .onx-hero-ekg::after {
  animation-duration: var(--ekg-breath-duration);
}

/* Baseline breathing glow (very subtle) */
.onx-hero-breathe .onx-hero-ekg::before {
  animation-name: onx-breathe-line;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

/* Dot glow also "breathes" slightly */
.onx-hero-breathe .onx-hero-ekg::after {
  animation-name: onx-breathe-dot, onx-ekg-move, onx-ekg-beat, onx-ekg-flash;
  animation-timing-function: ease-in-out, linear, cubic-bezier(0.22, 0.61, 0.36, 1), linear;
  animation-iteration-count: infinite, infinite, infinite, infinite;
}

/* Flare sync: applied via JS on enter — briefly boosts brightness */
.onx-hero-breathe.is-inview .onx-hero-ekg {
  filter: brightness(var(--ekg-flare-boost));
}

.onx-hero-breathe .onx-hero-ekg {
  transition: filter 0.45s ease; /* smooth settle after flare */
}

/* Breathing animation keyframes */
@keyframes onx-breathe-line {
  0% {
    filter: drop-shadow(0 0 6px rgba(229, 0, 0, 0.35)) drop-shadow(0 0 14px rgba(229, 0, 0, 0.18));
    opacity: 0.92;
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(229, 0, 0, 0.45)) drop-shadow(0 0 22px rgba(229, 0, 0, 0.22));
    opacity: calc(0.92 + 0.05 * var(--ekg-breath-strength));
  }
  100% {
    filter: drop-shadow(0 0 6px rgba(229, 0, 0, 0.35)) drop-shadow(0 0 14px rgba(229, 0, 0, 0.18));
    opacity: 0.92;
  }
}

@keyframes onx-breathe-dot {
  0% {
    box-shadow: 0 0 40px rgba(229, 0, 0, 0.75), 0 0 120px rgba(229, 0, 0, 0.35);
  }
  50% {
    box-shadow: 0 0 60px rgba(229, 0, 0, 0.9), 0 0 160px rgba(229, 0, 0, 0.45);
  }
  100% {
    box-shadow: 0 0 40px rgba(229, 0, 0, 0.75), 0 0 120px rgba(229, 0, 0, 0.35);
  }
}

/* Flash restart helper for JS re-triggering */
.onx-hero-flash-restart .onx-hero-ekg::after {
  animation: onx-breathe-dot 4.2s ease-in-out infinite,
             onx-ekg-move 4.2s linear infinite,
             onx-ekg-beat 1.2s cubic-bezier(0.22, 0.61, 0.36, 1) infinite,
             onx-ekg-flash 4.2s linear infinite;
}

/* Disable animations for reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .onx-hero-ekg::after {
    animation: none !important;
    display: none;
  }

  .onx-hero-breathe .onx-hero-ekg::before,
  .onx-hero-breathe .onx-hero-ekg::after {
    animation: none !important;
  }

  .onx-hero-breathe .onx-hero-ekg {
    filter: none !important;
  }
}

/* Mobile perf: tone down heavy blurs on small screens */
@media (max-width: 640px) {
  .onx-hero-breathe .onx-hero-ekg::before {
    filter: drop-shadow(0 0 5px rgba(229, 0, 0, 0.3)) !important;
  }

  .onx-hero-breathe .onx-hero-ekg::after {
    box-shadow: 0 0 36px rgba(229, 0, 0, 0.7), 0 0 96px rgba(229, 0, 0, 0.35) !important;
  }
}

/* Responsive: Stack on mobile */
@media (max-width: 768px) {
  .onx-hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 72px 24px 60px;
  }

  .onx-hero__content {
    max-width: 100%;
  }

  .onx-hero h1,
  .onx-hero__sub {
    text-align: center;
  }

  .onx-hero-ekg {
    width: 320px;
    height: 120px;
    margin: 32px auto 0;
  }
}
