/* ============================================================
   GRIDHACK · index-v2 — CINEMATIC ENHANCEMENT LAYER
   ------------------------------------------------------------
   Strictly additive. Layered on top of styles.css / sections.css.
   Removes nothing. If you delete cinematic.css + motion.js the
   page degrades cleanly back to the static v1.
   ============================================================ */

/* ─── Smooth-scroll container (Lenis-friendly) ─── */
/* These rules only apply when motion.js has activated Lenis (desktop / fine
   pointer). On touch devices the html.lenis class is never added, so native
   scrolling is left alone. */
html.lenis { height: auto; }
html.lenis, html.lenis body { overflow: clip; }
html.lenis-smooth { scroll-behavior: auto; }
html.lenis-scrolling iframe { pointer-events: none; }
/* Hard safety: even if html.lenis somehow slipped in, never disable scroll
   on a touch viewport. */
@media (pointer: coarse), (max-width: 768px) {
  html.lenis, html.lenis body { overflow: auto !important; }
}

/* ─── Top scroll-progress line ─── */
.cx-progress {
  position: fixed; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  transform-origin: 0 0;
  transform: scaleX(0);
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 0 10px rgba(34,197,94,0.6);
}

/* ─── Custom cursor (desktop only) ─── */
@media (pointer: fine) {
  html.cx-cursor, html.cx-cursor body, html.cx-cursor a, html.cx-cursor button { cursor: none; }
  .cx-cursor-dot,
  .cx-cursor-ring {
    position: fixed; left: 0; top: 0;
    pointer-events: none;
    z-index: 10000;
    transform: translate(-50%, -50%);
    mix-blend-mode: screen;
    will-change: transform;
  }
  .cx-cursor-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    transition: width 0.18s ease, height 0.18s ease, opacity 0.2s ease;
  }
  .cx-cursor-ring {
    width: 32px; height: 32px;
    border: 1px solid rgba(34,197,94,0.45);
    border-radius: 50%;
    transition: width 0.22s ease, height 0.22s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.06s linear;
  }
  /* Expand on interactive elements */
  .cx-cursor-hot .cx-cursor-dot { width: 10px; height: 10px; }
  .cx-cursor-hot .cx-cursor-ring { width: 52px; height: 52px; border-color: var(--accent); }
  /* Hide if user is selecting text or typing */
  .cx-cursor-text .cx-cursor-dot { opacity: 0; }
  .cx-cursor-text .cx-cursor-ring { opacity: 0.4; }
}
@media (pointer: coarse) {
  .cx-cursor-dot, .cx-cursor-ring { display: none; }
}

/* ─── Hero overlay: light sweep + scan drift + grain ─── */
.cx-hero-fx {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
  mix-blend-mode: screen;
}
.cx-light-sweep {
  position: absolute;
  top: -20%; left: -40%;
  width: 80%; height: 140%;
  background: linear-gradient(115deg,
    transparent 35%,
    rgba(34,197,94,0.05) 45%,
    rgba(255,255,255,0.04) 50%,
    rgba(34,197,94,0.05) 55%,
    transparent 65%);
  filter: blur(12px);
  transform: translateX(-30%);
  animation: cx-sweep 14s cubic-bezier(0.65, 0, 0.35, 1) infinite;
  will-change: transform, opacity;
}
@keyframes cx-sweep {
  0%   { transform: translateX(-40%); opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateX(220%); opacity: 0; }
}
.cx-scan {
  position: absolute; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.45;
  animation: cx-scan-drop 7s linear infinite;
  box-shadow: 0 0 6px var(--accent-glow);
}
@keyframes cx-scan-drop {
  0%   { top: -2%;  opacity: 0; }
  10%  { opacity: 0.5; }
  90%  { opacity: 0.5; }
  100% { top: 102%; opacity: 0; }
}
.cx-grain {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 0 0, rgba(255,255,255,0.03) 1px, transparent 1px),
    radial-gradient(circle at 8px 12px, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 16px 16px, 24px 24px;
  opacity: 0.6;
  animation: cx-grain-shift 4s steps(4) infinite;
}
@keyframes cx-grain-shift {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-2px, 1px); }
  50%  { transform: translate(1px, -2px); }
  75%  { transform: translate(-1px, 2px); }
  100% { transform: translate(0, 0); }
}

