/*
 * innerpulse atmosphere — grain, vignette, fog and the backdrop reading, for the heads of pages on product grounds.
 * Load after innerpulse-tokens.css. Rules and placement: references/atmosphere.md.
 *
 *   <div class="ip-grain" aria-hidden="true"></div>          once, right after <body>
 *   <div class="ip-vignette" aria-hidden="true"></div>       once, ink grounds only (hidden on paper)
 *   <header class="ip-atmos">                               any page head or hero
 *     <div class="ip-atmos-bg" aria-hidden="true">
 *       <div class="ip-backdrop">…the page's own reading (scripts/backdrop.mjs), or a photograph the product owns…</div>
 *       <i class="ip-fog f1"></i><i class="ip-fog f2"></i><i class="ip-fog f3"></i>
 *     </div>
 *     …the head's own content…
 *   </header>
 *
 * Everything is decorative (aria-hidden), sits behind the content, and stops under prefers-reduced-motion.
 * Ember is never used here: the fog takes the ground's own tones and one family accent.
 */

:root {
  --ip-atmos-fog-1: light-dark(rgba(110, 100, 86, .12), rgba(120, 132, 156, .15));
  --ip-atmos-fog-2: light-dark(rgba(150, 138, 120, .1), rgba(70, 82, 104, .2));
  --ip-atmos-fog-3: var(--ip-atmos-accent, light-dark(rgba(192, 66, 28, .07), rgba(255, 122, 89, .10)));
  --ip-atmos-scrim: var(--innerpulse-ground, #0b0d10);
  --ip-atmos-reading: var(--innerpulse-text, #e3e6e9);
}

/* Grain: film grain over the whole page. Overlay on ink, a faint paper tooth (multiply) on paper. */
.ip-grain {
  position: fixed; inset: -50%; z-index: 90; pointer-events: none; opacity: .055; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: ip-grain 1.6s steps(5) infinite; will-change: transform;
}
@keyframes ip-grain { 0%{transform:translate(0,0)} 25%{transform:translate(-3%,2%)} 50%{transform:translate(2%,-4%)} 75%{transform:translate(-4%,-1%)} 100%{transform:translate(0,0)} }
.ip-paused .ip-grain { animation-play-state: paused; }

/* Vignette: the edges of an ink page fall off, weighted to the top. */
.ip-vignette { position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 0%, transparent 42%, rgba(0, 0, 0, .5) 100%); }

/* Page-head atmosphere. The background bleeds to the viewport's edges, so the page must clip what
   passes them (100vw includes the scrollbar). */
body:has(.ip-atmos) { overflow-x: clip; }
.ip-atmos { position: relative; isolation: isolate; }
.ip-atmos-bg { position: absolute; inset: 0 calc(50% - 50vw); z-index: -1; overflow: hidden; pointer-events: none; }
/* Faded out with masks rather than painted over, so the head blends into whatever the page is (ground,
   vignette, grain) with no seam. Text-side and bottom fall off fastest. */
.ip-atmos-bg {
  -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,.28) 0%, rgba(0,0,0,.6) 40%, #000 75%), linear-gradient(0deg, transparent 0%, #000 60%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, rgba(0,0,0,.28) 0%, rgba(0,0,0,.6) 40%, #000 75%), linear-gradient(0deg, transparent 0%, #000 60%);
  mask-composite: intersect;
}
.ip-backdrop { position: absolute; inset: -4%; opacity: .55; animation: ip-drift 44s ease-in-out infinite alternate; }
/* The reading (scripts/backdrop.mjs): mirrored bars in the text color, faint; the masks above fade it off the text side. */
.ip-backdrop .ip-reading { display: block; width: 100%; height: 100%; color: var(--ip-atmos-reading); opacity: .2; }
.ip-backdrop img { width: 100%; height: 100%; object-fit: cover; object-position: center 35%; filter: saturate(.72) contrast(1.06); }
@keyframes ip-drift { to { transform: scale(1.06) translate(-1.5%, -1%); } }
.ip-fog { position: absolute; border-radius: 50%; filter: blur(64px); pointer-events: none; }
.ip-fog.f1 { width: 64vw; height: 40vh; left: -12vw; bottom: -14vh; background: var(--ip-atmos-fog-1); animation: ip-fog-a 40s ease-in-out infinite alternate; }
.ip-fog.f2 { width: 58vw; height: 36vh; right: -18vw; bottom: 0; background: var(--ip-atmos-fog-2); animation: ip-fog-b 48s ease-in-out infinite alternate; }
.ip-fog.f3 { width: 38vw; height: 30vh; right: 6vw; top: 4vh; background: var(--ip-atmos-fog-3); animation: ip-fog-a 54s ease-in-out infinite alternate-reverse; }
@keyframes ip-fog-a { to { transform: translate(16vw, -4vh) scale(1.18); } }
@keyframes ip-fog-b { to { transform: translate(-20vw, 3vh) scale(1.1); } }


/* A frosted panel for content that sits over the atmosphere. */
.ip-glass { background: color-mix(in srgb, var(--innerpulse-ground, #0b0d10) 55%, transparent); border: 1px solid var(--innerpulse-line-2, rgba(227,230,233,.16));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* Paper: grain becomes tooth, the vignette goes, the reading quietens. */
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .ip-grain { mix-blend-mode: multiply; opacity: .04; filter: invert(1); }
  :root:not([data-theme="dark"]) .ip-vignette { display: none; }
  :root:not([data-theme="dark"]) .ip-backdrop .ip-reading { opacity: .16; } }
:root[data-theme="light"] .ip-grain { mix-blend-mode: multiply; opacity: .04; filter: invert(1); }
:root[data-theme="light"] .ip-vignette { display: none; }
:root[data-theme="light"] .ip-backdrop .ip-reading { opacity: .16; }

@media (prefers-reduced-motion: reduce) {
  .ip-grain, .ip-backdrop, .ip-fog { animation: none; }
}
@media print { .ip-grain, .ip-vignette, .ip-atmos-bg { display: none !important; } }
