/* ═══════════════════════════════════════════════════════════════════════════
   UnlockedMagick — Enchant Layer v2
   Uplifting · exciting · powerful · progressive discovery
   Great-Hall warmth (not storm gloom). Time bends as you explore.
   Opt-out: body[data-no-enchant]
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --ench-dawn: #2a1c42;
  --ench-hall: #352550;
  --ench-gold: #ffd978;
  --ench-amber: #f5c84c;
  --ench-rose: rgba(255, 190, 210, 0.22);
  --ench-sky: rgba(160, 205, 255, 0.2);
  --ench-warm: rgba(255, 230, 160, 0.32);
  --ench-glow: 0.22;
  --ench-ceil: 0.28; /* ceiling lantern strength */
}

/* ── Base: warm enchanted hall (lift the void) ─────────────────────────────── */
body:not([data-no-cosmic]):not([data-no-enchant]) {
  background: #221834 !important;
  transition: background-color 1.2s ease;
}
body:not([data-no-cosmic]):not([data-no-enchant])::before {
  background:
    /* Golden ceiling lanterns — Great Hall feast light */
    radial-gradient(ellipse 100% 55% at 50% -2%,  rgba(255, 230, 150, 0.38) 0%, transparent 58%),
    radial-gradient(ellipse 55% 40% at 18% 8%,   rgba(255, 200, 120, 0.2) 0%, transparent 62%),
    radial-gradient(ellipse 50% 38% at 82% 10%,  rgba(255, 190, 140, 0.16) 0%, transparent 60%),
    /* Soft dawn violet + sky — wonder, not storm */
    radial-gradient(ellipse 80% 50% at 12% 55%,  rgba(180, 150, 255, 0.16) 0%, transparent 62%),
    radial-gradient(ellipse 75% 48% at 90% 50%,  rgba(120, 180, 255, 0.14) 0%, transparent 60%),
    radial-gradient(ellipse 95% 50% at 50% 105%, rgba(100, 170, 255, 0.12) 0%, transparent 55%),
    /* Warm hall floor — purple-amber, never pure black */
    radial-gradient(ellipse 140% 120% at 50% 50%, #2c2044 0%, #221834 48%, #1a1228 100%) !important;
  transition: opacity 1s ease, filter 1.2s ease;
}

/* Stars → gold dust over warm air */
body:not([data-no-enchant]) .cp-layer[data-cp-layer="stars"] {
  opacity: 0.48;
  mix-blend-mode: screen;
}
body:not([data-no-enchant]) .cp-starfield::after {
  background-image: radial-gradient(circle at 50% 35%, transparent 30%, rgba(20, 12, 32, 0.28) 100%);
}
body:not([data-no-enchant]) .cp-nebula {
  opacity: 0.9;
  filter: blur(40px) saturate(1.25) brightness(1.08);
  background:
    radial-gradient(circle 52vmax at 22% 12%,  rgba(255, 220, 130, 0.22), transparent 62%),
    radial-gradient(circle 48vmax at 78% 22%,  rgba(190, 150, 255, 0.16), transparent 65%),
    radial-gradient(circle 42vmax at 55% 78%,  rgba(130, 200, 255, 0.14), transparent 65%),
    radial-gradient(circle 36vmax at 28% 72%,  rgba(255, 170, 190, 0.1), transparent 68%) !important;
}

/* Sanctuary breath → floating-candle warmth */
body:not([data-no-sanctuary]):not([data-no-enchant]) .um-sanctuary-breath::before {
  background: radial-gradient(circle, rgba(255, 225, 150, 0.42), transparent 68%) !important;
  opacity: 0.78;
}
body:not([data-no-sanctuary]):not([data-no-enchant]) .um-sanctuary-breath::after {
  background: radial-gradient(circle, rgba(190, 160, 255, 0.26), transparent 70%) !important;
  opacity: 0.58;
}

/* ── Progressive stages: hall brightens, time softens ─────────────────────── */
body.ench-stage-0 { --ench-glow: 0.18; --ench-ceil: 0.26; }
body.ench-stage-1 { --ench-glow: 0.32; --ench-ceil: 0.38; }
body.ench-stage-2 { --ench-glow: 0.48; --ench-ceil: 0.52; }
body.ench-stage-3 { --ench-glow: 0.65; --ench-ceil: 0.7; }

/* Stage 1 — second door: warmer amber wash */
body:not([data-no-enchant]).ench-stage-1::before {
  filter: brightness(1.06) saturate(1.08);
}
body:not([data-no-enchant]).ench-stage-1 .cp-nebula {
  opacity: 0.95;
}

/* Stage 2 — map brightens + soft time-bend vignette */
body:not([data-no-enchant]).ench-stage-2::before {
  filter: brightness(1.12) saturate(1.12);
}
body:not([data-no-enchant]).ench-stage-2 {
  background: #2a1f40 !important;
}

/* Stage 3 — full wonder: hall fully lit */
body:not([data-no-enchant]).ench-stage-3::before {
  filter: brightness(1.18) saturate(1.18);
}
body:not([data-no-enchant]).ench-stage-3 {
  background: #322548 !important;
}
body:not([data-no-enchant]).ench-stage-2 .um-btn-primary,
body:not([data-no-enchant]).ench-stage-3 .um-btn-primary {
  box-shadow:
    0 0 32px rgba(255, 215, 0, 0.42),
    0 0 60px rgba(255, 200, 100, 0.18),
    0 10px 30px rgba(0, 0, 0, 0.28);
}
body:not([data-no-enchant]).ench-stage-3 .um-path-card,
body:not([data-no-enchant]).ench-stage-3 .um-sanctuary-pillar {
  border-color: rgba(255, 217, 120, 0.42);
  box-shadow: 0 0 40px rgba(255, 200, 100, 0.12);
}

/* ── Gold dust motes ───────────────────────────────────────────────────────── */
.um-enchant-motes {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.um-enchant-motes span {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff8e0, #ffd978 40%, transparent 70%);
  box-shadow: 0 0 10px rgba(255, 217, 120, 0.85);
  opacity: 0;
  animation: umMoteFloat linear infinite;
}
@keyframes umMoteFloat {
  0%   { opacity: 0; transform: translate3d(0, 24px, 0) scale(0.55); }
  10%  { opacity: 0.9; }
  80%  { opacity: 0.45; }
  100% { opacity: 0; transform: translate3d(var(--mx, 24px), -115vh, 0) scale(1.15); }
}

/* ── Floating candles (Great Hall) — more appear as stage rises ───────────── */
.um-enchant-candles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.um-enchant-candles .um-candle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #fffef5 0%, #ffd978 35%, #f0a030 70%, transparent 100%);
  box-shadow:
    0 0 12px 4px rgba(255, 210, 100, 0.55),
    0 0 28px 8px rgba(255, 180, 60, 0.25);
  opacity: 0;
  animation: umCandleBob ease-in-out infinite;
}
.um-enchant-candles .um-candle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 18px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, rgba(255, 200, 100, 0.35), transparent);
  border-radius: 1px;
}
@keyframes umCandleBob {
  0%, 100% {
    opacity: var(--c-op, 0.55);
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    opacity: calc(var(--c-op, 0.55) * 1.15);
    transform: translate3d(var(--c-dx, 6px), var(--c-dy, -10px), 0) scale(1.08);
  }
}

