/* =====================================================
   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 var(--main);
    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);
    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,
                background 0.3s ease,
                border-color 0.3s ease,
                box-shadow 0.3s ease;
    will-change: transform, opacity;
}

/* --- Animated Border Glow --- */
.token-toast::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 19px;
    padding: 1.5px;
    background: var(--main);
    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: 0.5;
}

@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: var(--main);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease 0.3s;
}

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

/* --- 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: transparent;
    box-shadow: 0 0 20px var(--main);
    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;
    color: var(--main);
    background: linear-gradient(135deg, var(--main), var(--main-hover), var(--main));
    -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;
    color: var(--main);
    -webkit-text-fill-color: var(--main);
    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;
    transition: color 0.3s ease;
}

.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;
    transition: color 0.3s ease;
}

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

.token-toast-balance-value {
    color: var(--main);
    font-weight: 700;
    display: inline-block;
    transition: color 0.3s ease;
}

.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: var(--main);
    font-weight: 700;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid var(--main);
    opacity: 0;
    position: relative;
}

.token-toast-combo::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px;
    background: var(--main);
    opacity: 0.1;
    pointer-events: none;
}

.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 — syncs with night-mode-css link presence
   Night mode = default (dark.css loaded via <link class="night-mode-css">)
   Day mode  = html:not(:has(link.night-mode-css))
   ===================================================== */

/* --- Day Mode (no dark.css stylesheet present) --- */
html:not(:has(link.night-mode-css)) .token-toast {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-color: var(--main);
    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);
}

html:not(:has(link.night-mode-css)) .token-toast-message {
    color: rgba(0, 0, 0, 0.55);
}

html:not(:has(link.night-mode-css)) .token-toast-balance {
    color: rgba(0, 0, 0, 0.4);
}

html:not(:has(link.night-mode-css)) .token-toast-balance-value {
    color: var(--main);
}

html:not(:has(link.night-mode-css)) .token-toast-close {
    color: rgba(0, 0, 0, 0.2);
}

html:not(:has(link.night-mode-css)) .token-toast-close:hover {
    color: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.04);
}

html:not(:has(link.night-mode-css)) .token-toast-amount {
    color: var(--main);
    background: linear-gradient(135deg, var(--main), var(--main-hover), var(--main));
    -webkit-background-clip: text;
    background-clip: text;
}

html:not(:has(link.night-mode-css)) .token-toast-coin {
    color: var(--main);
    -webkit-text-fill-color: var(--main);
}

html:not(:has(link.night-mode-css)) .token-toast-icon {
    box-shadow: 0 0 15px var(--main);
}

html:not(:has(link.night-mode-css)) .token-toast-combo {
    color: var(--main-hover);
    border-color: var(--main);
}

/* --- Night Mode (dark.css IS loaded — default capsule style) --- */
html:has(link.night-mode-css) .token-toast {
    background: rgba(15, 12, 30, 0.88);
    border-color: var(--main);
}
html:has(link.night-mode-css) .token-toast-amount {
    color: var(--main);
    background: linear-gradient(135deg, var(--main), var(--main-hover), var(--main));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
html:has(link.night-mode-css) .token-toast-coin {
    color: var(--main);
    -webkit-text-fill-color: var(--main);
}
html:has(link.night-mode-css) .token-toast-balance-value {
    color: var(--main);
}
html:has(link.night-mode-css) .token-toast-icon {
    box-shadow: 0 0 20px var(--main);
}
html:has(link.night-mode-css) .token-toast-combo {
    color: var(--main);
    border-color: var(--main);
}

/* --- Fallback classes for theme sync (always active) --- */
/* JS MutationObserver adds .token-toast-day / .token-toast-night to container */
/* Using ID+class selector for specificity over base .token-toast rules */
#token-toast-container.token-toast-day .token-toast {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-color: var(--main);
    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);
}
#token-toast-container.token-toast-day .token-toast-message { color: rgba(0, 0, 0, 0.55); }
#token-toast-container.token-toast-day .token-toast-balance { color: rgba(0, 0, 0, 0.4); }
#token-toast-container.token-toast-day .token-toast-balance-value { color: var(--main); }
#token-toast-container.token-toast-day .token-toast-close { color: rgba(0, 0, 0, 0.2); }
#token-toast-container.token-toast-day .token-toast-close:hover { color: rgba(0, 0, 0, 0.6); background: rgba(0, 0, 0, 0.04); }
#token-toast-container.token-toast-day .token-toast-amount {
    color: var(--main);
    background: linear-gradient(135deg, var(--main), var(--main-hover), var(--main));
    -webkit-background-clip: text;
    background-clip: text;
}
#token-toast-container.token-toast-day .token-toast-coin { color: var(--main); -webkit-text-fill-color: var(--main); }
#token-toast-container.token-toast-day .token-toast-icon {
    box-shadow: 0 0 15px var(--main);
}
#token-toast-container.token-toast-day .token-toast-combo {
    color: var(--main-hover);
    border-color: var(--main);
}
#token-toast-container.token-toast-night .token-toast {
    background: rgba(15, 12, 30, 0.88);
    border-color: var(--main);
    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);
}
#token-toast-container.token-toast-night .token-toast-amount {
    color: var(--main);
    background: linear-gradient(135deg, var(--main), var(--main-hover), var(--main));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
#token-toast-container.token-toast-night .token-toast-coin {
    color: var(--main);
    -webkit-text-fill-color: var(--main);
}
#token-toast-container.token-toast-night .token-toast-balance-value {
    color: var(--main);
}
#token-toast-container.token-toast-night .token-toast-icon {
    box-shadow: 0 0 20px var(--main);
}
#token-toast-container.token-toast-night .token-toast-combo {
    color: var(--main);
    border-color: var(--main);
}
#token-toast-container.token-toast-night .token-toast::before {
    background: var(--main);
}

/* =====================================================
   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;
    }
}
