/**
 * Mega Celebration - Robot Rides Rocket Animation
 * Triggered at 500 viewers milestone
 *
 * @version 1.4.0
 * @see docs/avatar.md
 */

/* ===== Overlay Container ===== */
.mega-celebration-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at center, rgba(10, 15, 30, 0.95) 0%, rgba(0, 0, 0, 0.98) 100%);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    overflow: hidden;
}

.mega-celebration-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ===== Stars Background ===== */
.mega-stars {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.mega-star {
    position: absolute;
    width: 3px;
    height: 3px;
    background: white;
    border-radius: 50%;
    opacity: 0;
}

.mega-celebration-overlay.active .mega-star {
    animation: star-twinkle 1.5s ease-in-out infinite;
}

@keyframes star-twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.5); }
}

/* ===== Launch Pad ===== */
.mega-launchpad {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 40px;
    background: linear-gradient(180deg, #374151 0%, #1f2937 100%);
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -5px 30px rgba(0, 0, 0, 0.5);
}

.mega-launchpad::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 8px;
    background: repeating-linear-gradient(
        90deg,
        #fbbf24 0px,
        #fbbf24 20px,
        #1f2937 20px,
        #1f2937 40px
    );
    border-radius: 4px;
}

/* ===== Rocket + Robot Container ===== */
.mega-rocket-container {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mega-celebration-overlay.launching .mega-rocket-container {
    animation: rocket-launch 3s ease-in forwards;
}

@keyframes rocket-launch {
    0% {
        transform: translateX(-50%) translateY(0);
    }
    5% {
        transform: translateX(-50%) translateY(5px);
    }
    10% {
        transform: translateX(-50%) translateY(0);
    }
    100% {
        transform: translateX(-50%) translateY(-150vh);
    }
}

/* ===== Robot Rider ===== */
.mega-robot {
    position: relative;
    width: 60px;
    height: 70px;
    z-index: 10;
    transform: translateY(15px);
}

.mega-robot-head {
    position: relative;
    width: 50px;
    height: 40px;
    background: linear-gradient(180deg, #1e3a5f 0%, #0f2744 100%);
    border: 3px solid #3b82f6;
    border-radius: 12px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.mega-robot-antenna {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 15px;
    background: linear-gradient(180deg, #60a5fa, #3b82f6);
    border-radius: 2px;
}

.mega-robot-antenna::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    background: #f472b6;
    border-radius: 50%;
    box-shadow: 0 0 10px #f472b6;
    animation: antenna-pulse 0.5s ease-in-out infinite;
}

@keyframes antenna-pulse {
    0%, 100% { box-shadow: 0 0 10px #f472b6; }
    50% { box-shadow: 0 0 20px #f472b6, 0 0 30px #f472b6; }
}

.mega-robot-eyes {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding-top: 10px;
}

.mega-robot-eye {
    width: 12px;
    height: 12px;
    background: #22d3ee;
    border-radius: 50%;
    box-shadow: 0 0 10px #22d3ee;
    animation: eye-excited 0.3s ease-in-out infinite;
}

@keyframes eye-excited {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.mega-robot-mouth {
    width: 20px;
    height: 8px;
    background: #22d3ee;
    border-radius: 0 0 10px 10px;
    margin: 6px auto 0;
    box-shadow: 0 0 8px #22d3ee;
}

/* Robot arms waving */
.mega-robot-arms {
    position: absolute;
    top: 25px;
    width: 100%;
}

.mega-robot-arm {
    position: absolute;
    width: 8px;
    height: 25px;
    background: #3b82f6;
    border-radius: 4px;
}

.mega-robot-arm.left {
    left: -5px;
    transform-origin: top center;
    animation: wave-left 0.4s ease-in-out infinite;
}

.mega-robot-arm.right {
    right: -5px;
    transform-origin: top center;
    animation: wave-right 0.4s ease-in-out infinite;
}

@keyframes wave-left {
    0%, 100% { transform: rotate(-30deg); }
    50% { transform: rotate(-60deg); }
}

@keyframes wave-right {
    0%, 100% { transform: rotate(30deg); }
    50% { transform: rotate(60deg); }
}

/* ===== Rocket Body ===== */
.mega-rocket {
    position: relative;
    width: 80px;
    height: 180px;
}

.mega-rocket-nose {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 30px solid transparent;
    border-right: 30px solid transparent;
    border-bottom: 50px solid #ef4444;
}

.mega-rocket-nose::after {
    content: '';
    position: absolute;
    top: 20px;
    left: -15px;
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    border-radius: 50%;
    border: 3px solid #dc2626;
}

.mega-rocket-body {
    position: absolute;
    top: 45px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 100px;
    background: linear-gradient(180deg, #dc2626 0%, #b91c1c 50%, #991b1b 100%);
    border-radius: 5px;
}

.mega-rocket-body::before {
    content: '500';
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.mega-rocket-window {
    position: absolute;
    top: 55px;
    left: 50%;
    transform: translateX(-50%);
    width: 25px;
    height: 25px;
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    border-radius: 50%;
    border: 3px solid #1e40af;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
}

.mega-rocket-fins {
    position: absolute;
    bottom: 0;
    width: 100%;
}

.mega-rocket-fin {
    position: absolute;
    bottom: 0;
    width: 0;
    height: 0;
}

.mega-rocket-fin.left {
    left: -10px;
    border-top: 30px solid transparent;
    border-right: 25px solid #dc2626;
    border-bottom: 20px solid #dc2626;
}

.mega-rocket-fin.right {
    right: -10px;
    border-top: 30px solid transparent;
    border-left: 25px solid #dc2626;
    border-bottom: 20px solid #dc2626;
}

/* ===== Flames ===== */
.mega-flames {
    position: absolute;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 100px;
    opacity: 0;
}

.mega-celebration-overlay.launching .mega-flames {
    opacity: 1;
}

.mega-flame {
    position: absolute;
    bottom: 0;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    animation: flame-flicker 0.1s ease-in-out infinite alternate;
}

.mega-flame.main {
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 80px;
    background: linear-gradient(180deg, #fbbf24 0%, #f97316 40%, #ef4444 70%, #dc2626 100%);
}

.mega-flame.left {
    left: 5px;
    width: 20px;
    height: 50px;
    background: linear-gradient(180deg, #fde047 0%, #fbbf24 50%, #f97316 100%);
    animation-delay: 0.05s;
}

.mega-flame.right {
    right: 5px;
    width: 20px;
    height: 50px;
    background: linear-gradient(180deg, #fde047 0%, #fbbf24 50%, #f97316 100%);
    animation-delay: 0.1s;
}

@keyframes flame-flicker {
    0% { transform: translateX(-50%) scaleY(1) scaleX(1); }
    100% { transform: translateX(-50%) scaleY(1.1) scaleX(0.9); }
}

.mega-flame.left, .mega-flame.right {
    animation: flame-flicker-side 0.1s ease-in-out infinite alternate;
}

@keyframes flame-flicker-side {
    0% { transform: scaleY(1) scaleX(1); }
    100% { transform: scaleY(1.15) scaleX(0.85); }
}

/* ===== Smoke ===== */
.mega-smoke {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    height: 150px;
    pointer-events: none;
    opacity: 0;
}

.mega-celebration-overlay.launching .mega-smoke {
    opacity: 1;
}

.mega-smoke-puff {
    position: absolute;
    bottom: 0;
    background: radial-gradient(ellipse, rgba(156, 163, 175, 0.8) 0%, rgba(107, 114, 128, 0.4) 50%, transparent 70%);
    border-radius: 50%;
    animation: smoke-expand 2s ease-out forwards;
}

@keyframes smoke-expand {
    0% {
        transform: scale(0.3) translateY(0);
        opacity: 0.8;
    }
    100% {
        transform: scale(3) translateY(-50px);
        opacity: 0;
    }
}

/* ===== Screen Shake ===== */
.mega-celebration-overlay.shake {
    animation: screen-shake 0.5s ease-in-out;
}

@keyframes screen-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* ===== Countdown ===== */
.mega-countdown {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 120px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.8), 0 0 60px rgba(251, 191, 36, 0.4);
    opacity: 0;
    z-index: 100;
}

.mega-countdown.show {
    animation: countdown-pop 0.8s ease-out forwards;
}

@keyframes countdown-pop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ===== Final Message ===== */
.mega-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    opacity: 0;
    z-index: 100;
}

.mega-message.show {
    animation: message-appear 1s ease-out forwards;
}

@keyframes message-appear {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.1); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.mega-message-number {
    font-size: 150px;
    font-weight: 900;
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    filter: drop-shadow(0 0 30px rgba(251, 191, 36, 0.6));
    line-height: 1;
}

.mega-message-text {
    font-size: 36px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    margin-top: 10px;
}

/* ===== Confetti ===== */
.mega-confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.mega-confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    opacity: 0;
}

.mega-confetti.show {
    animation: confetti-fall 4s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0.5;
    }
}

/* ===== Firework Bursts ===== */
.mega-firework {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    opacity: 0;
}

.mega-firework.burst {
    animation: firework-burst 1s ease-out forwards;
}

@keyframes firework-burst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* ===== Robot Speech Bubble (during launch) ===== */
.mega-robot-bubble {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    border: 2px solid #60a5fa;
    border-radius: 15px;
    padding: 8px 15px;
    white-space: nowrap;
    opacity: 0;
    z-index: 20;
}

.mega-robot-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: #3b82f6;
}

.mega-robot-bubble-text {
    font-size: 14px;
    font-weight: bold;
    color: white;
}

.mega-robot-bubble.show {
    animation: bubble-pop 0.3s ease-out forwards;
}

@keyframes bubble-pop {
    0% { transform: translateX(-50%) scale(0); opacity: 0; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ===== Close Button ===== */
.mega-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000;
}

.mega-close:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.mega-close::before,
.mega-close::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: white;
}

.mega-close::before { transform: rotate(45deg); }
.mega-close::after { transform: rotate(-45deg); }

/* ===== Mobile Adjustments ===== */
@media (max-width: 768px) {
    .mega-rocket-container {
        transform: translateX(-50%) scale(0.7);
    }

    .mega-message-number {
        font-size: 80px;
    }

    .mega-message-text {
        font-size: 24px;
    }

    .mega-countdown {
        font-size: 80px;
    }
}
