/* KITforge Labs - cyberpunk glitch effects.
   Enqueued only on the 4 main pages (inc/glitch.php).
   All animation lives inside @media (prefers-reduced-motion: no-preference) so a
   stray class is inert for reduced-motion users; glitch.js also never starts then.
   No layout shift: only transform / opacity / clip-path / filter / pseudo-elements.
   Effects target the logo WRAPPER (figure/a), never the <img> (it already carries
   filter:url(#kf-logo-map); a filter on the img would drop the recolour). */

:root {
  --kfg-cyan: #05d9e8;
  --kfg-magenta: #ff2a6d;
  --kfg-yellow: #feff00;
  --kfg-coral: #fd6077;
  --kfg-blue: #0067bf;
}

/* Scramble clone sits over a visibility:hidden big text (h1, h2, product-title bar); JS copies its box, font and fill. */
.kfg-scramble-clone {
  overflow: hidden;
  pointer-events: none;
  z-index: 2147483646;
}

@media (prefers-reduced-motion: no-preference) {

  /* 1. RGB split (chromatic aberration) - logo wrapper */
  .kfg-rgb {
    animation: kfg-rgb 0.28s steps(2, jump-none) 2 both;
    will-change: transform, filter;
  }
  @keyframes kfg-rgb {
    0%   { transform: translate3d(0, 0, 0);     filter: drop-shadow(-2px 0 var(--kfg-magenta)) drop-shadow(2px 0 var(--kfg-cyan)); }
    25%  { transform: translate3d(-3px, 1px, 0); filter: drop-shadow(-5px 0 var(--kfg-magenta)) drop-shadow(5px 0 var(--kfg-cyan)); }
    50%  { transform: translate3d(3px, -1px, 0); filter: drop-shadow(4px 0 var(--kfg-cyan)) drop-shadow(-4px 0 var(--kfg-magenta)); }
    75%  { transform: translate3d(-1px, 0, 0);   filter: drop-shadow(-2px 0 var(--kfg-magenta)) drop-shadow(2px 0 var(--kfg-cyan)); }
    100% { transform: translate3d(0, 0, 0);      filter: none; }
  }

  /* 3. Slice (horizontal band tear) - logo wrapper */
  .kfg-slice {
    animation: kfg-slice 0.32s steps(1) 2 both;
    will-change: clip-path, transform;
  }
  @keyframes kfg-slice {
    0%   { clip-path: inset(0 0 0 0);       transform: translateX(0); }
    15%  { clip-path: inset(0 0 68% 0);     transform: translateX(-7px); }
    30%  { clip-path: inset(38% 0 30% 0);   transform: translateX(6px); }
    45%  { clip-path: inset(70% 0 0 0);     transform: translateX(-5px); }
    60%  { clip-path: inset(22% 0 55% 0);   transform: translateX(5px); }
    80%  { clip-path: inset(0 0 40% 0);     transform: translateX(-3px); }
    100% { clip-path: inset(0 0 0 0);       transform: translateX(0); }
  }

  /* 5. Neon flicker (failing sign) - logo wrapper */
  .kfg-neon {
    animation: kfg-neon 0.62s linear 1 both;
    will-change: opacity, filter;
  }
  @keyframes kfg-neon {
    0%, 100% { opacity: 1; filter: none; }
    10% { opacity: 0.3; }
    13% { opacity: 1; filter: drop-shadow(0 0 6px var(--kfg-cyan)) drop-shadow(0 0 12px var(--kfg-magenta)); }
    21% { opacity: 0.5; }
    24% { opacity: 1; }
    42% { opacity: 0.85; filter: drop-shadow(0 0 5px var(--kfg-yellow)); }
    56% { opacity: 0.2; }
    60% { opacity: 1; filter: drop-shadow(0 0 9px var(--kfg-cyan)); }
    82% { opacity: 1; filter: drop-shadow(0 0 4px var(--kfg-magenta)); }
  }

  /* 4. Scramble clone look (JS fills and positions it) */
  .kfg-scramble-clone,
  .kfg-scramble-clone * {
    color: var(--kfg-cyan) !important;
  }
  .kfg-scramble-clone {
    text-shadow: 0.03em 0 var(--kfg-magenta), -0.03em 0 var(--kfg-cyan);
  }

  /* 6. Contact submit button - the same reminder glitch as the store bars:
     bg jumps coral/green/yellow + RGB-split text + horizontal band slices, resting yellow.
     Text/arrow live in child nodes, so they animate separately. */
  .kit-contact-submit.is-glitching {
    animation: kfg-cta 0.6s steps(1) 1 both;
    will-change: background-color, clip-path, translate;
  }
  .kit-contact-submit.is-glitching input[type="submit"],
  .kit-contact-submit.is-glitching::after {
    animation: kfg-cta-text 0.6s steps(1) 1 both;
  }
  @keyframes kfg-cta {
    0%   { background-color: var(--kf-brand-primary, #fd6077); translate: -3px 0; clip-path: inset(0 0 55% 0); }
    15%  { background-color: var(--kf-brand-accent-2, #8add7f); translate: 4px 0; clip-path: inset(45% 0 0 0); }
    30%  { background-color: var(--kf-brand-accent, #feff00); translate: -2px 0; clip-path: inset(26% 0 26% 0); }
    45%  { background-color: var(--kf-brand-primary, #fd6077); translate: 3px 0; clip-path: inset(0 0 0 0); }
    60%  { background-color: var(--kf-brand-accent-2, #8add7f); translate: -4px 0; clip-path: inset(0 0 68% 0); }
    78%  { background-color: var(--kf-brand-accent, #feff00); translate: 2px 0; clip-path: inset(60% 0 0 0); }
    90%, 100% { background-color: var(--kf-brand-accent-2, #8add7f); translate: 0 0; clip-path: polygon(0.6rem 0, 100% 0, calc(100% - 0.6rem) 100%, 0 100%); }
  }
  @keyframes kfg-cta-text {
    0%, 78%   { color: #fff; text-shadow: -2px 0 var(--kfg-cyan), 2px 0 var(--kfg-magenta); }
    90%, 100% { color: var(--kf-brand-background, #051545); text-shadow: none; }
  }
}
