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 
 
 
9dcc7bc
f860042
 
9dcc7bc
f860042
 
 
 
 
 
9dcc7bc
f860042
 
 
9dcc7bc
 
 
 
 
 
 
 
 
 
f860042
 
 
9dcc7bc
f860042
 
 
 
 
 
9dcc7bc
 
 
 
f860042
 
 
9dcc7bc
f860042
 
 
 
9dcc7bc
 
f860042
 
 
 
 
 
 
9dcc7bc
 
 
 
f860042
 
 
 
 
9dcc7bc
 
 
 
f860042
9dcc7bc
 
 
 
 
 
 
f860042
 
 
 
 
9dcc7bc
 
 
 
 
 
 
 
 
f860042
 
 
 
9dcc7bc
 
f860042
 
d7bf09b
f860042
 
9dcc7bc
 
 
 
 
 
 
f860042
 
 
 
 
 
9dcc7bc
f860042
 
 
 
9dcc7bc
f860042
 
 
 
 
 
 
 
 
 
 
 
 
9dcc7bc
 
f860042
 
1d2b7e9
 
 
 
 
 
 
 
 
d7bf09b
 
 
 
 
1d2b7e9
 
 
 
 
d7bf09b
 
1d2b7e9
 
d7bf09b
 
 
1d2b7e9
f860042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7bf09b
 
f860042
 
 
 
 
 
 
 
 
9dcc7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d2b7e9
 
 
 
 
9dcc7bc
1d2b7e9
 
 
f860042
9dcc7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d2b7e9
 
f860042
1d2b7e9
9dcc7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d2b7e9
 
 
 
f860042
1d2b7e9
 
 
 
 
 
 
 
f860042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dcc7bc
f860042
 
 
 
 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 
f860042
 
9dcc7bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d2b7e9
 
 
9dcc7bc
f860042
1d2b7e9
 
 
9dcc7bc
 
 
1d2b7e9
9dcc7bc
 
 
 
 
 
 
1d2b7e9
9dcc7bc
 
 
 
 
1d2b7e9
 
f860042
 
9dcc7bc
f860042
9dcc7bc
 
f860042
9dcc7bc
f860042
 
 
9dcc7bc
f860042
 
9dcc7bc
 
 
 
 
f860042
 
1d2b7e9
 
 
 
