/* Kadro Sakuga-VFX Layer — Authentic manga/anime visual effects stylesheet.
 * Strictly layered inside @layer components:
 * - Zero raw #hex / rgb() / rgba() literals (uses canonical @layer tokens vars)
 * - Zero !important declarations
 * - Zero infinite animations (all keyframes are finite event/reveal bursts)
 * - Full compliance with [data-motion="reduced"] & prefers-reduced-motion
 */
@layer components {
  /* Shared fixed viewport Canvas overlay (Sakuga-VFX front layer) */
  canvas.sakuga-fx,
  .sakuga-vfx-stage {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9000;
    display: block;
  }

  /* ── Speedlines / Shūchūsen Container ─────────────────────────────────── */
  [data-vfx="speedlines"],
  .vfx-speedlines {
    position: relative;
    isolation: isolate;
  }

  .sakuga-speedlines-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
    z-index: 0;
  }

  .sakuga-speedlines-layer.is-underlay {
    z-index: -1;
  }

  .sakuga-speedlines-canvas,
  .sakuga-speedlines-svg {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }

  .sakuga-speedlines-layer.vfx-speedlines-enter {
    animation: sakugaSpeedlinesSnap 280ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  /* ── Ben-Day Halftone / Screentone Zones ──────────────────────────────── */
  [data-vfx="halftone"],
  .vfx-halftone {
    background-image: var(
      --tone-halftone,
      radial-gradient(color-mix(in srgb, var(--text) 11%, transparent) 1.15px, transparent 1.15px)
    );
    background-size: var(--tone-size, 8px 8px);
  }

  [data-vfx="halftone"][data-vfx-density="strong"],
  .vfx-halftone-strong {
    background-image: var(
      --tone-halftone-strong,
      radial-gradient(color-mix(in srgb, var(--text) 18%, transparent) 1.35px, transparent 1.35px)
    );
    background-size: var(--tone-size, 8px 8px);
  }

  .vfx-halftone-band {
    position: relative;
    isolation: isolate;
  }

  .vfx-halftone-band::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
    background-image: var(
      --tone-halftone,
      radial-gradient(color-mix(in srgb, var(--text) 11%, transparent) 1.15px, transparent 1.15px)
    );
    background-size: var(--tone-size, 8px 8px);
    -webkit-mask-image: linear-gradient(180deg, var(--text) 0%, transparent 100%);
    mask-image: linear-gradient(180deg, var(--text) 0%, transparent 100%);
  }

  /* ── Manga Panel Wipe & Snap-In Reveal (Graceful Degradation Safe) ────── */
  [data-vfx="panel-reveal"],
  .vfx-panel-reveal {
    opacity: 1;
    transform: none;
  }

  /* Only applied by JS when IntersectionObserver exists, motion=full, and below fold */
  .vfx-reveal-armed {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.985);
    will-change: transform, opacity;
  }

  .vfx-reveal-armed[data-vfx-wipe="left"] {
    transform: translate3d(-14px, 0, 0);
    clip-path: inset(0 18% 0 0);
  }

  .vfx-reveal-armed[data-vfx-wipe="right"] {
    transform: translate3d(14px, 0, 0);
    clip-path: inset(0 0 0 18%);
  }

  .vfx-reveal-armed[data-vfx-wipe="ink"] {
    transform: translate3d(0, 10px, 0);
    clip-path: inset(0 0 22% 0);
  }

  .vfx-revealed {
    animation: sakugaPanelSnap 260ms cubic-bezier(0.22, 1, 0.36, 1) var(--vfx-delay, 0ms) 1 both;
  }

  .vfx-revealed[data-vfx-wipe="left"] {
    animation: sakugaWipeLeft 280ms cubic-bezier(0.22, 1, 0.36, 1) var(--vfx-delay, 0ms) 1 both;
  }

  .vfx-revealed[data-vfx-wipe="right"] {
    animation: sakugaWipeRight 280ms cubic-bezier(0.22, 1, 0.36, 1) var(--vfx-delay, 0ms) 1 both;
  }

  .vfx-revealed[data-vfx-wipe="ink"] {
    animation: sakugaWipeInk 280ms cubic-bezier(0.22, 1, 0.36, 1) var(--vfx-delay, 0ms) 1 both;
  }

  /* ── Onomatopoeia / SFX Stamp Pop Entrance ────────────────────────────── */
  [data-vfx="sfx-pop"],
  .vfx-sfx-pop {
    transform-origin: center center;
  }

  .vfx-sfx-armed {
    opacity: 0;
    transform: scale(0.62) rotate(-7deg);
  }

  .vfx-sfx-pop-active {
    animation: sakugaSfxPop 340ms cubic-bezier(0.2, 1.35, 0.35, 1) var(--vfx-delay, 0ms) 1 both;
  }

  /* ── Anime Text-Field / Input VFX (Sakuga Input) ──────────────────────── */
  [data-vfx="input"],
  .sakuga-input {
    caret-color: var(--vfx-accent, var(--accent));
    transition: border-color var(--duration, 170ms) var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
      box-shadow var(--duration, 170ms) var(--ease, cubic-bezier(0.22, 1, 0.36, 1));
  }

  [data-vfx="input"]:focus,
  [data-vfx="input"]:focus-within,
  .sakuga-input:focus,
  .sakuga-input:focus-within {
    border-color: var(--vfx-accent, var(--accent));
    box-shadow: var(--shadow-accent, var(--shadow-control));
  }

  .vfx-input-focus-snap {
    animation: sakugaInputFocus 200ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  .vfx-input-type-give {
    animation: sakugaInputGive 120ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  .vfx-input-clear-recoil {
    animation: sakugaInputClear 170ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  /* ── Toggle / Check / Tab / Card / Sheet Finite Spring Snaps ──────────── */
  .vfx-toggle-snap {
    animation: sakugaToggleSnap 220ms cubic-bezier(0.2, 1.32, 0.35, 1) 1 both;
  }

  .vfx-tab-dash {
    animation: sakugaTabDash 200ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  .vfx-card-charge {
    animation: sakugaCardCharge 210ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  .vfx-sheet-pop {
    transform-origin: center center;
    animation: sakugaSheetPop 240ms cubic-bezier(0.2, 1.3, 0.35, 1) 1 both;
  }

  /* ── Interactive Element Tactile Squash & Sakuga Impact-Frame Invert ──── */
  .vfx-press-hold {
    transform: scale(1.03, 0.93);
    transition: transform 80ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .vfx-hit-recoil {
    animation: sakugaHitRecoil 220ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  /* Authentic Sakuga-VFX 2-frame monochrome/accent impact inversion cut */
  .sakuga-impact-invert {
    background-color: var(--vfx-flash-bg, var(--text));
    color: var(--vfx-flash-ink, var(--bg));
    border-color: var(--vfx-accent, var(--accent));
    box-shadow: none;
    transform: rotate(-1.5deg) scale(1.03);
  }

  /* Brief full-viewport Sakuga impact flash cut (finite 180ms) */
  .sakuga-impact-overlay {
    position: fixed;
    inset: 0;
    z-index: 9010;
    pointer-events: none;
    border: 6px solid var(--vfx-flash-bg, var(--text));
    background: color-mix(in srgb, var(--vfx-flash-bg, var(--text)) 22%, transparent);
    animation: sakugaImpactCut 180ms steps(2, end) 1 both;
  }

  /* Brief edge-framed Manga Speed Dash Rush (vertical / horizontal jump) */
  .sakuga-speed-dash {
    position: fixed;
    inset: 0;
    z-index: 9008;
    pointer-events: none;
    overflow: hidden;
    animation: sakugaSpeedDashFade 250ms cubic-bezier(0.22, 1, 0.36, 1) 1 both;
  }

  .sakuga-speed-dash::before,
  .sakuga-speed-dash::after {
    content: "";
    position: absolute;
    pointer-events: none;
    background: repeating-linear-gradient(
      90deg,
      transparent 0 10px,
      var(--vfx-speedline, var(--tone-speedline)) 10px 12px,
      transparent 12px 26px,
      color-mix(in srgb, var(--vfx-accent, var(--accent)) 24%, transparent) 26px 28px
    );
  }

  .sakuga-speed-dash::before {
    inset: 0 auto 0 0;
    width: min(14vw, 96px);
  }

  .sakuga-speed-dash::after {
    inset: 0 0 0 auto;
    width: min(14vw, 96px);
  }

  .sakuga-speed-dash[data-dir="up"]::before,
  .sakuga-speed-dash[data-dir="up"]::after {
    animation: sakugaDashUp 250ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  .sakuga-speed-dash[data-dir="down"]::before,
  .sakuga-speed-dash[data-dir="down"]::after {
    animation: sakugaDashDown 250ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  .sakuga-speed-dash[data-dir="left"]::before,
  .sakuga-speed-dash[data-dir="left"]::after,
  .sakuga-speed-dash[data-dir="right"]::before,
  .sakuga-speed-dash[data-dir="right"]::after {
    inset: 0 0 auto 0;
    width: 100%;
    height: min(12vh, 72px);
    background: repeating-linear-gradient(
      180deg,
      transparent 0 8px,
      var(--vfx-speedline, var(--tone-speedline)) 8px 10px,
      transparent 10px 22px,
      color-mix(in srgb, var(--vfx-accent, var(--accent)) 22%, transparent) 22px 24px
    );
  }

  .sakuga-speed-dash[data-dir="left"]::after,
  .sakuga-speed-dash[data-dir="right"]::after {
    inset: auto 0 0 0;
  }

  .sakuga-speed-dash[data-dir="left"]::before,
  .sakuga-speed-dash[data-dir="left"]::after {
    animation: sakugaDashLeft 250ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  .sakuga-speed-dash[data-dir="right"]::before,
  .sakuga-speed-dash[data-dir="right"]::after {
    animation: sakugaDashRight 250ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  /* Theme Transition Ink-Wipe Shutter Cut (Light <-> Dark, finite 210ms) */
  .sakuga-theme-wipe {
    position: fixed;
    inset: 0;
    z-index: 9015;
    pointer-events: none;
    overflow: hidden;
    background: color-mix(in srgb, var(--vfx-flash-bg, var(--text)) 82%, transparent);
    animation: sakugaThemeWipe 210ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  .sakuga-theme-wipe::after {
    content: "";
    position: absolute;
    inset: -12% -8%;
    background: linear-gradient(
      105deg,
      transparent 40%,
      var(--vfx-accent, var(--accent)) 40%,
      var(--vfx-accent, var(--accent)) 46%,
      var(--vfx-flash-ink, var(--bg)) 46%,
      var(--vfx-flash-ink, var(--bg)) 54%,
      var(--vfx-accent, var(--accent)) 54%,
      var(--vfx-accent, var(--accent)) 60%,
      transparent 60%
    );
    animation: sakugaThemeSlash 210ms cubic-bezier(0.16, 1, 0.3, 1) 1 both;
  }

  /* ── Finite Keyframes (ZERO infinite loops) ───────────────────────────── */
  @keyframes sakugaSpeedlinesSnap {
    0% {
      opacity: 0;
      transform: scale(1.07);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  }

  @keyframes sakugaPanelSnap {
    0% {
      opacity: 0;
      transform: translate3d(0, 14px, 0) scale(0.985);
    }
    70% {
      opacity: 1;
      transform: translate3d(0, -1px, 0) scale(1.004);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
  }

  @keyframes sakugaWipeLeft {
    0% {
      opacity: 0;
      transform: translate3d(-14px, 0, 0);
      clip-path: inset(0 18% 0 0);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0);
      clip-path: inset(0 0 0 0);
    }
  }

  @keyframes sakugaWipeRight {
    0% {
      opacity: 0;
      transform: translate3d(14px, 0, 0);
      clip-path: inset(0 0 0 18%);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0);
      clip-path: inset(0 0 0 0);
    }
  }

  @keyframes sakugaWipeInk {
    0% {
      opacity: 0;
      transform: translate3d(0, 10px, 0);
      clip-path: inset(0 0 22% 0);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0);
      clip-path: inset(0 0 0 0);
    }
  }

  @keyframes sakugaSfxPop {
    0% {
      opacity: 0;
      transform: scale(0.54) rotate(-8deg);
    }
    52% {
      opacity: 1;
      transform: scale(1.12) rotate(2deg);
    }
    78% {
      opacity: 1;
      transform: scale(0.96) rotate(-1deg);
    }
    100% {
      opacity: 1;
      transform: scale(1) rotate(0deg);
    }
  }

  @keyframes sakugaInputFocus {
    0% {
      transform: scale(0.988, 1.024);
    }
    55% {
      transform: scale(1.012, 0.99);
    }
    100% {
      transform: scale(1, 1);
    }
  }

  @keyframes sakugaInputGive {
    0% {
      transform: scale(1.006, 0.986);
    }
    100% {
      transform: scale(1, 1);
    }
  }

  @keyframes sakugaInputClear {
    0% {
      transform: translate3d(-4px, 0, 0) scale(0.985, 1.018);
    }
    60% {
      transform: translate3d(2px, 0, 0) scale(1.006, 0.995);
    }
    100% {
      transform: translate3d(0, 0, 0) scale(1, 1);
    }
  }

  @keyframes sakugaToggleSnap {
    0% {
      transform: scale(0.88, 1.12) rotate(-2deg);
    }
    55% {
      transform: scale(1.06, 0.94) rotate(1deg);
    }
    100% {
      transform: scale(1, 1) rotate(0deg);
    }
  }

  @keyframes sakugaTabDash {
    0% {
      transform: translate3d(var(--vfx-dash-x, -5px), 0, 0) scale(1.05, 0.94);
    }
    60% {
      transform: translate3d(0, -2px, 0) scale(0.98, 1.03);
    }
    100% {
      transform: translate3d(0, 0, 0) scale(1, 1);
    }
  }

  @keyframes sakugaCardCharge {
    0% {
      transform: translate3d(-1px, -1px, 0) scale(1.008);
    }
    100% {
      transform: translate3d(0, 0, 0) scale(1);
    }
  }

  @keyframes sakugaSheetPop {
    0% {
      opacity: 0;
      transform: translate3d(0, 14px, 0) scale(0.94);
    }
    62% {
      opacity: 1;
      transform: translate3d(0, -2px, 0) scale(1.015);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
  }

  @keyframes sakugaHitRecoil {
    0% {
      transform: scale(1.04, 0.92);
    }
    48% {
      transform: scale(0.98, 1.03);
    }
    100% {
      transform: scale(1, 1);
    }
  }

  @keyframes sakugaImpactCut {
    0% {
      opacity: 1;
    }
    55% {
      opacity: 0.45;
    }
    100% {
      opacity: 0;
    }
  }

  @keyframes sakugaSpeedDashFade {
    0% {
      opacity: 0.95;
    }
    70% {
      opacity: 0.85;
    }
    100% {
      opacity: 0;
    }
  }

  @keyframes sakugaDashUp {
    0% {
      transform: translate3d(0, 18%, 0);
    }
    100% {
      transform: translate3d(0, -18%, 0);
    }
  }

  @keyframes sakugaDashDown {
    0% {
      transform: translate3d(0, -18%, 0);
    }
    100% {
      transform: translate3d(0, 18%, 0);
    }
  }

  @keyframes sakugaDashLeft {
    0% {
      transform: translate3d(18%, 0, 0);
    }
    100% {
      transform: translate3d(-18%, 0, 0);
    }
  }

  @keyframes sakugaDashRight {
    0% {
      transform: translate3d(-18%, 0, 0);
    }
    100% {
      transform: translate3d(18%, 0, 0);
    }
  }

  @keyframes sakugaThemeWipe {
    0% {
      clip-path: polygon(0 0, 0 0, -14% 100%, 0 100%);
      opacity: 0.95;
    }
    46% {
      clip-path: polygon(0 0, 114% 0, 100% 100%, 0 100%);
      opacity: 0.9;
    }
    100% {
      clip-path: polygon(114% 0, 114% 0, 100% 100%, 100% 100%);
      opacity: 0;
    }
  }

  @keyframes sakugaThemeSlash {
    0% {
      transform: translate3d(-48%, 0, 0);
    }
    100% {
      transform: translate3d(48%, 0, 0);
    }
  }

  /* ── Reduced Motion Full Compliance ───────────────────────────────────── */
  :root[data-motion="reduced"] canvas.sakuga-fx,
  :root[data-motion="reduced"] .sakuga-vfx-stage,
  :root[data-motion="reduced"] .sakuga-impact-overlay,
  :root[data-motion="reduced"] .sakuga-theme-wipe,
  :root[data-motion="reduced"] .sakuga-speed-dash {
    display: none;
  }

  :root[data-motion="reduced"] .vfx-reveal-armed,
  :root[data-motion="reduced"] .vfx-revealed,
  :root[data-motion="reduced"] .vfx-sfx-armed,
  :root[data-motion="reduced"] .vfx-sfx-pop-active,
  :root[data-motion="reduced"] .sakuga-speedlines-layer.vfx-speedlines-enter,
  :root[data-motion="reduced"] .vfx-press-hold,
  :root[data-motion="reduced"] .vfx-hit-recoil,
  :root[data-motion="reduced"] .vfx-input-focus-snap,
  :root[data-motion="reduced"] .vfx-input-type-give,
  :root[data-motion="reduced"] .vfx-input-clear-recoil,
  :root[data-motion="reduced"] .vfx-toggle-snap,
  :root[data-motion="reduced"] .vfx-tab-dash,
  :root[data-motion="reduced"] .vfx-card-charge,
  :root[data-motion="reduced"] .vfx-sheet-pop {
    opacity: 1;
    transform: none;
    clip-path: none;
    animation: none;
    transition: none;
  }

  @media (prefers-reduced-motion: reduce) {
    canvas.sakuga-fx,
    .sakuga-vfx-stage,
    .sakuga-impact-overlay,
    .sakuga-theme-wipe,
    .sakuga-speed-dash {
      display: none;
    }

    .vfx-reveal-armed,
    .vfx-revealed,
    .vfx-sfx-armed,
    .vfx-sfx-pop-active,
    .sakuga-speedlines-layer.vfx-speedlines-enter,
    .vfx-press-hold,
    .vfx-hit-recoil,
    .vfx-input-focus-snap,
    .vfx-input-type-give,
    .vfx-input-clear-recoil,
    .vfx-toggle-snap,
    .vfx-tab-dash,
    .vfx-card-charge,
    .vfx-sheet-pop {
      opacity: 1;
      transform: none;
      clip-path: none;
      animation: none;
      transition: none;
    }
  }
}
