/* ═══════════════════════════════════════════════════════════════════════════
   UnlockedMagick — Cosmic Portal Theme (v1)
   Site-wide immersive upgrade. Non-destructive. Opt-out via body[data-no-cosmic].
   ─────────────────────────────────────────────────────────────────────────── */

/* ── Design tokens (extend, don't replace) ─────────────────────────────────── */
:root {
  --cp-obsidian:       #030007;
  --cp-obsidian-2:     #08030f;
  --cp-void:           #0b0618;
  --cp-nebula-violet:  rgba(90, 50, 200, 0.18);
  --cp-nebula-azure:   rgba(40, 110, 210, 0.12);
  --cp-nebula-gold:    rgba(201, 168, 76, 0.12);
  --cp-gold:           #C9A84C;
  --cp-gold-bright:    #FFD700;
  --cp-gold-light:     #E8C96A;
  --cp-gold-glow:      rgba(201, 168, 76, 0.35);
  --cp-rune-glow:      rgba(255, 215, 0, 0.55);
  --cp-glass-bg:       rgba(13, 8, 24, 0.55);
  --cp-glass-border:   rgba(201, 168, 76, 0.28);
  --cp-glass-shine:    rgba(255, 215, 0, 0.08);
  --cp-beam-cyan:      rgba(110, 180, 255, 0.35);
  --cp-beam-violet:    rgba(170, 120, 255, 0.3);
}

/* ── Reduced motion base ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cp-layer, .cp-starfield, .cp-runes, .cp-particle,
  .cp-geom, .cp-hero-ring, .cp-divider {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Fixed ambient background layers ───────────────────────────────────────── */
/* Layer stack (bottom → top):
   1. Deep obsidian radial gradient (body ::before)
   2. Nebula glow (.cp-layer[data-cp-layer="nebula"])
   3. Animated starfield (.cp-layer[data-cp-layer="stars"])
   4. Sacred geometry ring overlay (.cp-layer[data-cp-layer="geom"])
   5. Drifting runes (.cp-layer[data-cp-layer="runes"])
   All are pointer-events:none; z-index: -10 → -6 so page content sits above. */

body:not([data-no-cosmic]) {
  position: relative;
  background: #030007 !important;
}
body:not([data-no-cosmic])::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -11;
  pointer-events: none;
  background:
    radial-gradient(ellipse 120% 80% at 20% 10%,  var(--cp-nebula-gold) 0%,   transparent 55%),
    radial-gradient(ellipse 100% 70% at 85% 25%,  var(--cp-nebula-violet) 0%, transparent 60%),
    radial-gradient(ellipse 90%  60% at 50% 90%,  var(--cp-nebula-azure) 0%,  transparent 65%),
    radial-gradient(ellipse 140% 120% at 50% 50%, #0a0417 0%, #050109 55%, #020006 100%);
}

.cp-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.cp-layer[data-cp-layer="stars"]  { z-index: -10; opacity: 0.8; }
.cp-layer[data-cp-layer="nebula"] { z-index: -9;  opacity: 0.55; mix-blend-mode: screen; }
.cp-layer[data-cp-layer="geom"]   { z-index: -8;  opacity: 0.18; }
.cp-layer[data-cp-layer="runes"]  { z-index: -7;  opacity: 0.45; }

/* Animated starfield (CSS radial dots + slow drift) */
.cp-starfield {
  position: absolute; inset: -10% -10% -10% -10%;
  background-image:
    radial-gradient(1px 1px at 12% 18%,  rgba(255,230,180,0.9) 40%, transparent 41%),
    radial-gradient(1px 1px at 34% 62%,  rgba(200,220,255,0.7) 40%, transparent 41%),
    radial-gradient(1.5px 1.5px at 58% 22%, rgba(255,255,255,0.85) 40%, transparent 41%),
    radial-gradient(1px 1px at 74% 78%,  rgba(255,215,120,0.85) 40%, transparent 41%),
    radial-gradient(1px 1px at 86% 36%,  rgba(190,170,255,0.75) 40%, transparent 41%),
    radial-gradient(1.2px 1.2px at 22% 84%, rgba(255,235,180,0.8) 40%, transparent 41%),
    radial-gradient(1px 1px at 50% 50%,  rgba(220,220,255,0.65) 40%, transparent 41%),
    radial-gradient(1.2px 1.2px at 8% 48%, rgba(255,255,230,0.85) 40%, transparent 41%),
    radial-gradient(1px 1px at 68% 12%,  rgba(190,220,255,0.7) 40%, transparent 41%),
    radial-gradient(1.3px 1.3px at 92% 70%, rgba(255,220,160,0.9) 40%, transparent 41%);
  background-size: 600px 600px, 800px 800px, 1000px 1000px, 700px 700px, 900px 900px,
                   650px 650px, 750px 750px, 850px 850px, 550px 550px, 950px 950px;
  animation: cpStarDrift 120s linear infinite;
}
.cp-starfield::after {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(circle at 50% 50%, transparent 40%, rgba(0,0,0,0.45) 100%);
}
@keyframes cpStarDrift {
  0%   { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(-160px, -80px, 0); }
}

