> { gameStarted = false; currentIndex = totalTyped = correctTyped = 0; elements.start.style.display = 'inline-block'; elements.input.value = ''; elements.input.disabled = true; elements.display.textContent = 'Queencard 골든 로얄 타이핑을 시작하세요!'; updateStats(); }); elements.input.addEventListener('input', () => { if (!gameStarted) return; const current = elements.input.value; const target = phrases[currentIndex]; let html = ''; for (let i = 0; i < target.length; i++) { if (i < current.length) { html += current[i] === target[i] ? `${target[i]}` : `${target[i]}`; } else { html += target[i]; } } elements.display.innerHTML = html; totalTyped = current.length; correctTyped = current.split('').filter((c, i) => c === target[i]).length; updateStats(); }); elements.input.addEventListener('keypress', (e) => { if (e.key === 'Enter' && gameStarted) { if (elements.input.value.trim() === phrases[currentIndex]) { currentIndex++; setTimeout(showPhrase, 200); } } }); function showPhrase() { if (currentIndex >= phrases.length) { alert('👑 Queencard 완료! WPM: ' + elements.wpm.textContent); return; } elements.display.innerHTML = `${phrases[currentIndex]}`; elements.input.value = ''; } function updateStats() { if (startTime) { const elapsed = (new Date() - startTime) / 60000; elements.wpm.textContent = elapsed > 0 ? Math.round((totalTyped / 5) / elapsed) : 0; } elements.accuracy.textContent = totalTyped > 0 ? Math.round((correctTyped / totalTyped) * 100) : 100; const prog = Math.round((currentIndex / phrases.length) * 100); elements.progress.textContent = prog; elements.fill.style.width = prog + '%'; } updateStats();