/* ==========================================================================
   M222HP GLORY — Multi-Layer Animated Atmospheric Backdrop
   ========================================================================== */
.m2-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  contain: strict;
  background:
    radial-gradient(ellipse 85% 60% at 50% -10%, rgba(var(--accent-rgb), 0.08), transparent 60%),
    linear-gradient(165deg, var(--bg-primary) 0%, var(--bg-secondary) 52%, var(--bg-primary) 100%);
}

/* Layer 2: Precision architectural grid */
.m2-bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 85% 75% at 50% 25%, #000 35%, transparent 95%);
  opacity: 0.72;
}

/* Layer 3: Soft slow-moving ambient glows */
.m2-bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(88px);
  will-change: transform;
  opacity: 0.55;
}

.m2-bg-orb--gold {
  width: min(56vw, 620px);
  height: min(56vw, 620px);
  top: -18%;
  left: -8%;
  background: radial-gradient(circle, rgba(var(--accent-rgb), 0.22) 0%, rgba(var(--accent-rgb), 0.04) 55%, transparent 72%);
}

.m2-bg-orb--violet {
  width: min(52vw, 580px);
  height: min(52vw, 580px);
  bottom: -20%;
  right: -10%;
  background: radial-gradient(circle, rgba(var(--accent-violet-rgb), 0.22) 0%, rgba(var(--accent-violet-rgb), 0.04) 55%, transparent 72%);
}

.m2-bg-orb--accent {
  width: min(36vw, 400px);
  height: min(36vw, 400px);
  top: 38%;
  right: 18%;
  background: radial-gradient(circle, rgba(var(--accent-rgb), 0.1) 0%, transparent 70%);
  opacity: 0.42;
}

/* Layer 4: Subtle particles canvas */
.m2-bg-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Compositor-only ambient motion when user allows motion & effects are on */
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-fx="off"]) .m2-bg-orb--gold {
    animation: m2FloatA 26s ease-in-out infinite alternate;
  }
  :root:not([data-fx="off"]) .m2-bg-orb--violet {
    animation: m2FloatB 32s ease-in-out infinite alternate;
  }
  :root:not([data-fx="off"]) .m2-bg-orb--accent {
    animation: m2FloatC 22s ease-in-out infinite alternate;
  }
}

@keyframes m2FloatA {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(7vw, 5vh, 0) scale(1.08); }
}

@keyframes m2FloatB {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-8vw, -6vh, 0) scale(1.1); }
}

@keyframes m2FloatC {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-5vw, 7vh, 0) scale(0.94); }
}

/* Effects disabled or reduced motion */
:root[data-fx="off"] .m2-bg-orb {
  opacity: 0.22;
  animation: none;
}

:root[data-fx="off"] .m2-bg-particles {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .m2-bg-particles {
    display: none;
  }
}

/* Strict SaaS Admin Mode: disable gaming glows and particles */
body.m2-admin-mode .m2-bg {
  background:
    radial-gradient(ellipse 75% 40% at 50% 0%, rgba(var(--accent-rgb), 0.045), transparent 65%),
    linear-gradient(180deg, var(--bg-primary), var(--bg-secondary));
}

body.m2-admin-mode .m2-bg-grid {
  background-size: 32px 32px;
  opacity: 0.45;
}

body.m2-admin-mode .m2-bg-orb,
body.m2-admin-mode .m2-bg-particles {
  display: none !important;
}
