/* Hypnodutch immersive listening overlay
   Triggered by .listen-btn buttons on /course. Fullscreen takeover with
   breathing purple gradient, drifting particle canvas, purple Luuk silhouette
   that pulses with the audio, synced captions at the bottom. Click backdrop
   or X to exit. */

#hd-immersive {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 35%, #2a1a4a 0%, #15102e 45%, #0a0a18 100%);
  color: #E8EAF0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  overflow: hidden;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

#hd-immersive.is-open {
  display: flex;
  animation: hd-imm-fade-in 0.7s ease-out both;
}

#hd-immersive.is-closing {
  animation: hd-imm-fade-out 0.5s ease-in both;
}

@keyframes hd-imm-fade-in {
  from { opacity: 0; transform: scale(1.04); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes hd-imm-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

#hd-immersive .hd-imm-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: saturate(1.05) contrast(1.08) brightness(0.72);
  transform: scale(1.02);
  transition: opacity 0.9s ease;
  pointer-events: none;
}
#hd-immersive.has-video .hd-imm-video { opacity: 0.42; }
#hd-immersive .hd-imm-video-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 8, 20, 0.20), rgba(10, 10, 24, 0.78)),
    radial-gradient(circle at 50% 42%, rgba(238, 214, 255, 0.10), transparent 42%);
  pointer-events: none;
}
#hd-immersive .hd-imm-geometry {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0.42;
  pointer-events: none;
}
#hd-immersive.has-video .hd-imm-geometry { opacity: 0.18; }
#hd-immersive .hd-imm-geometry span {
  position: absolute;
  width: min(72vmin, 760px);
  aspect-ratio: 1;
  border: 1px solid rgba(214, 188, 250, 0.22);
  border-radius: 50%;
  box-shadow: inset 0 0 42px rgba(96, 219, 204, 0.06), 0 0 32px rgba(214, 188, 250, 0.08);
  animation: hd-geo-spin 36s linear infinite;
}
#hd-immersive .hd-imm-geometry span:nth-child(2) {
  width: min(58vmin, 620px);
  border-radius: 18%;
  transform: rotate(45deg);
  animation-duration: 44s;
  animation-direction: reverse;
}
#hd-immersive .hd-imm-geometry span:nth-child(3) {
  width: min(44vmin, 480px);
  clip-path: polygon(50% 0, 100% 86%, 0 86%);
  border-radius: 0;
  border-color: rgba(96, 219, 204, 0.18);
  animation-duration: 52s;
}
#hd-immersive .hd-imm-geometry span:nth-child(4) {
  width: min(31vmin, 340px);
  border-color: rgba(242, 203, 107, 0.18);
  animation-duration: 28s;
  animation-direction: reverse;
}
#hd-immersive .hd-imm-geometry span:nth-child(5) {
  width: min(18vmin, 190px);
  border-radius: 24%;
  border-color: rgba(255, 255, 255, 0.18);
  animation-duration: 18s;
}
@keyframes hd-geo-spin {
  from { transform: rotate(0deg) scale(0.96); }
  50% { transform: rotate(180deg) scale(1.04); }
  to { transform: rotate(360deg) scale(0.96); }
}

/* Slow drifting gradient backdrop (wave-like breathing) */
#hd-immersive .hd-imm-aura {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(circle at 20% 30%, rgba(155, 90, 220, 0.30), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(110, 60, 200, 0.22), transparent 55%),
    radial-gradient(circle at 60% 20%, rgba(220, 140, 255, 0.14), transparent 60%);
  filter: blur(10px);
  animation: hd-imm-aura-drift 22s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hd-imm-aura-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(2%, -1%) scale(1.06); }
}

/* Particle canvas */
#hd-immersive canvas.hd-imm-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.7;
}

/* Center stack */
#hd-immersive .hd-imm-stack {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 720px;
  width: 100%;
}

