<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Рандомайзер намоток</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vanta/0.5.21/vanta.clouds.min.js"></script>
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2ecc71;
            --error-color: #e74c3c;
            --bg-color: rgba(255, 255, 255, 0.9);
            --text-color: #333;
            --highlight-color: #e8f4fc;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Roboto', sans-serif;
            color: var(--text-color);
            position: relative;
            min-height: 100vh;
            overflow-x: hidden;
        }
        
        #vanta-bg {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
        }
        
        .content {
            position: relative;
            z-index: 1;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: var(--bg-color);
            margin-top: 20px;
            margin-bottom: 20px;
        }
        
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }
        
        .dice-container {
            display: inline-block;
            margin-right: 10px;
        }
        
        .dice {
            display: inline-block;
            font-size: 1.2em;
            transition: transform 0.3s;
        }
        
        .rotating {
            animation: dice-rotate 1s linear infinite;
        }
        
        @keyframes dice-rotate {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .groups {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            justify-content: center;
        }
        
        .group {
            flex: 1;
            min-width: 300px;
            background-color: rgba(255, 255, 255, 0.8);
            padding: 15px;
            border-radius: 8px;
        }
        
        .person {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 5px;
            border-bottom: 1px dotted #eee;
        }
        
        .counter {
            background: var(--secondary-color);
            color: white;
            padding: 2px 8px;
            border-radius: 10px;
            font-size: 0.85em;
            min-width: 20px;
            text-align: center;
        }
        
        .controls {
            display: flex;
            justify-content: center;
            gap: 10px;
            flex-wrap: wrap;
            margin: 20px 0;
        }
        
        button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: transform 0.2s;
        }
        
        button:hover:not(:disabled) {
            transform: translateY(-2px);
        }
        
        button:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }
        
        .result {
            background-color: rgba(255, 255, 255, 0.8);
            padding: 20px;
            border-radius: 8px;
            text-align: center;
            font-size: 1.2em;
            font-weight: bold;
            margin: 20px 0;
            min-height: 60px;
        }
        
        .stats-container {
            background-color: rgba(255, 255, 255, 0.8);
            padding: 20px;
            border-radius: 8px;
            margin-top: 20px;
        }
        
        .stats-container h2 {
            margin-top: 0;
            color: var(--primary-color);
            border-bottom: 2px solid #eee;
            padding-bottom: 10px;
            margin-bottom: 15px;
        }
        
        .stat-item {
            display: flex;
            justify-content: space-between;
            padding: 8px 0;
            border-bottom: 1px dotted #eee;
        }
        
        .highlight {
            background-color: var(--highlight-color);
            font-weight: bold;
        }
        
        @keyframes glow {
            0% { box-shadow: 0 0 5px #ff0000; }
            50% { box-shadow: 0 0 20px #ff0000; }
            100% { box-shadow: 0 0 5px #ff0000; }
        }
        
        .glow-effect {
            animation: glow 1s infinite;
        }
        
        .progress-bar {
            height: 5px;
            background-color: #e0e0e0;
            border-radius: 3px;
            margin-top: 10px;
            overflow: hidden;
        }
        
        .progress {
            height: 100%;
            background-color: var(--primary-color);
            width: 0%;
            transition: width 0.1s linear;
        }
    </style>
</head>
<body>
    <div id="vanta-bg"></div>
    <div class="content">
        <h1>
            <span class="dice-container">
                <span class="dice">🎲</span>
            </span>
            Рандомайзер намоток
        </h1>
        
        <div class="groups">
            <div class="group" id="senior-group">
                <h2>👨‍✈️ Старший призыв</h2>
                <div id="senior-list"></div>
            </div>
            
            <div class="group" id="junior-group">
                <h2>👶 Младший призыв</h2>
                <div id="junior-list"></div>
            </div>
        </div>
        
        <div class="result" id="result">Нажмите кнопку "Выбрать случайного"</div>
        
        <div class="progress-bar">
            <div class="progress" id="progress"></div>
        </div>
        
        <div class="controls">
            <button id="random-btn">🎲 Выбрать</button>
            <button id="reset-btn">🔄 Сбросить</button>
            <button id="export-btn">💾 Экспорт</button>
            <button id="import-btn">📂 Импорт</button>
        </div>
        
        <div class="stats-container">
            <h2>📊 Статистика выборов</h2>
            <div id="stats-list"></div>
        </div>
    </div>

    <script>
        class Randomizer {
            constructor() {
                this.people = {
                    senior: ["Артем Ш.", "Артем В.", "Олег Щ.", "Дима Г.", "Никита Л.", 
                            "Максим С.", "Леха Д.", "Антон К.", "Арыслан Х.", "Даня Ч."],
                    junior: ["Витя М.", "Андрей Л.", "Андрей Б.", "Серега Л.", "Дима З.", 
                            "Камиль Х.", "Гриша М.", "Валера Р.", "Влад Я.", "Вова К."]
                };
                
                this.stats = {};
                this.STORAGE_KEY = 'randomizer_stats_opt_v3';
                this.isSelecting = false;
                this.diceElement = document.querySelector('.dice');
                this.progressElement = document.getElementById('progress');
                this.selectDuration = 3000; // 3 секунды
                
                this.initBackground();
                this.initDOM();
                this.loadStats();
                this.bindEvents();
            }
            
            initBackground() {
                VANTA.CLOUDS({
                    el: "#vanta-bg",
                    mouseControls: true,
                    touchControls: true,
                    gyroControls: false,
                    skyColor: 0x0,
                    cloudColor: 0x4a6081,
                    cloudShadowColor: 0x506474,
                    sunColor: 0xc51f81,
                    speed: 0.2
                });
            }
            
            initDOM() {
                this.renderList('senior');
                this.renderList('junior');
                this.updateStatsList();
            }
            
            renderList(group) {
                const container = document.getElementById(`${group}-list`);
                container.innerHTML = this.people[group]
                    .map(name => `
                        <div class="person" data-name="${name}">
                            <span class="person-name">${name}</span>
                            <span class="counter">${this.stats[name] || 0}</span>
                        </div>
                    `)
                    .join('');
            }
            
            loadStats() {
                const savedStats = localStorage.getItem(this.STORAGE_KEY);
                if (savedStats) {
                    this.stats = JSON.parse(savedStats);
                    this.updateAllCounters();
                } else {
                    this.resetStats();
                }
            }
            
            resetStats() {
                this.stats = {};
                [...this.people.senior, ...this.people.junior].forEach(name => {
                    this.stats[name] = 0;
                });
                this.saveStats();
                this.updateAllCounters();
                this.updateStatsList();
            }
            
            saveStats() {
                localStorage.setItem(this.STORAGE_KEY, JSON.stringify(this.stats));
            }
            
            updateAllCounters() {
                document.querySelectorAll('.person').forEach(el => {
                    const name = el.dataset.name;
                    el.querySelector('.counter').textContent = this.stats[name] || 0;
                });
            }
            
            updateStatsList() {
                const statsList = document.getElementById('stats-list');
                const sortedStats = Object.entries(this.stats)
                    .sort((a, b) => b[1] - a[1]);
                
                statsList.innerHTML = sortedStats
                    .map(([name, count]) => `
                        <div class="stat-item">
                            <span>${name}</span>
                            <span>${count}</span>
                        </div>
                    `)
                    .join('');
            }
            
            getRandomPerson() {
                const group = Math.random() < 0.5 ? 'senior' : 'junior';
                const randomIndex = Math.floor(Math.random() * this.people[group].length);
                return this.people[group][randomIndex];
            }
            
            selectPerson() {
                if(this.isSelecting) return;
                
                this.isSelecting = true;
                this.startSelectionAnimation();
                this.disableButtons(true);
                this.updateResult("Выбираем...");
                
                // Запускаем прогресс бар
                this.progressElement.style.width = '0%';
                anime({
                    targets: this.progressElement,
                    width: '100%',
                    duration: this.selectDuration,
                    easing: 'linear'
                });
                
                setTimeout(() => {
                    const person = this.getRandomPerson();
                    this.updateResult(`Выбран: ${person}`);
                    this.updateStats(person);
                    this.stopSelectionAnimation();
                    this.disableButtons(false);
                    this.isSelecting = false;
                }, this.selectDuration);
            }
            
            startSelectionAnimation() {
                this.diceElement.classList.add('rotating');
                anime({
                    targets: this.diceElement,
                    rotate: '+=360',
                    duration: 1000,
                    loop: true,
                    easing: 'linear'
                });
            }
            
            stopSelectionAnimation() {
                this.diceElement.classList.remove('rotating');
                anime.remove(this.diceElement);
                anime({
                    targets: this.diceElement,
                    rotate: 0,
                    duration: 300
                });
            }
            
            disableButtons(disabled) {
                document.querySelectorAll('button').forEach(btn => {
                    btn.disabled = disabled;
                });
            }
            
            highlightPerson(person) {
                document.querySelectorAll('.person').forEach(el => el.classList.remove('highlight'));
                const personEl = document.querySelector(`.person[data-name="${person}"]`);
                if (personEl) {
                    personEl.classList.add('highlight');
                }
            }
            
            triggerEffect(person) {
                const personEl = document.querySelector(`.person[data-name="${person}"]`);
                if (!personEl) return;
                
                anime({
                    targets: personEl,
                    scale: [1, 1.2, 1],
                    duration: 800,
                    easing: 'easeOutElastic'
                });
            }
            
            updateResult(text) {
                const resultEl = document.getElementById('result');
                resultEl.textContent = text;
            }
            
            exportData() {
                const data = JSON.stringify(this.stats, null, 2);
                const blob = new Blob([data], { type: 'application/json' });
                const url = URL.createObjectURL(blob);
                
                const a = document.createElement('a');
                a.href = url;
                a.download = 'randomizer_stats.json';
                a.click();
                
                URL.revokeObjectURL(url);
            }
            
            importData() {
                const input = document.createElement('input');
                input.type = 'file';
                input.accept = '.json';
                
                input.onchange = e => {
                    const file = e.target.files[0];
                    if (!file) return;
                    
                    const reader = new FileReader();
                    reader.onload = event => {
                        try {
                            const data = JSON.parse(event.target.result);
                            if (this.validateData(data)) {
                                this.stats = data;
                                this.saveStats();
                                this.updateAllCounters();
                                this.updateStatsList();
                                this.updateResult('Данные импортированы!');
                            } else {
                                alert('Неверный формат данных');
                            }
                        } catch (error) {
                            alert('Ошибка при чтении файла');
                        }
                    };
                    reader.readAsText(file);
                };
                
                input.click();
            }
            
            validateData(data) {
                const allNames = [...this.people.senior, ...this.people.junior];
                return allNames.every(name => data.hasOwnProperty(name));
            }
            
            bindEvents() {
                document.getElementById('random-btn').addEventListener('click', () => this.selectPerson());
                document.getElementById('reset-btn').addEventListener('click', () => {
                    if (confirm('Сбросить статистику?')) {
                        this.resetStats();
                        this.updateResult('Статистика сброшена');
                    }
                });
                document.getElementById('export-btn').addEventListener('click', () => this.exportData());
                document.getElementById('import-btn').addEventListener('click', () => this.importData());
            }
        }

        // Инициализация при загрузке страницы
        document.addEventListener('DOMContentLoaded', () => new Randomizer());
    </script>
</body>
</html>

Uncaught TypeError: this.updateStats is not a function
    at NAMOTKA.HTML:373:26

И делай чтобы при наводе мышкой на имя Витя М., прозвучивался звук 02633.mp3