/* =========================================================================
   KAI STUDIO — FX layer (futuristic / tech visuals)
   Brand rules respected: no continuous flashing, effects never cover text,
   everything static under prefers-reduced-motion. Remove this file + js/fx.js
   to return to the plain look.
   ========================================================================= */

@property --fx-angle { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

/* ---------- Scroll progress ---------- */
.fx-progress {
  position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 60; pointer-events: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: 0 50%; transform: scaleX(var(--p, 0));
  box-shadow: 0 0 12px rgba(var(--accent-rgb), .6);
}

/* ---------- Film grain (very subtle) ---------- */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 70; pointer-events: none; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Particle canvas (hero) ---------- */
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }

/* ---------- Perspective tech grid (hero floor) ---------- */
.fx-grid {
  position: absolute; left: -20%; right: -20%; bottom: 0; height: 46%; z-index: -1; pointer-events: none;
  transform: perspective(520px) rotateX(62deg); transform-origin: 50% 100%;
  background-image:
    linear-gradient(rgba(var(--accent-rgb), .22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--accent-rgb), .22) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: linear-gradient(0deg, #000 0%, transparent 85%);
  mask-image: linear-gradient(0deg, #000 0%, transparent 85%);
  animation: fx-grid-move 6s linear infinite;
}
@keyframes fx-grid-move { to { background-position: 0 64px, 0 0; } }

/* ---------- HUD frame around hero art ---------- */
.fx-hud { position: absolute; inset: -4% -3% -6%; pointer-events: none; z-index: 1; }
.fx-hud i {
  position: absolute; width: 28px; height: 28px; border: 2px solid rgba(var(--accent-rgb), .8);
  transition: border-color .7s;
}
.fx-hud i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.fx-hud i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.fx-hud i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.fx-hud i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.fx-hud span {
  position: absolute; font-family: var(--font-display); font-weight: 600; font-size: 11px; letter-spacing: .24em;
  color: rgba(255, 255, 255, .55); text-transform: uppercase; white-space: nowrap;
}
.fx-hud span b { color: var(--accent-2); font-weight: 700; }
.fx-hud .tl { top: -22px; left: 0; }
.fx-hud .br { bottom: -22px; right: 0; }
/* one-time scan sweep when the art appears (not looping) */
.fx-hud::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(var(--accent-rgb), .9), transparent);
  box-shadow: 0 0 18px rgba(var(--accent-rgb), .8);
  opacity: 0;
}
@keyframes fx-scan { 0% { top: 0; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { top: 100%; opacity: 0; } }
:root:not(.is-booting) .fx-hud::after { animation: fx-scan 1.8s var(--ease) .5s 1 both; }
:root:not(.is-booting) .fx-hud.rescan::after { animation: none; }
@media (max-width: 960px) { .fx-hud { inset: 0 2% -2%; } }

/* Hero art parallax target */
.hero__art { transition: transform .3s ease-out; will-change: transform; }

/* ---------- Spotlight follow on surfaces ---------- */
.card, .feature, .channel, .mv__item, .discipline, .job, .world, .steps li {
  --mx: 50%; --my: 50%;
}
.card::before, .channel::before, .discipline::before, .job::before, .world::before, .news-card::before, .lib-item::before {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit;
  background: radial-gradient(360px circle at var(--mx) var(--my), rgba(var(--accent-rgb), .14), transparent 45%);
  opacity: 0; transition: opacity .3s;
}
.channel, .discipline, .job { position: relative; overflow: hidden; }
.card:hover::before, .channel:hover::before, .discipline:hover::before, .job:hover::before, .world:hover::before, .news-card:hover::before, .lib-item:hover::before { opacity: 1; }

/* Spotlight on the border (gradient ring that follows the cursor) */
.card::after, .world::after {
  content: ""; position: absolute; inset: 0; z-index: 4; pointer-events: none; border-radius: inherit;
  padding: 1px;
  background: radial-gradient(240px circle at var(--mx) var(--my), rgba(var(--accent-rgb), .9), transparent 60%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0; transition: opacity .3s;
}
.card:hover::after, .world:hover::after { opacity: 1; }

/* 3D tilt */
.fx-tilt { transform-style: preserve-3d; will-change: transform; }
.card.fx-tilt:hover, .news-card.fx-tilt:hover { transform: none; } /* JS drives the transform */

/* ---------- Angled HUD corners on media ---------- */
.card__media::before {
  content: ""; position: absolute; right: 12px; top: 12px; z-index: 2; width: 18px; height: 18px;
  border-top: 2px solid rgba(255, 255, 255, .5); border-right: 2px solid rgba(255, 255, 255, .5);
  transition: border-color .3s, width .3s, height .3s;
}
.card:hover .card__media::before { border-color: var(--accent-2); width: 28px; height: 28px; }

/* ---------- Animated conic border (CTA) ---------- */
.cta::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: conic-gradient(from var(--fx-angle), transparent 0 70%, rgba(var(--accent-rgb), .9) 85%, var(--accent-2) 90%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  animation: fx-spin 6s linear infinite;
}
@keyframes fx-spin { to { --fx-angle: 360deg; } }

/* ---------- Section HUD rail (eyebrow ticks) ---------- */
.eyebrow::after {
  content: ""; width: 6px; height: 6px; background: rgba(var(--accent-rgb), .7);
  clip-path: polygon(0 0, 100% 0, 40% 100%, 0 100%);
}

/* ---------- Button sheen ---------- */
.btn--primary { position: relative; overflow: hidden; }
.btn--primary::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .45), transparent);
  transform: skewX(-20deg); transition: left .6s var(--ease);
}
.btn--primary:hover::after { left: 130%; }

