/* ---------------------------------------------------------------
   Motion: theme-matched animations (see js/motion.js).
   Runes are "carved" and glow amber; nothing bounces like a toy.
   With prefers-reduced-motion, base.css shortens every animation
   to 1 ms and js/motion.js skips the overlays entirely.
---------------------------------------------------------------- */

/* ---------- Section change: rune seal ---------- */
.rune-seal {
  position: fixed; inset: 0; z-index: 80; pointer-events: none;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(244,239,230,.92), rgba(244,239,230,.35) 45%, rgba(244,239,230,0) 75%);
  animation: seal-veil 700ms var(--ease) both;
}
.rune-seal__mark .rune { --size: 160px; --stroke: var(--c-amber-text); filter: drop-shadow(0 0 16px rgba(212,154,70,.8)); }
.rune-seal__mark { animation: seal-mark 700ms var(--ease) both; }
.rune-seal__line {
  position: absolute; left: 50%; top: 50%; width: min(70vw, 520px); height: 2px;
  background: linear-gradient(90deg, transparent, var(--c-amber), transparent);
  transform: translate(-50%, -50%) scaleX(0);
  animation: seal-line 700ms var(--ease) both;
}
@keyframes seal-veil { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
@keyframes seal-mark {
  0% { opacity: 0; transform: scale(.7) rotate(-6deg); }
  30% { opacity: 1; transform: scale(1) rotate(0); }
  70% { opacity: .9; }
  100% { opacity: 0; transform: scale(1.15); }
}
@keyframes seal-line { 0% { transform: translate(-50%, -50%) scaleX(0); opacity: 0; } 35% { opacity: 1; transform: translate(-50%, -50%) scaleX(1); } 100% { opacity: 0; transform: translate(-50%, -50%) scaleX(1.2); } }

/* ---------- Cards rise into view ---------- */
.reveal { opacity: 0; transform: translateY(14px); }
.reveal.is-visible {
  opacity: 1; transform: none;
  transition: opacity 520ms var(--ease) calc(var(--ri, 0) * 60ms), transform 520ms var(--ease) calc(var(--ri, 0) * 60ms),
    box-shadow var(--t-med), border-color var(--t-med);
}
/* hover lift still works once a card has risen */
.section-card.reveal.is-visible:hover, .home-sec.reveal.is-visible:hover { transform: translateY(-2px); }

/* ---------- Active nav link: the amber line is carved in ---------- */
.nav-desktop a { position: relative; }
.nav-desktop a[aria-current="page"] { box-shadow: none; }
.nav-desktop a::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px;
  background: var(--c-amber); border-radius: 2px;
  transform: scaleX(0); transition: transform 380ms var(--ease);
}
.nav-desktop a[aria-current="page"]::after { transform: scaleX(1); }
.nav-mobile a[aria-current="page"] .rune { animation: nav-glow 600ms var(--ease); }
@keyframes nav-glow { 40% { transform: translateY(-3px) scale(1.15); filter: drop-shadow(0 0 6px rgba(240,201,135,.8)); } }

/* ---------- Rune sparks (purchases, right answers, level up) ---------- */
.burst { position: fixed; z-index: 75; width: 0; height: 0; pointer-events: none; }
.burst__ring {
  position: absolute; left: -30px; top: -30px; width: 60px; height: 60px; border-radius: 50%;
  border: 2px solid var(--c-amber); opacity: 0;
  animation: burst-ring 650ms var(--ease) both;
}
.burst__spark { position: absolute; left: 0; top: 0; animation: burst-fly 900ms var(--ease) var(--sd, 0ms) both; }
.burst__spark .rune { --size: 26px; --stroke: var(--c-amber-text); filter: drop-shadow(0 0 5px rgba(240,201,135,.95)); }
@keyframes burst-ring { 0% { opacity: .9; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.8); } }
@keyframes burst-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot)); }
}

/* ---------- XP token flying to the wallet ---------- */
.xp-token {
  position: fixed; z-index: 76; pointer-events: none;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--c-forest); color: var(--c-amber-soft); font-weight: 800; font-size: .85rem;
  border: 1.5px solid var(--c-amber); box-shadow: var(--shadow-2);
  transform: translate(-50%, -50%);
  animation: token-fly 850ms cubic-bezier(.5, 0, .3, 1) both;
}
.xp-token .rune { --size: 14px; --stroke: var(--c-amber-soft); }
@keyframes token-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  15% { opacity: 1; transform: translate(-50%, calc(-50% - 18px)) scale(1.05); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(.5); }
}

