File size: 41,100 Bytes
54ba9fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
<html><head><base href="https://treegen.ai"><title>Promptimg - AI Image Prompt Generator</title>
<style>
  body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #0f1628;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }
  .container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
  }
  h1 {
    color: #ffffff;
    text-align: center;
    font-size: 2rem;
  }
  #config {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    background-color: #1e293b;
    padding: 15px;
    border-radius: 8px;
  }
  #config label {
    margin-right: 15px;
    font-size: 14px;
    margin-bottom: 5px;
  }
  #config input[type="number"] {
    width: 60px;
    padding: 5px;
    background-color: #2d3748;
    border: 1px solid #4a5568;
    color: #ffffff;
    border-radius: 4px;
    margin-bottom: 5px;
  }
  #config input[type="range"] {
    width: 150px;
    margin: 0 10px 5px 10px;
  }
  #prompt-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    overflow-x: auto;
  }
  .prompt-layer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    padding: 10px;
    position: relative;
    width: 100%;
  }
  .prompt-group {
    background-color: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 10px;
    padding: 15px;
    margin-top: 30px;
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 600px;
  }
  .prompt-group::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 50%;
    width: 2px;
    height: 20px;
    background-color: rgba(59, 130, 246, 0.5);
  }
  .prompt-group-title {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #0f1628;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
  }
  .prompt-group-title-hidden {
    display: none;
  }
  .prompt-group-user-input {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #0f1628;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
  }
  .prompt-card {
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    margin: 5px;
    width: 100px;
    height: 100px;
  }
  .prompt-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transition: all 0.3s ease;
  }
  .prompt-card:hover img {
    filter: brightness(70%);
  }
  .prompt-card p {
    display: none;
  }
  #prompt-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 20px;
    border: 1px solid #3b4b66;
    border-radius: 4px;
    background-color: #1e293b;
    color: #ffffff;
    box-sizing: border-box;
  }
  #generate-btn {
    display: block;
    width: 100%;
    max-width: 250px;
    margin: 0 auto 20px;
    padding: 10px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
  }
  #generate-btn:hover {
    background-color: #2563eb;
  }
  .modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.8);
  }
  .modal-content {
    background-color: #1e293b;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #3b4b66;
    width: 90%;
    max-width: 800px;
    border-radius: 10px;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
  }
  .close {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
  }
  .modal-content img {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    margin-bottom: 20px;
  }
  .action-buttons {
    display: none;
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(59, 130, 246, 0.8);
    border-radius: 20px;
    padding: 5px 10px;
    z-index: 10;
  }
  .action-button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    margin: 0 5px;
  }
  .action-button:hover {
    color: #f0f0f0;
  }
  #download-btn {
    position: absolute;
    top: 10px;
    right: 60px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
  }
  #download-btn:hover {
    background-color: #2563eb;
  }
  footer {
    background-color: #1e293b;
    color: #ffffff;
    text-align: center;
    padding: 10px;
    font-size: 14px;
  }
  .nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2rem;
    color: #ffffff;
    background-color: rgba(59, 130, 246, 0.5);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }
  .nav-arrow:hover {
    background-color: rgba(59, 130, 246, 0.8);
  }
  #prev-arrow {
    left: 20px;
  }
  #next-arrow {
    right: 20px;
  }
  #thumbnails {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
  }
  .thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    transition: all 0.3s ease;
  }
  .thumbnail:hover, .thumbnail.active {
    border: 2px solid #3b82f6;
    transform: scale(1.1);
  }
  .group-action-buttons {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(59, 130, 246, 0.8);
    border-radius: 20px;
    padding: 5px 10px;
    z-index: 10;
  }
  .prompt-layer {
    overflow: visible;
  }
  .prompt-group {
    overflow: visible;
  }
  .add-node-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(59, 130, 246, 0.2);
    color: white;
    border: 2px dashed rgba(59, 130, 246, 0.5);
    border-radius: 50%;
    width: 100px;
    height: 100px;
    font-size: 40px;
    cursor: pointer;
    transition: all 0.3s ease;
  }
  .add-node-btn:hover {
    background-color: rgba(59, 130, 246, 0.4);
  }
  .parent-image {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #3b82f6;
  }
  .parent-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .edit-prompt-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
  }
  .edit-prompt-content {
    background-color: #1e293b;
    margin: 10% auto;
    padding: 20px;
    border: 1px solid #3b4b66;
    width: 90%;
    max-width: 600px;
    border-radius: 10px;
  }
  .edit-prompt-textarea {
    width: 100%;
    height: 100px;
    margin-bottom: 10px;
    padding: 10px;
    background-color: #2d3748;
    border: 1px solid #4a5568;
    color: #ffffff;
    border-radius: 4px;
    resize: vertical;
    box-sizing: border-box;
  }
  .edit-prompt-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
  .edit-prompt-btn {
    padding: 5px 10px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
  .edit-prompt-btn:hover {
    background-color: #2563eb;
  }
  .highlighted-prompt {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.4;
  }
  .highlighted-prompt span {
    padding: 2px 4px;
    border-radius: 3px;
  }
  .loading-message {
    font-size: 18px;
    color: #ffffff;
    text-align: center;
    margin: 20px 0;
  }
  @keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
  }
  .loading-message {
    animation: pulse 1.5s infinite;
  }
  .image-details {
    margin-top: 20px;
    text-align: left;
    width: 100%;
  }
  .image-details p {
    margin: 5px 0;
  }
  .image-details .parent-prompt,
  .image-details .user-input {
    font-size: 0.9em;
    color: #a0aec0;
  }
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  .loading-icon {
    animation: spin 1s linear infinite;
  }
  .group-placeholder {
    background-color: rgba(59, 130, 246, 0.1);
    border: 1px dashed rgba(59, 130, 246, 0.3);
    border-radius: 10px;
    padding: 15px;
    margin-top: 30px;
    text-align: center;
    min-width: 200px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    z-index: 10;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 100%;
    max-width: 300px;
    height: 100%;
    background-color: #1e293b;
    transition: left 0.3s ease-in-out;
    z-index: 1000;
    overflow-y: auto;
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-content {
    padding: 20px;
    color: #ffffff;
  }
  .sidebar h2 {
    margin-top: 0;
  }
  .sidebar ul {
    padding-left: 20px;
  }
  .sidebar li {
    margin-bottom: 10px;
  }
  .toggle-sidebar {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px;
    cursor: pointer;
  }
  .modal-image-container {
    position: relative;
    max-width: 100%;
    max-height: 60vh;
""
    margin-bottom: 20px;
  }
  .modal-image-container img {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    width: auto;
  }
  .modal-prompt-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  .modal-image-container:hover .modal-prompt-overlay {
    opacity: 1;
  }
  .circular-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #3b82f6;
    color: white;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin: 0 5px;
    transition: background-color 0.3s ease;
  }
  .circular-button:hover {
    background-color: #2563eb;
  }
  .modal-buttons {
    display: flex;
    justify-content: center;
    margin-top: 10px;
  }
  .action-toggle {
    display: none;
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(59, 130, 246, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 16px;
    cursor: pointer;
    z-index: 9;
  }
  .group-action-toggle {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(59, 130, 246, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 16px;
    cursor: pointer;
    z-index: 9;
  }
  @media (min-width: 769px) {
    .prompt-card:hover .action-buttons {
      display: flex;
    }
    .prompt-group:hover .group-action-buttons {
      display: flex;
    }
    .action-toggle, .group-action-toggle {
      display: none !important;
    }
  }
  @media (max-width: 768px) {
    .container {
      padding: 10px;
    }
    h1 {
      font-size: 1.5rem;
    }
    #config {
      flex-direction: column;
      align-items: flex-start;
    }
    #config label, #config input {
      margin-bottom: 10px;
    }
    .prompt-group {
      padding: 10px;
    }
    .nav-arrow {
      font-size: 1.5rem;
      width: 40px;
      height: 40px;
    }
    #prev-arrow {
      left: 10px;
    }
    #next-arrow {
      right: 10px;
    }
    .thumbnail {
      width: 50px;
      height: 50px;
    }
    .action-buttons, .group-action-buttons {
      display: none;
    }
    .action-toggle, .group-action-toggle {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
</style>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <button class="toggle-sidebar" id="toggleSidebar">
    <i class="fas fa-bars"></i>
  </button>
  
  <div class="sidebar" id="sidebar">
    <div class="sidebar-content">
      <h2><i class="fas fa-lightbulb"></i> How to Use Promptimg</h2>
      <ol>
        <li>Enter an initial concept in the input field.</li>
        <li>Click "Generate image prompts" to create a group of prompts.</li>
        <li>Explore the generated images by clicking on them.</li>
        <li>Use the action buttons to:
          <ul>
            <li><i class="fas fa-redo"></i> Regenerate an image or entire group of prompts</li>
            <li><i class="fas fa-edit"></i> Edit a prompt</li>
            <li><i class="fas fa-trash"></i> Delete a prompt</li>
            <li><i class="fas fa-sitemap"></i> Create child nodes (bifurcate)</li>
          </ul>
        </li>
        <li>Adjust the number of prompts and node size using the controls at the top.</li>
        <li>Create new groups by bifurcating or adding nodes to existing groups.</li>
      </ol>
      
      <div class="sidebar-footer">
        <p><i class="fas fa-code"></i> Promptimg v0.1.0-release</p>
        <p><i class="fas fa-heart"></i> Made with love by @eechever</p>
      </div>
    </div>
  </div>

  <div class="container">
    <h1>Promptimg - Find your dream prompts &amp; images</h1>
    <div id="config">
      <label for="num-prompts">Number of prompts:</label>
      <input type="number" id="num-prompts" min="1" max="10" value="3">
      <label for="node-size">Node size:</label>
      <input type="range" id="node-size" min="20" max="200" value="100">
      <span id="node-size-value">100px</span>
    </div>
    <input type="text" id="prompt-input" placeholder="Enter your initial concept">
    <button id="generate-btn">Generate image prompts</button>
    <div id="prompt-container"></div>
  </div>

  <div id="imageModal" class="modal">
    <div class="modal-content">
      <span class="close">×</span>
      <button id="prev-arrow" class="nav-arrow"><i class="fas fa-chevron-left"></i></button>
      <button id="next-arrow" class="nav-arrow"><i class="fas fa-chevron-right"></i></button>
      <div class="modal-image-container">
        <img id="modalImage" src="" alt="Full size image">
        <div class="modal-prompt-overlay">
          <p id="modalDescription"></p>
        </div>
      </div>
      <div class="modal-buttons">
        <button id="copyPromptBtn" class="circular-button" title="Copy Prompt">
          <i class="fas fa-copy"></i>
        </button>
        <button id="downloadImageBtn" class="circular-button" title="Download Image">
          <i class="fas fa-download"></i>
        </button>
      </div>
      <div class="image-details">
        <p id="userInput" class="user-input"></p>
      </div>
      <div id="thumbnails"></div>
    </div>
  </div>

  <div id="editPromptModal" class="edit-prompt-modal">
    <div class="edit-prompt-content">
      <textarea id="editPromptTextarea" class="edit-prompt-textarea"></textarea>
      <div class="edit-prompt-buttons">
        <button id="cancelEditPrompt" class="edit-prompt-btn">Cancel</button>
        <button id="saveEditPrompt" class="edit-prompt-btn">Save</button>
      </div>
    </div>
  </div>

  <footer>
    <p>Made with ❤️ by <a href="https://www.linkedin.com/in/eechev/" target="_blank" style="color: white; text-decoration: none; transition: opacity 0.3s ease;" onmouseover="this.style.opacity='0.7'" onmouseout="this.style.opacity='1'">@eechever</a> and WebSim</p>
    <a href="https://buymeacoffee.com/eechever" target="_blank" style="display: inline-block; background-color: #FFDD00; color: #000000; padding: 8px 16px; text-decoration: none; border-radius: 5px; font-weight: bold; margin-top: 10px;">
      <i class="fas fa-coffee" style="margin-right: 5px;"></i> Buy me a coffee
    </a>
  </footer>

  <a id="hiddenDownloadLink" style="display: none;"></a>

  <script>
    const promptContainer = document.getElementById('prompt-container');
    const promptInput = document.getElementById('prompt-input');
    const generateBtn = document.getElementById('generate-btn');
    const numPromptsInput = document.getElementById('num-prompts');
    const nodeSizeInput = document.getElementById('node-size');
    const nodeSize =  document.getElementById('node-size-value');
    const modal = document.getElementById('imageModal');
    const modalImage = document.getElementById('modalImage');
    const modalDescription = document.getElementById('modalDescription');
    const userInput = document.getElementById('userInput');
    const closeModal = document.getElementsByClassName('close')[0];
    const prevArrow = document.getElementById('prev-arrow');
    const nextArrow = document.getElementById('next-arrow');
    const thumbnailsContainer = document.getElementById('thumbnails');
    const editPromptModal = document.getElementById('editPromptModal');
    const editPromptTextarea = document.getElementById('editPromptTextarea');
    const cancelEditPrompt = document.getElementById('cancelEditPrompt');
    const saveEditPrompt = document.getElementById('saveEditPrompt');
    const sidebar = document.getElementById('sidebar');
    const toggleSidebar = document.getElementById('toggleSidebar');
    const copyPromptBtn = document.getElementById('copyPromptBtn');
    const downloadImageBtn = document.getElementById('downloadImageBtn');
    const hiddenDownloadLink = document.getElementById('hiddenDownloadLink');

    let currentGroupImages = [];
    let currentImageIndex = 0;
    let currentEditingCard = null;
    let currentOpenActionButtons = null;

    generateBtn.addEventListener('click', () => {
      const initialConcept = promptInput.value;
      if (initialConcept) {
        setButtonLoading(generateBtn);
        generatePrompts(initialConcept);
      }
    });

    nodeSizeInput.addEventListener('input', () => {
      nodeSize.textContent = `${nodeSizeInput.value}px`;
      updateNodeSize();
    });

    closeModal.onclick = function() {
      modal.style.display = "none";
    }

    window.onclick = function(event) {
      if (event.target == modal) {
        modal.style.display = "none";
      }
      if (event.target == editPromptModal) {
        editPromptModal.style.display = "none";
      }
      if (window.innerWidth <= 768 && currentOpenActionButtons && !event.target.closest('.action-buttons') && !event.target.closest('.action-toggle') && !event.target.closest('.group-action-buttons') && !event.target.closest('.group-action-toggle')) {
        currentOpenActionButtons.style.display = 'none';
        currentOpenActionButtons = null;
      }
    }

    prevArrow.addEventListener('click', () => navigateImages(-1));
    nextArrow.addEventListener('click', () => navigateImages(1));

    document.addEventListener('keydown', (e) => {
      if (modal.style.display === "block") {
        if (e.key === "ArrowLeft") navigateImages(-1);
        if (e.key === "ArrowRight") navigateImages(1);
      }
    });

    cancelEditPrompt.addEventListener('click', () => {
      editPromptModal.style.display = "none";
    });

    saveEditPrompt.addEventListener('click', () => {
      if (currentEditingCard) {
        const newPrompt = editPromptTextarea.value;
        const promptData = JSON.parse(currentEditingCard.querySelector('p').textContent);
        promptData.text = newPrompt;
        currentEditingCard.querySelector('p').textContent = JSON.stringify(promptData);
        regenerateImage(currentEditingCard);
        editPromptModal.style.display = "none";
      }
    });

    toggleSidebar.addEventListener('click', () => {
      sidebar.classList.toggle('open');
    });

    copyPromptBtn.addEventListener('click', () => {
      const promptText = modalDescription.textContent;
      navigator.clipboard.writeText(promptText).then(() => {
        alert('Prompt copied to clipboard!');
      }).catch(err => {
        console.error('Failed to copy text: ', err);
      });
    });

    downloadImageBtn.addEventListener('click', function(e) {
      e.preventDefault();
      hiddenDownloadLink.click();
    });

    function updateNodeSize() {
      const size = nodeSizeInput.value;
      const promptCards = document.querySelectorAll('.prompt-card, .add-node-btn');
      promptCards.forEach(card => {
        card.style.width = `${size}px`;
        card.style.height = `${size}px`;
      });
    }

    async function generatePrompts(initialConcept) {
      const placeholder = createGroupPlaceholder("Generating prompts...");
      const layer = getOrCreateRootLayer();
      layer.appendChild(placeholder);

      const numPrompts = parseInt(numPromptsInput.value);
      const complexPrompts = await generateComplexPrompts(initialConcept, numPrompts);
      
      placeholder.innerHTML = "Generating images...";
      const group = await createPromptGroup(complexPrompts, initialConcept, initialConcept);
      layer.replaceChild(group, placeholder);
      updateNodeSize();
      resetButtonLoading(generateBtn);
    }

    function getOrCreateRootLayer() {
      let rootLayer = promptContainer.querySelector('.prompt-layer');
      if (!rootLayer) {
        rootLayer = createPromptLayer();
        promptContainer.appendChild(rootLayer);
      }
      return rootLayer;
    }

    function createPromptLayer() {
      const layer = document.createElement('div');
      layer.className = 'prompt-layer';
      return layer;
    }

    function createGroupPlaceholder(message) {
      const placeholder = document.createElement('div');
      placeholder.className = 'group-placeholder';
      placeholder.innerHTML = `
        <i class="fas fa-spinner fa-spin fa-2x"></i>
        <p>${message}</p>
      `;
      return placeholder;
    }

    async function createPromptGroup(prompts, parentPrompt, userInputText, parentImage = null) {
      const group = document.createElement('div');
      group.className = 'prompt-group';
      
      const hiddenTitle = document.createElement('div');
      hiddenTitle.className = 'prompt-group-title prompt-group-title-hidden';
      hiddenTitle.textContent = parentPrompt;
      group.appendChild(hiddenTitle);

      const userInputTitle = document.createElement('div');
      userInputTitle.className = 'prompt-group-user-input';
      userInputTitle.textContent = userInputText;
      group.appendChild(userInputTitle);

      if (parentImage) {
        const parentImageContainer = document.createElement('div');
        parentImageContainer.className = 'parent-image';
        const img = document.createElement('img');
        img.src = parentImage;
        img.alt = 'Parent Image';
        parentImageContainer.appendChild(img);
        group.appendChild(parentImageContainer);
      }

      const groupActionButtons = document.createElement('div');
      groupActionButtons.className = 'group-action-buttons';
      groupActionButtons.innerHTML = `
        <button class="action-button" title="Regenerate group"><i class="fas fa-redo"></i></button>
        <button class="action-button" title="Edit group prompt"><i class="fas fa-edit"></i></button>
        <button class="action-button" title="Delete group"><i class="fas fa-trash"></i></button>
      `;
      group.appendChild(groupActionButtons);

      const groupActionToggle = document.createElement('button');
      groupActionToggle.className = 'group-action-toggle';
      groupActionToggle.innerHTML = '<i class="fas fa-ellipsis-v"></i>';
      group.appendChild(groupActionToggle);

      const regenerateGroupBtn = groupActionButtons.querySelector('.action-button:nth-child(1)');
      const editGroupBtn = groupActionButtons.querySelector('.action-button:nth-child(2)');
      const deleteGroupBtn = groupActionButtons.querySelector('.action-button:nth-child(3)');

      regenerateGroupBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        regenerateGroup(group);
      });
      editGroupBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        editGroupPrompt(group);
      });
      deleteGroupBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        deleteGroup(group);
      });
      groupActionToggle.addEventListener('click', (e) => {
        e.stopPropagation();
        toggleGroupActionButtons(group);
      });

      for (const prompt of prompts) {
        const imageUrl = await generateImage(prompt.text);
        const promptCard = createPromptCard(prompt, imageUrl, parentPrompt, userInputText);
        group.appendChild(promptCard);
      }

      const addNodeBtn = document.createElement('div');
      addNodeBtn.className = 'add-node-btn prompt-card';
      addNodeBtn.innerHTML = '<i class="fas fa-plus"></i>';
      addNodeBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        addNewNode(group);
      });
      group.appendChild(addNodeBtn);

      return group;
    }

    function createPromptCard(prompt, imageUrl, parentPrompt, userInputText) {
      const card = document.createElement('div');
      card.className = 'prompt-card';
      card.innerHTML = `
        <img src="${imageUrl}" alt="Generated image for ${prompt.text}">
        <p>${JSON.stringify({...prompt, parentPrompt, userInputText})}</p>
        <div class="action-buttons">
          <button class="action-button" title="Regenerate image"><i class="fas fa-redo"></i></button>
          <button class="action-button" title="Edit prompt"><i class="fas fa-edit"></i></button>
          <button class="action-button" title="Delete prompt"><i class="fas fa-trash"></i></button>
          <button class="action-button" title="Bifurcate/Create nodes"><i class="fas fa-sitemap"></i></button>
        </div>
        <button class="action-toggle"><i class="fas fa-ellipsis-v"></i></button>
      `;
      
      const regenerateBtn = card.querySelector('.action-button:nth-child(1)');
      const editBtn = card.querySelector('.action-button:nth-child(2)');
      const deleteBtn = card.querySelector('.action-button:nth-child(3)');
      const bifurcateBtn = card.querySelector('.action-button:nth-child(4)');
      const actionToggle = card.querySelector('.action-toggle');
      const actionButtons = card.querySelector('.action-buttons');

      regenerateBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        regenerateImage(card);
      });
      editBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        editPromptWithModal(card);
      });
      deleteBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        deletePrompt(card);
      });
      bifurcateBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        createChildNodesWithPrompt(card);
      });
      actionToggle.addEventListener('click', (e) => {
        e.stopPropagation();
        toggleActionButtons(card);
      });

      card.addEventListener('click', () => showFullImage(card));

      return card;
    }

    function toggleActionButtons(card) {
      const actionButtons = card.querySelector('.action-buttons');
      if (window.innerWidth <= 768) {
        if (currentOpenActionButtons && currentOpenActionButtons !== actionButtons) {
          currentOpenActionButtons.style.display = 'none';
        }
        actionButtons.style.display = actionButtons.style.display === 'flex' ? 'none' : 'flex';
        currentOpenActionButtons = actionButtons.style.display === 'flex' ? actionButtons : null;
      }
    }

    function toggleGroupActionButtons(group) {
      const groupActionButtons = group.querySelector('.group-action-buttons');
      if (window.innerWidth <= 768) {
        if (currentOpenActionButtons && currentOpenActionButtons !== groupActionButtons) {
          currentOpenActionButtons.style.display = 'none';
        }
        groupActionButtons.style.display = groupActionButtons.style.display === 'flex' ? 'none' : 'flex';
        currentOpenActionButtons = groupActionButtons.style.display === 'flex' ? groupActionButtons : null;
      }
    }

    function showFullImage(card) {
      const group = card.closest('.prompt-group');
      currentGroupImages = Array.from(group.querySelectorAll('.prompt-card')).filter(card => !card.classList.contains('add-node-btn'));
      currentImageIndex = currentGroupImages.indexOf(card);

      updateModalImage();
      modal.style.display = "block";
      updateThumbnails();
    }

    function updateModalImage() {
      const currentCard = currentGroupImages[currentImageIndex];
      const imgSrc = currentCard.querySelector('img').src;
      const promptData = JSON.parse(currentCard.querySelector('p').textContent);
      modalImage.src = imgSrc;
      modalDescription.textContent = promptData.text;
      userInput.textContent = `User Input: ${promptData.userInputText}`;

      // Update hidden download link
      const fileName = `${promptData.text.slice(0, 30).replace(/[^a-z0-9]/gi, '_').toLowerCase()}.jpg`;
      hiddenDownloadLink.href = imgSrc;
      hiddenDownloadLink.download = fileName;
    }

    function updateThumbnails() {
      thumbnailsContainer.innerHTML = '';
      currentGroupImages.forEach((card, index) => {
        const thumbnail = document.createElement('img');
        thumbnail.src = card.querySelector('img').src;
        thumbnail.alt = `Thumbnail ${index + 1}`;
        thumbnail.classList.add('thumbnail');
        if (index === currentImageIndex) thumbnail.classList.add('active');
        thumbnail.addEventListener('click', () => {
          currentImageIndex = index;
          updateModalImage();
          updateThumbnails();
        });
        thumbnailsContainer.appendChild(thumbnail);
      });
    }

    function navigateImages(direction) {
      currentImageIndex = (currentImageIndex + direction + currentGroupImages.length) % currentGroupImages.length;
      updateModalImage();
      updateThumbnails();
    }

    async function regenerateImage(card) {
      const promptData = JSON.parse(card.querySelector('p').textContent);
      setCardLoading(card);
      const newImageUrl = await generateImage(promptData.text);
      const oldImg = card.querySelector('img');
      const newImg = document.createElement('img');
      newImg.src = newImageUrl;
      newImg.alt = `Generated image for ${promptData.text}`;
      oldImg.parentNode.replaceChild(newImg, oldImg);
      resetCardLoading(card);
    }

    function editPromptWithModal(card) {
      currentEditingCard = card;
      const currentPrompt = JSON.parse(card.querySelector('p').textContent);
      editPromptTextarea.value = currentPrompt.text;
      editPromptModal.style.display = "block";
    }

    function deletePrompt(card) {
      if (confirm("Are you sure you want to delete this prompt?")) {
        const parentGroup = card.closest('.prompt-group');
        card.remove();
        
        if (parentGroup.querySelectorAll('.prompt-card').length === 1) { // Only the add-node-btn left
          deleteGroup(parentGroup);
        }
      }
    }

    async function createChildNodesWithPrompt(card) {
      const promptData = JSON.parse(card.querySelector('p').textContent);
      const userPrompt = prompt("Enter an optional prompt to add to the request (or leave blank):");
      
      if (userPrompt === null) {
        return; // User canceled the operation
      }

      setButtonLoading(card.querySelector('.action-button:nth-child(4)'));

      const placeholder = createGroupPlaceholder("Generating prompts...");
      let nextLayer = card.closest('.prompt-layer').nextElementSibling;
      if (!nextLayer || !nextLayer.classList.contains('prompt-layer')) {
        nextLayer = createPromptLayer();
        promptContainer.insertBefore(nextLayer, card.closest('.prompt-layer').nextElementSibling);
      }
      nextLayer.appendChild(placeholder);

      const childNodes = await generateComplexPrompts(promptData.text, 3, userPrompt);
      
      placeholder.innerHTML = "Generating images...";
      const parentImage = card.querySelector('img').src;
      const newGroup = await createPromptGroup(childNodes, promptData.text, userPrompt || promptData.text, parentImage);
      
      nextLayer.replaceChild(newGroup, placeholder);
      updateNodeSize();
      resetButtonLoading(card.querySelector('.action-button:nth-child(4)'));
    }

    async function regenerateGroup(group) {
      const groupTitle = group.querySelector('.prompt-group-title');
      const basePrompt = groupTitle.textContent;
      const numPrompts = group.querySelectorAll('.prompt-card:not(.add-node-btn)').length;
      const userInputTitle = group.querySelector('.prompt-group-user-input');
      const userInputText = userInputTitle.textContent;
      
      setButtonLoading(group.querySelector('.action-button:nth-child(1)'));
      
      const placeholder = createGroupPlaceholder("Generating prompts...");
      group.innerHTML = '';
      group.appendChild(placeholder);

      const newPrompts = await generateComplexPrompts(basePrompt, numPrompts, userInputText);
      
      placeholder.innerHTML = "Generating images...";
      
      group.innerHTML = '';
      group.appendChild(groupTitle);
      group.appendChild(userInputTitle);
      
      for (const prompt of newPrompts) {
        const newImageUrl = await generateImage(prompt.text);
        const promptCard = createPromptCard(prompt, newImageUrl, basePrompt, userInputText);
        group.appendChild(promptCard);
      }
      
      const addNodeBtn = document.createElement('div');
      addNodeBtn.className = 'add-node-btn prompt-card';
      addNodeBtn.innerHTML = '<i class="fas fa-plus"></i>';
      addNodeBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        addNewNode(group);
      });
      group.appendChild(addNodeBtn);
      
      updateNodeSize();
      resetButtonLoading(group.querySelector('.action-button:nth-child(1)'));
    }

    async function editGroupPrompt(group) {
      const groupTitle = group.querySelector('.prompt-group-title');
      const currentPrompt = groupTitle.textContent;
      const userInputTitle = group.querySelector('.prompt-group-user-input');
      const userIndication = prompt("Enter a new prompt for this group:", currentPrompt);
      
      if (userIndication !== null && userIndication !== "") {
        groupTitle.textContent = currentPrompt; // Keep the original parent prompt
        userInputTitle.textContent = userIndication; // Update user input
        await regenerateGroup(group);
      }
    }

    function deleteGroup(group) {
      if (confirm("Are you sure you want to delete this entire group?")) {
        const parentLayer = group.closest('.prompt-layer');
        group.remove();
        
        if (parentLayer.querySelectorAll('.prompt-group').length === 0) {
          parentLayer.remove();
        }
      }
    }

    async function addNewNode(group) {
      const groupTitle = group.querySelector('.prompt-group-title');
      const basePrompt = groupTitle.textContent;
      const userInputTitle = group.querySelector('.prompt-group-user-input');
      const userInputText = userInputTitle.textContent;

      setButtonLoading(group.querySelector('.add-node-btn'));

      const newPrompt = await generateComplexPrompts(basePrompt, 1, userInputText);
      const newImageUrl = await generateImage(newPrompt[0].text);
      const promptCard = createPromptCard(newPrompt[0], newImageUrl, basePrompt, userInputText);
      group.insertBefore(promptCard, group.querySelector('.add-node-btn'));
      updateNodeSize();

      resetButtonLoading(group.querySelector('.add-node-btn'));
    }

    async function generateComplexPrompts(basePrompt, count, userPrompt = "") {
      const response = await fetch('https://websim.ai/api/web', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          prompt: `Generate ${count} unique and creative image prompts based on this concept: "${basePrompt}". ${userPrompt ? `Include this additional context: "${userPrompt}".` : ''} Each prompt should be detailed and vivid, suitable for AI image generation. Respond in the following JSON format:
          {
            "prompts": [
              {
                "text": "Full prompt text"
              },
              ...
            ]
          }`,
        }),
      });

      const data = await response.json();
      return data.prompts;
    }

    async function generateImage(prompt) {
      // Use a placeholder loading image
      const placeholderUrl = 'https://via.placeholder.com/400x400.png?text=Loading...';
      
      // Simulate image generation delay
      await new Promise(resolve => setTimeout(resolve, 1000));
      
      // For this example, we'll still use a placeholder image service
      // In a real application, you would integrate with an actual AI image generation API
      return `https://picsum.photos/400?random=${Math.random()}`;
    }

    function setButtonLoading(button) {
      const originalContent = button.innerHTML;
      button.disabled = true;
      button.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
      button.dataset.originalContent = originalContent;
    }

    function resetButtonLoading(button) {
      const originalContent = button.dataset.originalContent;
      if (originalContent) {
        button.innerHTML = originalContent;
        button.disabled = false;
        delete button.dataset.originalContent;
      }
    }

    function setCardLoading(card) {
      const loadingOverlay = document.createElement('div');
      loadingOverlay.className = 'loading-overlay';
      loadingOverlay.innerHTML = '<i class="fas fa-spinner fa-spin fa-2x"></i>';
      card.appendChild(loadingOverlay);
    }

    function resetCardLoading(card) {
      const loadingOverlay = card.querySelector('.loading-overlay');
      if (loadingOverlay) {
""
        loadingOverlay.remove();
      }
    }

    // Add this code to restore default link behavior after the page is loaded
    document.addEventListener('DOMContentLoaded', function() {
      const restoreDefaultLinkBehavior = function(element) {
        const links = element.getElementsByTagName('a');
        for (let i = 0; i < links.length; i++) {
          links[i].addEventListener('click', function(event) {
            event.stopPropagation();
          });
        }
      };

      // Restore default behavior for existing links
      restoreDefaultLinkBehavior(document);

      // Use a MutationObserver to handle dynamically added content
      const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
          if (mutation.type === 'childList') {
            mutation.addedNodes.forEach(function(node) {
              if (node.nodeType === 1) { // ELEMENT_NODE
                restoreDefaultLinkBehavior(node);
              }
            });
          }
        });
      });

      // Configure the observer to watch for changes in the entire document
      const config = { childList: true, subtree: true };
      observer.observe(document.body, config);
    });

    // Modify the download functionality
    downloadImageBtn.addEventListener('click', function(e) {
      e.preventDefault();
      const imgSrc = modalImage.src;
      const promptData = JSON.parse(currentGroupImages[currentImageIndex].querySelector('p').textContent);
      const fileName = `${promptData.text.slice(0, 30).replace(/[^a-z0-9]/gi, '_').toLowerCase()}.jpg`;

      fetch(imgSrc)
        .then(resp => resp.blob())
        .then(blob => {
          const url = window.URL.createObjectURL(blob);
          const a = document.createElement('a');
          a.style.display = 'none';
          a.href = url;
          a.download = fileName;
          document.body.appendChild(a);
          a.click();
          window.URL.revokeObjectURL(url);
        })
        .catch(() => alert('An error occurred while downloading the image.'));
    });
  </script>

</body></html>