/* ============================================================
   ABC Quest — Animation System v1.0
   
   A complete animation library for the RPG learning platform:
   - Entrance animations (fade, slide, scale, bounce)
   - Micro-interactions (hover, tap, pulse)
   - Quest/game effects (confetti, XP popup, level-up)
   - Progress animations (bars, rings, streaks)
   - Character/mascot animations (float, wave, idle)
   ============================================================ */

/* ============================================================
   1. KEYFRAME DEFINITIONS
   ============================================================ */

/* --- Fade & Slide --- */
@keyframes abq-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes abq-fade-in-up {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes abq-fade-in-down {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes abq-fade-in-left {
    from { opacity: 0; transform: translateX(-30px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes abq-fade-in-right {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes abq-fade-in-scale {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

/* --- Bounce & Elastic --- */
@keyframes abq-bounce-in {
    0%   { opacity: 0; transform: scale(0.3); }
    50%  { opacity: 1; transform: scale(1.05); }
    70%  { transform: scale(0.95); }
    100% { transform: scale(1); }
}
@keyframes abq-bounce-up {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}
@keyframes abq-bounce-gentle {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

/* --- Pulse & Glow --- */
@keyframes abq-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}
@keyframes abq-pulse-soft {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.03); opacity: 0.85; }
}
@keyframes abq-glow {
    0%, 100% { box-shadow: 0 0 5px rgba(34,197,94,0.3); }
    50%      { box-shadow: 0 0 20px rgba(34,197,94,0.6), 0 0 40px rgba(34,197,94,0.2); }
}
@keyframes abq-glow-orange {
    0%, 100% { box-shadow: 0 0 5px rgba(249,115,22,0.3); }
    50%      { box-shadow: 0 0 20px rgba(249,115,22,0.6), 0 0 40px rgba(249,115,22,0.2); }
}

/* --- Float & Wave (Mascot) --- */
@keyframes abq-float {
    0%, 100% { transform: translateY(0px); }
    50%      { transform: translateY(-12px); }
}
@keyframes abq-float-slow {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    25%      { transform: translateY(-8px) rotate(-1deg); }
    75%      { transform: translateY(-6px) rotate(1deg); }
}
@keyframes abq-wave {
    0%, 100% { transform: rotate(0deg); }
    25%      { transform: rotate(-5deg); }
    75%      { transform: rotate(5deg); }
}
@keyframes abq-idle-bounce {
    0%, 100% { transform: scaleY(1) scaleX(1); }
    30%      { transform: scaleY(0.92) scaleX(1.04); }
    60%      { transform: scaleY(1.05) scaleX(0.95); }
}

/* --- Shake --- */
@keyframes abq-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}
@keyframes abq-shake-hard {
    0%, 100% { transform: translateX(0); }
    10%, 50%, 90% { transform: translateX(-8px); }
    30%, 70% { transform: translateX(8px); }
}

/* --- Rotate & Spin --- */
@keyframes abq-spin {
    to { transform: rotate(360deg); }
}
@keyframes abq-spin-slow {
    to { transform: rotate(360deg); }
}
@keyframes abq-rotate-coin {
    0%   { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

/* --- Progress --- */
@keyframes abq-progress-fill {
    from { width: 0; }
}
@keyframes abq-progress-ring-fill {
    from { stroke-dashoffset: var(--ring-circumference, 427); }
}
@keyframes abq-bar-stripe {
    0% { background-position: 0 0; }
    100% { background-position: 40px 0; }
}

/* --- XP / Reward --- */
@keyframes abq-xp-popup {
    0%   { opacity: 0; transform: translateY(20px) scale(0.5); }
    30%  { opacity: 1; transform: translateY(-10px) scale(1.2); }
    60%  { transform: translateY(-30px) scale(1); }
    100% { opacity: 0; transform: translateY(-60px) scale(0.8); }
}
@keyframes abq-xp-float-up {
    0%   { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-80px); }
}
@keyframes abq-star-pop {
    0%   { transform: scale(0) rotate(0deg); opacity: 0; }
    50%  { transform: scale(1.4) rotate(180deg); opacity: 1; }
    100% { transform: scale(1) rotate(360deg); opacity: 1; }
}
@keyframes abq-coin-drop {
    0%   { transform: translateY(-200px) rotate(0deg); opacity: 0; }
    50%  { opacity: 1; }
    80%  { transform: translateY(0px) rotate(720deg); }
    90%  { transform: translateY(-10px) rotate(750deg); }
    100% { transform: translateY(0) rotate(720deg); opacity: 1; }
}

/* --- Level Up --- */
@keyframes abq-level-up-flash {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 0.3; }
    50%      { opacity: 0.8; }
}
@keyframes abq-level-up-text {
    0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
    40%  { transform: scale(1.3) rotate(3deg); opacity: 1; }
    70%  { transform: scale(0.9) rotate(-1deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes abq-level-up-rays {
    0%   { transform: scale(0) rotate(0deg); opacity: 0; }
    100% { transform: scale(2) rotate(180deg); opacity: 0; }
}

/* --- Confetti --- */
@keyframes abq-confetti-fall {
    0%   { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
@keyframes abq-confetti-sway {
    0%, 100% { transform: translateX(0); }
    50%      { transform: translateX(30px); }
}

/* --- Streak Flame --- */
@keyframes abq-flame-flicker {
    0%, 100% { transform: scale(1) rotate(-2deg); }
    25%      { transform: scale(1.1) rotate(2deg); }
    50%      { transform: scale(0.95) rotate(-1deg); }
    75%      { transform: scale(1.05) rotate(1deg); }
}

/* --- Typewriter --- */
@keyframes abq-typewriter {
    from { width: 0; }
    to   { width: 100%; }
}
@keyframes abq-cursor-blink {
    0%, 100% { border-color: transparent; }
    50%      { border-color: #22c55e; }
}
@keyframes abq-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

/* --- Loading Skeleton --- */
@keyframes abq-skeleton-loading {
    0%   { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

/* --- Slide In (for mobile panels) --- */
@keyframes abq-slide-in-left {
    from { transform: translateX(-100%); }
    to   { transform: translateX(0); }
}
@keyframes abq-slide-out-left {
    from { transform: translateX(0); }
    to   { transform: translateX(-100%); }
}

/* --- Count Up (used via JS) --- */
@keyframes abq-count-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Pop In (notification/badge) --- */
@keyframes abq-pop-in {
    0%   { transform: scale(0); opacity: 0; }
    80%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Ripple Effect --- */
@keyframes abq-ripple {
    to { transform: scale(4); opacity: 0; }
}

/* --- Spotlight --- */
@keyframes abq-spotlight {
    0%, 100% { opacity: 0; transform: scale(0.8); }
    50%      { opacity: 0.15; transform: scale(1.2); }
}


/* ============================================================
   2. UTILITY CLASSES — Apply animations
   ============================================================ */

/* Entrance animations */
.abq-anim-fade-in       { animation: abq-fade-in 0.6s ease both; }
.abq-anim-fade-in-up    { animation: abq-fade-in-up 0.6s ease both; }
.abq-anim-fade-in-down  { animation: abq-fade-in-down 0.5s ease both; }
.abq-anim-fade-in-left  { animation: abq-fade-in-left 0.6s ease both; }
.abq-anim-fade-in-right { animation: abq-fade-in-right 0.6s ease both; }
.abq-anim-fade-in-scale { animation: abq-fade-in-scale 0.5s ease both; }
.abq-anim-bounce-in     { animation: abq-bounce-in 0.7s cubic-bezier(0.68, -0.55, 0.265, 1.55) both; }

/* Hover micro-interactions */
.abq-hover-lift {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}
.abq-hover-lift:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.12);
}
.abq-hover-scale {
    transition: transform 0.3s ease;
}
.abq-hover-scale:hover {
    transform: scale(1.04);
}
.abq-hover-glow {
    transition: box-shadow 0.3s ease;
}
.abq-hover-glow:hover {
    box-shadow: 0 0 24px rgba(34,197,94,0.3);
}

/* Loop animations */
.abq-loop-float       { animation: abq-float 3s ease-in-out infinite; }
.abq-loop-float-slow  { animation: abq-float-slow 5s ease-in-out infinite; }
.abq-loop-pulse       { animation: abq-pulse 2s ease-in-out infinite; }
.abq-loop-pulse-soft  { animation: abq-pulse-soft 3s ease-in-out infinite; }
.abq-loop-bounce      { animation: abq-bounce-gentle 2s ease-in-out infinite; }
.abq-loop-blink       { animation: abq-blink 1.5s ease-in-out infinite; }
.abq-loop-spin        { animation: abq-spin 1s linear infinite; }
.abq-loop-spin-slow   { animation: abq-spin-slow 8s linear infinite; }
.abq-loop-glow        { animation: abq-glow 2s ease-in-out infinite; }
.abq-loop-glow-orange { animation: abq-glow-orange 2s ease-in-out infinite; }
.abq-loop-flame       { animation: abq-flame-flicker 0.6s ease-in-out infinite; }

/* Entrance delay utilities */
.abq-delay-100 { animation-delay: 0.1s; }
.abq-delay-200 { animation-delay: 0.2s; }
.abq-delay-300 { animation-delay: 0.3s; }
.abq-delay-400 { animation-delay: 0.4s; }
.abq-delay-500 { animation-delay: 0.5s; }
.abq-delay-600 { animation-delay: 0.6s; }
.abq-delay-800 { animation-delay: 0.8s; }
.abq-delay-1000 { animation-delay: 1s; }

/* Stagger children (parent needs .abq-stagger-children) */
.abq-stagger-children > * {
    opacity: 0;
    animation: abq-fade-in-up 0.5s ease forwards;
}
.abq-stagger-children > *:nth-child(1)  { animation-delay: 0.05s; }
.abq-stagger-children > *:nth-child(2)  { animation-delay: 0.10s; }
.abq-stagger-children > *:nth-child(3)  { animation-delay: 0.15s; }
.abq-stagger-children > *:nth-child(4)  { animation-delay: 0.20s; }
.abq-stagger-children > *:nth-child(5)  { animation-delay: 0.25s; }
.abq-stagger-children > *:nth-child(6)  { animation-delay: 0.30s; }
.abq-stagger-children > *:nth-child(7)  { animation-delay: 0.35s; }
.abq-stagger-children > *:nth-child(8)  { animation-delay: 0.40s; }
.abq-stagger-children > *:nth-child(9)  { animation-delay: 0.45s; }
.abq-stagger-children > *:nth-child(10) { animation-delay: 0.50s; }

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* ============================================================
   3. SPECIAL COMPONENT ANIMATIONS
   ============================================================ */

/* --- XP Popup Toast --- */
.abq-xp-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    pointer-events: none;
    animation: abq-xp-popup 1.8s ease-out forwards;
}
.abq-xp-toast-inner {
    background: linear-gradient(135deg, #22c55e, #10b981);
    color: #fff;
    padding: 16px 28px;
    border-radius: 20px;
    font-size: 1.3rem;
    font-weight: 800;
    box-shadow: 0 8px 32px rgba(34,197,94,0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

/* --- Level Up Overlay --- */
.abq-level-up-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.abq-level-up-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(34,197,94,0.3), transparent 70%);
    animation: abq-level-up-flash 2s ease-out both;
}
.abq-level-up-content {
    position: relative;
    text-align: center;
    z-index: 1;
}
.abq-level-up-text {
    font-size: 3rem;
    font-weight: 900;
    color: #22c55e;
    text-shadow: 0 0 40px rgba(34,197,94,0.5), 0 4px 12px rgba(0,0,0,0.2);
    animation: abq-level-up-text 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) both;
}
.abq-level-up-sub {
    font-size: 1.2rem;
    color: #fff;
    font-weight: 700;
    margin-top: 8px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    animation: abq-fade-in-up 0.6s 0.3s ease both;
}

/* --- Confetti Container --- */
.abq-confetti-container {
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: none;
    overflow: hidden;
}
.abq-confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -20px;
    border-radius: 2px;
    animation: abq-confetti-fall 3s linear forwards;
}

/* --- Star Burst --- */
.abq-star-burst {
    position: absolute;
    pointer-events: none;
    animation: abq-star-pop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) both;
}

/* --- Progress Ring Animation --- */
.abq-progress-ring-fill {
    animation: abq-progress-ring-fill 1.2s ease-out forwards;
}

/* --- Progress Bar with Stripes --- */
.abq-bar-striped {
    background-size: 40px 40px;
    background-image: linear-gradient(
        45deg,
        rgba(255,255,255,.15) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255,255,255,.15) 50%,
        rgba(255,255,255,.15) 75%,
        transparent 75%,
        transparent
    );
    animation: abq-bar-stripe 1s linear infinite;
}

/* --- Streak Fire --- */
.abq-streak-fire {
    animation: abq-flame-flicker 0.6s ease-in-out infinite;
    transform-origin: center bottom;
}

/* --- Card Entrance Stagger --- */
.abq-card-entrance {
    opacity: 0;
    transform: translateY(20px);
    animation: abq-fade-in-up 0.5s ease forwards;
}

/* --- Step Progress Dot --- */
.abq-step-dot {
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.abq-step-dot.completed {
    animation: abq-pop-in 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) both;
}

/* --- Click Ripple --- */
.abq-ripple-container {
    position: relative;
    overflow: hidden;
}
.abq-ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    transform: scale(0);
    animation: abq-ripple 0.6s ease-out;
    pointer-events: none;
}

/* --- Skeleton Loading --- */
.abq-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: abq-skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}
.abq-skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}
.abq-skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}
.abq-skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}
.abq-skeleton-card {
    height: 200px;
    border-radius: 16px;
}

/* --- Scroll Reveal --- */
.abq-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}
.abq-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}


