/*
 * TFM Effects — page transitions, sink-in titles, shader background, cursor, taps
 * /wp-content/themes/blocksy-child/css/tfm-fx.css
 *
 * Loaded on every front-end page by php/tfm-fx.php, together with js/tfm-fx.js and
 * js/tfm-fx-gl.js. Area-specific parts of the effects live in the area CSS files
 * (tfm-home.css, tfm-village.css, tfm-academy.css, tfm-townsquare*.css).
 *
 * Flags on <html>:
 *   .tfm-fx       effects active (head script)
 *   .tfm-fx-sink  hero titles will sink in (not with reduced motion)
 *   .tfm-sink-go  the sink timelines are set up, everything may show
 *   .tfm-tr-in    arriving covered from a page transition (first paint)
 *   .tfm-fx-gl    the WebGL background runs (or is switched off in the FAB)
 */

/* ============================================================
   1. PAGE TRANSITION
   ============================================================ */

/* film grain tile, used by the first-paint cover and the transition overlay */
:root {
  --tfm-fx-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* First paint after a covered transition: html::after shows the exact fog frame
   the previous page ended on, before <body> exists. js/tfm-fx.js replaces it
   with the real overlay in the same frame and uncovers. If the script never
   runs, the cover fades out on its own after 8 s. */
html.tfm-tr-in::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  background: var(--tr-bg, #07040e);
  animation: tfmFxCoverFailsafe .6s ease 8s forwards;
}
/* the grain of the covered frame belongs to the first paint as well */
html.tfm-tr-in[data-tr="fog"]::before {
  content: '';
  position: fixed;
  inset: -50%;
  z-index: 2147483001;
  pointer-events: none;
  background-image: var(--tfm-fx-grain);
  mix-blend-mode: overlay;
  opacity: .35;
  animation: tfmFxCoverFailsafe .6s ease 8s forwards;
}
@keyframes tfmFxCoverFailsafe {
  to { opacity: 0; visibility: hidden; }
}

.tfm-fx-tr {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  pointer-events: none;
  overflow: hidden;
}
.tfm-fx-tr.is-blocking { pointer-events: auto; }
.tfm-fx-tr > * { position: absolute; }
.tfm-fx-tr__fill { inset: 0; }
.tfm-fx-tr__blob {
  width: 90vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(30px);
  will-change: transform, opacity;
}
/* film grain: SVG turbulence as tile, moved in steps so it "boils" like analog grain */
.tfm-fx-tr__grain {
  inset: -50%;
  background-image: var(--tfm-fx-grain);
  mix-blend-mode: overlay;
  opacity: 0;
  animation: tfmFxGrain .5s steps(4) infinite;
}
@keyframes tfmFxGrain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-6%, 4%); }
  50% { transform: translate(5%, -3%); }
  75% { transform: translate(-3%, -6%); }
  100% { transform: translate(0, 0); }
}

/* ============================================================
   2. SINK-IN TITLES
   Hidden until the GSAP timelines have set their start values
   (html.tfm-sink-go), so the plain text never flashes. Their old
   entrance animations (tfm-home.css, Elementor "Entrance Animation")
   are switched off. If the script never runs, everything shows
   after 2.5 s on its own.
   ============================================================ */

/* The same list three times; every entry is one class, so :is() keeps the specificity.
   js/tfm-fx.js animates these (sinkHome, SINK_AREA, SINK_SUB). */