/* ---------- Intro splash (once per session) ---------- */
.fx-intro {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: var(--bg); transition: opacity .6s ease, visibility .6s;
}
.no-intro .fx-intro { display: none; }
:root:not(.is-booting) .fx-intro { opacity: 0; visibility: hidden; }
.fx-intro__inner { display: grid; gap: 28px; justify-items: center; }
.fx-intro img { width: min(280px, 60vw); height: auto; animation: fx-intro-logo 1s var(--ease) both; }
.fx-intro__bar { width: min(220px, 50vw); height: 2px; background: var(--line-2); overflow: hidden; }
.fx-intro__bar::after {
  content: ""; display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: 0 50%; animation: fx-intro-bar 1.1s var(--ease) .15s both;
}
.fx-intro__tag { font-family: var(--font-display); font-weight: 600; font-size: 12px; letter-spacing: .5em; color: var(--muted); animation: fx-fade .6s ease .5s both; }
@keyframes fx-intro-logo { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes fx-intro-bar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fx-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Entrance (once, after the boot gate opens) ---------- */
:root:not(.is-booting) .hero__copy > *,
:root:not(.is-booting) .page-hero .wrap > *,
:root:not(.is-booting) .ghero__content > * { animation: fx-rise .8s var(--ease) both; }
:root:not(.is-booting) .hero__copy > :nth-child(2), :root:not(.is-booting) .page-hero .wrap > :nth-child(2), :root:not(.is-booting) .ghero__content > :nth-child(2) { animation-delay: .08s; }
:root:not(.is-booting) .hero__copy > :nth-child(3), :root:not(.is-booting) .page-hero .wrap > :nth-child(3), :root:not(.is-booting) .ghero__content > :nth-child(3) { animation-delay: .16s; }
:root:not(.is-booting) .hero__copy > :nth-child(4), :root:not(.is-booting) .page-hero .wrap > :nth-child(4), :root:not(.is-booting) .ghero__content > :nth-child(4) { animation-delay: .24s; }
:root:not(.is-booting) .hero__copy > :nth-child(n+5), :root:not(.is-booting) .page-hero .wrap > :nth-child(n+5), :root:not(.is-booting) .ghero__content > :nth-child(n+5) { animation-delay: .32s; }
:root:not(.is-booting) .hero__art > img { animation: fx-art-in 1s var(--ease) .1s both; }
@keyframes fx-rise { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
@keyframes fx-art-in { from { scale: .94; } to { scale: 1; } }

/* ---------- Reduced motion & touch ---------- */
@media (prefers-reduced-motion: reduce) {
  .fx-grid, .cta::before, .fx-hud::after, .hero__copy > *, .page-hero .wrap > *, .ghero__content > *, .hero__art > img { animation: none !important; }
  .fx-hud::after { display: none; }
  .fx-intro { display: none; }
}
@media (hover: none) {
  .card::before, .card::after, .world::before, .world::after,
  .channel::before, .discipline::before, .job::before { display: none; }
}
