/* =====================================================
   triBBBal Token Reward Capsule - Premium UX
   Inspired by: Duolingo streaks, Discord Nitro,
   Apple Wallet confirmations, TikTok gift effects
   ===================================================== */

/* --- Container --- */
#token-toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    max-width: 340px;
    width: 100%;
}

/* --- Particle Canvas --- */
.token-toast-particles {
    position: absolute;
    inset: -20px;
    pointer-events: none;
    overflow: hidden;
    border-radius: 20px;
}

.token-toast-particles .particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    opacity: 0;
    animation: particleBurst 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes particleBurst {
    0% { transform: translate(0, 0) scale(0); opacity: 1; }
    60% { opacity: 0.8; }
    100% { transform: translate(var(--px), var(--py)) scale(0.3); opacity: 0; }
}

/* --- Reward Capsule --- */
.token-toast {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-radius: 18px;
    pointer-events: auto;
    overflow: hidden;
    background: rgba(15, 12, 30, 0.85);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border: 1px solid rgba(255, 215, 0, 0.15);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2),
        0 8px 24px rgba(0, 0, 0, 0.3),
        0 20px 60px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 0 30px rgba(255, 215, 0, 0.05);
    transform: translateX(120%) scale(0.8);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    will-change: transform, opacity;
}

/* --- Animated Gold Border Glow --- */
.token-toast::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 19px;
    padding: 1.5px;
    background: linear-gradient(
        135deg,
        rgba(255, 215, 0, 0.6),
        rgba(255, 180, 0, 0.1),
        rgba(255, 215, 0, 0.4),
        rgba(255, 140, 0, 0.1),
        rgba(255, 215, 0, 0.6)
    );
    background-size: 300% 300%;
    animation: borderGlow 3s ease-in-out infinite;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease 0.2s;
}

.token-toast-visible::before {
    opacity: 1;
}

@keyframes borderGlow {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* --- Ambient radial glow --- */
.token-toast::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 18px;
    background: radial-gradient(ellipse at 30% 50%, rgba(255, 215, 0, 0.08), transparent 70%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease 0.3s;
}

.token-toast-visible::after {
    opacity: 1;
}

/* --- States --- */
.token-toast-visible {
    transform: translateX(0) scale(1);
    opacity: 1;
}

.token-toast-exit {
    transform: translateY(-20px) scale(0.9);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.55, 0, 1, 0.45), opacity 0.35s ease;
}

/* --- Token Icon --- */
.token-toast-icon {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.15), rgba(255, 180, 0, 0.05));
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.1);
    animation: none;
}

.token-toast-visible .token-toast-icon {
    animation: iconPulse 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}

@keyframes iconPulse {
    0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
    50% { transform: scale(1.15) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* --- Body --- */
.token-toast-body {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

/* --- Amount (hero number) --- */
.token-toast-amount {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, #ffd700, #ffb800, #ffa500);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
    letter-spacing: -0.3px;
    opacity: 0;
    transform: translateY(8px);
}

.token-toast-visible .token-toast-amount {
    animation: slideReveal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s forwards;
}

@keyframes slideReveal {
    to { opacity: 1; transform: translateY(0); }
}

.token-toast-coin {
    font-size: 11px;
    font-weight: 600;
    -webkit-text-fill-color: rgba(255, 215, 0, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Message --- */
.token-toast-message {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    opacity: 0;
}

.token-toast-visible .token-toast-message {
    animation: slideReveal 0.4s ease 0.25s forwards;
}

/* --- Balance (animated counter) --- */
.token-toast-balance {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    opacity: 0;
}

.token-toast-visible .token-toast-balance {
    animation: slideReveal 0.4s ease 0.35s forwards;
}

.token-toast-balance-value {
    color: rgba(255, 215, 0, 0.8);
    font-weight: 700;
    display: inline-block;
}

.token-toast-balance-value.counting {
    animation: countPulse 0.15s ease infinite alternate;
}

@keyframes countPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* --- Combo --- */
.token-toast-combo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #ff6b35;
    font-weight: 700;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255, 107, 53, 0.1);
    border: 1px solid rgba(255, 107, 53, 0.2);
    opacity: 0;
}

.token-toast-visible .token-toast-combo {
    animation: comboReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s forwards;
}

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

/* --- Close Button --- */
.token-toast-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.25);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    z-index: 2;
}

.token-toast-close:hover {
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.08);
}

