/* ==========================================================================
   THE WISE JAM · Disco Ball 3D & Volumetric Light Show (Dark + Light)
   Modulo autonomo: scende dall header con fisica spring, proietta raggi
   volumetrici e riflessi a specchio 3D su tutta la pagina.
   ========================================================================== */

:root {
  /* Spring easing realistico per discesa motorizzata con rimbalzo smorzato */
  --wjp-disco-spring: linear(
    0, 0.012 1%, 0.048 2.2%, 0.19 4.8%, 0.62 11%, 0.94 17%,
    1.08 22%, 1.11 25.5%, 1.09 29%, 1.01 36%, 0.965 42%,
    0.96 46%, 0.985 54%, 1.012 63%, 1.008 71%, 0.997 82%, 1
  );
  --wjp-disco-top: 112px;
  --wjp-disco-cable-h: 14px;
  --wjp-disco-size: 94px;
}

/* Canvas full-viewport per raggi volumetrici e riflessi a specchio */
.wjp-disco-lights {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 44;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.65s ease-out;
  mix-blend-mode: screen;
}

:root[data-theme="light"] .wjp-disco-lights {
  mix-blend-mode: normal;
}

body.wjp-disco-on .wjp-disco-lights {
  opacity: 1;
}

/* Vignette atmosferica sottile in Dark Mode per far risaltare i fasci */
.wjp-disco-atmo {
  position: fixed;
  inset: 0;
  z-index: 43;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.7s ease-out;
  background:
    radial-gradient(62% 46% at 50% 8%, rgba(34, 211, 238, 0.14), transparent 68%),
    radial-gradient(45% 42% at 22% 28%, rgba(168, 85, 247, 0.11), transparent 70%),
    radial-gradient(45% 42% at 78% 28%, rgba(244, 114, 182, 0.10), transparent 70%);
}

:root[data-theme="light"] .wjp-disco-atmo {
  background:
    radial-gradient(58% 42% at 50% 8%, rgba(8, 145, 178, 0.10), transparent 66%),
    radial-gradient(42% 38% at 22% 26%, rgba(124, 58, 237, 0.08), transparent 68%),
    radial-gradient(42% 38% at 78% 26%, rgba(219, 39, 119, 0.07), transparent 68%);
}

body.wjp-disco-on .wjp-disco-atmo {
  opacity: 1;
}

/* Rig della Disco Ball: scende da dietro l header */
.wjp-disco-rig {
  position: fixed;
  top: var(--wjp-disco-top);
  left: clamp(340px, 36.8vw, 560px);
  z-index: 46;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transform-origin: top center;
  /* Fallback standard per browser senza linear() */
  transform: translate3d(-50%, -260px, 0) scale(0.92);
  opacity: 0;
  transition:
    transform 0.9s cubic-bezier(0.34, 1.45, 0.64, 1),
    opacity 0.35s ease-out;
  transition-timing-function: var(--wjp-disco-spring), ease-out;
  will-change: transform, opacity;
}

@supports not (animation-timing-function: linear(0, 1)) {
  .wjp-disco-rig {
    transition:
      transform 0.75s cubic-bezier(0.34, 1.45, 0.64, 1),
      opacity 0.35s ease-out;
  }
}

body.wjp-disco-on .wjp-disco-rig {
  transform: translate3d(-50%, 0, 0) scale(1);
  opacity: 1;
}

/* Quando si scrolla in basso, si compatta leggermente per non ingombrare */
body.wjp-disco-on.wjp-disco-scrolled .wjp-disco-rig {
  transform: translate3d(-50%, -26px, 0) scale(0.76);
  transition:
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease-out;
}

/* Oscillazione pendolare morbida solo se reduced-motion non e attivo */
.wjp-disco-pendulum {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: top center;
}

@media (prefers-reduced-motion: no-preference) {
  body.wjp-disco-on .wjp-disco-pendulum {
    animation: wjpDiscoSway 6.4s ease-in-out infinite;
  }
}

@keyframes wjpDiscoSway {
  0%, 100% { transform: rotate(-1.6deg); }
  50% { transform: rotate(1.6deg); }
}

