/* ========================================
   Moments of Truth — Celebration System
   Toast notifications + milestone celebrations
   ======================================== */

/* --- Toast Container --- */
.cx-toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    width: 90%;
    max-width: 480px;
}

/* --- Single Toast --- */
.cx-toast {
    pointer-events: auto;
    width: 100%;
    padding: 18px 22px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #fff;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.08);
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
    animation: cxToastIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    cursor: pointer;
    transition: transform 0.2s ease;
    direction: rtl;
}
.cx-toast:hover {
    transform: translateY(-2px) scale(1.01);
}
.cx-toast.toast-exit {
    animation: cxToastOut 0.4s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

/* Toast icon */
.cx-toast-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(255,255,255,0.12);
}

/* Toast content */
.cx-toast-body {
    flex: 1;
    min-width: 0;
}
.cx-toast-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 2px;
}
.cx-toast-msg {
    font-size: 0.85rem;
    opacity: 0.85;
    line-height: 1.4;
}

/* Toast close */
.cx-toast-close {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.6);
    border-radius: 50%;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.cx-toast-close:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* --- Toast Variants --- */

/* Achievement / milestone */
.cx-toast-achievement {
    background: linear-gradient(135deg, rgba(99,102,241,0.92), rgba(6,182,212,0.92));
    border: 1px solid rgba(255,255,255,0.15);
}

/* Streak */
.cx-toast-streak {
    background: linear-gradient(135deg, rgba(245,158,11,0.92), rgba(239,68,68,0.92));
    border: 1px solid rgba(255,255,255,0.15);
}

/* Quiz success */
.cx-toast-quiz {
    background: linear-gradient(135deg, rgba(16,185,129,0.92), rgba(6,182,212,0.92));
    border: 1px solid rgba(255,255,255,0.15);
}

/* Level up / phase */
.cx-toast-levelup {
    background: linear-gradient(135deg, rgba(168,85,247,0.92), rgba(236,72,153,0.92));
    border: 1px solid rgba(255,255,255,0.15);
}

/* Welcome back */
.cx-toast-welcome {
    background: linear-gradient(135deg, rgba(30,41,59,0.95), rgba(51,65,85,0.95));
    border: 1px solid rgba(99,102,241,0.3);
}

/* Tool completion */
.cx-toast-tool {
    background: linear-gradient(135deg, rgba(6,182,212,0.92), rgba(99,102,241,0.92));
    border: 1px solid rgba(255,255,255,0.15);
}

/* --- Confetti Canvas (for big milestones) --- */
.cx-confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    pointer-events: none;
}

/* --- Progress bar on toast (for streak) --- */
.cx-toast-progress {
    height: 3px;
    border-radius: 3px;
    background: rgba(255,255,255,0.15);
    margin-top: 8px;
    overflow: hidden;
}
.cx-toast-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: rgba(255,255,255,0.6);
    transition: width 0.3s;
}

/* --- Animations --- */
@keyframes cxToastIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes cxToastOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

@keyframes cxPulseGlow {
    0%, 100% { box-shadow: 0 12px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.08); }
    50% { box-shadow: 0 12px 40px rgba(0,0,0,0.3), 0 0 20px rgba(99,102,241,0.3), 0 0 0 1px rgba(255,255,255,0.15); }
}

.cx-toast-levelup {
    animation: cxToastIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
              cxPulseGlow 2s ease-in-out infinite 0.5s;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .cx-toast-container {
        top: 12px;
        width: 95%;
    }
    .cx-toast {
        padding: 14px 16px;
        gap: 10px;
        border-radius: 12px;
    }
    .cx-toast-icon {
        font-size: 1.4rem;
        width: 40px;
        height: 40px;
    }
    .cx-toast-title {
        font-size: 0.9rem;
    }
    .cx-toast-msg {
        font-size: 0.8rem;
    }
}

/* --- Light Theme --- */
body.light-theme .cx-toast-welcome {
    background: linear-gradient(135deg, rgba(241,245,249,0.97), rgba(226,232,240,0.97));
    color: #1e293b;
    border: 1px solid rgba(99,102,241,0.2);
    box-shadow: 0 12px 40px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.05);
}
body.light-theme .cx-toast-welcome .cx-toast-msg {
    color: #475569;
}
body.light-theme .cx-toast-close {
    background: rgba(0,0,0,0.06);
    color: rgba(0,0,0,0.4);
}
body.light-theme .cx-toast-close:hover {
    background: rgba(0,0,0,0.1);
    color: rgba(0,0,0,0.7);
}

/* --- Print: hide everything --- */
@media print {
    .cx-toast-container,
    .cx-confetti-canvas {
        display: none !important;
    }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    .cx-toast {
        animation-duration: 0.01ms !important;
    }
    .cx-toast-levelup {
        animation: cxToastIn 0.01ms forwards !important;
    }
}