/* Purple Luuk silhouette */
#hd-immersive .hd-imm-luuk {
  position: relative;
  width: clamp(160px, 32vmin, 320px);
  height: clamp(160px, 32vmin, 320px);
  margin: 8px 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 50% 85%;
  animation: hd-luuk-wander 18s ease-in-out infinite;
}
#hd-immersive .hd-imm-luuk-glow {
  position: absolute;
  inset: -25%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(180, 120, 255, 0.45), rgba(120, 70, 200, 0.18) 45%, transparent 70%);
  filter: blur(28px);
  animation: hd-imm-luuk-pulse 4.6s ease-in-out infinite;
}
#hd-immersive .hd-imm-luuk img,
#hd-immersive .hd-imm-luuk svg {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 14px 30px rgba(80, 30, 140, 0.55)) hue-rotate(45deg) saturate(1.4);
  animation: hd-imm-breath 5.4s ease-in-out infinite;
}
#hd-immersive .hd-imm-luuk-bubble {
  position: absolute;
  left: 50%;
  top: -12px;
  transform: translate(-50%, -100%) scale(0.98);
  min-width: min(260px, 72vw);
  max-width: min(320px, 78vw);
  padding: 10px 14px;
  border: 1px solid rgba(220, 180, 255, 0.42);
  border-radius: 18px 18px 18px 6px;
  background: rgba(19, 15, 42, 0.78);
  backdrop-filter: blur(12px);
  color: #f5efff;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
#hd-immersive .hd-imm-luuk-bubble.is-shown {
  opacity: 1;
  transform: translate(-50%, -100%) scale(1);
}
@keyframes hd-imm-luuk-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50%      { opacity: 0.95; transform: scale(1.08); }
}
@keyframes hd-imm-breath {
  0%, 100% { transform: scale(1); }
  45%      { transform: scale(1.04); }
}
@keyframes hd-luuk-wander {
  0%, 100% { translate: 0 0; rotate: -1deg; }
  25% { translate: -18px 8px; rotate: 1.5deg; }
  50% { translate: 14px -4px; rotate: -0.8deg; }
  75% { translate: 20px 10px; rotate: 1deg; }
}
#hd-immersive.luuk-sleeping .hd-imm-luuk {
  animation: hd-luuk-sleep 9s ease-in-out both;
}
#hd-immersive.luuk-sleeping .hd-imm-luuk img {
  animation: hd-luuk-sleep-breath 3.4s ease-in-out infinite !important;
}
@keyframes hd-luuk-sleep {
  0% { translate: 0 0; rotate: 0deg; }
  22% { translate: 18px 18px; rotate: 8deg; }
  100% { translate: 28px 38px; rotate: 12deg; }
}
@keyframes hd-luuk-sleep-breath {
  0%, 100% { transform: scale(0.98); filter: drop-shadow(0 14px 30px rgba(80, 30, 140, 0.45)); }
  50% { transform: scale(1.02); filter: drop-shadow(0 14px 34px rgba(96, 219, 204, 0.26)); }
}

/* Concentric breathing rings */
#hd-immersive .hd-imm-rings {
  position: absolute;
  width: clamp(220px, 50vmin, 520px);
  height: clamp(220px, 50vmin, 520px);
  pointer-events: none;
}
#hd-immersive .hd-imm-rings span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(220, 180, 255, 0.18);
  animation: hd-imm-ring 7.2s ease-out infinite;
}
#hd-immersive .hd-imm-rings span:nth-child(2) { animation-delay: 1.4s; }
#hd-immersive .hd-imm-rings span:nth-child(3) { animation-delay: 2.8s; }
#hd-immersive .hd-imm-rings span:nth-child(4) { animation-delay: 4.2s; }
@keyframes hd-imm-ring {
  0%   { transform: scale(0.55); opacity: 0; }
  20%  { opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Title + meta */
#hd-immersive .hd-imm-eyebrow {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(220, 180, 255, 0.7);
  margin-bottom: 14px;
}
#hd-immersive .hd-imm-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-style: italic;
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1.15;
  margin: 4px 0 8px;
  color: #f0e6ff;
  text-shadow: 0 4px 24px rgba(120, 70, 200, 0.4);
}
#hd-immersive .hd-imm-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: rgba(232, 234, 240, 0.62);
  line-height: 1.6;
  max-width: 520px;
  margin: 0 auto 32px;
}

/* Time + scrubber */
#hd-immersive .hd-imm-time {
  display: flex;
  justify-content: space-between;
  font-family: 'Inter', monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: rgba(220, 180, 255, 0.55);
  margin: 18px 0 6px;
  width: clamp(220px, 40vmin, 380px);
}
#hd-immersive .hd-imm-bar {
  width: clamp(220px, 40vmin, 380px);
  height: 3px;
  border-radius: 2px;
  background: rgba(220, 180, 255, 0.14);
  overflow: hidden;
  cursor: pointer;
}
#hd-immersive .hd-imm-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b794f4, #d6bcfa);
  box-shadow: 0 0 14px rgba(183, 148, 244, 0.7);
  transition: width 0.18s linear;
}

