File size: 55,098 Bytes
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
6e7a654
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
09eca26
 
6e7a654
09eca26
 
6e7a654
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
6e7a654
 
 
09eca26
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
6e7a654
09eca26
 
6e7a654
 
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
09eca26
6e7a654
 
 
 
 
09eca26
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
6e7a654
 
 
09eca26
6e7a654
 
09eca26
6e7a654
 
 
 
 
09eca26
 
 
 
 
6e7a654
 
 
09eca26
 
 
 
 
6e7a654
 
 
 
 
 
 
09eca26
6e7a654
 
09eca26
6e7a654
 
 
 
09eca26
 
 
 
6e7a654
 
09eca26
6e7a654
09eca26
 
 
 
6e7a654
 
 
 
 
 
 
 
09eca26
 
 
6e7a654
09eca26
6e7a654
09eca26
6e7a654
 
 
 
09eca26
 
6e7a654
09eca26
6e7a654
 
09eca26
6e7a654
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
09eca26
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
09eca26
6e7a654
 
09eca26
6e7a654
 
09eca26
 
 
 
 
 
 
6e7a654
09eca26
6e7a654
 
09eca26
6e7a654
 
09eca26
 
6e7a654
 
 
 
 
 
 
09eca26
6e7a654
 
 
09eca26
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
09eca26
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09eca26
 
 
6e7a654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lake Minnetonka: Sailing Tower Defense</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #1a1a2e;
            overflow: hidden;
            font-family: 'Georgia', serif;
            user-select: none;
        }
        
        canvas {
            display: block;
            cursor: crosshair;
        }
        
        .ui-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 100;
        }
        
        .ui-panel {
            pointer-events: auto;
        }
        
        .controls {
            position: absolute;
            top: 20px;
            left: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
            min-width: 200px;
        }
        
        .controls h3 {
            margin: 0 0 10px 0;
            color: #daa520;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
        }
        
        .controls p {
            margin: 5px 0;
            font-size: 12px;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
        }
        
        .resource-panel {
            position: absolute;
            top: 20px;
            right: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
            min-width: 200px;
        }
        
        .tower-shop {
            position: absolute;
            bottom: 20px;
            left: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
            display: flex;
            gap: 10px;
        }
        
        .tower-button {
            background: rgba(139, 69, 19, 0.8);
            border: 2px solid #d4af37;
            color: #d4af37;
            padding: 10px;
            border-radius: 5px;
            cursor: pointer;
            font-family: Georgia, serif;
            font-size: 12px;
            transition: all 0.3s;
        }
        
        .tower-button:hover {
            background: rgba(218, 165, 32, 0.3);
            border-color: #daa520;
        }
        
        .tower-button.selected {
            background: rgba(218, 165, 32, 0.6);
            border-color: #FFD700;
        }
        
        .tower-button.disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }
        
        .wave-info {
            position: absolute;
            bottom: 20px;
            right: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
        }
        
        .environment-info {
            position: absolute;
            bottom: 140px;
            left: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
        }
        
        .wind-indicator {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: #87CEEB;
            background: rgba(0, 0, 0, 0.8);
            padding: 10px;
            border-radius: 50%;
            border: 2px solid #87CEEB;
            width: 80px;
            height: 80px;
            text-align: center;
            font-size: 16px;
        }
        
        .area-indicator {
            position: absolute;
            top: 120px;
            left: 50%;
            transform: translateX(-50%);
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 10px;
            border-radius: 10px;
            border: 2px solid #8B4513;
            text-align: center;
            min-width: 150px;
        }
        
        .health-bar {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 300px;
            height: 20px;
            background: rgba(139, 0, 0, 0.8);
            border: 2px solid #8B4513;
            border-radius: 10px;
            overflow: hidden;
        }
        
        .health-fill {
            height: 100%;
            background: linear-gradient(90deg, #FF6B35, #DAA520);
            transition: width 0.5s;
        }
        
        .game-over {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #d4af37;
            background: rgba(0, 0, 0, 0.9);
            padding: 30px;
            border-radius: 15px;
            border: 3px solid #8B4513;
            text-align: center;
            display: none;
        }
        
        .restart-button {
            background: rgba(139, 69, 19, 0.8);
            border: 2px solid #d4af37;
            color: #d4af37;
            padding: 15px 30px;
            border-radius: 10px;
            cursor: pointer;
            font-family: Georgia, serif;
            font-size: 16px;
            margin-top: 20px;
        }
        
        .cargo-panel {
            position: absolute;
            top: 180px;
            right: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #8B4513;
            min-width: 200px;
            max-height: 300px;
            overflow-y: auto;
        }
        
        .cargo-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 5px 0;
            padding: 5px;
            background: rgba(139, 69, 19, 0.3);
            border-radius: 5px;
            font-size: 14px;
        }
        
        .cargo-emoji {
            font-size: 18px;
            margin-right: 8px;
        }
        
        .island-trade-panel {
            position: absolute;
            bottom: 180px;
            right: 20px;
            color: #d4af37;
            background: rgba(0, 0, 0, 0.9);
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #FFD700;
            min-width: 250px;
            display: none;
        }
        
        .trade-button {
            background: rgba(0, 128, 0, 0.8);
            border: 2px solid #32CD32;
            color: #d4af37;
            padding: 5px 10px;
            border-radius: 3px;
            cursor: pointer;
            font-family: Georgia, serif;
            font-size: 12px;
            margin: 2px;
        }
        
        .trade-button:hover {
            background: rgba(0, 200, 0, 0.8);
        }
        
        .trade-button.buy {
            background: rgba(0, 0, 128, 0.8);
            border-color: #4169E1;
        }
        
        .trade-button.buy:hover {
            background: rgba(0, 0, 200, 0.8);
        }
        
        .island-indicator {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #FFD700;
            background: rgba(0, 0, 0, 0.8);
            padding: 10px 20px;
            border-radius: 10px;
            border: 2px solid #FFD700;
            font-size: 18px;
            display: none;
            z-index: 200;
        }
    </style>
