@layer ambient {
  .ambient-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background:
      radial-gradient(120% 90% at 12% 8%, rgba(130, 200, 201, 0.28) 0%, transparent 58%),
      radial-gradient(90% 80% at 88% 18%, rgba(106, 184, 185, 0.22) 0%, transparent 55%),
      radial-gradient(100% 90% at 50% 92%, rgba(35, 43, 78, 0.08) 0%, transparent 62%),
      linear-gradient(175deg, var(--color-surface) 0%, var(--color-bg-base) 48%, var(--color-bg-mist) 100%);
  }

  #calm-canvas {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    display: block;
    opacity: 0.96;
  }

  .ambient-orb {
    position: absolute;
    border-radius: 50%;
    will-change: transform, opacity;
    pointer-events: none;
  }

  .ambient-orb--teal {
    inline-size: clamp(24rem, 45vw, 46rem);
    block-size: clamp(24rem, 45vw, 46rem);
    inset-block-start: -12%;
    inset-inline-start: -10%;
    background: radial-gradient(
      circle at 42% 42%,
      rgba(106, 184, 185, 0.34) 0%,
      rgba(130, 200, 201, 0.16) 46%,
      transparent 72%
    );
    animation: orb-breathe-teal 11s ease-in-out infinite alternate;
  }

  .ambient-orb--sage {
    inline-size: clamp(26rem, 48vw, 50rem);
    block-size: clamp(26rem, 48vw, 50rem);
    inset-block-start: 22%;
    inset-inline-end: -14%;
    background: radial-gradient(
      circle at 55% 45%,
      rgba(130, 200, 201, 0.3) 0%,
      rgba(217, 239, 239, 0.26) 48%,
      transparent 74%
    );
    animation: orb-breathe-sage 14s ease-in-out infinite alternate;
  }

  .ambient-orb--navy {
    inline-size: clamp(22rem, 40vw, 42rem);
    block-size: clamp(22rem, 40vw, 42rem);
    inset-block-end: -14%;
    inset-inline-start: 16%;
    background: radial-gradient(
      circle at 50% 50%,
      rgba(35, 43, 78, 0.1) 0%,
      rgba(106, 184, 185, 0.14) 46%,
      transparent 74%
    );
    animation: orb-breathe-navy 17s ease-in-out infinite alternate;
  }

  .ambient-orb--aqua {
    inline-size: clamp(18rem, 34vw, 34rem);
    block-size: clamp(18rem, 34vw, 34rem);
    inset-block-start: 46%;
    inset-inline-start: 22%;
    background: radial-gradient(
      circle at 50% 50%,
      rgba(130, 200, 201, 0.24) 0%,
      rgba(106, 184, 185, 0.1) 48%,
      transparent 74%
    );
    animation: orb-breathe-aqua 13s ease-in-out infinite alternate;
  }

  /* Pure-CSS GPU-composited seamless silk wave ribbons */
  .ambient-wave {
    position: absolute;
    inset-inline-start: 0;
    inset-block-end: 6%;
    inline-size: 200%;
    block-size: clamp(12rem, 26vh, 22rem);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 220' preserveAspectRatio='none'%3E%3Cpath d='M0,110 C200,45 400,175 600,110 C800,45 1000,175 1200,110 L1200,220 L0,220 Z' fill='%236AB8B9' fill-opacity='0.11'/%3E%3Cpath d='M0,110 C200,45 400,175 600,110 C800,45 1000,175 1200,110' fill='none' stroke='%233D8B8D' stroke-opacity='0.16' stroke-width='2'/%3E%3C/svg%3E");
    background-size: 50% 100%;
    background-repeat: repeat-x;
    will-change: transform;
    animation: wave-drift-primary 18s linear infinite;
  }

  .ambient-wave--secondary {
    inset-block-end: 0;
    block-size: clamp(10rem, 20vh, 18rem);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 200' preserveAspectRatio='none'%3E%3Cpath d='M0,95 C220,165 420,25 600,95 C780,165 980,25 1200,95 L1200,200 L0,200 Z' fill='%2382C8C9' fill-opacity='0.14'/%3E%3Cpath d='M0,95 C220,165 420,25 600,95 C780,165 980,25 1200,95' fill='none' stroke='%236AB8B9' stroke-opacity='0.2' stroke-width='1.5'/%3E%3C/svg%3E");
    animation: wave-drift-secondary 26s linear infinite;
  }

  @keyframes wave-drift-primary {
    0% {
      transform: translate3d(0, 0, 0);
    }
    100% {
      transform: translate3d(-50%, 0, 0);
    }
  }

  @keyframes wave-drift-secondary {
    0% {
      transform: translate3d(-50%, 0, 0);
    }
    100% {
      transform: translate3d(0, 0, 0);
    }
  }

  @keyframes orb-breathe-teal {
    0% {
      transform: translate3d(0, 0, 0) scale(0.95);
      opacity: 0.7;
    }
    50% {
      transform: translate3d(8vw, 5vh, 0) scale(1.12);
      opacity: 0.96;
    }
    100% {
      transform: translate3d(3vw, 8vh, 0) scale(1.02);
      opacity: 0.8;
    }
  }

  @keyframes orb-breathe-sage {
    0% {
      transform: translate3d(0, 0, 0) scale(0.96);
      opacity: 0.72;
    }
    50% {
      transform: translate3d(-9vw, -5vh, 0) scale(1.14);
      opacity: 0.96;
    }
    100% {
      transform: translate3d(-4vw, 6vh, 0) scale(1);
      opacity: 0.76;
    }
  }

  @keyframes orb-breathe-navy {
    0% {
      transform: translate3d(0, 0, 0) scale(0.94);
      opacity: 0.68;
    }
    100% {
      transform: translate3d(10vw, -7vh, 0) scale(1.12);
      opacity: 0.92;
    }
  }

  @keyframes orb-breathe-aqua {
    0% {
      transform: translate3d(-4vw, 3vh, 0) scale(0.95);
      opacity: 0.55;
    }
    50% {
      transform: translate3d(6vw, -4vh, 0) scale(1.12);
      opacity: 0.85;
    }
    100% {
      transform: translate3d(-2vw, -5vh, 0) scale(1.04);
      opacity: 0.65;
    }
  }

  .ambient-paused .ambient-orb,
  .ambient-paused .ambient-wave {
    animation-play-state: paused;
  }

  @media (prefers-reduced-motion: reduce) {
    .ambient-orb,
    .ambient-wave {
      animation: none;
    }
  }

  /* Keep foreground document content cleanly layered above the living canvas */
  .site-header,
  main,
  .site-footer {
    position: relative;
    z-index: 1;
  }

  /* Discrete ambient motion control */
  .ambient-toggle {
    position: fixed;
    inset-block-end: 1.15rem;
    inset-inline-start: 1.15rem;
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-pill);
    border: 1px solid var(--glass-border);
    background: var(--glass-bg-strong);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--color-navy);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
  }

  .ambient-toggle:hover {
    background: var(--color-white);
    border-color: var(--color-teal);
    transform: translateY(-1px);
  }

  .ambient-toggle:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring), var(--shadow-soft);
  }

  .ambient-toggle__dot {
    inline-size: 0.55rem;
    block-size: 0.55rem;
    border-radius: 50%;
    background: var(--color-teal-deep);
    transition: background-color 0.2s ease, transform 0.2s ease;
  }

  .ambient-paused .ambient-toggle__dot {
    background: var(--color-ink-muted);
    transform: scale(0.85);
  }

  @media (max-width: 480px) {
    .ambient-toggle {
      inset-block-end: 0.85rem;
      inset-inline-start: 0.85rem;
      padding: 0.45rem 0.75rem;
    }
  }
}