/* Subtle animated grid canvas slot (motion.js paints into this) */
.cx-grid-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0.55;
}

/* ─── Reveal primitives (GSAP attaches; CSS handles fallback) ─── */
.cx-reveal { opacity: 0; transform: translateY(28px); }
.cx-reveal-fade { opacity: 0; }
.cx-reveal-rise { opacity: 0; transform: translateY(40px); }
.cx-reveal-clip { clip-path: inset(0 100% 0 0); }
.cx-reveal-blur { opacity: 0; filter: blur(12px); transform: translateY(16px); }
/* GSAP sets these to their final state; if GSAP fails we still show via .cx-loaded */
html.cx-loaded .cx-reveal,
html.cx-loaded .cx-reveal-fade,
html.cx-loaded .cx-reveal-rise,
html.cx-loaded .cx-reveal-blur { opacity: 1; transform: none; filter: none; }
html.cx-loaded .cx-reveal-clip { clip-path: inset(0 0 0 0); }

/* ─── Text reveal: per-line clip mask used by motion.js to slice <h1> ─── */
.cx-line { display: block; overflow: hidden; }
.cx-line > span { display: inline-block; will-change: transform, opacity; }

/* ─── Magnetic buttons (motion.js attaches transform) ─── */
[data-magnetic] {
  display: inline-block;
  will-change: transform;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
[data-magnetic]:hover { transition-duration: 0.18s; }

/* ─── Soft card glow on hover (cards must add .cx-glow) ─── */
.cx-glow { position: relative; transition: transform 0.4s cubic-bezier(0.16,1,0.3,1), border-color 0.3s ease; }
.cx-glow::after {
  content: ''; position: absolute; inset: -1px;
  border-radius: inherit;
  background: radial-gradient(220px circle at var(--mx, 50%) var(--my, 50%), rgba(34,197,94,0.22), transparent 60%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 0;
}
.cx-glow:hover { transform: translateY(-3px); }
.cx-glow:hover::after { opacity: 1; }
.cx-glow > * { position: relative; z-index: 1; }

/* ─── Parallax layer hook (motion.js drives the transform) ─── */
[data-parallax] { will-change: transform; }

/* ─── Section reveal: full-section fade-up with stagger of children ─── */
.cx-section-reveal { opacity: 0; transform: translateY(40px); }
html.cx-loaded .cx-section-reveal { opacity: 1; transform: none; }

/* ─── Sticky section label rail (optional decoration) ─── */
.cx-section-rail {
  position: fixed; left: 28px; top: 50%;
  transform: translateY(-50%);
  display: none;  /* shown via JS when section labels are configured */
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}
@media (max-width: 1100px) { .cx-section-rail { display: none !important; } }
.cx-rail-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  transition: background 0.3s ease, transform 0.3s ease;
}
.cx-rail-dot.is-active {
  background: var(--accent);
  transform: scale(1.6);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ─── prefers-reduced-motion: kill the choreography, keep the styles ─── */
@media (prefers-reduced-motion: reduce) {
  .cx-light-sweep, .cx-scan, .cx-grain { animation: none !important; }
  .cx-grid-canvas { display: none !important; }
  .cx-reveal, .cx-reveal-fade, .cx-reveal-rise, .cx-reveal-clip, .cx-reveal-blur,
  .cx-section-reveal { opacity: 1 !important; transform: none !important; clip-path: inset(0) !important; filter: none !important; }
  [data-magnetic] { transition: none !important; }
}

/* ─── Mobile fence: tone down expensive effects ─── */
@media (max-width: 768px) {
  .cx-grain { display: none; }
  .cx-light-sweep { animation-duration: 22s; }
  .cx-grid-canvas { opacity: 0.35; }
  .cx-cursor-dot, .cx-cursor-ring { display: none !important; }
}
