/* ==========================================================================
   XEDLABS — TORCH LENS SYSTEM v1.0
   • Single-DOM grayscale overlay with radial mask cutout
   • Soft-feathered pink halo ring
   • 60fps requestAnimationFrame cursor tracking
   • Mobile ambient drift fallback
   • prefers-reduced-motion respect
   ========================================================================== */

/* ─────────────────────────────────────────────────────────────
   1. GRAYSCALE OVERLAY — covers entire viewport
   Applies backdrop-filter: grayscale + contrast boost.
   The radial-gradient mask punches a soft circular hole
   wherever the torch (cursor) sits.
   ───────────────────────────────────────────────────────────── */
.torch-overlay {
  position: fixed;
  inset: 0;
  z-index: 9990;
  pointer-events: none;
  backdrop-filter: grayscale(100%) contrast(1.05) brightness(0.92);
  -webkit-backdrop-filter: grayscale(100%) contrast(1.05) brightness(0.92);
  -webkit-mask-image: radial-gradient(
    circle var(--torch-r, 180px) at var(--torch-x, 50%) var(--torch-y, 50%),
    transparent 55%,
    rgba(0,0,0,0.25) 70%,
    rgba(0,0,0,0.65) 82%,
    black 100%
  );
  mask-image: radial-gradient(
    circle var(--torch-r, 180px) at var(--torch-x, 50%) var(--torch-y, 50%),
    transparent 55%,
    rgba(0,0,0,0.25) 70%,
    rgba(0,0,0,0.65) 82%,
    black 100%
  );
  transition: opacity 0.6s ease;
}

/* When torch is OFF (full-color mode), hide the overlay */
.torch-overlay.is-off {
  opacity: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* ─────────────────────────────────────────────────────────────
   2. NEON PINK HALO RING — soft-feathered glow around beam
   ───────────────────────────────────────────────────────────── */
.torch-halo {
  position: fixed;
  z-index: 9991;
  pointer-events: none;
  border-radius: 50%;
  /* Size matches the torch radius × 2 */
  width: calc(var(--torch-r, 180px) * 2);
  height: calc(var(--torch-r, 180px) * 2);
  /* Centered on torch position */
  left: var(--torch-x, 50%);
  top: var(--torch-y, 50%);
  transform: translate(-50%, -50%);
  /* Soft pink glow ring */
  background: radial-gradient(
    circle at center,
    transparent 50%,
    rgba(255, 30, 138, 0.0) 56%,
    rgba(255, 30, 138, 0.12) 62%,
    rgba(255, 30, 138, 0.22) 68%,
    rgba(255, 30, 138, 0.12) 74%,
    rgba(255, 30, 138, 0.04) 82%,
    transparent 100%
  );
  transition: opacity 0.6s ease;
}

.torch-halo.is-off {
  opacity: 0;
}

/* ─────────────────────────────────────────────────────────────
   3. TORCH MODE TOGGLE BUTTON (header)
   ───────────────────────────────────────────────────────────── */
.torch-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs, 4px);
  padding: var(--space-xs, 8px) var(--space-sm, 12px);
  background: var(--color-paper-2, #1a1d26);
  border: 1px solid var(--color-rule, #333);
  border-radius: var(--radius-pill, 9999px);
  color: var(--color-muted, #999);
  font-size: var(--text-xs, 0.75rem);
  font-family: var(--font-mono, monospace);
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  line-height: 1;
}

.torch-toggle-btn:hover {
  border-color: #FF1E8A;
  color: #FF1E8A;
}

/* Active state: torch is ON */
.torch-toggle-btn[aria-pressed="true"] {
  border-color: #FF1E8A;
  color: #FF1E8A;
  background: rgba(255, 30, 138, 0.1);
}

/* Torch icon (small flashlight SVG) */
.torch-toggle-btn .torch-ico {
  width: 14px;
  height: 14px;
}

/* ─────────────────────────────────────────────────────────────
   4. HIDE CUSTOM CURSOR IN TORCH MODE
   The torch IS the cursor now, so hide the magnetic dot/ring.
   ───────────────────────────────────────────────────────────── */
body.torch-active .magnetic-cursor-dot,
body.torch-active .magnetic-cursor-ring {
  opacity: 0 !important;
}

/* In torch mode on desktop, hide the default cursor */
@media (pointer: fine) {
  body.torch-active {
    cursor: none;
  }
  body.torch-active a,
  body.torch-active button,
  body.torch-active input,
  body.torch-active select,
  body.torch-active textarea,
  body.torch-active [role="button"],
  body.torch-active summary {
    cursor: none;
  }
}

/* ─────────────────────────────────────────────────────────────
   5. REDUCED MOTION — disable torch entirely
   ───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .torch-overlay,
  .torch-halo {
    display: none !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   6. MOBILE — the halo uses CSS transitions for smoother
      ambient drift (no mousemove). Overlay stays identical.
   ───────────────────────────────────────────────────────────── */
@media (pointer: coarse) {
  .torch-halo {
    transition: left 2.5s cubic-bezier(0.16, 1, 0.3, 1),
                top 2.5s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.6s ease;
  }
  .torch-overlay {
    transition: -webkit-mask-image 0s, mask-image 0s, opacity 0.6s ease;
  }
}