/* =====================================================
   THEMES
   ===================================================== */

body.day_mode .token-toast,
body:not(.night_mode) .token-toast {
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-color: rgba(255, 180, 0, 0.25);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.04),
        0 8px 24px rgba(0, 0, 0, 0.08),
        0 20px 60px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        0 0 30px rgba(255, 215, 0, 0.04);
}

body.day_mode .token-toast::after,
body:not(.night_mode) .token-toast::after {
    background: radial-gradient(ellipse at 30% 50%, rgba(255, 215, 0, 0.06), transparent 70%);
}

body.day_mode .token-toast-message,
body:not(.night_mode) .token-toast-message {
    color: rgba(0, 0, 0, 0.55);
}

body.day_mode .token-toast-balance,
body:not(.night_mode) .token-toast-balance {
    color: rgba(0, 0, 0, 0.4);
}

body.day_mode .token-toast-balance-value,
body:not(.night_mode) .token-toast-balance-value {
    color: #b8860b;
}

body.day_mode .token-toast-close,
body:not(.night_mode) .token-toast-close {
    color: rgba(0, 0, 0, 0.2);
}

body.day_mode .token-toast-close:hover,
body:not(.night_mode) .token-toast-close:hover {
    color: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.04);
}

body.day_mode .token-toast-amount,
body:not(.night_mode) .token-toast-amount {
    background: linear-gradient(135deg, #d4a000, #b8860b, #cc8800);
    -webkit-background-clip: text;
    background-clip: text;
}

body.day_mode .token-toast-icon,
body:not(.night_mode) .token-toast-icon {
    background: linear-gradient(145deg, rgba(255, 200, 0, 0.12), rgba(255, 160, 0, 0.05));
    box-shadow: 0 0 15px rgba(255, 200, 0, 0.08);
}

body.night_mode .token-toast {
    background: rgba(15, 12, 30, 0.88);
}

/* =====================================================
   RTL SUPPORT
   ===================================================== */
[dir="rtl"] #token-toast-container {
    right: auto;
    left: 20px;
}

[dir="rtl"] .token-toast {
    transform: translateX(-120%) scale(0.8);
}

[dir="rtl"] .token-toast-visible {
    transform: translateX(0) scale(1);
}

[dir="rtl"] .token-toast-exit {
    transform: translateY(-20px) scale(0.9);
}

[dir="rtl"] .token-toast-close {
    right: auto;
    left: 10px;
}

/* =====================================================
   REDUCED MOTION
   ===================================================== */
@media (prefers-reduced-motion: reduce) {
    .token-toast {
        transition: opacity 0.3s ease !important;
        transform: none !important;
    }
    .token-toast-visible {
        opacity: 1;
    }
    .token-toast-exit {
        opacity: 0;
    }
    .token-toast-visible .token-toast-icon,
    .token-toast-visible .token-toast-amount,
    .token-toast-visible .token-toast-message,
    .token-toast-visible .token-toast-balance,
    .token-toast-visible .token-toast-combo {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    .token-toast-particles .particle {
        display: none;
    }
    .token-toast::before {
        animation: none !important;
    }
}

/* =====================================================
   MOBILE
   ===================================================== */
@media (max-width: 480px) {
    #token-toast-container {
        top: auto;
        bottom: 80px;
        right: 12px;
        left: 12px;
        max-width: none;
        align-items: center;
    }
    .token-toast {
        max-width: 320px;
        width: 100%;
        padding: 14px 16px;
        border-radius: 16px;
    }
    .token-toast-icon {
        width: 38px;
        height: 38px;
        font-size: 20px;
    }
    .token-toast-amount {
        font-size: 18px;
    }
}
