/* ==========================================================================
   FW Custom Cursor — DSGVO-konform, vanilla, kein externes Asset.
   Konfiguration via CSS-Custom-Properties auf #fw-cursor-root, gesetzt
   vom JS aus den Admin-Settings.
   ========================================================================== */

#fw-cursor-root {
  /* CSS-Variablen als Schnittstelle zum JS. Defaults sind sicherer Standard. */
  --fwc-color:        #6366f1;
  --fwc-opacity:      1;
  --fwc-size:         12px;
  --fwc-border-c:     transparent;
  --fwc-border-w:     0px;
  --fwc-blend:        normal;

  --fwc-outer-color:  #6366f1;
  --fwc-outer-size:   40px;
  --fwc-outer-border-c: rgba(99,102,241,.45);
  --fwc-outer-border-w: 1.5px;

  --fwc-trail-color:  rgba(99,102,241,.4);
  --fwc-trail-size:   6px;

  --fwc-hover-scale:  2;
  --fwc-hover-color:  #f59e0b;

  --fwc-click-color:  #6366f1;
  --fwc-glow-color:   rgba(99,102,241,.35);

  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2147483645; /* unter Modal-Overlays, über allem anderen */
  contain: layout style paint;
  will-change: transform;
}

/* Wenn aktiv, native cursor entweder verstecken oder erhalten */
html.fw-cursor-active { cursor: none; }
html.fw-cursor-active * { cursor: none !important; }
html.fw-cursor-active-preserve,
html.fw-cursor-active-preserve * { cursor: auto; }

/* Inputs/Textareas brauchen eh den Text-Caret — niemals verstecken */
html.fw-cursor-active input,
html.fw-cursor-active textarea,
html.fw-cursor-active [contenteditable="true"],
html.fw-cursor-active [contenteditable=""] { cursor: text !important; }

/* ==========================================================================
   Inner Dot (primärer Cursor)
   ========================================================================== */
.fw-cursor-dot {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--fwc-size);
  height: var(--fwc-size);
  margin-top: calc(var(--fwc-size) / -2);
  margin-left: calc(var(--fwc-size) / -2);
  background: var(--fwc-color);
  opacity: var(--fwc-opacity);
  border: var(--fwc-border-w) solid var(--fwc-border-c);
  mix-blend-mode: var(--fwc-blend);
  will-change: transform;
  transform: translate3d(-100px, -100px, 0);
  transition:
    width    0.25s cubic-bezier(0.22, 1, 0.36, 1),
    height   0.25s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.2s ease,
    border-radius 0.25s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.2s ease;
}

/* Formen */
.fw-cursor-shape-dot      .fw-cursor-dot { border-radius: 50%; }
.fw-cursor-shape-ring     .fw-cursor-dot { border-radius: 50%; background: transparent; border-width: 2px; border-color: var(--fwc-color); }
.fw-cursor-shape-dot-ring .fw-cursor-dot { border-radius: 50%; }
.fw-cursor-shape-square   .fw-cursor-dot { border-radius: 2px; }
.fw-cursor-shape-diamond  .fw-cursor-dot { border-radius: 2px; transform-origin: center; }
.fw-cursor-shape-blob     .fw-cursor-dot {
  border-radius: 50% 40% 50% 60% / 60% 50% 40% 50%;
  animation: fwBlobMorph 6s ease-in-out infinite;
}
@keyframes fwBlobMorph {
  0%, 100% { border-radius: 50% 40% 50% 60% / 60% 50% 40% 50%; }
  33%      { border-radius: 60% 40% 30% 70% / 40% 60% 70% 30%; }
  66%      { border-radius: 40% 60% 70% 30% / 50% 40% 60% 50%; }
}

/* Cross + Arrow + Triangle: separate elements für saubere Geometrie */
.fw-cursor-shape-cross .fw-cursor-dot {
  background: transparent;
}
.fw-cursor-shape-cross .fw-cursor-dot::before,
.fw-cursor-shape-cross .fw-cursor-dot::after {
  content: "";
  position: absolute;
  background: var(--fwc-color);
  border-radius: 1px;
}
.fw-cursor-shape-cross .fw-cursor-dot::before {
  top: 0; left: 50%; width: 2px; height: 100%; transform: translateX(-50%);
}
.fw-cursor-shape-cross .fw-cursor-dot::after {
  top: 50%; left: 0; width: 100%; height: 2px; transform: translateY(-50%);
}

.fw-cursor-shape-arrow .fw-cursor-dot {
  background: transparent;
  border: none;
  width: calc(var(--fwc-size) * 1.4);
  height: calc(var(--fwc-size) * 1.4);
  margin-top: calc(var(--fwc-size) * -0.2);
  margin-left: calc(var(--fwc-size) * -0.2);
}
.fw-cursor-shape-arrow .fw-cursor-dot::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  border-left: var(--fwc-size) solid var(--fwc-color);
  border-top: calc(var(--fwc-size) * 0.6) solid transparent;
  border-bottom: calc(var(--fwc-size) * 0.6) solid transparent;
  filter: drop-shadow(0 0 4px var(--fwc-color));
}

.fw-cursor-shape-triangle .fw-cursor-dot {
  background: transparent;
  width: 0;
  height: 0;
  border-left:   calc(var(--fwc-size) / 2) solid transparent;
  border-right:  calc(var(--fwc-size) / 2) solid transparent;
  border-bottom: calc(var(--fwc-size) * 0.9) solid var(--fwc-color);
  border-radius: 0;
  margin-top: calc(var(--fwc-size) * -0.45);
  margin-left: calc(var(--fwc-size) / -2);
}

/* ==========================================================================
   Outer Ring (sekundärer Cursor, optional)
   ========================================================================== */
