File size: 49,711 Bytes
673102b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>هوش مصنوعی همه‌کاره | Nova AI</title>
<link href="https://cdn.jsdelivr.net/fontsource/fonts/vazirmatn@latest/font-faces.css" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Vazirmatn', sans-serif; }
:root {
  --bg: #0a0a1a;
  --bg2: #12122a;
  --card: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.08);
  --text: #e8e8f0;
  --muted: #8888aa;
  --accent: #8b5cf6;
  --accent2: #06b6d4;
  --pink: #ec4899;
  --green: #10b981;
  --orange: #f59e0b;
}
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 20% 10%, rgba(139,92,246,0.15), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(6,182,212,0.12), transparent 40%);
}
/* Header */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,26,0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 12px;
  font-size: 20px; font-weight: 700;
}
.logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 0 20px rgba(139,92,246,0.4);
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 20px rgba(139,92,246,0.4); }
  50% { box-shadow: 0 0 30px rgba(139,92,246,0.7); }
}
.logo span { background: linear-gradient(135deg, #fff, #c4b5fd); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-actions { display: flex; gap: 10px; }
.btn-voice {
  width: 42px; height: 42px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.3s;
  font-size: 18px;
}
.btn-voice:hover { background: var(--accent); border-color: var(--accent); }
.btn-voice.active {
  background: #ef4444;
  border-color: #ef4444;
  animation: voicePulse 1s ease-in-out infinite;
}
@keyframes voicePulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}
/* Layout */
.container {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 70px);
}
/* Sidebar */
.sidebar {
  background: rgba(0,0,0,0.2);
  border-left: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.nav-item {
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: all 0.2s;
  color: var(--muted);
  font-size: 14px;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(6,182,212,0.1));
  border-color: rgba(139,92,246,0.3);
  color: #fff;
}
.nav-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  background: var(--card);
}
.nav-item.active .nav-icon { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.nav-label { font-weight: 500; }
.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.sidebar-footer strong { color: var(--green); }
/* Main */
.main { padding: 24px; overflow-y: auto; max-height: calc(100vh - 70px); }
.view { display: none; animation: fadeIn 0.4s ease; }
.view.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.view-header { margin-bottom: 24px; }
.view-title {
  font-size: 28px; font-weight: 700;
  background: linear-gradient(135deg, #fff, #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}
.view-subtitle { color: var(--muted); font-size: 14px; }
/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
}
/* Chat */
.chat-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex; flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 500px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg {
  display: flex; gap: 12px;
  max-width: 85%;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.msg.user { align-self: flex-start; flex-direction: row; }
.msg.ai { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--accent2), var(--green)); }
.msg.ai .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--pink)); }
.msg-content {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.7;
}
.msg.user .msg-content { background: rgba(6,182,212,0.1); border: 1px solid rgba(6,182,212,0.2); border-top-right-radius: 4px; }
.msg.ai .msg-content { background: rgba(139,92,246,0.1); border: 1px solid rgba(139,92,246,0.2); border-top-left-radius: 4px; }
.msg-content img { max-width: 100%; border-radius: 12px; margin-top: 8px; }
.chat-input-wrap {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.chat-input-box {
  display: flex; gap: 10px; align-items: center;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
  transition: all 0.2s;
}
.chat-input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139,92,246,0.15); }
.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  padding: 10px 0;
  font-family: inherit;
}
.chat-input::placeholder { color: var(--muted); }
.send-btn {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.typing { display: flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%,60%,100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-8px); opacity: 1; }
}
/* Welcome */
.welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px;
  text-align: center;
}
.welcome-icon {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  margin-bottom: 20px;
  box-shadow: 0 10px 40px rgba(139,92,246,0.4);
}
.welcome h2 { font-size: 24px; margin-bottom: 8px; }
.welcome p { color: var(--muted); margin-bottom: 24px; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 700px;
}
.suggestion {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: right;
  font-size: 13px;
  transition: all 0.2s;
}
.suggestion:hover { border-color: var(--accent); transform: translateY(-2px); }
.suggestion-icon { font-size: 20px; margin-bottom: 6px; }
/* Image Gen */
.image-gen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .image-gen-grid { grid-template-columns: 1fr; } }
.prompt-area {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}
.prompt-area textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  resize: none;
  min-height: 100px;
  font-family: inherit;
}
.prompt-area textarea::placeholder { color: var(--muted); }
.style-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 12px;
}
.chip {
  padding: 6px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--muted);
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(139,92,246,0.3); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.image-preview {
  aspect-ratio: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview .placeholder { color: var(--muted); text-align: center; padding: 20px; }
.image-preview .placeholder-icon { font-size: 48px; margin-bottom: 10px; }
.loader {
  width: 50px; height: 50px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.gallery-item {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border);
}
.gallery-item:hover { transform: scale(1.03); border-color: var(--accent); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
/* Music */
.music-player {
  background: linear-gradient(135deg, rgba(236,72,153,0.1), rgba(139,92,246,0.1));
  border: 1px solid rgba(236,72,153,0.2);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
}
.music-cover {
  width: 180px; height: 180px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--pink), var(--accent));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 80px;
  box-shadow: 0 20px 60px rgba(236,72,153,0.3);
  animation: coverFloat 4s ease-in-out infinite;
}
@keyframes coverFloat {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.music-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.music-artist { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.music-controls {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  margin-bottom: 20px;
}
.music-btn {
  width: 48px; height: 48px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}
.music-btn.play {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--pink), var(--accent));
  border: none;
  font-size: 22px;
}
.music-btn:hover { transform: scale(1.1); }
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, var(--pink), var(--accent));
  border-radius: 2px;
  transition: width 0.3s;
}
.music-time { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.music-list { margin-top: 20px; }
.music-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.music-item:hover { border-color: var(--pink); }
.music-item.active { border-color: var(--pink); background: rgba(236,72,153,0.1); }
.music-item-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--pink), var(--accent));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.music-item-info { flex: 1; }
.music-item-title { font-size: 14px; font-weight: 600; }
.music-item-sub { font-size: 12px; color: var(--muted); }
.music-item-dur { color: var(--muted); font-size: 12px; }
/* Study */
.grade-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.grade-btn {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s;
}
.grade-btn:hover { border-color: var(--green); }
.grade-btn.active { background: linear-gradient(135deg, var(--green), var(--accent2)); border-color: transparent; }
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.subject-card {
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.subject-card:hover { transform: translateY(-4px); border-color: var(--green); }
.subject-icon { font-size: 32px; margin-bottom: 8px; }
.subject-name { font-size: 14px; font-weight: 600; }
/* Search */
.search-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px;
  display: flex;
  margin-bottom: 20px;
}
.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 14px 18px;
  font-size: 15px;
  font-family: inherit;
}
.search-box button {
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent2), var(--green));
  border: none;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