/* Nebula glow (slow pulse) */
.cp-nebula {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle 45vmax at 15% 25%,  rgba(201,168,76,0.18),  transparent 60%),
    radial-gradient(circle 55vmax at 80% 20%,  rgba(120,80,220,0.16),  transparent 65%),
    radial-gradient(circle 50vmax at 70% 85%,  rgba(60,140,220,0.14),  transparent 65%),
    radial-gradient(circle 40vmax at 25% 80%,  rgba(255,215,0,0.08),   transparent 65%);
  animation: cpNebulaPulse 22s ease-in-out infinite alternate;
  filter: blur(30px);
}
@keyframes cpNebulaPulse {
  0%   { transform: scale(1)   rotate(0deg); opacity: 0.55; }
  100% { transform: scale(1.08) rotate(6deg); opacity: 0.75; }
}

/* Sacred geometry overlay (centered Metatron-style rings + dashed) */
.cp-geom {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}
.cp-geom svg {
  width: clamp(600px, 90vmin, 1400px);
  height: clamp(600px, 90vmin, 1400px);
  opacity: 0.55;
  animation: cpGeomSpin 180s linear infinite;
}
@keyframes cpGeomSpin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Drifting rune particles (rendered via JS into .cp-runes) */
.cp-runes { position: absolute; inset: 0; }
.cp-rune {
  position: absolute;
  font-family: 'Cinzel', serif;
  color: var(--cp-rune-glow);
  text-shadow: 0 0 12px rgba(255,215,0,0.45);
  opacity: 0;
  animation: cpRuneFloat 18s linear infinite;
  user-select: none;
  font-size: 14px;
}
@keyframes cpRuneFloat {
  0%   { transform: translateY(12vh) scale(0.6); opacity: 0; }
  10%  { opacity: 0.9; }
  50%  { opacity: 0.7; }
  90%  { opacity: 0.5; }
  100% { transform: translateY(-12vh) scale(1.1); opacity: 0; }
}

/* ── Page hero overlay ─────────────────────────────────────────────────────── */
/* Inserted by JS as the first child of the hero section for each route.
   Fully absolute, pointer-events:none so it never blocks clicks. */
.cp-hero-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.cp-hero-scene > * { position: absolute; }

.cp-hero-ring {
  top: 50%; left: 50%;
  width: min(900px, 95vw);
  height: min(900px, 95vw);
  transform: translate(-50%, -50%);
  opacity: 0.9;
}
.cp-hero-ring svg { width: 100%; height: 100%; display: block; }
.cp-hero-ring .cp-ring-outer { animation: cpRingSpin 90s linear infinite; transform-origin: 50% 50%; transform-box: fill-box; }
.cp-hero-ring .cp-ring-mid   { animation: cpRingSpin 60s linear infinite reverse; transform-origin: 50% 50%; transform-box: fill-box; }
.cp-hero-ring .cp-ring-inner { animation: cpRingSpin 40s linear infinite; transform-origin: 50% 50%; transform-box: fill-box; }
@keyframes cpRingSpin { to { transform: rotate(360deg); } }

.cp-hero-glow {
  top: 50%; left: 50%;
  width: 120%; height: 120%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 50% 55%, rgba(255,215,0,0.18), transparent 38%),
    radial-gradient(circle at 50% 55%, rgba(150,90,255,0.12), transparent 55%);
  filter: blur(24px);
  animation: cpHeroGlowPulse 8s ease-in-out infinite alternate;
}
@keyframes cpHeroGlowPulse {
  0%   { opacity: 0.7; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 1;   transform: translate(-50%,-50%) scale(1.05); }
}

/* Beam rays (for buy / vault) */
.cp-hero-beams {
  top: 0; left: 50%; transform: translateX(-50%);
  width: 140%; height: 120%;
  background:
    conic-gradient(from 200deg at 50% 100%,
      transparent 0deg,
      rgba(255,215,0,0.08) 10deg,
      transparent 20deg,
      rgba(255,215,0,0.06) 35deg,
      transparent 50deg,
      rgba(255,215,0,0.09) 70deg,
      transparent 90deg,
      rgba(255,215,0,0.07) 110deg,
      transparent 130deg,
      rgba(255,215,0,0.08) 150deg,
      transparent 360deg);
  mix-blend-mode: screen;
  opacity: 0.7;
  animation: cpBeamDrift 30s linear infinite;
}
@keyframes cpBeamDrift {
  0%   { transform: translateX(-50%) rotate(0deg); }
  100% { transform: translateX(-50%) rotate(6deg); }
}