html.tfm-fx-sink :is(.tfm-hero-pretitle, .tfm-hero-title-welcome, .tfm-hero-title-kingdom, .tfm-hero-line, .tfm-hero-subtitle, .tfm-hero-divider-wrap, .tfm-hero-buttons-wrap, .tfm-hero__h1, .tfm-hero__sub, .tfm-ac-hero-title, .tfm-sq-hero-title, .tfm-tc-hero-title, .tfm-ac-hero-subtitle, .tfm-sq-hero-subtitle, .tfm-tc-hero-subtitle, .tfm-loc-title, .tfm-loc-eyebrow, .tfm-loc-mood) {
  animation: none !important;
}
html.tfm-fx-sink:not(.tfm-sink-go) :is(.tfm-hero-pretitle, .tfm-hero-title-welcome, .tfm-hero-title-kingdom, .tfm-hero-line, .tfm-hero-subtitle, .tfm-hero-divider-wrap, .tfm-hero-buttons-wrap, .tfm-hero__h1, .tfm-hero__sub, .tfm-ac-hero-title, .tfm-sq-hero-title, .tfm-tc-hero-title, .tfm-ac-hero-subtitle, .tfm-sq-hero-subtitle, .tfm-tc-hero-subtitle, .tfm-loc-title, .tfm-loc-eyebrow, .tfm-loc-mood) {
  visibility: hidden;
  animation: tfmFxSinkFailsafe 0s linear 2.5s forwards !important;
}
@keyframes tfmFxSinkFailsafe {
  to { visibility: visible; }
}
/* Elementor keeps widgets with an entrance animation invisible until they scroll in */
html.tfm-fx-sink.tfm-sink-go .elementor-invisible:is(.tfm-hero-pretitle, .tfm-hero-title-welcome, .tfm-hero-title-kingdom, .tfm-hero-line, .tfm-hero-subtitle, .tfm-hero-divider-wrap, .tfm-hero-buttons-wrap, .tfm-hero__h1, .tfm-hero__sub, .tfm-ac-hero-title, .tfm-sq-hero-title, .tfm-tc-hero-title, .tfm-ac-hero-subtitle, .tfm-sq-hero-subtitle, .tfm-tc-hero-subtitle, .tfm-loc-title, .tfm-loc-eyebrow, .tfm-loc-mood) {
  visibility: visible !important;
}
/* the accent word of the Home title starts to glow (--glow is tweened 0 → 1) */
html.tfm-fx-sink .tfm-hero-title-kingdom em {
  --glow: 0;
  text-shadow: 0 0 calc(var(--glow) * 28px) color-mix(in srgb, var(--area-accent-soft, #c4a0ff) calc(var(--glow) * 90%), transparent);
}
/* SplitText masks clip at their box: give italic overhangs and descenders room.
   The mask is named after the word class set in js/tfm-fx.js (wordsClass). */
html.tfm-fx-sink .tfm_fx_word-mask {
  padding: .08em .08em .16em;
  margin: -.08em -.08em -.16em;
}

/* ============================================================
   3. SHADER BACKGROUND
   Fixed behind the page (z-index -1 in the root stacking context, the body
   background lies on the canvas below it). 100lvh: the mobile address bar
   showing or hiding does not resize the canvas.
   ============================================================ */

#tfm-fx-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: -1;
  pointer-events: none;
}
#tfm-fx-bg canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}
/* The shader replaces the CSS backgrounds. Without WebGL (or with reduced
   motion) html.tfm-fx-gl is never set and they stay as the fallback. */
html.tfm-fx-gl .tfm-parallax-orb,
html.tfm-fx-gl .tfm-hero-orb,
html.tfm-fx-gl .tfm-bg-canvas,
html.tfm-fx-gl .tfm-ac-atmosphere,
html.tfm-fx-gl .tfm-sq-atmosphere,
html.tfm-fx-gl .tfm-tc-atmosphere {
  display: none !important;
}

/* ============================================================
   4. CURSOR + TAPS
   ============================================================ */

#tfm-fx-cursor {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 99998;
  pointer-events: none;
}
.tfm-fx-tap {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99997;
  pointer-events: none;
}
.tfm-fx-tap__ring {
  position: absolute;
  width: 60px;
  height: 60px;
  margin: -30px;
  border-radius: 50%;
  border: 2px solid var(--area-accent-soft, #c4a0ff);
  box-shadow: 0 0 14px var(--area-accent-glow, rgba(140, 60, 255, .38));
}
.tfm-fx-tap__spark {
  position: absolute;
  width: 5px;
  height: 5px;
  margin: -2.5px;
  border-radius: 50%;
  background: var(--area-accent-soft, #c4a0ff);
  box-shadow: 0 0 6px var(--area-accent-soft, #c4a0ff);
}
.tfm-fx-tap__spot {
  position: absolute;
  width: 180px;
  height: 180px;
  margin: -90px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--area-accent-soft, #c4a0ff) 55%, transparent), color-mix(in srgb, var(--area-accent, #b06eff) 18%, transparent) 40%, transparent 70%);
  mix-blend-mode: screen;
}

/* ============================================================
   5. TASK CHECK HELPERS (lab no. 09, used by the Town Square scripts)
   ============================================================ */

.tfm-fx-sparks {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.tfm-fx-sparks i {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px;
  border-radius: 2px;
}
.tfm-fx-odo {
  display: inline-block;
  vertical-align: bottom;
}
.tfm-fx-odo__cols {
  display: inline-flex;
  align-items: flex-start;
  overflow: hidden;
  height: 1.3em;
  line-height: 1.3em;
  vertical-align: bottom;
}
.tfm-fx-odo__cols > span {
  display: flex;
  flex-direction: column;
}
.tfm-fx-odo__cols b {
  display: block;
  height: 1.3em;
  font-weight: inherit;
}

/* ============================================================
   6. REDUCED MOTION
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .tfm-fx-tr__grain {
    animation: none !important;
  }
}