/* ============================================================
   4. QUEST CARD EFFECTS
   ============================================================ */

/* Quest Card — 3D hover tilt */
.abq-quest-card-3d {
    perspective: 1000px;
}
.abq-quest-card-3d-inner {
    transition: transform 0.3s ease;
}
.abq-quest-card-3d:hover .abq-quest-card-3d-inner {
    transform: rotateY(3deg) rotateX(-2deg);
}

/* Quest Card — Difficulty glow */
.abq-card-glow-easy   { box-shadow: 0 0 12px rgba(34,197,94,0.15); }
.abq-card-glow-medium { box-shadow: 0 0 12px rgba(245,158,11,0.15); }
.abq-card-glow-hard   { box-shadow: 0 0 12px rgba(239,68,68,0.15); }

/* Quest Card — Status badge pulse */
.abq-card-badge-new {
    animation: abq-pulse 2s ease-in-out infinite;
}

/* Quest Card — Completion overlay */
.abq-card-completed-overlay {
    position: absolute;
    inset: 0;
    background: rgba(34,197,94,0.08);
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.abq-quest-card.completed .abq-card-completed-overlay {
    opacity: 1;
}
.abq-card-checkmark {
    font-size: 2.5rem;
    animation: abq-bounce-in 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) both;
}


/* ============================================================
   5. STEP RUNNER ANIMATIONS
   ============================================================ */

