/* ML / AI ambient background — neural net, attention, CV motifs */
.bg-ml {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-ml-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(248, 251, 252, 0.92) 0%,
    rgba(240, 244, 248, 0.55) 35%,
    rgba(238, 242, 247, 0.85) 100%
  );
  z-index: 4;
}

/* Attention-style rotating soft beams (transformer “spotlight” metaphor) */
.bg-ml-attention {
  position: absolute;
  inset: -50%;
  z-index: 0;
  background: conic-gradient(
    from 0deg at 50% 50%,
    transparent 0deg,
    rgba(99, 102, 241, 0.07) 45deg,
    transparent 90deg,
    rgba(13, 148, 136, 0.06) 140deg,
    transparent 200deg,
    rgba(99, 102, 241, 0.05) 260deg,
    transparent 360deg
  );
  animation: bg-ml-attention-spin 48s linear infinite;
}

.bg-ml-attention-2 {
  position: absolute;
  inset: -30%;
  z-index: 0;
  background: radial-gradient(
    ellipse 80% 50% at 70% 20%,
    rgba(99, 102, 241, 0.11),
    transparent 55%
  );
  animation: bg-ml-attention-drift 32s ease-in-out infinite alternate;
}

/* CV: faint “pixel / feature map” grid */
.bg-ml-cv-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0.35;
  background-image: linear-gradient(rgba(15, 23, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
  animation: bg-ml-cv-pan 80s linear infinite;
  mask-image: radial-gradient(ellipse 85% 70% at 50% 40%, black 15%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 85% 70% at 50% 40%, black 15%, transparent 70%);
}

/* Scan line (vision / frame capture metaphor) */
.bg-ml-scan {
  position: absolute;
  left: 0;
  right: 0;
  height: 120px;
  z-index: 2;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(13, 148, 136, 0.04),
    rgba(99, 102, 241, 0.05),
    transparent
  );
  animation: bg-ml-scan-move 14s ease-in-out infinite;
  opacity: 0.9;
}

/* Neural network SVG */
.bg-ml-net {
  position: absolute;
  left: 50%;
  top: 45%;
  width: min(140vw, 1600px);
  height: min(90vh, 900px);
  transform: translate(-50%, -50%);
  z-index: 3;
  opacity: 0.55;
}

.bg-ml-bbox rect {
  animation: bg-ml-bbox-dash 24s linear infinite;
}

.bg-ml-bbox rect:nth-child(2) {
  animation-duration: 32s;
  animation-direction: reverse;
}

@keyframes bg-ml-bbox-dash {
  to {
    stroke-dashoffset: -120;
  }
}

.bg-ml-edge {
  fill: none;
  stroke: rgba(13, 148, 136, 0.35);
  stroke-width: 1.2;
  stroke-linecap: round;
  animation: bg-ml-edge-flow 5s ease-in-out infinite;
}

.bg-ml-edge:nth-child(odd) {
  stroke: rgba(99, 102, 241, 0.3);
  animation-duration: 6.5s;
}

.bg-ml-edge:nth-child(3n) {
  animation-delay: -1.5s;
}

.bg-ml-edge:nth-child(5n) {
  animation-delay: -3s;
}

.bg-ml-node {
  animation: bg-ml-node-pulse 4s ease-in-out infinite;
}

.bg-ml-nodes > g:nth-child(odd) {
  animation-duration: 5.5s;
  animation-delay: -2s;
}

.bg-ml-node-core {
  fill: rgba(13, 148, 136, 0.9);
}

.bg-ml-node-halo {
  fill: none;
  stroke: rgba(99, 102, 241, 0.35);
  stroke-width: 1;
  opacity: 0.6;
}

.bg-ml-nodes > g:nth-child(3n) .bg-ml-node-core {
  fill: rgba(99, 102, 241, 0.8);
}

@keyframes bg-ml-attention-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes bg-ml-attention-drift {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 0.7;
  }
  100% {
    transform: translate(-8%, 5%) scale(1.08);
    opacity: 1;
  }
}

@keyframes bg-ml-cv-pan {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 24px 24px;
  }
}

@keyframes bg-ml-scan-move {
  0%,
  100% {
    top: -15%;
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  50% {
    top: 55%;
  }
  85% {
    opacity: 1;
  }
}

@keyframes bg-ml-edge-flow {
  0%,
  100% {
    stroke-opacity: 0.25;
  }
  50% {
    stroke-opacity: 0.85;
  }
}

@keyframes bg-ml-node-pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-ml-attention,
  .bg-ml-attention-2,
  .bg-ml-cv-grid,
  .bg-ml-scan,
  .bg-ml-edge,
  .bg-ml-node,
  .bg-ml-bbox rect {
    animation: none !important;
  }

  .bg-ml-net {
    opacity: 0.32;
  }
}

@media (max-width: 768px) {
  .bg-ml-net {
    opacity: 0.4;
    width: 180vw;
  }

  .bg-ml-attention {
    animation-duration: 72s;
  }
}