/* Placca motore + asta metallica spazzolata */
.wjp-disco-mount {
  width: 28px;
  height: 10px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(90deg, #334155 0%, #e2e8f0 38%, #94a3b8 64%, #1e293b 100%);
  box-shadow: 0 4px 12px rgba(2, 6, 23, 0.45);
}

.wjp-disco-cable {
  width: 3px;
  height: var(--wjp-disco-cable-h);
  background: linear-gradient(90deg, #475569 0%, #f8fafc 50%, #334155 100%);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.35);
}

.wjp-disco-collar {
  width: 16px;
  height: 8px;
  border-radius: 4px 4px 2px 2px;
  margin-bottom: -3px;
  z-index: 2;
  background: linear-gradient(90deg, #475569 0%, #f1f5f9 45%, #64748b 100%);
  box-shadow: 0 2px 6px rgba(2, 6, 23, 0.5);
}

/* Bottone-sfera interattivo (click = Turbo Spin) */
.wjp-disco-ball-btn {
  position: relative;
  width: var(--wjp-disco-size);
  height: var(--wjp-disco-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  display: grid;
  place-items: center;
  outline-offset: 6px;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.wjp-disco-ball-btn:hover {
  transform: scale(1.05);
}

.wjp-disco-ball-btn:active {
  transform: scale(0.96);
}

.wjp-disco-ball-btn:focus-visible {
  outline: 2px solid var(--wjp-accent, #22d3ee);
}

/* Alone luminoso attorno alla sfera */
.wjp-disco-ball-btn::before {
  content: "";
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    circle,
    rgba(248, 250, 252, 0.34) 0%,
    rgba(34, 211, 238, 0.24) 36%,
    rgba(168, 85, 247, 0.14) 62%,
    transparent 74%
  );
  filter: blur(8px);
  opacity: 0.9;
}

:root[data-theme="light"] .wjp-disco-ball-btn::before {
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.65) 0%,
    rgba(8, 145, 178, 0.22) 40%,
    rgba(124, 58, 237, 0.14) 64%,
    transparent 76%
  );
}

.wjp-disco-ball-canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  filter: drop-shadow(0 12px 24px rgba(2, 6, 23, 0.45));
}

:root[data-theme="light"] .wjp-disco-ball-canvas {
  filter: drop-shadow(0 10px 22px rgba(15, 23, 42, 0.24));
}

/* Riflesso cromatico sottile sulle card frosted glass in Disco Mode */
body.wjp-disco-on .wjp-regia-player,
body.wjp-disco-on .wjp-chat-panel {
  border-color: rgba(34, 211, 238, 0.38);
  box-shadow:
    var(--wjp-shadow),
    0 0 38px rgba(34, 211, 238, 0.12),
    0 0 64px rgba(168, 85, 247, 0.10);
}

:root[data-theme="light"] body.wjp-disco-on .wjp-regia-player,
:root[data-theme="light"] body.wjp-disco-on .wjp-chat-panel {
  border-color: rgba(124, 58, 237, 0.30);
  box-shadow:
    var(--wjp-shadow),
    0 0 28px rgba(8, 145, 178, 0.12),
    0 0 46px rgba(124, 58, 237, 0.09);
}

/* Stile attivo del bottone Disco Mode nella barra player e dock */
.wjp-btn-disco[aria-pressed="true"] {
  border-color: rgba(34, 211, 238, 0.65) !important;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.22), rgba(168, 85, 247, 0.24)) !important;
  color: var(--wjp-ink-strong) !important;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.24);
}

:root[data-theme="light"] .wjp-btn-disco[aria-pressed="true"] {
  border-color: rgba(124, 58, 237, 0.55) !important;
  background: linear-gradient(135deg, rgba(8, 145, 178, 0.16), rgba(124, 58, 237, 0.18)) !important;
  color: #0f172a !important;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.18);
}

.wjp-btn-disco .wjp-disco-btn-ico {
  transition: transform 0.35s ease;
}

.wjp-btn-disco[aria-pressed="true"] .wjp-disco-btn-ico {
  color: var(--wjp-accent, #22d3ee);
}

/* Mobile & schermi medi: sfera compatta e leggermente a destra per non coprire logo/titolo */
@media (max-width: 1024px) {
  :root {
    --wjp-disco-top: 104px;
    --wjp-disco-cable-h: 16px;
    --wjp-disco-size: 72px;
  }
  .wjp-disco-rig {
    left: auto;
    right: 22px;
    transform: translate3d(0, -220px, 0) scale(0.92);
  }
  body.wjp-disco-on .wjp-disco-rig {
    transform: translate3d(0, 0, 0) scale(1);
  }
  body.wjp-disco-on.wjp-disco-scrolled .wjp-disco-rig {
    transform: translate3d(0, -18px, 0) scale(0.78);
  }
}

@media (max-width: 640px) {
  :root {
    --wjp-disco-top: 98px;
    --wjp-disco-cable-h: 4px;
    --wjp-disco-size: 54px;
  }
  .wjp-disco-rig {
    right: 14px;
  }
}

/* Rispetto prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .wjp-disco-rig,
  body.wjp-disco-on.wjp-disco-scrolled .wjp-disco-rig {
    transition: opacity 0.25s ease-out;
  }
  .wjp-disco-pendulum {
    animation: none !important;
  }
}
