/* =========================================================================
   Custom Cursor & Magnetic Lens Physics
   ========================================================================= */

#cur-dot {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9999;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  mix-blend-mode: difference;
  contain: layout style paint;
  will-change: transform;
  transform-origin: center center;
}

#cur-ring {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9998;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border-radius: 50%;
  background: var(--cur-ring-bg, rgba(150, 150, 150, 0.1));
  color: var(--cur-ring-border, rgba(150, 150, 150, 0.3));
  contain: layout style paint;
  will-change: transform, color, width, height, border-radius;
  transform-origin: center center;
  transition: color 0.15s ease;
}

/* Fallback styles if SVG is not yet mounted */
#cur-ring:not(:has(svg)) {
  border: 1px solid var(--cur-ring-border, rgba(150, 150, 150, 0.3));
}
#cur-dot:not(:has(svg)) {
  background: #fff;
}

/* Hover mode (buttons, controls, nav-items, and inline links):
   Morph cursor into the white Invariant Noether Symmetry Weave logo (never green) */
@keyframes cur-logo-pop {
  0% {
    transform: scale(0.55);
    opacity: 0.4;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

html[data-cursor-mode="link"] #cur-ring {
  color: var(--accent-rim, rgba(200, 250, 75, 0.55));
}
html[data-cursor-mode="link"] #cur-ring:not(:has(svg)) {
  border-color: var(--accent-rim, rgba(200, 250, 75, 0.55));
}

/* Inline links & tags mode: remove the circle ring completely */
html[data-cursor-mode="inline-link"] #cur-ring {
  opacity: 0 !important;
}

html[data-cursor-mode="link"] #cur-dot,
html[data-cursor-mode="inline-link"] #cur-dot {
  width: 22px !important;
  height: 22px !important;
  margin: -11px 0 0 -11px !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: #ffffff !important;
}

html[data-cursor-mode="link"] #cur-dot .cur-dot-circle,
html[data-cursor-mode="inline-link"] #cur-dot .cur-dot-circle {
  display: none !important;
}

html[data-cursor-mode="link"] #cur-dot .cur-dot-logo,
html[data-cursor-mode="inline-link"] #cur-dot .cur-dot-logo {
  display: block !important;
  width: 22px;
  height: 22px;
  color: inherit;
  filter: none;
  animation: cur-logo-pop 0.16s cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
}

/* When mix-blend-mode is forced to normal (e.g. open chat panel) in light mode, use dark ink */
html[data-theme="light"] body:has(.ltc-panel.is-open)[data-cursor-mode="link"] #cur-dot,
html[data-theme="light"] body:has(.ltc-panel.is-open)[data-cursor-mode="inline-link"] #cur-dot,
html[data-theme="light"][data-cursor-mode="link"] body:has(.ltc-panel.is-open) #cur-dot,
html[data-theme="light"][data-cursor-mode="inline-link"] body:has(.ltc-panel.is-open) #cur-dot {
  color: #0A0D13 !important;
}

/* Text mode: reform circle into custom I-beam straight-line caret */
html[data-cursor-mode="text"] #cur-dot {
  opacity: 0 !important;
}

html[data-cursor-mode="text"] #cur-ring {
  opacity: 1 !important;
  width: 2px !important;
  height: 22px !important;
  margin: -11px 0 0 -1px !important;
  border-radius: 1px !important;
  background: var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  border: none !important;
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent, #C8FA4B) 60%, transparent) !important;
  backdrop-filter: none !important;
  transition: background-color 0.15s ease !important;
}

/* Hide SVG circle while in text mode so only reformed I-beam geometry renders */
html[data-cursor-mode="text"] #cur-ring svg {
  display: none !important;
}