/* Play/pause button */
#hd-immersive .hd-imm-play {
  margin: 22px 0 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid rgba(220, 180, 255, 0.4);
  background: rgba(180, 120, 255, 0.12);
  backdrop-filter: blur(10px);
  color: #f0e6ff;
  font-size: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.3s ease, border-color 0.3s ease;
}
#hd-immersive .hd-imm-play:hover {
  transform: scale(1.08);
  background: rgba(180, 120, 255, 0.22);
  border-color: rgba(220, 180, 255, 0.7);
}
#hd-immersive .hd-imm-play:active { transform: scale(0.96); }

/* Caption band (bottom) */
#hd-immersive .hd-imm-caption {
  position: absolute;
  bottom: max(36px, 8vh);
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, 88vw);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(16px, 2.4vw, 22px);
  line-height: 1.5;
  text-align: center;
  color: rgba(240, 230, 255, 0.85);
  text-shadow: 0 2px 14px rgba(40, 10, 80, 0.7);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}
#hd-immersive .hd-imm-caption.is-shown { opacity: 1; }

/* Close button */
#hd-immersive .hd-imm-close {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(220, 180, 255, 0.32);
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
  color: #f0e6ff;
  font-size: 20px;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.2s ease, background 0.3s ease;
}
#hd-immersive .hd-imm-close:hover { transform: scale(1.06); background: rgba(120, 70, 200, 0.4); }

#hd-immersive .hd-stardust {
  position: absolute;
  left: 26px;
  bottom: 28px;
  z-index: 7;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(242, 203, 107, 0.55);
  background:
    radial-gradient(circle at 38% 36%, rgba(255,255,255,0.92), rgba(242,203,107,0.68) 22%, rgba(155,90,220,0.26) 54%, rgba(25,18,55,0.18) 72%);
  box-shadow: 0 0 26px rgba(242, 203, 107, 0.34), 0 0 60px rgba(155, 90, 220, 0.22);
  cursor: grab;
  touch-action: none;
}
#hd-immersive .hd-stardust:active,
#hd-immersive .hd-stardust.is-dragging { cursor: grabbing; }
#hd-immersive .hd-stardust-core,
#hd-immersive .hd-stardust-core::before,
#hd-immersive .hd-stardust-core::after {
  position: absolute;
  content: "";
  inset: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.54);
}
#hd-immersive .hd-stardust-core::before {
  inset: -8px;
  transform: rotate(45deg);
  border-radius: 18%;
}
#hd-immersive .hd-stardust-core::after {
  inset: 5px;
  border-color: rgba(96, 219, 204, 0.65);
}
#hd-immersive .hd-stardust-hint {
  position: absolute;
  left: 92px;
  bottom: 46px;
  z-index: 6;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(240, 230, 255, 0.62);
  pointer-events: none;
}
#hd-immersive .hd-sparkle {
  position: absolute;
  z-index: 8;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f9e8a4;
  box-shadow: 0 0 16px rgba(249, 232, 164, 0.9);
  pointer-events: none;
  animation: hd-sparkle-out 0.9s ease-out forwards;
}
@keyframes hd-sparkle-out {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* Reduced motion respect */
@media (prefers-reduced-motion: reduce) {
  #hd-immersive .hd-imm-aura,
  #hd-immersive .hd-imm-geometry span,
  #hd-immersive .hd-imm-luuk img,
  #hd-immersive .hd-imm-luuk,
  #hd-immersive .hd-imm-luuk-glow,
  #hd-immersive .hd-imm-rings span { animation: none !important; }
}

/* Custom listen-btn replacement for raw audio controls */
.listen-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  border-radius: 100px;
  border: 1px solid rgba(180, 120, 255, 0.35);
  background: linear-gradient(180deg, rgba(155, 90, 220, 0.10), rgba(120, 60, 200, 0.04));
  color: #e8d6ff;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
  width: fit-content;
}
.listen-btn:hover {
  border-color: rgba(220, 180, 255, 0.7);
  background: linear-gradient(180deg, rgba(155, 90, 220, 0.20), rgba(120, 60, 200, 0.10));
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(120, 70, 200, 0.28);
}
.listen-btn .play-icon {
  width: 14px; height: 14px;
  display: inline-block;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent currentColor;
}
