/* ============================================================
   CASTELLAN · FX LAYER
   Shared atmospheric & interaction effects across all pages.
   Auto-loaded by fx.js; no per-page markup required.
   ============================================================ */

/* ---------- Tokens (fallbacks; pages already define these) ---- */
:root {
  --fx-accent:      var(--accent, #2D7CFF);
  --fx-accent-soft: var(--accent-soft, #5BA0FF);
  --fx-accent-glow: var(--accent-glow, rgba(45,124,255,0.35));
  --fx-stage:       var(--bg-stage, #08090C);
  --fx-ease:        cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- WebGL aurora canvas (hero backdrop) -------------- */
.fx-aurora {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2s ease-out;
  mix-blend-mode: screen;
}
.fx-aurora.ready { opacity: 0.85; }

/* Aurora glow ring — pure CSS halo that sits above the canvas,
   reinforcing the centre of attention without depending on WebGL. */
.fx-halo {
  position: absolute;
  top: 50%; left: 50%;
  width: clamp(700px, 90vw, 1400px);
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 50%,
      rgba(45,124,255,0.18) 0%,
      rgba(45,124,255,0.08) 22%,
      transparent 55%);
  filter: blur(40px);
  animation: fxHaloDrift 22s ease-in-out infinite alternate;
}
@keyframes fxHaloDrift {
  0%   { transform: translate(-50%, -50%) scale(1)    rotate(0deg);    opacity: 0.85; }
  100% { transform: translate(-48%, -52%) scale(1.12) rotate(12deg);   opacity: 1; }
}

/* ---------- Sovereign Lattice (constellation backdrop) ------- */
.fx-lattice {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
  display: block;
}
.fx-lattice circle {
  fill: var(--fx-accent);
  filter: drop-shadow(0 0 4px var(--fx-accent-glow));
}
.fx-lattice line {
  stroke: var(--fx-accent-soft);
  stroke-width: 0.4;
  opacity: 0.25;
}
.fx-lattice .fx-node-pulse {
  animation: fxNodePulse 4s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}
@keyframes fxNodePulse {
  0%, 100% { opacity: 0.4; r: 1.2; }
  50%      { opacity: 1;   r: 2.2; }
}

/* ---------- Magnetic CTAs ------------------------------------ */
.fx-magnetic {
  position: relative;
  transition: transform 0.5s var(--fx-ease);
  will-change: transform;
}
.fx-magnetic-aura {
  position: absolute;
  inset: -24px;
  border-radius: 999px;
  background: radial-gradient(
    circle at var(--fx-mx, 50%) var(--fx-my, 50%),
    rgba(45,124,255,0.45),
    rgba(45,124,255,0.15) 35%,
    transparent 65%);
  opacity: 0;
  transition: opacity 0.4s var(--fx-ease);
  pointer-events: none;
  z-index: -1;
  filter: blur(16px);
}
.fx-magnetic:hover .fx-magnetic-aura,
.fx-magnetic:focus-visible .fx-magnetic-aura { opacity: 1; }

/* ---------- Char-split headline reveal ----------------------- */
/* Uses CSS animation (not transition) so reveal completes even
   when the tab is briefly throttled or in a hidden preview frame.
   Words are wrapped in .fx-word containers so line breaks fall
   between words, never mid-word. */
.fx-split { display: inline; }
.fx-word {
  display: inline-block;
  white-space: nowrap;
}
.fx-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.5em);
  filter: blur(10px);
  will-change: opacity, transform, filter;
}
.fx-char.shown {
  animation: fxCharReveal 0.95s var(--fx-ease) both;
}
@keyframes fxCharReveal {
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

/* ---------- Generic scroll reveal ---------------------------- */
.fx-reveal {
  opacity: 0;
  transform: translateY(24px);
}
.fx-reveal.shown {
  animation: fxRevealUp 1.1s var(--fx-ease) both;
}
@keyframes fxRevealUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Edge sentinels (light-trace at viewport edges) --- */
.fx-edges {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  overflow: hidden;
}
.fx-edge {
  position: absolute;
  background: linear-gradient(180deg,
    transparent 0%,
    var(--fx-accent) 50%,
    transparent 100%);
  width: 1px;
  height: 30vh;
  opacity: 0;
  filter: blur(0.5px);
}
.fx-edge.left  { left: 0;  animation: fxEdgeFall 18s linear infinite; }
.fx-edge.right { right: 0; animation: fxEdgeFall 18s linear infinite; animation-delay: -9s; }
@keyframes fxEdgeFall {
  0%   { transform: translateY(-40vh); opacity: 0; }
  10%  { opacity: 0.7; }
  90%  { opacity: 0.7; }
  100% { transform: translateY(110vh); opacity: 0; }
}

/* ---------- Nav status pill ---------------------------------- */
.fx-nav-status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.7rem;
  margin-right: 0.75rem;
  border: 1px solid var(--hairline-dark, rgba(255,255,255,0.08));
  border-radius: 999px;
  font-family: var(--font-mono, monospace);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-on-dark-soft, #B8BCC8);
  background: rgba(255,255,255,0.02);
  white-space: nowrap;
}
.fx-nav-status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #2BD16B;
  box-shadow: 0 0 8px rgba(43, 209, 107, 0.7);
  animation: fxStatusPulse 2.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes fxStatusPulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.8); }
}
@media (max-width: 1024px) { .fx-nav-status { display: none; } }