/* Horizontal bars (top & bottom serifs) forming the classic "I" shape */
html[data-cursor-mode="text"] #cur-ring::before,
html[data-cursor-mode="text"] #cur-ring::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 8px;
  height: 2px;
  margin-left: -4px;
  background: var(--accent, #C8FA4B);
  border-radius: 1px;
  box-shadow: 0 0 6px color-mix(in srgb, var(--accent, #C8FA4B) 50%, transparent);
}

html[data-cursor-mode="text"] #cur-ring::before {
  top: 0;
}

html[data-cursor-mode="text"] #cur-ring::after {
  bottom: 0;
}

/* High-contrast light mode styling for custom I-beam */
html[data-theme="light"][data-cursor-mode="text"] #cur-ring,
html[data-theme="light"][data-cursor-mode="text"] #cur-ring::before,
html[data-theme="light"][data-cursor-mode="text"] #cur-ring::after {
  background: #0A0D13 !important;
  color: #0A0D13 !important;
  box-shadow: 0 0 4px rgba(10, 13, 19, 0.35) !important;
}

/* =========================================================================
   Zero-lag Performance Over Backdrop-Filter Elements
   Decouple mix-blend-mode: difference to normal over translucent/blur panels
   to completely eliminate GPU framebuffer readbacks and compositor lag.
   ========================================================================= */
body:has(.ltc-panel.is-open) #cur-dot,
body:has(.ltc-panel.is-open) #cur-ring,
.ltc-panel #cur-dot,
.ltc-panel #cur-ring,
html[data-cursor-mode^="resize"] #cur-dot,
html[data-cursor-mode^="resize"] #cur-ring,
html[data-cursor-mode^="grab"] #cur-dot,
html[data-cursor-mode^="grab"] #cur-ring {
  mix-blend-mode: normal !important;
}

body:has(.ltc-panel[data-mode="fullscreen"].is-open) #cur-dot {
  background: transparent !important;
  color: #ffffff !important;
  box-shadow: none !important;
}
html[data-theme="light"] body:has(.ltc-panel[data-mode="fullscreen"].is-open) #cur-dot {
  color: #0A0D13 !important;
}
html[data-theme="light"] body:has(.ltc-panel[data-mode="fullscreen"].is-open) #cur-dot .cur-dot-circle circle {
  fill: #0A0D13 !important;
}
body:has(.ltc-panel[data-mode="fullscreen"].is-open) #cur-ring {
  color: rgba(255, 255, 255, 0.45) !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
  box-shadow: none !important;
}
html[data-theme="light"] body:has(.ltc-panel[data-mode="fullscreen"].is-open) #cur-ring {
  color: rgba(10, 13, 19, 0.45) !important;
  border-color: rgba(10, 13, 19, 0.45) !important;
}

/* =========================================================================
   Custom Morphing Cursor Modes (Resize & Grab)
   ========================================================================= */

/* Cur-icons base state inside cur-ring */
.cur-icon {
  display: none;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.2, 0.9, 0.2, 1);
}

/* Horizontal resize (EW) */
html[data-cursor-mode="resize-ew"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="resize-ew"] #cur-ring {
  opacity: 1 !important;
  width: 44px !important;
  height: 24px !important;
  margin: -12px 0 0 -22px !important;
  border-radius: 999px !important;
  background: rgba(15, 20, 30, 0.9) !important;
  border: 1.5px solid var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 10px color-mix(in srgb, var(--accent, #C8FA4B) 40%, transparent) !important;
}
html[data-cursor-mode="resize-ew"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="resize-ew"] .cur-icon-ew {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) !important;
}

/* Vertical resize (NS) */
html[data-cursor-mode="resize-ns"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="resize-ns"] #cur-ring {
  opacity: 1 !important;
  width: 24px !important;
  height: 44px !important;
  margin: -22px 0 0 -12px !important;
  border-radius: 999px !important;
  background: rgba(15, 20, 30, 0.9) !important;
  border: 1.5px solid var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 10px color-mix(in srgb, var(--accent, #C8FA4B) 40%, transparent) !important;
}
html[data-cursor-mode="resize-ns"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="resize-ns"] .cur-icon-ns {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) !important;
}