/* Constellation dots (tokens page) */
.cp-constellation { inset: 0; width: 100%; height: 100%; opacity: 0.8; }

/* Path trail (how-it-works) */
.cp-path { inset: 0; width: 100%; height: 100%; opacity: 0.7; }
.cp-path path { stroke-dasharray: 4 8; animation: cpPathDash 60s linear infinite; }
@keyframes cpPathDash { to { stroke-dashoffset: -400; } }

/* ── Premium treatments (opt-in via classes) ───────────────────────────────── */
.cp-glass {
  background: var(--cp-glass-bg) !important;
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  border: 1px solid var(--cp-glass-border);
  box-shadow:
    0 10px 40px rgba(0,0,0,0.5),
    inset 0 0 0 1px var(--cp-glass-shine);
}

.cp-cta {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: 999px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #0a0610;
  background: linear-gradient(135deg, #C9A84C 0%, #FFD700 50%, #E8C96A 100%);
  border: 1px solid rgba(255,215,0,0.55);
  box-shadow:
    0 0 24px rgba(201,168,76,0.4),
    0 0 60px rgba(255,215,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.35);
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform .25s ease, box-shadow .25s ease, filter .25s ease;
}
.cp-cta::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 40%, rgba(255,255,255,0.35) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform .7s ease;
}
.cp-cta:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 36px rgba(255,215,0,0.55),
    0 0 80px rgba(255,215,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.45);
  filter: brightness(1.05);
}
.cp-cta:hover::before { transform: translateX(100%); }

/* Section divider — glowing rune line */
.cp-divider {
  position: relative;
  height: 2px;
  margin: 80px auto;
  width: min(80%, 900px);
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(201,168,76,0) 10%,
    rgba(201,168,76,0.5) 45%,
    rgba(255,215,0,0.9) 50%,
    rgba(201,168,76,0.5) 55%,
    rgba(201,168,76,0) 90%,
    transparent 100%);
  filter: drop-shadow(0 0 8px rgba(255,215,0,0.5));
}
.cp-divider::before,
.cp-divider::after {
  content: '✦';
  position: absolute; top: 50%;
  transform: translateY(-50%);
  color: var(--cp-gold-bright);
  font-size: 14px;
  text-shadow: 0 0 10px rgba(255,215,0,0.7);
}
.cp-divider::before { left: calc(50% - 12px); content: '◈'; background: #030007; padding: 0 8px; }
.cp-divider::after  { display: none; }

/* Portal entry vignette — top-of-page subtle fade-in */
body:not([data-no-cosmic]) > main,
body:not([data-no-cosmic]) > section:first-of-type {
  animation: cpFadeIn 1.2s ease-out both;
}
@keyframes cpFadeIn {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── Wizard theme integration ──────────────────────────────────────────────── */
/* Match wizard speech bubble + panel to cosmic palette without touching JS */
#mg-speech {
  border: 1px solid var(--cp-glass-border) !important;
  background: linear-gradient(145deg, rgba(20,12,36,0.92), rgba(8,3,18,0.94)) !important;
  box-shadow:
    0 0 28px rgba(201,168,76,0.28),
    0 6px 24px rgba(0,0,0,0.7) !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#mg-chat {
  background: linear-gradient(165deg, rgba(13,8,24,0.96) 0%, rgba(5,2,12,0.98) 100%) !important;
  border: 1px solid rgba(201,168,76,0.32) !important;
  box-shadow:
    0 28px 90px rgba(0,0,0,0.95),
    0 0 60px rgba(120,80,220,0.08),
    inset 0 0 0 1px rgba(255,215,0,0.06) !important;
}
.cp-wizard-aura {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 240px; height: 240px;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(circle at 50% 60%,
    rgba(255,215,0,0.22) 0%,
    rgba(201,168,76,0.15) 25%,
    rgba(120,80,220,0.08) 50%,
    transparent 70%);
  filter: blur(18px);
  animation: cpWizardAuraPulse 6s ease-in-out infinite alternate;
}
@keyframes cpWizardAuraPulse {
  0%   { opacity: 0.65; transform: scale(1); }
  100% { opacity: 1;    transform: scale(1.06); }
}

/* ── Subtle auto-lift for existing section headings on cosmic pages ────────── */
body:not([data-no-cosmic]) .h1,
body:not([data-no-cosmic]) h1 {
  text-shadow: 0 0 24px rgba(255,215,0,0.15);
}

/* ── Mobile / small-screen tuning ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .cp-geom svg { opacity: 0.35; }
  .cp-hero-ring { width: 120vw; height: 120vw; }
  .cp-nebula { filter: blur(18px); }
  .cp-wizard-aura { width: 160px; height: 160px; right: 10px; bottom: 10px; }
}