/* Step transition */
@keyframes abq-step-slide-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes abq-step-slide-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-40px); }
}

.abq-step-enter {
    animation: abq-step-slide-in 0.4s ease both;
}
.abq-step-exit {
    animation: abq-step-slide-out 0.3s ease both;
}

/* Step complete celebration */
@keyframes abq-step-complete {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.05); background: #dcfce7; }
    100% { transform: scale(1); background: transparent; }
}
.abq-step-complete-flash {
    animation: abq-step-complete 0.6s ease;
}


/* ============================================================
   6. DASHBOARD WIDGET ANIMATIONS
   ============================================================ */

/* Today's Quest card entrance */
.abq-dashboard-card {
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.abq-dashboard-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

/* Progress ring update */
@keyframes abq-ring-update {
    to { stroke-dashoffset: var(--ring-target, 427); }
}

/* Stat counter */
.abq-stat-counter {
    display: inline-block;
    animation: abq-count-up 0.3s ease both;
}


/* ============================================================
   7. MOBILE BOTTOM NAV ANIMATION
   ============================================================ */

@keyframes abq-nav-icon-bounce {
    0%, 100% { transform: translateY(0); }
    30%      { transform: translateY(-3px); }
    60%      { transform: translateY(0); }
}

.abq-mobile-nav .current-menu-item .abq-nav-icon {
    animation: abq-nav-icon-bounce 0.4s ease;
}
