/* XBOTNOW hero background: realistic ESP32 scene, current flowing along the wires, light 3D tilt.
   Sits behind the homepage hero text (markup in modules/home/page.html). All class names start with xb-bg so nothing clashes. */

.xb-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* The scene keeps the photo's aspect ratio, is 70% of the hero height, centred vertically and anchored to the right
   and moved in from the right edge on wide screens, where there is room between the text and the parts
   (none on 1366px screens, growing to 7vw at about 1800px). */
.xb-bg__scene {
  position: absolute;
  top: 15%;
  right: clamp(0px, calc((100vw - 1366px) * .3), 7vw);
  height: 70%;
  aspect-ratio: 1751 / 898;
  perspective: 1600px;
  /* soft right edge, so the photo does not end in a hard line now that it no longer touches the screen edge */
  -webkit-mask-image: linear-gradient(90deg, #000 86%, transparent);
  mask-image: linear-gradient(90deg, #000 86%, transparent);
}
.xb-bg__tilt {
  position: absolute;
  inset: 0;
  transform: rotateX(var(--xb-rx, 6deg)) rotateY(var(--xb-ry, -8deg)) scale(1.03);
  transform-origin: 66% 50%;
  transform-style: preserve-3d;
  transition: transform 700ms cubic-bezier(.2, .8, .2, 1);
}
.xb-bg__img,
.xb-bg__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.xb-bg__svg { overflow: visible; }

/* A soft light that sweeps across the scene every few seconds */
.xb-bg__sweep {
  position: absolute;
  inset: 0;
  overflow: hidden;
  mix-blend-mode: screen;
}
.xb-bg__sweep span {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: xb-bg-sweep 7s ease-in-out 1s infinite;
}

/* Blends the scene into the page background (#fafbfc): solid behind the text on the left, soft at the top and bottom. */
.xb-bg__fade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, #fafbfc 0%, #fafbfc 43%, rgba(250, 251, 252, .86) 51%, rgba(250, 251, 252, 0) 69%),
    linear-gradient(180deg, #fafbfc 0%, #fafbfc 17%, transparent 32%, transparent 68%, #fafbfc 82%);
}

@keyframes xb-bg-pulse { from { stroke-dashoffset: 60; } to { stroke-dashoffset: -1000; } }
@keyframes xb-bg-pad   { 0%, 90% { opacity: 0; } 95% { opacity: 0.9; } 100% { opacity: 0; } }
@keyframes xb-bg-sweep { 0% { transform: translateX(-30%); } 100% { transform: translateX(130%); } }

/* Paused while off screen or while the tab is hidden (set by hero-bg.js) */
.xb-bg.is-paused * { animation-play-state: paused !important; }

/* Tablets: a little smaller and further right, with a wider fade */
@media (max-width: 1000px) {
  .xb-bg__scene { top: 16%; height: 68%; right: -8%; }
  .xb-bg__fade {
    background:
      linear-gradient(90deg, #fafbfc 0%, rgba(250, 251, 252, .94) 34%, transparent 76%),
      linear-gradient(180deg, #fafbfc, transparent 25%, transparent 75%, #fafbfc);
  }
}
/* Phones: the scene sits at the bottom, fainter, mostly hidden behind the text */
@media (max-width: 760px) {
  .xb-bg__scene { top: auto; bottom: 0; height: 76%; right: -60vw; opacity: .56; -webkit-mask-image: none; mask-image: none; }
  .xb-bg__fade {
    background:
      linear-gradient(180deg, #fafbfc 0%, #fafbfc 20%, rgba(250, 251, 252, .93) 38%, rgba(250, 251, 252, .66) 65%, rgba(250, 251, 252, .22) 100%),
      linear-gradient(90deg, rgba(250, 251, 252, .85), transparent 70%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .xb-bg * { animation: none !important; transition: none !important; }
}