/* Stage gates for candles */
body.ench-stage-0 .um-enchant-candles .um-candle:nth-child(n+5) { display: none; }
body.ench-stage-1 .um-enchant-candles .um-candle:nth-child(n+9) { display: none; }
body.ench-stage-2 .um-enchant-candles .um-candle:nth-child(n+14) { display: none; }
/* stage-3 shows all */

/* ── Time-bend overlay (stage 2+) — soft merging rings ─────────────────────── */
.um-time-bend {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s ease;
  background:
    radial-gradient(circle 40vmax at 50% 45%, transparent 40%, rgba(255, 220, 140, 0.04) 55%, transparent 70%),
    conic-gradient(from 0deg at 50% 48%,
      transparent 0deg,
      rgba(255, 210, 120, 0.03) 40deg,
      transparent 80deg,
      rgba(160, 190, 255, 0.03) 160deg,
      transparent 220deg,
      rgba(200, 160, 255, 0.03) 300deg,
      transparent 360deg);
  mix-blend-mode: screen;
}
body.ench-stage-2 .um-time-bend,
body.ench-stage-3 .um-time-bend {
  opacity: 1;
  animation: umTimeSpin 90s linear infinite;
}
body.ench-stage-3 .um-time-bend {
  animation-duration: 60s;
  background:
    radial-gradient(circle 45vmax at 50% 45%, transparent 35%, rgba(255, 230, 150, 0.06) 52%, transparent 72%),
    conic-gradient(from 0deg at 50% 48%,
      transparent 0deg,
      rgba(255, 220, 140, 0.05) 35deg,
      transparent 70deg,
      rgba(150, 200, 255, 0.04) 140deg,
      transparent 200deg,
      rgba(210, 160, 255, 0.04) 280deg,
      transparent 360deg);
}
@keyframes umTimeSpin {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(1.04); }
  100% { transform: rotate(360deg) scale(1); }
}