/* ---------- Mobile nav drawer fix ----------------------------
   The mobile menu (.nav-links) is position:fixed and lives INSIDE
   <nav>. When the nav has backdrop-filter (added via .scrolled on
   the home page when scrolling down, and always present on the
   sub-pages), the nav becomes the containing block for its fixed
   descendant — so the drawer's top/bottom resolve against the ~64px
   nav box instead of the viewport, collapsing the menu to nav height.
   Removing the nav's backdrop-filter on mobile restores the drawer to
   full-viewport height. The semi-opaque background is kept (and made
   a touch more solid) so the top bar still reads cleanly without blur. */
@media (max-width: 1024px) {
  .nav,
  .nav.scrolled {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  .nav.scrolled {
    background: rgba(8, 9, 12, 0.95) !important;
  }
}

/* ---------- View-transition curtain (fallback) --------------- */
.fx-curtain {
  position: fixed;
  inset: 0;
  background: var(--fx-stage);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease-in;
}
.fx-curtain.active {
  opacity: 1;
  pointer-events: auto;
}
.fx-curtain::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  border: 1.5px solid transparent;
  border-top-color: var(--fx-accent);
  border-radius: 50%;
  animation: fxSpin 0.9s linear infinite;
  opacity: 0;
  transition: opacity 0.2s 0.15s ease;
}
.fx-curtain.active::after { opacity: 1; }
@keyframes fxSpin { to { transform: rotate(360deg); } }

/* ---------- Native View Transitions API ---------------------- */
::view-transition-old(root) {
  animation: fxFadeOut 0.35s var(--fx-ease) both;
}
::view-transition-new(root) {
  animation: fxFadeIn 0.55s var(--fx-ease) both;
}
@keyframes fxFadeOut { to { opacity: 0; transform: translateY(-8px); } }
@keyframes fxFadeIn  { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Mouse parallax layers --------------------------- */
.fx-parallax {
  will-change: transform;
  transition: transform 0.6s var(--fx-ease);
}

/* ---------- Compute Grid (signature hero scene) --------------- */
.fx-grid3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.8s ease-out;
  mix-blend-mode: screen;
  /* keep the copy readable: fade the field toward the top-left */
  mask-image: radial-gradient(120% 90% at 68% 62%, black 40%, transparent 92%);
  -webkit-mask-image: radial-gradient(120% 90% at 68% 62%, black 40%, transparent 92%);
}
.fx-grid3d.ready { opacity: 0.9; }

/* ---------- Timeline scrub (trajectory choreography) ---------- */
.fx-scrub-enabled [data-fx-scrub] { height: 220vh; position: relative; }
.fx-scrub-enabled [data-fx-scrub] .path-sticky {
  position: sticky;
  top: 12vh;
}
.path-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
  margin-bottom: 3.5rem;
}
.path-readout-label {
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-on-dark-mute, #6B7080);
}
.path-readout-num {
  font-family: var(--font-display, serif);
  font-size: clamp(3rem, 6vw, 5rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink-on-dark, #FBFBFB);
  font-variant-numeric: tabular-nums;
}
.path-readout-num small {
  font-size: 0.4em;
  font-style: italic;
  color: var(--fx-accent);
  font-weight: 400;
}
.path-readout-bar {
  width: min(420px, 60vw);
  height: 2px;
  margin-top: 0.9rem;
  background: rgba(255,255,255,0.08);
  position: relative;
  overflow: hidden;
}
.path-readout-bar i {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent-dim, #1E5BCC), var(--fx-accent), var(--fx-accent-soft));
  transform: scaleX(var(--path-p, 0));
  transform-origin: 0 50%;
}
.fx-scrub-enabled .path-timeline::before {
  transform: scaleX(var(--path-p, 0));
  transform-origin: 0 50%;
}

/* ---------- Scroll progress hairline ------------------------- */
.fx-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 1001;
  background: linear-gradient(90deg,
    var(--accent-dim, #1E5BCC),
    var(--fx-accent),
    var(--fx-accent-soft));
  transform-origin: 0 50%;
  transform: scaleX(0);
  pointer-events: none;
  box-shadow: 0 0 10px var(--fx-accent-glow);
}

/* ---------- Card spotlight (cursor-following highlight) ------ */
.fx-spot { position: relative; }
.fx-spot-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.45s var(--fx-ease);
  background: radial-gradient(
    240px circle at var(--fx-sx, 50%) var(--fx-sy, 50%),
    rgba(45, 124, 255, 0.10),
    transparent 65%);
}
.fx-spot:hover .fx-spot-layer { opacity: 1; }

/* ---------- Flagship shimmer border --------------------------
   Rotating conic highlight traced around .build-card-feature.
   Falls back to a static gradient ring where @property (typed
   custom properties) is unsupported. */
@property --fx-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}
.build-card-feature { position: relative; }
.build-card-feature::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1.5px;
  pointer-events: none;
  z-index: 2;
  background: conic-gradient(from var(--fx-angle, 0deg),
    rgba(30, 91, 204, 0) 0%,
    rgba(45, 124, 255, 0.9) 12%,
    rgba(91, 160, 255, 0.35) 24%,
    rgba(30, 91, 204, 0) 40%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  animation: fxBorderSpin 7s linear infinite;
}
@keyframes fxBorderSpin {
  to { --fx-angle: 360deg; }
}

/* ---------- Reduced motion: degrade quietly ----------------- */
@media (prefers-reduced-motion: reduce) {
  .fx-aurora,
  .fx-halo,
  .fx-edges,
  .fx-curtain::after { display: none !important; }

  .fx-grid3d { opacity: 0.5 !important; transition: none !important; }

  .fx-char,
  .fx-reveal {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    transition: none !important;
  }

  .fx-lattice .fx-node-pulse,
  .fx-nav-status-dot,
  .fx-halo,
  .build-card-feature::before {
    animation: none !important;
  }

  .fx-spot-layer { display: none !important; }

  .fx-magnetic { transition: none !important; }
}
