/* ═══════════════════════════════════════════════════════
   FAUX OS V2.1 - Advanced FX Layer
   Ghost trails • Parallax textures • System monitor •
   VHS distortion • Window decay
   ═══════════════════════════════════════════════════════ */


/* ══════════════════════════════════════════════════════
   1. DESTRUKTIVE UI — Ghost Trails & Window Decay
   ══════════════════════════════════════════════════════ */

/* ── Ghost Trail (cloned window afterimage during drag) ── */
.ghost-trail {
  position: absolute;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-lg);
  background: rgba(255, 255, 255, 0.015);
  -webkit-backdrop-filter: blur(1px);
  backdrop-filter: blur(1px);
  opacity: 0;
  animation: ghost-fade 0.7s var(--ease-smooth) forwards;
  z-index: 1;
  overflow: hidden;

  /* Chromatic split on ghosts */
  &::before,
  &::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
  }

  &::before {
    border-left: 1px solid rgba(255, 80, 50, 0.08);
    transform: translateX(-1px);
  }

  &::after {
    border-right: 1px solid rgba(80, 200, 255, 0.08);
    transform: translateX(1px);
  }
}

@keyframes ghost-fade {
  0%   { opacity: 0.12; transform: scale(1); filter: blur(0px); }
  100% { opacity: 0; transform: scale(0.99); filter: blur(2px); }
}

/* ── Fracture Close Animation ── */
.window.is-fracturing {
  animation: none !important;
  pointer-events: none;
}

.fracture-shard {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
  background: var(--glass);
  border: 1px solid var(--border);
  backface-visibility: hidden;
  will-change: transform, opacity;
  animation: shard-fly 0.6s var(--ease-out) forwards;
}

@keyframes shard-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
    filter: blur(0);
  }
  60% {
    opacity: 0.6;
  }
  100% {
    opacity: 0;
    transform: translate(var(--shard-tx), var(--shard-ty))
               rotate(var(--shard-rot))
               scale(0.7);
    filter: blur(2px);
  }
}

/* ── Window Idle Drift (subtle entropy) ── */
.window.is-drifting {
  animation: idle-drift 20s ease-in-out infinite alternate;
}

@keyframes idle-drift {
  0%   { translate: 0 0; rotate: 0deg; }
  25%  { translate: 0.5px -0.3px; rotate: 0.02deg; }
  50%  { translate: -0.3px 0.5px; rotate: -0.015deg; }
  75%  { translate: 0.4px 0.2px; rotate: 0.01deg; }
  100% { translate: -0.2px -0.4px; rotate: -0.02deg; }
}

/* ── Titlebar Decay Indicator (shows window age) ── */
.window__decay-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--accent);
  opacity: 0.15;
  transition: width 2s linear;
  border-radius: 0 1px 0 0;
}


/* ══════════════════════════════════════════════════════
   2. PARALLAX TEXTURE DEPTH — mouse-reactive layers
   ══════════════════════════════════════════════════════ */

/* Override texture transforms — JS controls via CSS vars */
.texture--grain,
.texture--scanlines,
.texture--topo,
.texture--chroma,
.texture--lightleak,
.texture--dither {
  will-change: transform;
  transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Vignette follows cursor center */
.texture--vignette {
  will-change: background;
  transition: background 1.2s ease-out;
}


/* ══════════════════════════════════════════════════════
   3. GENERATIVE SYSTEM MONITOR — fake OS telemetry
   ══════════════════════════════════════════════════════ */

.sys-monitor {
  position: fixed;
  bottom: 70px;
  left: var(--sp-4);
  width: 180px;
  z-index: 3;
  pointer-events: none;
  opacity: 0.44;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ink-faint);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
}

.sys-monitor__header {
  font-family: var(--font-pixel);
  font-size: 7px;
  letter-spacing: var(--tracking-pixel);
  color: var(--accent);
  opacity: 0.6;
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
  margin-bottom: 2px;
}

.sys-monitor__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sys-monitor__label {
  opacity: 0.5;
}

.sys-monitor__value {
  font-variant-numeric: tabular-nums;
}

.sys-monitor__bar {
  height: 3px;
  background: var(--c-graphite);
  border-radius: 1px;
  overflow: hidden;
  margin-top: 1px;
}

.sys-monitor__bar-fill {
  height: 100%;
  background: var(--ink-faint);
  border-radius: 1px;
  transition: width 1.5s var(--ease-smooth);
}

