/*==================================================================
  ELECTRICAL MOTIFS — shared by every page (component/motifs/Motifs.js)
  Circuit traces with flowing current, AC sine waves, electron
  orbits, a vertical power line that charges on scroll.
  Palette: --green (PES) / --red (PELS coral) from theme.css.
==================================================================*/

/* ---------- circuit board ---------- */
.pp-circuit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: var(--circuit-opacity, 0.5);
}

.pp-circuit__trace {
  fill: none;
  stroke: rgba(232, 238, 235, 0.09);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.pp-circuit__via {
  fill: var(--bg, #0b0f0e);
  stroke: rgba(232, 238, 235, 0.18);
  stroke-width: 1.4;
}

.pp-circuit__pulse {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 34 2000;
  stroke-dashoffset: 34;
  animation: pp-current 6s linear infinite;
  filter: drop-shadow(0 0 4px currentColor);
}

.pp-circuit--green .pp-circuit__pulse,
.pp-circuit--mix .is-a .pp-circuit__pulse { stroke: #6fd6a3; color: #4cc38a; }

.pp-circuit--red .pp-circuit__pulse,
.pp-circuit--mix .is-b .pp-circuit__pulse { stroke: #f08a8f; color: #e5636a; }

.pp-circuit--green .pp-circuit__via { stroke: rgba(76, 195, 138, 0.35); }
.pp-circuit--red .pp-circuit__via { stroke: rgba(229, 99, 106, 0.35); }
.pp-circuit--mix .is-a .pp-circuit__via { stroke: rgba(76, 195, 138, 0.35); }
.pp-circuit--mix .is-b .pp-circuit__via { stroke: rgba(229, 99, 106, 0.35); }

@keyframes pp-current {
  from { stroke-dashoffset: 34; }
  to { stroke-dashoffset: -1000; }
}

/* ---------- AC sine waves ---------- */
.pp-sine {
  display: block;
  width: 100%;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent);
}

.pp-sine__wave { animation: pp-sine 14s linear infinite; }
.pp-sine__wave.is-2 { animation-duration: 20s; animation-direction: reverse; opacity: 0.7; }
.pp-sine__wave.is-3 { animation-duration: 30s; opacity: 0.45; }

@keyframes pp-sine {
  from { transform: translateX(0); }
  to { transform: translateX(-1440px); }
}

/* ---------- electron orbits ---------- */
.pp-orbit {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  --orbit-green: #6fd6a3;
  --orbit-red: #f08a8f;
}

.pp-orbit__core {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
}

.pp-orbit__rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pp-orbit__ring {
  position: absolute;
  inset: 0;
  transform: rotate(var(--tilt, 0deg));
}

.pp-orbit__path {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(232, 238, 235, 0.12);
  transform: scaleY(0.36);
}

/* the electron rides a rotating wrapper so it follows the ellipse */
.pp-orbit__electron {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  animation: pp-orbit var(--spin, 8s) linear infinite;
}

.pp-orbit__electron::after {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  transform: scaleY(2.6); /* undo the ellipse squash so the dot stays round */
  background: var(--orbit-green);
  box-shadow: 0 0 10px 2px var(--orbit-green);
}

.pp-orbit--red .pp-orbit__electron::after,
.pp-orbit--mix .pp-orbit__ring:nth-child(2) .pp-orbit__electron::after {
  background: var(--orbit-red);
  box-shadow: 0 0 10px 2px var(--orbit-red);
}

.pp-orbit--green .pp-orbit__path { border-color: rgba(76, 195, 138, 0.22); }
.pp-orbit--red .pp-orbit__path { border-color: rgba(229, 99, 106, 0.22); }

@keyframes pp-orbit { to { transform: rotate(360deg); } }

/* ---------- vertical power line ---------- */
.pp-powerline {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: rgba(232, 238, 235, 0.08);
  pointer-events: none;
}

.pp-powerline__charge {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #6fd6a3, #4cc38a 45%, #e5636a);
  transform-origin: top center;
  transform: scaleY(var(--progress, 0));
  box-shadow: 0 0 12px rgba(76, 195, 138, 0.55);
}

.pp-powerline__spark {
  position: absolute;
  left: 50%;
  top: calc(var(--progress, 0) * 100%);
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(76, 195, 138, 0.25), 0 0 18px 4px rgba(76, 195, 138, 0.8);
  opacity: calc(var(--progress, 0) * 40); /* hidden until charging starts */
}

/* ---------- bolt ---------- */
.pp-bolt { display: inline-block; vertical-align: middle; flex: none; }

/* ---------- dotted engineering grid (utility background) ---------- */
.pp-dotgrid {
  background-image: radial-gradient(rgba(232, 238, 235, 0.08) 1px, transparent 1.2px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}

@media (prefers-reduced-motion: reduce) {
  .pp-circuit__pulse,
  .pp-sine__wave,
  .pp-orbit__electron { animation: none !important; }
  .pp-circuit__pulse { stroke-dashoffset: -300; }
}
