/* ============================================================
   PersonalStudy — Priority 2: Medium Effort UX Enhancements
   Mobile Bottom Nav · Celebrations · Progress Rings
   
   Add AFTER ux_foundations.css in index.php:
   <link href="assets/ux_priority2.css" rel="stylesheet">
   ============================================================ */


/* ============================================================
   5. MOBILE BOTTOM NAVIGATION
   Source: Duolingo, Brilliant.org, Memrise, Instagram
   
   Persistent bottom bar on mobile with key nav items.
   Hides top nav links on mobile; bottom nav appears instead.
   ============================================================ */

/* --- Bottom Nav Container --- */
.ps-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    background: var(--bg-card, #fff);
    border-top: 1px solid var(--border, #e8eaf0);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.ps-bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    max-width: 480px;
    margin: 0 auto;
    height: 56px;
}

/* --- Bottom Nav Items --- */
.ps-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 2px;
    padding: 6px 4px;
    color: var(--text-muted, #9ca3af);
    text-decoration: none;
    font-size: 0.625rem;
    font-weight: var(--fw-medium, 500);
    letter-spacing: 0.02em;
    transition: color 0.2s ease, transform 0.15s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.ps-bottom-nav-item i {
    font-size: 1.25rem;
    transition: transform 0.2s var(--fun-bounce, cubic-bezier(0.68, -0.55, 0.265, 1.55));
}

.ps-bottom-nav-item.active {
    color: var(--primary, #6C63FF);
}

.ps-bottom-nav-item.active i {
    transform: scale(1.15);
}

/* Active indicator dot */
.ps-bottom-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary, #6C63FF);
}

/* Touch feedback */
.ps-bottom-nav-item:active {
    transform: scale(0.92);
}

/* --- Show on mobile, hide top nav center items --- */
@media (max-width: 767.98px) {
    .ps-bottom-nav {
        display: block;
    }

    /* Hide center nav items on mobile (they're in bottom nav now) */
    .ps-nav-center {
        display: none !important;
    }

    /* Add bottom padding to body so content doesn't hide behind bottom nav */
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    /* Slim down top navbar on mobile */
    .ps-navbar-inner {
        height: 48px;
        padding: 0 16px;
    }
}

/* --- Dark Mode --- */
[data-theme="dark"] .ps-bottom-nav {
    background: var(--bg-card, #1a1d2e);
    border-top-color: var(--border, #2d3148);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
}


/* ============================================================
   6. CELEBRATION MICRO-INTERACTIONS
   Source: Duolingo, Brilliant.org, Khan Academy
   
   Enhanced confetti, XP popup, badge reveal, streak fire,
   mastery celebration, and level-up screen.
   ============================================================ */

/* --- CSS Confetti System --- */
@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg) scale(0.5);
        opacity: 0;
    }
}

.confetti-piece {
    position: fixed;
    top: -10px;
    width: 10px;
    height: 10px;
    z-index: 10000;
    pointer-events: none;
    animation: confettiFall var(--fall-duration, 3s) var(--fall-delay, 0s) ease-in forwards;
}

.confetti-piece:nth-child(odd) {
    border-radius: 50%;
}

.confetti-piece:nth-child(3n) {
    border-radius: 2px;
    width: 8px;
    height: 14px;
}

.confetti-piece:nth-child(5n) {
    width: 6px;
    height: 6px;
    border-radius: 1px;
}

/* --- XP Gain Popup (Enhanced) --- */
@keyframes xpGainPop {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(20px);
    }
    30% {
        opacity: 1;
        transform: scale(1.3) translateY(-5px);
    }
    50% {
        transform: scale(1) translateY(-10px);
    }
    100% {
        opacity: 0;
        transform: scale(0.8) translateY(-60px);
    }
}

.xp-gain-popup {
    position: fixed;
    z-index: 10001;
    pointer-events: none;
    font-size: 1.5rem;
    font-weight: var(--fw-extrabold, 800);
    color: var(--fun-yellow, #FFEA00);
    text-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(255, 234, 0, 0.4);
    animation: xpGainPop 1.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    white-space: nowrap;
}

.xp-gain-popup::before {
    content: '+';
}

.xp-gain-popup::after {
    content: ' XP';
    font-size: 0.75em;
    opacity: 0.8;
}

/* --- Badge Reveal Animation --- */
@keyframes badgeReveal {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.3) rotate(10deg);
    }
    70% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes badgeGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4); }
    50% { box-shadow: 0 0 20px 10px rgba(255, 215, 0, 0.2); }
}

