/**
 * Subtle atmospheric layer for music/training surfaces.
 * Add: <div class="jg-ambient jg-ambient--music" aria-hidden="true"></div> as first body child.
 * Requires body.jg-ambient-page for correct stacking (see below).
 */

.jg-ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

body.jg-ambient-page {
  isolation: isolate;
  position: relative;
}

/* Soft drifting “score” dots + faint staff lines — pure CSS, low contrast */
.jg-ambient--music::before,
.jg-ambient--music::after {
  content: "";
  position: absolute;
  inset: -5%;
  opacity: 0.14;
  background-repeat: repeat;
  background-size: 120px 90px, 100% 100%;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(27, 111, 168, 0.35) 0, transparent 38%),
    radial-gradient(circle at 80% 70%, rgba(154, 114, 36, 0.2) 0, transparent 36%),
    linear-gradient(
      165deg,
      transparent 0%,
      rgba(27, 111, 168, 0.06) 45%,
      transparent 100%
    );
  animation: jg-ambient-drift-a 85s linear infinite;
}

.jg-ambient--music::after {
  opacity: 0.1;
  background-size: 140px 100px, 100% 100%;
  background-image:
    linear-gradient(
      105deg,
      rgba(154, 114, 36, 0.07) 0%,
      transparent 30%,
      rgba(27, 111, 168, 0.05) 70%,
      transparent 100%
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 18px,
      rgba(27, 111, 168, 0.045) 18px,
      rgba(27, 111, 168, 0.045) 19px
    );
  animation: jg-ambient-drift-b 110s linear infinite reverse;
}

@keyframes jg-ambient-drift-a {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  50% {
    transform: translate3d(-1.2%, 0.8%, 0) rotate(0.4deg);
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
}

@keyframes jg-ambient-drift-b {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(1.5%, -1%, 0) scale(1.02);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
}

/* Marketing pages — even quieter */
.jg-ambient--marketing::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background: radial-gradient(
    ellipse 80% 50% at 50% 0%,
    rgba(201, 151, 63, 0.2),
    transparent 60%
  );
  animation: jg-ambient-drift-a 120s linear infinite;
}

@media (max-width: 900px) {
  .jg-ambient--marketing::before {
    animation: none;
    opacity: 0.06;
  }
}

.jg-ambient--marketing::after {
  display: none;
}

html[data-theme="sunlit"] .jg-ambient--music::before,
html[data-theme="sunlit"] .jg-ambient--music::after {
  opacity: 0.12;
}

html:not([data-theme]) .jg-ambient--music::before,
html:not([data-theme]) .jg-ambient--music::after {
  opacity: 0.1;
}

@media (prefers-reduced-motion: reduce) {
  .jg-ambient--music::before,
  .jg-ambient--music::after,
  .jg-ambient--marketing::before {
    animation: none !important;
  }
  .jg-ambient {
    opacity: 0.85;
  }
}

/* Fixed return chip — interior marketing pages (see layout.js mountMarketingReturn) */
.jg-marketing-return {
  position: fixed;
  z-index: 40;
  /* Sit just below sticky marketing nav (~48px + bar padding) so chip and bar do not stack */
  top: calc(58px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 14px 9px 11px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
  color: rgba(26, 26, 30, 0.74);
  background: rgba(253, 251, 246, 0.78);
  border: 1px solid rgba(120, 95, 55, 0.14);
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 18px rgba(26, 26, 30, 0.055);
  max-width: min(48vw, 200px);
}

html[data-theme="dark"] .jg-marketing-return {
  color: rgba(247, 242, 234, 0.88);
  background: rgba(28, 26, 22, 0.75);
  border-color: rgba(214, 175, 92, 0.2);
}

.jg-marketing-return:hover {
  border-color: rgba(27, 111, 168, 0.35);
  color: #1b6fa8;
}

.jg-marketing-return:focus-visible {
  outline: 2px solid rgba(27, 111, 168, 0.55);
  outline-offset: 2px;
}

.jg-marketing-return__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .jg-marketing-return {
    top: calc(62px + env(safe-area-inset-top, 0px));
    left: calc(14px + env(safe-area-inset-left, 0px));
  }

  .jg-marketing-return__text {
    max-width: 5.5rem;
  }
}

/* Mobile / in-app browsers: stop drifting layers + lighten blur (GPU + layout stability) */
@media (max-width: 768px) {
  .jg-ambient--music::before,
  .jg-ambient--music::after {
    opacity: 0.045;
    animation: none;
  }

  .jg-ambient--marketing::before {
    animation: none;
    opacity: 0.035;
  }

  .jg-marketing-return {
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
  }
}