/* ---------- Shop: bought / equipped item, avatar "dressing" glow ---------- */
.item-card.is-acquired { animation: acquired 900ms var(--ease); }
@keyframes acquired {
  0% { box-shadow: 0 0 0 0 rgba(212,154,70,.7); border-color: var(--c-amber); }
  60% { box-shadow: 0 0 0 10px rgba(212,154,70,0); border-color: var(--c-amber); }
  100% { box-shadow: var(--shadow-1); }
}
.is-dressing { position: relative; }
.is-dressing::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius-lg); pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(240,201,135,.45) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: dressing 900ms var(--ease) both;
}
@keyframes dressing { from { background-position: 120% 0; opacity: 1; } to { background-position: -40% 0; opacity: 0; } }

/* ---------- Rune crate: shake, then a burst of light ---------- */
.crate-shake { display: grid; justify-items: center; padding: 14px 0; animation: crate-shake 700ms ease-in-out both; }
.crate-shake .rune { --stroke: var(--c-amber-text); }
@keyframes crate-shake {
  0%, 100% { transform: none; }
  15% { transform: rotate(-8deg); } 30% { transform: rotate(7deg); } 45% { transform: rotate(-6deg) scale(1.05); }
  60% { transform: rotate(5deg) scale(1.08); } 75% { transform: rotate(-3deg) scale(1.1); } 90% { transform: scale(1.14); }
}
.crate-reveal { position: relative; }
.crate-reveal__rays {
  position: absolute; left: 50%; top: 38%; width: 160px; height: 160px; margin: -80px 0 0 -80px; z-index: -1;
  background: repeating-conic-gradient(rgba(240,201,135,.35) 0 10deg, transparent 10deg 30deg);
  border-radius: 50%;
  mask-image: radial-gradient(circle, #000 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 70%);
  animation: rays 1.6s var(--ease) both;
}
@keyframes rays { from { opacity: 0; transform: scale(.4) rotate(0); } 30% { opacity: 1; } to { opacity: 0; transform: scale(1.2) rotate(60deg); } }

/* ---------- Lessons: steps slide in, answers react ---------- */
.lesson__body > .card { animation: step-in 360ms var(--ease) both; }
@keyframes step-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.option.is-correct { animation: correct-glow 700ms var(--ease); }
@keyframes correct-glow { 0% { box-shadow: 0 0 0 0 rgba(47,107,79,.55); } 100% { box-shadow: 0 0 0 12px rgba(47,107,79,0); } }
.option.is-wrong, .is-shake { animation: shake 380ms ease-in-out; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }
.acc-meter.is-shift { animation: meter-shift 500ms var(--ease); }
@keyframes meter-shift { 40% { transform: scale(1.12); } }
.lifeline-bar.is-fired { animation: fired 900ms var(--ease); }
.lifeline-bar.is-fired .rune { animation: fired-rune 900ms var(--ease); }
@keyframes fired { 0% { box-shadow: 0 0 0 0 rgba(212,154,70,.7); } 100% { box-shadow: 0 0 0 14px rgba(212,154,70,0); } }
@keyframes fired-rune { 30% { transform: scale(1.3) rotate(-8deg); filter: drop-shadow(0 0 10px rgba(240,201,135,.9)); } }

/* ---------- Results: stars are struck one by one ---------- */
.results { animation: step-in 360ms var(--ease) both; }
.results__stars .stars > span { display: inline-block; animation: star-strike 520ms var(--ease) both; }
.results__stars .stars > span:nth-child(1) { animation-delay: 150ms; }
.results__stars .stars > span:nth-child(2) { animation-delay: 330ms; }
.results__stars .stars > span:nth-child(3) { animation-delay: 510ms; }
@keyframes star-strike { 0% { opacity: 0; transform: scale(.3) rotate(-25deg); } 70% { opacity: 1; transform: scale(1.2); } 100% { transform: none; } }
.results__xp strong { display: inline-block; animation: xp-rise 700ms var(--ease) 200ms both; }
@keyframes xp-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Progress bars fill when a page opens ---------- */
.progress-card .progress > span, .quest__bar > span, .unit .progress > span { animation: bar-fill 1s var(--ease) 150ms both; }
@keyframes bar-fill { from { transform: scaleX(0); } }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
  .rune-seal, .burst, .xp-token { display: none; }
}