/* Diagonal NWSE resize */
html[data-cursor-mode="resize-nwse"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="resize-nwse"] #cur-ring {
  opacity: 1 !important;
  width: 36px !important;
  height: 36px !important;
  margin: -18px 0 0 -18px !important;
  border-radius: 999px !important;
  background: rgba(15, 20, 30, 0.9) !important;
  border: 1.5px solid var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 10px color-mix(in srgb, var(--accent, #C8FA4B) 40%, transparent) !important;
}
html[data-cursor-mode="resize-nwse"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="resize-nwse"] .cur-icon-nwse {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) !important;
}

/* Diagonal NESW resize */
html[data-cursor-mode="resize-nesw"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="resize-nesw"] #cur-ring {
  opacity: 1 !important;
  width: 36px !important;
  height: 36px !important;
  margin: -18px 0 0 -18px !important;
  border-radius: 999px !important;
  background: rgba(15, 20, 30, 0.9) !important;
  border: 1.5px solid var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 10px color-mix(in srgb, var(--accent, #C8FA4B) 40%, transparent) !important;
}
html[data-cursor-mode="resize-nesw"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="resize-nesw"] .cur-icon-nesw {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) !important;
}

/* Grab mode */
html[data-cursor-mode="grab"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="grab"] #cur-ring {
  opacity: 1 !important;
  width: 36px !important;
  height: 36px !important;
  margin: -18px 0 0 -18px !important;
  border-radius: 50% !important;
  background: rgba(15, 20, 30, 0.88) !important;
  border: 1.5px solid var(--accent, #C8FA4B) !important;
  color: var(--accent, #C8FA4B) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 10px color-mix(in srgb, var(--accent, #C8FA4B) 40%, transparent) !important;
}
html[data-cursor-mode="grab"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="grab"] .cur-icon-grab {
  display: block !important;
  opacity: 1 !important;
  transform: scale(1) !important;
}

/* Grabbing mode */
html[data-cursor-mode="grabbing"] #cur-dot {
  opacity: 0 !important;
}
html[data-cursor-mode="grabbing"] #cur-ring {
  opacity: 1 !important;
  width: 32px !important;
  height: 32px !important;
  margin: -16px 0 0 -16px !important;
  border-radius: 50% !important;
  background: var(--accent, #C8FA4B) !important;
  border: 1.5px solid #ffffff !important;
  color: #0A0D13 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 16px var(--accent, #C8FA4B) !important;
}
html[data-cursor-mode="grabbing"] #cur-ring .cur-ring-circle {
  display: none !important;
}
html[data-cursor-mode="grabbing"] .cur-icon-grab {
  display: block !important;
  opacity: 1 !important;
  transform: scale(0.9) !important;
}

/* Light theme overrides for morphing cursor */
html[data-theme="light"][data-cursor-mode^="resize"] #cur-ring,
html[data-theme="light"][data-cursor-mode="grab"] #cur-ring {
  background: rgba(255, 255, 255, 0.95) !important;
  border-color: #0A0D13 !important;
  color: #0A0D13 !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
}
html[data-theme="light"][data-cursor-mode="grabbing"] #cur-ring {
  background: #0A0D13 !important;
  border-color: #0A0D13 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3) !important;
}

/* Universal native cursor suppression: native cursor stays hidden everywhere when custom cursor is active */
@media (hover: hover) and (pointer: fine) {
  html[data-cursor="on"][data-cursor="on"][data-cursor="on"],
  html[data-cursor="on"][data-cursor="on"][data-cursor="on"] *,
  html[data-cursor="on"] .prose code.primer-link,
  html[data-cursor="on"] .primer-link {
    cursor: none !important;
  }
}

/* Accessibility gating */
@media (hover: none) or (pointer: coarse), (prefers-reduced-motion: reduce), (forced-colors: active) {
  #cur-dot,
  #cur-ring {
    display: none !important;
  }
  * {
    cursor: auto !important;
  }
}