.sys-monitor__bar-fill--accent {
  background: var(--accent);
  opacity: 0.5;
}

/* Wave/oscilloscope display */
.sys-monitor__wave {
  width: 100%;
  height: 24px;
  opacity: 0.6;
}

.sys-monitor__wave line {
  stroke: var(--ink-faint);
  stroke-width: 0.5;
  opacity: 0.15;
}

.sys-monitor__wave polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  opacity: 0.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hide on mobile */
body.mode--mobile .sys-monitor { display: none; }


/* ══════════════════════════════════════════════════════
   4. VHS / TAPE DISTORTION
   ══════════════════════════════════════════════════════ */

/* ── Tracking Line (horizontal glitch bar) ── */
.vhs-tracking {
  position: fixed;
  left: 0;
  right: 0;
  height: 0;
  z-index: var(--z-overlay);
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
}

.vhs-tracking.is-active {
  animation: vhs-track-pass 0.4s linear forwards;
}

@keyframes vhs-track-pass {
  0% {
    opacity: 0;
    height: 0;
    top: var(--vhs-start, 30%);
  }
  10% {
    opacity: 1;
    height: 4px;
  }
  50% {
    height: 6px;
    opacity: 0.7;
  }
  90% {
    opacity: 0.3;
    height: 3px;
  }
  100% {
    opacity: 0;
    height: 0;
    top: var(--vhs-end, 70%);
  }
}

.vhs-tracking__bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 10%,
    rgba(255, 255, 255, 0.15) 20%,
    rgba(255, 255, 255, 0.04) 35%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.06) 70%,
    rgba(255, 255, 255, 0.1) 90%,
    transparent 100%
  );
  -webkit-backdrop-filter: blur(1px) saturate(1.5);
  backdrop-filter: blur(1px) saturate(1.5);
}

/* ── Color Bleed on fast scroll ── */
.vhs-colorbleed {
  position: fixed;
  inset: 0;
  z-index: var(--z-texture);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  mix-blend-mode: screen;
  background:
    linear-gradient(180deg,
      rgba(255, 50, 50, 0.03) 0%,
      transparent 8%,
      transparent 92%,
      rgba(50, 50, 255, 0.03) 100%
    );
}

.vhs-colorbleed.is-active {
  opacity: 1;
}

/* ── Tape Warp (horizontal displacement band) ── */
.vhs-warp {
  position: fixed;
  left: 0;
  right: 0;
  height: 60px;
  z-index: var(--z-texture);
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
}

.vhs-warp.is-active {
  animation: tape-warp 0.3s ease-out forwards;
}

@keyframes tape-warp {
  0% {
    opacity: 0;
    transform: scaleY(0.5);
    clip-path: inset(30% 0);
  }
  30% {
    opacity: 0.5;
    transform: scaleY(1.2) skewX(-0.5deg);
    clip-path: inset(5% 0);
  }
  60% {
    opacity: 0.3;
    transform: scaleY(0.8) skewX(0.3deg);
  }
  100% {
    opacity: 0;
    transform: scaleY(1) skewX(0deg);
    clip-path: inset(50% 0);
  }
}

.vhs-warp__content {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    0deg,
    transparent 0%,
    rgba(255, 255, 255, 0.02) 20%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(255, 255, 255, 0.02) 80%,
    transparent 100%
  );
  -webkit-backdrop-filter: blur(0.5px);
  backdrop-filter: blur(0.5px);
}

/* ── Global VHS Jitter (rare, full-screen micro-shake) ── */
.vhs-jitter {
  animation: vhs-jitter-shake 0.08s steps(2) 3;
}

@keyframes vhs-jitter-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(2px, 0); }
  50%  { transform: translate(-1px, 1px); }
  75%  { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0); }
}

/* ── Static Noise Flash (very brief) ── */
.vhs-static {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-overlay) + 1);
  pointer-events: none;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
  background-size: 100px 100px;
  mix-blend-mode: overlay;
}

.vhs-static.is-flash {
  animation: static-flash 0.12s steps(3) forwards;
}

@keyframes static-flash {
  0%   { opacity: 0; }
  20%  { opacity: 0.4; }
  40%  { opacity: 0.1; }
  60%  { opacity: 0.3; }
  80%  { opacity: 0.05; }
  100% { opacity: 0; }
}