/* Brief pulse when stage advances */
.um-time-pulse {
  position: fixed;
  inset: 0;
  z-index: 9300;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 40%, rgba(255, 230, 160, 0.28), transparent 55%);
  transition: opacity 0.6s ease;
}
.um-time-pulse.on {
  opacity: 1;
  animation: umTimePulse 1.1s ease-out forwards;
}
@keyframes umTimePulse {
  0%   { opacity: 0.7; transform: scale(0.92); }
  40%  { opacity: 0.45; }
  100% { opacity: 0; transform: scale(1.08); }
}

/* ── Playful living words ──────────────────────────────────────────────────── */
.um-word-live {
  display: inline-block;
  min-width: 0.5em;
  color: var(--ench-gold);
  text-shadow: 0 0 18px rgba(255, 217, 120, 0.5);
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease, letter-spacing 0.35s ease;
  cursor: default;
}
.um-word-live.is-flipping {
  opacity: 0.12;
  transform: translateY(5px) scale(0.94) rotateX(28deg);
  filter: blur(2.5px);
  letter-spacing: 0.06em;
}
body.ench-stage-2 .um-word-live,
body.ench-stage-3 .um-word-live {
  text-shadow:
    0 0 20px rgba(255, 217, 120, 0.55),
    0 0 36px rgba(255, 180, 80, 0.25);
}

/* Labels that rewrite themselves at higher stages */
.um-label-live {
  transition: color 0.5s ease, text-shadow 0.5s ease;
}
body.ench-stage-2 .um-label-live,
body.ench-stage-3 .um-label-live {
  color: #ffe9a8;
  text-shadow: 0 0 12px rgba(255, 210, 100, 0.35);
}

/* ── Corner whisper — Marauder-map style ───────────────────────────────────── */
#umEnchantWhisper {
  position: fixed;
  z-index: 9400;
  left: 50%;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px));
  transform: translateX(-50%) translateY(8px);
  max-width: min(440px, 92vw);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12.5px;
  letter-spacing: 0.045em;
  line-height: 1.35;
  color: #fff6d8;
  background: linear-gradient(145deg, rgba(48, 32, 72, 0.92), rgba(28, 18, 48, 0.9));
  border: 1px solid rgba(255, 217, 120, 0.42);
  box-shadow:
    0 10px 36px rgba(0, 0, 0, 0.35),
    0 0 28px rgba(255, 200, 100, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  text-align: center;
}
#umEnchantWhisper.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Hero gold lift */
body:not([data-no-enchant]) .um-hero-title .gold {
  background: linear-gradient(135deg, #fffaf0 0%, #ffe08a 28%, #ffd700 52%, #e8b84d 78%, #fff0c0 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

/* Sanctuary parchment glass warmer */
body:not([data-no-enchant]) .um-sanctuary-band .usb-inner {
  background:
    linear-gradient(145deg, rgba(52, 36, 72, 0.94), rgba(28, 18, 44, 0.9)),
    rgba(255, 235, 190, 0.04);
  border-color: rgba(255, 215, 130, 0.38);
  box-shadow:
    0 0 90px rgba(255, 200, 100, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Soft scroll-edge glow grows with stage */
body:not([data-no-enchant])::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: 120px;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 220, 140, calc(var(--ench-ceil, 0.28) * 0.45)),
    transparent
  );
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .um-enchant-motes span { animation: none !important; opacity: 0.3; }
  .um-enchant-candles .um-candle { animation: none !important; opacity: 0.4; }
  .um-word-live.is-flipping { filter: none; transform: none; opacity: 0.5; }
  .um-time-bend { animation: none !important; opacity: 0.35; }
  .um-time-pulse { animation: none !important; }
  #umEnchantWhisper { transition: none; }
  body:not([data-no-cosmic]):not([data-no-enchant])::before { transition: none; }
}
