<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>لعبة الحروف التفاعلية - A, B, C</title>
    <style>
        * {
            box-sizing: border-box;
            font-family: 'Comic Sans MS', 'Arial', sans-serif;
        }
        body {
            background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
        }
        h1 {
            color: #fff;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-align: center;
        }
        .container {
            max-width: 800px;
            width: 100%;
            background: white;
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
            text-align: center;
        }
        .tabs {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }
        .tab-btn {
            background-color: #ff6b6b;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 50px;
            cursor: pointer;
            font-size: 1.1rem;
            transition: 0.3s;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        .tab-btn.active, .tab-btn:hover {
            background-color: #ff5252;
            transform: scale(1.05);
        }
        .section {
            display: none;
        }
        .section.active {
            display: block;
        }
        /* بطاقات الحروف */
        .cards-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        .card {
            background: #f9f9f9;
            border: 4px dashed #4ecdc4;
            border-radius: 15px;
            padding: 20px;
            cursor: pointer;
            transition: 0.3s;
        }
        .card:hover {
            transform: translateY(-5px);
            background: #f0f8ff;
            border-color: #ff6b6b;
        }
        .letter {
            font-size: 4rem;
            color: #ff6b6b;
            font-weight: bold;
            margin: 0;
        }
        .word {
            font-size: 1.5rem;
            color: #333;
            margin: 10px 0 0 0;
        }
        .emoji {
            font-size: 3rem;
            margin-top: 10px;
        }
        /* الألعاب والتتبع */
        .game-area, .trace-area {
            margin-top: 20px;
            padding: 20px;
            background: #fdfdfd;
            border-radius: 10px;
            border: 2px solid #eee;
        }
        canvas {
            border: 3px solid #4ecdc4;
            border-radius: 10px;
            background: #fff;
            touch-action: none;
            cursor: crosshair;
        }
        .score {
            font-size: 1.3rem;
            color: #2ecc71;
            font-weight: bold;
            margin-top: 15px;
        }
        .btn {
            background-color: #4ecdc4;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 10px;
            font-size: 1rem;
            cursor: pointer;
            margin-top: 10px;
            transition: 0.3s;
        }
        .btn:hover {
            background-color: #2bc8bd;
        }
    </style>
</head>
<body>

    <h1>🌟 لعبة الحروف الممتعة A - B - C 🌟</h1>

    <div class="container">
        <!-- أزرار التنقل بين الأقسام -->
        <div class="tabs">
            <button class="tab-btn active" onclick="switchTab('cards')">بطاقات الحروف</button>
            <button class="tab-btn" onclick="switchTab('quiz')">لعبة أين الحرف؟</button>
            <button class="tab-btn" onclick="switchTab('trace')">رسم وتتبع الحروف</button>
        </div>

        <!-- قسم 1: بطاقات الحروف -->
        <div id="cards" class="section active">
            <h2>اضغط على الحرف لتسمع صوته! (نطق C مثل K)</h2>
            <div class="cards-grid">
                <div class="card" onclick="playSound('A', 'Apple')">
                    <p class="letter">A</p>
                    <p class="word">Apple (تفاحة)</p>
                    <div class="emoji">🍎</div>
                </div>
                <div class="card" onclick="playSound('B', 'Ball')">
                    <p class="letter">B</p>
                    <p class="word">Ball (كرة)</p>
                    <div class="emoji">⚽</div>
                </div>
                <div class="card" onclick="playSound('C', 'Cat', 'K')">
                    <p class="letter">C</p>
                    <p class="word">Cat (قطة)</p>
                    <div class="emoji">🐱</div>
                </div>
            </div>
        </div>

        <!-- قسم 2: لعبة أين الحرف -->
        <div id="quiz" class="section">
            <h2>لعبة البحث عن الحرف</h2>
            <p id="quiz-question" style="font-size: 1.4rem; color: #555;">اضغط على الحرف: <span id="target-letter" style="color:#ff6b6b; font-weight:bold;">A</span></p>
            <div style="display: flex; justify-content: center; gap: 20px; margin-top: 20px;">
                <button class="tab-btn" onclick="checkAnswer('A')">A</button>
                <button class="tab-btn" onclick="checkAnswer('B')">B</button>
                <button class="tab-btn" onclick="checkAnswer('C')">C</button>
            </div>
            <p class="score" id="quiz-score">النقاط: 0 ⭐</p>
        </div>

        <!-- قسم 3: التتبع والرسومات -->
        <div id="trace" class="section">
            <h2>ارسم وتتبع الحروف</h2>
            <p>قم بالرسم فوق المربع أدناه لتتدرب على كتابة الحروف:</p>
            <canvas id="drawCanvas" width="300" height="200"></canvas>
            <div>
                <button class="btn" onclick="clearCanvas()">مسح اللوحة</button>
            </div>
        </div>
    </div>

    <script>
        // التبديل بين الأقسام
        function switchTab(tabId) {
            document.querySelectorAll('.section').forEach(sec => sec.classList.remove('active'));
            document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
            document.getElementById(tabId).classList.add('active');
            event.currentTarget.classList.add('active');
        }

        // نطق الكلمات والحروف (مع جعل نطق C صوتاً صلباً مثل K)
        function playSound(letter, word, customSound) {
            let textToSpeak = letter + ", " + word;
            if (letter === 'C') {
                // نطق حرف C كصوت K الصلب
                textToSpeak = "K, Cat";
            }
            
            const utterance = new SpeechSynthesisUtterance(textToSpeak);
            utterance.lang = 'en-US';
            utterance.rate = 0.9;
            window.speechSynthesis.speak(utterance);
        }

        // منطق لعبة أين الحرف
        let currentTarget = 'A';
        let score = 0;
        const lettersList = ['A', 'B', 'C'];

        function nextQuestion() {
            currentTarget = lettersList[Math.floor(Math.random() * lettersList.length)];
            document.getElementById('target-letter').innerText = currentTarget;
        }

        function checkAnswer(selected) {
            if (selected === currentTarget) {
                score += 10;
                document.getElementById('quiz-score').innerText = "النقاط: " + score + " ⭐ أحسنت!";
                let utterance = new SpeechSynthesisUtterance("رائع جداً!");
                utterance.lang = 'ar-SA';
                window.speechSynthesis.speak(utterance);
                setTimeout(nextQuestion, 1000);
            } else {
                let utterance = new SpeechSynthesisUtterance("حاول مرة أخرى!");
                utterance.lang = 'ar-SA';
                window.speechSynthesis.speak(utterance);
            }
        }

        // لوحة الرسم والتتبع
        const canvas = document.getElementById('drawCanvas');
        const ctx = canvas.getContext('2d');
        let painting = false;

        function startPosition(e) {
            painting = true;
            draw(e);
        }

        function endPosition() {
            painting = false;
            ctx.beginPath();
        }

        function draw(e) {
            if (!painting) return;
            ctx.lineWidth = 8;
            ctx.lineCap = 'round';
            ctx.strokeStyle = '#ff6b6b';

            let clientX = e.clientX || (e.touches ? e.touches[0].clientX : 0);
            let clientY = e.clientY || (e.touches ? e.touches[0].clientY : 0);
            
            let rect = canvas.getBoundingClientRect();
            let x = clientX - rect.left;
            let y = clientY - rect.top;

            ctx.lineTo(x, y);
            ctx.stroke();
            ctx.beginPath();
            ctx.moveTo(x, y);
        }

        canvas.addEventListener('mousedown', startPosition);
        canvas.addEventListener('mouseup', endPosition);
        canvas.addEventListener('mousemove', draw);

        canvas.addEventListener('touchstart', startPosition);
        canvas.addEventListener('touchend', endPosition);
        canvas.addEventListener('touchmove', draw);

        function clearCanvas() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
        }
    </script>
</body>
</html>
