/**
 * Enhanced Animations for Caly-Quiz LMS / Reveal.js
 * Subtle, professional animations that complement the Habilec theme.
 * Works alongside Reveal.js transitions and AOS library.
 * v1.0
 */

/* ============================================
   SLIDE ENTRANCE ANIMATIONS
   Triggered via .ea-fade-up, .ea-fade-left, etc.
   on elements inside Reveal slides.
   ============================================ */

/* --- Base transition for all enhanced-animation elements --- */
.reveal .slides section [class*="ea-"] {
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* --- Fade Up --- */
.reveal .slides section .ea-fade-up {
    opacity: 0;
    transform: translateY(24px);
}
.reveal .slides section.present .ea-fade-up {
    opacity: 1;
    transform: translateY(0);
}

/* --- Fade Down --- */
.reveal .slides section .ea-fade-down {
    opacity: 0;
    transform: translateY(-24px);
}
.reveal .slides section.present .ea-fade-down {
    opacity: 1;
    transform: translateY(0);
}

/* --- Fade Left --- */
.reveal .slides section .ea-fade-left {
    opacity: 0;
    transform: translateX(30px);
}
.reveal .slides section.present .ea-fade-left {
    opacity: 1;
    transform: translateX(0);
}

/* --- Fade Right --- */
.reveal .slides section .ea-fade-right {
    opacity: 0;
    transform: translateX(-30px);
}
.reveal .slides section.present .ea-fade-right {
    opacity: 1;
    transform: translateX(0);
}

/* --- Zoom In (subtle) --- */
.reveal .slides section .ea-zoom-in {
    opacity: 0;
    transform: scale(0.92);
}
.reveal .slides section.present .ea-zoom-in {
    opacity: 1;
    transform: scale(1);
}


/* ============================================
   ANIMATED GRADIENT BACKGROUNDS
   For title slides and section dividers.
   ============================================ */

@keyframes ea-gradient-shift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.reveal .slides section.ea-gradient-bg {
    background: linear-gradient(
        135deg,
        var(--hab-secondary) 0%,
        #1a365d 25%,
        var(--hab-secondary) 50%,
        #0f172a 75%,
        var(--hab-secondary) 100%
    );
    background-size: 300% 300%;
    animation: ea-gradient-shift 12s ease infinite;
}

.reveal .slides section.ea-gradient-bg h1,
.reveal .slides section.ea-gradient-bg h2 {
    color: #fff;
    -webkit-text-fill-color: #fff;
    border: none;
}

.reveal .slides section.ea-gradient-bg p {
    color: rgba(255, 255, 255, 0.8);
}

/* Warm gradient variant (orange-based) */
.reveal .slides section.ea-gradient-warm {
    background: linear-gradient(
        135deg,
        var(--hab-primary-dark) 0%,
        var(--hab-primary) 25%,
        #ea580c 50%,
        var(--hab-primary-dark) 75%,
        var(--hab-primary) 100%
    );
    background-size: 300% 300%;
    animation: ea-gradient-shift 12s ease infinite;
}

.reveal .slides section.ea-gradient-warm h1,
.reveal .slides section.ea-gradient-warm h2,
.reveal .slides section.ea-gradient-warm p {
    color: #fff;
    -webkit-text-fill-color: #fff;
    border: none;
}


/* ============================================
   SVG LINE-DRAWING ANIMATION
   Apply .ea-svg-draw to SVG path/line/circle
   inside a Reveal slide.
   ============================================ */

@keyframes ea-draw-line {
    to {
        stroke-dashoffset: 0;
    }
}

.reveal .slides section .ea-svg-draw path,
.reveal .slides section .ea-svg-draw line,
.reveal .slides section .ea-svg-draw polyline,
.reveal .slides section .ea-svg-draw circle,
.reveal .slides section .ea-svg-draw rect {
    stroke-dasharray: var(--ea-dash-length, 1000);
    stroke-dashoffset: var(--ea-dash-length, 1000);
    transition: stroke-dashoffset 0s;
}

.reveal .slides section.present .ea-svg-draw path,
.reveal .slides section.present .ea-svg-draw line,
.reveal .slides section.present .ea-svg-draw polyline,
.reveal .slides section.present .ea-svg-draw circle,
.reveal .slides section.present .ea-svg-draw rect {
    animation: ea-draw-line 1.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}


/* ============================================
   PULSE EFFECTS FOR INTERACTIVE ELEMENTS
   Buttons, clickable cards, quiz options.
   ============================================ */

@keyframes ea-pulse-ring {
    0%   { transform: scale(1);   opacity: 0.6; }
    70%  { transform: scale(1.12); opacity: 0; }
    100% { transform: scale(1.12); opacity: 0; }
}

.ea-pulse {
    position: relative;
}

.ea-pulse::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid var(--hab-primary);
    animation: ea-pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    pointer-events: none;
}

/* Subtle hover glow for interactive elements */
@keyframes ea-hover-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
    50%      { box-shadow: 0 0 12px 2px rgba(245, 158, 11, 0.15); }
}

.ea-interactive:hover {
    animation: ea-hover-glow 1.5s ease infinite;
}


/* ============================================
   STAGGERED LIST ITEM ANIMATIONS
   Applied automatically by JS to li elements
   inside .ea-stagger-list within Reveal slides.
   ============================================ */

