File size: 26,587 Bytes
d43e07e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Speed Typing Challenge</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-5px); }
            75% { transform: translateX(5px); }
        }
        .key-active {
            background-color: #3b82f6 !important;
            color: white !important;
            transform: translateY(2px);
            box-shadow: 0 2px 0 #1d4ed8;
        }
        .key-correct {
            background-color: #10b981 !important;
        }
        .key-wrong {
            background-color: #ef4444 !important;
            animation: shake 0.2s;
        }
        .current-char {
            border-bottom: 3px solid #3b82f6;
        }
        .correct-char {
            color: #10b981;
        }
        .wrong-char {
            color: #ef4444;
            text-decoration: underline;
        }
        .progress-bar {
            transition: width 0.3s ease;
        }
        .floating-emoji {
            position: absolute;
            pointer-events: none;
            font-size: 1.5rem;
            animation: float-up 2s forwards;
        }
        @keyframes float-up {
            0% { transform: translateY(0); opacity: 1; }
            100% { transform: translateY(-100px); opacity: 0; }
        }
    </style>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen flex flex-col">
    <div class="container mx-auto px-4 py-8 flex-1 flex flex-col">
        <!-- Header -->
        <header class="text-center mb-8">
            <h1 class="text-4xl font-bold text-blue-400 mb-2">Speed Typing Challenge</h1>
            <p class="text-gray-400">Test your typing speed and accuracy!</p>
        </header>

        <!-- Game Stats -->
        <div class="bg-gray-800 rounded-lg p-4 mb-6 shadow-lg">
            <div class="flex justify-between items-center mb-4">
                <div class="text-center">
                    <div class="text-2xl font-bold text-blue-400" id="wpm">0</div>
                    <div class="text-gray-400 text-sm">WPM</div>
                </div>
                <div class="text-center">
                    <div class="text-2xl font-bold text-green-400" id="accuracy">100%</div>
                    <div class="text-gray-400 text-sm">Accuracy</div>
                </div>
                <div class="text-center">
                    <div class="text-2xl font-bold text-purple-400" id="score">0</div>
                    <div class="text-gray-400 text-sm">Score</div>
                </div>
                <div class="text-center">
                    <div class="text-2xl font-bold text-yellow-400" id="time">60</div>
                    <div class="text-gray-400 text-sm">Seconds</div>
                </div>
            </div>
            <div class="w-full bg-gray-700 rounded-full h-2.5">
                <div id="time-progress" class="progress-bar bg-blue-600 h-2.5 rounded-full" style="width: 100%"></div>
            </div>
        </div>

        <!-- Game Area -->
        <div class="flex-1 flex flex-col">
            <!-- Text Display -->
            <div class="bg-gray-800 rounded-lg p-6 mb-6 shadow-lg relative overflow-hidden min-h-32">
                <div id="text-display" class="text-xl leading-relaxed font-mono select-none"></div>
                <div id="floating-emojis" class="absolute inset-0 pointer-events-none overflow-hidden"></div>
            </div>

            <!-- Keyboard -->
            <div class="bg-gray-800 rounded-lg p-4 shadow-lg">
                <div class="keyboard-row flex justify-center mb-2">
                    <div class="key" data-key="`">`</div>
                    <div class="key" data-key="1">1</div>
                    <div class="key" data-key="2">2</div>
                    <div class="key" data-key="3">3</div>
                    <div class="key" data-key="4">4</div>
                    <div class="key" data-key="5">5</div>
                    <div class="key" data-key="6">6</div>
                    <div class="key" data-key="7">7</div>
                    <div class="key" data-key="8">8</div>
                    <div class="key" data-key="9">9</div>
                    <div class="key" data-key="0">0</div>
                    <div class="key" data-key="-">-</div>
                    <div class="key" data-key="=">=</div>
                    <div class="key key-wide" data-key="backspace">
                        <i class="fas fa-backspace"></i>
                    </div>
                </div>
                <div class="keyboard-row flex justify-center mb-2">
                    <div class="key key-wide" data-key="tab">Tab</div>
                    <div class="key" data-key="q">Q</div>
                    <div class="key" data-key="w">W</div>
                    <div class="key" data-key="e">E</div>
                    <div class="key" data-key="r">R</div>
                    <div class="key" data-key="t">T</div>
                    <div class="key" data-key="y">Y</div>
                    <div class="key" data-key="u">U</div>
                    <div class="key" data-key="i">I</div>
                    <div class="key" data-key="o">O</div>
                    <div class="key" data-key="p">P</div>
                    <div class="key" data-key="[">[</div>
                    <div class="key" data-key="]">]</div>
                    <div class="key" data-key="\\">\</div>
                </div>
                <div class="keyboard-row flex justify-center mb-2">
                    <div class="key key-extra-wide" data-key="capslock">
                        <i class="fas fa-caps-lock"></i>
                    </div>
                    <div class="key" data-key="a">A</div>
                    <div class="key" data-key="s">S</div>
                    <div class="key" data-key="d">D</div>
                    <div class="key" data-key="f">F</div>
                    <div class="key" data-key="g">G</div>
                    <div class="key" data-key="h">H</div>
                    <div class="key" data-key="j">J</div>
                    <div class="key" data-key="k">K</div>
                    <div class="key" data-key="l">L</div>
                    <div class="key" data-key=";">;</div>
                    <div class="key" data-key="'">'</div>
                    <div class="key key-extra-wide" data-key="enter">
                        <i class="fas fa-arrow-left rotate-180"></i>
                    </div>
                </div>
                <div class="keyboard-row flex justify-center mb-2">
                    <div class="key key-ultra-wide" data-key="shift">
                        <i class="fas fa-arrow-up"></i>
                    </div>
                    <div class="key" data-key="z">Z</div>
                    <div class="key" data-key="x">X</div>
                    <div class="key" data-key="c">C</div>
                    <div class="key" data-key="v">V</div>
                    <div class="key" data-key="b">B</div>
                    <div class="key" data-key="n">N</div>
                    <div class="key" data-key="m">M</div>
                    <div class="key" data-key=",">,</div>
                    <div class="key" data-key=".">.</div>
                    <div class="key" data-key="/">/</div>
                    <div class="key key-ultra-wide" data-key="shift">
                        <i class="fas fa-arrow-up"></i>
                    </div>
                </div>
                <div class="keyboard-row flex justify-center">
                    <div class="key" data-key="ctrl">Ctrl</div>
                    <div class="key" data-key="win">
                        <i class="fab fa-windows"></i>
                    </div>
                    <div class="key" data-key="alt">Alt</div>
                    <div class="key key-space" data-key=" ">Space</div>
                    <div class="key" data-key="alt">Alt</div>
                    <div class="key" data-key="fn">Fn</div>
                    <div class="key" data-key="ctrl">Ctrl</div>
                </div>
            </div>
        </div>

        <!-- Controls -->
        <div class="mt-6 text-center">
            <button id="start-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-8 rounded-full text-lg transition-all duration-300 transform hover:scale-105 shadow-lg">
                <i class="fas fa-play mr-2"></i> Start Game
            </button>
            <div class="mt-4 flex justify-center space-x-4">
                <button id="easy-btn" class="difficulty-btn bg-green-600 hover:bg-green-700 px-4 py-2 rounded" data-level="easy">Easy</button>
                <button id="medium-btn" class="difficulty-btn bg-yellow-600 hover:bg-yellow-700 px-4 py-2 rounded" data-level="medium">Medium</button>
                <button id="hard-btn" class="difficulty-btn bg-red-600 hover:bg-red-700 px-4 py-2 rounded" data-level="hard">Hard</button>
            </div>
        </div>
    </div>

    <!-- Game Over Modal -->
    <div id="game-over-modal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center hidden z-50">
        <div class="bg-gray-800 rounded-xl p-8 max-w-md w-full mx-4 shadow-2xl transform transition-all duration-300 scale-95 opacity-0">
            <div class="text-center">
                <h2 class="text-3xl font-bold text-blue-400 mb-4">Game Over!</h2>
                <div class="text-xl mb-6">
                    <div class="flex justify-between mb-2">
                        <span class="text-gray-400">Final Score:</span>
                        <span class="font-bold" id="final-score">0</span>
                    </div>
                    <div class="flex justify-between mb-2">
                        <span class="text-gray-400">WPM:</span>
                        <span class="font-bold" id="final-wpm">0</span>
                    </div>
                    <div class="flex justify-between mb-2">
                        <span class="text-gray-400">Accuracy:</span>
                        <span class="font-bold" id="final-accuracy">100%</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-400">Difficulty:</span>
                        <span class="font-bold" id="final-difficulty">Medium</span>
                    </div>
                </div>
                <button id="play-again-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-full transition-all duration-300 transform hover:scale-105">
                    <i class="fas fa-redo mr-2"></i> Play Again
                </button>
            </div>
        </div>
    </div>

    <script>
        // Game variables
        let currentText = '';
        let currentIndex = 0;
        let correctChars = 0;
        let wrongChars = 0;
        let startTime;
        let timer;
        let gameActive = false;
        let difficulty = 'medium';
        let score = 0;
        let emojis = ['🎯', 'πŸ”₯', '⚑', 'πŸš€', 'πŸ’―', 'πŸ‘', 'πŸ‘', '✨', '🌟', 'πŸ†'];
        let positiveEmojis = ['😊', '🀩', '😎', '🀘', 'πŸ‘Œ', 'πŸ’ͺ', 'πŸ™Œ', 'πŸ¦„', '🌈', 'πŸ•'];
        let negativeEmojis = ['πŸ˜…', '😬', '😳', 'πŸ€”', 'πŸ™„', 'πŸ˜“', 'πŸ˜₯', 'πŸ€’', '😡', 'πŸ’€'];

        // DOM elements
        const textDisplay = document.getElementById('text-display');
        const startBtn = document.getElementById('start-btn');
        const gameOverModal = document.getElementById('game-over-modal');
        const playAgainBtn = document.getElementById('play-again-btn');
        const wpmDisplay = document.getElementById('wpm');
        const accuracyDisplay = document.getElementById('accuracy');
        const scoreDisplay = document.getElementById('score');
        const timeDisplay = document.getElementById('time');
        const timeProgress = document.getElementById('time-progress');
        const floatingEmojis = document.getElementById('floating-emojis');
        const difficultyBtns = document.querySelectorAll('.difficulty-btn');
        const keys = document.querySelectorAll('.key');
        const finalScore = document.getElementById('final-score');
        const finalWpm = document.getElementById('final-wpm');
        const finalAccuracy = document.getElementById('final-accuracy');
        const finalDifficulty = document.getElementById('final-difficulty');

        // Sample texts based on difficulty
        const sampleTexts = {
            easy: [
                "The quick brown fox jumps over the lazy dog.",
                "Programming is fun and challenging at the same time.",
                "Learning to type quickly will improve your productivity.",
                "Practice makes perfect when it comes to typing skills.",
                "The sun shines brightly on a beautiful summer day."
            ],
            medium: [
                "JavaScript is a versatile programming language used for web development. It allows developers to create interactive websites and applications.",
                "The complexity of modern software systems requires careful planning and design to ensure reliability and maintainability.",
                "Artificial intelligence is transforming various industries by automating tasks that previously required human intelligence.",
                "Responsive web design ensures that websites look good on all devices, from mobile phones to desktop computers.",
                "Cloud computing has revolutionized how businesses store and process data, offering scalability and cost efficiency."
            ],
            hard: [
                "The intricacies of quantum computing lie in its ability to process information using quantum bits or qubits, which can exist in multiple states simultaneously, unlike classical bits that are binary.",
                "Neural networks, inspired by biological neurons, consist of layers of interconnected nodes that process input data through weighted connections, adjusting these weights during training to minimize error in predictions.",
                "Cryptographic hash functions are mathematical algorithms that map data of arbitrary size to fixed-size values, designed to be one-way functions that are infeasible to invert, providing data integrity verification.",
                "The observer effect in quantum mechanics states that the act of observation inevitably alters the system being observed, a fundamental limitation in measuring quantum phenomena with absolute precision.",
                "Polymorphism in object-oriented programming allows objects of different classes to be treated as objects of a common superclass, enabling code reuse and more flexible software design through method overriding and overloading."
            ]
        };

        // Initialize game
        function initGame() {
            // Set difficulty
            difficultyBtns.forEach(btn => {
                btn.addEventListener('click', () => {
                    difficulty = btn.dataset.level;
                    difficultyBtns.forEach(b => b.classList.remove('ring-2', 'ring-white'));
                    btn.classList.add('ring-2', 'ring-white');
                });
            });

            // Set medium as default difficulty
            document.getElementById('medium-btn').click();

            // Keyboard highlight
            document.addEventListener('keydown', (e) => {
                if (!gameActive) return;
                
                const key = e.key.toLowerCase();
                const keyElement = document.querySelector(`.key[data-key="${key}"]`) || 
                                  document.querySelector(`.key[data-key="${e.code.replace('Key', '').toLowerCase()}"]`);
                
                if (keyElement) {
                    keyElement.classList.add('key-active');
                }
            });

            document.addEventListener('keyup', (e) => {
                const key = e.key.toLowerCase();
                const keyElement = document.querySelector(`.key[data-key="${key}"]`) || 
                                  document.querySelector(`.key[data-key="${e.code.replace('Key', '').toLowerCase()}"]`);
                
                if (keyElement) {
                    keyElement.classList.remove('key-active');
                }
            });

            // Start game button
            startBtn.addEventListener('click', startGame);

            // Play again button
            playAgainBtn.addEventListener('click', () => {
                gameOverModal.classList.add('hidden');
                startGame();
            });
        }

        // Start the game
        function startGame() {
            // Reset stats
            currentIndex = 0;
            correctChars = 0;
            wrongChars = 0;
            score = 0;
            scoreDisplay.textContent = '0';
            accuracyDisplay.textContent = '100%';
            wpmDisplay.textContent = '0';
            timeDisplay.textContent = '60';
            timeProgress.style.width = '100%';

            // Get random text based on difficulty
            const texts = sampleTexts[difficulty];
            currentText = texts[Math.floor(Math.random() * texts.length)];

            // Display text with current character highlighted
            displayText();

            // Start timer
            startTime = new Date();
            let timeLeft = 60;
            timer = setInterval(() => {
                timeLeft--;
                timeDisplay.textContent = timeLeft;
                timeProgress.style.width = `${(timeLeft / 60) * 100}%`;

                if (timeLeft <= 0) {
                    endGame();
                }
            }, 1000);

            // Focus on window for key events
            window.focus();

            // Set game state
            gameActive = true;
            startBtn.disabled = true;
            startBtn.classList.remove('bg-blue-600', 'hover:bg-blue-700');
            startBtn.classList.add('bg-gray-600', 'cursor-not-allowed');
            startBtn.innerHTML = '<i class="fas fa-gamepad mr-2"></i> Game in Progress...';
        }

        // Display text with current character highlighted
        function displayText() {
            let html = '';
            for (let i = 0; i < currentText.length; i++) {
                let charClass = '';
                if (i < currentIndex) {
                    charClass = 'correct-char';
                } else if (i === currentIndex) {
                    charClass = 'current-char';
                }
                html += `<span class="${charClass}">${currentText[i]}</span>`;
            }
            textDisplay.innerHTML = html;
        }

        // Handle key press
        document.addEventListener('keydown', (e) => {
            if (!gameActive) return;

            // Prevent default for most keys except Tab, Escape, etc.
            if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Enter' || e.key === 'Space') {
                e.preventDefault();
            }

            const expectedChar = currentText[currentIndex];
            const typedChar = e.key;

            // Highlight key
            const key = e.key.toLowerCase();
            const keyElement = document.querySelector(`.key[data-key="${key}"]`) || 
                              document.querySelector(`.key[data-key="${e.code.replace('Key', '').toLowerCase()}"]`);
            
            if (keyElement) {
                keyElement.classList.add('key-active');
                
                // Remove highlight after short delay
                setTimeout(() => {
                    keyElement.classList.remove('key-active');
                }, 200);
            }

            // Handle backspace
            if (typedChar === 'Backspace') {
                if (currentIndex > 0) {
                    currentIndex--;
                    // If we're going back over a wrong character, decrease wrong count
                    if (textDisplay.children[currentIndex].classList.contains('wrong-char')) {
                        wrongChars--;
                    } else {
                        correctChars--;
                    }
                    displayText();
                }
                return;
            }

            // Check if game is over (all characters typed)
            if (currentIndex >= currentText.length) {
                return;
            }

            // Check if typed character matches expected character
            if (typedChar === expectedChar) {
                correctChars++;
                score += 10;
                
                // Add floating emoji for correct key
                if (Math.random() > 0.7) {
                    addFloatingEmoji(positiveEmojis[Math.floor(Math.random() * positiveEmojis.length)]);
                }
                
                // Highlight key as correct
                if (keyElement) {
                    keyElement.classList.add('key-correct');
                    setTimeout(() => {
                        keyElement.classList.remove('key-correct');
                    }, 300);
                }
            } else {
                wrongChars++;
                score = Math.max(0, score - 5);
                
                // Add floating emoji for wrong key
                if (Math.random() > 0.7) {
                    addFloatingEmoji(negativeEmojis[Math.floor(Math.random() * negativeEmojis.length)]);
                }
                
                // Highlight key as wrong
                if (keyElement) {
                    keyElement.classList.add('key-wrong');
                    setTimeout(() => {
                        keyElement.classList.remove('key-wrong');
                    }, 300);
                }
                
                // Mark character as wrong
                textDisplay.children[currentIndex].classList.add('wrong-char');
            }

            // Move to next character
            currentIndex++;
            
            // Update stats
            updateStats();

            // Check if all characters are typed
            if (currentIndex >= currentText.length) {
                setTimeout(() => {
                    addFloatingEmoji(emojis[Math.floor(Math.random() * emojis.length)]);
                    score += 100; // Bonus for completing the text
                    updateStats();
                    endGame();
                }, 300);
            } else {
                displayText();
            }
        });

        // Add floating emoji effect
        function addFloatingEmoji(emoji) {
            const emojiElement = document.createElement('div');
            emojiElement.className = 'floating-emoji';
            emojiElement.textContent = emoji;
            
            // Random position in the text display area
            const textRect = textDisplay.getBoundingClientRect();
            const x = Math.random() * (textRect.width - 30);
            const y = Math.random() * (textRect.height - 30);
            
            emojiElement.style.left = `${x}px`;
            emojiElement.style.top = `${y}px`;
            
            floatingEmojis.appendChild(emojiElement);
            
            // Remove after animation
            setTimeout(() => {
                emojiElement.remove();
            }, 2000);
        }

        // Update game stats
        function updateStats() {
            // Calculate WPM (Words Per Minute)
            const timeElapsed = (new Date() - startTime) / 60000; // in minutes
            const wordsTyped = correctChars / 5; // standard word length
            const wpm = Math.round(wordsTyped / timeElapsed) || 0;
            
            // Calculate accuracy
            const totalTyped = correctChars + wrongChars;
            const accuracy = totalTyped > 0 ? Math.round((correctChars / totalTyped) * 100) : 100;
            
            // Update displays
            wpmDisplay.textContent = wpm;
            accuracyDisplay.textContent = `${accuracy}%`;
            scoreDisplay.textContent = score;
        }

        // End the game
        function endGame() {
            clearInterval(timer);
            gameActive = false;
            
            // Update final stats
            finalScore.textContent = score;
            finalWpm.textContent = wpmDisplay.textContent;
            finalAccuracy.textContent = accuracyDisplay.textContent;
            finalDifficulty.textContent = difficulty.charAt(0).toUpperCase() + difficulty.slice(1);
            
            // Show game over modal with animation
            gameOverModal.classList.remove('hidden');
            setTimeout(() => {
                const modalContent = gameOverModal.querySelector('div');
                modalContent.classList.remove('scale-95', 'opacity-0');
                modalContent.classList.add('scale-100', 'opacity-100');
            }, 10);
            
            // Reset start button
            startBtn.disabled = false;
            startBtn.classList.remove('bg-gray-600', 'cursor-not-allowed');
            startBtn.classList.add('bg-blue-600', 'hover:bg-blue-700');
            startBtn.innerHTML = '<i class="fas fa-play mr-2"></i> Start Game';
        }

        // Initialize the game when page loads
        window.addEventListener('load', initGame);
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=GMANMD12/speed-typing-challenge" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>