.badge-reveal {
    animation: badgeReveal 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

.badge-new-glow {
    animation: badgeGlow 2s ease-in-out 3;
}

/* --- Streak Fire Enhancement --- */
@keyframes streakFirePulse {
    0%, 100% {
        transform: scale(1);
        filter: brightness(1);
    }
    50% {
        transform: scale(1.15);
        filter: brightness(1.3);
    }
}

.streak-fire-active {
    animation: streakFirePulse 0.6s ease-in-out;
}

/* Streak milestone celebration (7, 14, 30, 60, 100 days) */
@keyframes streakMilestone {
    0% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.3) rotate(-10deg); }
    50% { transform: scale(1.5) rotate(5deg); }
    75% { transform: scale(1.2) rotate(-3deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.streak-milestone {
    animation: streakMilestone 1s var(--fun-bounce, cubic-bezier(0.68, -0.55, 0.265, 1.55));
}

/* --- Mastery Complete Overlay --- */
.mastery-overlay {
    position: fixed;
    inset: 0;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease forwards;
    pointer-events: auto;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mastery-overlay__content {
    text-align: center;
    animation: masteryPop 0.6s var(--fun-bounce) forwards;
}

@keyframes masteryPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.mastery-overlay__icon {
    font-size: 5rem;
    margin-bottom: var(--space-4, 1rem);
    filter: drop-shadow(0 4px 20px rgba(255, 215, 0, 0.5));
}

.mastery-overlay__title {
    font-size: var(--fs-2xl, 1.5rem);
    font-weight: var(--fw-extrabold, 800);
    color: white;
    margin-bottom: var(--space-2, 0.5rem);
}

.mastery-overlay__subtitle {
    font-size: var(--fs-md, 1rem);
    color: rgba(255, 255, 255, 0.7);
}

/* --- Correct Answer Pulse (on answer buttons/cards) --- */
@keyframes correctPulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.6); }
    70% { box-shadow: 0 0 0 15px rgba(0, 230, 118, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 230, 118, 0); }
}

.correct-pulse {
    animation: correctPulse 0.6s ease-out;
}

/* --- Wrong Answer Shake --- */
@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    10%, 50%, 90% { transform: translateX(-4px); }
    30%, 70% { transform: translateX(4px); }
}

.wrong-shake {
    animation: wrongShake 0.5s ease-in-out;
}

/* --- Level Up Banner --- */
.level-up-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 10003;
    text-align: center;
    padding: var(--space-8, 2rem) var(--space-12, 3rem);
    background: var(--grad-magic, linear-gradient(135deg, #E040FB 0%, #7C4DFF 50%, #448AFF 100%));
    border-radius: var(--fun-radius-xl, 32px);
    color: white;
    pointer-events: none;
    animation: levelUpAppear 2.5s var(--fun-bounce) forwards;
}

@keyframes levelUpAppear {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    30% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
}

.level-up-banner__level {
    font-size: var(--fs-3xl, 2.5rem);
    font-weight: var(--fw-extrabold, 800);
    line-height: 1;
}

.level-up-banner__label {
    font-size: var(--fs-md, 1rem);
    opacity: 0.8;
    margin-top: var(--space-2, 0.5rem);
}


/* ============================================================
   7. SVG PROGRESS RINGS
   Source: Duolingo, Coursera, Apple Fitness
   
   Circular SVG progress indicators for level/XP/mastery.
   Replaces flat bars where compact visualization is needed.
   ============================================================ */

/* --- Progress Ring Component --- */
.progress-ring {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.progress-ring svg {
    transform: rotate(-90deg);
    overflow: visible;
}

.progress-ring__track {
    fill: none;
    stroke: var(--bg-input, #f3f4f8);
    stroke-width: var(--ring-stroke, 6);
}

.progress-ring__fill {
    fill: none;
    stroke: var(--ring-color, var(--primary, #6C63FF));
    stroke-width: var(--ring-stroke, 6);
    stroke-linecap: round;
    stroke-dasharray: var(--ring-circumference);
    stroke-dashoffset: var(--ring-offset, var(--ring-circumference));
    transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-ring__label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.progress-ring__value {
    font-size: var(--fs-lg, 1.125rem);
    font-weight: var(--fw-extrabold, 800);
    line-height: 1;
    color: var(--text-primary, #1a1a2e);
}

.progress-ring__text {
    font-size: var(--fs-xs, 0.6875rem);
    color: var(--text-muted, #9ca3af);
    margin-top: 2px;
}

/* --- Ring Sizes --- */
.progress-ring--sm {
    --ring-size: 48px;
    --ring-radius: 19;
    --ring-stroke: 5;
    --ring-circumference: 119.38;
}

.progress-ring--md {
    --ring-size: 72px;
    --ring-radius: 30;
    --ring-stroke: 6;
    --ring-circumference: 188.5;
}

.progress-ring--lg {
    --ring-size: 96px;
    --ring-radius: 40;
    --ring-stroke: 8;
    --ring-circumference: 251.33;
}

.progress-ring--xl {
    --ring-size: 128px;
    --ring-radius: 54;
    --ring-stroke: 10;
    --ring-circumference: 339.29;
}

/* --- Ring Colors --- */
.progress-ring--primary { --ring-color: var(--primary, #6C63FF); }
.progress-ring--success { --ring-color: var(--success, #00C9A7); }
.progress-ring--warning { --ring-color: var(--warning, #FFD93D); }
.progress-ring--danger  { --ring-color: var(--danger, #FF4757); }
.progress-ring--fire    { --ring-color: var(--fun-orange, #FF9100); }

/* --- Animated ring fill on scroll into view --- */
.progress-ring[data-animate] .progress-ring__fill {
    stroke-dashoffset: var(--ring-circumference);
}

.progress-ring[data-animate].in-view .progress-ring__fill {
    stroke-dashoffset: var(--ring-offset);
}

/* --- Dark Mode Ring Track --- */
[data-theme="dark"] .progress-ring__track {
    stroke: var(--bg-input, #252836);
}

/* --- Stat Card with Ring integration --- */
.stat-card--ring {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2, 0.5rem);
}

/* --- XP Bar Enhanced (keep existing but add ring option) --- */
.xp-ring-container {
    position: relative;
    display: inline-flex;
}

.xp-ring-level {
    font-size: var(--fs-xl, 1.25rem);
    font-weight: var(--fw-extrabold, 800);
    color: var(--primary, #6C63FF);
}
