/* Entrance animations. Each slide's content mounts fresh, so these play once per slide.
   --d is the element's step in the reveal order, --t an explicit delay. */

@keyframes rise {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

@keyframes slide {
    from { opacity: 0; transform: translateX(-26px); }
    to { opacity: 1; transform: none; }
}

@keyframes drop {
    0% { opacity: 0; transform: translateY(-30px); }
    70% { opacity: 1; transform: translateY(4px); }
    100% { transform: none; }
}

@keyframes slam {
    0% { opacity: 0; transform: scale(1.35); }
    60% { opacity: 1; }
    100% { transform: none; }
}

@keyframes wipe {
    from { clip-path: inset(0 100% 0 0); }
    to { clip-path: inset(0 0 0 0); }
}

@keyframes stamp {
    from { box-shadow: 0 0 0 0 var(--sh); transform: translate(7px, 7px); }
    to { transform: none; }
}

@keyframes glitch {
    0% { opacity: 0; }
    10% { opacity: 1; text-shadow: 5px 0 var(--primary-color), -5px 0 var(--secondary-color); transform: translateX(3px); }
    25% { text-shadow: -4px 0 var(--primary-color), 4px 0 var(--secondary-color); transform: translateX(-3px); }
    40% { text-shadow: 2px 0 var(--primary-color), -2px 0 var(--secondary-color); transform: none; }
    55%, 100% { text-shadow: none; }
}

@keyframes cglitch {
    0% { transform: translate(2px, -1px); text-shadow: 3px 0 var(--secondary-color), -3px 0 var(--primary-color); clip-path: inset(0 0 40% 0); }
    50% { transform: translate(-2px, 1px); text-shadow: -3px 0 var(--secondary-color), 3px 0 var(--primary-color); clip-path: inset(45% 0 0 0); }
    100% { transform: none; clip-path: none; }
}

@keyframes grow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

@keyframes pop {
    0% { transform: scale(0); }
    80% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes blink {
    50% { opacity: 0; }
}

@keyframes drift {
    from { transform: translate(0, 0); }
    to { transform: translate(-8px, -10px); }
}

.a-rise { animation: rise 0.45s calc((var(--d, 0) + 2) * var(--step)) both; }
.a-slide { animation: slide 0.4s calc((var(--d, 0) + 2) * var(--step)) both; }
.a-drop { animation: drop 0.5s var(--t, calc(2 * var(--step))) both; }
.a-wipe { animation: wipe 0.6s steps(12) both; }
.a-type { animation: wipe 1.1s calc((var(--d, 0) + 2) * var(--step)) steps(28) both; }
.a-glitch { animation: glitch 0.9s calc((var(--d, 0) + 2) * var(--step)) both; }
.a-grow { animation: grow 0.7s calc((var(--d, 0) + 2) * var(--step)) cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.a-pop { animation: pop 0.3s calc((var(--d, 0) + 3) * var(--step)) both; }
.a-stamp { animation: stamp 0.35s calc((var(--d, 0) + 2) * var(--step)) both; }

/* Cards with a hard shadow stamp it down after rising. */
.card.hl.a-rise,
.card.list.a-rise {
    animation: rise 0.45s calc((var(--d, 0) + 2) * var(--step)) both, stamp 0.3s calc((var(--d, 0) + 6) * var(--step)) both;
}

/* 1st place slams in, then stamps. */
.mrow.r1.a-drop {
    animation: slam 0.6s var(--t) cubic-bezier(0.2, 1.4, 0.4, 1) both, stamp 0.3s calc(var(--t) + 6 * var(--step)) both;
}

/* A purged podium row switches off once it has landed. */
.mrow.purged { --purge-at: calc(var(--t) + 8 * var(--step)); }
.mrow.purged.a-drop { animation: drop 0.5s var(--t) both, purge-border 0.01s var(--purge-at) both; }
.mrow.purged .tag,
.mrow.purged .mval,
.mrow.purged .mitems { animation: purge-dim 0.5s var(--purge-at) both; }
.mrow.purged .purge-blur { animation: purge-out 0.3s var(--purge-at) both; }
.mrow.purged .purge { animation: purge-in 0.35s calc(var(--purge-at) + 150ms) cubic-bezier(0.2, 1.4, 0.4, 1) both; }

@keyframes purge-border { to { border-style: dashed; } }
@keyframes purge-dim { to { filter: grayscale(1); opacity: 0.45; } }
@keyframes purge-out { to { opacity: 0; filter: blur(12px); } }
@keyframes purge-in {
    from { opacity: 0; transform: scale(1.6); }
    to { opacity: 1; transform: scale(1); }
}

/* Beat pulse: the slide container sets data-beat on every beat and data-bar on every
   downbeat, alternating two values so each change restarts the animation. */
.slide-bg[data-beat="a"] .brackets { animation: beat-a calc(var(--beat) * 0.8) ease-out; }
.slide-bg[data-beat="b"] .brackets { animation: beat-b calc(var(--beat) * 0.8) ease-out; }
.slide-bg[data-bar="a"] .ghost { animation: drift 14s ease-in-out infinite alternate, bar-a calc(var(--beat) * 2) ease-out; }
.slide-bg[data-bar="b"] .ghost { animation: drift 14s ease-in-out infinite alternate, bar-b calc(var(--beat) * 2) ease-out; }

@keyframes beat-a { from { opacity: 0.55; transform: scale(1.012); } to { opacity: 1; transform: none; } }
@keyframes beat-b { from { opacity: 0.55; transform: scale(1.012); } to { opacity: 1; transform: none; } }
@keyframes bar-a { from { -webkit-text-stroke-color: var(--secondary-color); } }
@keyframes bar-b { from { -webkit-text-stroke-color: var(--secondary-color); } }

/* Closing slide reveal order. */
.final .big-recap { animation: glitch 0.9s calc(2 * var(--step)) both; }
.final .tag-cred { animation: rise 0.45s calc(6 * var(--step)) both, stamp 0.3s calc(10 * var(--step)) both; }
.final .who { animation: wipe 0.9s calc(8 * var(--step)) steps(30) both; }
.final .rows-a { animation: rise 0.45s calc(10 * var(--step)) both, stamp 0.3s calc(14 * var(--step)) both; }
.final .pair-line { animation: slide 0.4s calc(16 * var(--step)) both; }
.final .doll { animation: wipe 0.8s calc(18 * var(--step)) steps(20) both; }
.final .decode { animation: pop 0.3s calc(26 * var(--step)) both; }
.final .thx { animation: rise 0.5s calc(28 * var(--step)) both, stamp 0.3s calc(32 * var(--step)) both; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        animation-iteration-count: 1 !important;
    }
}