f860042
1d2b7e9
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
1527
1528
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Technology Tree Evolution</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f0f2f5;
            color: #333;
            overflow-y: auto;
            overflow-x: hidden;
        }

        header {
            background: linear-gradient(135deg, #2c3e50, #4ca1af);
            color: white;
            padding: 2rem 0;
            text-align: center;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 0.5rem;
        }

        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
        }

        .container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 1rem;
            display: flex;
        }

        .controls {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 2rem;
            flex-wrap: wrap;
            gap: 1rem;
            width: 200px;
            margin-right: 2rem;
            flex-direction: column;
        }

        .era-navigation {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            width: 100%;
        }

        .add-tech-btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 30px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            background-color: #9d4edd;
            color: white;
            font-size: 0.9rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            width: 100%;
        }

        .add-tech-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
            background-color: #7b2cbf;
        }

        .era-button {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 30px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            font-size: 0.9rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            width: 100%;
            text-align: left;
        }

        .era-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }

        .era-ancient {
            background-color: #e9c46a;
            color: #333;
        }

        .era-classical {
            background-color: #f4a261;
            color: white;
        }

        .era-medieval {
            background-color: #e76f51;
            color: white;
        }

        .era-industrial {
            background-color: #2a9d8f;
            color: white;
        }

        .era-modern {
            background-color: #1d3557;
            color: white;
        }

        .era-future {
            background-color: #9d4edd;
            color: white;
        }

        .tech-tree-container {
            width: calc(100% - 220px);
            height: 800px;
            overflow: auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            padding: 2rem;
            position: relative;
            margin-bottom: 3rem;
        }

        .tech-tree {
            position: relative;
            width: 100%;
            height: 3500px;
            margin: 0 auto;
        }

        .era-line {
            position: absolute;
            width: 100%;
            height: 2px;
            background-color: rgba(0, 0, 0, 0.1);
            z-index: 0;
            left: 0;
        }

        .ancient-line { top: 150px; }
        .classical-line { top: 450px; }
        .medieval-line { top: 750px; }
        .industrial-line { top: 1050px; }
        .modern-line { top: 1350px; }
        .future-line { top: 1650px; }

        .era-labels {
            position: absolute;
            left: 0;
            width: 100px;
            display: flex;
            flex-direction: column;
            gap: 300px;
            z-index: 5;
            font-weight: bold;
            color: #555;
            text-transform: uppercase;
            font-size: 0.9rem;
            letter-spacing: 1px;
            top: 0;
            padding-left: 20px;
        }

        .tech-node {
            position: absolute;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            z-index: 10;
            transform: scale(0.95);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .tech-node:hover {
            transform: scale(1.05);
            z-index: 20;
        }

        .tech-icon {
            font-size: 1.8rem;
            margin-bottom: 0.3rem;
        }

        .tech-name {
            font-weight: bold;
            font-size: 0.7rem;
        }

        .tech-era {
            font-size: 0.6rem;
            opacity: 0.8;
            margin-top: 2px;
        }

        /* Node colors based on era */
        .ancient {
            background-color: #e9c46a;
            color: #333;
        }

        .classical {
            background-color: #f4a261;
            color: white;
        }

        .medieval {
            background-color: #e76f51;
            color: white;
        }

        .industrial {
            background-color: #2a9d8f;
            color: white;
        }

        .modern {
            background-color: #1d3557;
            color: white;
        }

        .future {
            background-color: #9d4edd;
            color: white;
        }

        /* Connection lines */
        .connection {
            position: absolute;
            background-color: #aaa;
            height: 2px;
            z-index: 1;
            transform-origin: 0 0;
        }

        .node-popup {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.9);
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
            z-index: 100;
            max-width: 400px;
            opacity: 0;
            pointer-events: none;
            transition: all 0.3s ease;
        }

        .node-popup.active {
            transform: translate(-50%, -50%) scale(1);
            opacity: 1;
            pointer-events: auto;
        }

        .node-popup h3 {
            margin-bottom: 0.5rem;
            color: #444;
            font-size: 1.5rem;
        }

        .node-popup .era {
            font-size: 0.9rem;
            margin-bottom: 1rem;
            font-weight: bold;
            padding: 0.3rem 0.8rem;
            background-color: #f0f0f0;
            display: inline-block;
            border-radius: 20px;
            color: #555;
        }

        .node-popup .description {
            margin-bottom: 1.5rem;
            line-height: 1.6;
            color: #555;
        }

        .node-popup .prerequisites {
            font-size: 0.9rem;
            color: #666;
            padding: 0.8rem;
            background-color: #f8f8f8;
            border-radius: 6px;
            border-left: 3px solid #9d4edd;
        }

        .close-popup {
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 1.5rem;
            cursor: pointer;
            color: #888;
            transition: all 0.2s;
        }

        .close-popup:hover {
            color: #333;
            transform: rotate(90deg);
        }

        .add-node-form {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.9);
            background: white;
            padding: 1rem;
            border-radius: 12px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
            z-index: 100;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
            max-width: 320px;
            opacity: 0;
            pointer-events: none;
            transition: all 0.3s ease;
        }

        .add-node-form.active {
            transform: translate(-50%, -50%) scale(1);
            opacity: 1;
            pointer-events: auto;
        }

        .add-node-form h2 {
            margin-bottom: 0.8rem;
            color: #444;
            font-size: 1.1rem;
            padding-bottom: 0.5rem;
            border-bottom: 1px solid #eee;
        }

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

        .form-group label {
            display: block;
            margin-bottom: 0.2rem;
            font-weight: bold;
            color: #555;
            font-size: 0.8rem;
        }

        .form-group input, 
        .form-group select, 
        .form-group textarea {
            width: 100%;
            padding: 0.5rem;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-family: inherit;
            font-size: 0.8rem;
            transition: all 0.2s;
        }

        .form-group input:focus, 
        .form-group select:focus, 
        .form-group textarea:focus {
            border-color: #9d4edd;
            outline: none;
            box-shadow: 0 0 0 3px rgba(157, 78, 221, 0.2);
        }

        .form-group textarea {
            min-height: 60px;
            resize: vertical;
        }

        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 0.6rem;
            margin-top: 0.8rem;
            padding-top: 0.8rem;
            border-top: 1px solid #eee;
        }

        .form-actions button {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: bold;
            font-size: 0.8rem;
            transition: all 0.2s;
        }

        .form-cancel {
            background-color: #f0f0f0;
            color: #555;
        }

        .form-cancel:hover {
            background-color: #e0e0e0;
        }

        .form-submit {
            background-color: #9d4edd;
            color: white;
        }

        .form-submit:hover {
            background-color: #7b2cbf;
        }

        .checkbox-group {
            margin-top: 0.3rem;
            max-height: 100px;
            overflow-y: auto;
            border: 1px solid #eee;
            padding: 0.3rem;
            border-radius: 4px;
            font-size: 0.75rem;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
            margin-bottom: 0.2rem;
            font-size: 0.75rem;
            padding: 0.2rem;
            border-radius: 3px;
            transition: all 0.2s;
        }

        .checkbox-item:hover {
            background-color: #f5f5f5;
        }

        .checkbox-item input {
            width: auto;
            margin-right: 0.3rem;
            accent-color: #9d4edd;
        }

        .icon-selecter {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.3rem;
            margin-top: 0.3rem;
            max-height: 120px;
            overflow-y: auto;
            padding: 0.3rem;
            border: 1px solid #eee;
            border-radius: 4px;
        }

        .icon-option {
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 0.3rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 0.7rem;
        }

        .icon-option:hover {
            border-color: #9d4edd;
            background-color: #f9f0ff;
        }

        .icon-option.selected {
            border-color: #9d4edd;
            background-color: #f0d6ff;
        }

        .icon-option i {
            font-size: 1rem;
            margin-bottom: 0.1rem;
        }

        footer {
            text-align: center;
            padding: 2rem 0;
            background-color: #2c3e50;
            color: white;
        }

        .timeline-bar {
            position: absolute;
            top: 0;
            right: 0;
            width: 4px;
            height: 100%;
            background: linear-gradient(to bottom, #e9c46a, #f4a261, #e76f51, #2a9d8f, #1d3557, #9d4edd);
            border-radius: 0 0 12px 12px;
        }

        .tech-path {
            position: absolute;
            width: 4px;
            height: 0;
            background-color: rgba(255, 255, 255, 0.8);
            z-index: 2;
            top: 0;
            right: 0;
            transition: height 0.5s ease-in-out;
        }

        .drag-handle {
            position: absolute;
            top: -5px;
            right: -5px;
            width: 20px;
            height: 20px;
            background-color: rgba(255, 255, 255, 0.8);
            border-radius: 50%;
            border: 1px solid #ccc;
            cursor: move;
            display: none;
            z-index: 30;
            font-size: 0.7rem;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #555;
        }

        .tech-node.editable .drag-handle {
            display: flex;
        }

        .delete-node {
            position: absolute;
            top: -5px;
            left: -5px;
            width: 20px;
            height: 20px;
            background-color: #ff6b6b;
            border-radius: 50%;
            cursor: pointer;
            display: none;
            z-index: 30;
            font-size: 0.7rem;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            opacity: 0;
            transition: opacity 0.2s;
        }

        .tech-node.editable:hover .delete-node {
            opacity: 1;
        }

        .editable-mode {
            border: 2px dashed #9d4edd;
        }

        .toggle-edit-mode {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 30px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            font-size: 0.9rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            background-color: #ff6b6b;
            color: white;
            width: 100%;
            text-align: left;
        }

        .toggle-edit-mode:hover {
            background-color: #ff5252;
        }

        .toggle-edit-mode.active {
            background-color: #4CAF50;
        }

        /* Additional styling for the controls section */
        .controls-section {
            background-color: white;
            padding: 1rem;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            margin-bottom: 1rem;
        }

        .controls-title {
            font-size: 0.9rem;
            font-weight: bold;
            color: #555;
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .controls-title i {
            font-size: 1rem;
        }

        /* Animation for new nodes */
        @keyframes nodeAppear {
            0% {
                transform: scale(0.5) rotate(0deg);
                opacity: 0;
            }
            100% {
                transform: scale(1) rotate(0deg);
                opacity: 1;
            }
        }

        .new-node {
            animation: nodeAppear 0.3s ease-out forwards;
        }
    </style>
</head>
<body>
    <header>
        <h1>Technology Evolution Tree</h1>
        <div class="subtitle">Explore the progression of human innovation through history</div>
    </header>

    <div class="container">
        <div class="controls">
            <div class="controls-section">
                <div class="controls-title"><i class="fas fa-clock"></i> Era Navigation</div>
                <div class="era-navigation">
                    <button class="era-button era-ancient">Ancient</button>
                    <button class="era-button era-classical">Classical</button>
                    <button class="era-button era-medieval">Medieval</button>
                    <button class="era-button era-industrial">Industrial</button>
                    <button class="era-button era-modern">Modern</button>
                    <button class="era-button era-future">Future</button>
                </div>
            </div>

            <div class="controls-section">
                <div class="controls-title"><i class="fas fa-cog"></i> Controls</div>
                <button class="add-tech-btn" id="addTechBtn">
                    <i class="fas fa-plus"></i> Add Technology
                </button>
                <button class="toggle-edit-mode" id="toggleEditMode">
                    <i class="fas fa-edit"></i> Toggle Edit Mode
                </button>
            </div>
        </div>

        <div class="tech-tree-container" id="techTreeContainer">
            <div class="tech-tree" id="techTree">
                <!-- Era dividers -->
                <div class="era-line ancient-line"></div>
                <div class="era-line classical-line"></div>
                <div class="era-line medieval-line"></div>
                <div class="era-line industrial-line"></div>
                <div class="era-line modern-line"></div>
                <div class="era-line future-line"></div>

                <div class="era-labels">
                    <div>Ancient</div>
                    <div>Classical</div>
                    <div>Medieval</div>
                    <div>Industrial</div>
                    <div>Modern</div>
                    <div>Future</div>
                </div>

                <div class="timeline-bar">
                    <div class="tech-path"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Technology Details Popup -->
    <div class="node-popup" id="nodePopup">
        <span class="close-popup">&times;</span>
        <h3 id="popupTitle">Technology Name</h3>
        <div class="era" id="popupEra">Ancient Era</div>
        <div class="description" id="popupDescription">Description of technology...</div>
        <div class="prerequisites" id="popupPrereqs">Prerequisites: None</div>
    </div>

    <!-- Add Technology Form -->
    <div class="add-node-form" id="addNodeForm">
        <h2>Add New Technology</h2>
        <form id="techForm">
            <div class="form-group">
                <label for="techName">Technology Name</label>
                <input type="text" id="techName" required placeholder="e.g., Quantum Computing">
            </div>

            <div class="form-group">
                <label for="techEra">Era</label>
                <select id="techEra" required>
                    <option value="ancient">Ancient</option>
                    <option value="classical">Classical</option>
                    <option value="medieval">Medieval</option>
                    <option value="industrial">Industrial</option>
                    <option value="modern">Modern</option>
                    <option value="future">Future</option>
                </select>
            </div>

            <div class="form-group">
                <label for="techIcon">Icon</label>
                <div class="icon-selecter" id="iconSelector">
                    <!-- Icons will be added via JavaScript -->
                </div>
            </div>

            <div class="form-group">
                <label for="techDescription">Description</label>
                <textarea id="techDescription" required placeholder="Describe the technology and its significance..."></textarea>
            </div>

            <div class="form-group">
                <label>Prerequisites</label>
                <div class="checkbox-group" id="prerequisiteCheckboxes">
                    <!-- Checkboxes will be added via JavaScript -->
                </div>
            </div>

            <div class="form-actions">
                <button type="button" class="form-cancel" id="cancelForm">Cancel</button>
                <button type="submit" class="form-submit">Add Technology</button>
            </div>
        </form>
    </div>

    <footer>
        <p>Explore the technological advancements that shaped human civilization</p>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const techTree = document.getElementById('techTree');
            const techTreeContainer = document.getElementById('techTreeContainer');
            const nodePopup = document.getElementById('nodePopup');
            const closePopup = document.querySelector('.close-popup');
            const techPath = document.querySelector('.tech-path');
            const addTechBtn = document.getElementById('addTechBtn');
            const addNodeForm = document.getElementById('addNodeForm');
            const techForm = document.getElementById('techForm');
            const cancelForm = document.getElementById('cancelForm');
            const iconSelector = document.getElementById('iconSelector');
            const prerequisiteCheckboxes = document.getElementById('prerequisiteCheckboxes');
            const toggleEditMode = document.getElementById('toggleEditMode');
            
            let selectedIcon = 'fas fa-question';
            let techData = [];
            let nextId = 1;
            let draggingNode = null;
            let offsetX, offsetY;
            let isEditMode = false;

            // Extended list of Font Awesome icons for technologies
            const commonIcons = [
                'fas fa-fire', 'fas fa-wheel', 'fas fa-seedling', 'fas fa-book',
                'fas fa-square-root-alt', 'fas fa-hammer', 'fas fa-print',
                'fas fa-compass', 'fas fa-train', 'fas fa-bolt', 'fas fa-satellite-dish',
                'fas fa-car', 'fas fa-plane', 'fas fa-computer', 'fas fa-network-wired',
                'fas fa-robot', 'fas fa-atom', 'fas fa-dna', 'fas fa-rocket',
                'fas fa-microchip', 'fas fa-brain', 'fas fa-vr-cardboard',
                'fas fa-biohazard', 'fas fa-solar-panel', 'fas fa-wind', 'fas fa-eye',
                'fas fa-bullseye', 'fas fa-tools', 'fas fa-flask', 'fas fa-microscope',
                'fas fa-disease', 'fas fa-virus', 'fas fa-dove', 'fas fa-globe',
                'fas fa-magnet', 'fas fa-lightbulb', 'fas fa-broadcast-tower',
                'fas fa-satellite', 'fas fa-shield-alt', 'fas fa-cogs', 'fas fa-brain',
                'fas fa-fan', 'fas fa-chart-line', 'fas fa-industry', 'fas fa-city',
                'fas fa-battery-full', 'fas fa-cloud', 'fas fa-database'
            ];

            // Initialize with robust technology data
            initializeTechData();

            // Draw the initial technology tree
            drawTechTree();

            // Technology data initialization
            function initializeTechData() {
                techData = [
                    // Ancient Era (4000 BCE - 500 BCE)
                    {
                        id: nextId++,
                        name: "Fire",
                        era: "ancient",
                        icon: "fas fa-fire",
                        description: "Mastery of fire allowed for cooking, warmth, protection and became the foundation for later metallurgy and energy technologies.",
                        x: 100,
                        y: 150,
                        prerequisites: []
                    },
                    {
                        id: nextId++,
                        name: "Wheel",
                        era: "ancient",
                        icon: "fas fa-wheel",
                        description: "The invention of the wheel revolutionized transportation and mechanical applications, enabling carts, potter's wheels, and later complex machinery.",
                        x: 300,
                        y: 150,
                        prerequisites: []
                    },
                    {
                        id: nextId++,
                        name: "Agriculture",
                        era: "ancient",
                        icon: "fas fa-seedling",
                        description: "The domestication of plants led to settled communities, food surplus, and the development of complex societies and specialization.",
                        x: 500,
                        y: 150,
                        prerequisites: [1] // Requires Fire
                    },
                    {
                        id: nextId++,
                        name: "Writing",
                        era: "ancient",
                        icon: "fas fa-book",
                        description: "Early writing systems like cuneiform and hieroglyphics emerged for record keeping, enabling complex administration and knowledge transmission.",
                        x: 700,
                        y: 150,
                        prerequisites: [3] // Requires Agriculture
                    },
                    
                    // Classical Era (500 BCE - 500 CE)
                    {
                        id: nextId++,
                        name: "Mathematics",
                        era: "classical",
                        icon: "fas fa-square-root-alt",
                        description: "Systematic development of mathematics including geometry, algebra, and number theory that became foundational for all sciences.",
                        x: 100,
                        y: 450,
                        prerequisites: [4] // Requires Writing
                    },
                    {
                        id: nextId++,
                        name: "Architecture",
                        era: "classical",
                        icon: "fas fa-archway",
                        description: "Advanced techniques in construction enabled monumental buildings like temples, aqueducts and coliseums using arches, domes and concrete.",
                        x: 300,
                        y: 450,
                        prerequisites: [5] // Requires Mathematics
                    },
                    {
                        id: nextId++,
                        name: "Metalworking",
                        era: "classical",
                        icon: "fas fa-hammer",
                        description: "Advanced techniques in smelting and forging enabled better tools, weapons, armor and the beginning of mechanical engineering.",
                        x: 500,
                        y: 450,
                        prerequisites: [1] // Requires Fire
                    },
                    {
                        id: nextId++,
                        name: "Currency",
                        era: "classical",
                        icon: "fas fa-coins",
                        description: "Standardized coinage systems enabled complex trade networks and economic systems beyond simple barter.",
                        x: 700,
                        y: 450,
                        prerequisites: [4, 3] // Requires Writing, Agriculture
                    },
                    
                    // Medieval Era (500 CE - 1500 CE)
                    {
                        id: nextId++,
                        name: "Printing",
                        era: "medieval",
                        icon: "fas fa-print",
                        description: "Movable type printing enabled mass production of books, spreading literacy and enabling the Renaissance and scientific revolution.",
                        x: 100,
                        y: 750,
                        prerequisites: [4] // Requires Writing
                    },
                    {
                        id: nextId++,
                        name: "Compass",
                        era: "medieval",
                        icon: "fas fa-compass",
                        description: "The magnetic compass enabled reliable navigation at sea, facilitating global exploration, trade and cultural exchange.",
                        x: 300,
                        y: 750,
                        prerequisites: [7] // Requires Metalworking
                    },
                    {
                        id: nextId++,
                        name: "Gunpowder",
                        era: "medieval",
                        icon: "fas fa-bomb",
                        description: "Revolutionized warfare and mining, leading to new military strategies and eventually industrial explosives.",
                        x: 500,
                        y: 750,
                        prerequisites: [7] // Requires Metalworking
                    },
                    {
                        id: nextId++,
                        name: "Mechanical Clock",
                        era: "medieval",
                        icon: "fas fa-clock",
                        description: "Accurate timekeeping enabled better navigation, scheduling of economic activities, and scientific measurements.",
                        x: 700,
                        y: 750,
                        prerequisites: [7] // Requires Metalworking
                    },
                    
                    // Industrial Era (1500 CE - 1900 CE)
                    {
                        id: nextId++,
                        name: "Steam Engine",
                        era: "industrial",
                        icon: "fas fa-train",
                        description: "Powered the Industrial Revolution, transforming transportation, manufacturing and energy production.",
                        x: 100,
                        y: 1050,
                        prerequisites: [7] // Requires Metalworking
                    },
                    {
                        id: nextId++,
                        name: "Electricity",
                        era: "industrial",
                        icon: "fas fa-bolt",
                        description: "Harnessing electricity transformed every aspect of life from lighting and communication to industrial production.",
                        x: 300,
                        y: 1050,
                        prerequisites: [13] // Requires Steam Engine
                    },
                    {
                        id: nextId++,
                        name: "Telegraph",
                        era: "industrial",
                        icon: "fas fa-broadcast-tower",
                        description: "First rapid long-distance communication system that shrank the world and transformed business, news and diplomacy.",
                        x: 500,
                        y: 1050,
                        prerequisites: [14] // Requires Electricity
                    },
                    {
                        id: nextId++,
                        name: "Vaccination",
                        era: "industrial",
                        icon: "fas fa-syringe",
                        description: "Scientific immunization methods dramatically reduced mortality from infectious diseases, increasing global population health.",
                        x: 700,
                        y: 1050,
                        prerequisites: []
                    },
                    
                    // Modern Era (1900 CE - 2000 CE)
                    {
                        id: nextId++,
                        name: "Computing",
                        era: "modern",
                        icon: "fas fa-computer",
                        description: "Digital computing revolutionized information processing, leading to the Information Age and transforming society.",
                        x: 100,
                        y: 1350,
                        prerequisites: [14] // Requires Electricity
                    },
                    {
                        id: nextId++,
                        name: "Automobile",
                        era: "modern",
                        icon: "fas fa-car",
                        description: "Mass production of affordable personal vehicles transformed transportation, urban design and modern lifestyles.",
                        x: 300,
                        y: 1350,
                        prerequisites: [13, 14] // Requires Steam Engine, Electricity
                    },
                    {
                        id: nextId++,
                        name: "Aviation",
                        era: "modern",
                        icon: "fas fa-plane",
                        description: "Powered flight revolutionized global transportation, warfare and connected the world more tightly than ever before.",
                        x: 500,
                        y: 1350,
                        prerequisites: [13, 14] // Requires Steam Engine, Electricity
                    },
                    {
                        id: nextId++,
                        name: "Internet",
                        era: "modern",
                        icon: "fas fa-network-wired",
                        description: "Global digital network revolutionized communication, commerce, education and access to information.",
                        x: 700,
                        y: 1350,
                        prerequisites: [17] // Requires Computing
                    },
                    
                    // Future Era (2000 CE - beyond)
                    {
                        id: nextId++,
                        name: "AI",
                        era: "future",
                        icon: "fas fa-robot",
                        description: "Artificial Intelligence promises to automate complex tasks, enhance human capabilities and solve problems beyond human-scale processing.",
                        x: 100,
                        y: 1650,
                        prerequisites: [17, 20] // Requires Computing, Internet
                    },
                    {
                        id: nextId++,
                        name: "Fusion Power",
                        era: "future",
                        icon: "fas fa-atom",
                        description: "Nuclear fusion could provide nearly limitless clean energy, solving humanity's energy needs while reducing environmental impact.",
                        x: 300,
                        y: 1650,
                        prerequisites: [14, 17] // Requires Electricity, Computing
                    },
                    {
                        id: nextId++,
                        name: "Quantum Computing",
                        era: "future",
                        icon: "fas fa-brain",
                        description: "Harnesses quantum mechanics to perform calculations impossible for classical computers, revolutionizing cryptography, simulation and optimization.",
                        x: 500,
                        y: 1650,
                        prerequisites: [17] // Requires Computing
                    },
                    {
                        id: nextId++,
                        name: "Space Colonization",
                        era: "future",
                        icon: "fas fa-rocket",
                        description: "Establishing permanent human settlements beyond Earth would ensure species survival and open new frontiers for exploration and resources.",
                        x: 700,
                        y: 1650,
                        prerequisites: [14, 22] // Requires Electricity, Fusion Power
                    }
                ];
            }

            // Draw the entire technology tree
            function drawTechTree() {
                // Clear existing nodes and connections
                techTree.innerHTML = '';
                
                // Add back the era dividers and labels
                techTree.innerHTML += `
                    <div class="era-line ancient-line"></div>
                    <div class="era-line classical-line"></div>
                    <div class="era-line medieval-line"></div>
                    <div class="era-line industrial-line"></div>
                    <div class="era-line modern-line"></div>
                    <div class="era-line future-line"></div>
                    
                    <div class="era-labels">
                        <div style="top: 150px;">Ancient</div>
                        <div style="top: 450px;">Classical</div>
                        <div style="top: 750px;">Medieval</div>
                        <div style="top: 1050px;">Industrial</div>
                        <div style="top: 1350px;">Modern</div>
                        <div style="top: 1650px;">Future</div>
                    </div>
                `;
                
                // Draw connections first (so nodes appear on top)
                techData.forEach(tech => {
                    if (tech.prerequisites && tech.prerequisites.length) {
                        tech.prerequisites.forEach(prereqId => {
                            const prereqTech = techData.find(t => t.id === prereqId);
                            if (prereqTech) {
                                drawConnection(
                                    prereqTech.x + 50, prereqTech.y + 50, // source (center of circle)
                                    tech.x + 50, tech.y + 50 // target
                                );
                            }
                        });
                    }
                });

                // Draw the technology nodes
                techData.forEach(tech => {
                    createTechNode(tech);
                });
            }

            // Create a single technology node
            function createTechNode(tech) {
                const node = document.createElement('div');
                node.className = `tech-node ${tech.era}`;
                node.style.left = `${tech.x}px`;
                node.style.top = `${tech.y}px`;
                node.dataset.id = tech.id;
                
                node.innerHTML = `
                    <div class="tech-icon">
                        <i class="${tech.icon}"></i>
                    </div>
                    <div class="tech-name">${tech.name}</div>
                    <div class="tech-era">${tech.era.charAt(0).toUpperCase() + tech.era.slice(1)}</div>
                    <div class="drag-handle">↔</div>
                    <div class="delete-node">×</div>
                `;
                
                node.addEventListener('click', (e) => {
                    // Don't show popup if in edit mode or clicking on the delete button
                    if (isEditMode || e.target.classList.contains('delete-node') || e.target.classList.contains('drag-handle')) {
                        return;
                    }
                    
                    showTechPopup(tech);
                    animateTechPath(tech.era);
                });
                
                // Dragging functionality (only in edit mode)
                node.addEventListener('mousedown', (e) => {
                    if (!isEditMode) return;
                    
                    // Don't drag if clicking on the delete button
                    if (e.target.classList.contains('delete-node')) {
                        return;
                    }
                    
                    e.preventDefault();
                    draggingNode = node;
                    
                    // Calculate offset from mouse to node position
                    const rect = node.getBoundingClientRect();
                    offsetX = e.clientX - rect.left;
                    offsetY = e.clientY - rect.top;
                    
                    // Set the node to absolute positioning (if not already)
                    node.style.position = 'absolute';
                    
                    // Move the node to the front
                    node.style.zIndex = '1000';
                    
                    document.addEventListener('mousemove', dragNode);
                    document.addEventListener('mouseup', stopDrag);
                });
                
                // Delete functionality (only in edit mode)
                const deleteBtn = node.querySelector('.delete-node');
                deleteBtn.addEventListener('click', (e) => {
                    if (!isEditMode) return;
                    
                    e.stopPropagation();
                    if (confirm(`Delete "${tech.name}"?`)) {
                        // Remove this tech from prerequisites of other techs
                        techData.forEach(t => {
                            t.prerequisites = t.prerequisites.filter(id => id !== tech.id);
                        });
                        
                        // Remove the tech
                        techData = techData.filter(t => t.id !== tech.id);
                        
                        // Reddraw the tree
                        drawTechTree();
                    }
                });
                
                // Show/hide edit controls based on mode
                updateNodeEditControls(node);
                
                techTree.appendChild(node);
                return node;
            }

            // Update node edit controls based on current mode
            function updateNodeEditControls(node) {
                const dragHandle = node.querySelector('.drag-handle');
                const deleteBtn = node.querySelector('.delete-node');
                
                if (isEditMode) {
                    node.classList.add('editable');
                    dragHandle.style.display = 'flex';
                    deleteBtn.style.display = 'flex';
                } else {
                    node.classList.remove('editable');
                    dragHandle.style.display = 'none';
                    deleteBtn.style.display = 'none';
                }
            }

            // Function to draw a connection line between two points
            function drawConnection(x1, y1, x2, y2) {
                const line = document.createElement('div');
                line.className = 'connection';
                
                // Calculate length and angle of the line
                const length = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
                const angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI;
                
                // Style the line
                line.style.width = `${length}px`;
                line.style.left = `${x1}px`;
                line.style.top = `${y1}px`;
                line.style.transform = `rotate(${angle}deg)`;
                
                techTree.appendChild(line);
                return line;
            }

            // Drag node handler
            function dragNode(e) {
                if (!draggingNode) return;
                
                // Calculate new position
                const containerRect = techTreeContainer.getBoundingClientRect();
                let newX = e.clientX - containerRect.left - offsetX;
                let newY = e.clientY - containerRect.top - offsetY;
                
                // Constrain movement within container
                newX = Math.max(0, Math.min(newX, techTreeContainer.scrollWidth - 100));
                newY = Math.max(0, Math.min(newY, techTreeContainer.scrollHeight - 100));
                
                // Update node position
                draggingNode.style.left = `${newX}px`;
                draggingNode.style.top = `${newY}px`;
                
                // Update position in the tech data
                const techId = parseInt(draggingNode.dataset.id);
                const tech = techData.find(t => t.id === techId);
                if (tech) {
                    tech.x = newX;
                    tech.y = newY;
                }
                
                // Redraw connections
                redrawConnections();
            }

            // Stop dragging handler
            function stopDrag() {
                if (!draggingNode) return;
                
                draggingNode.style.zIndex = '10';
                draggingNode = null;
                document.removeEventListener('mousemove', dragNode);
                document.removeEventListener('mouseup', stopDrag);
            }

            // Redraw just the connections (more efficient than redrawing the whole tree)
            function redrawConnections() {
                // Remove all connection elements
                const connections = document.querySelectorAll('.connection');
                connections.forEach(c => c.remove());
                
                // Redraw all connections
                techData.forEach(tech => {
                    if (tech.prerequisites && tech.prerequisites.length) {
                        tech.prerequisites.forEach(prereqId => {
                            const prereqTech = techData.find(t => t.id === prereqId);
                            if (prereqTech) {
                                drawConnection(
                                    prereqTech.x + 50, prereqTech.y + 50,
                                    tech.x + 50, tech.y + 50
                                );
                            }
                        });
                    }
                });
            }

            // Show technology details popup
            function showTechPopup(tech) {
                document.getElementById('popupTitle').textContent = tech.name;
                
                // Format era with appropriate color
                const eraElement = document.getElementById('popupEra');
                eraElement.textContent = `${tech.era.charAt(0).toUpperCase() + tech.era.slice(1)} Era`;
                eraElement.className = `era ${tech.era}`;
                
                document.getElementById('popupDescription').textContent = tech.description;
                
                if (tech.prerequisites && tech.prerequisites.length) {
                    const prereqNames = tech.prerequisites.map(id => {
                        const prereq = techData.find(t => t.id === id);
                        return prereq ? prereq.name : 'Unknown Technology';
                    }).join(', ');
                    document.getElementById('popupPrereqs').textContent = 
                        `Prerequisites: ${prereqNames}`;
                } else {
                    document.getElementById('popupPrereqs').textContent = 
                        'Prerequisites: None (starting technology)';
                }
                
                // Show the popup with animation
                nodePopup.classList.add('active');
            }

            // Close popup when clicking the X
            closePopup.addEventListener('click', () => {
                nodePopup.classList.remove('active');
            });

            // Close popup when clicking outside
            window.addEventListener('click', (e) => {
                if (e.target === nodePopup) {
                    nodePopup.classList.remove('active');
                }
            });

            // Show add technology form
            addTechBtn.addEventListener('click', () => {
                // Populate icon selector
                iconSelector.innerHTML = '';
                commonIcons.forEach(icon => {
                    const iconOption = document.createElement('div');
                    iconOption.className = `icon-option ${icon === selectedIcon ? 'selected' : ''}`;
                    iconOption.dataset.icon = icon;
                    iconOption.innerHTML = `<i class="${icon}"></i>`;
                    
                    iconOption.addEventListener('click', () => {
                        selectedIcon = icon;
                        document.querySelectorAll('.icon-option').forEach(opt => {
                            opt.classList.remove('selected');
                        });
                        iconOption.classList.add('selected');
                    });
                    
                    iconSelector.appendChild(iconOption);
                });
                
                // Populate prerequisite checkboxes
                prerequisiteCheckboxes.innerHTML = '';
                techData.forEach(tech => {
                    const checkboxItem = document.createElement('div');
                    checkboxItem.className = 'checkbox-item';
                    
                    const checkbox = document.createElement('input');
                    checkbox.type = 'checkbox';
                    checkbox.id = `prereq-${tech.id}`;
                    checkbox.value = tech.id;
                    
                    const label = document.createElement('label');
                    label.htmlFor = `prereq-${tech.id}`;
                    label.textContent = tech.name;
                    
                    checkboxItem.appendChild(checkbox);
                    checkboxItem.appendChild(label);
                    prerequisiteCheckboxes.appendChild(checkboxItem);
                });
                
                // Show the form with animation
                addNodeForm.classList.add('active');
                techForm.reset();
            });

            // Close add technology form
            cancelForm.addEventListener('click', () => {
                addNodeForm.classList.remove('active');
                techForm.reset();
            });

            // Submit new technology
            techForm.addEventListener('submit', (e) => {
                e.preventDefault();
                
                const name = document.getElementById('techName').value;
                const era = document.getElementById('techEra').value;
                const description = document.getElementById('techDescription').value;
                
                // Get selected prerequisites
                const prerequisites = [];
                document.querySelectorAll('#prerequisiteCheckboxes input:checked').forEach(checkbox => {
                    prerequisites.push(parseInt(checkbox.value));
                });
                
                // Determine default position based on era
                let x, y;
                const eraTechs = techData.filter(t => t.era === era);
                
                if (eraTechs.length > 0) {
                    // Position new node near others of the same era
                    const lastTech = eraTechs[eraTechs.length - 1];
                    x = lastTech.x + 200;
                    y = lastTech.y;
                } else {
                    // First tech of this era - position appropriately
                    switch(era) {
                        case 'ancient': y = 150; break;
                        case 'classical': y = 450; break;
                        case 'medieval': y = 750; break;
                        case 'industrial': y = 1050; break;
                        case 'modern': y = 1350; break;
                        case 'future': y = 1650; break;
                        default: y = 150;
                    }
                    x = 100;
                }
                
                // Create the new tech
                const newTech = {
                    id: nextId++,
                    name,
                    era,
                    icon: selectedIcon,
                    description,
                    x,
                    y,
                    prerequisites
                };
                
                // Add to our data
                techData.push(newTech);
                
                // Redraw the tree
                drawTechTree();
                
                // Close and reset the form
                addNodeForm.classList.remove('active');
                techForm.reset();
                
                // Scroll to show the new node
                techTreeContainer.scrollTo({
                    top: y - 100,
                    behavior: 'smooth'
                });
            });

            // Animate the timeline path to show current era
            function animateTechPath(era) {
                let height = 0;
                switch(era) {
                    case 'ancient': height = 7; break;
                    case 'classical': height = 20; break;
                    case 'medieval': height = 35; break;
                    case 'industrial': height = 50; break;
                    case 'modern': height = 70; break;
                    case 'future': height = 100; break;
                }
                techPath.style.height = `${height}%`;
            }

            // Era navigation buttons
            document.querySelectorAll('.era-button').forEach(button => {
                button.addEventListener('click', () => {
                    const era = button.textContent.toLowerCase();
                    scrollToEra(era);
                    animateTechPath(era);
                });
            });

            // Scroll to specific era
            function scrollToEra(era) {
                let scrollTop;
                switch(era) {
                    case 'ancient': scrollTop = 0; break;
                    case 'classical': scrollTop = 300; break;
                    case 'medieval': scrollTop = 600; break;
                    case 'industrial': scrollTop = 900; break;
                    case 'modern': scrollTop = 1200; break;
                    case 'future': scrollTop = 1500; break;
                    default: scrollTop = 0;
                }
                
                techTreeContainer.scrollTo({
                    top: scrollTop,
                    behavior: 'smooth'
                });
            }

            // Toggle edit mode
            toggleEditMode.addEventListener('click', () => {
                isEditMode = !isEditMode;
                
                // Update button appearance
                if (isEditMode) {
                    toggleEditMode.classList.add('active');
                    toggleEditMode.innerHTML = '<i class="fas fa-check"></i> Edit Mode ON';
                    techTreeContainer.classList.add('editable-mode');
                } else {
                    toggleEditMode.classList.remove('active');
                    toggleEditMode.innerHTML = '<i class="fas fa-edit"></i> Toggle Edit Mode';
                    techTreeContainer.classList.remove('editable-mode');
                }
                
                // Update all nodes
                document.querySelectorAll('.tech-node').forEach(node => {
                    updateNodeEditControls(node);
                });
            });

            // Initial load - set to ancient era
            animateTechPath('ancient');
        });
    </script>
</body>
</html>