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
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
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<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=Amiri+Quran&family=Vazirmatn:wght@400;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-primary: #0a1f18;
            --bg-secondary: #133327;
            --accent-gold: #d4af37;
            --accent-gold-light: #f3e5ab;
            --text-light: #f0f7f4;
            --text-muted: #a3c2b5;
            --active-ayah: #1b4d3e;
            --border-color: #245745;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Vazirmatn', sans-serif;
        }

        body {
            background-color: var(--bg-primary);
            color: var(--text-light);
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            padding-bottom: 90px;
        }

        header {
            background: linear-gradient(135deg, #0d281e, #1a4234);
            border-bottom: 2px solid var(--accent-gold);
            padding: 20px;
            text-align: center;
            box-shadow: 0 4px 15px rgba(0,0,0,0.5);
        }

        header h1 {
            color: var(--accent-gold);
            font-size: 1.8rem;
            margin-bottom: 5px;
        }

        .controls {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            max-width: 1000px;
            margin: 15px auto;
            padding: 15px;
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            justify-content: space-around;
            align-items: center;
        }

        .control-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        label {
            font-size: 0.9rem;
            color: var(--text-muted);
        }

        select, button {
            background: var(--bg-primary);
            color: var(--text-light);
            border: 1px solid var(--accent-gold);
            padding: 8px 12px;
            border-radius: 6px;
            outline: none;
            cursor: pointer;
            font-size: 0.9rem;
        }

        button:hover, select:hover {
            background: var(--border-color);
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 10px 20px;
            width: 100%;
        }

        .bismillah {
            font-family: 'Amiri Quran', serif;
            font-size: 2.2rem;
            text-align: center;
            color: var(--accent-gold);
            margin: 25px 0;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }

        /* View Modes */
        .ayah-list-view .ayah-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 15px;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .ayah-list-view .ayah-card.active {
            background: var(--active-ayah);
            border-color: var(--accent-gold);
            box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
        }

        .quran-text {
            font-family: 'Amiri Quran', serif;
            font-size: 1.9rem;
            line-height: 2.5rem;
            text-align: right;
            direction: rtl;
            color: var(--accent-gold-light);
            margin-bottom: 12px;
        }

        .translation-text {
            color: var(--text-muted);
            font-size: 1rem;
            line-height: 1.6rem;
            text-align: right;
        }

        .ayah-number {
            display: inline-block;
            color: var(--accent-gold);
            border: 1px solid var(--accent-gold);
            border-radius: 50%;
            width: 32px;
            height: 32px;
            text-align: center;
            line-height: 30px;
            font-size: 0.85rem;
            margin-right: 10px;
        }

        /* Page View Styling */
        .page-view {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 10px;
            padding: 30px;
            line-height: 3.2rem;
            text-align: justify;
            direction: rtl;
        }

        .page-view .inline-ayah {
            font-family: 'Amiri Quran', serif;
            font-size: 1.8rem;
            color: var(--text-light);
            cursor: pointer;
            padding: 2px 4px;
            border-radius: 4px;
        }

        .page-view .inline-ayah.active {
            background-color: var(--accent-gold);
            color: #000;
        }

        /* Fixed Bottom Player */
        .player-bar {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: #071712;
            border-top: 2px solid var(--accent-gold);
            padding: 12px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 1000;
        }

        .player-info {
            font-size: 0.95rem;
            color: var(--accent-gold);
        }

        .player-controls {
            display: flex;
            gap: 10px;
        }

        .loading {
            text-align: center;
            font-size: 1.2rem;
            color: var(--accent-gold);
            margin-top: 50px;
        }
    </style>
</head>
<body>

    <header>
        <h1>سوره مبارکه یونس (ع)</h1>
        <p>قرآن هوشمند با قابلیت تکرار و قرائت آیه به آیه</p>
    </header>

    <div class="controls">
        <div class="control-group">
            <label>قاری:</label>
            <select id="reciterSelect">
                <option value="Parhizgar_48kbps">استاد شهریار پرهیزگار</option>
                <option value="Alafasy_128kbps">استاد مشاری العفاسی</option>
                <option value="Minshawy_Murattal_128kbps">استاد محمد صدیق منشاوی</option>
                <option value="Husary_128kbps">استاد خلیل الحصری</option>
                <option value="Abdul_Basit_Murattal_192kbps">استاد عبدالباسط</option>
            </select>
        </div>

        <div class="control-group">
            <label>تکرار هر آیه:</label>
            <select id="repeatSelect">
                <option value="1">۱ بار</option>
                <option value="2">۲ بار</option>
                <option value="3">۳ بار</option>
                <option value="5">۵ بار</option>
            </select>
        </div>

        <div class="control-group">
            <label>حالت نمایش:</label>
            <select id="viewSelect">
                <option value="list">آیه به آیه (با ترجمه)</option>
                <option value="page">حالت صفحه ای (پیوسته)</option>
            </select>
        </div>
    </div>

    <div class="container">
        <div class="bismillah">بِسْمِ ٱللَّهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ</div>
        <div id="content" class="loading">در حال دریافت اطلاعات سوره یونس...</div>
    </div>

    <div class="player-bar">
        <div class="player-info" id="playerStatus">آیه‌ای انتخاب نشده است</div>
        <div class="player-controls">
            <button id="prevBtn">آیه قبل</button>
            <button id="playBtn">پخش / توقف</button>
            <button id="nextBtn">آیه بعد</button>
        </div>
    </div>

    <audio id="audioPlayer"></audio>

    <script>
        const SURAH_NUMBER = 10;
        let versesData = [];
        let currentAyahIndex = 0;
        let currentRepeatCount = 0;
        let isPlaying = false;

        const audioPlayer = document.getElementById('audioPlayer');
        const contentDiv = document.getElementById('content');
        const reciterSelect = document.getElementById('reciterSelect');
        const repeatSelect = document.getElementById('repeatSelect');
        const viewSelect = document.getElementById('viewSelect');
        const playBtn = document.getElementById('playBtn');
        const prevBtn = document.getElementById('prevBtn');
        const nextBtn = document.getElementById('nextBtn');
        const playerStatus = document.getElementById('playerStatus');

        // Fetch Quran Data (Uthmani + Translation)
        async function fetchSurahData() {
            try {
                const response = await fetch(`https://api.alquran.cloud/v1/surah/${SURAH_NUMBER}/editions/quran-uthmani,fa.fooladvand`);
                const json = await response.json();
                
                const arabic = json.data[0].ayahs;
                const translation = json.data[1].ayahs;

                versesData = arabic.map((item, index) => ({
                    numberInSurah: item.numberInSurah,
                    text: item.text,
                    translation: translation[index].text
                }));

                render();
            } catch (error) {
                contentDiv.innerHTML = 'خطا در بارگیری داده‌ها. لطفاً اتصال اینترنت خود را بررسی کنید.';
            }
        }

        function render() {
            const mode = viewSelect.value;
            contentDiv.className = mode === 'list' ? 'ayah-list-view' : 'page-view';
            contentDiv.innerHTML = '';

            if (mode === 'list') {
                versesData.forEach((ayah, index) => {
                    const card = document.createElement('div');
                    card.className = `ayah-card ${index === currentAyahIndex ? 'active' : ''}`;
                    card.id = `ayah-${index}`;
                    card.onclick = () => playAyah(index);

                    card.innerHTML = `
                        <div class="quran-text">${ayah.text} <span class="ayah-number">${ayah.numberInSurah}</span></div>
                        <div class="translation-text">${ayah.translation}</div>
                    `;
                    contentDiv.appendChild(card);
                });
            } else {
                versesData.forEach((ayah, index) => {
                    const span = document.createElement('span');
                    span.className = `inline-ayah ${index === currentAyahIndex ? 'active' : ''}`;
                    span.id = `ayah-${index}`;
                    span.onclick = () => playAyah(index);
                    span.innerHTML = `${ayah.text} <span class="ayah-number">${ayah.numberInSurah}</span> `;
                    contentDiv.appendChild(span);
                });
            }
        }

        function getAudioUrl(surah, ayah) {
            const reciter = reciterSelect.value;
            const sStr = String(surah).padStart(3, '0');
            const aStr = String(ayah).padStart(3, '0');
            return `https://everyayah.com/data/${reciter}/${sStr}${aStr}.mp3`;
        }

        function playAyah(index) {
            if (index < 0 || index >= versesData.length) return;
            
            if (currentAyahIndex !== index) {
                currentAyahIndex = index;
                currentRepeatCount = 0;
            }

            const ayah = versesData[currentAyahIndex];
            audioPlayer.src = getAudioUrl(SURAH_NUMBER, ayah.numberInSurah);
            audioPlayer.play();
            isPlaying = true;

            updateUI();
        }

        function updateUI() {
            renderHighlights();
            const ayah = versesData[currentAyahIndex];
            const maxRepeat = parseInt(repeatSelect.value);
            playerStatus.textContent = `آیه ${ayah.numberInSurah} از ۱۰۹ (تکرار: ${currentRepeatCount + 1} از ${maxRepeat})`;
            playBtn.textContent = isPlaying ? 'توقف' : 'پخش';

            const activeElem = document.getElementById(`ayah-${currentAyahIndex}`);
            if (activeElem) {
                activeElem.scrollIntoView({ behavior: 'smooth', block: 'center' });
            }
        }

        function renderHighlights() {
            document.querySelectorAll('.active').forEach(el => el.classList.remove('active'));
            const activeElem = document.getElementById(`ayah-${currentAyahIndex}`);
            if (activeElem) activeElem.classList.add('active');
        }

        audioPlayer.onended = () => {
            const maxRepeat = parseInt(repeatSelect.value);
            currentRepeatCount++;

            if (currentRepeatCount < maxRepeat) {
                audioPlayer.play();
                updateUI();
            } else {
                currentRepeatCount = 0;
                if (currentAyahIndex + 1 < versesData.length) {
                    playAyah(currentAyahIndex + 1);
                } else {
                    isPlaying = false;
                    updateUI();
                }
            }
        };

        playBtn.onclick = () => {
            if (isPlaying) {
                audioPlayer.pause();
                isPlaying = false;
            } else {
                if (!audioPlayer.src) {
                    playAyah(0);
                } else {
                    audioPlayer.play();
                    isPlaying = true;
                }
            }
            playBtn.textContent = isPlaying ? 'توقف' : 'پخش';
        };

        prevBtn.onclick = () => playAyah(currentAyahIndex - 1);
        nextBtn.onclick = () => playAyah(currentAyahIndex + 1);
        viewSelect.onchange = render;
        reciterSelect.onchange = () => { if (isPlaying) playAyah(currentAyahIndex); };

        fetchSurahData();
    </script>
</body>
</html>