<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lootrun - Игровая платформа</title>
    
    <!-- External Resources -->
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
    
    <!-- Tailwind Configuration -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#6C5DD3',
                        secondary: '#1E1E2E',
                        accent: '#2D2D3F',
                        success: '#00B87C',
                        warning: '#FFBE5C',
                        danger: '#FF5C5C',
                        info: '#3498db',
                        'primary-hover': '#5B4EC2',
                        'secondary-hover': '#2A2A3A',
                        'dark-800': 'rgba(18, 18, 28, 0.8)',
                        'dark-900': 'rgba(14, 14, 22, 0.9)',
                        'gradient-1': '#6C5DD3',
                        'gradient-2': '#FF5C5C',
                        'gradient-3': '#00B87C'
                    },
                    fontFamily: {
                        sans: ['Inter', 'sans-serif'],
                    },
                    animation: {
                        'float': 'float 3s ease-in-out infinite',
                        'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
                        'bounce-slow': 'bounce 2s infinite',
                        'spin-slow': 'spin 3s linear infinite',
                        'ping-slow': 'ping 2s cubic-bezier(0, 0, 0.2, 1) infinite',
                        'gradient': 'gradient 15s ease infinite',
                    },
                    keyframes: {
                        float: {
                            '0%, 100%': { transform: 'translateY(0)' },
                            '50%': { transform: 'translateY(-10px)' }
                        },
                        gradient: {
                            '0%': { backgroundPosition: '0% 50%' },
                            '50%': { backgroundPosition: '100% 50%' },
                            '100%': { backgroundPosition: '0% 50%' }
                        }
                    },
                    backdropBlur: {
                        xs: '2px',
                    }
                }
            }
        }
    </script>

    <!-- Base Styles -->
    <style>
        /* Christmas Background Animation */
        .christmas-bg {
            background: linear-gradient(135deg, 
                rgba(0,40,0,0.2) 0%, 
                rgba(30,30,46,1) 50%, 
                rgba(40,0,0,0.2) 100%
            );
            animation: backgroundShift 15s ease infinite;
            background-size: 400% 400%;
            position: relative;
        }

        .christmas-bg::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath fill='%23ffffff' d='M95.35,49.27c0.43,0.37,0.85,0.76,1.25,1.17c1.38,1.41,2.03,3.21,1.87,5.28c-0.16,2.07-1.08,3.71-2.76,4.91c-0.43,0.31-0.88,0.58-1.35,0.83c0.82,0.74,1.54,1.57,2.15,2.47c1.16,1.7,1.57,3.57,1.22,5.61c-0.35,2.04-1.43,3.66-3.25,4.86c-0.92,0.61-1.91,1.11-2.97,1.5c0.45,0.81,0.82,1.66,1.1,2.55c0.61,1.96,0.45,3.9-0.46,5.82c-0.91,1.92-2.37,3.28-4.37,4.08c-1.02,0.41-2.08,0.71-3.19,0.9c0.12,0.84,0.17,1.69,0.13,2.56c-0.09,2.03-0.81,3.84-2.17,5.43c-1.36,1.59-3.06,2.6-5.1,3.03c-1.04,0.22-2.1,0.33-3.17,0.33c-0.19,0.85-0.46,1.67-0.82,2.47c-0.77,1.72-2.01,3.09-3.71,4.11c-1.7,1.02-3.54,1.47-5.51,1.36c-1.97-0.11-3.76-0.81-5.36-2.11c-0.82-0.66-1.54-1.42-2.17-2.28c-0.63,0.86-1.35,1.62-2.17,2.28c-1.6,1.3-3.39,2-5.36,2.11c-1.97,0.11-3.81-0.34-5.51-1.36c-1.7-1.02-2.94-2.39-3.71-4.11c-0.36-0.79-0.63-1.62-0.82-2.47c-1.07,0-2.13-0.11-3.17-0.33c-2.04-0.43-3.74-1.44-5.1-3.03c-1.36-1.59-2.08-3.4-2.17-5.43c-0.04-0.87,0.01-1.72,0.13-2.56c-1.11-0.19-2.17-0.49-3.19-0.9c-2-0.8-3.46-2.16-4.37-4.08c-0.91-1.92-1.07-3.86-0.46-5.82c0.28-0.89,0.65-1.74,1.1-2.55c-1.06-0.39-2.05-0.89-2.97-1.5c-1.82-1.2-2.9-2.82-3.25-4.86c-0.35-2.04,0.06-3.91,1.22-5.61c0.61-0.9,1.33-1.73,2.15-2.47c-0.47-0.25-0.92-0.52-1.35-0.83c-1.68-1.2-2.6-2.84-2.76-4.91c-0.16-2.07,0.49-3.87,1.87-5.28c0.4-0.41,0.82-0.8,1.25-1.17c-0.71-0.61-1.36-1.29-1.94-2.03c-1.38-1.77-1.97-3.72-1.79-5.85c0.18-2.13,1.09-3.95,2.71-5.46c0.47-0.44,0.97-0.85,1.5-1.22c-0.82-0.74-1.54-1.57-2.15-2.47c-1.16-1.7-1.57-3.57-1.22-5.61c0.35-2.04,1.43-3.66,3.25-4.86c0.53-0.35,1.09-0.67,1.66-0.94c-0.82-0.74-1.54-1.57-2.15-2.47c-1.16-1.7-1.57-3.57-1.22-5.61c0.35-2.04,1.43-3.66,3.25-4.86c0.92-0.61,1.91-1.11,2.97-1.5c-0.45-0.81-0.82-1.66-1.1-2.55c-0.61-1.96-0.45-3.9,0.46-5.82c0.91-1.92,2.37-3.28,4.37-4.08c1.02-0.41,2.08-0.71,3.19-0.9c-0.12-0.84-0.17-1.69-0.13-2.56c0.09-2.03,0.81-3.84,2.17-5.43c1.36-1.59,3.06-2.6,5.1-3.03c1.04-0.22,2.1-0.33,3.17-0.33c0.19-0.85,0.46-1.67,0.82-2.47c0.77-1.72,2.01-3.09,3.71-4.11c1.7-1.02,3.54-1.47,5.51-1.36c1.97,0.11,3.76,0.81,5.36,2.11c0.82,0.66,1.54,1.42,2.17,2.28c0.63-0.86,1.35-1.62,2.17-2.28c1.6-1.3,3.39-2,5.36-2.11c1.97-0.11,3.81,0.34,5.51,1.36c1.7,1.02,2.94,2.39,3.71,4.11c0.36,0.79,0.63,1.62,0.82,2.47c1.07,0,2.13,0.11,3.17,0.33c2.04,0.43,3.74,1.44,5.1,3.03c1.36,1.59,2.08,3.4,2.17,5.43c0.04,0.87-0.01,1.72-0.13,2.56c1.11,0.19,2.17,0.49,3.19,0.9c2,0.8,3.46,2.16,4.37,4.08c0.91,1.92,1.07,3.86,0.46,5.82c-0.28,0.89-0.65,1.74-1.1,2.55c1.06,0.39,2.05,0.89,2.97,1.5c1.82,1.2,2.9,2.82,3.25,4.86c0.35,2.04-0.06,3.91-1.22,5.61c-0.61,0.9-1.33,1.73-2.15,2.47c0.57,0.37,1.13,0.69,1.66,0.94c1.82,1.2,2.9,2.82,3.25,4.86c0.35,2.04-0.06,3.91-1.22,5.61c-0.61,0.9-1.33,1.73-2.15,2.47c0.53,0.37,1.03,0.78,1.5,1.22c1.62,1.51,2.53,3.33,2.71,5.46c0.18,2.13-0.41,4.08-1.79,5.85C96.71,47.98,96.06,48.66,95.35,49.27z'/%3E%3C/svg%3E") center/20px repeat;
            opacity: 0.05;
            z-index: 0;
            pointer-events: none;
        }

        /* Continued in next message due to length... */
        <!-- Продолжение стилей -->
    <style>
        /* Animations & Effects */
        @keyframes backgroundShift {
            0% { background-position: 0% 50% }
            50% { background-position: 100% 50% }
            100% { background-position: 0% 50% }
        }

        @keyframes neonPulse {
            0%, 100% { 
                box-shadow: 0 0 5px #6C5DD3,
                           0 0 10px #6C5DD3,
                           0 0 15px #6C5DD3;
            }
            50% { 
                box-shadow: 0 0 10px #6C5DD3,
                           0 0 20px #6C5DD3,
                           0 0 30px #6C5DD3;
            }
        }

        /* Snowfall Effect */
        .snowflake {
            position: fixed;
            top: -10px;
            z-index: 1;
            color: white;
            text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
            animation: snowfall linear infinite;
            pointer-events: none;
        }

        @keyframes snowfall {
            0% {
                transform: translateY(-10px) translateX(0) rotate(0deg);
                opacity: 1;
            }
            100% {
                transform: translateY(100vh) translateX(20px) rotate(360deg);
                opacity: 0;
            }
        }

        /* Glass Effect */
        .glass-effect {
            backdrop-filter: blur(10px);
            background: rgba(45, 45, 63, 0.3);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        /* Custom Scrollbar */
        .custom-scrollbar::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }

        .custom-scrollbar::-webkit-scrollbar-track {
            background: rgba(45, 45, 63, 0.3);
            border-radius: 3px;
        }

        .custom-scrollbar::-webkit-scrollbar-thumb {
            background: #6C5DD3;
            border-radius: 3px;
            transition: all 0.3s ease;
        }

        .custom-scrollbar::-webkit-scrollbar-thumb:hover {
            background: #5B4EC2;
        }

        /* Card Effects */
        .game-card {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            transform: translateZ(0);
            backface-visibility: hidden;
        }

        .game-card:hover {
            transform: translateY(-5px) translateZ(0);
            box-shadow: 0 10px 20px rgba(108, 93, 211, 0.2);
        }

        .game-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            border-radius: inherit;
            background: linear-gradient(45deg, #6C5DD3, transparent);
            opacity: 0;
            transition: opacity 0.3s ease;
            z-index: -1;
        }

        .game-card:hover::before {
            opacity: 0.1;
        }

        /* Button Effects */
        .btn-primary {
            position: relative;
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .btn-primary::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 0;
            height: 0;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            transition: width 0.6s ease, height 0.6s ease;
        }

        .btn-primary:hover::before {
            width: 300px;
            height: 300px;
        }

        /* Gradient Text Effect */
        .gradient-text {
            background: linear-gradient(45deg, #6C5DD3, #FF5C5C);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            animation: gradientShift 3s ease infinite;
        }

        @keyframes gradientShift {
            0% { background-position: 0% 50% }
            50% { background-position: 100% 50% }
            100% { background-position: 0% 50% }
        }

        /* Loading Animation */
        .loader {
            width: 48px;
            height: 48px;
            border: 3px solid #6C5DD3;
            border-bottom-color: transparent;
            border-radius: 50%;
            display: inline-block;
            box-sizing: border-box;
            animation: rotation 1s linear infinite;
        }

        @keyframes rotation {
            0% { transform: rotate(0deg) }
            100% { transform: rotate(360deg) }
        }

        /* Tooltip */
        .tooltip {
            position: relative;
        }

        .tooltip::before,
        .tooltip::after {
            position: absolute;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }

        .tooltip::before {
            content: attr(data-tooltip);
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            padding: 6px 10px;
            background: rgba(45, 45, 63, 0.95);
            color: white;
            font-size: 12px;
            white-space: nowrap;
            border-radius: 4px;
            margin-bottom: 5px;
        }

        .tooltip::after {
            content: '';
            bottom: calc(100% - 5px);
            left: 50%;
            transform: translateX(-50%);
            border: 5px solid transparent;
            border-top-color: rgba(45, 45, 63, 0.95);
        }

        .tooltip:hover::before,
        .tooltip:hover::after {
            opacity: 1;
            visibility: visible;
        }

        /* Live Animation */
        .live-indicator {
            position: relative;
        }

        .live-indicator::before {
            content: '';
            position: absolute;
            width: 8px;
            height: 8px;
            background: #FF5C5C;
            border-radius: 50%;
            top: 50%;
            left: -12px;
            transform: translateY(-50%);
            animation: livePulse 1.5s ease infinite;
        }

        @keyframes livePulse {
            0% { transform: translateY(-50%) scale(1); opacity: 1; }
            50% { transform: translateY(-50%) scale(1.5); opacity: 0.5; }
            100% { transform: translateY(-50%) scale(1); opacity: 1; }
        }

        /* Modal Animations */
        .modal {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .modal-content {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            transform: scale(0.9);
            opacity: 0;
        }

        .modal.active .modal-content {
            transform: scale(1);
            opacity: 1;
        }
    </style>
</head>
<body class="christmas-bg min-h-screen text-white font-sans custom-scrollbar">
    <!-- Snowfall Container -->
    <div id="snowfall-container" class="fixed inset-0 pointer-events-none z-50"></div>

    <!-- Toast Notifications Container -->
    <div id="toast-container" class="fixed bottom-4 right-4 z-50 space-y-2"></div>

    <!-- Main Content -->
    <div class="relative z-10">
        <!-- Header будет в следующей части... -->
         <!-- Header -->
        <header class="fixed top-0 w-full z-40 glass-effect">
            <div class="container mx-auto px-4">
                <div class="flex items-center justify-between h-16">
                    <!-- Logo -->
                    <div class="flex items-center space-x-4">
                        <div class="relative group">
                            <div class="text-primary text-2xl font-bold flex items-center space-x-2 group-hover:scale-105 transition-transform">
                                <svg class="w-8 h-8 animate-spin-slow" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M12 2L1 21h22L12 2zm0 3.99L19.53 19H4.47L12 5.99z"/>
                                </svg>
                                <span class="gradient-text">lootrun</span>
                            </div>
                            <div class="absolute -bottom-1 left-0 w-full h-0.5 bg-gradient-to-r from-primary via-warning to-danger transform scale-x-0 group-hover:scale-x-100 transition-transform origin-left"></div>
                        </div>
                    </div>

                    <!-- Main Navigation -->
                    <nav class="hidden md:flex items-center space-x-1">
                        <a href="#" class="nav-link group px-4 py-2 rounded-lg hover:bg-white/5 transition-all relative" onclick="switchTab('games')">
                            <span class="flex items-center space-x-2">
                                <svg class="w-5 h-5 text-primary group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v3h8v-3zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-3a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v3h-3zM4.75 12.094A5.973 5.973 0 004 15v3H1v-3a3 3 0 013.75-2.906z"/>
                                </svg>
                                <span>Игры</span>
                            </span>
                            <div class="absolute bottom-0 left-0 w-full h-0.5 bg-primary transform scale-x-0 group-hover:scale-x-100 transition-transform"></div>
                        </a>

                        <a href="#" class="nav-link group px-4 py-2 rounded-lg hover:bg-white/5 transition-all relative" onclick="switchTab('live')">
                            <span class="flex items-center space-x-2">
                                <svg class="w-5 h-5 text-danger group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd"/>
                                </svg>
                                <span class="live-indicator">Live</span>
                            </span>
                            <div class="absolute bottom-0 left-0 w-full h-0.5 bg-danger transform scale-x-0 group-hover:scale-x-100 transition-transform"></div>
                        </a>

                        <a href="#" class="nav-link group px-4 py-2 rounded-lg hover:bg-white/5 transition-all relative" onclick="switchTab('bets')">
                            <span class="flex items-center space-x-2">
                                <svg class="w-5 h-5 text-success group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd"/>
                                </svg>
                                <span>Ставки</span>
                            </span>
                            <div class="absolute bottom-0 left-0 w-full h-0.5 bg-success transform scale-x-0 group-hover:scale-x-100 transition-transform"></div>
                        </a>

                        <div class="relative group">
                            <a href="#" class="nav-link group px-4 py-2 rounded-lg hover:bg-white/5 transition-all relative" onclick="switchTab('bonus')">
                                <span class="flex items-center space-x-2">
                                    <svg class="w-5 h-5 text-warning group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                        <path fill-rule="evenodd" d="M5 5a3 3 0 015-2.236A3 3 0 0114.83 6H16a2 2 0 110 4h-5V9a1 1 0 10-2 0v1H4a2 2 0 110-4h1.17C5.06 5.687 5 5.35 5 5zm4 1V5a1 1 0 10-1 1h1zm3 0a1 1 0 10-1-1v1h1z" clip-rule="evenodd"/>
                                        <path d="M9 11H3v5a2 2 0 002 2h4v-7zM11 18h4a2 2 0 002-2v-5h-6v7z"/>
                                    </svg>
                                    <span>Бонусы</span>
                                </span>
                                <div class="absolute bottom-0 left-0 w-full h-0.5 bg-warning transform scale-x-0 group-hover:scale-x-100 transition-transform"></div>
                            </a>
                            <!-- Bonus Indicator -->
                            <div class="absolute -top-1 -right-1 w-3 h-3 bg-warning rounded-full animate-ping"></div>
                            <div class="absolute -top-1 -right-1 w-3 h-3 bg-warning rounded-full"></div>
                        </div>
                    </nav>

                    <!-- User Actions -->
                    <div class="flex items-center space-x-4">
                        <!-- Balance -->
                        <div class="group relative">
                            <div class="flex items-center bg-accent/50 px-4 py-2 rounded-lg cursor-pointer hover:bg-accent/70 transition-all"
                                 onclick="showBalanceDetails()">
                                <svg class="w-5 h-5 text-primary mr-2 group-hover:rotate-180 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M4 4a2 2 0 00-2 2v1h16V6a2 2 0 00-2-2H4z"/>
                                    <path fill-rule="evenodd" d="M18 9H2v5a2 2 0 002 2h12a2 2 0 002-2V9zM4 13a1 1 0 011-1h1a1 1 0 110 2H5a1 1 0 01-1-1zm5-1a1 1 0 100 2h1a1 1 0 100-2H9z" clip-rule="evenodd"/>
                                </svg>
                                <span class="font-medium balance-amount" data-balance="1234.56">1,234.56 $</span>
                            </div>

                            <!-- Balance Dropdown -->
                            <div class="absolute right-0 mt-2 w-64 bg-accent rounded-xl shadow-lg py-2 hidden group-hover:block">
                                <div class="px-4 py-2 border-b border-white/10">
                                    <div class="text-sm text-gray-400">Доступно</div>
                                    <div class="text-lg font-bold text-success">1,234.56 $</div>
                                </div>
                                <div class="px-4 py-2">
                                    <div class="text-sm text-gray-400">В ставках</div>
                                    <div class="text-lg font-bold text-warning">234.00 $</div>
                                </div>
                            </div>
                        </div>

                        <!-- Deposit Button -->
                        <button class="btn-primary bg-primary hover:bg-primary-hover px-4 py-2 rounded-lg flex items-center space-x-2 group"
                                onclick="showDepositModal()">
                            <svg class="w-5 h-5 transform group-hover:rotate-12 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
                            </svg>
                            <span>Депозит</span>
                        </button>

                        <!-- Profile Menu -->
                        <div class="relative" id="profileDropdown">
                            <button class="w-10 h-10 rounded-full bg-accent/50 flex items-center justify-center hover:bg-accent/70 transition-all group"
                                    onclick="toggleProfileMenu()">
                                <svg class="w-6 h-6 text-primary group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"/>
                                </svg>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </header>
        <!-- Main Content Area -->
        <div class="container mx-auto px-4 pt-20">
            <div class="flex flex-col lg:flex-row gap-6 py-6">
                <!-- Sidebar -->
                <aside class="w-full lg:w-80 space-y-4">
                    <!-- Profile Card -->
                    <div class="glass-effect rounded-xl p-4 transform hover:scale-[1.02] transition-all">
                        <div class="flex items-center gap-4 mb-4">
                            <div class="relative">
                                <div class="w-16 h-16 rounded-full bg-gradient-to-r from-primary to-danger flex items-center justify-center group-hover:animate-pulse">
                                    <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z'/%3E%3C/svg%3E"
                                         alt="Profile" class="w-10 h-10">
                                </div>
                                <div class="absolute -bottom-1 -right-1 w-6 h-6 bg-success rounded-full border-4 border-accent flex items-center justify-center">
                                    <div class="w-2 h-2 bg-white rounded-full animate-pulse"></div>
                                </div>
                            </div>
                            <div>
                                <h3 class="font-bold text-lg">Player123</h3>
                                <div class="flex items-center space-x-2 text-sm text-gray-400">
                                    <span>ID: 648292</span>
                                    <span class="w-1 h-1 bg-gray-400 rounded-full"></span>
                                    <span class="text-success">Online</span>
                                </div>
                            </div>
                        </div>

                        <!-- Stats -->
                        <div class="grid grid-cols-3 gap-2 mb-4">
                            <div class="text-center p-2 rounded-lg bg-white/5">
                                <div class="text-primary font-bold">147</div>
                                <div class="text-xs text-gray-400">Игр</div>
                            </div>
                            <div class="text-center p-2 rounded-lg bg-white/5">
                                <div class="text-success font-bold">24</div>
                                <div class="text-xs text-gray-400">Побед</div>
                            </div>
                            <div class="text-center p-2 rounded-lg bg-white/5">
                                <div class="text-warning font-bold">5.2K</div>
                                <div class="text-xs text-gray-400">Рейтинг</div>
                            </div>
                        </div>

                        <!-- Quick Actions -->
                        <div class="grid grid-cols-2 gap-2">
                            <button class="btn-primary bg-primary hover:bg-primary-hover transition-all py-2 rounded-lg font-medium flex items-center justify-center group"
                                    onclick="showDepositModal()">
                                <svg class="w-4 h-4 mr-2 transform group-hover:rotate-12 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
                                </svg>
                                Депозит
                            </button>
                            <button class="bg-accent hover:bg-accent/80 transition-all py-2 rounded-lg font-medium flex items-center justify-center group"
                                    onclick="showWithdrawModal()">
                                <svg class="w-4 h-4 mr-2 transform group-hover:-translate-y-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 9l-3 3m0 0l-3-3m3 3V4m0 0v12"/>
                                </svg>
                                Вывод
                            </button>
                        </div>
                    </div>

                    <!-- Navigation Menu -->
                    <nav class="glass-effect rounded-xl overflow-hidden">
                        <div class="p-2 space-y-1">
                            <a href="#" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg hover:bg-white/5 transition-all group"
                               onclick="switchTab('profile')">
                                <svg class="w-5 h-5 text-primary group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"/>
                                </svg>
                                <span>Профиль</span>
                            </a>

                            <a href="#" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg hover:bg-white/5 transition-all group relative"
                               onclick="switchTab('inventory')">
                                <svg class="w-5 h-5 text-warning group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M4 3a2 2 0 100 4h12a2 2 0 100-4H4z"/>
                                    <path fill-rule="evenodd" d="M3 8h14v7a2 2 0 01-2 2H5a2 2 0 01-2-2V8zm5 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z" clip-rule="evenodd"/>
                                </svg>
                                <span>Инвентарь</span>
                                <span class="absolute right-4 top-1/2 -translate-y-1/2 px-2 py-1 bg-warning text-xs rounded-full">
                                    New
                                </span>
                            </a>

                            <a href="#" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg hover:bg-white/5 transition-all group"
                               onclick="switchTab('history')">
                                <svg class="w-5 h-5 text-info group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"/>
                                </svg>
                                <span>История</span>
                            </a>

                            <a href="#" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg hover:bg-white/5 transition-all group"
                               onclick="switchTab('achievements')">
                                <svg class="w-5 h-5 text-success group-hover:scale-110 transition-transform" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
                                </svg>
                                <span>Достижения</span>
                            </a>
                        </div>
                    </nav>

                    <!-- Promo Banner -->
                    <div class="glass-effect rounded-xl p-4 relative overflow-hidden group">
                        <div class="relative z-10">
                            <div class="flex items-center space-x-2 mb-3">
                                <span class="text-2xl">🎄</span>
                                <h3 class="text-lg font-bold gradient-text">Новогодний бонус</h3>
                            </div>
                            <p class="text-sm text-gray-400 mb-4">Получи до 500$ на первый депозит и 100 фриспинов!</p>
                            <button class="w-full bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg flex items-center justify-center group space-x-2"
                                    onclick="claimBonus()">
                                <span>Забрать бонус</span>
                                <svg class="w-4 h-4 transform group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                                </svg>
                            </button>
                        </div>
                        <div class="absolute -right-10 -bottom-10 w-32 h-32 bg-gradient-to-r from-primary to-danger rounded-full opacity-20 group-hover:scale-150 transition-transform"></div>
                    </div>
                </aside>

                <!-- Main Content -->
                <main class="flex-1">
                    <div id="mainContent" class="glass-effect rounded-xl p-6">
                        <!-- Dynamic Content will be loaded here -->
                    </div>
                </main>
            </div>
        </div>
        <!-- Modals -->
        <!-- Deposit Modal -->
        <div id="depositModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-md glass-effect rounded-xl p-6 transform scale-95 opacity-0 transition-all">
                <div class="flex justify-between items-center mb-6">
                    <h3 class="text-xl font-bold">Пополнение баланса</h3>
                    <button class="text-gray-400 hover:text-white transition-colors" onclick="closeModal('depositModal')">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                        </svg>
                    </button>
                </div>

                <!-- Payment Methods -->
                <div class="grid grid-cols-2 gap-3 mb-6">
                    <button class="payment-method-btn active" data-method="card">
                        <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 20 20">
                            <path d="M4 4a2 2 0 00-2 2v1h16V6a2 2 0 00-2-2H4z"/>
                            <path fill-rule="evenodd" d="M18 9H2v5a2 2 0 002 2h12a2 2 0 002-2V9zM4 13a1 1 0 011-1h1a1 1 0 110 2H5a1 1 0 01-1-1zm5-1a1 1 0 100 2h1a1 1 0 100-2H9z" clip-rule="evenodd"/>
                        </svg>
                        Карта
                    </button>
                    <button class="payment-method-btn" data-method="crypto">
                        <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 20 20">
                            <path d="M10 2a8 8 0 100 16 8 8 0 000-16zm0 14a6 6 0 110-12 6 6 0 010 12z"/>
                            <path fill-rule="evenodd" d="M11 9V7a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2z" clip-rule="evenodd"/>
                        </svg>
                        Крипто
                    </button>
                </div>

                <!-- Amount Selection -->
                <div class="grid grid-cols-3 gap-3 mb-6">
                    <button class="amount-btn" data-amount="10">$10</button>
                    <button class="amount-btn" data-amount="50">$50</button>
                    <button class="amount-btn" data-amount="100">$100</button>
                    <button class="amount-btn" data-amount="250">$250</button>
                    <button class="amount-btn" data-amount="500">$500</button>
                    <button class="amount-btn custom" data-amount="custom">
                        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                            <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"/>
                        </svg>
                    </button>
                </div>

                <!-- Custom Amount Input -->
                <div class="relative mb-6 hidden" id="customAmountInput">
                    <input type="number" class="w-full bg-accent/50 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary" 
                           placeholder="Введите сумму">
                    <span class="absolute right-4 top-1/2 -translate-y-1/2 text-gray-400">$</span>
                </div>

                <!-- Bonus Info -->
                <div class="bg-accent/30 rounded-lg p-4 mb-6">
                    <div class="flex items-center space-x-2 mb-2">
                        <svg class="w-5 h-5 text-warning" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M5 2a2 2 0 00-2 2v14l3.5-2 3.5 2 3.5-2 3.5 2V4a2 2 0 00-2-2H5zm4.707 3.707a1 1 0 00-1.414-1.414l-3 3a1 1 0 000 1.414l3 3a1 1 0 001.414-1.414L8.414 9H10a3 3 0 013 3v1a1 1 0 102 0v-1a5 5 0 00-5-5H8.414l1.293-1.293z" clip-rule="evenodd"/>
                        </svg>
                        <span class="font-medium">Доступный бонус</span>
                    </div>
                    <p class="text-sm text-gray-400">+100% к депозиту до $500</p>
                    <div class="w-full bg-accent/50 rounded-full h-2 mt-2">
                        <div class="bg-warning h-full rounded-full w-3/4"></div>
                    </div>
                </div>

                <!-- Submit Button -->
                <button class="w-full bg-primary hover:bg-primary-hover transition-all py-3 rounded-lg font-medium flex items-center justify-center group space-x-2"
                        onclick="processDeposit()">
                    <span>Пополнить</span>
                    <svg class="w-5 h-5 transform group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                    </svg>
                </button>
            </div>
        </div>

        <!-- Withdraw Modal -->
        <div id="withdrawModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-md glass-effect rounded-xl p-6 transform scale-95 opacity-0 transition-all">
                <div class="flex justify-between items-center mb-6">
                    <h3 class="text-xl font-bold">Вывод средств</h3>
                    <button class="text-gray-400 hover:text-white transition-colors" onclick="closeModal('withdrawModal')">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                        </svg>
                    </button>
                </div>

                <!-- Available Balance -->
                <div class="bg-accent/30 rounded-lg p-4 mb-6">
                    <div class="text-sm text-gray-400">Доступно к выводу</div>
                    <div class="text-2xl font-bold">$1,234.56</div>
                </div>

                <!-- Withdrawal Method -->
                <div class="mb-6">
                    <label class="block text-sm text-gray-400 mb-2">Способ вывода</label>
                    <div class="grid grid-cols-2 gap-3">
                        <button class="payment-method-btn active" data-method="card">
                            <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 00-2 2v1h16V6a2 2 0 00-2-2H4z"/>
                                <path fill-rule="evenodd" d="M18 9H2v5a2 2 0 002 2h12a2 2 0 002-2V9zM4 13a1 1 0 011-1h1a1 1 0 110 2H5a1 1 0 01-1-1zm5-1a1 1 0 100 2h1a1 1 0 100-2H9z" clip-rule="evenodd"/>
                            </svg>
                            Карта
                        </button>
                        <button class="payment-method-btn" data-method="crypto">
                            <svg class="w-6 h-6 mb-2" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M10 2a8 8 0 100 16 8 8 0 000-16zm0 14a6 6 0 110-12 6 6 0 010 12z"/>
                                <path fill-rule="evenodd" d="M11 9V7a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2z" clip-rule="evenodd"/>
                            </svg>
                            Крипто
                        </button>
                    </div>
                </div>

                <!-- Amount Input -->
                <div class="relative mb-6">
                    <input type="number" class="w-full bg-accent/50 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary" 
                           placeholder="Сумма вывода">
                    <span class="absolute right-4 top-1/2 -translate-y-1/2 text-gray-400">$</span>
                </div>

                <!-- Submit Button -->
                <button class="w-full bg-primary hover:bg-primary-hover transition-all py-3 rounded-lg font-medium flex items-center justify-center group space-x-2"
                        onclick="processWithdraw()">
                    <span>Вывести</span>
                    <svg class="w-5 h-5 transform group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                    </svg>
                </button>
            </div>
        </div>

        <!-- Success Modal Template -->
        <div id="successModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-sm glass-effect rounded-xl p-6 text-center transform scale-95 opacity-0 transition-all">
                <div class="w-16 h-16 bg-success/20 rounded-full flex items-center justify-center mx-auto mb-4">
                    <svg class="w-8 h-8 text-success" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                    </svg>
                </div>
                <h3 class="text-xl font-bold mb-2">Успешно!</h3>
                <p class="text-gray-400 mb-6" id="successMessage">Операция выполнена успешно</p>
                <button class="w-full bg-success hover:bg-success/80 transition-all py-3 rounded-lg font-medium"
                        onclick="closeModal('successModal')">
                    Готово
                </button>
            </div>
        </div>

        <!-- Error Modal Template -->
        <div id="errorModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-sm glass-effect rounded-xl p-6 text-center transform scale-95 opacity-0 transition-all">
                <div class="w-16 h-16 bg-danger/20 rounded-full flex items-center justify-center mx-auto mb-4">
                    <svg class="w-8 h-8 text-danger" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                    </svg>
                </div>
                <h3 class="text-xl font-bold mb-2">Ошибка</h3>
                <p class="text-gray-400 mb-6" id="errorMessage">Что-то пошло не так</p>
                <button class="w-full bg-danger hover:bg-danger/80 transition-all py-3 rounded-lg font-medium"
                        onclick="closeModal('errorModal')">
                    Закрыть
                </button>
            </div>
        </div>
        <!-- Notification System -->
        <div id="notificationContainer" class="fixed top-4 right-4 z-50 space-y-2"></div>

        <script>
            // Utility Functions
            const $ = (selector) => document.querySelector(selector);
            const $$ = (selector) => document.querySelectorAll(selector);

            // Snowfall Effect
            function createSnowflakes() {
                const container = $('#snowfall-container');
                const snowflakeChars = ['❄', '❅', '❆'];
                
                setInterval(() => {
                    const snowflake = document.createElement('div');
                    snowflake.className = 'snowflake';
                    snowflake.style.left = Math.random() * 100 + 'vw';
                    snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
                    snowflake.innerHTML = snowflakeChars[Math.floor(Math.random() * snowflakeChars.length)];
                    container.appendChild(snowflake);

                    setTimeout(() => snowflake.remove(), 5000);
                }, 200);
            }

            // Notification System
            class NotificationSystem {
                static show(message, type = 'info', duration = 3000) {
                    const notification = document.createElement('div');
                    notification.className = `notification glass-effect rounded-lg p-4 transform translate-x-full transition-all flex items-center space-x-3 ${type}`;
                    
                    const icons = {
                        success: `<svg class="w-5 h-5 text-success" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                                </svg>`,
                        error: `<svg class="w-5 h-5 text-danger" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                                </svg>`,
                        info: `<svg class="w-5 h-5 text-info" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                </svg>`,
                        warning: `<svg class="w-5 h-5 text-warning" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
                                </svg>`
                    };

                    notification.innerHTML = `
                        ${icons[type]}
                        <span>${message}</span>
                        <button class="ml-auto text-gray-400 hover:text-white" onclick="this.parentElement.remove()">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                            </svg>
                        </button>
                    `;

                    $('#notificationContainer').appendChild(notification);
                    
                    requestAnimationFrame(() => {
                        notification.style.transform = 'translateX(0)';
                    });

                    setTimeout(() => {
                        notification.style.transform = 'translateX(calc(100% + 1rem))';
                        notification.style.opacity = '0';
                        setTimeout(() => notification.remove(), 300);
                    }, duration);
                }
            }

            // Modal System
            class ModalSystem {
                static show(modalId) {
                    const modal = $(`#${modalId}`);
                    modal.style.display = 'flex';
                    requestAnimationFrame(() => {
                        modal.querySelector('.modal-content').style.transform = 'scale(1)';
                        modal.querySelector('.modal-content').style.opacity = '1';
                    });
                }

                static close(modalId) {
                    const modal = $(`#${modalId}`);
                    const content = modal.querySelector('.modal-content');
                    content.style.transform = 'scale(0.95)';
                    content.style.opacity = '0';
                    setTimeout(() => {
                        modal.style.display = 'none';
                    }, 300);
                }
            }

            // Payment System
            class PaymentSystem {
                static async processDeposit(amount, method) {
                    try {
                        // Симуляция API запроса
                        await new Promise(resolve => setTimeout(resolve, 1500));
                        
                        if (Math.random() > 0.1) { // 90% успеха
                            ModalSystem.close('depositModal');
                            NotificationSystem.show('Депозит успешно выполнен!', 'success');
                            this.updateBalance(amount);
                        } else {
                            throw new Error('Ошибка обработки платежа');
                        }
                    } catch (error) {
                        NotificationSystem.show(error.message, 'error');
                    }
                }

                static updateBalance(amount) {
                    const balanceEl = $('.balance-amount');
                    const currentBalance = parseFloat(balanceEl.dataset.balance);
                    const newBalance = currentBalance + amount;
                    
                    balanceEl.dataset.balance = newBalance;
                    balanceEl.textContent = new Intl.NumberFormat('en-US', {
                        style: 'currency',
                        currency: 'USD'
                    }).format(newBalance);

                    // Анимация обновления баланса
                    balanceEl.classList.add('animate-pulse');
                    setTimeout(() => balanceEl.classList.remove('animate-pulse'), 1000);
                }
            }

            // Game System
            class GameSystem {
                static games = [
                    {
                        id: 1,
                        name: 'Cosmic Adventure',
                        image: 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"%3E%3Crect width="200" height="200" fill="%236C5DD3"/%3E%3C/svg%3E',
                        category: 'slots',
                        provider: 'SpaceGames',
                        rtp: 96.5,
                        popularity: 4.8
                    },
                    // Добавьте больше игр здесь
                ];

                static loadGames(category = 'all') {
                    const gamesContainer = $('#mainContent');
                    const filteredGames = category === 'all' 
                        ? this.games 
                        : this.games.filter(game => game.category === category);

                    gamesContainer.innerHTML = `
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                            ${filteredGames.map(game => this.createGameCard(game)).join('')}
                        </div>
                    `;
                }

                static createGameCard(game) {
                    return `
                        <div class="game-card glass-effect rounded-xl overflow-hidden relative group">
                            <img src="${game.image}" alt="${game.name}" class="w-full h-48 object-cover">
                            <div class="p-4">
                                <h3 class="font-bold text-lg mb-2">${game.name}</h3>
                                <div class="flex items-center justify-between text-sm text-gray-400">
                                    <span>${game.provider}</span>
                                    <span>RTP: ${game.rtp}%</span>
                                </div>
                            </div>
                            <div class="absolute inset-0 bg-gradient-to-t from-black/80 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity flex items-end justify-center p-4">
                                <button class="bg-primary hover:bg-primary-hover transition-all px-6 py-2 rounded-lg font-medium mb-4"
                                        onclick="GameSystem.startGame(${game.id})">
                                    Играть
                                </button>
                            </div>
                        </div>
                    `;
                }

                static startGame(gameId) {
                    // Имплементация запуска игры
                    NotificationSystem.show('Игра запускается...', 'info');
                }
            }

            // Event Listeners
            document.addEventListener('DOMContentLoaded', () => {
                createSnowflakes();
                GameSystem.loadGames();

                // Initialize payment method buttons
                $$('.payment-method-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        $$('.payment-method-btn').forEach(b => b.classList.remove('active'));
                        btn.classList.add('active');
                    });
                });

                // Initialize amount buttons
                $$('.amount-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        $$('.amount-btn').forEach(b => b.classList.remove('active'));
                        btn.classList.add('active');
                        
                        if (btn.dataset.amount === 'custom') {
                            $('#customAmountInput').classList.remove('hidden');
                        } else {
                            $('#customAmountInput').classList.add('hidden');
                        }
                    });
                });
            });

            // Demo Functions
            function showDepositModal() {
                ModalSystem.show('depositModal');
            }

            function showWithdrawModal() {
                ModalSystem.show('withdrawModal');
            }

            function processDeposit() {
                const amount = parseFloat($('.amount-btn.active')?.dataset.amount || $('#customAmountInput input').value);
                const method = $('.payment-method-btn.active')?.dataset.method;

                if (!amount || isNaN(amount)) {
                    NotificationSystem.show('Пожалуйста, введите сумму', 'error');
                    return;
                }

                PaymentSystem.processDeposit(amount, method);
            }

            function claimBonus() {
                NotificationSystem.show('Бонус успешно активирован!', 'success');
            }
        </script>
        <!-- Live Chat Widget -->
        <div id="chatWidget" class="fixed bottom-4 right-4 z-40 w-80 glass-effect rounded-xl shadow-lg transform transition-transform translate-y-[calc(100%-3.5rem)]" 
             style="height: 480px;">
            <div class="p-4 cursor-pointer flex items-center justify-between border-b border-white/10"
                 onclick="toggleChat()">
                <div class="flex items-center space-x-2">
                    <div class="relative">
                        <svg class="w-6 h-6 text-primary" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z" clip-rule="evenodd"/>
                        </svg>
                        <span class="absolute -top-1 -right-1 w-3 h-3 bg-success rounded-full border-2 border-accent"></span>
                    </div>
                    <span class="font-medium">Чат</span>
                    <span class="text-xs text-gray-400">(3 онлайн)</span>
                </div>
                <svg class="w-5 h-5 transform transition-transform chat-arrow" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                </svg>
            </div>

            <div class="h-[calc(100%-4rem)] flex flex-col">
                <!-- Chat Messages -->
                <div id="chatMessages" class="flex-1 overflow-y-auto p-4 space-y-4 custom-scrollbar">
                    <!-- Messages will be dynamically added here -->
                </div>

                <!-- Chat Input -->
                <div class="p-4 border-t border-white/10">
                    <div class="flex items-center space-x-2">
                        <input type="text" id="chatInput" 
                               class="flex-1 bg-accent/50 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary"
                               placeholder="Написать сообщение...">
                        <button class="w-10 h-10 flex items-center justify-center bg-primary hover:bg-primary-hover rounded-lg transition-colors"
                                onclick="sendChatMessage()">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"/>
                            </svg>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Achievement Popup -->
        <div id="achievementPopup" class="fixed bottom-20 left-1/2 -translate-x-1/2 transform scale-0 transition-transform duration-300">
            <div class="glass-effect rounded-xl p-4 flex items-center space-x-4">
                <div class="w-12 h-12 rounded-xl bg-warning/20 flex items-center justify-center">
                    <svg class="w-6 h-6 text-warning" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M5 2a2 2 0 00-2 2v14l3.5-2 3.5 2 3.5-2 3.5 2V4a2 2 0 00-2-2H5zm2.5 3a1.5 1.5 0 100 3 1.5 1.5 0 000-3zm6.207.293a1 1 0 00-1.414 0l-6 6a1 1 0 101.414 1.414l6-6a1 1 0 000-1.414zM12.5 10a1.5 1.5 0 100 3 1.5 1.5 0 000-3z" clip-rule="evenodd"/>
                    </svg>
                </div>
                <div>
                    <div class="text-sm text-gray-400">Новое достижение!</div>
                    <div class="font-medium achievement-title">Название достижения</div>
                </div>
            </div>
        </div>

        <script>
            // Chat System
            class ChatSystem {
                static messages = [];
                static isOpen = false;

                static initialize() {
                    this.loadDemoMessages();
                    this.renderMessages();

                    // Enter key listener
                    $('#chatInput').addEventListener('keypress', (e) => {
                        if (e.key === 'Enter') {
                            this.sendMessage();
                        }
                    });
                }

                static loadDemoMessages() {
                    this.messages = [
                        { user: 'System', message: 'Добро пожаловать в чат!', type: 'system' },
                        { user: 'Player123', message: 'Всем привет!', type: 'user' },
                        { user: 'GameMaster', message: 'Приветствуем!', type: 'admin' }
                    ];
                }

                static renderMessages() {
                    const container = $('#chatMessages');
                    container.innerHTML = this.messages.map(msg => this.createMessageElement(msg)).join('');
                    container.scrollTop = container.scrollHeight;
                }

                static createMessageElement(msg) {
                    const typeClasses = {
                        system: 'bg-accent/30',
                        user: 'bg-primary/30',
                        admin: 'bg-warning/30'
                    };

                    return `
                        <div class="message ${typeClasses[msg.type]} rounded-lg p-3">
                            <div class="flex items-center space-x-2 mb-1">
                                <span class="font-medium">${msg.user}</span>
                                ${msg.type === 'admin' ? '<span class="text-xs bg-warning/20 text-warning px-2 py-0.5 rounded">Admin</span>' : ''}
                            </div>
                            <div class="text-sm text-gray-300">${msg.message}</div>
                        </div>
                    `;
                }

                static sendMessage() {
                    const input = $('#chatInput');
                    const message = input.value.trim();

                    if (message) {
                        this.messages.push({
                            user: 'You',
                            message: message,
                            type: 'user'
                        });

                        this.renderMessages();
                        input.value = '';
                    }
                }

                static toggle() {
                    const chat = $('#chatWidget');
                    const arrow = $('.chat-arrow');
                    this.isOpen = !this.isOpen;
                    
                    chat.style.transform = this.isOpen ? 'translateY(0)' : 'translateY(calc(100% - 3.5rem))';
                    arrow.style.transform = this.isOpen ? 'rotate(180deg)' : 'rotate(0)';
                }
            }

            // Achievement System
            class AchievementSystem {
                static achievements = [
                    { id: 1, title: 'Первая победа', description: 'Выиграйте свою первую игру', icon: '🏆' },
                    { id: 2, title: 'Счастливчик', description: 'Выиграйте 10 раз подряд', icon: '🍀' },
                    { id: 3, title: 'Богач', description: 'Накопите 10,000$', icon: '💰' },
                    // Добавьте больше достижений
                ];

                static unlockedAchievements = new Set();

                static unlock(achievementId) {
                    if (this.unlockedAchievements.has(achievementId)) return;

                    const achievement = this.achievements.find(a => a.id === achievementId);
                    if (!achievement) return;

                    this.unlockedAchievements.add(achievementId);
                    this.showPopup(achievement);
                    NotificationSystem.show(`Получено достижение: ${achievement.title}`, 'success', 5000);
                }

                static showPopup(achievement) {
                    const popup = $('#achievementPopup');
                    popup.querySelector('.achievement-title').textContent = achievement.title;
                    popup.style.transform = 'translate(-50%, 0) scale(1)';

                    setTimeout(() => {
                        popup.style.transform = 'translate(-50%, 0) scale(0)';
                    }, 3000);
                }
            }

            // Initialize Systems
            document.addEventListener('DOMContentLoaded', () => {
                ChatSystem.initialize();

                // Demo achievement unlock after 5 seconds
                setTimeout(() => {
                    AchievementSystem.unlock(1);
                }, 5000);
            });

            // Helper Functions
            function toggleChat() {
                ChatSystem.toggle();
            }

            function sendChatMessage() {
                ChatSystem.sendMessage();
            }
        </script>
        <!-- Tournament Banner -->
        <div id="tournamentBanner" class="fixed top-20 left-4 z-30 w-64">
            <div class="glass-effect rounded-xl p-4 transform hover:scale-105 transition-transform cursor-pointer"
                 onclick="showTournamentDetails()">
                <div class="relative">
                    <div class="absolute -top-6 -right-6 w-12 h-12 bg-warning rounded-xl flex items-center justify-center transform rotate-12 animate-pulse">
                        <span class="text-xl">🏆</span>
                    </div>
                    <h3 class="text-lg font-bold mb-2">Турнир дня</h3>
                    <div class="text-sm text-gray-400 mb-3">Призовой фонд:</div>
                    <div class="text-2xl font-bold gradient-text mb-4">$10,000</div>
                    
                    <!-- Progress Bar -->
                    <div class="relative pt-1">
                        <div class="text-xs text-gray-400 mb-1">До начала: 2:34:15</div>
                        <div class="overflow-hidden h-2 text-xs flex rounded bg-accent/30">
                            <div class="tournament-progress animate-width-change w-1/2 shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-gradient-to-r from-primary to-warning"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Tournament Modal -->
        <div id="tournamentModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-4xl glass-effect rounded-xl p-6 transform scale-95 opacity-0 transition-all">
                <div class="flex justify-between items-center mb-6">
                    <h3 class="text-2xl font-bold gradient-text">Турнир "Космическая гонка"</h3>
                    <button class="text-gray-400 hover:text-white transition-colors" onclick="closeTournamentModal()">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                        </svg>
                    </button>
                </div>

                <!-- Tournament Info -->
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
                    <div class="glass-card p-4 rounded-xl bg-accent/20">
                        <div class="text-sm text-gray-400 mb-1">Призовой фонд</div>
                        <div class="text-2xl font-bold gradient-text">$10,000</div>
                    </div>
                    <div class="glass-card p-4 rounded-xl bg-accent/20">
                        <div class="text-sm text-gray-400 mb-1">Участников</div>
                        <div class="text-2xl font-bold">234 / 500</div>
                    </div>
                    <div class="glass-card p-4 rounded-xl bg-accent/20">
                        <div class="text-sm text-gray-400 mb-1">Время до старта</div>
                        <div class="text-2xl font-bold countdown">2:34:15</div>
                    </div>
                </div>

                <!-- Prize Distribution -->
                <div class="mb-6">
                    <h4 class="text-lg font-bold mb-4">Распределение призов</h4>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="relative glass-card p-4 rounded-xl bg-warning/20 transform hover:scale-105 transition-transform">
                            <div class="absolute -top-3 -right-3 w-8 h-8 bg-warning rounded-full flex items-center justify-center">
                                1
                            </div>
                            <div class="text-sm text-gray-400 mb-1">1 место</div>
                            <div class="text-xl font-bold">$5,000</div>
                        </div>
                        <div class="relative glass-card p-4 rounded-xl bg-accent/30 transform hover:scale-105 transition-transform">
                            <div class="absolute -top-3 -right-3 w-8 h-8 bg-accent rounded-full flex items-center justify-center">
                                2
                            </div>
                            <div class="text-sm text-gray-400 mb-1">2 место</div>
                            <div class="text-xl font-bold">$3,000</div>
                        </div>
                        <div class="relative glass-card p-4 rounded-xl bg-accent/20 transform hover:scale-105 transition-transform">
                            <div class="absolute -top-3 -right-3 w-8 h-8 bg-accent/80 rounded-full flex items-center justify-center">
                                3
                            </div>
                            <div class="text-sm text-gray-400 mb-1">3 место</div>
                            <div class="text-xl font-bold">$2,000</div>
                        </div>
                    </div>
                </div>

                <!-- Leaderboard -->
                <div class="mb-6">
                    <h4 class="text-lg font-bold mb-4">Текущий рейтинг</h4>
                    <div class="overflow-hidden rounded-xl">
                        <table class="w-full">
                            <thead>
                                <tr class="bg-accent/30">
                                    <th class="px-4 py-3 text-left">Место</th>
                                    <th class="px-4 py-3 text-left">Игрок</th>
                                    <th class="px-4 py-3 text-right">Очки</th>
                                    <th class="px-4 py-3 text-right">Выигрыш</th>
                                </tr>
                            </thead>
                            <tbody id="tournamentLeaderboard">
                                <!-- Will be filled dynamically -->
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Join Button -->
                <button class="w-full bg-primary hover:bg-primary-hover transition-all py-3 rounded-lg font-medium flex items-center justify-center group space-x-2"
                        onclick="joinTournament()">
                    <span>Участвовать</span>
                    <span class="text-sm">(Buy-in: $50)</span>
                    <svg class="w-5 h-5 transform group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                    </svg>
                </button>
            </div>
        </div>

        <script>
            // Tournament System
            class TournamentSystem {
                static tournaments = [];
                static currentTournament = null;

                static initialize() {
                    this.loadDemoTournament();
                    this.startCountdown();
                    this.updateLeaderboard();
                }

                static loadDemoTournament() {
                    this.currentTournament = {
                        id: 1,
                        name: 'Космическая гонка',
                        prizePoll: 10000,
                        participants: 234,
                        maxParticipants: 500,
                        startTime: new Date(Date.now() + 9255000), // 2:34:15 from now
                        leaderboard: [
                            { rank: 1, player: 'ProGamer123', points: 1250, winnings: 0 },
                            { rank: 2, player: 'LuckyOne', points: 980, winnings: 0 },
                            { rank: 3, player: 'StarPlayer', points: 875, winnings: 0 },
                            { rank: 4, player: 'GameMaster', points: 720, winnings: 0 },
                            { rank: 5, player: 'Winner777', points: 690, winnings: 0 }
                        ]
                    };
                }

                static startCountdown() {
                    const updateCountdown = () => {
                        const now = new Date();
                        const distance = this.currentTournament.startTime - now;

                        const hours = Math.floor(distance / (1000 * 60 * 60));
                        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                        const seconds = Math.floor((distance % (1000 * 60)) / 1000);

                        const countdownStr = `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
                        $$('.countdown').forEach(el => el.textContent = countdownStr);

                        if (distance < 0) {
                            clearInterval(this.countdownInterval);
                            this.startTournament();
                        }
                    };

                    updateCountdown();
                    this.countdownInterval = setInterval(updateCountdown, 1000);
                }

                static updateLeaderboard() {
                    const tbody = $('#tournamentLeaderboard');
                    tbody.innerHTML = this.currentTournament.leaderboard.map(entry => `
                        <tr class="border-t border-white/10 hover:bg-accent/20 transition-colors">
                            <td class="px-4 py-3">
                                <div class="flex items-center space-x-2">
                                    ${entry.rank === 1 ? '🏆' : entry.rank === 2 ? '🥈' : entry.rank === 3 ? '🥉' : entry.rank}
                                </div>
                            </td>
                            <td class="px-4 py-3">
                                <div class="flex items-center space-x-2">
                                    <div class="w-8 h-8 rounded-full bg-accent/50 flex items-center justify-center">
                                        ${entry.player.charAt(0)}
                                    </div>
                                    <span>${entry.player}</span>
                                </div>
                            </td>
                            <td class="px-4 py-3 text-right">${entry.points.toLocaleString()}</td>
                            <td class="px-4 py-3 text-right">$${entry.winnings.toLocaleString()}</td>
                        </tr>
                    `).join('');
                }

                static joinTournament() {
                    if (this.currentTournament.participants >= this.currentTournament.maxParticipants) {
                        NotificationSystem.show('Турнир уже заполнен!', 'error');
                        return;
                    }

                    // Check balance and deduct buy-in
                    PaymentSystem.processTransaction(-50, 'tournament-buy-in')
                        .then(() => {
                            this.currentTournament.participants++;
                            NotificationSystem.show('Вы успешно зарегистрированы в турнире!', 'success');
                            this.updateTournamentInfo();
                        })
                        .catch(() => {
                            NotificationSystem.show('Недостаточно средств для участия', 'error');
                        });
                }

                static updateTournamentInfo() {
                    // Update participants count and other info
                    // This would be more complex in a real application
                }
            }

            // Initialize Tournament System
            document.addEventListener('DOMContentLoaded', () => {
                TournamentSystem.initialize();
            });

            // Helper Functions
            function showTournamentDetails() {
                ModalSystem.show('tournamentModal');
            }

            function closeTournamentModal() {
                ModalSystem.close('tournamentModal');
            }

            function joinTournament() {
                TournamentSystem.joinTournament();
            }
        </script>
        <!-- Level Up Popup -->
        <div id="levelUpPopup" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-md glass-effect rounded-xl p-6 text-center transform scale-95 opacity-0 transition-all">
                <div class="relative mb-6">
                    <div class="absolute inset-0 bg-gradient-to-r from-primary to-warning rounded-full animate-spin-slow opacity-20"></div>
                    <div class="w-24 h-24 mx-auto bg-gradient-to-r from-primary to-warning rounded-full flex items-center justify-center">
                        <div class="text-4xl font-bold level-number">10</div>
                    </div>
                </div>
                <h3 class="text-2xl font-bold mb-2">Новый уровень!</h3>
                <p class="text-gray-400 mb-6">Вы достигли 10 уровня</p>
                <div class="grid grid-cols-2 gap-4 mb-6">
                    <div class="bg-accent/30 rounded-xl p-4">
                        <div class="text-sm text-gray-400 mb-1">Награда</div>
                        <div class="text-xl font-bold">$100</div>
                    </div>
                    <div class="bg-accent/30 rounded-xl p-4">
                        <div class="text-sm text-gray-400 mb-1">Бонус</div>
                        <div class="text-xl font-bold">50 FS</div>
                    </div>
                </div>
                <button class="w-full bg-primary hover:bg-primary-hover transition-all py-3 rounded-lg font-medium"
                        onclick="closeLevelUpPopup()">
                    Круто!
                </button>
            </div>
        </div>

        <!-- Profile Section -->
        <div id="profileSection" class="hidden">
            <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                <!-- Stats Overview -->
                <div class="glass-effect rounded-xl p-6">
                    <h3 class="text-xl font-bold mb-4">Статистика</h3>
                    <div class="space-y-4">
                        <div class="flex items-center justify-between">
                            <div class="text-gray-400">Всего игр</div>
                            <div class="font-bold">1,234</div>
                        </div>
                        <div class="flex items-center justify-between">
                            <div class="text-gray-400">Победы</div>
                            <div class="text-success font-bold">789</div>
                        </div>
                        <div class="flex items-center justify-between">
                            <div class="text-gray-400">Проигрыши</div>
                            <div class="text-danger font-bold">445</div>
                        </div>
                        <div class="flex items-center justify-between">
                            <div class="text-gray-400">Винрейт</div>
                            <div class="text-warning font-bold">63.9%</div>
                        </div>
                    </div>

                    <!-- Level Progress -->
                    <div class="mt-6">
                        <div class="flex items-center justify-between mb-2">
                            <div class="text-sm text-gray-400">Уровень 10</div>
                            <div class="text-sm text-gray-400">2,345 / 3,000 XP</div>
                        </div>
                        <div class="relative h-3 bg-accent/30 rounded-full overflow-hidden">
                            <div class="absolute inset-0 bg-gradient-to-r from-primary to-warning w-[78%] transition-all duration-1000"></div>
                        </div>
                    </div>
                </div>

                <!-- Recent Activity -->
                <div class="glass-effect rounded-xl p-6">
                    <h3 class="text-xl font-bold mb-4">Последние игры</h3>
                    <div class="space-y-4">
                        <div class="flex items-center justify-between p-3 bg-accent/20 rounded-lg">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center">
                                    🎰
                                </div>
                                <div>
                                    <div class="font-medium">Cosmic Adventure</div>
                                    <div class="text-sm text-gray-400">2 минуты назад</div>
                                </div>
                            </div>
                            <div class="text-success font-bold">+$123.45</div>
                        </div>
                        <div class="flex items-center justify-between p-3 bg-accent/20 rounded-lg">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center">
                                    🎲
                                </div>
                                <div>
                                    <div class="font-medium">Lucky Dice</div>
                                    <div class="text-sm text-gray-400">15 минут назад</div>
                                </div>
                            </div>
                            <div class="text-danger font-bold">-$45.00</div>
                        </div>
                    </div>
                </div>

                <!-- Achievements Progress -->
                <div class="glass-effect rounded-xl p-6">
                    <h3 class="text-xl font-bold mb-4">Достижения</h3>
                    <div class="space-y-4">
                        <div class="achievement-card p-3 bg-accent/20 rounded-lg relative overflow-hidden group">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-warning/20 flex items-center justify-center text-xl">
                                    🏆
                                </div>
                                <div>
                                    <div class="font-medium">Первая победа</div>
                                    <div class="text-sm text-success">Выполнено!</div>
                                </div>
                            </div>
                            <div class="absolute inset-0 bg-gradient-to-r from-success/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"></div>
                        </div>
                        <div class="achievement-card p-3 bg-accent/20 rounded-lg relative overflow-hidden group">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center text-xl">
                                    💰
                                </div>
                                <div>
                                    <div class="font-medium">Богач</div>
                                    <div class="text-sm text-gray-400">7,500 / 10,000$</div>
                                </div>
                            </div>
                            <div class="absolute bottom-0 left-0 h-1 bg-primary" style="width: 75%"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Level System
            class LevelSystem {
                static currentLevel = 10;
                static currentXP = 2345;
                static xpToNextLevel = 3000;
                
                static initialize() {
                    this.updateLevelDisplay();
                }

                static addXP(amount) {
                    this.currentXP += amount;
                    if (this.currentXP >= this.xpToNextLevel) {
                        this.levelUp();
                    }
                    this.updateLevelDisplay();
                }

                static levelUp() {
                    this.currentLevel++;
                    this.currentXP = this.currentXP - this.xpToNextLevel;
                    this.xpToNextLevel = Math.floor(this.xpToNextLevel * 1.2);
                    this.showLevelUpPopup();
                }

                static updateLevelDisplay() {
                    // Update level progress bar and numbers
                    const progressPercent = (this.currentXP / this.xpToNextLevel) * 100;
                    $('.level-progress').style.width = `${progressPercent}%`;
                    $('.level-number').textContent = this.currentLevel;
                    $('.level-xp').textContent = `${this.currentXP.toLocaleString()} / ${this.xpToNextLevel.toLocaleString()} XP`;
                }

                static showLevelUpPopup() {
                    const popup = $('#levelUpPopup');
                    popup.style.display = 'flex';
                    setTimeout(() => {
                        popup.querySelector('.modal-content').style.transform = 'scale(1)';
                        popup.querySelector('.modal-content').style.opacity = '1';
                    }, 10);

                    // Add rewards
                    PaymentSystem.addFunds(100, 'Level Up Bonus');
                    // Add free spins or other bonuses
                }
            }

            // Profile System
            class ProfileSystem {
                static stats = {
                    totalGames: 1234,
                    wins: 789,
                    losses: 445,
                    winRate: 63.9
                };

                static recentGames = [
                    {
                        game: 'Cosmic Adventure',
                        time: '2 minutes ago',
                        amount: 123.45,
                        win: true
                    },
                    {
                        game: 'Lucky Dice',
                        time: '15 minutes ago',
                        amount: -45.00,
                        win: false
                    }
                ];

                static initialize() {
                    this.updateStats();
                    this.updateRecentGames();
                }

                static updateStats() {
                    // Update stats display
                    // This would be more complex in a real application
                }

                static updateRecentGames() {
                    // Update recent games list
                    // This would be more complex in a real application
                }

                static addGame(gameData) {
                    this.recentGames.unshift(gameData);
                    this.recentGames = this.recentGames.slice(0, 5); // Keep only last 5 games
                    this.updateRecentGames();
                    this.updateStats();
                }
            }

            // Initialize Systems
            document.addEventListener('DOMContentLoaded', () => {
                LevelSystem.initialize();
                ProfileSystem.initialize();
            });

            function closeLevelUpPopup() {
                const popup = $('#levelUpPopup');
                popup.querySelector('.modal-content').style.transform = 'scale(0.95)';
                popup.querySelector('.modal-content').style.opacity = '0';
                setTimeout(() => {
                    popup.style.display = 'none';
                }, 300);
            }
        </script>
        <!-- Settings Modal -->
        <div id="settingsModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden items-center justify-center z-50">
            <div class="modal-content w-full max-w-4xl glass-effect rounded-xl p-6 transform scale-95 opacity-0 transition-all">
                <div class="flex justify-between items-center mb-6">
                    <h3 class="text-2xl font-bold">Настройки</h3>
                    <button class="text-gray-400 hover:text-white transition-colors" onclick="closeSettingsModal()">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                        </svg>
                    </button>
                </div>

                <!-- Settings Tabs -->
                <div class="flex space-x-4 mb-6 border-b border-white/10">
                    <button class="settings-tab active px-4 py-2 relative" data-tab="profile">
                        Профиль
                        <div class="absolute bottom-0 left-0 w-full h-0.5 bg-primary transform scale-x-0 transition-transform origin-left"></div>
                    </button>
                    <button class="settings-tab px-4 py-2 relative" data-tab="security">
                        Безопасность
                        <div class="absolute bottom-0 left-0 w-full h-0.5 bg-primary transform scale-x-0 transition-transform origin-left"></div>
                    </button>
                    <button class="settings-tab px-4 py-2 relative" data-tab="notifications">
                        Уведомления
                        <div class="absolute bottom-0 left-0 w-full h-0.5 bg-primary transform scale-x-0 transition-transform origin-left"></div>
                    </button>
                    <button class="settings-tab px-4 py-2 relative" data-tab="preferences">
                        Предпочтения
                        <div class="absolute bottom-0 left-0 w-full h-0.5 bg-primary transform scale-x-0 transition-transform origin-left"></div>
                    </button>
                </div>

                <!-- Settings Content -->
                <div class="settings-content">
                    <!-- Profile Settings -->
                    <div class="settings-panel active" data-panel="profile">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <!-- Avatar Upload -->
                            <div class="text-center">
                                <div class="relative w-32 h-32 mx-auto mb-4">
                                    <div class="w-full h-full rounded-full bg-accent/30 flex items-center justify-center overflow-hidden">
                                        <img id="avatarPreview" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%236C7293' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z'/%3E%3C/svg%3E" 
                                             alt="Avatar" class="w-full h-full object-cover">
                                    </div>
                                    <label class="absolute bottom-0 right-0 w-8 h-8 bg-primary rounded-full flex items-center justify-center cursor-pointer hover:bg-primary-hover transition-colors">
                                        <input type="file" class="hidden" accept="image/*" onchange="handleAvatarUpload(event)">
                                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
                                        </svg>
                                    </label>
                                </div>
                                <div class="text-sm text-gray-400">Рекомендуемый размер: 256x256</div>
                            </div>

                            <!-- Profile Info -->
                            <div class="space-y-4">
                                <div>
                                    <label class="block text-sm text-gray-400 mb-2">Никнейм</label>
                                    <input type="text" class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary"
                                           value="Player123">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-400 mb-2">Email</label>
                                    <input type="email" class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary"
                                           value="player@example.com">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Security Settings -->
                    <div class="settings-panel hidden" data-panel="security">
                        <div class="space-y-6">
                            <!-- Password Change -->
                            <div class="space-y-4">
                                <div>
                                    <label class="block text-sm text-gray-400 mb-2">Текущий пароль</label>
                                    <input type="password" class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-400 mb-2">Новый пароль</label>
                                    <input type="password" class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-400 mb-2">Подтвердите пароль</label>
                                    <input type="password" class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary">
                                </div>
                            </div>

                            <!-- 2FA -->
                            <div class="flex items-center justify-between p-4 bg-accent/20 rounded-lg">
                                <div>
                                    <div class="font-medium">Двухфакторная аутентификация</div>
                                    <div class="text-sm text-gray-400">Повысьте безопасность вашего аккаунта</div>
                                </div>
                                <label class="relative inline-flex items-center cursor-pointer">
                                    <input type="checkbox" class="sr-only peer" onchange="toggle2FA(this)">
                                    <div class="w-11 h-6 bg-accent/30 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary"></div>
                                </label>
                            </div>
                        </div>
                    </div>

                    <!-- Notifications Settings -->
                    <div class="settings-panel hidden" data-panel="notifications">
                        <div class="space-y-4">
                            <div class="flex items-center justify-between p-4 bg-accent/20 rounded-lg">
                                <div>
                                    <div class="font-medium">Турниры</div>
                                    <div class="text-sm text-gray-400">Уведомления о новых турнирах</div>
                                </div>
                                <label class="relative inline-flex items-center cursor-pointer">
                                    <input type="checkbox" class="sr-only peer" checked>
                                    <div class="w-11 h-6 bg-accent/30 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary"></div>
                                </label>
                            </div>
                            <div class="flex items-center justify-between p-4 bg-accent/20 rounded-lg">
                                <div>
                                    <div class="font-medium">Бонусы</div>
                                    <div class="text-sm text-gray-400">Уведомления о новых бонусах</div>
                                </div>
                                <label class="relative inline-flex items-center cursor-pointer">
                                    <input type="checkbox" class="sr-only peer" checked>
                                    <div class="w-11 h-6 bg-accent/30 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary"></div>
                                </label>
                            </div>
                            <div class="flex items-center justify-between p-4 bg-accent/20 rounded-lg">
                                <div>
                                    <div class="font-medium">Достижения</div>
                                    <div class="text-sm text-gray-400">Уведомления о новых достижениях</div>
                                </div>
                                <label class="relative inline-flex items-center cursor-pointer">
                                    <input type="checkbox" class="sr-only peer" checked>
                                    <div class="w-11 h-6 bg-accent/30 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary"></div>
                                </label>
                            </div>
                        </div>
                    </div>

                    <!-- Preferences Settings -->
                    <div class="settings-panel hidden" data-panel="preferences">
                        <div class="space-y-6">
                            <!-- Theme Selection -->
                            <div>
                                <label class="block text-sm text-gray-400 mb-4">Тема оформления</label>
                                <div class="grid grid-cols-3 gap-4">
                                    <button class="theme-btn active" data-theme="dark">
                                        <div class="w-full h-20 rounded-lg bg-accent mb-2"></div>
                                        <span>Тёмная</span>
                                    </button>
                                    <button class="theme-btn" data-theme="light">
                                        <div class="w-full h-20 rounded-lg bg-white mb-2"></div>
                                        <span>Светлая</span>
                                    </button>
                                    <button class="theme-btn" data-theme="auto">
                                        <div class="w-full h-20 rounded-lg bg-gradient-to-r from-accent to-white mb-2"></div>
                                        <span>Авто</span>
                                    </button>
                                </div>
                            </div>

                            <!-- Language Selection -->
                            <div>
                                <label class="block text-sm text-gray-400 mb-2">Язык</label>
                                <select class="w-full bg-accent/30 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary">
                                    <option value="ru">Русский</option>
                                    <option value="en">English</option>
                                    <option value="es">Español</option>
                                    <option value="de">Deutsch</option>
                                </select>
                            </div>

                            <!-- Sound Settings -->
                            <div>
                                <label class="block text-sm text-gray-400 mb-2">Громкость звуков</label>
                                <input type="range" class="w-full" min="0" max="100" value="80">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Save Button -->
                <div class="mt-6 flex justify-end">
                    <button class="bg-primary hover:bg-primary-hover transition-all px-6 py-3 rounded-lg font-medium"
                            onclick="saveSettings()">
                        Сохранить изменения
                    </button>
                </div>
            </div>
        </div>

        <script>
            // Settings System
            class SettingsSystem {
                static initialize() {
                    this.initializeTabs();
                    this.initializeThemeButtons();
                }

                static initializeTabs() {
                    $$('.settings-tab').forEach(tab => {
                        tab.addEventListener('click', () => {
                            const targetTab = tab.dataset.tab;
                            
                            // Update tabs
                            $$('.settings-tab').forEach(t => {
                                t.classList.remove('active');
                                t.querySelector('div').style.transform = 'scaleX(0)';
                            });
                            tab.classList.add('active');
                            tab.querySelector('div').style.transform = 'scaleX(1)';

                            // Update panels
                            $$('.settings-panel').forEach(p => p.classList.add('hidden'));
                            $(`.settings-panel[data-panel="${targetTab}"]`).classList.remove('hidden');
                        });
                    });
                }

                static initializeThemeButtons() {
                    $$('.theme-btn').forEach(btn => {
                        btn.addEventListener('click', () => {
                            $$('.theme-btn').forEach(b => b.classList.remove('active'));
                            btn.classList.add('active');
                            this.setTheme(btn.dataset.theme);
                        });
                    });
                }

                static setTheme(theme) {
                    // Implementation of theme switching would go here
                    NotificationSystem.show(`Тема изменена на: ${theme}`, 'success');
                }

                static saveSettings() {
                    // Implementation of settings saving would go here
                    NotificationSystem.show('Настройки успешно сохранены', 'success');
                    closeSettingsModal();
                }
            }

            // Initialize Settings
            document.addEventListener('DOMContentLoaded', () => {
                SettingsSystem.initialize();
            });

            function handleAvatarUpload(event) {
                const file = event.target.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(e) {
                        $('#avatarPreview').src = e.target.result;
                    }
                    reader.readAsDataURL(file);
                }
            }

            function toggle2FA(checkbox) {
                if (checkbox.checked) {
                    // Implementation of 2FA setup would go here
                    NotificationSystem.show('2FA активирована', 'success');
                } else {
                    NotificationSystem.show('2FA деактивирована', 'warning');
                }
            }

            function saveSettings() {
                SettingsSystem.saveSettings();
            }

            function closeSettingsModal() {
                ModalSystem.close('settingsModal');
            }
        </script>
        <!-- Rewards Panel -->
        <div id="rewardsPanel" class="glass-effect rounded-xl p-6 hidden">
            <!-- Daily Rewards -->
            <div class="mb-8">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-xl font-bold">Ежедневные награды</h3>
                    <div class="text-sm text-gray-400">День 5 из 7</div>
                </div>
                <div class="grid grid-cols-7 gap-4">
                    <!-- Days 1-7 -->
                    <template x-for="i in 7">
                        <div class="relative group">
                            <div class="w-full aspect-square bg-accent/20 rounded-lg flex flex-col items-center justify-center overflow-hidden">
                                <div class="text-2xl mb-2" x-text="getRewardEmoji(i)"></div>
                                <div class="text-xs text-gray-400">День <span x-text="i"></span></div>
                                <!-- Collected Overlay -->
                                <div class="absolute inset-0 bg-success/20 flex items-center justify-center"
                                     x-show="i < 5">
                                    <svg class="w-6 h-6 text-success" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                                    </svg>
                                </div>
                            </div>
                            <!-- Tooltip -->
                            <div class="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-32 p-2 bg-accent rounded-lg text-center text-sm opacity-0 group-hover:opacity-100 transition-opacity">
                                <div x-text="getRewardDescription(i)"></div>
                            </div>
                        </div>
                    </template>
                </div>
            </div>

            <!-- Active Bonuses -->
            <div class="mb-8">
                <h3 class="text-xl font-bold mb-4">Активные бонусы</h3>
                <div class="space-y-4">
                    <div class="bg-accent/20 rounded-lg p-4">
                        <div class="flex items-center justify-between mb-2">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-warning/20 flex items-center justify-center text-xl">
                                    🎲
                                </div>
                                <div>
                                    <div class="font-medium">Free Spins</div>
                                    <div class="text-sm text-gray-400">50 бесплатных вращений</div>
                                </div>
                            </div>
                            <div class="text-sm text-warning">23:45:12</div>
                        </div>
                        <div class="w-full h-2 bg-accent/30 rounded-full overflow-hidden">
                            <div class="h-full bg-warning" style="width: 65%"></div>
                        </div>
                    </div>
                    <div class="bg-accent/20 rounded-lg p-4">
                        <div class="flex items-center justify-between mb-2">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center text-xl">
                                    💰
                                </div>
                                <div>
                                    <div class="font-medium">Cashback</div>
                                    <div class="text-sm text-gray-400">10% на все игры</div>
                                </div>
                            </div>
                            <div class="text-sm text-warning">47:12:33</div>
                        </div>
                        <div class="w-full h-2 bg-accent/30 rounded-full overflow-hidden">
                            <div class="h-full bg-primary" style="width: 85%"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Available Bonuses -->
            <div>
                <h3 class="text-xl font-bold mb-4">Доступные бонусы</h3>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <!-- Welcome Bonus -->
                    <div class="bonus-card glass-effect rounded-xl p-6 relative overflow-hidden group">
                        <div class="relative z-10">
                            <div class="text-2xl mb-2">🎁</div>
                            <h4 class="text-lg font-bold mb-2">Приветственный бонус</h4>
                            <div class="text-sm text-gray-400 mb-4">100% до $500 + 100 Free Spins</div>
                            <button class="w-full bg-primary hover:bg-primary-hover transition-all py-2 rounded-lg font-medium"
                                    onclick="claimBonus('welcome')">
                                Активировать
                            </button>
                        </div>
                        <div class="absolute inset-0 bg-gradient-to-r from-primary/20 to-warning/20 opacity-0 group-hover:opacity-100 transition-opacity"></div>
                    </div>

                    <!-- Reload Bonus -->
                    <div class="bonus-card glass-effect rounded-xl p-6 relative overflow-hidden group">
                        <div class="relative z-10">
                            <div class="text-2xl mb-2">💎</div>
                            <h4 class="text-lg font-bold mb-2">Релоад бонус</h4>
                            <div class="text-sm text-gray-400 mb-4">50% до $200 каждую пятницу</div>
                            <button class="w-full bg-primary hover:bg-primary-hover transition-all py-2 rounded-lg font-medium"
                                    onclick="claimBonus('reload')">
                                Активировать
                            </button>
                        </div>
                        <div class="absolute inset-0 bg-gradient-to-r from-primary/20 to-warning/20 opacity-0 group-hover:opacity-100 transition-opacity"></div>
                    </div>
                </div>
            </div>

            <!-- VIP Progress -->
            <div class="mt-8">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-xl font-bold">VIP Статус</h3>
                    <div class="text-sm text-warning">Silver</div>
                </div>
                <div class="relative mb-8">
                    <div class="w-full h-2 bg-accent/30 rounded-full overflow-hidden">
                        <div class="h-full bg-warning" style="width: 45%"></div>
                    </div>
                    <div class="absolute top-full left-0 right-0 mt-2 flex justify-between text-xs text-gray-400">
                        <span>0 SP</span>
                        <span>500 SP</span>
                        <span>1000 SP</span>
                    </div>
                </div>
                <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
                    <div class="vip-perk p-4 bg-accent/20 rounded-lg text-center">
                        <div class="text-2xl mb-2">🎯</div>
                        <div class="font-medium">Кешбэк</div>
                        <div class="text-sm text-warning">5%</div>
                    </div>
                    <div class="vip-perk p-4 bg-accent/20 rounded-lg text-center">
                        <div class="text-2xl mb-2">💰</div>
                        <div class="font-medium">Вывод</div>
                        <div class="text-sm text-warning">12 часов</div>
                    </div>
                    <div class="vip-perk p-4 bg-accent/20 rounded-lg text-center">
                        <div class="text-2xl mb-2">🎲</div>
                        <div class="font-medium">Free Spins</div>
                        <div class="text-sm text-warning">50/нед</div>
                    </div>
                    <div class="vip-perk p-4 bg-accent/20 rounded-lg text-center">
                        <div class="text-2xl mb-2">💎</div>
                        <div class="font-medium">Релоад</div>
                        <div class="text-sm text-warning">50%</div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Rewards System
            class RewardsSystem {
                static dailyRewards = [
                    { day: 1, reward: '💰', description: '$5 Bonus', claimed: true },
                    { day: 2, reward: '🎲', description: '10 Free Spins', claimed: true },
                    { day: 3, reward: '💰', description: '$10 Bonus', claimed: true },
                    { day: 4, reward: '🎲', description: '20 Free Spins', claimed: true },
                    { day: 5, reward: '💎', description: '50 Free Spins', claimed: false },
                    { day: 6, reward: '💰', description: '$25 Bonus', claimed: false },
                    { day: 7, reward: '🏆', description: '$50 + 100 FS', claimed: false }
                ];

                static activeBonus = {
                    freeSpins: { amount: 50, expires: new Date(Date.now() + 86400000) },
                    cashback: { amount: 10, expires: new Date(Date.now() + 172800000) }
                };

                static vipStatus = {
                    level: 'Silver',
                    points: 450,
                    nextLevel: 1000,
                    perks: {
                        cashback: 5,
                        withdrawal: 12,
                        freeSpins: 50,
                        reload: 50
                    }
                };

                static initialize() {
                    this.updateDailyRewards();
                    this.updateActiveBonuses();
                    this.updateVIPProgress();
                    this.startBonusTimers();
                }

                static updateDailyRewards() {
                    // Update daily rewards display
                }

                static updateActiveBonuses() {
                    // Update active bonuses timers and progress
                    this.startBonusTimers();
                }

                static updateVIPProgress() {
                    // Update VIP progress and perks
                }

                static startBonusTimers() {
                    setInterval(() => {
                        // Update countdown timers for active bonuses
                    }, 1000);
                }

                static claimDailyReward() {
                    const currentDay = this.dailyRewards.findIndex(r => !r.claimed);
                    if (currentDay === -1) return;

                    const reward = this.dailyRewards[currentDay];
                    reward.claimed = true;
                    this.updateDailyRewards();
                    
                    // Add reward to player's account
                    this.processReward(reward);
                }

                static processReward(reward) {
                    // Process different types of rewards
                    switch (reward.type) {
                        case 'cash':
                            PaymentSystem.addFunds(reward.amount, 'Daily Reward');
                            break;
                        case 'freeSpins':
                            this.addFreeSpins(reward.amount);
                            break;
                        // Add other reward types
                    }

                    NotificationSystem.show(`Получена награда: ${reward.description}`, 'success');
                }

                static addFreeSpins(amount) {
                    // Add free spins to player's account
                }

                static claimBonus(bonusType) {
                    switch (bonusType) {
                        case 'welcome':
                            this.claimWelcomeBonus();
                            break;
                        case 'reload':
                            this.claimReloadBonus();
                            break;
                        // Add other bonus types
                    }
                }

                static claimWelcomeBonus() {
                    // Process welcome bonus
                    NotificationSystem.show('Приветственный бонус активирован!', 'success');
                }

                static claimReloadBonus() {
                    // Process reload bonus
                    NotificationSystem.show('Релоад бонус активирован!', 'success');
                }
            }

            // Initialize Rewards System
            document.addEventListener('DOMContentLoaded', () => {
                RewardsSystem.initialize();
            });

            // Helper Functions
            function claimBonus(type) {
                RewardsSystem.claimBonus(type);
            }
        </script>
        <!-- Social Hub Panel -->
        <div id="socialHub" class="glass-effect rounded-xl p-6 hidden">
            <!-- Friends List -->
            <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                <div class="lg:col-span-1">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-xl font-bold">Друзья</h3>
                        <div class="text-sm text-success">12 онлайн</div>
                    </div>
                    
                    <!-- Friends Search -->
                    <div class="relative mb-4">
                        <input type="text" 
                               class="w-full bg-accent/30 rounded-lg pl-10 pr-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary"
                               placeholder="Поиск друзей...">
                        <svg class="w-5 h-5 absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                        </svg>
                    </div>

                    <!-- Friends List -->
                    <div class="space-y-2 max-h-[500px] overflow-y-auto custom-scrollbar">
                        <template x-for="friend in friends">
                            <div class="friend-card bg-accent/20 rounded-lg p-3 flex items-center justify-between group hover:bg-accent/30 transition-colors cursor-pointer"
                                 @click="selectFriend(friend)">
                                <div class="flex items-center space-x-3">
                                    <div class="relative">
                                        <div class="w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center">
                                            <span x-text="friend.name.charAt(0)"></span>
                                        </div>
                                        <div class="absolute -bottom-1 -right-1 w-3 h-3 rounded-full"
                                             :class="friend.online ? 'bg-success' : 'bg-gray-400'"></div>
                                    </div>
                                    <div>
                                        <div class="font-medium" x-text="friend.name"></div>
                                        <div class="text-xs text-gray-400" x-text="friend.status"></div>
                                    </div>
                                </div>
                                <div class="opacity-0 group-hover:opacity-100 transition-opacity">
                                    <button class="p-2 hover:bg-accent/50 rounded-lg transition-colors">
                                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                        </svg>
                                    </button>
                                </div>
                            </div>
                        </template>
                    </div>
                </div>

                <!-- Social Feed -->
                <div class="lg:col-span-2">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-xl font-bold">Лента активности</h3>
                        <button class="p-2 hover:bg-accent/30 rounded-lg transition-colors"
                                @click="refreshFeed">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
                            </svg>
                        </button>
                    </div>

                    <!-- Post Creation -->
                    <div class="bg-accent/20 rounded-lg p-4 mb-4">
                        <div class="flex items-start space-x-4">
                            <div class="w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center">
                                <span>Y</span>
                            </div>
                            <div class="flex-1">
                                <textarea class="w-full bg-accent/30 rounded-lg px-4 py-2 min-h-[100px] focus:outline-none focus:ring-2 focus:ring-primary resize-none"
                                          placeholder="Что нового?"></textarea>
                                <div class="flex items-center justify-between mt-4">
                                    <div class="flex space-x-2">
                                        <button class="p-2 hover:bg-accent/30 rounded-lg transition-colors">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                            </svg>
                                        </button>
                                        <button class="p-2 hover:bg-accent/30 rounded-lg transition-colors">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                            </svg>
                                        </button>
                                    </div>
                                    <button class="bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg font-medium"
                                            @click="createPost">
                                        Опубликовать
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Feed Posts -->
                    <div class="space-y-4">
                        <template x-for="post in socialFeed">
                            <div class="post-card bg-accent/20 rounded-lg p-4">
                                <div class="flex items-start space-x-4">
                                    <div class="w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center">
                                        <span x-text="post.author.charAt(0)"></span>
                                    </div>
                                    <div class="flex-1">
                                        <div class="flex items-center justify-between mb-2">
                                            <div>
                                                <span class="font-medium" x-text="post.author"></span>
                                                <span class="text-sm text-gray-400 ml-2" x-text="post.time"></span>
                                            </div>
                                            <button class="p-2 hover:bg-accent/30 rounded-lg transition-colors">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"/>
                                                </svg>
                                            </button>
                                        </div>
                                        <div class="mb-4" x-text="post.content"></div>
                                        <template x-if="post.image">
                                            <div class="mb-4">
                                                <img :src="post.image" class="rounded-lg w-full">
                                            </div>
                                        </template>
                                        <div class="flex items-center space-x-4">
                                            <button class="flex items-center space-x-2 text-sm hover:text-primary transition-colors">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"/>
                                                </svg>
                                                <span x-text="post.likes"></span>
                                            </button>
                                            <button class="flex items-center space-x-2 text-sm hover:text-primary transition-colors">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
                                                </svg>
                                                <span x-text="post.comments"></span>
                                            </button>
                                            <button class="flex items-center space-x-2 text-sm hover:text-primary transition-colors">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"/>
                                                </svg>
                                                <span x-text="post.shares"></span>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Social System
            class SocialSystem {
                static friends = [];
                static socialFeed = [];
                static selectedFriend = null;

                static initialize() {
                    this.loadDemoData();
                    this.updateFriendsList();
                    this.updateSocialFeed();
                }

                static loadDemoData() {
                    this.friends = [
                        { id: 1, name: 'John Doe', status: 'Playing Cosmic Slot', online: true },
                        { id: 2, name: 'Jane Smith', status: 'Just won $500!', online: true },
                        { id: 3, name: 'Mike Johnson', status: 'Last seen 2h ago', online: false }
                    ];

                    this.socialFeed = [
                        {
                            id: 1,
                            author: 'John Doe',
                            content: 'Just hit the jackpot! 🎰💰',
                            time: '5 min ago',
                            likes: 12,
                            comments: 3,
                            shares: 1
                        },
                        {
                            id: 2,
                            author: 'Jane Smith',
                            content: 'New personal record in Cosmic Race! 🏎️',
                            time: '15 min ago',
                            likes: 8,
                            comments: 2,
                            shares: 0
                        }
                    ];
                }

                static updateFriendsList() {
                    // Update friends list display
                }

                static updateSocialFeed() {
                    // Update social feed display
                }

                static selectFriend(friend) {
                    this.selectedFriend = friend;
                    // Update UI accordingly
                }

                static createPost(content) {
                    const newPost = {
                        id: this.socialFeed.length + 1,
                        author: 'You',
                        content: content,
                        time: 'Just now',
                        likes: 0,
                        comments: 0,
                        shares: 0
                    };

                    this.socialFeed.unshift(newPost);
                    this.updateSocialFeed();
                    NotificationSystem.show('Пост опубликован!', 'success');
                }

                static likePost(postId) {
                    const post = this.socialFeed.find(p => p.id === postId);
                    if (post) {
                        post.likes++;
                        this.updateSocialFeed();
                    }
                }

                static addFriend(userId) {
                    // Add friend logic
                    NotificationSystem.show('Запрос дружбы отправлен!', 'success');
                }
            }

            // Initialize Social System
            document.addEventListener('DOMContentLoaded', () => {
                SocialSystem.initialize();
            });
        </script>
        <!-- Game Modes Panel -->
        <div id="gameModes" class="glass-effect rounded-xl p-6 hidden">
            <!-- Featured Mode -->
            <div class="featured-mode mb-8">
                <div class="relative rounded-xl overflow-hidden">
                    <div class="absolute inset-0 bg-gradient-to-r from-primary to-warning opacity-20 animate-pulse"></div>
                    <div class="relative p-6">
                        <div class="flex items-start justify-between">
                            <div>
                                <div class="text-sm text-warning mb-2">Специальный режим</div>
                                <h3 class="text-2xl font-bold mb-2">Космическая гонка</h3>
                                <p class="text-gray-400 mb-4">Соревнуйтесь с другими игроками в реальном времени!</p>
                                <div class="flex items-center space-x-4">
                                    <button class="bg-primary hover:bg-primary-hover transition-all px-6 py-2 rounded-lg font-medium"
                                            onclick="joinGameMode('race')">
                                        Играть
                                    </button>
                                    <div class="text-sm text-gray-400">
                                        <span class="text-success">1,234</span> игроков онлайн
                                    </div>
                                </div>
                            </div>
                            <div class="text-6xl">🏎️</div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Game Modes Grid -->
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- Classic Mode -->
                <div class="game-mode-card glass-effect rounded-xl p-6 transform hover:scale-105 transition-all cursor-pointer"
                     onclick="selectGameMode('classic')">
                    <div class="text-4xl mb-4">🎰</div>
                    <h4 class="text-lg font-bold mb-2">Классический</h4>
                    <p class="text-sm text-gray-400 mb-4">Традиционный режим игры</p>
                    <div class="flex items-center justify-between">
                        <div class="text-sm text-success">Доступно</div>
                        <div class="text-sm text-gray-400">
                            <span class="text-warning">789</span> онлайн
                        </div>
                    </div>
                </div>

                <!-- Tournament Mode -->
                <div class="game-mode-card glass-effect rounded-xl p-6 transform hover:scale-105 transition-all cursor-pointer"
                     onclick="selectGameMode('tournament')">
                    <div class="text-4xl mb-4">🏆</div>
                    <h4 class="text-lg font-bold mb-2">Турнир</h4>
                    <p class="text-sm text-gray-400 mb-4">Соревнуйтесь за крупные призы</p>
                    <div class="flex items-center justify-between">
                        <div class="text-sm text-success">Доступно</div>
                        <div class="text-sm text-gray-400">
                            <span class="text-warning">456</span> онлайн
                        </div>
                    </div>
                </div>

                <!-- Practice Mode -->
                <div class="game-mode-card glass-effect rounded-xl p-6 transform hover:scale-105 transition-all cursor-pointer"
                     onclick="selectGameMode('practice')">
                    <div class="text-4xl mb-4">🎮</div>
                    <h4 class="text-lg font-bold mb-2">Практика</h4>
                    <p class="text-sm text-gray-400 mb-4">Игра на виртуальные монеты</p>
                    <div class="flex items-center justify-between">
                        <div class="text-sm text-success">Доступно</div>
                        <div class="text-sm text-gray-400">
                            <span class="text-warning">234</span> онлайн
                        </div>
                    </div>
                </div>
            </div>

            <!-- Active Game Sessions -->
            <div class="mt-8">
                <h3 class="text-xl font-bold mb-4">Активные сессии</h3>
                <div class="space-y-4">
                    <div class="session-card bg-accent/20 rounded-lg p-4">
                        <div class="flex items-center justify-between">
                            <div class="flex items-center space-x-4">
                                <div class="w-12 h-12 rounded-lg bg-primary/20 flex items-center justify-center text-2xl">
                                    🏎️
                                </div>
                                <div>
                                    <div class="font-medium">Космическая гонка</div>
                                    <div class="text-sm text-gray-400">Турнир #12345</div>
                                </div>
                            </div>
                            <button class="bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg font-medium"
                                    onclick="resumeGame('race_12345')">
                                Продолжить
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Game Modes System
            class GameModesSystem {
                static activeModes = {
                    classic: { players: 789, status: 'available' },
                    tournament: { players: 456, status: 'available' },
                    practice: { players: 234, status: 'available' },
                    race: { players: 1234, status: 'featured' }
                };

                static activeSession = null;
                static gameHistory = [];

                static initialize() {
                    this.updateGameModes();
                    this.startPlayerCountUpdates();
                }

                static updateGameModes() {
                    // Update game modes display and statistics
                }

                static startPlayerCountUpdates() {
                    setInterval(() => {
                        // Simulate real-time player count updates
                        Object.keys(this.activeModes).forEach(mode => {
                            const variation = Math.floor(Math.random() * 21) - 10;
                            this.activeModes[mode].players = Math.max(0, this.activeModes[mode].players + variation);
                        });
                        this.updateGameModes();
                    }, 5000);
                }

                static selectGameMode(mode) {
                    if (this.activeModes[mode].status === 'maintenance') {
                        NotificationSystem.show('Режим временно недоступен', 'error');
                        return;
                    }

                    // Show game mode details and options
                    this.showGameModeDetails(mode);
                }

                static showGameModeDetails(mode) {
                    // Implement mode-specific UI and options
                    ModalSystem.show(`${mode}DetailsModal`);
                }

                static joinGameMode(mode) {
                    // Check requirements and start game session
                    if (this.checkRequirements(mode)) {
                        this.startGameSession(mode);
                    }
                }

                static checkRequirements(mode) {
                    switch (mode) {
                        case 'tournament':
                            return PaymentSystem.checkBalance(50);
                        case 'race':
                            return true;
                        default:
                            return true;
                    }
                }

                static startGameSession(mode) {
                    this.activeSession = {
                        mode: mode,
                        id: `${mode}_${Date.now()}`,
                        startTime: new Date()
                    };

                    // Start game-specific logic
                    switch (mode) {
                        case 'race':
                            this.startRaceMode();
                            break;
                        case 'tournament':
                            this.startTournamentMode();
                            break;
                        default:
                            this.startClassicMode();
                    }
                }

                static startRaceMode() {
                    // Initialize race mode
                    AnimationSystem.playTransition('race');
                    // Additional race mode logic
                }

                static startTournamentMode() {
                    // Initialize tournament mode
                    AnimationSystem.playTransition('tournament');
                    // Additional tournament mode logic
                }

                static startClassicMode() {
                    // Initialize classic mode
                    AnimationSystem.playTransition('classic');
                    // Additional classic mode logic
                }

                static resumeGame(sessionId) {
                    // Resume previous game session
                    const session = this.gameHistory.find(s => s.id === sessionId);
                    if (session) {
                        this.activeSession = session;
                        this.startGameSession(session.mode);
                    }
                }
            }

            // Animation System
            class AnimationSystem {
                static transitions = {
                    race: {
                        duration: 1000,
                        easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
                        elements: [
                            { selector: '.game-container', properties: { scale: [0.95, 1], opacity: [0, 1] } },
                            { selector: '.ui-overlay', properties: { translateY: [20, 0], opacity: [0, 1] } }
                        ]
                    },
                    tournament: {
                        duration: 800,
                        easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
                        elements: [
                            { selector: '.game-container', properties: { rotate: [-5, 0], opacity: [0, 1] } }
                        ]
                    }
                };

                static playTransition(type) {
                    const transition = this.transitions[type];
                    if (!transition) return;

                    transition.elements.forEach(element => {
                        const el = document.querySelector(element.selector);
                        if (!el) return;

                        Object.entries(element.properties).forEach(([property, values]) => {
                            el.animate(
                                { [property]: values },
                                { 
                                    duration: transition.duration,
                                    easing: transition.easing,
                                    fill: 'forwards'
                                }
                            );
                        });
                    });
                }
            }

            // Initialize Systems
            document.addEventListener('DOMContentLoaded', () => {
                GameModesSystem.initialize();
            });

            // Helper Functions
            function selectGameMode(mode) {
                GameModesSystem.selectGameMode(mode);
            }

            function joinGameMode(mode) {
                GameModesSystem.joinGameMode(mode);
            }

            function resumeGame(sessionId) {
                GameModesSystem.resumeGame(sessionId);
            }
        </script>
        <!-- System Integration Layer -->
        <script>
            // Core System Integration
            class GameSystem {
                static instances = new Map();
                static eventBus = new EventTarget();
                static isInitialized = false;

                static async initialize() {
                    if (this.isInitialized) return;
                    
                    try {
                        // Initialize core systems
                        await this.initializeCore();
                        // Initialize game systems
                        await this.initializeGameSystems();
                        // Initialize UI systems
                        await this.initializeUI();
                        
                        this.isInitialized = true;
                        this.emit('system:ready');
                        
                        // Start performance monitoring
                        PerformanceMonitor.start();
                        
                    } catch (error) {
                        console.error('System initialization failed:', error);
                        NotificationSystem.show('Ошибка инициализации системы', 'error');
                    }
                }

                static async initializeCore() {
                    // Initialize core dependencies
                    await Promise.all([
                        this.register('cache', new CacheSystem()),
                        this.register('storage', new StorageSystem()),
                        this.register('network', new NetworkSystem()),
                        this.register('auth', new AuthSystem())
                    ]);
                }

                static async initializeGameSystems() {
                    // Initialize game-specific systems
                    await Promise.all([
                        this.register('payment', new PaymentSystem()),
                        this.register('rewards', new RewardsSystem()),
                        this.register('social', new SocialSystem()),
                        this.register('gameModes', new GameModesSystem())
                    ]);
                }

                static async initializeUI() {
                    // Initialize UI systems
                    await Promise.all([
                        this.register('ui', new UISystem()),
                        this.register('animation', new AnimationSystem()),
                        this.register('notification', new NotificationSystem())
                    ]);
                }

                static register(name, instance) {
                    if (this.instances.has(name)) {
                        throw new Error(`System "${name}" is already registered`);
                    }
                    this.instances.set(name, instance);
                    return instance.initialize?.();
                }

                static get(name) {
                    if (!this.instances.has(name)) {
                        throw new Error(`System "${name}" not found`);
                    }
                    return this.instances.get(name);
                }

                static emit(event, detail = {}) {
                    this.eventBus.dispatchEvent(new CustomEvent(event, { detail }));
                }

                static on(event, callback) {
                    this.eventBus.addEventListener(event, callback);
                }

                static off(event, callback) {
                    this.eventBus.removeEventListener(event, callback);
                }
            }

            // Performance Monitoring
            class PerformanceMonitor {
                static metrics = {
                    fps: [],
                    memory: [],
                    network: [],
                    events: []
                };

                static start() {
                    this.startFPSMonitoring();
                    this.startMemoryMonitoring();
                    this.startNetworkMonitoring();
                    this.startEventMonitoring();
                }

                static startFPSMonitoring() {
                    let lastTime = performance.now();
                    let frames = 0;

                    const measure = () => {
                        const currentTime = performance.now();
                        frames++;

                        if (currentTime >= lastTime + 1000) {
                            const fps = Math.round((frames * 1000) / (currentTime - lastTime));
                            this.metrics.fps.push({ time: Date.now(), value: fps });
                            this.metrics.fps = this.metrics.fps.slice(-60); // Keep last minute

                            frames = 0;
                            lastTime = currentTime;

                            if (fps < 30) {
                                this.optimizePerformance();
                            }
                        }

                        requestAnimationFrame(measure);
                    };

                    requestAnimationFrame(measure);
                }

                static startMemoryMonitoring() {
                    setInterval(() => {
                        if (performance.memory) {
                            const used = performance.memory.usedJSHeapSize / 1048576; // Convert to MB
                            this.metrics.memory.push({ time: Date.now(), value: used });
                            this.metrics.memory = this.metrics.memory.slice(-60);

                            if (used > 100) { // If using more than 100MB
                                this.cleanupMemory();
                            }
                        }
                    }, 1000);
                }

                static startNetworkMonitoring() {
                    // Monitor network requests
                    const originalFetch = window.fetch;
                    window.fetch = async (...args) => {
                        const startTime = performance.now();
                        try {
                            const response = await originalFetch(...args);
                            const endTime = performance.now();
                            this.metrics.network.push({
                                time: Date.now(),
                                duration: endTime - startTime,
                                url: args[0]
                            });
                            return response;
                        } catch (error) {
                            const endTime = performance.now();
                            this.metrics.network.push({
                                time: Date.now(),
                                duration: endTime - startTime,
                                url: args[0],
                                error: true
                            });
                            throw error;
                        }
                    };
                }

                static startEventMonitoring() {
                    const observer = new PerformanceObserver((list) => {
                        for (const entry of list.getEntries()) {
                            if (entry.entryType === 'event') {
                                this.metrics.events.push({
                                    time: Date.now(),
                                    name: entry.name,
                                    duration: entry.duration
                                });
                            }
                        }
                    });

                    observer.observe({ entryTypes: ['event'] });
                }

                static optimizePerformance() {
                    // Reduce visual effects
                    document.body.classList.add('reduce-animations');
                    
                    // Reduce particle effects
                    GameSystem.get('animation').reduceEffects();
                    
                    // Optimize rendering
                    this.optimizeRendering();
                }

                static optimizeRendering() {
                    // Use passive event listeners
                    const options = {
                        passive: true,
                        capture: false
                    };

                    window.addEventListener('scroll', this.throttle(() => {
                        // Handle scroll events
                    }, 100), options);

                    window.addEventListener('resize', this.throttle(() => {
                        // Handle resize events
                    }, 100), options);
                }

                static cleanupMemory() {
                    // Clear cached data
                    GameSystem.get('cache').cleanup();
                    
                    // Clear old metrics
                    Object.keys(this.metrics).forEach(key => {
                        this.metrics[key] = this.metrics[key].slice(-30);
                    });
                    
                    // Force garbage collection if possible
                    if (window.gc) {
                        window.gc();
                    }
                }

                static throttle(func, limit) {
                    let inThrottle;
                    return function(...args) {
                        if (!inThrottle) {
                            func.apply(this, args);
                            inThrottle = true;
                            setTimeout(() => inThrottle = false, limit);
                        }
                    }
                }

                static getMetrics() {
                    return {
                        fps: this.getAverageMetric(this.metrics.fps),
                        memory: this.getAverageMetric(this.metrics.memory),
                        network: this.getAverageNetworkMetrics(),
                        events: this.metrics.events.length
                    };
                }

                static getAverageMetric(metrics) {
                    if (!metrics.length) return 0;
                    return metrics.reduce((sum, m) => sum + m.value, 0) / metrics.length;
                }

                static getAverageNetworkMetrics() {
                    if (!this.metrics.network.length) return { avgDuration: 0, errorRate: 0 };
                    
                    const total = this.metrics.network.length;
                    const errors = this.metrics.network.filter(m => m.error).length;
                    const avgDuration = this.metrics.network.reduce((sum, m) => sum + m.duration, 0) / total;
                    
                    return {
                        avgDuration,
                        errorRate: (errors / total) * 100
                    };
                }
            }

            // Initialize the game system when the document is ready
            document.addEventListener('DOMContentLoaded', () => {
                GameSystem.initialize().then(() => {
                    console.log('Game system initialized successfully');
                }).catch(error => {
                    console.error('Failed to initialize game system:', error);
                });
            });
        </script>
        <!-- Error Boundary -->
        <div id="errorBoundary" class="fixed inset-0 bg-black/90 backdrop-blur-lg hidden flex-col items-center justify-center z-50">
            <div class="text-6xl mb-4">⚠️</div>
            <h2 class="text-2xl font-bold mb-4">Упс! Что-то пошло не так</h2>
            <p class="text-gray-400 mb-6 text-center max-w-md">Произошла непредвиденная ошибка. Мы уже работаем над её устранением.</p>
            <div class="space-x-4">
                <button class="bg-primary hover:bg-primary-hover transition-all px-6 py-3 rounded-lg font-medium"
                        onclick="ErrorHandler.reloadApp()">
                    Перезапустить
                </button>
                <button class="bg-accent/30 hover:bg-accent/50 transition-all px-6 py-3 rounded-lg font-medium"
                        onclick="ErrorHandler.reportIssue()">
                    Сообщить об ошибке
                </button>
            </div>
        </div>

        <script>
            // Error Handling System
            class ErrorHandler {
                static errors = [];
                static maxErrors = 100;
                static criticalErrorCount = 0;
                static isRecovering = false;

                static initialize() {
                    this.setupGlobalHandlers();
                    this.setupNetworkErrorHandling();
                    this.setupPromiseErrorHandling();
                    this.startErrorMonitoring();
                }

                static setupGlobalHandlers() {
                    window.onerror = (message, source, line, column, error) => {
                        this.handleError({
                            type: 'global',
                            message,
                            source,
                            line,
                            column,
                            stack: error?.stack,
                            timestamp: Date.now()
                        });
                        return false;
                    };

                    window.onunhandledrejection = (event) => {
                        this.handleError({
                            type: 'promise',
                            message: event.reason?.message || 'Unhandled Promise Rejection',
                            stack: event.reason?.stack,
                            timestamp: Date.now()
                        });
                    };
                }

                static setupNetworkErrorHandling() {
                    const originalFetch = window.fetch;
                    window.fetch = async (...args) => {
                        try {
                            const response = await originalFetch(...args);
                            if (!response.ok) {
                                throw new Error(`HTTP error! status: ${response.status}`);
                            }
                            return response;
                        } catch (error) {
                            this.handleError({
                                type: 'network',
                                url: args[0],
                                message: error.message,
                                timestamp: Date.now()
                            });
                            throw error;
                        }
                    };
                }

                static setupPromiseErrorHandling() {
                    window.addEventListener('unhandledrejection', (event) => {
                        this.handleError({
                            type: 'promise',
                            message: event.reason?.message || 'Unknown Promise Error',
                            stack: event.reason?.stack,
                            timestamp: Date.now()
                        });
                    });
                }

                static startErrorMonitoring() {
                    setInterval(() => {
                        if (this.errors.length > this.maxErrors) {
                            this.cleanupErrors();
                        }

                        if (this.criticalErrorCount > 5) {
                            this.attemptRecovery();
                        }
                    }, 5000);
                }

                static handleError(error) {
                    // Add context information
                    error.context = {
                        url: window.location.href,
                        userAgent: navigator.userAgent,
                        timestamp: Date.now(),
                        gameState: GameSystem.get('gameModes')?.activeSession,
                        performanceMetrics: PerformanceMonitor.getMetrics()
                    };

                    // Log error
                    this.errors.push(error);

                    // Check error severity
                    if (this.isCriticalError(error)) {
                        this.criticalErrorCount++;
                        this.handleCriticalError(error);
                    } else {
                        this.handleNonCriticalError(error);
                    }

                    // Report error
                    this.reportError(error);
                }

                static isCriticalError(error) {
                    return error.type === 'global' || 
                           (error.type === 'network' && error.message.includes('Failed to fetch')) ||
                           error.message.includes('Out of memory');
                }

                static handleCriticalError(error) {
                    if (this.isRecovering) return;

                    // Show error boundary
                    this.showErrorBoundary();

                    // Attempt recovery
                    this.attemptRecovery();

                    // Notify user
                    NotificationSystem.show('Произошла критическая ошибка', 'error');
                }

                static handleNonCriticalError(error) {
                    // Log warning
                    console.warn('Non-critical error:', error);

                    // Show user-friendly notification
                    NotificationSystem.show('Произошла ошибка. Мы уже работаем над её устранением', 'warning');
                }

                static attemptRecovery() {
                    if (this.isRecovering) return;
                    this.isRecovering = true;

                    try {
                        // Save current state
                        this.saveCurrentState();

                        // Clear caches
                        this.clearCaches();

                        // Reset systems
                        this.resetSystems();

                        // Reinitialize
                        GameSystem.initialize().then(() => {
                            this.isRecovering = false;
                            this.criticalErrorCount = 0;
                            this.hideErrorBoundary();
                        });
                    } catch (error) {
                        this.forceReload();
                    }
                }

                static saveCurrentState() {
                    try {
                        const state = {
                            timestamp: Date.now(),
                            gameState: GameSystem.get('gameModes')?.activeSession,
                            userState: GameSystem.get('auth')?.currentUser
                        };
                        localStorage.setItem('recovery_state', JSON.stringify(state));
                    } catch (error) {
                        console.error('Failed to save recovery state:', error);
                    }
                }

                static clearCaches() {
                    // Clear application cache
                    GameSystem.get('cache')?.clear();

                    // Clear local storage (except recovery state)
                    const recoveryState = localStorage.getItem('recovery_state');
                    localStorage.clear();
                    if (recoveryState) {
                        localStorage.setItem('recovery_state', recoveryState);
                    }
                }

                static resetSystems() {
                    GameSystem.instances.forEach(instance => {
                        instance.reset?.();
                    });
                }

                static showErrorBoundary() {
                    const errorBoundary = document.getElementById('errorBoundary');
                    if (errorBoundary) {
                        errorBoundary.style.display = 'flex';
                    }
                }

                static hideErrorBoundary() {
                    const errorBoundary = document.getElementById('errorBoundary');
                    if (errorBoundary) {
                        errorBoundary.style.display = 'none';
                    }
                }

                static async reportError(error) {
                    try {
                        // Prepare error report
                        const report = {
                            ...error,
                            sessionId: GameSystem.get('auth')?.sessionId,
                            timestamp: Date.now()
                        };

                        // Send to error reporting service
                        await fetch('/api/error-report', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify(report)
                        });
                    } catch (error) {
                        console.error('Failed to report error:', error);
                    }
                }

                static cleanupErrors() {
                    // Keep only recent and important errors
                    this.errors = this.errors
                        .filter(error => Date.now() - error.timestamp < 3600000) // Last hour
                        .slice(-this.maxErrors);
                }

                static forceReload() {
                    window.location.reload();
                }

                static reloadApp() {
                    this.forceReload();
                }

                static reportIssue() {
                    // Open issue reporter
                    ModalSystem.show('issueReporterModal');
                }

                static getErrorReport() {
                    return {
                        errors: this.errors,
                        criticalErrorCount: this.criticalErrorCount,
                        performanceMetrics: PerformanceMonitor.getMetrics(),
                        systemState: {
                            initialized: GameSystem.isInitialized,
                            activeSystems: Array.from(GameSystem.instances.keys())
                        }
                    };
                }
            }

            // Initialize Error Handler
            document.addEventListener('DOMContentLoaded', () => {
                ErrorHandler.initialize();
            });
        </script>
        <!-- Documentation Panel (Accessible only in development mode) -->
        <div id="devDocs" class="fixed inset-0 bg-black/90 backdrop-blur-lg hidden z-50 overflow-auto">
            <div class="container mx-auto p-6">
                <div class="flex justify-between items-center mb-8">
                    <h2 class="text-2xl font-bold">Документация разработчика</h2>
                    <button class="p-2 hover:bg-accent/30 rounded-lg" onclick="DevTools.toggleDocs()">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                        </svg>
                    </button>
                </div>

                <div class="grid grid-cols-1 lg:grid-cols-4 gap-6">
                    <!-- Navigation -->
                    <div class="lg:col-span-1">
                        <div class="space-y-2">
                            <button class="w-full text-left p-3 rounded-lg hover:bg-accent/30 transition-colors"
                                    onclick="DevTools.showSection('architecture')">
                                Архитектура
                            </button>
                            <button class="w-full text-left p-3 rounded-lg hover:bg-accent/30 transition-colors"
                                    onclick="DevTools.showSection('api')">
                                API Reference
                            </button>
                            <button class="w-full text-left p-3 rounded-lg hover:bg-accent/30 transition-colors"
                                    onclick="DevTools.showSection('components')">
                                Компоненты
                            </button>
                            <button class="w-full text-left p-3 rounded-lg hover:bg-accent/30 transition-colors"
                                    onclick="DevTools.showSection('testing')">
                                Тестирование
                            </button>
                        </div>
                    </div>

                    <!-- Content -->
                    <div class="lg:col-span-3">
                        <div id="docContent" class="space-y-6">
                            <!-- Dynamic content will be loaded here -->
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Development Tools and Documentation
            class DevTools {
                static isInitialized = false;
                static currentSection = null;
                static documentation = {};

                static initialize() {
                    if (this.isInitialized) return;

                    this.loadDocumentation();
                    this.setupTestEnvironment();
                    this.setupDevTools();

                    this.isInitialized = true;
                }

                static loadDocumentation() {
                    this.documentation = {
                        architecture: {
                            title: 'Архитектура приложения',
                            content: `
                                <h3 class="text-xl font-bold mb-4">Обзор архитектуры</h3>
                                <p class="mb-4">Приложение построено на модульной архитектуре с использованием следующих основных систем:</p>
                                <ul class="list-disc list-inside space-y-2 mb-6">
                                    <li>GameSystem - Ядро приложения</li>
                                    <li>UISystem - Управление интерфейсом</li>
                                    <li>AuthSystem - Аутентификация</li>
                                    <li>PaymentSystem - Платежная система</li>
                                </ul>

                                <h3 class="text-xl font-bold mb-4">Структура проекта</h3>
                                <pre class="bg-accent/20 p-4 rounded-lg overflow-auto">
└── src/
    ├── core/
    │   ├── GameSystem.js
    │   ├── ErrorHandler.js
    │   └── PerformanceMonitor.js
    ├── ui/
    │   ├── components/
    │   └── styles/
    ├── services/
    │   ├── AuthService.js
    │   └── PaymentService.js
    └── utils/
                                </pre>
                            `
                        },
                        api: {
                            title: 'API Reference',
                            content: `
                                <h3 class="text-xl font-bold mb-4">Core API</h3>
                                <div class="space-y-4">
                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">GameSystem.initialize()</h4>
                                        <p class="text-sm text-gray-400 mb-2">Инициализирует основные системы приложения</p>
                                        <pre class="bg-black/30 p-2 rounded">
await GameSystem.initialize();
                                        </pre>
                                    </div>

                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">GameSystem.emit(event, detail)</h4>
                                        <p class="text-sm text-gray-400 mb-2">Отправляет событие через систему событий</p>
                                        <pre class="bg-black/30 p-2 rounded">
GameSystem.emit('userAction', { type: 'click', target: 'button' });
                                        </pre>
                                    </div>
                                </div>
                            `
                        },
                        components: {
                            title: 'Компоненты UI',
                            content: `
                                <h3 class="text-xl font-bold mb-4">Доступные компоненты</h3>
                                <div class="grid grid-cols-2 gap-4 mb-6">
                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">Button</h4>
                                        <div class="space-y-2">
                                            <button class="bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg">
                                                Primary Button
                                            </button>
                                            <button class="bg-accent/30 hover:bg-accent/50 transition-all px-4 py-2 rounded-lg">
                                                Secondary Button
                                            </button>
                                        </div>
                                    </div>
                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">Input</h4>
                                        <input type="text" 
                                               class="w-full bg-accent/30 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary"
                                               placeholder="Sample Input">
                                    </div>
                                </div>
                            `
                        },
                        testing: {
                            title: 'Тестирование',
                            content: `
                                <h3 class="text-xl font-bold mb-4">Запуск тестов</h3>
                                <div class="space-y-4">
                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">Unit Tests</h4>
                                        <pre class="bg-black/30 p-2 rounded mb-2">npm run test:unit</pre>
                                        <button class="bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg"
                                                onclick="DevTools.runTests('unit')">
                                            Запустить Unit Tests
                                        </button>
                                    </div>

                                    <div class="bg-accent/20 p-4 rounded-lg">
                                        <h4 class="font-bold mb-2">Integration Tests</h4>
                                        <pre class="bg-black/30 p-2 rounded mb-2">npm run test:integration</pre>
                                        <button class="bg-primary hover:bg-primary-hover transition-all px-4 py-2 rounded-lg"
                                                onclick="DevTools.runTests('integration')">
                                            Запустить Integration Tests
                                        </button>
                                    </div>
                                </div>

                                <h3 class="text-xl font-bold my-4">Результаты тестов</h3>
                                <div id="testResults" class="bg-accent/20 p-4 rounded-lg">
                                    <div class="flex items-center justify-between mb-4">
                                        <div>Всего тестов: <span class="text-success">142</span></div>
                                        <div>Пройдено: <span class="text-success">138</span></div>
                                        <div>Провалено: <span class="text-error">4</span></div>
                                    </div>
                                    <div class="w-full h-2 bg-accent/30 rounded-full overflow-hidden">
                                        <div class="h-full bg-success" style="width: 97%"></div>
                                    </div>
                                </div>
                            `
                        }
                    };
                }

                static setupTestEnvironment() {
                    this.tests = {
                        unit: [
                            { name: 'GameSystem', tests: [] },
                            { name: 'UISystem', tests: [] },
                            { name: 'PaymentSystem', tests: [] }
                        ],
                        integration: [
                            { name: 'User Flow', tests: [] },
                            { name: 'Payment Flow', tests: [] }
                        ]
                    };
                }

                static setupDevTools() {
                    if (process.env.NODE_ENV === 'development') {
                        window.devTools = {
                            GameSystem,
                            ErrorHandler,
                            PerformanceMonitor,
                            test: this.runTests.bind(this)
                        };
                    }
                }

                static toggleDocs() {
                    const docs = document.getElementById('devDocs');
                    if (docs) {
                        docs.style.display = docs.style.display === 'none' ? 'block' : 'none';
                    }
                }

                static showSection(section) {
                    this.currentSection = section;
                    const content = document.getElementById('docContent');
                    if (content && this.documentation[section]) {
                        content.innerHTML = this.documentation[section].content;
                    }
                }

                static async runTests(type) {
                    try {
                        const results = await TestRunner.run(type);
                        this.updateTestResults(results);
                    } catch (error) {
                        console.error('Test execution failed:', error);
                        NotificationSystem.show('Ошибка выполнения тестов', 'error');
                    }
                }

                static updateTestResults(results) {
                    const resultsDiv = document.getElementById('testResults');
                    if (resultsDiv) {
                        // Update test results UI
                    }
                }
            }

            // Initialize DevTools in development mode
            if (process.env.NODE_ENV === 'development') {
                document.addEventListener('DOMContentLoaded', () => {
                    DevTools.initialize();
                });
            }
        </script>
        </body></html>