File size: 26,512 Bytes
d9be66f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d05efe6
d9be66f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Générateur de Code IA | Interface Moderne</title>
    
    <!-- Importation de polices modernes et d'icônes -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <style>
        :root {
            --primary: #3b82f6;
            --primary-hover: #2563eb;
            --secondary: #10b981;
            --bg-dark: #0f172a;
            --bg-card: #1e293b;
            --bg-input: #334155;
            --text-main: #f8fafc;
            --text-muted: #94a3b8;
            --border: #334155;
            --code-bg: #0d1117;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--bg-dark);
            color: var(--text-main);
            line-height: 1.6;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* Header */
        header {
            background: rgba(30, 41, 59, 0.8);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid var(--border);
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .logo {
            font-size: 1.25rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 10px;
            color: var(--primary);
        }

        .logo i {
            font-size: 1.5rem;
        }

        .anycoder-link {
            font-size: 0.875rem;
            color: var(--text-muted);
            text-decoration: none;
            transition: color 0.3s;
            border: 1px solid var(--border);
            padding: 5px 12px;
            border-radius: 20px;
        }

        .anycoder-link:hover {
            color: var(--primary);
            border-color: var(--primary);
        }

        /* Main Container */
        main {
            flex: 1;
            max-width: 1200px;
            width: 100%;
            margin: 0 auto;
            padding: 2rem;
            display: grid;
            grid-template-columns: 1fr;
            gap: 2rem;
        }

        @media (min-width: 900px) {
            main {
                grid-template-columns: 350px 1fr;
                align-items: start;
            }
        }

        /* Input Section */
        .input-section {
            background: var(--bg-card);
            padding: 1.5rem;
            border-radius: 16px;
            border: 1px solid var(--border);
            box-shadow: var(--shadow);
            position: relative;
            overflow: hidden;
        }

        .input-section h2 {
            font-size: 1.1rem;
            margin-bottom: 1rem;
            color: var(--text-main);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            font-size: 0.9rem;
            color: var(--text-muted);
        }

        textarea {
            width: 100%;
            height: 120px;
            background: var(--bg-input);
            border: 2px solid transparent;
            border-radius: 8px;
            padding: 12px;
            color: var(--text-main);
            font-family: 'Inter', sans-serif;
            font-size: 1rem;
            resize: vertical;
            transition: all 0.3s ease;
        }

        textarea:focus {
            outline: none;
            border-color: var(--primary);
            background: #1e293b;
        }

        .btn-generate {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, var(--primary), var(--primary-hover));
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
        }

        .btn-generate:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
        }

        .btn-generate:active {
            transform: translateY(0);
        }

        /* Suggestions Chips */
        .suggestions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 1rem;
        }

        .chip {
            background: rgba(59, 130, 246, 0.1);
            color: var(--primary);
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            cursor: pointer;
            transition: background 0.2s;
            border: 1px solid rgba(59, 130, 246, 0.2);
        }

        .chip:hover {
            background: rgba(59, 130, 246, 0.2);
        }

        /* Output Section */
        .output-section {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }

        .tabs {
            display: flex;
            gap: 1rem;
            border-bottom: 1px solid var(--border);
            padding-bottom: 1px;
        }

        .tab {
            background: none;
            border: none;
            color: var(--text-muted);
            padding: 8px 16px;
            cursor: pointer;
            font-size: 0.95rem;
            font-weight: 500;
            position: relative;
            transition: color 0.3s;
        }

        .tab.active {
            color: var(--primary);
        }

        .tab.active::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 100%;
            height: 2px;
            background: var(--primary);
        }

        .panel {
            display: none;
            background: var(--bg-card);
            border-radius: 12px;
            border: 1px solid var(--border);
            overflow: hidden;
            animation: fadeIn 0.3s ease;
        }

        .panel.active {
            display: block;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(5px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* Code Viewer */
        .code-container {
            position: relative;
            background: var(--code-bg);
        }

        .code-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 16px;
            background: #161b22;
            border-bottom: 1px solid #30363d;
        }

        .lang-label {
            font-size: 0.8rem;
            color: var(--text-muted);
            font-family: 'Fira Code', monospace;
        }

        .btn-copy {
            background: transparent;
            border: 1px solid var(--border);
            color: var(--text-muted);
            padding: 4px 10px;
            border-radius: 4px;
            font-size: 0.8rem;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .btn-copy:hover {
            color: var(--text-main);
            border-color: var(--text-muted);
        }

        pre {
            margin: 0;
            padding: 1.5rem;
            overflow-x: auto;
            color: #e6edf3;
            font-family: 'Fira Code', monospace;
            font-size: 0.9rem;
            white-space: pre-wrap;
        }

        /* Iframe Preview */
        .preview-container {
            width: 100%;
            height: 400px;
            background: white;
            border: none;
        }

        /* Explanation */
        .explanation-content {
            padding: 1.5rem;
        }

        .explanation-content h4 {
            color: var(--primary);
            margin-bottom: 1rem;
        }

        .explanation-content ul {
            padding-left: 1.5rem;
            color: var(--text-muted);
        }

        .explanation-content li {
            margin-bottom: 0.5rem;
        }

        /* Footer */
        footer {
            text-align: center;
            padding: 2rem;
            color: var(--text-muted);
            font-size: 0.9rem;
            margin-top: auto;
        }

        /* Utility for syntax highlighting simulation */
        .tag { color: #7ee787; }
        .attr { color: #79c0ff; }
        .val { color: #a5d6ff; }
        .keyword { color: #ff7b72; }
        .func { color: #d2a8ff; }

    </style>
</head>
<body>

    <header>
        <div class="logo">
            <i class="fa-solid fa-code"></i>
            <span>SimpleGen AI</span>
        </div>
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">
            Built with anycoder
        </a>
    </header>

    <main>
        <!-- Input Section -->
        <section class="input-section">
            <h2><i class="fa-solid fa-wand-magic-sparkles"></i> Configuration</h2>
            <div class="form-group">
                <label for="prompt">Décrivez votre application :</label>
                <textarea id="prompt" placeholder="Ex: une calculatrice simple, un compte à rebours, une liste de tâches..."></textarea>
            </div>
            
            <button class="btn-generate" onclick="generate()">
                <i class="fa-solid fa-bolt"></i> Générer le code
            </button>

            <div class="suggestions">
                <span class="chip" onclick="setPrompt('compteur')">Compteur</span>
                <span class="chip" onclick="setPrompt('calculatrice')">Calculatrice</span>
                <span class="chip" onclick="setPrompt('liste de tâches')">To-Do List</span>
                <span class="chip" onclick="setPrompt('générateur de couleur')">Couleurs</span>
                <span class="chip" onclick="setPrompt('minuteur')">Minuteur</span>
            </div>
        </section>

        <!-- Output Section -->
        <section class="output-section">
            <div class="tabs">
                <button class="tab active" onclick="switchTab('preview')"><i class="fa-solid fa-eye"></i> Aperçu</button>
                <button class="tab" onclick="switchTab('code')"><i class="fa-solid fa-file-code"></i> Code Source</button>
                <button class="tab" onclick="switchTab('explain')"><i class="fa-solid fa-book-open"></i> Explications</button>
            </div>

            <!-- Tab: Preview -->
            <div id="panel-preview" class="panel active">
                <div class="code-header">
                    <span class="lang-label">Live Render</span>
                </div>
                <iframe id="previewFrame" class="preview-container" title="Aperçu"></iframe>
            </div>

            <!-- Tab: Code -->
            <div id="panel-code" class="panel">
                <div class="code-container">
                    <div class="code-header">
                        <span class="lang-label">index.html</span>
                        <button class="btn-copy" onclick="copyCode()">
                            <i class="fa-regular fa-copy"></i> Copier
                        </button>
                    </div>
                    <pre id="code"></pre>
                </div>
            </div>

            <!-- Tab: Explanation -->
            <div id="panel-explain" class="panel">
                <div class="explanation-content" id="explain">
                    <p style="color: var(--text-muted); font-style: italic;">Générez du code pour voir les explications détaillées ici.</p>
                </div>
            </div>
        </section>
    </main>

    <footer>
        <p>&copy; 2023 SimpleGen AI. Interface démonstrative en HTML/CSS/JS pur.</p>
    </footer>

    <script>
        // --- Templates et Logique de Génération ---

        const templates = {
            counter: {
                keywords: ['compteur', 'counter', 'incrémenter', 'compte'],
                code: `<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #f0f2f5; }
  .card { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; }
  h1 { color: #333; }
  #count { font-size: 4rem; font-weight: bold; color: #2563eb; margin: 20px 0; }
  button { padding: 10px 20px; font-size: 1.2rem; cursor: pointer; border: none; border-radius: 6px; margin: 0 5px; transition: opacity 0.2s; }
  .btn-inc { background: #2563eb; color: white; }
  .btn-dec { background: #ef4444; color: white; }
  button:hover { opacity: 0.9; }
</style>
</head>
<body>
  <div class="card">
    <h1>Compteur</h1>
    <div id="count">0</div>
    <button class="btn-dec" onclick="update(-1)">-</button>
    <button class="btn-inc" onclick="update(1)">+</button>
  </div>
  <script>
    let count = 0;
    function update(val) {
      count += val;
      document.getElementById('count').innerText = count;
    }
  <\/script>
</body>
</html>`,
                explanation: `
                    <h4><i class="fa-solid fa-list-ol"></i> Fonctionnement du Compteur</h4>
                    <ul>
                        <li><strong>Structure HTML :</strong> Une carte (div) centrée contenant le titre, l'affichage du nombre et deux boutons.</li>
                        <li><strong>Style CSS :</strong> Utilisation de Flexbox pour centrer le contenu verticalement et horizontalement. Les boutons ont des couleurs distinctes pour l'action positive (+) et négative (-).</li>
                        <li><strong>Logique JS :</strong> Une variable <code>count</code> stocke la valeur. La fonction <code>update(val)</code> modifie cette valeur et met à jour le texte de l'élément avec l'ID "count".</li>
                    </ul>
                `
            },
            calculator: {
                keywords: ['calculatrice', 'calcul', 'math', 'calculator'],
                code: `<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: 'Segoe UI', sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: #222; }
  .calc { background: #333; padding: 20px; border-radius: 15px; box-shadow: 0 10px 20px rgba(0,0,0,0.5); width: 260px; }
  #display { width: 100%; height: 50px; background: #444; color: white; border: none; text-align: right; font-size: 24px; padding: 10px; border-radius: 5px; margin-bottom: 15px; box-sizing: border-box; }
  .grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
  button { padding: 15px; font-size: 18px; border: none; border-radius: 5px; cursor: pointer; background: #555; color: white; transition: 0.1s; }
  button:hover { background: #666; }
  .op { background: #f39c12; }
  .eq { background: #27ae60; grid-column: span 2; }
  .clr { background: #c0392b; }
</style>
</head>
<body>
  <div class="calc">
    <input type="text" id="display" readonly>
    <div class="grid">
      <button class="clr" onclick="clearD()">C</button>
      <button class="op" onclick="append('/')">/</button>
      <button class="op" onclick="append('*')">×</button>
      <button onclick="append('7')">7</button>
      <button onclick="append('8')">8</button>
      <button onclick="append('9')">9</button>
      <button class="op" onclick="append('-')">-</button>
      <button onclick="append('4')">4</button>
      <button onclick="append('5')">5</button>
      <button onclick="append('6')">6</button>
      <button class="op" onclick="append('+')">+</button>
      <button onclick="append('1')">1</button>
      <button onclick="append('2')">2</button>
      <button onclick="append('3')">3</button>
      <button class="eq" onclick="calc()">=</button>
      <button onclick="append('0')">0</button>
      <button onclick="append('.')">.</button>
    </div>
  </div>
  <script>
    const display = document.getElementById('display');
    function append(v) { display.value += v; }
    function clearD() { display.value = ''; }
    function calc() { 
      try { display.value = eval(display.value); } 
      catch { display.value = 'Erreur'; }
    }
  <\/script>
</body>
</html>`,
                explanation: `
                    <h4><i class="fa-solid fa-calculator"></i> Logique de la Calculatrice</h4>
                    <ul>
                        <li><strong>Affichage :</strong> Un champ input en lecture seule affiche la chaîne de calcul.</li>
                        <li><strong>Grille CSS :</strong> Le pavé numérique utilise CSS Grid pour aligner parfaitement les boutons.</li>
                        <li><strong>Fonctions JS :</strong>
                            <ul>
                                <li><code>append(v)</code> : Ajoute le chiffre ou l'opérateur à la chaîne.</li>
                                <li><code>clearD()</code> : Efface tout le contenu.</li>
                                <li><code>calc()</code> : Utilise <code>eval()</code> pour calculer le résultat mathématique de la chaîne (avec gestion d'erreur simple).</li>
                            </ul>
                        </li>
                    </ul>
                `
            },
            todo: {
                keywords: ['tâche', 'todo', 'liste', 'task'],
                code: `<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: sans-serif; background: #eef2f3; padding: 20px; }
  .container { max-width: 400px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
  h2 { text-align: center; color: #333; }
  input[type="text"] { width: 70%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
  button { padding: 10px 15px; background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; }
  ul { list-style: none; padding: 0; }
  li { background: #f9f9f9; margin: 8px 0; padding: 10px; display: flex; justify-content: space-between; align-items: center; border-radius: 5px; }
  li.done span { text-decoration: line-through; color: #888; }
  .del-btn { background: #dc3545; padding: 5px 10px; font-size: 12px; }
</style>
</head>
<body>
  <div class="container">
    <h2>Ma Liste</h2>
    <div style="display:flex; gap:5px; margin-bottom: 20px;">
      <input type="text" id="taskInput" placeholder="Nouvelle tâche...">
      <button onclick="add()">Ajouter</button>
    </div>
    <ul id="list"></ul>
  </div>
  <script>
    function add() {
      const txt = document.getElementById('taskInput').value;
      if(!txt) return;
      
      const li = document.createElement('li');
      li.innerHTML = '<span onclick="this.parentElement.classList.toggle(\\'done\\')">' + txt + '</span> <button class="del-btn" onclick="this.parentElement.remove()">X</button>';
      document.getElementById('list').appendChild(li);
      document.getElementById('taskInput').value = '';
    }
  <\/script>
</body>
</html>`,
                explanation: `
                    <h4><i class="fa-solid fa-check-square"></i> Gestion de Liste de Tâches</h4>
                    <ul>
                        <li><strong>Ajout dynamique :</strong> La fonction <code>add()</code> crée un nouvel élément <code>li</code> via <code>document.createElement</code> et l'ajoute à la liste <code>ul</code>.</li>
                        <li><strong>Interaction :</strong> Cliquer sur le texte de la tâche bascule la classe CSS <code>done</code>, qui applique un style barré via <code>text-decoration: line-through</code>.</li>
                        <li><strong>Suppression :</strong> Chaque tâche possède un bouton "X" qui appelle <code>this.parentElement.remove()</code> pour supprimer l'élément du DOM.</li>
                    </ul>
                `
            },
            color: {
                keywords: ['couleur', 'color', 'background', 'thème'],
                code: `<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; transition: background 0.5s; text-align: center; }
  .card { background: rgba(255,255,255,0.9); padding: 30px; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
  h1 { margin-bottom: 20px; }
  button { padding: 15px 30px; font-size: 18px; cursor: pointer; background: #333; color: white; border: none; border-radius: 50px; transition: transform 0.2s; }
  button:hover { transform: scale(1.05); }
  #hex { font-size: 24px; font-family: monospace; margin-top: 20px; color: #333; font-weight: bold; }
</style>
</head>
<body>
  <div class="card">
    <h1>Générateur de Couleur</h1>
    <button onclick="changeColor()">Changer la couleur</button>
    <div id="hex">#FFFFFF</div>
  </div>
  <script>
    function changeColor() {
      const randomColor = '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0');
      document.body.style.background = randomColor;
      document.getElementById('hex').innerText = randomColor.toUpperCase();
      
      // Ajuster la couleur du texte si fond trop sombre (simplifié)
      document.getElementById('hex').style.color = randomColor;
    }
  <\/script>
</body>
</html>`,
                explanation: `
                    <h4><i class="fa-solid fa-palette"></i> Générateur Aléatoire</h4>
                    <ul>
                        <li><strong>Math.random :</strong> Génère un nombre hexadécimal aléatoire pour créer une couleur RGB.</li>
                        <li><strong>Manipulation du DOM :</strong> La fonction modifie directement le style <code>background</code> du <code>body</code> pour changer la couleur de toute la page.</li>
                        <li><strong>Interaction :</strong> Un bouton déclenche la fonction, offrant un retour visuel immédiat.</li>
                    </ul>
                `
            }
        };

        const defaultTemplate = {
            code: `<!DOCTYPE html>
<html>
<head>
<style>
  body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); margin: 0; }
  .card { background: white; padding: 40px; border-radius: 12px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
  h1 { color: #333; margin-bottom: 10px; }
  p { color: #666; }
</style>
</head>
<body>
  <div class="card">
    <h1>Hello World!</h1>
    <p>Je n'ai pas compris votre demande, mais voici une belle carte par défaut.</p>
  </div>
</body>
</html>`,
            explanation: `<p>Aucun modèle spécifique n'a été détecté dans votre demande. Essayez des mots-clés comme "compteur", "calculatrice" ou "liste".</p>`
        };

        // --- Fonctions Principales ---

        function setPrompt(text) {
            const textarea = document.getElementById('prompt');
            textarea.value = text;
            textarea.focus();
            generate();
        }

        function switchTab(tabName) {
            // Mettre à jour les boutons
            document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
            const index = ['preview', 'code', 'explain'].indexOf(tabName);
            document.querySelectorAll('.tab')[index].classList.add('active');

            // Mettre à jour les panneaux
            document.querySelectorAll('.panel').forEach(p => p.classList.remove('active'));
            document.getElementById('panel-' + tabName).classList.add('active');
        }

        function generate() {
            const prompt = document.getElementById('prompt').value.toLowerCase();
            let result = defaultTemplate;
            let found = false;

            // Recherche simple de mots-clés
            for (const key in templates) {
                const t = templates[key];
                if (t.keywords.some(k => prompt.includes(k))) {
                    result = t;
                    found = true;
                    break;
                }
            }

            // Affichage du code brut
            document.getElementById('code').textContent = result.code;
            
            // Affichage des explications
            document.getElementById('explain').innerHTML = result.explanation;

            // Mise à jour de l'iframe (Preview)
            const iframe = document.getElementById('previewFrame');
            const doc = iframe.contentDocument || iframe.contentWindow.document;
            doc.open();
            doc.write(result.code);
            doc.close();

            // Switch automatique vers l'onglet preview si on vient de cliquer sur générer
            switchTab('preview');
        }

        function copyCode() {
            const codeText = document.getElementById('code').textContent;
            navigator.clipboard.writeText(codeText).then(() => {
                const btn = document.querySelector('.btn-copy');
                const originalHTML = btn.innerHTML;
                btn.innerHTML = '<i class="fa-solid fa-check"></i> Copié !';
                btn.style.color = 'var(--secondary)';
                btn.style.borderColor = 'var(--secondary)';
                
                setTimeout(() => {
                    btn.innerHTML = originalHTML;
                    btn.style.color = '';
                    btn.style.borderColor = '';
                }, 2000);
            });
        }

        // Générer un "Hello World" au chargement initial
        window.onload = function() {
            document.getElementById('prompt').value = "";
            // On peut pré-remplir ou laisser vide. Laissons vide pour inviter à l'action.
        };

    </script>
</body>
</html>