.fw-cursor-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--fwc-outer-size);
  height: var(--fwc-outer-size);
  margin-top: calc(var(--fwc-outer-size) / -2);
  margin-left: calc(var(--fwc-outer-size) / -2);
  border-radius: 50%;
  border: var(--fwc-outer-border-w) solid var(--fwc-outer-border-c);
  background: var(--fwc-outer-color);
  opacity: 0.0; /* JS toggelt opacity wenn enabled */
  mix-blend-mode: var(--fwc-blend);
  will-change: transform;
  transform: translate3d(-100px, -100px, 0);
  transition:
    width    0.3s cubic-bezier(0.22, 1, 0.36, 1),
    height   0.3s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.25s ease,
    background 0.25s ease,
    opacity 0.25s ease;
}
#fw-cursor-root[data-outer="on"] .fw-cursor-ring { opacity: 1; }

/* ==========================================================================
   Trail-Punkte (Spur)
   ========================================================================== */
.fw-cursor-trail {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
.fw-trail-dot {
  position: absolute;
  width: var(--fwc-trail-size);
  height: var(--fwc-trail-size);
  margin-top: calc(var(--fwc-trail-size) / -2);
  margin-left: calc(var(--fwc-trail-size) / -2);
  border-radius: 50%;
  background: var(--fwc-trail-color);
  mix-blend-mode: var(--fwc-blend);
  will-change: transform, opacity;
}

/* ==========================================================================
   Hover-State (auf interaktiven Elementen)
   ========================================================================== */
#fw-cursor-root.is-hovering .fw-cursor-dot {
  width: calc(var(--fwc-size) * var(--fwc-hover-scale));
  height: calc(var(--fwc-size) * var(--fwc-hover-scale));
  margin-top: calc(var(--fwc-size) * var(--fwc-hover-scale) / -2);
  margin-left: calc(var(--fwc-size) * var(--fwc-hover-scale) / -2);
  background: var(--fwc-hover-color);
}
#fw-cursor-root.is-hovering .fw-cursor-ring {
  width: calc(var(--fwc-outer-size) * 0.6);
  height: calc(var(--fwc-outer-size) * 0.6);
  margin-top: calc(var(--fwc-outer-size) * -0.3);
  margin-left: calc(var(--fwc-outer-size) * -0.3);
  border-color: var(--fwc-hover-color);
  opacity: 0.55;
}

/* Text-Caret-Hover: schmaler I-Beam */
#fw-cursor-root.is-text .fw-cursor-dot {
  width: 2px;
  height: calc(var(--fwc-size) * 1.6);
  margin-top: calc(var(--fwc-size) * -0.8);
  margin-left: -1px;
  border-radius: 0;
  background: var(--fwc-color);
}
#fw-cursor-root.is-text .fw-cursor-ring { opacity: 0; }

/* Hide-Mode: kompletter Cursor verschwindet (z.B. bei expliziter [data-cursor="hide"]) */
#fw-cursor-root.is-hidden .fw-cursor-dot,
#fw-cursor-root.is-hidden .fw-cursor-ring,
#fw-cursor-root.is-hidden .fw-trail-dot { opacity: 0; }

/* ==========================================================================
   Button-Lift + Glow (Hover-Hervorhebung)
   ========================================================================== */
[data-fwc-lift] {
  transition:
    transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.3s ease;
  will-change: transform;
}
[data-fwc-lift].is-fwc-hovered {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px -8px var(--fwc-glow-color, rgba(99,102,241,.35));
  filter: brightness(1.04);
}

/* Magnet-Effekt: Button wird vom JS via translate3d transformiert.
   transition sorgt für smoothes Zurückgleiten, sobald Klasse weg ist. */
[data-fwc-magnet] {
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* ==========================================================================
   Click-Effekte
   ========================================================================== */
#fw-cursor-root.is-clicking .fw-cursor-dot {
  transform-origin: center;
  animation: fwClickPulse 0.4s ease-out;
}
@keyframes fwClickPulse {
  0%   { transform: translate3d(var(--fwc-x, 0), var(--fwc-y, 0), 0) scale(1); }
  50%  { transform: translate3d(var(--fwc-x, 0), var(--fwc-y, 0), 0) scale(0.7); }
  100% { transform: translate3d(var(--fwc-x, 0), var(--fwc-y, 0), 0) scale(1); }
}

.fw-click-ripple {
  position: fixed;
  pointer-events: none;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  margin-left: -5px;
  border-radius: 50%;
  border: 2px solid var(--fwc-click-color, #6366f1);
  z-index: 2147483644;
  opacity: 1;
  animation: fwRipple 0.6s ease-out forwards;
}
@keyframes fwRipple {
  to { width: 80px; height: 80px; margin-top: -40px; margin-left: -40px; opacity: 0; }
}

.fw-click-splash {
  position: fixed;
  pointer-events: none;
  z-index: 2147483644;
}
.fw-click-splash span {
  position: absolute;
  top: 0; left: 0;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--fwc-click-color, #6366f1);
  animation: fwSplash 0.55s ease-out forwards;
}

/* ==========================================================================
   Reduced-Motion / Print: alles aus
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  #fw-cursor-root,
  .fw-click-ripple,
  .fw-click-splash { display: none !important; }
  html.fw-cursor-active,
  html.fw-cursor-active * { cursor: auto !important; }
  [data-fwc-magnet] { transform: none !important; }
}

@media print {
  #fw-cursor-root,
  .fw-click-ripple,
  .fw-click-splash { display: none !important; }
}

/* Touch-Geräte: JS entfernt den Root, aber Fallback falls JS lädt zu spät */
@media (hover: none) and (pointer: coarse) {
  #fw-cursor-root { display: none !important; }
  html.fw-cursor-active,
  html.fw-cursor-active * { cursor: auto !important; }
}
