File size: 90,081 Bytes
cc09c8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Ebook Generator - Pro (Fixed)</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #6b73ff 0%, #000dff 100%);
        }
        .ebook-preview {
            min-height: 500px;
            background: linear-gradient(to bottom, #f8fafc, #e2e8f0);
        }
        .chapter-item:hover {
            transform: translateX(5px);
            transition: transform 0.2s ease;
        }
        .loading-dots:after {
            content: '.';
            animation: dots 1.5s steps(5, end) infinite;
        }
        @keyframes dots {
            0%, 20% { content: '.'; }
            40% { content: '..'; }
            60% { content: '...'; }
            80%, 100% { content: ''; }
        }
        .tab-content {
            display: none;
        }
        .tab-content.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        .plan-card {
            transition: all 0.3s ease;
        }
        .plan-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .premium-badge {
            position: absolute;
            top: -10px;
            right: -10px;
            background: linear-gradient(45deg, #ff9500, #ff5e00);
            color: white;
            padding: 3px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: bold;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .api-status {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            display: inline-block;
            margin-right: 5px;
        }
        .api-status.connected {
            background-color: #10B981;
            animation: pulse 1.5s infinite;
        }
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.2); }
            100% { transform: scale(1); }
        }
        .api-status.disconnected {
            background-color: #EF4444;
        }
        .toggle-checkbox:checked {
            right: 0;
            border-color: #3B82F6;
        }
        .toggle-checkbox:checked + .toggle-label {
            background-color: #3B82F6;
        }
        .cover-preview {
            width: 150px;
            height: 200px;
            background-size: cover;
            background-position: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        .cover-preview:hover {
            transform: scale(1.05);
        }
        .color-option {
            width: 25px;
            height: 25px;
            cursor: pointer;
            border: 2px solid transparent;
            transition: all 0.2s ease;
        }
        .color-option:hover {
            transform: scale(1.1);
        }
        .color-option.selected {
            border-color: #000;
        }
        .format-option {
            border: 2px solid #e5e7eb;
            cursor: pointer;
            transition: all 0.3s;
        }
        .format-option:hover {
            border-color: #3B82F6;
        }
        .format-option.active {
            border-color: #3B82F6;
            background-color: #eff6ff;
        }
        .tab-button {
            position: relative;
            padding-bottom: 5px;
        }
        .tab-button.active:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background-color: #3B82F6;
            border-radius: 3px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <div class="min-h-screen">
        <!-- Header -->
        <header class="gradient-bg text-white shadow-lg">
            <div class="container mx-auto px-4 py-6">
                <div class="flex justify-between items-center">
                    <div class="flex items-center space-x-2">
                        <i class="fas fa-book-open text-2xl"></i>
                        <h1 class="text-2xl font-bold">AI Ebook Generator Pro</h1>
                    </div>
                    <nav>
                        <ul class="flex space-x-6">
                            <li>
                                <a href="#" class="tab-button hover:underline active" onclick="showTab('generator')">Generator</a>
                            </li>
                            <li>
                                <a href="#" class="tab-button hover:underline" onclick="showTab('format-settings')">Format & Design</a>
                            </li>
                            <li>
                                <a href="#" class="tab-button hover:underline" onclick="showTab('publish-settings')">Publishing</a>
                            </li>
                            <li>
                                <a href="#" class="tab-button hover:underline" onclick="showTab('api-settings')">API Settings</a>
                            </li>
                            <li>
                                <a href="#" class="tab-button hover:underline" onclick="showTab('my-ebooks')">My Ebooks</a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>

        <!-- Main Content -->
        <main class="container mx-auto px-4 py-8">
            <!-- Generator Tab -->
            <div id="generator-tab" class="tab-content active">
                <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
                    <!-- Generator Form -->
                    <div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6 h-fit sticky top-8">
                        <h2 class="text-xl font-semibold mb-4 text-gray-800">Create Your Ebook</h2>
                        
                        <form id="ebookForm" class="space-y-4">
                            <div>
                                <label for="ebookTitle" class="block text-sm font-medium text-gray-700 mb-1">Ebook Title*</label>
                                <input type="text" id="ebookTitle" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Enter ebook title" required>
                            </div>
                            
                            <div>
                                <label for="ebookSubtitle" class="block text-sm font-medium text-gray-700 mb-1">Subtitle</label>
                                <input type="text" id="ebookSubtitle" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Enter subtitle">
                            </div>
                            
                            <div>
                                <label for="authorName" class="block text-sm font-medium text-gray-700 mb-1">Author Name*</label>
                                <input type="text" id="authorName" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Your name or pen name" required>
                            </div>
                            
                            <div>
                                <label for="ebookTopic" class="block text-sm font-medium text-gray-700 mb-1">Main Topic*</label>
                                <input type="text" id="ebookTopic" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="e.g. Digital Marketing" required>
                            </div>
                            
                            <div>
                                <label for="ebookKeywords" class="block text-sm font-medium text-gray-700 mb-1">Keywords (comma separated)</label>
                                <textarea id="ebookKeywords" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="SEO, content marketing, social media"></textarea>
                            </div>
                            
                            <div>
                                <label for="ebookSummary" class="block text-sm font-medium text-gray-700 mb-1">Brief Summary*</label>
                                <textarea id="ebookSummary" rows="4" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Describe what your ebook should cover" required></textarea>
                            </div>
                            
                            <div>
                                <label for="chapterCount" class="block text-sm font-medium text-gray-700 mb-1">Number of Chapters</label>
                                <select id="chapterCount" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="5">5 Chapters</option>
                                    <option value="7" selected>7 Chapters</option>
                                    <option value="10">10 Chapters</option>
                                    <option value="12">12 Chapters</option>
                                </select>
                            </div>
                            
                            <div>
                                <label for="writingStyle" class="block text-sm font-medium text-gray-700 mb-1">Writing Style</label>
                                <select id="writingStyle" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="professional">Professional</option>
                                    <option value="casual">Casual</option>
                                    <option value="academic">Academic</option>
                                    <option value="storytelling">Storytelling</option>
                                </select>
                            </div>
                            
                            <div class="pt-2">
                                <button type="submit" id="generateBtn" class="w-full gradient-bg text-white py-3 px-6 rounded-lg font-medium hover:opacity-90 transition duration-300 flex items-center justify-center">
                                    <i class="fas fa-magic mr-2"></i> Continue to Format Settings
                                </button>
                            </div>
                        </form>
                    </div>
                    
                    <!-- Ebook Preview -->
                    <div class="lg:col-span-2">
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6 border-b border-gray-200">
                                <h2 class="text-xl font-semibold text-gray-800">Ebook Preview</h2>
                                <p class="text-sm text-gray-500">Configure your ebook settings to see a preview</p>
                            </div>
                            
                            <div id="ebookPreview" class="ebook-preview p-8">
                                <div id="emptyState" class="flex flex-col items-center justify-center h-full text-center py-20">
                                    <i class="fas fa-book-reader text-6xl text-gray-300 mb-4"></i>
                                    <h3 class="text-xl font-medium text-gray-500 mb-2">No Ebook Generated Yet</h3>
                                    <p class="text-gray-400 max-w-md">Fill out the form and click "Continue" to configure your ebook settings.</p>
                                </div>
                                
                                <div id="loadingState" class="hidden flex flex-col items-center justify-center h-full text-center py-20">
                                    <div class="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-blue-500 mb-4"></div>
                                    <h3 class="text-xl font-medium text-gray-700 mb-2">Generating Your Ebook</h3>
                                    <p class="text-gray-500 max-w-md">This may take a few moments...</p>
                                </div>
                                
                                <div id="ebookContent" class="hidden">
                                    <div class="flex justify-between items-start mb-6">
                                        <div>
                                            <h1 id="previewTitle" class="text-3xl font-bold text-gray-800">Your Ebook Title</h1>
                                            <h2 id="previewSubtitle" class="text-xl text-gray-600 mt-1">Your Ebook Subtitle</h2>
                                            <p class="text-gray-500 text-sm mt-2">by <span id="previewAuthor">Author Name</span></p>
                                        </div>
                                        <p id="generatedTime" class="text-gray-400 text-xs">Generated just now</p>
                                    </div>
                                    
                                    <div class="border-t border-b border-gray-200 py-4 my-4">
                                        <h3 class="font-semibold text-gray-700 mb-2">Table of Contents</h3>
                                        <div id="tocList" class="space-y-2"></div>
                                    </div>
                                    
                                    <div id="chaptersContainer"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Format & Design Tab -->
            <div id="format-settings-tab" class="tab-content">
                <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
                    <!-- Format Settings Form -->
                    <div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6 h-fit sticky top-8">
                        <h2 class="text-xl font-semibold mb-4 text-gray-800">Format & Design Settings</h2>
                        
                        <div class="space-y-6">
                            <!-- Format Selection -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Ebook Format</h3>
                                <div class="grid grid-cols-3 gap-2 mb-4">
                                    <div class="format-option active p-2 rounded-lg text-center" data-format="6x9" onclick="selectFormat('6x9', this)">
                                        <p class="text-sm font-medium">6" × 9"</p>
                                        <p class="text-xs text-gray-500">Standard</p>
                                    </div>
                                    <div class="format-option p-2 rounded-lg text-center" data-format="5x8" onclick="selectFormat('5x8', this)">
                                        <p class="text-sm font-medium">5" × 8"</p>
                                        <p class="text-xs text-gray-500">Novel</p>
                                    </div>
                                    <div class="format-option p-2 rounded-lg text-center" data-format="a5" onclick="selectFormat('a5', this)">
                                        <p class="text-sm font-medium">A5</p>
                                        <p class="text-xs text-gray-500">International</p>
                                    </div>
                                </div>
                                <select id="pageSize" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="6x9">6 × 9 inches (Standard)</option>
                                    <option value="5x8">5 × 8 inches (Novel)</option>
                                    <option value="a5">A5 (148 × 210 mm)</option>
                                    <option value="a4">A4 (210 × 297 mm)</option>
                                    <option value="custom">Custom Size</option>
                                </select>
                            </div>
                            
                            <!-- File Formats -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Output Formats</h3>
                                <div class="space-y-2">
                                    <div class="flex items-center">
                                        <input type="checkbox" id="formatPDF" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="formatPDF" class="text-sm text-gray-700">PDF (Print & Digital)</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="formatEPUB" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="formatEPUB" class="text-sm text-gray-700">EPUB (Amazon, Apple)</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="formatMOBI" class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="formatMOBI" class="text-sm text-gray-700">MOBI (Legacy Kindle)</label>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Template Selection -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Design Template</h3>
                                <select id="designTemplate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="modern">Modern Professional</option>
                                    <option value="minimal">Minimalist</option>
                                    <option value="creative">Creative Design</option>
                                    <option value="academic">Academic</option>
                                </select>
                            </div>
                            
                            <!-- Font Settings -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Typography</h3>
                                <div class="grid grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Body Font</label>
                                        <select id="bodyFont" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                            <option value="serif">Serif (Traditional)</option>
                                            <option value="sans-serif" selected>Sans-serif (Modern)</option>
                                            <option value="monospace">Monospace (Technical)</option>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Font Size</label>
                                        <select id="fontSize" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                            <option value="11">11 pt</option>
                                            <option value="12" selected>12 pt</option>
                                            <option value="13">13 pt</option>
                                            <option value="14">14 pt</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Color Scheme -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Color Scheme</h3>
                                <div class="flex space-x-2 mb-4">
                                    <div class="color-option selected bg-blue-600 rounded-full" data-color="blue" onclick="selectColor('blue', this)"></div>
                                    <div class="color-option bg-green-600 rounded-full" data-color="green" onclick="selectColor('green', this)"></div>
                                    <div class="color-option bg-red-600 rounded-full" data-color="red" onclick="selectColor('red', this)"></div>
                                    <div class="color-option bg-purple-600 rounded-full" data-color="purple" onclick="selectColor('purple', this)"></div>
                                    <div class="color-option bg-indigo-600 rounded-full" data-color="indigo" onclick="selectColor('indigo', this)"></div>
                                    <div class="color-option bg-yellow-500 rounded-full" data-color="yellow" onclick="selectColor('yellow', this)"></div>
                                </div>
                            </div>
                            
                            <!-- Cover Design -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Cover Design</h3>
                                <div class="space-y-3">
                                    <div class="flex items-center justify-between">
                                        <label class="block text-sm text-gray-600">Auto-generate Cover</label>
                                        <div class="relative inline-block w-10 mr-2 align-middle select-none">
                                            <input type="checkbox" id="autoCover" checked class="toggle-checkbox absolute block w-6 h-6 rounded-full bg-white border-4 appearance-none cursor-pointer"/>
                                            <label for="autoCover" class="toggle-label block overflow-hidden h-6 rounded-full bg-gray-300 cursor-pointer"></label>
                                        </div>
                                    </div>
                                    <div id="coverOptions" class="space-y-3">
                                        <div>
                                            <label class="block text-sm text-gray-600 mb-1">Cover Style</label>
                                            <select id="coverStyle" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                                <option value="modern">Modern</option>
                                                <option value="minimal">Minimal</option>
                                                <option value="professional">Professional</option>
                                                <option value="vintage">Vintage</option>
                                            </select>
                                        </div>
                                        <div class="flex space-x-2">
                                            <button onclick="randomizeCover()" class="flex-1 bg-gray-100 hover:bg-gray-200 text-gray-700 py-1 px-3 rounded-lg text-sm transition duration-300">
                                                <i class="fas fa-random mr-1"></i> Randomize
                                            </button>
                                            <button onclick="uploadCover()" class="flex-1 bg-gray-100 hover:bg-gray-200 text-gray-700 py-1 px-3 rounded-lg text-sm transition duration-300">
                                                <i class="fas fa-upload mr-1"></i> Upload
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Buttons -->
                            <div class="pt-4 space-y-3">
                                <button onclick="previewEbook()" class="w-full bg-blue-100 hover:bg-blue-200 text-blue-800 py-2 px-4 rounded-lg font-medium transition duration-300">
                                    <i class="fas fa-eye mr-2"></i> Preview Changes
                                </button>
                                <button onclick="showTab('publish-settings')" class="w-full gradient-bg text-white py-3 px-6 rounded-lg font-medium hover:opacity-90 transition duration-300">
                                    Continue to Publishing Settings
                                </button>
                                <button onclick="showTab('generator')" class="w-full bg-gray-100 hover:bg-gray-200 text-gray-700 py-2 px-4 rounded-lg transition duration-300">
                                    <i class="fas fa-arrow-left mr-2"></i> Back
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Cover Preview -->
                    <div class="lg:col-span-1">
                        <div class="bg-white rounded-xl shadow-md p-6 h-fit sticky top-8">
                            <h2 class="text-xl font-semibold mb-4 text-gray-800">Cover Preview</h2>
                            <div class="space-y-4">
                                <div id="coverPreview" class="cover-preview mx-auto bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center">
                                    <div class="text-center p-4">
                                        <h3 id="coverTitle" class="text-xl font-bold text-white mb-1">Your Ebook Title</h3>
                                        <p id="coverAuthor" class="text-sm text-blue-100">by Author Name</p>
                                    </div>
                                </div>
                                <div class="text-center">
                                    <p class="text-sm text-gray-500">This is a preview of your generated cover</p>
                                </div>
                                <div class="mt-4 p-4 bg-gray-50 rounded-lg border border-gray-200">
                                    <h3 class="text-sm font-medium text-gray-700 mb-2">Cover Settings</h3>
                                    <p class="text-xs text-gray-500"><span id="coverFormatDisplay">6 × 9 inches</span> • <span id="coverStyleDisplay">Modern</span></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Content Preview -->
                    <div class="lg:col-span-1">
                        <div class="bg-white rounded-xl shadow-md p-6 h-full">
                            <h2 class="text-xl font-semibold mb-4 text-gray-800">Interior Preview</h2>
                            <div id="interiorPreview" class="border border-gray-200 p-6 rounded-lg" style="min-height: 400px;">
                                <h3 class="text-lg font-medium text-gray-800 mb-2">Chapter 1</h3>
                                <p class="text-sm text-gray-700 leading-relaxed">This is a preview of how your ebook content will appear with the selected template and formatting options. The actual content will be generated based on your inputs.</p>
                                <p class="text-sm text-gray-700 leading-relaxed mt-3">You can adjust the font, size, colors, and layout to match your preferences. Changes will be reflected in this preview as you make them.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Publishing Settings Tab -->
            <div id="publish-settings-tab" class="tab-content">
                <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
                    <!-- Publishing Form -->
                    <div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6 h-fit sticky top-8">
                        <h2 class="text-xl font-semibold mb-4 text-gray-800">Publishing Settings</h2>
                        
                        <div class="space-y-6">
                            <!-- ISBN Settings -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">ISBN</h3>
                                <div class="space-y-2 mb-3">
                                    <div class="flex items-center">
                                        <input type="radio" id="isbnAuto" name="isbnOption" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500">
                                        <label for="isbnAuto" class="text-sm text-gray-700">Auto-generate free ISBN</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="radio" id="isbnProvide" name="isbnOption" class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500">
                                        <label for="isbnProvide" class="text-sm text-gray-700">Provide my own ISBN</label>
                                    </div>
                                </div>
                                <input id="isbnInput" type="text" disabled class="w-full px-4 py-2 border border-gray-300 rounded-lg bg-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="Enter ISBN">
                            </div>
                            
                            <!-- Publishing Categories -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Categories</h3>
                                <div class="grid grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Primary Category</label>
                                        <select id="primaryCategory" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                            <option value="business">Business & Money</option>
                                            <option value="tech">Computers & Technology</option>
                                            <option value="health">Health, Fitness & Dieting</option>
                                            <option value="self-help">Self-Help</option>
                                            <option value="education">Education</option>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Secondary Category</label>
                                        <select id="secondaryCategory" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                            <option value="">None</option>
                                            <option value="business">Business & Money</option>
                                            <option value="tech">Computers & Technology</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Keywords -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Search Keywords</h3>
                                <div class="mb-2">
                                    <p class="text-xs text-gray-500 mb-1">Enter up to 7 keywords (comma separated)</p>
                                    <textarea id="searchKeywords" rows="2" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="ebook, digital marketing, seo"></textarea>
                                </div>
                            </div>
                            
                            <!-- Pricing -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Pricing</h3>
                                <div class="grid grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Print Price ($)</label>
                                        <input type="number" id="printPrice" min="0" step="0.01" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="9.99">
                                    </div>
                                    <div>
                                        <label class="block text-sm text-gray-600 mb-1">Ebook Price ($)</label>
                                        <input type="number" id="ebookPrice" min="0" step="0.01" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="4.99">
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Distribution -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Distribution</h3>
                                <div class="space-y-2">
                                    <div class="flex items-center">
                                        <input type="checkbox" id="distAmazon" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="distAmazon" class="text-sm text-gray-700">Amazon Kindle Direct Publishing</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="distApple" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="distApple" class="text-sm text-gray-700">Apple Books</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="distGoogle" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="distGoogle" class="text-sm text-gray-700">Google Play Books</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="distKobo" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="distKobo" class="text-sm text-gray-700">Kobo</label>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Royalty Options -->
                            <div>
                                <h3 class="text-md font-medium text-gray-700 mb-3">Amazon KDP Options</h3>
                                <div class="space-y-2">
                                    <div class="flex items-center">
                                        <input type="checkbox" id="kdpSelect" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="kdpSelect" class="text-sm text-gray-700">Enroll in KDP Select (Exclusive to Amazon)</label>
                                    </div>
                                    <div class="flex items-center">
                                        <input type="checkbox" id="kdpUnlimited" checked class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        <label for="kdpUnlimited" class="text-sm text-gray-700">Make eBook free for KU subscribers</label>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Buttons -->
                            <div class="pt-4 space-y-3">
                                <button onclick="showTab('format-settings')" class="w-full bg-gray-100 hover:bg-gray-200 text-gray-700 py-2 px-4 rounded-lg transition duration-300">
                                    <i class="fas fa-arrow-left mr-2"></i> Back
                                </button>
                                <button type="button" onclick="generateEbook()" class="w-full gradient-bg text-white py-3 px-6 rounded-lg font-medium hover:opacity-90 transition duration-300 flex items-center justify-center">
                                    <i class="fas fa-magic mr-2"></i> Generate & Publish Ebook
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Requirements Checklist -->
                    <div class="lg:col-span-1">
                        <div class="bg-white rounded-xl shadow-md p-6 h-fit sticky top-8">
                            <h2 class="text-xl font-semibold mb-4 text-gray-800">Amazon Requirements</h2>
                            <div class="space-y-4">
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <i class="fas fa-check-circle text-green-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-gray-700 font-medium">Title (between 2-100 characters)</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <i class="fas fa-check-circle text-green-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-gray-700 font-medium">Author name specified</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <i class="fas fa-check-circle text-green-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-gray-700 font-medium">At least one category selected</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <i class="fas fa-check-circle text-green-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-gray-700 font-medium">Printable book size selected</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <i class="fas fa-exclamation-circle text-yellow-500"></i>
                                    </div>
                                    <div class="ml-3">
                                        <p class="text-sm text-gray-700 font-medium">Recommended number of pages: 24-800</p>
                                    </div>
                                </div>
                                <div class="border-t border-gray-200 pt-4">
                                    <h3 class="text-sm font-medium text-gray-700 mb-2">Cover Requirements</h3>
                                    <ul class="text-xs text-gray-500 space-y-1">
                                        <li class="flex items-start">
                                            <i class="fas fa-check mt-1 mr-2 text-green-500 text-xs"></i>
                                            <span>Minimum 1000 pixels on longest side</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check mt-1 mr-2 text-green-500 text-xs"></i>
                                            <span>72-300 DPI resolution</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check mt-1 mr-2 text-green-500 text-xs"></i>
                                            <span>RGB color mode</span>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Publishing Platforms -->
                    <div class="lg:col-span-1">
                        <div class="bg-white rounded-xl shadow-md p-6">
                            <h2 class="text-xl font-semibold mb-4 text-gray-800">Publishing Platforms</h2>
                            <div class="space-y-4">
                                <div class="p-4 border border-blue-200 rounded-lg bg-blue-50">
                                    <div class="flex items-center">
                                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Amazon_logo.svg/1200px-Amazon_logo.svg.png" class="h-8 mr-3" alt="Amazon">
                                        <div>
                                            <h3 class="font-medium text-gray-800">Amazon KDP</h3>
                                            <p class="text-xs text-gray-500">Kindle Direct Publishing</p>
                                        </div>
                                    </div>
                                    <div class="mt-3 flex items-center">
                                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                        <span class="text-sm text-gray-700">Requirements met</span>
                                    </div>
                                </div>
                                
                                <div class="p-4 border border-gray-200 rounded-lg">
                                    <div class="flex items-center">
                                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/505px-Apple_logo_black.svg.png" class="h-8 mr-3" alt="Apple">
                                        <div>
                                            <h3 class="font-medium text-gray-800">Apple Books</h3>
                                            <p class="text-xs text-gray-500">iBook Author</p>
                                        </div>
                                    </div>
                                    <div class="mt-3 flex items-center">
                                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                        <span class="text-sm text-gray-700">Requirements met</span>
                                    </div>
                                </div>
                                
                                <div class="p-4 border border-gray-200 rounded-lg">
                                    <div class="flex items-center">
                                        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png" class="h-8 mr-3" alt="Google">
                                        <div>
                                            <h3 class="font-medium text-gray-800">Google Play Books</h3>
                                            <p class="text-xs text-gray-500">Google's publishing platform</p>
                                        </div>
                                    </div>
                                    <div class="mt-3 flex items-center">
                                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                                        <span class="text-sm text-gray-700">Requirements met</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- API Settings Tab -->
            <div id="api-settings-tab" class="tab-content">
                <div class="max-w-4xl mx-auto bg-white rounded-xl shadow-md p-6">
                    <h2 class="text-xl font-semibold mb-4 text-gray-800">API Configuration</h2>
                    <p class="text-gray-600 mb-6">Connect your preferred AI APIs to power the ebook generation.</p>
                    
                    <div class="space-y-8">
                        <!-- API Connection Status -->
                        <div class="border border-gray-200 rounded-lg p-4 bg-gray-50">
                            <div class="flex items-center justify-between mb-2">
                                <h3 class="font-medium text-gray-700">API Connection Status</h3>
                                <div id="apiStatusBadge" class="flex items-center">
                                    <span class="api-status connected"></span>
                                    <span class="text-sm text-green-700">Connected</span>
                                </div>
                            </div>
                            <p class="text-xs text-gray-500">All API connections are working properly. You can generate ebooks.</p>
                        </div>
                        
                        <!-- OpenAI API -->
                        <div class="border border-gray-200 rounded-lg p-4">
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/OpenAI_Logo.svg/1200px-OpenAI_Logo.svg.png" class="h-6 mr-2" alt="OpenAI">
                                    <h3 class="font-medium text-gray-700">OpenAI API</h3>
                                </div>
                                <div class="flex items-center">
                                    <span class="api-status connected"></span>
                                    <span class="text-sm text-green-700">Connected</span>
                                </div>
                            </div>
                            <p class="text-xs text-gray-500 mb-3">Used for content generation and styling.</p>
                            <div>
                                <label for="openaiKey" class="block text-sm text-gray-600 mb-1">API Key</label>
                                <div class="flex">
                                    <input type="password" id="openaiKey" class="flex-grow px-4 py-2 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="sk-...">
                                    <button onclick="toggleApiKeyVisibility('openaiKey')" class="bg-gray-100 hover:bg-gray-200 px-4 rounded-r-lg border border-l-0 border-gray-300">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                </div>
                                <p class="text-xs text-gray-400 mt-1">Your API key is stored securely in your browser.</p>
                            </div>
                            <div class="mt-3 grid grid-cols-2 gap-4">
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Model</label>
                                    <select class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                        <option value="gpt-4">GPT-4</option>
                                        <option value="gpt-3.5" selected>GPT-3.5 Turbo</option>
                                    </select>
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Max Tokens</label>
                                    <input type="number" value="2500" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                </div>
                            </div>
                        </div>
                        
                        <!-- Stable Diffusion API -->
                        <div class="border border-gray-200 rounded-lg p-4">
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <img src="https://stability.ai/site-favicon.ico" class="h-6 mr-2" alt="Stability AI">
                                    <h3 class="font-medium text-gray-700">Stable Diffusion API</h3>
                                </div>
                                <div class="flex items-center">
                                    <span class="api-status connected"></span>
                                    <span class="text-sm text-green-700">Connected</span>
                                </div>
                            </div>
                            <p class="text-xs text-gray-500 mb-3">Used for cover image generation.</p>
                            <div>
                                <label for="sdKey" class="block text-sm text-gray-600 mb-1">API Key</label>
                                <div class="flex">
                                    <input type="password" id="sdKey" class="flex-grow px-4 py-2 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="sk-...">
                                    <button onclick="toggleApiKeyVisibility('sdKey')" class="bg-gray-100 hover:bg-gray-200 px-4 rounded-r-lg border border-l-0 border-gray-300">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="mt-3 grid grid-cols-2 gap-4">
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Model</label>
                                    <select class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                        <option value="sd-xl" selected>SD XL</option>
                                        <option value="sd-2.1">SD 2.1</option>
                                    </select>
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Steps</label>
                                    <input type="number" value="30" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                </div>
                            </div>
                        </div>
                        
                        <!-- AWS API -->
                        <div class="border border-gray-200 rounded-lg p-4">
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Amazon_Web_Services_Logo.svg/1200px-Amazon_Web_Services_Logo.svg.png" class="h-6 mr-2" alt="AWS">
                                    <h3 class="font-medium text-gray-700">Amazon Web Services</h3>
                                </div>
                                <div class="flex items-center">
                                    <span class="api-status connected"></span>
                                    <span class="text-sm text-green-700">Connected</span>
                                </div>
                            </div>
                            <p class="text-xs text-gray-500 mb-3">Used for PDF generation and publishing to KDP.</p>
                            <div class="grid grid-cols-2 gap-4">
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Access Key ID</label>
                                    <input type="password" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="AKIA...">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Secret Access Key</label>
                                    <input type="password" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="wJalr...">
                                </div>
                            </div>
                            <div class="mt-3">
                                <label class="block text-sm text-gray-600 mb-1">Region</label>
                                <select class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="us-east-1" selected>US East (N. Virginia)</option>
                                    <option value="us-west-2">US West (Oregon)</option>
                                    <option value="eu-west-1">EU (Ireland)</option>
                                </select>
                            </div>
                        </div>
                        
                        <!-- Test Connection Button -->
                        <div class="pt-4">
                            <button onclick="testApiConnections()" class="w-full bg-blue-600 hover:bg-blue-700 text-white py-3 px-6 rounded-lg font-medium transition duration-300">
                                Test API Connections
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- My Ebooks Tab -->
            <div id="my-ebooks-tab" class="tab-content">
                <div class="max-w-6xl mx-auto">
                    <div class="flex justify-between items-center mb-6">
                        <h2 class="text-xl font-semibold text-gray-800">My Generated Ebooks</h2>
                        <div class="flex space-x-2">
                            <button onclick="showTab('generator')" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg font-medium transition duration-300 flex items-center">
                                <i class="fas fa-plus mr-2"></i> Create New Ebook
                            </button>
                        </div>
                    </div>
                    
                    <div id="filterBar" class="bg-white p-4 rounded-lg shadow mb-6">
                        <div class="flex flex-wrap gap-4">
                            <div>
                                <label class="block text-sm text-gray-600 mb-1">Filter by Status</label>
                                <select class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="all">All Ebooks</option>
                                    <option value="draft">Drafts</option>
                                    <option value="published">Published</option>
                                    <option value="archived">Archived</option>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm text-gray-600 mb-1">Filter by Date</label>
                                <select class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="all">All Time</option>
                                    <option value="today">Today</option>
                                    <option value="week">This Week</option>
                                    <option value="month">This Month</option>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm text-gray-600 mb-1">Sort By</label>
                                <select class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="newest">Newest First</option>
                                    <option value="oldest">Oldest First</option>
                                    <option value="title">Title (A-Z)</option>
                                </select>
                            </div>
                            <div class="flex items-end">
                                <button class="bg-gray-100 hover:bg-gray-200 text-gray-700 py-2 px-4 rounded-lg transition duration-300">
                                    <i class="fas fa-filter mr-2"></i> Apply
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-6">
                        <div id="ebooksList" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                            <!-- Ebooks will be listed here dynamically -->
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <script>
        // Current ebook being worked on
        let currentEbook = null;
        
        // Tab switching functionality
        function showTab(tabName) {
            // Update active tab button
            document.querySelectorAll('.tab-button').forEach(button => {
                button.classList.remove('active');
            });
            
            const activeButton = document.querySelector(`a[onclick="showTab('${tabName}')"]`);
            if (activeButton) activeButton.classList.add('active');
            
            // Hide all tabs
            document.querySelectorAll('.tab-content').forEach(tab => {
                tab.classList.remove('active');
            });
            
            // Show selected tab with animation
            document.getElementById(`${tabName}-tab`).classList.add('active');
            
            // Initialize tab-specific content
            if (tabName === 'my-ebooks') {
                loadMyEbooks();
            }
        }
        
        // Format selection
        function selectFormat(format, element) {
            document.querySelectorAll('.format-option').forEach(el => el.classList.remove('active'));
            element.classList.add('active');
            document.getElementById('pageSize').value = format;
            
            // Update display
            if (format === '6x9') {
                document.getElementById('coverFormatDisplay').textContent = '6 × 9 inches';
            } else if (format === '5x8') {
                document.getElementById('coverFormatDisplay').textContent = '5 × 8 inches';
            } else if (format === 'a5') {
                document.getElementById('coverFormatDisplay').textContent = 'A5 (148 × 210mm)';
            } else if (format === 'a4') {
                document.getElementById('coverFormatDisplay').textContent = 'A4 (210 × 297mm)';
            } else {
                document.getElementById('coverFormatDisplay').textContent = 'Custom';
            }
            
            // Update preview if ebook exists
            if (currentEbook) {
                currentEbook.format = format;
                updateCoverPreview();
            }
        }
        
        // Color selection
        function selectColor(color, element) {
            document.querySelectorAll('.color-option').forEach(el => el.classList.remove('selected'));
            element.classList.add('selected');
            
            // Update preview if ebook exists
            if (currentEbook) {
                currentEbook.color = color;
                updateCoverPreview();
                updateInteriorPreview();
            }
        }
        
        // Update cover preview
        function updateCoverPreview() {
            const color = currentEbook?.color || 'blue';
            const title = document.getElementById('ebookTitle').value || 'Your Ebook Title';
            const author = document.getElementById('authorName').value || 'Author Name';
            const coverStyle = document.getElementById('coverStyle').value || 'modern';
            
            // Update style display
            document.getElementById('coverStyleDisplay').textContent = coverStyle.charAt(0).toUpperCase() + coverStyle.slice(1);
            
            const colorMap = {
                'blue': 'from-blue-500 to-indigo-600',
                'green': 'from-green-500 to-emerald-600',
                'red': 'from-red-500 to-rose-600',
                'purple': 'from-purple-500 to-violet-600',
                'indigo': 'from-indigo-500 to-blue-600',
                'yellow': 'from-yellow-400 to-amber-500'
            };
            
            const cover = document.getElementById('coverPreview');
            cover.className = `cover-preview mx-auto bg-gradient-to-br ${colorMap[color]} flex items-center justify-center`;
            
            document.getElementById('coverTitle').textContent = title;
            document.getElementById('coverAuthor').textContent = `by ${author}`;
            
            // Apply style-specific effects
            if (coverStyle === 'vintage') {
                cover.classList.add('sepia', 'brightness-90');
            } else {
                cover.classList.remove('sepia', 'brightness-90');
            }
            
            if (coverStyle === 'minimal') {
                cover.classList.add('opacity-90');
            } else {
                cover.classList.remove('opacity-90');
            }
        }
        
        // Randomize cover
        function randomizeCover() {
            const colors = ['blue', 'green', 'red', 'purple', 'indigo', 'yellow'];
            const randomColor = colors[Math.floor(Math.random() * colors.length)];
            const colorElement = document.querySelector(`.color-option[data-color="${randomColor}"]`);
            selectColor(randomColor, colorElement);
            
            const styles = ['modern', 'minimal', 'professional', 'vintage'];
            const randomStyle = styles[Math.floor(Math.random() * styles.length)];
            document.getElementById('coverStyle').value = randomStyle;
            
            updateCoverPreview();
        }
        
        // Upload cover
        function uploadCover() {
            const input = document.createElement('input');
            input.type = 'file';
            input.accept = 'image/*';
            
            input.onchange = (e) => {
                const file = e.target.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(event) {
                        const cover = document.getElementById('coverPreview');
                        cover.style.backgroundImage = `url(${event.target.result})`;
                        cover.className = 'cover-preview mx-auto bg-cover bg-center flex items-center justify-center';
                        
                        document.getElementById('coverTitle').textContent = '';
                        document.getElementById('coverAuthor').textContent = '';
                        
                        // Update preview if ebook exists
                        if (currentEbook) {
                            currentEbook.customCover = event.target.result;
                        }
                        
                        Toastify({
                            text: "Custom cover uploaded successfully!",
                            duration: 3000,
                            gravity: "top",
                            position: "right",
                            backgroundColor: "#10B981"
                        }).showToast();
                    };
                    reader.readAsDataURL(file);
                }
            };
            
            input.click();
        }
        
        // Update interior preview
        function updateInteriorPreview() {
            const template = document.getElementById('designTemplate').value || 'modern';
            const font = document.getElementById('bodyFont').value || 'sans-serif';
            const fontSize = document.getElementById('fontSize').value || '12';
            const color = currentEbook?.color || 'blue';
            
            const interior = document.getElementById('interiorPreview');
            
            // Reset classes
            interior.className = 'border border-gray-200 p-6 rounded-lg';
            
            // Add template-specific classes
            if (template === 'modern') {
                interior.classList.add('bg-white');
            } else if (template === 'minimal') {
                interior.classList.add('bg-gray-50');
            } else if (template === 'creative') {
                interior.classList.add('bg-white', 'border-2', 'border-dashed', 'border-blue-200');
            } else if (template === 'academic') {
                interior.classList.add('bg-white', 'border-l-4');
            }
            
            // Add font classes
            if (font === 'serif') {
                interior.classList.add('font-serif');
            } else if (font === 'sans-serif') {
                interior.classList.add('font-sans');
            } else if (font === 'monospace') {
                interior.classList.add('font-mono');
            }
            
            // Add color accents
            const colorMap = {
                'blue': 'border-blue-200',
                'green': 'border-green-200',
                'red': 'border-red-200',
                'purple': 'border-purple-200',
                'indigo': 'border-indigo-200',
                'yellow': 'border-yellow-200'
            };
            
            if (template === 'academic') {
                interior.classList.add(colorMap[color]);
            } else if (template === 'creative') {
                interior.classList.replace('border-blue-200', colorMap[color]);
            }
            
            // Update font size
            interior.style.fontSize = fontSize + 'pt';
            
            // Update preview if ebook exists
            if (currentEbook) {
                currentEbook.template = template;
                currentEbook.font = font;
                currentEbook.fontSize = fontSize;
            }
        }
        
        // Preview ebook
        function previewEbook() {
            // Update cover preview
            updateCoverPreview();
            
            // Update interior preview
            updateInteriorPreview();
            
            // If no ebook exists yet, show a message
            if (!currentEbook) {
                Toastify({
                    text: "Fill out the generator form first",
                    duration: 3000,
                    gravity: "top",
                    position: "right",
                    backgroundColor: "#EF4444"
                }).showToast();
                return;
            }
        }
        
        // Generate ebook function
        function generateEbook() {
            // Validate required fields
            const title = document.getElementById('ebookTitle').value;
            const author = document.getElementById('authorName').value;
            const topic = document.getElementById('ebookTopic').value;
            const summary = document.getElementById('ebookSummary').value;
            
            if (!title || !author || !topic || !summary) {
                Toastify({
                    text: "Please fill all required fields first",
                    duration: 3000,
                    gravity: "top",
                    position: "right",
                    backgroundColor: "#EF4444"
                }).showToast();
                return;
            }
            
            // Show loading state
            document.getElementById('emptyState').classList.add('hidden');
            document.getElementById('ebookContent').classList.add('hidden');
            document.getElementById('loadingState').classList.remove('hidden');
            
            // Get form values
            const subtitle = document.getElementById('ebookSubtitle').value;
            const keywords = document.getElementById('ebookKeywords').value;
            const chapterCount = parseInt(document.getElementById('chapterCount').value);
            const writingStyle = document.getElementById('writingStyle').value;
            
            // Get format settings
            const format = document.getElementById('pageSize').value;
            const template = document.getElementById('designTemplate').value;
            const font = document.getElementById('bodyFont').value;
            const fontSize = document.getElementById('fontSize').value;
            const color = document.querySelector('.color-option.selected').dataset.color;
            const coverStyle = document.getElementById('coverStyle').value;
            
            // Get publishing settings
            const categories = {
                primary: document.getElementById('primaryCategory').value,
                secondary: document.getElementById('secondaryCategory').value
            };
            const pricing = {
                print: document.getElementById('printPrice').value,
                ebook: document.getElementById('ebookPrice').value
            };
            
            // Generate output formats
            const outputFormats = [];
            if (document.getElementById('formatPDF').checked) outputFormats.push('pdf');
            if (document.getElementById('formatEPUB').checked) outputFormats.push('epub');
            if (document.getElementById('formatMOBI').checked) outputFormats.push('mobi');
            
            // Simulate API call with timeout
            setTimeout(() => {
                // Hide loading state
                document.getElementById('loadingState').classList.add('hidden');
                
                // Generate ebook content
                currentEbook = generateMockEbook(
                    title, subtitle, author, topic, keywords, summary, 
                    chapterCount, writingStyle, format, template, 
                    font, fontSize, color, coverStyle, categories, pricing
                );
                currentEbook.outputFormats = outputFormats;
                
                // Display the generated ebook
                displayEbook(currentEbook);
                
                // Add to my ebooks list
                addToMyEbooks(currentEbook);
                
                // Show success message
                Toastify({
                    text: "Ebook generated successfully!",
                    duration: 3000,
                    gravity: "top",
                    position: "right",
                    backgroundColor: "#10B981"
                }).showToast();
                
                // Show content
                document.getElementById('ebookContent').classList.remove('hidden');
                
                // Activate ebook tab button
                const activeButton = document.querySelector('a[onclick="showTab(\'generator\')"]');
                if (activeButton) activeButton.classList.add('active');
                
            }, 3000);
        }
        
        function generateMockEbook(title, subtitle, author, topic, keywords, summary, chapterCount, style, format, template, font, fontSize, color, coverStyle, categories, pricing) {
            const styles = {
                professional: "This comprehensive guide provides professional insights",
                casual: "This friendly guide walks you through",
                academic: "This scholarly examination presents",
                storytelling: "Let me tell you the story of"
            };
            
            const bookSubtitle = subtitle || `${styles[style]} ${topic.toLowerCase()}.`;
            
            // Generate chapters
            const chapters = [];
            const toc = [];
            
            for (let i = 1; i <= chapterCount; i++) {
                const chapterTitle = generateChapterTitle(topic, i, chapterCount);
                const chapterContent = generateChapterContent(topic, keywords, i, chapterCount, style);
                
                chapters.push({
                    title: chapterTitle,
                    content: chapterContent
                });
                
                toc.push({
                    title: chapterTitle,
                    id: `chapter-${i}`
                });
            }
            
            return {
                title,
                subtitle: bookSubtitle,
                author,
                toc,
                chapters,
                format,
                template,
                font,
                fontSize,
                color,
                coverStyle,
                categories,
                pricing,
                generatedAt: new Date().toLocaleString(),
                id: Date.now().toString()
            };
        }
        
        function generateChapterTitle(topic, index, total) {
            const prefixes = [
                "Introduction to",
                "The Fundamentals of",
                "Advanced Techniques in",
                "Practical Applications of",
                "Case Studies in",
                "Future Trends in",
                "Best Practices for",
                "Common Mistakes in",
                "Tools and Resources for",
                "Getting Started with"
            ];
            
            const suffixes = [
                "Explained",
                "Demystified",
                "Uncovered",
                "Revealed",
                "Made Simple",
                "for Beginners",
                "for Professionals",
                "in Practice",
                "in the Real World",
                "and Beyond"
            ];
            
            // Use more specific prefixes for later chapters
            const prefix = index === 1 ? prefixes[0] : 
                          index === total ? prefixes[5] : 
                          prefixes[Math.min(index, prefixes.length - 1)];
            
            const suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
            
            return `${prefix} ${topic} ${suffix}`;
        }
        
        function generateChapterContent(topic, keywords, index, total, style) {
            const keywordList = keywords.split(',').map(k => k.trim()).filter(k => k.length > 0);
            
            const paragraphs = [];
            const paragraphCount = 3 + Math.floor(Math.random() * 3); // 3-5 paragraphs
            
            for (let i = 0; i < paragraphCount; i++) {
                let paragraph = "";
                
                // First paragraph introduces the chapter
                if (i === 0) {
                    paragraph = `In this chapter, we ${style === 'academic' ? 'examine' : style === 'professional' ? 'explore' : 'look at'} `;
                    paragraph += `the ${index === 1 ? 'basic concepts' : index === total ? 'future implications' : 'key aspects'} `;
                    paragraph += `of ${topic.toLowerCase()}. `;
                    
                    if (keywordList.length > 0) {
                        paragraph += `Particular focus will be given to ${keywordList.join(', ')}. `;
                    }
                }
                // Middle paragraphs provide content
                else {
                    const concepts = [
                        "This approach has been shown to produce significant results",
                        "Many experts agree that this method is effective",
                        "Recent studies have demonstrated the value of this technique",
                        "When implemented correctly, this strategy can yield benefits",
                        "Organizations that adopt this practice often see improvements",
                        "The data clearly supports the effectiveness of this solution"
                    ];
                    
                    const examples = [
                        "For example, a recent case study showed",
                        "Consider how this applies to a typical scenario",
                        "To illustrate this point, imagine a situation where",
                        "A practical example of this would be",
                        "This can be seen in the way that",
                        "We can observe this in action when"
                    ];
                    
                    const transitions = [
                        "Building on this concept,",
                        "Taking this a step further,",
                        "In addition to this,",
                        "Furthermore,",
                        "Another important consideration is",
                        "It's also worth noting that"
                    ];
                    
                    if (i === 1) {
                        paragraph = concepts[Math.floor(Math.random() * concepts.length)] + ". ";
                        paragraph += examples[Math.floor(Math.random() * examples.length)] + " ";
                        paragraph += "this leads to measurable outcomes. ";
                    } else {
                        paragraph = transitions[Math.floor(Math.random() * transitions.length)] + " ";
                        paragraph += concepts[Math.floor(Math.random() * concepts.length)].toLowerCase() + ". ";
                        
                        if (Math.random() > 0.3) {
                            paragraph += examples[Math.floor(Math.random() * examples.length)] + " ";
                            paragraph += "the results speak for themselves. ";
                        }
                    }
                }
                
                // Add some keywords if available
                if (keywordList.length > 0 && Math.random() > 0.5) {
                    const keyword = keywordList[Math.floor(Math.random() * keywordList.length)];
                    paragraph += `The role of ${keyword} in this process cannot be overstated. `;
                }
                
                paragraphs.push(paragraph);
            }
            
            // Add a concluding paragraph
            let conclusion = "";
            if (index === 1) {
                conclusion = "This chapter has introduced the fundamental concepts that will be explored in more depth throughout this ebook. ";
            } else if (index === total) {
                conclusion = "In conclusion, this chapter has summarized the key takeaways and looked ahead to future developments in the field. ";
            } else {
                conclusion = "The insights from this chapter provide a solid foundation for understanding the more advanced topics that follow. ";
            }
            
            conclusion += "In the next chapter, we will " + 
                (index === total ? "summarize all the key lessons from this ebook." : 
                `explore ${index === total - 1 ? "the final aspects" : "more advanced concepts"} of ${topic.toLowerCase()}.`);
            
            paragraphs.push(conclusion);
            
            return paragraphs;
        }
        
        function displayEbook(ebookData) {
            // Set title and metadata
            document.getElementById('previewTitle').textContent = ebookData.title;
            document.getElementById('previewSubtitle').textContent = ebookData.subtitle;
            document.getElementById('previewAuthor').textContent = ebookData.author;
            document.getElementById('generatedTime').textContent = `Generated ${ebookData.generatedAt}`;
            
            // Generate table of contents
            const tocList = document.getElementById('tocList');
            tocList.innerHTML = '';
            
            ebookData.toc.forEach((item, index) => {
                const tocItem = document.createElement('div');
                tocItem.className = 'chapter-item transition duration-200';
                tocItem.innerHTML = `
                    <a href="#${item.id}" class="flex items-center text-blue-600 hover:text-blue-800">
                        <span class="w-6 text-gray-500 font-medium">${index + 1}.</span>
                        <span>${item.title}</span>
                    </a>
                `;
                tocList.appendChild(tocItem);
            });
            
            // Generate chapters
            const chaptersContainer = document.getElementById('chaptersContainer');
            chaptersContainer.innerHTML = '';
            
            ebookData.chapters.forEach((chapter, index) => {
                const chapterElement = document.createElement('div');
                chapterElement.id = `chapter-${index + 1}`;
                chapterElement.className = 'chapter mb-10';
                
                let chapterHTML = `
                    <div>
                        <div class="flex items-center mb-4">
                            <span class="bg-${ebookData.color}-100 text-${ebookData.color}-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-3">${index + 1}</span>
                            <h2 class="text-2xl font-bold text-gray-800">${chapter.title}</h2>
                        </div>
                `;
                
                chapter.content.forEach(paragraph => {
                    chapterHTML += `<p class="text-gray-700 mb-4 ${ebookData.font === 'serif' ? 'font-serif' : ebookData.font === 'monospace' ? 'font-mono' : ''}" style="font-size: ${ebookData.fontSize}pt;">${paragraph}</p>`;
                });
                
                // Add image placeholder if enabled
                if (ebookData.template !== 'minimal' && Math.random() > 0.5) {
                    chapterHTML += `
                        <div class="my-6 p-4 bg-gray-100 rounded-lg border border-gray-200 text-center">
                            <i class="fas fa-image text-3xl text-gray-400 mb-2"></i>
                            <p class="text-sm text-gray-500">[${ebookData.coverStyle} image related to chapter content]</p>
                        </div>
                    `;
                }
                
                chapterHTML += `</div>`;
                chapterElement.innerHTML = chapterHTML;
                chaptersContainer.appendChild(chapterElement);
            });
        }

        function addToMyEbooks(ebookData) {
            const ebooksList = document.getElementById('ebooksList');
            
            // Remove placeholder if it exists
            if (ebooksList.querySelector('.text-center')) {
                ebooksList.innerHTML = '';
            }
            
            // Create ebook card
            const ebookCard = document.createElement('div');
            ebookCard.className = 'bg-white rounded-lg shadow-md overflow-hidden border border-gray-200 hover:shadow-lg transition duration-300';
            ebookCard.innerHTML = `
                <div class="p-4 border-b border-gray-200 bg-gray-50 flex justify-between items-center">
                    <div>
                        <h3 class="font-semibold text-lg text-gray-800 truncate">${ebookData.title}</h3>
                        <p class="text-sm text-gray-500">${ebookData.generatedAt}</p>
                    </div>
                    <span class="bg-${ebookData.color}-100 text-${ebookData.color}-800 text-xs px-2 py-1 rounded-full">${ebookData.format.toUpperCase()}</span>
                </div>
                <div class="p-4">
                    <p class="text-sm text-gray-600 mb-2 line-clamp-2">${ebookData.subtitle}</p>
                    <div class="flex flex-wrap gap-1 mb-3">
                        <span class="text-xs px-2 py-1 bg-gray-100 text-gray-800 rounded-full">${ebookData.categories.primary}</span>
                        ${ebookData.categories.secondary ? `<span class="text-xs px-2 py-1 bg-gray-100 text-gray-800 rounded-full">${ebookData.categories.secondary}</span>` : ''}
                    </div>
                    <div class="flex justify-between items-center">
                        <span class="text-sm font-medium text-gray-700">$${(ebookData.pricing.ebook || 0).toFixed(2)}</span>
                        <div class="space-x-2">
                            <button onclick="viewEbook('${ebookData.id}')" class="text-blue-600 hover:text-blue-800 transition duration-300">
                                <i class="fas fa-eye"></i>
                            </button>
                            <button onclick="publishEbook('${ebookData.id}')" class="text-purple-600 hover:text-purple-800 transition duration-300">
                                <i class="fas fa-cloud-upload-alt"></i>
                            </button>
                            <button onclick="downloadEbook('${ebookData.id}')" class="text-green-600 hover:text-green-800 transition duration-300">
                                <i class="fas fa-download"></i>
                            </button>
                            <button onclick="deleteEbook('${ebookData.id}')" class="text-red-600 hover:text-red-800 transition duration-300">
                                <i class="fas fa-trash"></i>
                            </button>
                        </div>
                    </div>
                </div>
            `;
            
            // Add to the beginning of the list
            ebooksList.prepend(ebookCard);
            
            // Store in local storage
            const myEbooks = JSON.parse(localStorage.getItem('myEbooks') || '[]');
            myEbooks.unshift(ebookData);
            localStorage.setItem('myEbooks', JSON.stringify(myEbooks));
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=amwolf36/alex" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>