.source-tag {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(6,182,212,0.15);
  border: 1px solid rgba(6,182,212,0.3);
  border-radius: 6px;
  font-size: 11px;
  color: var(--accent2);
  margin-left: 6px;
}
.result-item {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
}
.result-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; color: var(--accent2); }
.result-text { font-size: 13px; line-height: 1.7; color: var(--muted); }
/* Voice overlay */
.voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(20px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.voice-overlay.active { display: flex; }
.voice-circle {
  width: 180px; height: 180px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  display: flex; align-items: center; justify-content: center;
  font-size: 60px;
  position: relative;
  animation: voiceBreath 2s ease-in-out infinite;
}
@keyframes voiceBreath {
  0%,100% { transform: scale(1); box-shadow: 0 0 40px rgba(139,92,246,0.5); }
  50% { transform: scale(1.08); box-shadow: 0 0 80px rgba(139,92,246,0.8); }
}
.voice-ring {
  position: absolute;
  inset: -20px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  animation: ringExpand 2s ease-out infinite;
}
.voice-ring:nth-child(2) { animation-delay: 0.5s; }
.voice-ring:nth-child(3) { animation-delay: 1s; }
@keyframes ringExpand {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}
.voice-text {
  margin-top: 30px;
  font-size: 18px;
  color: var(--text);
  text-align: center;
  max-width: 400px;
}
.voice-close {
  margin-top: 30px;
  padding: 12px 30px;
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--border);
  border-radius: 30px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
/* Responsive */
@media (max-width: 768px) {
  .container { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
  .view-title { font-size: 22px; }
}
</style>
</head>
<body>

<header class="header">
  <div class="logo">
    <div class="logo-icon">✦</div>
    <span>Nova AI</span>
  </div>
  <div class="header-actions">
    <button class="btn-voice" id="voiceBtn" title="مکالمه صوتی">🎙</button>
  </div>
</header>

<div class="container">
  <aside class="sidebar">
    <div class="nav-item active" data-view="chat">
      <div class="nav-icon">💬</div>
      <div class="nav-label">گفتگو با AI</div>
    </div>
    <div class="nav-item" data-view="image">
      <div class="nav-icon">🎨</div>
      <div class="nav-label">تولید تصویر</div>
    </div>
    <div class="nav-item" data-view="music">
      <div class="nav-icon">🎵</div>
      <div class="nav-label">موسیقی</div>
    </div>
    <div class="nav-item" data-view="study">
      <div class="nav-icon">📚</div>
      <div class="nav-label">کمک درسی</div>
    </div>
    <div class="nav-item" data-view="search">
      <div class="nav-icon">🔍</div>
      <div class="nav-label">جستجوی هوشمند</div>
    </div>
    <div class="sidebar-footer">
      ✨ نسخه <strong>نامحدود و رایگان</strong><br>
      Nova AI v2.0
    </div>
  </aside>

  <main class="main">
    <!-- Chat View -->
    <div class="view active" id="view-chat">
      <div class="view-header">
        <div class="view-title">گفتگو با هوش مصنوعی</div>
        <div class="view-subtitle">هر سوالی داری بپرس، از منابع معتبر پاسخ می‌گیرید</div>
      </div>
      <div class="chat-container">
        <div class="chat-messages" id="chatMessages">
          <div class="welcome">
            <div class="welcome-icon">✦</div>
            <h2>سلام! من Nova هستم 👋</h2>
            <p>دستیار هوشمند شما برای هر سوال و نیازی. چطور می‌تونم کمکتون کنم؟</p>
            <div class="suggestions">
              <div class="suggestion" onclick="useSuggestion('یه عکس از غروب دریا بساز')">
                <div class="suggestion-icon">🎨</div>
                <div>یه عکس از غروب دریا بساز</div>
              </div>
              <div class="suggestion" onclick="useSuggestion('معادله درجه دوم رو توضیح بده')">
                <div class="suggestion-icon">📐</div>
                <div>معادله درجه دوم رو توضیح بده</div>
              </div>
              <div class="suggestion" onclick="useSuggestion('آخرین اخبار تکنولوژی چیه؟')">
                <div class="suggestion-icon">📰</div>
                <div>آخرین اخبار تکنولوژی چیه؟</div>
              </div>
              <div class="suggestion" onclick="useSuggestion('یه آهنگ شاد پیشنهاد بده')">
                <div class="suggestion-icon">🎵</div>
                <div>یه آهنگ شاد پیشنهاد بده</div>
              </div>
            </div>
          </div>
        </div>
        <div class="chat-input-wrap">
          <div class="chat-input-box">
            <input type="text" class="chat-input" id="chatInput" placeholder="پیام خود را بنویسید..." />
            <button class="send-btn" id="sendBtn" onclick="sendMessage()">➤</button>
          </div>
        </div>
      </div>
    </div>

    <!-- Image View -->
    <div class="view" id="view-image">
      <div class="view-header">
        <div class="view-title">🎨 تولید تصویر با AI</div>
        <div class="view-subtitle">توضیح بدید چه تصویری می‌خواید، ما می‌سازیمش</div>
      </div>
      <div class="image-gen-grid">
        <div>
          <div class="card">
            <label style="font-size:13px;color:var(--muted);margin-bottom:8px;display:block;">توضیح تصویر (Prompt)</label>
            <div class="prompt-area">
              <textarea id="imgPrompt" placeholder="مثال: یک گربه فضانورد روی ماه، سبک انیمه، رنگ‌های زنده..."></textarea>
              <div class="style-chips">
                <div class="chip active" data-style="realistic">واقع‌گرایانه</div>
                <div class="chip" data-style="anime">انیمه</div>
                <div class="chip" data-style="oil painting">نقاشی رنگ روغن</div>
                <div class="chip" data-style="3d render">سه‌بعدی</div>
                <div class="chip" data-style="watercolor">آبرنگ</div>
                <div class="chip" data-style="cyberpunk">سایبرپانک</div>
              </div>
            </div>
            <button class="btn-primary" id="genImgBtn" onclick="generateImage()">✨ ساخت تصویر</button>
          </div>
          <div class="card">
            <div style="font-size:14px;font-weight:600;margin-bottom:12px;">🖼 گالری تصاویر ساخته‌شده</div>
            <div class="gallery" id="imgGallery"></div>
          </div>
        </div>
        <div>
          <div class="image-preview" id="imgPreview">
            <div class="placeholder">
              <div class="placeholder-icon">🖼</div>
              <div>تصویر شما اینجا نمایش داده می‌شود</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Music View -->
    <div class="view" id="view-music">
      <div class="view-header">
        <div class="view-title">🎵 جستجو و تولید موسیقی</div>
        <div class="view-subtitle">آهنگ مورد علاقه‌تان را جستجو کنید یا با AI بسازید</div>
      </div>
      <div class="card" style="margin-bottom:20px;">
        <div class="search-box" style="margin-bottom:0;">
          <input type="text" id="musicSearch" placeholder="جستجوی آهنگ، خواننده یا سبک..." />
          <button onclick="searchMusic()">جستجو</button>
        </div>
      </div>
      <div class="music-player">
        <div class="music-cover" id="musicCover">🎵</div>
        <div class="music-title" id="musicTitle">آهنگی انتخاب نشده</div>
        <div class="music-artist" id="musicArtist">یک آهنگ از لیست زیر انتخاب کنید</div>
        <div class="music-controls">
          <button class="music-btn" onclick="prevTrack()">⏮</button>
          <button class="music-btn play" id="playBtn" onclick="togglePlay()">▶</button>
          <button class="music-btn" onclick="nextTrack()">⏭</button>
        </div>
        <div class="progress-bar"><div class="progress-fill" id="progressFill"></div></div>
        <div class="music-time">
          <span id="curTime">0:00</span>
          <span id="totalTime">0:00</span>
        </div>
      </div>
      <div class="music-list" id="musicList"></div>
    </div>

    <!-- Study View -->
    <div class="view" id="view-study">
      <div class="view-header">
        <div class="view-title">📚 کمک درسی هوشمند</div>
        <div class="view-subtitle">پاسخ سوالات درسی همه پایه‌ها با توضیحات کامل</div>
      </div>
      <div class="card">
        <div style="font-size:14px;font-weight:600;margin-bottom:12px;">پایه تحصیلی را انتخاب کنید:</div>
        <div class="grade-selector" id="gradeSelector"></div>
      </div>
      <div class="card">
        <div style="font-size:14px;font-weight:600;margin-bottom:12px;">درس مورد نظر:</div>
        <div class="subject-grid" id="subjectGrid"></div>
      </div>
      <div class="card" id="studyChat" style="display:none;">
        <div style="font-size:14px;font-weight:600;margin-bottom:12px;" id="studyTopic"></div>
        <div id="studyContent" style="line-height:1.9;font-size:14px;"></div>
      </div>
    </div>

    <!-- Search View -->
    <div class="view" id="view-search">
      <div class="view-header">
        <div class="view-title">🔍 جستجوی هوشمند</div>
        <div class="view-subtitle">از منابع معتبر، پاسخ دقیق و به‌روز دریافت کنید</div>
      </div>
      <div class="search-box">
        <input type="text" id="searchInput" placeholder="هر چیزی که می‌خواهید بدانید..." />
        <button onclick="doSearch()">جستجو</button>
      </div>
      <div id="searchResults"></div>
    </div>
  </main>
</div>

<!-- Voice Overlay -->
<div class="voice-overlay" id="voiceOverlay">
  <div class="voice-circle">
    <div class="voice-ring"></div>
    <div class="voice-ring"></div>
    <div class="voice-ring"></div>
    🎙
  </div>
  <div class="voice-text" id="voiceText">در حال گوش دادن...</div>
  <button class="voice-close" onclick="stopVoice()">توقف</button>
</div>

<script>
// Navigation
document.querySelectorAll('.nav-item').forEach(item => {
  item.addEventListener('click', () => {
    document.querySelectorAll('.nav-item').forEach(n => n.classList.remove('active'));
    document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
    item.classList.add('active');
    document.getElementById('view-' + item.dataset.view).classList.add('active');
  });
});

// Chat AI
const chatMessages = document.getElementById('chatMessages');
const chatInput = document.getElementById('chatInput');
let welcomeRemoved = false;

function removeWelcome() {
  if (!welcomeRemoved) {
    const w = chatMessages.querySelector('.welcome');
    if (w) w.remove();
    welcomeRemoved = true;
  }
}

function addMessage(text, type, img) {
  removeWelcome();
  const msg = document.createElement('div');
  msg.className = 'msg ' + type;
  msg.innerHTML = `
    <div class="msg-avatar">${type === 'user' ? '👤' : '✦'}</div>
    <div class="msg-content">${text}${img ? `<img src="${img}" alt="">` : ''}</div>
  `;
  chatMessages.appendChild(msg);
  chatMessages.scrollTop = chatMessages.scrollHeight;
  return msg;
}

function addTyping() {
  removeWelcome();
  const msg = document.createElement('div');
  msg.className = 'msg ai';
  msg.id = 'typingMsg';
  msg.innerHTML = `
    <div class="msg-avatar">✦</div>
    <div class="msg-content"><div class="typing"><span></span><span></span><span></span></div></div>
  `;
  chatMessages.appendChild(msg);
  chatMessages.scrollTop = chatMessages.scrollHeight;
}

function removeTyping() {
  const t = document.getElementById('typingMsg');
  if (t) t.remove();
}

// Smart response generator
function generateAIResponse(input) {
  const text = input.toLowerCase();
  
  // Image generation request
  if (text.includes('عکس') || text.includes('تصویر') || text.includes('بساز') || text.includes('طراحی')) {
    const prompt = input.replace(/عکس|تصویر|بساز|طراحی کن|درست کن|یه|یک/g, '').trim();
    return {
      text: `حتماً! در حال ساخت تصویر "${prompt}" هستم. لطفاً چند لحظه صبر کنید...`,
      action: 'image',
      prompt: prompt || 'یک تصویر زیبا و خلاقانه'
    };
  }
  
  // Music request
  if (text.includes('آهنگ') || text.includes('موسیقی') || text.includes('ترانه')) {
    return {
      text: `🎵 چند پیشنهاد موسیقی برای شما:\n\n• "رویای شب" - سبک آرامش‌بخش\n• "رقص نور" - سبک الکترونیک\n• "نسیم صبح" - سبک پیانو\n\nبرای گوش دادن به بخش موسیقی بروید یا بگویید کدام سبک را دوست دارید.`
    };
  }
  
  // Math
  if (text.includes('معادله') || text.includes('ریاضی') || text.includes('محاسبه')) {
    return {
      text: `📐 <strong>معادله درجه دوم:</strong>\n\nفرم کلی: ax² + bx + c = 0\n\n<strong>فرمول حل:</strong>\nx = (-b ± √(b²-4ac)) / 2a\n\n<strong>مثال:</strong> x² - 5x + 6 = 0\n• a=1, b=-5, c=6\n• Δ = 25-24 = 1\n• x₁ = (5+1)/2 = 3\n• x₂ = (5-1)/2 = 2\n\n<span class="source-tag">منبع: کتاب ریاضی دبیرستان</span>`
    };
  }
  
  // Science
  if (text.includes('فیزیک') || text.includes('شیمی') || text.includes('زیست')) {
    return {
      text: `🔬 بله! در کدام موضوع نیاز به توضیح دارید؟\n\n• <strong>فیزیک:</strong> مکانیک، الکتریسیته، نور، ترمودینامیک\n• <strong>شیمی:</strong> ساختار اتم، واکنش‌ها، ترکیبات\n• <strong>زیست:</strong> سلول، ژنتیک، اکوسیستم\n\nسوال دقیق‌تر خود را بپرسید تا توضیح کامل بدم.`
    };
  }
  
  // News
  if (text.includes('اخبار') || text.includes('تکنولوژی') || text.includes('جدید')) {
    return {
      text: `📰 <strong>آخرین تحولات تکنولوژی:</strong>\n\n• هوش مصنوعی مولد در حال تحول صنایع مختلف است\n• پیشرفت‌های جدید در پردازنده‌های کوانتومی\n• گسترش واقعیت افزوده در موبایل‌ها\n• توسعه خودروهای خودران\n\n<span class="source-tag">منبع: TechCrunch</span> <span class="source-tag">منبع: Wired</span>`
    };
  }
  
  // Greeting
  if (text.includes('سلام') || text.includes('درود') || text.includes('hello')) {
    return {
      text: `سلام! 👋 خوشحالم که اینجایید. من Nova هستم و می‌تونم در این زمینه‌ها کمکتون کنم:\n\n💬 پاسخ به سوالات عمومی و تخصصی\n🎨 ساخت تصویر با AI\n🎵 جستجو و پیشنهاد موسیقی\n📚 کمک درسی همه پایه‌ها\n🔍 جستجوی هوشمند\n\nچطور می‌تونم کمکتون کنم؟`
    };
  }
  
  // Default smart response
  const responses = [
    `سوال جالبی پرسیدید! 🤔\n\nبر اساس اطلاعات موجود، می‌تونم بگم که این موضوع از چند جنبه قابل بررسی است. آیا می‌خواهید جزئیات بیشتری در مورد بخش خاصی بدانید؟\n\n<span class="source-tag">منبع: دانشنامه معتبر</span>`,
    `این یک موضوع مهم است. 💡\n\nطبق منابع علمی و آموزشی، پاسخ به این سوال نیاز به بررسی چند عامل دارد. پیشنهاد می‌کنم برای اطلاعات دقیق‌تر، سوال را کمی جزئی‌تر بپرسید.\n\n<span class="source-tag">منبع: ویکی‌پدیا</span> <span class="source-tag">منبع: Britannica</span>`,
    `بله، می‌تونم در این مورد کمکتون کنم. ✨\n\nاین موضوع در حوزه‌های مختلفی کاربرد داره. اگه مایل باشید، می‌تونم توضیحات کامل‌تری با مثال ارائه بدم.\n\n<span class="source-tag">منبع: منابع آموزشی</span>`
  ];
  
  return { text: responses[Math.floor(Math.random() * responses.length)] };
}

async function sendMessage() {
  const text = chatInput.value.trim();
  if (!text) return;
  
  addMessage(text, 'user');
  chatInput.value = '';
  addTyping();
  
  const response = generateAIResponse(text);
  
  // Check if image generation
  if (response.action === 'image') {
    setTimeout(async () => {
      removeTyping();
      addMessage('در حال ساخت تصویر... 🎨', 'ai');
      try {
        const imgUrl = await window.imageGenAPI(response.prompt);
        addMessage(`تصویر "${response.prompt}" آماده شد! ✨`, 'ai', imgUrl);
      } catch(e) {
        addMessage('متأسفانه در ساخت تصویر مشکلی پیش آمد. لطفاً دوباره تلاش کنید.', 'ai');
      }
    }, 1500);
  } else {
    setTimeout(() => {
      removeTyping();
      addMessage(response.text.replace(/\n/g, '<br>'), 'ai');
    }, 1000 + Math.random() * 800);
  }
}

function useSuggestion(text) {
  chatInput.value = text;
  sendMessage();
}

chatInput.addEventListener('keypress', e => {
  if (e.key === 'Enter') sendMessage();
});

// Image Generation
let currentStyle = 'realistic';
document.querySelectorAll('.chip').forEach(chip => {
  chip.addEventListener('click', () => {
    document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
    chip.classList.add('active');
    currentStyle = chip.dataset.style;
  });
});

const gallery = document.getElementById('imgGallery');
const imgPreview = document.getElementById('imgPreview');
const genImgBtn = document.getElementById('genImgBtn');

async function generateImage() {
  const prompt = document.getElementById('imgPrompt').value.trim();
  if (!prompt) {
    alert('لطفاً توضیح تصویر را وارد کنید');
    return;
  }
  
  genImgBtn.disabled = true;
  genImgBtn.textContent = '⏳ در حال ساخت...';
  imgPreview.innerHTML = '<div class="loader"></div>';
  
  try {
    const fullPrompt = `${prompt}, ${currentStyle} style, high quality, detailed`;
    const url = await window.imageGenAPI(fullPrompt);
    imgPreview.innerHTML = `<img src="${url}" alt="${prompt}">`;
    
    // Add to gallery
    const item = document.createElement('div');
    item.className = 'gallery-item';
    item.innerHTML = `<img src="${url}" alt="">`;
    item.onclick = () => { imgPreview.innerHTML = `<img src="${url}" alt="">`; };
    gallery.prepend(item);
  } catch(e) {
    imgPreview.innerHTML = '<div class="placeholder"><div class="placeholder-icon">⚠️</div><div>خطا در ساخت تصویر</div></div>';
  }
  
  genImgBtn.disabled = false;
  genImgBtn.textContent = '✨ ساخت تصویر';
}

// Music
const musicData = [
  { title: 'رویای شب', artist: 'Nova AI', duration: '3:24', genre: 'آرامش‌بخش' },
  { title: 'رقص نور', artist: 'Nova AI', duration: '4:12', genre: 'الکترونیک' },
  { title: 'نسیم صبح', artist: 'Nova AI', duration: '2:58', genre: 'پیانو' },
  { title: 'سفر در زمان', artist: 'Nova AI', duration: '3:45', genre: 'امبینت' },
  { title: 'ستاره‌ها', artist: 'Nova AI', duration: '4:30', genre: 'کلاسیک' },
  { title: 'دریای آرام', artist: 'Nova AI', duration: '3:15', genre: 'طبیعت' },
];

const musicList = document.getElementById('musicList');
let currentTrack = 0;
let isPlaying = false;
let progressInterval;

function renderMusicList(filter = '') {
  musicList.innerHTML = '';
  musicData.forEach((m, i) => {
    if (filter && !m.title.includes(filter) && !m.artist.includes(filter) && !m.genre.includes(filter)) return;
    const item = document.createElement('div');
    item.className = 'music-item' + (i === currentTrack ? ' active' : '');
    item.innerHTML = `
      <div class="music-item-icon">🎵</div>
      <div class="music-item-info">
        <div class="music-item-title">${m.title}</div>
        <div class="music-item-sub">${m.artist} • ${m.genre}</div>
      </div>
      <div class="music-item-dur">${m.duration}</div>
    `;
    item.onclick = () => selectTrack(i);
    musicList.appendChild(item);
  });
}

function selectTrack(i) {
  currentTrack = i;
  const m = musicData[i];
  document.getElementById('musicTitle').textContent = m.title;
  document.getElementById('musicArtist').textContent = m.artist + ' • ' + m.genre;
  document.getElementById('totalTime').textContent = m.duration;
  renderMusicList();
  if (!isPlaying) togglePlay();
}

function togglePlay() {
  isPlaying = !isPlaying;
  document.getElementById('playBtn').textContent = isPlaying ? '⏸' : '▶';
  if (isPlaying) {
    let prog = parseFloat(document.getElementById('progressFill').style.width) || 0;
    progressInterval = setInterval(() => {
      prog += 0.5;
      if (prog > 100) { prog = 0; nextTrack(); }
      document.getElementById('progressFill').style.width = prog + '%';
      const [mm, ss] = musicData[currentTrack].duration.split(':').map(Number);
      const total = mm * 60 + ss;
      const cur = Math.floor(total * prog / 100);
      document.getElementById('curTime').textContent = Math.floor(cur/60) + ':' + String(cur%60).padStart(2,'0');
    }, 300);
  } else {
    clearInterval(progressInterval);
  }
}

function nextTrack() {
  currentTrack = (currentTrack + 1) % musicData.length;
  selectTrack(currentTrack);
}

function prevTrack() {
  currentTrack = (currentTrack - 1 + musicData.length) % musicData.length;
  selectTrack(currentTrack);
}

function searchMusic() {
  const q = document.getElementById('musicSearch').value.trim();
  renderMusicList(q);
}

renderMusicList();

// Study
const grades = ['اول', 'دوم', 'سوم', 'چهارم', 'پنجم', 'ششم', 'هفتم', 'هشتم', 'نهم', 'دهم', 'یازدهم', 'دوازدهم'];
const subjects = {
  'اول': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🎨 هنر'],
  'دوم': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🎨 هنر'],
  'سوم': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🏛 مطالعات'],
  'چهارم': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🏛 مطالعات'],
  'پنجم': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🏛 مطالعات'],
  'ششم': ['📖 فارسی', '🔢 ریاضی', '🌿 علوم', '📿 قرآن', '🏛 مطالعات'],
  'هفتم': ['📖 فارسی', '🔢 ریاضی', '🧪 علوم', '🕌 دینی', '🏛 مطالعات', '🇬🇧 انگلیسی'],
  'هشتم': ['📖 فارسی', '🔢 ریاضی', '🧪 علوم', '🕌 دینی', '🏛 مطالعات', '🇬🇧 انگلیسی'],
  'نهم': ['📖 فارسی', '🔢 ریاضی', '🧪 علوم', '🕌 دینی', '🏛 مطالعات', '🇬🇧 انگلیسی'],
  'دهم': ['📖 فارسی', '🔢 ریاضی', '🧪 فیزیک', '🧬 شیمی', '🌱 زیست', '🕌 دینی', '🏛 مطالعات'],
  'یازدهم': ['📖 فارسی', '🔢 ریاضی', '🧪 فیزیک', '🧬 شیمی', '🌱 زیست', '🕌 دینی'],
  'دوازدهم': ['📖 فارسی', '🔢 ریاضی', '🧪 فیزیک', '🧬 شیمی', '🌱 زیست', '🕌 دینی'],
};

let selectedGrade = null;
const gradeSelector = document.getElementById('gradeSelector');
const subjectGrid = document.getElementById('subjectGrid');

grades.forEach(g => {
  const btn = document.createElement('button');
  btn.className = 'grade-btn';
  btn.textContent = 'پایه ' + g;
  btn.onclick = () => {
    document.querySelectorAll('.grade-btn').forEach(b => b.classList.remove('active'));
    btn.classList.add('active');
    selectedGrade = g;
    renderSubjects(g);
  };
  gradeSelector.appendChild(btn);
});

function renderSubjects(grade) {
  subjectGrid.innerHTML = '';
  (subjects[grade] || []).forEach(s => {
    const card = document.createElement('div');
    card.className = 'subject-card';
    const [icon, name] = [s.split(' ')[0], s.split(' ').slice(1).join(' ')];
    card.innerHTML = `<div class="subject-icon">${icon}</div><div class="subject-name">${name}</div>`;
    card.onclick = () => showStudyContent(grade, name);
    subjectGrid.appendChild(card);
  });
}

function showStudyContent(grade, subject) {
  const chat = document.getElementById('studyChat');
  chat.style.display = 'block';
  document.getElementById('studyTopic').textContent = `📚 پایه ${grade} - ${subject}`;
  
  const contents = {
    'ریاضی': `<strong>مفاهیم پایه ریاضی پایه ${grade}:</strong><br><br>
      • <strong>اعداد و محاسبات:</strong> جمع، تفریق، ضرب و تقسیم<br>
      • <strong>کسرها:</strong> مفهوم کسر، جمع و تفریق کسرها<br>
      • <strong>هندسه:</strong> اشکال دوبعدی و دوبعدی، محیط و مساحت<br>
      • <strong>آمار و احتمال:</strong> میانگین، میانه، مد<br><br>
      <em>💡 نکته: برای یادگیری بهتر ریاضی، حتماً تمرین روزانه داشته باشید.</em>`,
    'فارسی': `<strong>درس‌های فارسی پایه ${grade}:</strong><br><br>
      • <strong>دستور زبان:</strong> نهاد، گزاره، مفعول، فعل<br>
      • <strong>آرایه‌های ادبی:</strong> تشبیه، استعاره، جان‌بخشی<br>
      • <strong>املا و نگارش:</strong> قواعد املایی و انشانویسی<br>
      • <strong>تاریخ ادبیات:</strong> شاعران و نویسندگان بزرگ<br><br>
      <em>💡 نکته: خواندن کتاب‌های غیردرسی به تقویت فارسی کمک می‌کند.</em>`,
    'علوم': `<strong>مباحث علوم پایه ${grade}:</strong><br><br>
      • <strong>زیست‌شناسی:</strong> سلول، گیاهان، جانوران<br>
      • <strong>فیزیک:</strong> نیرو، انرژی، حرکت<br>
      • <strong>شیمی:</strong> مواد، ترکیبات، واکنش‌ها<br>
      • <strong>زمین‌شناسی:</strong> سنگ‌ها، خاک، آب<br><br>
      <em>💡 نکته: انجام آزمایش‌های ساده در خانه یادگیری را جذاب می‌کند.</em>`,
    'فیزیک': `<strong>مباحث فیزیک پایه ${grade}:</strong><br><br>
      • <strong>مکانیک:</strong> حرکت، نیرو، قوانین نیوتن<br>
      • <strong>الکتریسیته:</strong> جریان، ولتاژ، مقاومت<br>
      • <strong>نور و اپتیک:</strong> بازتاب، شکست، عدسی<br>
      • <strong>ترمودینامیک:</strong> دما، گرما، انتقال حرارت<br><br>
      <em>💡 فرمول مهم: F = m × a (نیرو = جرم × شتاب)</em>`,
    'شیمی': `<strong>مباحث شیمی پایه ${grade}:</strong><br><br>
      • <strong>ساختار اتم:</strong> پروتون، نوترون، الکترون<br>
      • <strong>جدول تناوبی:</strong> گروه‌ها و دوره‌ها<br>
      • <strong>پیوندهای شیمیایی:</strong> یونی، کووالانسی<br>
      • <strong>واکنش‌های شیمیایی:</strong> موازنه و انواع<br><br>
      <em>💡 نکته: حفظ کردن جدول تناوبی با روش‌های خلاقانه آسان‌تر است.</em>`,
  };
  
  document.getElementById('studyContent').innerHTML = contents[subject] || 
    `<strong>محتوای درس ${subject} پایه ${grade}:</strong><br><br>
     برای دریافت توضیحات دقیق‌تر و پاسخ به سوالات خاص، لطفاً سوال خود را در بخش گفتگو بپرسید.<br><br>
     💡 من آماده‌ام تا در هر مبحثی از این درس به شما کمک کنم. سوالتان را بپرسید!`;
  
  chat.scrollIntoView({ behavior: 'smooth' });
}

// Search
function doSearch() {
  const q = document.getElementById('searchInput').value.trim();
  if (!q) return;
  
  const results = document.getElementById('searchResults');
  results.innerHTML = '<div style="text-align:center;padding:30px;"><div class="loader" style="margin:0 auto;"></div></div>';
  
  setTimeout(() => {
    const sampleResults = [
      { title: `تعریف و توضیح "${q}"`, text: `${q} یکی از مفاهیم مهم در حوزه خود است که در منابع علمی مختلف مورد بررسی قرار گرفته. این موضوع از جنبه‌های مختلفی قابل تحلیل است و کاربردهای گسترده‌ای در زندگی روزمره و صنعت دارد.`, sources: ['ویکی‌پدیا', 'Britannica'] },
      { title: `تاریخچه و پیشینه ${q}`, text: `بررسی‌های تاریخی نشان می‌دهد که ${q} از دیرباز مورد توجه پژوهشگران بوده است. در طول قرن‌های گذشته، تحولات بسیاری در درک ما از این موضوع رخ داده است.`, sources: ['دانشنامه جهان', 'منابع دانشگاهی'] },
      { title: `کاربردهای مدرن ${q}`, text: `امروزه ${q} در زمینه‌های مختلفی از جمله تکنولوژی، پزشکی، آموزش و صنعت کاربرد دارد. تحقیقات جدید نشان‌دهنده پتانسیل بالای این حوزه برای آینده است.`, sources: ['Nature', 'Science Daily'] },
    ];
    
    results.innerHTML = `<div style="margin-bottom:16px;color:var(--muted);font-size:13px;">نتایج جستجو برای: <strong style="color:var(--text);">${q}</strong></div>`;
    sampleResults.forEach(r => {
      const item = document.createElement('div');
      item.className = 'result-item';
      item.innerHTML = `
        <div class="result-title">${r.title}</div>
        <div class="result-text">${r.text}<br><br>${r.sources.map(s => `<span class="source-tag">${s}</span>`).join('')}</div>
      `;
      results.appendChild(item);
    });
  }, 800);
}

document.getElementById('searchInput').addEventListener('keypress', e => {
  if (e.key === 'Enter') doSearch();
});

// Voice
const voiceBtn = document.getElementById('voiceBtn');
const voiceOverlay = document.getElementById('voiceOverlay');
const voiceText = document.getElementById('voiceText');
let recognition = null;

voiceBtn.addEventListener('click', () => {
  if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
    alert('مرورگر شما از تشخیص صدا پشتیبانی نمی‌کند. لطفاً از Chrome استفاده کنید.');
    return;
  }
  voiceOverlay.classList.add('active');
  voiceBtn.classList.add('active');
  
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  recognition = new SpeechRecognition();
  recognition.lang = 'fa-IR';
  recognition.continuous = false;
  recognition.interimResults = true;
  
  recognition.onresult = (e) => {
    const transcript = Array.from(e.results).map(r => r[0].transcript).join('');
    voiceText.textContent = transcript || 'در حال گوش دادن...';
    if (e.results[0].isFinal) {
      setTimeout(() => {
        stopVoice();
        // Switch to chat and send
        document.querySelector('[data-view="chat"]').click();
        chatInput.value = transcript;
        sendMessage();
      }, 500);
    }
  };
  
  recognition.onerror = () => {
    voiceText.textContent = 'خطا در تشخیص صدا. دوباره تلاش کنید.';
    setTimeout(stopVoice, 1500);
  };
  
  recognition.onend = () => {
    if (voiceOverlay.classList.contains('active')) {
      voiceText.textContent = 'پایان. برای شروع دوباره کلیک کنید.';
      setTimeout(stopVoice, 1000);
    }
  };
  
  recognition.start();
});

function stopVoice() {
  voiceOverlay.classList.remove('active');
  voiceBtn.classList.remove('active');
  if (recognition) {
    try { recognition.stop(); } catch(e) {}
    recognition = null;
  }
}

// Image gen API bridge
window.imageGenAPI = async (prompt) => {
  // This will be replaced by actual tool call in the environment
  return new Promise((resolve, reject) => {
    window._pendingImageResolve = resolve;
    window._pendingImageReject = reject;
    window._pendingImagePrompt = prompt;
    // Trigger custom event for the host to handle
    window.dispatchEvent(new CustomEvent('novaImageRequest', { detail: { prompt } }));
  });
};

// Listen for image results from host
window.addEventListener('novaImageResult', (e) => {
  if (window._pendingImageResolve) {
    window._pendingImageResolve(e.detail.url);
    window._pendingImageResolve = null;
  }
});
</script>

</body>
</html>