.reveal .slides section .ea-stagger-list > li {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.reveal .slides section.present .ea-stagger-list > li {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delays (set by JS for flexibility, CSS fallback) */
.reveal .slides section.present .ea-stagger-list > li:nth-child(1)  { transition-delay: 0.08s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(2)  { transition-delay: 0.16s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(3)  { transition-delay: 0.24s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(4)  { transition-delay: 0.32s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(5)  { transition-delay: 0.40s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(6)  { transition-delay: 0.48s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(7)  { transition-delay: 0.56s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(8)  { transition-delay: 0.64s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(9)  { transition-delay: 0.72s; }
.reveal .slides section.present .ea-stagger-list > li:nth-child(10) { transition-delay: 0.80s; }


/* ============================================
   CARD FLIP ANIMATION
   For exercise / question cards in Reveal.
   Wrap front/back in .ea-flip-card.
   ============================================ */

.ea-flip-card {
    perspective: 800px;
    width: 100%;
    min-height: 180px;
}

.ea-flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.ea-flip-card.flipped .ea-flip-card-inner {
    transform: rotateY(180deg);
}

.ea-flip-card-front,
.ea-flip-card-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.ea-flip-card-front {
    background: var(--hab-bg-white);
    border: 2px solid var(--hab-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    cursor: pointer;
}

.ea-flip-card-back {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 2px solid var(--hab-primary);
    transform: rotateY(180deg);
}


/* ============================================
   PROGRESS BAR ANIMATIONS
   Animated fill for progress indicators.
   ============================================ */

@keyframes ea-progress-fill {
    from { width: 0; }
}

.ea-progress-bar {
    height: 6px;
    border-radius: 3px;
    background: rgba(245, 158, 11, 0.15);
    overflow: hidden;
    margin: 8px 0;
}

.ea-progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--hab-primary) 0%, var(--hab-accent, #ea580c) 100%);
    animation: ea-progress-fill 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    transition: width 0.6s ease;
}

/* Indeterminate / loading variant */
@keyframes ea-progress-indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(200%); }
}

.ea-progress-bar-indeterminate .ea-progress-bar-fill {
    width: 40%;
    animation: ea-progress-indeterminate 1.4s ease infinite;
}


/* ============================================
   GLOW EFFECTS FOR IMPORTANT ELEMENTS
   Apply .ea-glow to highlight key content.
   ============================================ */

@keyframes ea-glow-pulse {
    0%, 100% {
        box-shadow: 0 0 4px 0 rgba(245, 158, 11, 0.2),
                    0 0 12px 0 rgba(245, 158, 11, 0.08);
    }
    50% {
        box-shadow: 0 0 8px 2px rgba(245, 158, 11, 0.3),
                    0 0 20px 4px rgba(245, 158, 11, 0.12);
    }
}

.ea-glow {
    animation: ea-glow-pulse 3s ease-in-out infinite;
    border-radius: 8px;
}

/* Blue info glow */
.ea-glow-info {
    animation: ea-glow-pulse-info 3s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes ea-glow-pulse-info {
    0%, 100% {
        box-shadow: 0 0 4px 0 rgba(59, 130, 246, 0.2),
                    0 0 12px 0 rgba(59, 130, 246, 0.08);
    }
    50% {
        box-shadow: 0 0 8px 2px rgba(59, 130, 246, 0.3),
                    0 0 20px 4px rgba(59, 130, 246, 0.12);
    }
}

/* Success glow */
.ea-glow-success {
    animation: ea-glow-pulse-success 3s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes ea-glow-pulse-success {
    0%, 100% {
        box-shadow: 0 0 4px 0 rgba(34, 197, 94, 0.2),
                    0 0 12px 0 rgba(34, 197, 94, 0.08);
    }
    50% {
        box-shadow: 0 0 8px 2px rgba(34, 197, 94, 0.3),
                    0 0 20px 4px rgba(34, 197, 94, 0.12);
    }
}

/* Danger glow */
.ea-glow-danger {
    animation: ea-glow-pulse-danger 3s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes ea-glow-pulse-danger {
    0%, 100% {
        box-shadow: 0 0 4px 0 rgba(239, 68, 68, 0.2),
                    0 0 12px 0 rgba(239, 68, 68, 0.08);
    }
    50% {
        box-shadow: 0 0 8px 2px rgba(239, 68, 68, 0.3),
                    0 0 20px 4px rgba(239, 68, 68, 0.12);
    }
}


/* ============================================
   TYPEWRITER CURSOR
   Used by the JS typewriter effect.
   ============================================ */

@keyframes ea-blink-cursor {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

.ea-typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--hab-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: ea-blink-cursor 0.8s step-end infinite;
}

.ea-typewriter-cursor.ea-cursor-done {
    animation: ea-blink-cursor 0.8s step-end 3;
    animation-fill-mode: forwards;
    opacity: 0;
}


/* ============================================
   NUMBER COUNTER DISPLAY
   Styled container for the JS counter.
   ============================================ */

.ea-counter {
    font-family: 'Outfit', 'Inter', sans-serif;
    font-weight: 700;
    font-size: 2.4em;
    color: var(--hab-primary-dark);
    display: inline-block;
    min-width: 2ch;
    text-align: center;
    line-height: 1;
    tabular-nums: true;
    font-variant-numeric: tabular-nums;
}

.ea-counter-unit {
    font-size: 0.5em;
    font-weight: 400;
    color: var(--hab-text-light);
    margin-left: 4px;
}


/* ============================================
   UTILITY: REDUCED MOTION
   Respect user preference for reduced motion.
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .reveal .slides section [class*="ea-"],
    .reveal .slides section .ea-stagger-list > li,
    .ea-flip-card-inner,
    .ea-progress-bar-fill,
    .ea-glow,
    .ea-glow-info,
    .ea-glow-success,
    .ea-glow-danger,
    .ea-pulse::after,
    .ea-typewriter-cursor {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .reveal .slides section.ea-gradient-bg,
    .reveal .slides section.ea-gradient-warm {
        animation: none !important;
        background-size: 100% 100% !important;
    }
}