</head>
<body>
    <div class="ui-container">
        <div class="controls ui-panel">
            <h3>⛵ Ship Controls</h3>
            <p>🎮 WASD: Direct ship movement</p>
            <p>🎯 Click: Place towers</p>
            <p>⚡ Tab: Cycle towers</p>
            <p>🔄 Shift: Boost speed</p>
        </div>
        
        <div class="resource-panel ui-panel">
            <h3>⚓ Ship Status</h3>
            <p>💰 Gold: <span id="gold">500</span></p>
            <p>🏴‍☠️ Lives: <span id="lives">3</span></p>
            <p>⚔️ Wave: <span id="wave">1</span></p>
            <p>🎯 Score: <span id="score">0</span></p>
            <p>📦 Cargo: <span id="cargo-count">0</span>/<span id="cargo-capacity">6</span></p>
        </div>
        
        <div class="cargo-panel ui-panel">
            <h3>📦 Cargo Hold</h3>
            <div id="cargo-list">
                <p style="font-style: italic; color: #888;">Empty hold</p>
            </div>
        </div>
        
        <div class="wind-indicator ui-panel">
            <div id="wind-arrow" style="font-size: 24px;">💨</div>
            <div style="font-size: 12px; margin-top: 5px;">
                <span id="wind-speed">5</span> kts
            </div>
        </div>
        
        <div class="area-indicator ui-panel">
            <h4 id="current-area">Upper Lake</h4>
            <p id="area-effect">Calm Waters</p>
        </div>
        
        <div class="tower-shop ui-panel">
            <button class="tower-button" data-tower="cannon" data-cost="100">
                🏰 Cannon<br/>$100
            </button>
            <button class="tower-button" data-tower="harpoon" data-cost="150">
                🎯 Harpoon<br/>$150
            </button>
            <button class="tower-button" data-tower="net" data-cost="200">
                🕸️ Net Trap<br/>$200
            </button>
            <button class="tower-button" data-tower="lighthouse" data-cost="300">
                🗼 Lighthouse<br/>$300
            </button>
        </div>
        
        <div class="environment-info ui-panel">
            <h4>🌊 Environment</h4>
            <p>Ship Speed: <span id="ship-speed">0</span> kts</p>
            <p>Tide: <span id="tide-info">Normal</span></p>
            <p>Wind Effect: <span id="wind-effect">+0%</span></p>
        </div>
        
        <div class="wave-info ui-panel">
            <h4>🌊 Wave Status</h4>
            <p>Enemies: <span id="enemies-left">0</span></p>
            <p>Next Wave: <span id="wave-timer">30</span>s</p>
            <button id="start-wave" class="tower-button">Start Wave</button>
        </div>
        
        <div class="island-trade-panel ui-panel" id="trade-panel">
            <h3>🏝️ Island Trading Post</h3>
            <div id="trade-content"></div>
        </div>
        
        <div class="island-indicator ui-panel" id="island-indicator">
            ⚓ Press E to Trade ⚓
        </div>
        
        <div class="health-bar ui-panel">
            <div class="health-fill" id="health-fill" style="width: 100%"></div>
        </div>
        
        <div class="game-over ui-panel" id="game-over">
            <h2>⚓ Game Over ⚓</h2>
            <p>Your fleet has been defeated!</p>
            <p>Final Score: <span id="final-score">0</span></p>
            <button class="restart-button" onclick="restartGame()">Set Sail Again</button>
        </div>
    </div>

    <script>
        // Game state
        let gameState = {
            gold: 500,
            lives: 3,
            wave: 1,
            score: 0,
            health: 100,
            selectedTower: null,
            gameRunning: true,
            waveActive: false,
            enemies: [],
            towers: [],
            projectiles: [],
            particles: [],
            windDirection: 0,
            windSpeed: 5,
            currentArea: "Upper Lake",
            shipSpeed: 0,
            cargo: [],
            cargoCapacity: 6,
            nearIsland: null
        };

        // Cargo types with their emoji representations and base values
        const cargoTypes = {
            fish: { emoji: '🐟', name: 'Fresh Fish', baseValue: 30, rarity: 0.4 },
            lumber: { emoji: '🪵', name: 'Lumber', baseValue: 25, rarity: 0.3 },
            grain: { emoji: '🌾', name: 'Grain', baseValue: 20, rarity: 0.5 },
            gems: { emoji: '💎', name: 'Gems', baseValue: 100, rarity: 0.05 },
            gold: { emoji: '🪙', name: 'Gold Coins', baseValue: 75, rarity: 0.1 },
            spices: { emoji: '🌶️', name: 'Spices', baseValue: 50, rarity: 0.15 },
            pottery: { emoji: '🏺', name: 'Pottery', baseValue: 35, rarity: 0.2 },
            tools: { emoji: '🔨', name: 'Tools', baseValue: 40, rarity: 0.25 },
            cloth: { emoji: '🧶', name: 'Fine Cloth', baseValue: 45, rarity: 0.18 },
            wine: { emoji: '🍷', name: 'Wine', baseValue: 60, rarity: 0.12 }
        };

        // Lake areas with different environmental effects
        const lakeAreas = {
            "Upper Lake": {
                center: { x: 0, z: 0 },
                radius: 50,
                windMultiplier: 1.0,
                tideEffect: 0,
                description: "Calm Waters",
                color: 0x87CEEB
            },
            "Wayzata Bay": {
                center: { x: -80, z: -60 },
                radius: 40,
                windMultiplier: 1.5,
                tideEffect: 0.2,
                description: "Strong Winds",
                color: 0x4682B4
            },
            "Crystal Bay": {
                center: { x: 70, z: -50 },
                radius: 35,
                windMultiplier: 0.7,
                tideEffect: -0.1,
                description: "Sheltered Cove",
                color: 0x20B2AA
            },
            "Carmans Bay": {
                center: { x: -50, z: 80 },
                radius: 30,
                windMultiplier: 0.8,
                tideEffect: 0.3,
                description: "Choppy Waters",
                color: 0x008B8B
            },
            "Smithtown Bay": {
                center: { x: 60, z: 70 },
                radius: 32,
                windMultiplier: 1.3,
                tideEffect: -0.2,
                description: "Swift Currents",
                color: 0x5F9EA0
            }
        };

        // Scene setup
        const scene = new THREE.Scene();
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 2000);
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMap.enabled = true;
        renderer.shadowMap.type = THREE.PCFSoftShadowMap;
        document.body.appendChild(renderer.domElement);

        // Camera controls
        let cameraOffset = new THREE.Vector3(0, 25, 30);
        
        // Player ship
        let playerShip;
        let shipRotation = 0;
        const keys = {};
        const baseSpeed = 0.4;

        // Atmospheric fog
        scene.fog = new THREE.Fog(0x2d1810, 50, 1000);

        // Create atmospheric sky
        const skyGeometry = new THREE.SphereGeometry(1000, 32, 32);
        const skyMaterial = new THREE.ShaderMaterial({
            uniforms: {
                time: { value: 0 }
            },
            vertexShader: `
                varying vec3 vWorldPosition;
                void main() {
                    vec4 worldPosition = modelMatrix * vec4(position, 1.0);
                    vWorldPosition = worldPosition.xyz;
                    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
                }
            `,
            fragmentShader: `
                uniform float time;
                varying vec3 vWorldPosition;
                void main() {
                    vec3 direction = normalize(vWorldPosition);
                    float elevation = direction.y;
                    
                    vec3 dayBlue = vec3(0.3, 0.6, 0.9);
                    vec3 horizonGold = vec3(0.9, 0.7, 0.3);
                    vec3 deepBlue = vec3(0.1, 0.2, 0.4);
                    
                    float horizonGlow = exp(-abs(elevation) * 1.5);
                    vec3 color = mix(deepBlue, dayBlue, elevation + 0.3);
                    color = mix(color, horizonGold, horizonGlow * 0.6);
                    
                    gl_FragColor = vec4(color, 1.0);
                }
            `,
            side: THREE.BackSide
        });
        const sky = new THREE.Mesh(skyGeometry, skyMaterial);
        scene.add(sky);

        // Create Lake Minnetonka water system
        const lakeGeometry = new THREE.PlaneGeometry(2000, 2000, 200, 200);
        const lakeMaterial = new THREE.ShaderMaterial({
            uniforms: {
                time: { value: 0 },
                playerPos: { value: new THREE.Vector2(0, 0) }
            },
            vertexShader: `
                uniform float time;
                uniform vec2 playerPos;
                varying vec2 vUv;
                varying vec3 vPosition;
                varying float vDistanceToPlayer;
                
                void main() {
                    vUv = uv;
                    vec3 pos = position;
                    
                    // Distance-based wave intensity
                    float distToPlayer = length(vec2(pos.x, pos.y) - playerPos);
                    vDistanceToPlayer = distToPlayer;
                    
                    // Area-specific wave patterns
                    float wave1 = sin(pos.x * 0.02 + time * 0.5) * 0.2;
                    float wave2 = sin(pos.y * 0.015 + time * 0.7) * 0.15;
                    float wave3 = sin((pos.x + pos.y) * 0.01 + time * 0.3) * 0.25;
                    
                    // Stronger waves in certain areas
                    float areaEffect = sin(pos.x * 0.005) * sin(pos.y * 0.004) * 0.1;
                    
                    pos.z = wave1 + wave2 + wave3 + areaEffect;
                    
                    vPosition = pos;
                    gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
                }
            `,
            fragmentShader: `
                uniform float time;
                uniform vec2 playerPos;
                varying vec2 vUv;
                varying vec3 vPosition;
                varying float vDistanceToPlayer;
                
                void main() {
                    vec3 deepWater = vec3(0.1, 0.3, 0.5);
                    vec3 shallowWater = vec3(0.3, 0.5, 0.7);
                    vec3 currentWater = vec3(0.2, 0.6, 0.8);
                    
                    // Area-based water coloring
                    float areaBlend = sin(vPosition.x * 0.003 + time * 0.1) * sin(vPosition.y * 0.002 + time * 0.15);
                    
                    float wave = sin(vPosition.x * 0.1 + time) * sin(vPosition.y * 0.08 + time);
                    vec3 baseColor = mix(deepWater, shallowWater, wave * 0.5 + 0.5);
                    
                    // Add current effect in certain areas
                    vec3 finalColor = mix(baseColor, currentWater, areaBlend * 0.3);
                    
                    gl_FragColor = vec4(finalColor, 0.8);
                }
            `,
            transparent: true
        });
        lakeGeometry.rotateX(-Math.PI / 2);
        const lake = new THREE.Mesh(lakeGeometry, lakeMaterial);
        scene.add(lake);

        // Create visible lake sections with different colors
        Object.entries(lakeAreas).forEach(([name, area]) => {
            const sectionGeometry = new THREE.RingGeometry(area.radius * 0.9, area.radius, 32);
            const sectionMaterial = new THREE.MeshBasicMaterial({ 
                color: area.color, 
                transparent: true, 
                opacity: 0.15,
                side: THREE.DoubleSide
            });
            const section = new THREE.Mesh(sectionGeometry, sectionMaterial);
            section.rotation.x = -Math.PI / 2;
            section.position.set(area.center.x, 0.1, area.center.z);
            section.userData = { name: name, area: area };
            scene.add(section);
        });

        // Create islands and shoreline features
        function createIsland(x, z, size, name = null) {
            const islandGeometry = new THREE.CylinderGeometry(size, size * 1.2, 2, 16);
            const islandMaterial = new THREE.MeshLambertMaterial({ color: 0x4d5d3d });
            const island = new THREE.Mesh(islandGeometry, islandMaterial);
            island.position.set(x, 0, z);
            island.castShadow = true;
            
            // Generate random cargo offerings and demands for this island
            const availableCargo = [];
            const demandedCargo = [];
            
            Object.keys(cargoTypes).forEach(type => {
                if (Math.random() < cargoTypes[type].rarity) {
                    availableCargo.push({
                        type: type,
                        quantity: Math.floor(Math.random() * 3) + 1,
                        price: Math.floor(cargoTypes[type].baseValue * (0.7 + Math.random() * 0.6))
                    });
                }
                
                if (Math.random() < 0.3) {
                    demandedCargo.push({
                        type: type,
                        quantity: Math.floor(Math.random() * 2) + 1,
                        price: Math.floor(cargoTypes[type].baseValue * (1.2 + Math.random() * 0.8))
                    });
                }
            });
            
            island.userData = { 
                type: 'island',
                name: name || `Island ${Math.floor(Math.random() * 100)}`,
                size: size,
                availableCargo: availableCargo,
                demandedCargo: demandedCargo,
                lastRestock: Date.now()
            };
            
            // Add visual cargo indicators on the island
            availableCargo.forEach((cargo, index) => {
                const indicatorGeometry = new THREE.PlaneGeometry(1, 1);
                const indicatorMaterial = new THREE.MeshBasicMaterial({
                    map: createCargoTexture(cargoTypes[cargo.type].emoji),
                    transparent: true
                });
                const indicator = new THREE.Mesh(indicatorGeometry, indicatorMaterial);
                indicator.position.set(
                    x + (Math.cos(index * Math.PI / 2) * size * 0.7),
                    3,
                    z + (Math.sin(index * Math.PI / 2) * size * 0.7)
                );
                indicator.rotation.x = -Math.PI / 4;
                scene.add(indicator);
            });
            
            scene.add(island);
            
            // Add some trees
            for (let i = 0; i < 3; i++) {
                const treeGeometry = new THREE.ConeGeometry(1, 4, 8);
                const treeMaterial = new THREE.MeshLambertMaterial({ color: 0x2d4d1d });
                const tree = new THREE.Mesh(treeGeometry, treeMaterial);
                tree.position.set(
                    x + (Math.random() - 0.5) * size * 0.8,
                    2,
                    z + (Math.random() - 0.5) * size * 0.8
                );
                scene.add(tree);
            }
            
            return island;
        }

        // Create emoji texture for cargo indicators
        function createCargoTexture(emoji) {
            const canvas = document.createElement('canvas');
            canvas.width = 64;
            canvas.height = 64;
            const context = canvas.getContext('2d');
            context.font = '48px Arial';
            context.textAlign = 'center';
            context.textBaseline = 'middle';
            context.fillText(emoji, 32, 32);
            
            const texture = new THREE.Texture(canvas);
            texture.needsUpdate = true;
            return texture;
        }

        // Create strategic islands for tower placement and trading
        const islands = [
            createIsland(-20, -30, 8, "Merchant's Harbor"),
            createIsland(30, -20, 6, "Fisher's Cove"),
            createIsland(-40, 20, 7, "Timber Point"),
            createIsland(25, 35, 5, "Spice Island"),
            createIsland(0, -50, 9, "Grand Bazaar"),
            createIsland(-60, -10, 6, "Gold Coast"),
            createIsland(45, 10, 7, "Pottery Bay"),
            createIsland(-70, -50, 5, "Tool Town"),
            createIsland(55, -40, 6, "Wine Harbor"),
            createIsland(-35, 65, 7, "Gem Isle"),
            createIsland(40, 60, 6, "Cloth Port")
        ];

        // Create player ship
        function createPlayerShip() {
            const shipGroup = new THREE.Group();
            
            // Hull
            const hullGeometry = new THREE.BoxGeometry(2.5, 0.6, 8);
            const hullMaterial = new THREE.MeshLambertMaterial({ color: 0x8B4513 });
            const hull = new THREE.Mesh(hullGeometry, hullMaterial);
            hull.position.y = 0.3;
            shipGroup.add(hull);
            
            // Deck
            const deckGeometry = new THREE.BoxGeometry(2, 0.1, 7);
            const deckMaterial = new THREE.MeshLambertMaterial({ color: 0xDEB887 });
            const deck = new THREE.Mesh(deckGeometry, deckMaterial);
            deck.position.y = 0.65;
            shipGroup.add(deck);
            
            // Mast
            const mastGeometry = new THREE.CylinderGeometry(0.15, 0.15, 10);
            const mastMaterial = new THREE.MeshLambertMaterial({ color: 0x654321 });
            const mast = new THREE.Mesh(mastGeometry, mastMaterial);
            mast.position.y = 5.6;
            shipGroup.add(mast);
            
            // Main sail
            const sailGeometry = new THREE.PlaneGeometry(4, 6);
            const sailMaterial = new THREE.MeshLambertMaterial({ 
                color: 0xffffff,
                transparent: true,
                opacity: 0.9,
                side: THREE.DoubleSide
            });
            const sail = new THREE.Mesh(sailGeometry, sailMaterial);
            sail.position.set(2, 5, 0);
            sail.userData = { type: 'sail' };
            shipGroup.add(sail);
            
            // Bow decoration
            const bowGeometry = new THREE.ConeGeometry(0.3, 1.5, 8);
            const bowMaterial = new THREE.MeshLambertMaterial({ color: 0xFFD700 });
            const bow = new THREE.Mesh(bowGeometry, bowMaterial);
            bow.rotation.x = Math.PI / 2;
            bow.position.set(0, 1, 4);
            shipGroup.add(bow);
            
            shipGroup.position.set(0, 1, 0);
            return shipGroup;
        }

        playerShip = createPlayerShip();
        scene.add(playerShip);

        // Enemy ship creation (same as before)
        function createEnemyShip() {
            const shipGroup = new THREE.Group();
            
            const hullGeometry = new THREE.BoxGeometry(1.5, 0.4, 4);
            const hullMaterial = new THREE.MeshLambertMaterial({ color: 0x2c1810 });
            const hull = new THREE.Mesh(hullGeometry, hullMaterial);
            hull.position.y = 0.2;
            shipGroup.add(hull);
            
            const flagGeometry = new THREE.PlaneGeometry(1, 1);
            const flagMaterial = new THREE.MeshLambertMaterial({ 
                color: 0x000000,
                transparent: true,
                opacity: 0.8
            });
            const flag = new THREE.Mesh(flagGeometry, flagMaterial);
            flag.position.set(0, 3, 0);
            shipGroup.add(flag);
            
            return shipGroup;
        }

        // Tower creation functions (same as before but keeping them)
        function createCannonTower(position) {
            const towerGroup = new THREE.Group();
            
            const baseGeometry = new THREE.CylinderGeometry(1.5, 2, 2);
            const baseMaterial = new THREE.MeshLambertMaterial({ color: 0x654321 });
            const base = new THREE.Mesh(baseGeometry, baseMaterial);
            towerGroup.add(base);
            
            const cannonGeometry = new THREE.CylinderGeometry(0.2, 0.3, 2);
            const cannonMaterial = new THREE.MeshLambertMaterial({ color: 0x2c2c2c });
            const cannon = new THREE.Mesh(cannonGeometry, cannonMaterial);
            cannon.rotation.z = Math.PI / 2;
            cannon.position.y = 1.5;
            towerGroup.add(cannon);
            
            towerGroup.position.copy(position);
            towerGroup.userData = {
                type: 'cannon',
                range: 30,
                damage: 25,
                fireRate: 1000,
                lastFire: 0,
                cost: 100
            };
            
            return towerGroup;
        }

        function createHarpoonTower(position) {
            const towerGroup = new THREE.Group();
            
            const baseGeometry = new THREE.BoxGeometry(2, 1, 2);
            const baseMaterial = new THREE.MeshLambertMaterial({ color: 0x8B7355 });
            const base = new THREE.Mesh(baseGeometry, baseMaterial);
            towerGroup.add(base);
            
            const launcherGeometry = new THREE.BoxGeometry(0.5, 0.5, 3);
            const launcherMaterial = new THREE.MeshLambertMaterial({ color: 0x2c2c2c });
            const launcher = new THREE.Mesh(launcherGeometry, launcherMaterial);
            launcher.position.y = 1;
            towerGroup.add(launcher);
            
            towerGroup.position.copy(position);
            towerGroup.userData = {
                type: 'harpoon',
                range: 40,
                damage: 40,
                fireRate: 1500,
                lastFire: 0,
                cost: 150
            };
            
            return towerGroup;
        }

        function createNetTower(position) {
            const towerGroup = new THREE.Group();
            
            const baseGeometry = new THREE.CylinderGeometry(1, 1.5, 1.5);
            const baseMaterial = new THREE.MeshLambertMaterial({ color: 0x4d5d3d });
            const base = new THREE.Mesh(baseGeometry, baseMaterial);
            towerGroup.add(base);
            
            const netGeometry = new THREE.TorusGeometry(1, 0.1, 8, 16);
            const netMaterial = new THREE.MeshLambertMaterial({ color: 0x8B8B00 });
            const net = new THREE.Mesh(netGeometry, netMaterial);
            net.position.y = 2;
            towerGroup.add(net);
            
            towerGroup.position.copy(position);
            towerGroup.userData = {
                type: 'net',
                range: 25,
                damage: 15,
                fireRate: 2000,
                lastFire: 0,
                slow: 0.5,
                cost: 200
            };
            
            return towerGroup;
        }

        function createLighthouseTower(position) {
            const towerGroup = new THREE.Group();
            
            const baseGeometry = new THREE.CylinderGeometry(1.5, 2, 8);
            const baseMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
            const base = new THREE.Mesh(baseGeometry, baseMaterial);
            base.position.y = 4;
            towerGroup.add(base);
            
            const lightGeometry = new THREE.SphereGeometry(0.5);
            const lightMaterial = new THREE.MeshBasicMaterial({ color: 0xFFFF00 });
            const light = new THREE.Mesh(lightGeometry, lightMaterial);
            light.position.y = 8.5;
            towerGroup.add(light);
            
            const areaLight = new THREE.PointLight(0xFFFF00, 1, 60);
            areaLight.position.y = 8.5;
            towerGroup.add(areaLight);
            
            towerGroup.position.copy(position);
            towerGroup.userData = {
                type: 'lighthouse',
                range: 50,
                damage: 10,
                fireRate: 500,
                lastFire: 0,
                areaEffect: true,
                cost: 300
            };
            
            return towerGroup;
        }

        // Improved ship movement with area effects
        function updateShipMovement() {
            const currentArea = getCurrentArea();
            const areaData = lakeAreas[currentArea];
            
            // Base movement speed
            let moveSpeed = baseSpeed;
            
            // Apply area effects
            if (areaData) {
                // Wind effect
                const windEffect = areaData.windMultiplier;
                moveSpeed *= windEffect;
                
                // Tide effect (affects movement in certain directions)
                const tideBoost = areaData.tideEffect;
                moveSpeed += tideBoost * 0.2;
            }
            
            // Speed boost with Shift
            if (keys['ShiftLeft'] || keys['ShiftRight']) {
                moveSpeed *= 1.5;
            }
            
            // Direct WASD movement
            let movement = new THREE.Vector3(0, 0, 0);
            
            if (keys['KeyW']) movement.z -= moveSpeed;
            if (keys['KeyS']) movement.z += moveSpeed;
            if (keys['KeyA']) movement.x -= moveSpeed;
            if (keys['KeyD']) movement.x += moveSpeed;
            
            // Apply movement
            if (movement.length() > 0) {
                movement.normalize().multiplyScalar(moveSpeed);
                playerShip.position.add(movement);
                
                // Rotate ship to face movement direction
                if (movement.length() > 0) {
                    shipRotation = Math.atan2(movement.x, movement.z);
                    playerShip.rotation.y = shipRotation;
                }
            }
            
            // Constrain to lake bounds
            playerShip.position.x = Math.max(-95, Math.min(95, playerShip.position.x));
            playerShip.position.z = Math.max(-95, Math.min(95, playerShip.position.z));
            
            // Calculate actual speed for display
            gameState.shipSpeed = movement.length() * 10;
            
            // Update water shader with player position
            lakeMaterial.uniforms.playerPos.value.set(playerShip.position.x, playerShip.position.z);
        }

        // Area detection
        function getCurrentArea() {
            const playerPos = playerShip.position;
            
            for (const [name, area] of Object.entries(lakeAreas)) {
                const distance = Math.sqrt(
                    Math.pow(playerPos.x - area.center.x, 2) + 
                    Math.pow(playerPos.z - area.center.z, 2)
                );
                
                if (distance <= area.radius) {
                    return name;
                }
            }
            
            return "Open Water";
        }

        // Environment updates
        function updateEnvironment() {
            const currentArea = getCurrentArea();
            const areaData = lakeAreas[currentArea] || { windMultiplier: 1, tideEffect: 0, description: "Open Waters" };
            
            // Update current area if changed
            if (gameState.currentArea !== currentArea) {
                gameState.currentArea = currentArea;
                
                // Change wind based on area
                gameState.windSpeed = 3 + Math.random() * 4 + (areaData.windMultiplier - 1) * 2;
                gameState.windDirection += (Math.random() - 0.5) * 0.3;
            }
            
            // Random wind changes
            if (Math.random() < 0.002) {
                gameState.windDirection += (Math.random() - 0.5) * 0.5;
                gameState.windSpeed = Math.max(1, Math.min(10, gameState.windSpeed + (Math.random() - 0.5) * 2));
            }
            
            // Update sail animation based on area wind
            const sail = playerShip.children.find(child => child.userData.type === 'sail');
            if (sail) {
                const windIntensity = areaData.windMultiplier;
                sail.rotation.y = Math.sin(Date.now() * 0.003) * 0.15 * windIntensity;
                sail.position.x = 2 + Math.sin(Date.now() * 0.002) * 0.2 * windIntensity;
            }
        }

        // Input handling
        document.addEventListener('keydown', (event) => {
            keys[event.code] = true;
            
            if (event.code === 'Tab') {
                event.preventDefault();
                cycleTowerSelection();
            }
        });

        document.addEventListener('keyup', (event) => {
            keys[event.code] = false;
        });

        // Camera following
        function updateCamera() {
            const targetPosition = playerShip.position.clone().add(cameraOffset);
            camera.position.lerp(targetPosition, 0.08);
            camera.lookAt(playerShip.position);
        }

        // UI Updates
        function updateUI() {
            document.getElementById('gold').textContent = gameState.gold;
            document.getElementById('lives').textContent = gameState.lives;
            document.getElementById('wave').textContent = gameState.wave;
            document.getElementById('score').textContent = gameState.score;
            document.getElementById('enemies-left').textContent = gameState.enemies.length;
            document.getElementById('health-fill').style.width = `${gameState.health}%`;
            document.getElementById('wind-speed').textContent = Math.round(gameState.windSpeed);
            document.getElementById('ship-speed').textContent = gameState.shipSpeed.toFixed(1);
            
            // Update area info
            const currentArea = getCurrentArea();
            const areaData = lakeAreas[currentArea] || { description: "Open Waters", windMultiplier: 1, tideEffect: 0 };
            
            document.getElementById('current-area').textContent = currentArea;
            document.getElementById('area-effect').textContent = areaData.description;
            
            // Environmental effects
            const windEffect = ((areaData.windMultiplier - 1) * 100).toFixed(0);
            document.getElementById('wind-effect').textContent = `${windEffect >= 0 ? '+' : ''}${windEffect}%`;
            
            const tideText = areaData.tideEffect > 0.1 ? "Outgoing" : 
                             areaData.tideEffect < -0.1 ? "Incoming" : "Normal";
            document.getElementById('tide-info').textContent = tideText;
            
            // Update wind indicator
            const windArrow = document.getElementById('wind-arrow');
            windArrow.style.transform = `rotate(${gameState.windDirection * 180 / Math.PI}deg)`;
            
            // Update tower button states
            document.querySelectorAll('.tower-button').forEach(button => {
                if (button.dataset.cost) {
                    const cost = parseInt(button.dataset.cost);
                    button.classList.toggle('disabled', gameState.gold < cost);
                }
            });
        }

        // All combat and game logic functions remain the same...
        function createProjectile(start, target, type) {
            let projectileGeometry, projectileMaterial;
            
            switch(type) {
                case 'cannonball':
                    projectileGeometry = new THREE.SphereGeometry(0.2);
                    projectileMaterial = new THREE.MeshLambertMaterial({ color: 0x2c2c2c });
                    break;
                case 'harpoon':
                    projectileGeometry = new THREE.CylinderGeometry(0.05, 0.05, 1);
                    projectileMaterial = new THREE.MeshLambertMaterial({ color: 0x8B4513 });
                    break;
                case 'net':
                    projectileGeometry = new THREE.PlaneGeometry(1, 1);
                    projectileMaterial = new THREE.MeshLambertMaterial({ 
                        color: 0x8B8B00,
                        transparent: true,
                        opacity: 0.7
                    });
                    break;
                case 'lighthouse':
                    projectileGeometry = new THREE.SphereGeometry(0.1);
                    projectileMaterial = new THREE.MeshBasicMaterial({ color: 0xFFFF00 });
                    break;
            }
            
            const projectile = new THREE.Mesh(projectileGeometry, projectileMaterial);
            projectile.position.copy(start);
            
            const direction = new THREE.Vector3().subVectors(target, start).normalize();
            const distance = start.distanceTo(target);
            
            projectile.userData = {
                type: type,
                target: target.clone(),
                direction: direction,
                speed: 0.5,
                life: distance / 0.5
            };
            
            return projectile;
        }

        function spawnEnemyWave() {
            const waveSize = gameState.wave * 3 + 2;
            const spawnPoints = [
                new THREE.Vector3(-100, 1, -100),
                new THREE.Vector3(100, 1, -100),
                new THREE.Vector3(-100, 1, 100),
                new THREE.Vector3(100, 1, 100)
            ];
            
            for (let i = 0; i < waveSize; i++) {
                setTimeout(() => {
                    const spawnPoint = spawnPoints[i % spawnPoints.length];
                    const enemy = createEnemyShip();
                    enemy.position.copy(spawnPoint);
                    
                    const health = 50 + gameState.wave * 10;
                    const speed = 0.1 + gameState.wave * 0.02;
                    
                    enemy.userData = {
                        type: 'enemy',
                        health: health,
                        maxHealth: health,
                        speed: speed,
                        value: 25 + gameState.wave * 5,
                        slowFactor: 1,
                        slowTime: 0
                    };
                    
                    gameState.enemies.push(enemy);
                    scene.add(enemy);
                }, i * 1000);
            }
        }

        function updateTowers() {
            const currentTime = Date.now();
            
            gameState.towers.forEach(tower => {
                if (currentTime - tower.userData.lastFire < tower.userData.fireRate) return;
                
                let nearestEnemy = null;
                let nearestDistance = Infinity;
                
                gameState.enemies.forEach(enemy => {
                    const distance = tower.position.distanceTo(enemy.position);
                    if (distance <= tower.userData.range && distance < nearestDistance) {
                        nearestEnemy = enemy;
                        nearestDistance = distance;
                    }
                });
                
                if (nearestEnemy) {
                    tower.userData.lastFire = currentTime;
                    
                    const projectileType = {
                        'cannon': 'cannonball',
                        'harpoon': 'harpoon',
                        'net': 'net',
                        'lighthouse': 'lighthouse'
                    }[tower.userData.type];
                    
                    const startPos = tower.position.clone();
                    startPos.y += 2;
                    
                    const projectile = createProjectile(startPos, nearestEnemy.position, projectileType);
                    gameState.projectiles.push(projectile);
                    scene.add(projectile);
                    
                    tower.lookAt(nearestEnemy.position);
                }
            });
        }

        function updateProjectiles() {
            gameState.projectiles.forEach((projectile, index) => {
                projectile.userData.life -= 1;
                
                if (projectile.userData.life <= 0) {
                    scene.remove(projectile);
                    gameState.projectiles.splice(index, 1);
                    return;
                }
                
                const movement = projectile.userData.direction.clone().multiplyScalar(projectile.userData.speed);
                projectile.position.add(movement);
                
                gameState.enemies.forEach((enemy, enemyIndex) => {
                    if (projectile.position.distanceTo(enemy.position) < 2) {
                        const tower = gameState.towers.find(t => 
                            t.userData.type === projectile.userData.type.replace('ball', '').replace('lighthouse', 'lighthouse')
                        );
                        
                        if (tower) {
                            enemy.userData.health -= tower.userData.damage;
                            
                            if (tower.userData.type === 'net') {
                                enemy.userData.slowFactor = tower.userData.slow;
                                enemy.userData.slowTime = 3000;
                            }
                            
                            createHitEffect(enemy.position);
                        }
                        
                        scene.remove(projectile);
                        gameState.projectiles.splice(index, 1);
                    }
                });
            });
        }

        function updateEnemies() {
            gameState.enemies.forEach((enemy, index) => {
                if (enemy.userData.health <= 0) {
                    gameState.gold += enemy.userData.value;
                    gameState.score += enemy.userData.value;
                    scene.remove(enemy);
                    gameState.enemies.splice(index, 1);
                    return;
                }
                
                if (enemy.userData.slowTime > 0) {
                    enemy.userData.slowTime -= 16;
                    if (enemy.userData.slowTime <= 0) {
                        enemy.userData.slowFactor = 1;
                    }
                }
                
                const direction = new THREE.Vector3().subVectors(playerShip.position, enemy.position).normalize();
                const speed = enemy.userData.speed * enemy.userData.slowFactor;
                enemy.position.add(direction.multiplyScalar(speed));
                enemy.lookAt(playerShip.position);
                
                if (enemy.position.distanceTo(playerShip.position) < 3) {
                    gameState.health -= 20;
                    gameState.lives--;
                    scene.remove(enemy);
                    gameState.enemies.splice(index, 1);
                    
                    if (gameState.health <= 0 || gameState.lives <= 0) {
                        endGame();
                    }
                }
            });
        }

        function createHitEffect(position) {
            for (let i = 0; i < 10; i++) {
                const particleGeometry = new THREE.SphereGeometry(0.1);
                const particleMaterial = new THREE.MeshBasicMaterial({ 
                    color: Math.random() < 0.5 ? 0xFF6B35 : 0xFFFF00 
                });
                const particle = new THREE.Mesh(particleGeometry, particleMaterial);
                particle.position.copy(position);
                
                particle.userData = {
                    velocity: new THREE.Vector3(
                        (Math.random() - 0.5) * 0.2,
                        Math.random() * 0.2,
                        (Math.random() - 0.5) * 0.2
                    ),
                    life: 60
                };
                
                gameState.particles.push(particle);
                scene.add(particle);
            }
        }

        function updateParticles() {
            gameState.particles.forEach((particle, index) => {
                particle.userData.life--;
                
                if (particle.userData.life <= 0) {
                    scene.remove(particle);
                    gameState.particles.splice(index, 1);
                    return;
                }
                
                particle.position.add(particle.userData.velocity);
                particle.userData.velocity.y -= 0.005;
                particle.material.opacity = particle.userData.life / 60;
            });
        }

        // Tower placement
        let raycaster = new THREE.Raycaster();
        let mouse = new THREE.Vector2();

        renderer.domElement.addEventListener('click', (event) => {
            if (!gameState.selectedTower) return;
            
            mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
            mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
            
            raycaster.setFromCamera(mouse, camera);
            const intersects = raycaster.intersectObjects(islands);
            
            if (intersects.length > 0) {
                const position = intersects[0].point;
                position.y = 2;
                
                const cost = parseInt(document.querySelector(`[data-tower="${gameState.selectedTower}"]`).dataset.cost);
                
                if (gameState.gold >= cost) {
                    let tower;
                    switch(gameState.selectedTower) {
                        case 'cannon':
                            tower = createCannonTower(position);
                            break;
                        case 'harpoon':
                            tower = createHarpoonTower(position);
                            break;
                        case 'net':
                            tower = createNetTower(position);
                            break;
                        case 'lighthouse':
                            tower = createLighthouseTower(position);
                            break;
                    }
                    
                    if (tower) {
                        gameState.towers.push(tower);
                        scene.add(tower);
                        gameState.gold -= cost;
                        updateUI();
                    }
                }
            }
        });

        // UI event handlers
        document.querySelectorAll('.tower-button').forEach(button => {
            if (button.dataset.tower) {
                button.addEventListener('click', (e) => {
                    e.stopPropagation();
                    const towerType = button.dataset.tower;
                    const cost = parseInt(button.dataset.cost);
                    
                    if (gameState.gold >= cost) {
                        gameState.selectedTower = towerType;
                        document.querySelectorAll('.tower-button').forEach(b => b.classList.remove('selected'));
                        button.classList.add('selected');
                    }
                });
            }
        });

        document.getElementById('start-wave').addEventListener('click', () => {
            if (!gameState.waveActive) {
                startWave();
            }
        });

        function startWave() {
            gameState.waveActive = true;
            spawnEnemyWave();
            document.getElementById('start-wave').style.display = 'none';
        }

        function checkWaveComplete() {
            if (gameState.waveActive && gameState.enemies.length === 0) {
                gameState.waveActive = false;
                gameState.wave++;
                gameState.gold += 100;
                document.getElementById('start-wave').style.display = 'block';
                updateUI();
            }
        }

        function cycleTowerSelection() {
            const towers = ['cannon', 'harpoon', 'net', 'lighthouse'];
            const currentIndex = towers.indexOf(gameState.selectedTower);
            const nextIndex = (currentIndex + 1) % towers.length;
            
            const button = document.querySelector(`[data-tower="${towers[nextIndex]}"]`);
            if (button && !button.classList.contains('disabled')) {
                button.click();
            }
        }

        function endGame() {
            gameState.gameRunning = false;
            document.getElementById('final-score').textContent = gameState.score;
            document.getElementById('game-over').style.display = 'block';
        }

        function restartGame() {
            gameState = {
                gold: 500,
                lives: 3,
                wave: 1,
                score: 0,
                health: 100,
                selectedTower: null,
                gameRunning: true,
                waveActive: false,
                enemies: [],
                towers: [],
                projectiles: [],
                particles: [],
                windDirection: 0,
                windSpeed: 5,
                currentArea: "Upper Lake",
                shipSpeed: 0
            };
            
            [...gameState.enemies, ...gameState.towers, ...gameState.projectiles, ...gameState.particles]
                .forEach(obj => scene.remove(obj));
            
            playerShip.position.set(0, 1, 0);
            shipRotation = 0;
            
            document.getElementById('game-over').style.display = 'none';
            document.getElementById('start-wave').style.display = 'block';
            
            updateUI();
        }

        // Lighting
        const ambientLight = new THREE.AmbientLight(0x404070, 0.4);
        scene.add(ambientLight);

        const sunLight = new THREE.DirectionalLight(0xFFE4B5, 0.8);
        sunLight.position.set(100, 100, 50);
        sunLight.castShadow = true;
        sunLight.shadow.mapSize.width = 2048;
        sunLight.shadow.mapSize.height = 2048;
        scene.add(sunLight);

        // Animation loop
        let time = 0;
        function animate() {
            requestAnimationFrame(animate);
            time += 0.01;
            
            if (gameState.gameRunning) {
                updateShipMovement();
                updateCamera();
                updateTowers();
                updateProjectiles();
                updateEnemies();
                updateParticles();
                updateEnvironment();
                checkWaveComplete();
                updateUI();
            }
            
            lakeMaterial.uniforms.time.value = time;
            skyMaterial.uniforms.time.value = time;
            
            renderer.render(scene, camera);
        }

        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        updateUI();
        animate();
    </script>
</body>
</html>