-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
720 lines (671 loc) · 49.1 KB
/
Copy pathindex.html
File metadata and controls
720 lines (671 loc) · 49.1 KB
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
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>世界十大潛點地圖</title>
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore-compat.js"></script>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{background:#020d1a;color:#d0e8f0;font-family:'Trebuchet MS',sans-serif;height:100vh;overflow:hidden;display:flex;flex-direction:column}
/* HEADER */
header{padding:9px 18px;background:rgba(0,15,35,0.96);border-bottom:1px solid rgba(0,200,255,0.18);display:flex;align-items:center;gap:13px;flex-shrink:0;z-index:10}
header h1{font-size:17px;font-weight:400;letter-spacing:.18em;color:#80d8f0}
header h1 span{color:#00d4ff;font-weight:700}
.hdr-right{margin-left:auto;display:flex;align-items:center;gap:10px}
.sync-badge{font-size:9.5px;color:#3a6a80;letter-spacing:.1em;display:flex;align-items:center;gap:4px}
.sync-dot{width:6px;height:6px;border-radius:50%;background:#3a6a80}
.sync-dot.live{background:#00d4ff;box-shadow:0 0 6px #00d4ff}
.user-btn{display:flex;align-items:center;gap:8px;padding:5px 11px;background:rgba(0,212,255,0.08);border:1px solid rgba(0,212,255,0.22);border-radius:20px;cursor:pointer;transition:background .15s}
.user-btn:hover{background:rgba(0,212,255,0.16)}
.user-avatar{width:22px;height:22px;border-radius:50%;background:rgba(0,212,255,0.2);display:flex;align-items:center;justify-content:center;font-size:11px;overflow:hidden;flex-shrink:0}
.user-avatar img{width:100%;height:100%;object-fit:cover}
.user-name{font-size:11.5px;color:#80d8f0;max-width:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.login-btn{padding:6px 14px;background:rgba(0,212,255,0.1);border:1px solid rgba(0,212,255,0.3);border-radius:20px;color:#00d4ff;font-size:11.5px;cursor:pointer;transition:background .15s}
.login-btn:hover{background:rgba(0,212,255,0.2)}
/* LAYOUT */
.main{display:flex;flex:1;overflow:hidden}
.map-container{flex:1;position:relative;background:radial-gradient(ellipse at 50% 40%,#0d2a4a 0%,#020d1a 100%)}
svg#world{width:100%;height:100%;display:block}
.continent{fill:#1e3d2a;stroke:#2d5e3c;stroke-width:.7;opacity:.92}
.grid-line{stroke:rgba(80,140,190,0.10);stroke-width:.5;fill:none}
.equator{stroke:rgba(0,200,255,0.18);stroke-width:.8;stroke-dasharray:4,4;fill:none}
.marker-group{cursor:pointer}
.marker-group:hover .marker-dot{r:7;filter:url(#glow2)}
@keyframes pulse{0%{r:6;opacity:.9}100%{r:22;opacity:0}}
@keyframes pulse2{0%{r:6;opacity:.7}100%{r:16;opacity:0}}
.p1{animation:pulse 2.2s ease-out infinite}
.p2{animation:pulse2 2.2s ease-out infinite .7s}
.marker-dot{fill:#00d4ff;transition:r .15s}
.marker-num{fill:#020d1a;font-size:8.5px;font-weight:700;text-anchor:middle;dominant-baseline:middle;pointer-events:none}
.visited-marker{cursor:pointer}
@keyframes pulse-gold{0%{r:5;opacity:.9}100%{r:18;opacity:0}}
.vp1{animation:pulse-gold 2s ease-out infinite;stroke:#f5c518;fill:none;stroke-width:1.5}
/* SIDEBAR */
.sidebar{width:280px;background:rgba(3,14,32,0.97);border-left:1px solid rgba(0,200,255,0.12);padding:13px 11px;overflow-y:auto;display:flex;flex-direction:column}
.sidebar::-webkit-scrollbar{width:4px}.sidebar::-webkit-scrollbar-thumb{background:rgba(0,200,255,0.18);border-radius:2px}
.section-title{font-size:10px;letter-spacing:.22em;text-transform:uppercase;color:#00d4ff;margin-bottom:10px;padding-bottom:7px;border-bottom:1px solid rgba(0,200,255,0.18)}
.leg-item{display:flex;align-items:center;gap:9px;padding:6px 9px;border-radius:6px;cursor:pointer;transition:background .15s;border:1px solid transparent;margin-bottom:3px}
.leg-item:hover{background:rgba(0,212,255,0.07);border-color:rgba(0,212,255,0.18)}
.leg-item.active{background:rgba(0,212,255,0.11);border-color:rgba(0,212,255,0.28)}
.leg-num{width:19px;height:19px;border-radius:50%;background:#00d4ff;color:#020d1a;font-size:10px;font-weight:700;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.leg-name{font-size:11px;font-weight:600;color:#b8e0f0;line-height:1.2}
.leg-loc{font-size:9.5px;color:#4a7a8a;margin-top:1px}
/* SEARCH */
.search-section{margin-bottom:13px}
.search-row{display:flex;gap:6px}
.search-input{flex:1;background:rgba(245,197,24,0.06);border:1px solid rgba(245,197,24,0.22);border-radius:6px;padding:8px 10px;color:#d0e8f0;font-size:12px;outline:none;font-family:inherit}
.search-input::placeholder{color:#3a5a68}
.search-input:focus{border-color:rgba(245,197,24,0.5)}
.search-btn{background:rgba(245,197,24,0.12);border:1px solid rgba(245,197,24,0.32);border-radius:6px;color:#f5c518;padding:8px 11px;cursor:pointer;font-size:13px;transition:background .15s}
.search-btn:hover{background:rgba(245,197,24,0.24)}
.search-btn:disabled{opacity:.4;cursor:not-allowed}
.search-results{margin-top:6px;background:rgba(3,12,28,0.99);border:1px solid rgba(245,197,24,0.16);border-radius:7px;overflow:hidden;display:none}
.sr-item{padding:9px 11px;cursor:pointer;border-bottom:1px solid rgba(245,197,24,0.07);transition:background .15s}
.sr-item:last-child{border-bottom:none}
.sr-item:hover{background:rgba(245,197,24,0.07)}
.sr-name{font-size:11.5px;font-weight:600;color:#f0d878}
.sr-detail{font-size:9.5px;color:#4a6a70;margin-top:2px}
.sr-empty{padding:11px;font-size:11px;color:#3a5a68;text-align:center}
/* VISITED */
.visited-divider{border:none;border-top:1px solid rgba(245,197,24,0.14);margin:13px 0 11px}
.visited-title{font-size:10px;letter-spacing:.22em;text-transform:uppercase;color:#f5c518;margin-bottom:10px;display:flex;align-items:center;gap:7px}
.visited-count{background:rgba(245,197,24,0.16);color:#f5c518;font-size:9px;padding:1px 6px;border-radius:10px;letter-spacing:0}
.visited-item{display:flex;align-items:flex-start;gap:8px;padding:7px 9px;border-radius:6px;cursor:pointer;transition:background .15s;border:1px solid transparent;margin-bottom:3px}
.visited-item:hover{background:rgba(245,197,24,0.07);border-color:rgba(245,197,24,0.16)}
.vi-star{color:#f5c518;font-size:13px;flex-shrink:0;margin-top:1px}
.vi-name{font-size:11.5px;font-weight:600;color:#f0d878;line-height:1.2}
.vi-date{font-size:9.5px;color:#7a6828;margin-top:1px}
.vi-del{margin-left:auto;color:rgba(255,80,80,0.32);font-size:16px;cursor:pointer;flex-shrink:0;line-height:1;padding:0 2px;transition:color .15s}
.vi-del:hover{color:rgba(255,80,80,0.8)}
.no-visited{font-size:11px;color:#2a4a52;text-align:center;padding:14px 6px;line-height:1.8}
/* LOGIN PROMPT */
.login-prompt{background:rgba(0,212,255,0.04);border:1px dashed rgba(0,212,255,0.18);border-radius:8px;padding:12px;text-align:center;margin-bottom:13px}
.login-prompt p{font-size:11px;color:#3a7080;margin-bottom:9px;line-height:1.6}
.btn-login-prompt{width:100%;padding:8px;background:rgba(0,212,255,0.1);border:1px solid rgba(0,212,255,0.3);border-radius:6px;color:#00d4ff;font-size:11.5px;cursor:pointer;transition:background .15s}
.btn-login-prompt:hover{background:rgba(0,212,255,0.2)}
/* POPUP CARDS */
.info-card,.visited-card{position:fixed;background:rgba(4,18,42,0.95);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);border-radius:10px;padding:15px;width:232px;box-shadow:0 10px 36px rgba(0,0,0,.6);z-index:200;pointer-events:none;display:none}
.info-card{border:1px solid rgba(0,212,255,0.28)}
.visited-card{border:1px solid rgba(245,197,24,0.3)}
.info-card.show,.visited-card.show{display:block;animation:fadeUp .2s ease-out;pointer-events:all}
@keyframes fadeUp{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}
.card-header{display:flex;align-items:center;gap:7px;margin-bottom:10px}
.card-badge{width:22px;height:22px;border-radius:50%;background:#00d4ff;color:#020d1a;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.vc-badge{width:22px;height:22px;border-radius:50%;background:#f5c518;color:#020d1a;font-size:13px;display:flex;align-items:center;justify-content:center;flex-shrink:0;font-weight:700}
.card-title,.vc-title{font-size:13.5px;font-weight:700;line-height:1.2}
.card-title{color:#9ad8f0}.vc-title{color:#f0d878}
.card-country,.vc-date-label{font-size:9.5px;text-transform:uppercase;letter-spacing:.1em;margin-top:1px}
.card-country{color:#3a7090}.vc-date-label{color:#7a6828}
.card-divider,.gold-divider{border:none;margin:8px 0}
.card-divider{border-top:1px solid rgba(0,212,255,0.13)}
.gold-divider{border-top:1px solid rgba(245,197,24,0.16)}
.card-grid{display:grid;grid-template-columns:1fr 1fr;gap:5px;margin-bottom:9px}
.stat{background:rgba(0,212,255,0.05);border-radius:5px;padding:6px 8px}
.vc-stat{background:rgba(245,197,24,0.05);border-radius:5px;padding:7px 10px;margin-bottom:7px}
.stat-label,.vc-stat-label{font-size:8.5px;text-transform:uppercase;letter-spacing:.08em;margin-bottom:2px}
.stat-label{color:#3a6a80}.vc-stat-label{color:#6a5818}
.stat-val{font-size:11.5px;color:#7ad4ec;font-weight:600}
.vc-stat-val{font-size:11.5px;color:#c8a830;font-weight:600}
.card-marine{font-size:10px;color:#4a8a9a;line-height:1.55}
.card-marine b{color:#80c8e0}
.vc-notes{font-size:10.5px;color:#7a7040;line-height:1.55;word-break:break-word}
.close-x{position:absolute;top:8px;right:10px;font-size:15px;cursor:pointer;pointer-events:all;line-height:1;color:rgba(0,212,255,0.35)}
.close-x.gold{color:rgba(245,197,24,0.35)}
.btn-del{width:100%;margin-top:10px;background:rgba(200,60,60,0.08);border:1px solid rgba(200,60,60,0.22);color:rgba(220,100,100,0.65);border-radius:6px;padding:7px;cursor:pointer;font-size:11px;transition:all .15s;pointer-events:all}
.btn-del:hover{background:rgba(200,60,60,0.18);color:rgba(255,120,120,0.9)}
/* ADD PLACE MODAL */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.65);z-index:400;display:none;align-items:center;justify-content:center}
.modal-overlay.show{display:flex;animation:fadeIn .15s}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.modal{background:rgba(4,16,36,0.99);border-radius:12px;padding:22px;width:320px;box-shadow:0 20px 56px rgba(0,0,0,.8)}
.modal.add-modal{border:1px solid rgba(245,197,24,0.3)}
.modal h3{font-size:14px;margin-bottom:4px;font-weight:600}
.modal h3.gold{color:#f0d878}
.modal-sub{font-size:10.5px;color:#4a6a72;margin-bottom:16px}
.form-group{margin-bottom:11px}
.form-label{font-size:9.5px;text-transform:uppercase;letter-spacing:.1em;color:#4a6a72;margin-bottom:4px;display:block}
.form-input,.form-textarea{width:100%;background:rgba(255,255,255,0.04);border:1px solid rgba(255,255,255,0.12);border-radius:6px;padding:8px 10px;color:#d0e8f0;font-size:12px;outline:none;font-family:inherit;transition:border-color .15s}
.form-input.gold-focus:focus,.form-textarea.gold-focus:focus{border-color:rgba(245,197,24,0.5);background:rgba(245,197,24,0.06)}
.form-input.blue-focus:focus{border-color:rgba(0,212,255,0.5);background:rgba(0,212,255,0.05)}
.form-textarea{resize:vertical;min-height:60px}
.form-actions{display:flex;gap:8px;margin-top:16px}
.btn-confirm-gold{flex:1;background:rgba(245,197,24,0.14);border:1px solid rgba(245,197,24,0.4);color:#f5c518;border-radius:7px;padding:9px;cursor:pointer;font-size:12px;font-weight:600;transition:background .15s}
.btn-confirm-gold:hover{background:rgba(245,197,24,0.26)}
.btn-confirm-blue{flex:1;background:rgba(0,212,255,0.12);border:1px solid rgba(0,212,255,0.38);color:#00d4ff;border-radius:7px;padding:9px;cursor:pointer;font-size:12px;font-weight:600;transition:background .15s}
.btn-confirm-blue:hover{background:rgba(0,212,255,0.24)}
.btn-cancel{background:transparent;border:1px solid rgba(255,255,255,0.1);color:#3a6a72;border-radius:7px;padding:9px 14px;cursor:pointer;font-size:12px}
.btn-cancel:hover{background:rgba(255,255,255,0.05)}
/* AUTH MODAL */
.auth-modal{border:1px solid rgba(0,212,255,0.25);max-width:340px;width:100%}
.auth-logo{font-size:32px;text-align:center;margin-bottom:8px}
.auth-modal h3{color:#80d8f0;text-align:center;font-size:16px;margin-bottom:4px}
.auth-modal .modal-sub{text-align:center}
.btn-google{width:100%;display:flex;align-items:center;justify-content:center;gap:10px;padding:10px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.16);border-radius:8px;color:#d0e8f0;font-size:12.5px;cursor:pointer;transition:background .15s;margin-bottom:14px}
.btn-google:hover{background:rgba(255,255,255,0.1)}
.auth-divider{display:flex;align-items:center;gap:10px;margin:4px 0 14px;color:#2a4a58;font-size:11px}
.auth-divider::before,.auth-divider::after{content:'';flex:1;height:1px;background:rgba(255,255,255,0.07)}
.auth-tabs{display:flex;gap:0;margin-bottom:14px;background:rgba(0,212,255,0.06);border-radius:7px;padding:3px}
.auth-tab{flex:1;padding:6px;border:none;background:transparent;color:#3a7080;font-size:12px;cursor:pointer;border-radius:5px;transition:all .15s}
.auth-tab.active{background:rgba(0,212,255,0.16);color:#00d4ff}
.auth-error{font-size:11px;color:#e06060;margin-top:10px;text-align:center;min-height:16px}
.auth-note{font-size:10px;color:#2a4a58;text-align:center;margin-top:12px;line-height:1.6}
/* USER DROPDOWN */
.user-dropdown{position:absolute;top:46px;right:18px;background:rgba(4,16,36,0.98);border:1px solid rgba(0,212,255,0.22);border-radius:9px;padding:8px;min-width:190px;z-index:300;box-shadow:0 8px 28px rgba(0,0,0,.6);display:none}
.user-dropdown.show{display:block;animation:fadeUp .15s}
.ud-info{padding:8px 10px 10px;border-bottom:1px solid rgba(0,212,255,0.1);margin-bottom:6px}
.ud-name{font-size:12.5px;font-weight:600;color:#9ad8f0}
.ud-email{font-size:10px;color:#3a6a7a;margin-top:2px}
.ud-item{display:flex;align-items:center;gap:8px;padding:7px 10px;border-radius:6px;cursor:pointer;font-size:12px;color:#7aacb8;transition:background .15s}
.ud-item:hover{background:rgba(0,212,255,0.07);color:#a8d8e8}
.ud-item.danger{color:rgba(220,100,100,0.65)}
.ud-item.danger:hover{background:rgba(200,60,60,0.1);color:rgba(255,120,120,0.9)}
/* particles */
.sea-particles{position:absolute;inset:0;pointer-events:none;overflow:hidden}
.particle{position:absolute;border-radius:50%;background:rgba(0,212,255,0.14);animation:drift linear infinite}
@keyframes drift{0%{transform:translateY(0) scale(1);opacity:.4}50%{opacity:.15}100%{transform:translateY(-40px) scale(0.5);opacity:0}}
/* SETUP BANNER */
.setup-banner{position:fixed;bottom:16px;left:50%;transform:translateX(-50%);background:rgba(245,197,24,0.12);border:1px solid rgba(245,197,24,0.35);border-radius:10px;padding:12px 18px;z-index:500;font-size:11.5px;color:#c8a830;max-width:480px;text-align:center;line-height:1.7}
.setup-banner a{color:#f5c518;text-decoration:underline;cursor:pointer}
</style>
</head>
<body>
<header>
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#00d4ff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M2 12c3-4 7-6 10-6s7 2 10 6"/><path d="M2 12c3 4 7 6 10 6s7-2 10-6"/><line x1="12" y1="2" x2="12" y2="22"/></svg>
<h1>世界 <span>十大</span> 潛點地圖</h1>
<div class="hdr-right">
<div class="sync-badge"><div class="sync-dot" id="syncDot"></div><span id="syncText">離線</span></div>
<div id="userArea">
<button class="login-btn" onclick="openAuth()">登入 / 註冊</button>
</div>
</div>
</header>
<!-- USER DROPDOWN -->
<div class="user-dropdown" id="userDropdown">
<div class="ud-info">
<div class="ud-name" id="ddName"></div>
<div class="ud-email" id="ddEmail"></div>
</div>
<div class="ud-item" onclick="closeDropdown()">📍 我的足跡地圖</div>
<div class="ud-item danger" onclick="signOutUser()">⎋ 登出</div>
</div>
<div class="main">
<div class="map-container" id="mapContainer">
<div class="sea-particles" id="particles"></div>
<svg id="world" viewBox="0 0 1000 500" preserveAspectRatio="xMidYMid meet">
<defs>
<filter id="glow"><feGaussianBlur stdDeviation="2.5" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
<filter id="glow2"><feGaussianBlur stdDeviation="4" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
<filter id="glow-gold"><feGaussianBlur stdDeviation="3" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
<radialGradient id="og" cx="50%" cy="45%"><stop offset="0%" stop-color="#0e2d4f"/><stop offset="100%" stop-color="#020d1a"/></radialGradient>
<filter id="land-shadow"><feDropShadow dx="0" dy="1" stdDeviation="2" flood-color="#000" flood-opacity=".4"/></filter>
</defs>
<rect width="1000" height="500" fill="url(#og)"/>
<line class="grid-line" x1="83" y1="0" x2="83" y2="500"/><line class="grid-line" x1="167" y1="0" x2="167" y2="500"/><line class="grid-line" x1="250" y1="0" x2="250" y2="500"/><line class="grid-line" x1="333" y1="0" x2="333" y2="500"/><line class="grid-line" x1="417" y1="0" x2="417" y2="500"/><line class="grid-line" x1="500" y1="0" x2="500" y2="500"/><line class="grid-line" x1="583" y1="0" x2="583" y2="500"/><line class="grid-line" x1="667" y1="0" x2="667" y2="500"/><line class="grid-line" x1="750" y1="0" x2="750" y2="500"/><line class="grid-line" x1="833" y1="0" x2="833" y2="500"/><line class="grid-line" x1="917" y1="0" x2="917" y2="500"/>
<line class="grid-line" x1="0" y1="83" x2="1000" y2="83"/><line class="grid-line" x1="0" y1="167" x2="1000" y2="167"/><line class="equator" x1="0" y1="250" x2="1000" y2="250"/><line class="grid-line" x1="0" y1="333" x2="1000" y2="333"/><line class="grid-line" x1="0" y1="417" x2="1000" y2="417"/>
<polygon class="continent" filter="url(#land-shadow)" points="42,50 167,47 278,50 347,119 322,128 294,139 289,150 278,181 272,222 286,228 278,228 267,222 256,206 250,192 264,167 250,169 231,178 228,194 211,197 197,186 181,161 172,156 161,144 156,117 125,97 111,86 75,92 42,78"/>
<polygon class="continent" points="333,19 375,17 400,25 405,42 390,53 360,56 335,47 322,36"/>
<polygon class="continent" filter="url(#land-shadow)" points="267,203 278,203 283,228 294,219 314,217 330,219 406,261 392,292 381,313 355,344 342,378 319,403 308,406 294,375 297,306 286,264 278,256 270,242 267,222"/>
<polygon class="continent" points="472,150 472,128 483,117 494,103 486,89 500,83 514,78 539,58 569,50 583,56 575,83 564,97 556,100 539,100 522,100 508,111 508,128 520,128 536,144 544,136 556,139 569,139 578,136 600,147 628,142 655,144 672,150 656,161 628,167 611,153 595,150 580,150"/>
<polygon class="continent" filter="url(#land-shadow)" points="569,50 667,50 778,50 889,56 972,69 972,111 889,125 875,153 847,181 833,222 808,244 800,236 786,228 756,222 739,228 722,217 706,219 697,233 680,239 658,239 650,233 640,222 633,222 625,217 622,200 636,189 644,175 655,144 672,150 680,228 700,189 694,183 684,183 678,194 667,200 656,189 644,175 636,156 628,142 600,147 578,136 569,139 556,139 544,136 536,144 520,128 508,128 508,111 522,100 539,100 556,100 564,97 575,83 583,56"/>
<polygon class="continent" points="672,189 656,189 644,175 636,156 628,142 636,167 639,178 650,189 656,200 661,211 672,219 683,211 692,200 697,189 692,183 683,183"/>
<polygon class="continent" points="600,167 614,161 628,167 644,175 650,189 644,206 636,217 625,217 622,200 611,200 600,189"/>
<polygon class="continent" points="786,228 800,236 808,244 800,253 792,264 778,278 769,292 756,264 744,247 744,239 756,233 769,228"/>
<polygon class="continent" filter="url(#land-shadow)" points="472,156 486,150 500,147 528,147 550,150 583,147 600,153 611,167 622,189 614,206 608,222 619,228 619,239 611,253 606,267 597,281 592,294 586,311 578,328 564,339 550,344 539,344 525,339 511,328 503,311 497,294 494,275 492,261 494,247 500,242 508,244 511,253 519,256 522,247 519,236 514,228 508,222 500,219 492,222 483,231 475,239 469,233 467,219 469,208 472,200 467,178 464,167"/>
<polygon class="continent" points="578,281 583,272 589,283 594,294 589,303 583,294"/>
<polygon class="continent" filter="url(#land-shadow)" points="819,311 817,325 817,336 825,342 839,342 853,339 864,347 875,353 886,358 900,356 914,358 919,342 917,328 911,311 897,294 886,289 878,283 864,286 853,289 839,297 828,303"/>
<polygon class="continent" points="942,367 945,356 950,358 953,367 948,375"/><polygon class="continent" points="944,381 947,375 953,378 950,386 944,386"/>
<polygon class="continent" points="897,136 903,128 908,131 906,139 900,142"/><polygon class="continent" points="908,128 914,122 919,125 917,133 911,136"/>
<polygon class="continent" points="481,94 484,86 489,89 489,97 484,100"/>
<rect class="continent" x="0" y="444" width="1000" height="56" opacity=".5"/>
<g id="visitedLayer"></g>
<g class="marker-group" onclick="showCard(0,event)"><circle class="p1" cx="910" cy="302" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="910" cy="302" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="910" cy="302" r="6" filter="url(#glow)"/><text class="marker-num" x="910" y="302">1</text></g>
<g class="marker-group" onclick="showCard(1,event)"><circle class="p1" cx="257" cy="202" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="257" cy="202" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="257" cy="202" r="6" filter="url(#glow)"/><text class="marker-num" x="257" y="202">2</text></g>
<g class="marker-group" onclick="showCard(2,event)"><circle class="p1" cx="874" cy="229" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="874" cy="229" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="874" cy="229" r="6" filter="url(#glow)"/><text class="marker-num" x="874" y="229">3</text></g>
<g class="marker-group" onclick="showCard(3,event)"><circle class="p1" cx="595" cy="173" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="595" cy="173" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="595" cy="173" r="6" filter="url(#glow)"/><text class="marker-num" x="595" y="173">4</text></g>
<g class="marker-group" onclick="showCard(4,event)"><circle class="p1" cx="247" cy="253" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="247" cy="253" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="247" cy="253" r="6" filter="url(#glow)"/><text class="marker-num" x="247" y="253">5</text></g>
<g class="marker-group" onclick="showCard(5,event)"><circle class="p1" cx="832" cy="274" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="832" cy="274" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="832" cy="274" r="6" filter="url(#glow)"/><text class="marker-num" x="832" y="274">6</text></g>
<g class="marker-group" onclick="showCard(6,event)"><circle class="p1" cx="703" cy="241" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="703" cy="241" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="703" cy="241" r="6" filter="url(#glow)"/><text class="marker-num" x="703" y="241">7</text></g>
<g class="marker-group" onclick="showCard(7,event)"><circle class="p1" cx="829" cy="244" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="829" cy="244" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="829" cy="244" r="6" filter="url(#glow)"/><text class="marker-num" x="829" y="244">8</text></g>
<g class="marker-group" onclick="showCard(8,event)"><circle class="p1" cx="192" cy="198" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="192" cy="198" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="192" cy="198" r="6" filter="url(#glow)"/><text class="marker-num" x="192" y="198">9</text></g>
<g class="marker-group" onclick="showCard(9,event)"><circle class="p1" cx="263" cy="236" r="6" fill="none" stroke="#00d4ff" stroke-width="1.5"/><circle class="p2" cx="263" cy="236" r="6" fill="none" stroke="#00d4ff" stroke-width="1"/><circle class="marker-dot" cx="263" cy="236" r="6" filter="url(#glow)"/><text class="marker-num" x="263" y="236">10</text></g>
</svg>
</div>
<!-- SIDEBAR -->
<div class="sidebar">
<div id="loginPrompt" class="login-prompt" style="display:none">
<p>登入後可在任何裝置<br>同步你的足跡紀念冊</p>
<button class="btn-login-prompt" onclick="openAuth()">🔑 登入 / 建立帳號</button>
</div>
<div class="search-section">
<div class="visited-title" style="margin-bottom:8px"><span style="font-size:13px">★</span> 記錄足跡</div>
<div class="search-row">
<input class="search-input" id="searchInput" type="text" placeholder="搜尋地名…" autocomplete="off" onkeydown="if(event.key==='Enter')doSearch()"/>
<button class="search-btn" id="searchBtn" onclick="doSearch()">🔍</button>
</div>
<div class="search-results" id="searchResults"></div>
</div>
<div class="section-title">十大潛點 Top 10</div>
<div id="legend" style="margin-bottom:4px"></div>
<hr class="visited-divider">
<div class="visited-title">
<span style="font-size:13px">★</span> 足跡紀念冊
<span class="visited-count" id="visitedCount">0</span>
</div>
<div id="visitedList"></div>
</div>
</div>
<!-- DIVE INFO CARD -->
<div class="info-card" id="infoCard">
<span class="close-x" onclick="hideCard()">✕</span>
<div class="card-header"><div class="card-badge" id="cBadge"></div><div><div class="card-title" id="cTitle"></div><div class="card-country" id="cCountry"></div></div></div>
<hr class="card-divider">
<div class="card-grid">
<div class="stat"><div class="stat-label">最大深度</div><div class="stat-val" id="cDepth"></div></div>
<div class="stat"><div class="stat-label">能見度</div><div class="stat-val" id="cVis"></div></div>
<div class="stat"><div class="stat-label">最佳季節</div><div class="stat-val" id="cSeason"></div></div>
<div class="stat"><div class="stat-label">難度</div><div class="stat-val" id="cLevel"></div></div>
</div>
<div class="card-marine" id="cMarine"></div>
</div>
<!-- VISITED CARD -->
<div class="visited-card" id="visitedCard">
<span class="close-x gold" onclick="hideVisitedCard()">✕</span>
<div class="card-header"><div class="vc-badge">★</div><div><div class="vc-title" id="vcTitle"></div><div class="vc-date-label">足跡記錄</div></div></div>
<hr class="gold-divider">
<div class="vc-stat"><div class="vc-stat-label">日期</div><div class="vc-stat-val" id="vcDate"></div></div>
<div class="vc-stat"><div class="vc-stat-label">備註</div><div class="vc-notes" id="vcNotes"></div></div>
<button class="btn-del" id="vcDel">🗑 移除此地點</button>
</div>
<!-- ADD PLACE MODAL -->
<div class="modal-overlay" id="addModal" onclick="if(event.target===this)closeAddModal()">
<div class="modal add-modal">
<h3 class="gold">📍 加入足跡</h3>
<div class="modal-sub" id="addModalSub"></div>
<div class="form-group"><label class="form-label">地點名稱</label><input class="form-input gold-focus" id="modalName" type="text"/></div>
<div class="form-group"><label class="form-label">到訪日期</label><input class="form-input gold-focus" id="modalDate" type="month"/></div>
<div class="form-group"><label class="form-label">備註 / 回憶</label><textarea class="form-textarea gold-focus" id="modalNotes" placeholder="記下這趟旅程的故事…"></textarea></div>
<div class="form-actions">
<button class="btn-cancel" onclick="closeAddModal()">取消</button>
<button class="btn-confirm-gold" onclick="confirmAdd()">✦ 加入地圖</button>
</div>
</div>
</div>
<!-- AUTH MODAL -->
<div class="modal-overlay" id="authModal" onclick="if(event.target===this)closeAuth()">
<div class="modal auth-modal">
<div class="auth-logo">🤿</div>
<h3>登入足跡地圖</h3>
<p class="modal-sub">登入後可跨裝置同步,與朋友分享你的潛水足跡</p>
<button class="btn-google" onclick="signInGoogle()">
<svg width="18" height="18" viewBox="0 0 24 24"><path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/><path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/><path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z"/><path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/></svg>
使用 Google 帳號登入
</button>
<div class="auth-divider"><span>或用電子郵件</span></div>
<div class="auth-tabs">
<button class="auth-tab active" id="tabLogin" onclick="setAuthTab('login')">登入</button>
<button class="auth-tab" id="tabRegister" onclick="setAuthTab('register')">建立帳號</button>
</div>
<div class="form-group"><label class="form-label">電子郵件</label><input class="form-input blue-focus" id="authEmail" type="email" placeholder="you@example.com"/></div>
<div class="form-group"><label class="form-label">密碼</label><input class="form-input blue-focus" id="authPass" type="password" placeholder="至少 6 位字元"/></div>
<div id="authNameGroup" class="form-group" style="display:none"><label class="form-label">顯示名稱</label><input class="form-input blue-focus" id="authDisplayName" type="text" placeholder="你的名字"/></div>
<div class="form-actions">
<button class="btn-cancel" onclick="closeAuth()">稍後再說</button>
<button class="btn-confirm-blue" id="authSubmitBtn" onclick="doEmailAuth()">登入</button>
</div>
<div class="auth-error" id="authError"></div>
<p class="auth-note">登入即表示你同意本站使用 Firebase 儲存你的足跡資料</p>
</div>
</div>
<script>
// ══════════════════════════════════════════════════════════════
// ⚠️ FIREBASE 設定 — 請替換為你的專案設定
// 步驟:
// 1. 前往 https://console.firebase.google.com
// 2. 建立新專案
// 3. 新增 Web App,複製設定貼到下方
// 4. 在 Authentication 啟用 Google 與 Email/Password
// 5. 建立 Firestore Database(測試模式)
// 6. 在 Firestore Rules 貼入安全規則(見最下方)
// ══════════════════════════════════════════════════════════════
const FIREBASE_CONFIG = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};
// ══════════════════════════════════════════════════════════════
// ─── Firebase init ─────────────────────────────────────────────
let db = null, auth = null, firestoreUnsubscribe = null;
const firebaseReady = FIREBASE_CONFIG.apiKey !== 'YOUR_API_KEY';
if (firebaseReady) {
firebase.initializeApp(FIREBASE_CONFIG);
auth = firebase.auth();
db = firebase.firestore();
auth.onAuthStateChanged(user => {
if (user) {
setUserUI(user);
subscribeVisited(user.uid);
} else {
clearUserUI();
if (firestoreUnsubscribe) { firestoreUnsubscribe(); firestoreUnsubscribe = null; }
loadLocalVisited();
}
});
} else {
showSetupBanner();
loadLocalVisited();
}
// ─── Auth UI ───────────────────────────────────────────────────
function setUserUI(user) {
setSyncStatus(true);
document.getElementById('loginPrompt').style.display = 'none';
const name = user.displayName || user.email.split('@')[0];
document.getElementById('userArea').innerHTML = `
<div class="user-btn" onclick="toggleDropdown(event)">
<div class="user-avatar">${user.photoURL ? `<img src="${user.photoURL}">` : name[0].toUpperCase()}</div>
<span class="user-name">${esc(name)}</span>
</div>`;
document.getElementById('ddName').textContent = name;
document.getElementById('ddEmail').textContent = user.email || '';
}
function clearUserUI() {
setSyncStatus(false);
document.getElementById('loginPrompt').style.display = 'block';
document.getElementById('userArea').innerHTML = `<button class="login-btn" onclick="openAuth()">登入 / 註冊</button>`;
}
function setSyncStatus(live) {
const dot = document.getElementById('syncDot');
const txt = document.getElementById('syncText');
dot.className = 'sync-dot' + (live ? ' live' : '');
txt.textContent = live ? '雲端同步' : '離線模式';
}
function toggleDropdown(e) {
e.stopPropagation();
document.getElementById('userDropdown').classList.toggle('show');
}
function closeDropdown() { document.getElementById('userDropdown').classList.remove('show'); }
document.addEventListener('click', () => closeDropdown());
// ─── Auth modal ────────────────────────────────────────────────
let authTab = 'login';
function openAuth() { document.getElementById('authModal').classList.add('show'); document.getElementById('authError').textContent = ''; }
function closeAuth() { document.getElementById('authModal').classList.remove('show'); }
function setAuthTab(t) {
authTab = t;
document.getElementById('tabLogin').classList.toggle('active', t==='login');
document.getElementById('tabRegister').classList.toggle('active', t==='register');
document.getElementById('authNameGroup').style.display = t==='register' ? 'block' : 'none';
document.getElementById('authSubmitBtn').textContent = t==='login' ? '登入' : '建立帳號';
document.getElementById('authError').textContent = '';
}
async function signInGoogle() {
if (!firebaseReady) return;
try {
const provider = new firebase.auth.GoogleAuthProvider();
await auth.signInWithPopup(provider);
closeAuth();
} catch(e) { document.getElementById('authError').textContent = e.message; }
}
async function doEmailAuth() {
if (!firebaseReady) return;
const email = document.getElementById('authEmail').value.trim();
const pass = document.getElementById('authPass').value;
const name = document.getElementById('authDisplayName').value.trim();
const errEl = document.getElementById('authError');
errEl.textContent = '';
if (!email || !pass) { errEl.textContent = '請填寫電子郵件與密碼'; return; }
try {
if (authTab === 'login') {
await auth.signInWithEmailAndPassword(email, pass);
} else {
const cred = await auth.createUserWithEmailAndPassword(email, pass);
if (name) await cred.user.updateProfile({ displayName: name });
}
closeAuth();
} catch(e) {
const msgs = { 'auth/user-not-found':'找不到此帳號', 'auth/wrong-password':'密碼錯誤', 'auth/email-already-in-use':'此信箱已被使用', 'auth/weak-password':'密碼太短,至少 6 位', 'auth/invalid-email':'電子郵件格式不正確' };
errEl.textContent = msgs[e.code] || e.message;
}
}
async function signOutUser() {
closeDropdown();
if (auth) await auth.signOut();
}
// ─── Firestore ─────────────────────────────────────────────────
function subscribeVisited(uid) {
if (firestoreUnsubscribe) firestoreUnsubscribe();
firestoreUnsubscribe = db.collection('users').doc(uid).collection('visited')
.orderBy('createdAt','desc')
.onSnapshot(snap => {
visited = snap.docs.map(d => ({ id: d.id, ...d.data() }));
renderVisitedMarkers();
renderVisitedList();
});
}
async function saveToCloud(place) {
const uid = auth.currentUser?.uid;
if (!uid || !db) return;
const { id, ...data } = place;
await db.collection('users').doc(uid).collection('visited').doc(String(id)).set({ ...data, createdAt: firebase.firestore.FieldValue.serverTimestamp() });
}
async function deleteFromCloud(id) {
const uid = auth.currentUser?.uid;
if (!uid || !db) return;
await db.collection('users').doc(uid).collection('visited').doc(String(id)).delete();
}
// ─── Visited places ────────────────────────────────────────────
let visited = [];
function loadLocalVisited() {
visited = JSON.parse(localStorage.getItem('divingVisited') || '[]');
renderVisitedMarkers();
renderVisitedList();
}
function isLoggedIn() { return firebaseReady && auth?.currentUser; }
function saveVisited() {
if (!isLoggedIn()) localStorage.setItem('divingVisited', JSON.stringify(visited));
}
function latLonToSVG(lat, lon) { return { x:(lon+180)/360*1000, y:(90-lat)/180*500 }; }
function starPoints(cx, cy, n, outer, inner) {
const step = Math.PI/n; let pts = [];
for (let i = 0; i < 2*n; i++) {
const r = i%2===0 ? outer : inner, a = i*step - Math.PI/2;
pts.push(`${(cx+r*Math.cos(a)).toFixed(1)},${(cy+r*Math.sin(a)).toFixed(1)}`);
}
return pts.join(' ');
}
function renderVisitedMarkers() {
const layer = document.getElementById('visitedLayer');
layer.innerHTML = '';
visited.forEach(p => {
const {x,y} = latLonToSVG(p.lat, p.lon);
const g = document.createElementNS('http://www.w3.org/2000/svg','g');
g.setAttribute('class','visited-marker');
g.addEventListener('click', e => { e.stopPropagation(); showVisitedCard(p.id, e); });
const ring = document.createElementNS('http://www.w3.org/2000/svg','circle');
ring.setAttribute('cx',x); ring.setAttribute('cy',y); ring.setAttribute('r','5'); ring.setAttribute('class','vp1');
const star = document.createElementNS('http://www.w3.org/2000/svg','polygon');
star.setAttribute('points', starPoints(x,y,5,7,3));
star.setAttribute('fill','#f5c518'); star.setAttribute('filter','url(#glow-gold)');
g.appendChild(ring); g.appendChild(star);
layer.appendChild(g);
});
}
function renderVisitedList() {
const list = document.getElementById('visitedList');
document.getElementById('visitedCount').textContent = visited.length;
list.innerHTML = '';
if (!visited.length) {
list.innerHTML = '<div class="no-visited">尚無足跡記錄<br>搜尋地名後加入地圖<br>以 ★ 標記你到過的地方</div>';
return;
}
visited.forEach(p => {
const item = document.createElement('div'); item.className = 'visited-item';
const dateStr = p.date ? p.date.replace('-','年')+'月' : '';
item.innerHTML = `<span class="vi-star">★</span><div style="flex:1"><div class="vi-name">${esc(p.name)}</div>${dateStr?`<div class="vi-date">${dateStr}</div>`:''}</div><span class="vi-del" onclick="event.stopPropagation();removeVisited('${p.id}')">×</span>`;
item.onclick = () => showVisitedCard(p.id, null);
list.appendChild(item);
});
}
function showVisitedCard(id, e) {
const p = visited.find(x => String(x.id)===String(id)); if (!p) return;
hideCard();
document.getElementById('vcTitle').textContent = p.name;
document.getElementById('vcDate').textContent = p.date ? p.date.replace('-','年')+'月' : '未記錄';
document.getElementById('vcNotes').textContent = p.notes || '(無備註)';
document.getElementById('vcDel').onclick = () => { removeVisited(p.id); hideVisitedCard(); };
e ? positionCard('visitedCard',e) : pinCard('visitedCard');
}
function hideVisitedCard() { document.getElementById('visitedCard').classList.remove('show'); }
async function removeVisited(id) {
if (isLoggedIn()) {
await deleteFromCloud(id);
} else {
visited = visited.filter(p => String(p.id) !== String(id));
saveVisited(); renderVisitedMarkers(); renderVisitedList();
}
}
// ─── Search ────────────────────────────────────────────────────
let pendingPlace = null;
async function doSearch() {
const q = document.getElementById('searchInput').value.trim(); if (!q) return;
const btn = document.getElementById('searchBtn'); btn.disabled=true; btn.textContent='…';
const el = document.getElementById('searchResults');
el.innerHTML='<div class="sr-empty">搜尋中…</div>'; el.style.display='block';
try {
const res = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(q)}&format=json&limit=5&accept-language=zh-TW,zh`);
renderSearchResults(await res.json());
} catch { el.innerHTML='<div class="sr-empty">搜尋失敗,請確認網路連線</div>'; }
finally { btn.disabled=false; btn.textContent='🔍'; }
}
function renderSearchResults(data) {
const el = document.getElementById('searchResults'); el.innerHTML='';
if (!data.length) { el.innerHTML='<div class="sr-empty">找不到結果</div>'; return; }
data.forEach(r => {
const parts = r.display_name.split(',');
const item = document.createElement('div'); item.className='sr-item';
item.innerHTML=`<div class="sr-name">${esc(parts[0].trim())}</div><div class="sr-detail">${esc(parts.slice(1,3).join(',').trim())}</div>`;
item.onclick = () => openAddModal({ name:parts[0].trim(), displayName:r.display_name, lat:parseFloat(r.lat), lon:parseFloat(r.lon) });
el.appendChild(item);
});
}
function openAddModal(place) {
pendingPlace = place;
document.getElementById('modalName').value = place.name;
document.getElementById('addModalSub').textContent = place.displayName.slice(0,60) + (place.displayName.length>60?'…':'');
document.getElementById('modalDate').value = new Date().toISOString().slice(0,7);
document.getElementById('modalNotes').value = '';
document.getElementById('searchResults').style.display='none';
document.getElementById('searchInput').value='';
document.getElementById('addModal').classList.add('show');
}
function closeAddModal() { document.getElementById('addModal').classList.remove('show'); pendingPlace=null; }
async function confirmAdd() {
if (!pendingPlace) return;
const name = document.getElementById('modalName').value.trim() || pendingPlace.name;
const date = document.getElementById('modalDate').value;
const notes = document.getElementById('modalNotes').value.trim();
const place = { id: Date.now(), name, displayName: pendingPlace.displayName, lat: pendingPlace.lat, lon: pendingPlace.lon, date, notes };
if (isLoggedIn()) {
await saveToCloud(place); // onSnapshot will update UI
} else {
visited.push(place); saveVisited(); renderVisitedMarkers(); renderVisitedList();
}
closeAddModal();
}
// ─── Dive spots ────────────────────────────────────────────────
const spots = [
{name:"大堡礁",en:"Great Barrier Reef",country:"澳洲 AUSTRALIA",depth:"30m",vis:"30m+",season:"4–11月",level:"初–進階",marine:"<b>珊瑚礁魚</b>、海龜、礁鯊、蝠鱝,全球最大珊瑚礁系統"},
{name:"藍洞",en:"Blue Hole",country:"貝里斯 BELIZE",depth:"120m",vis:"30m+",season:"4–6月",level:"進階",marine:"<b>雙髻鯊、牛鯊</b>、護士鯊,UNESCO世界遺址"},
{name:"帛琉",en:"Palau",country:"密克羅尼西亞 PALAU",depth:"40m",vis:"30m",season:"11–4月",level:"中–進階",marine:"<b>蝠鱝、水母湖</b>、鯊魚、鯨鯊"},
{name:"紅海",en:"Red Sea",country:"埃及 EGYPT",depth:"40m",vis:"35m+",season:"3–5月",level:"初–進階",marine:"<b>拿破崙魚</b>、獅子魚,能見度極佳"},
{name:"加拉巴哥群島",en:"Galápagos Islands",country:"厄瓜多 ECUADOR",depth:"30m",vis:"20m",season:"6–11月",level:"進階",marine:"<b>雙髻鯊、鯨鯊</b>、海獅、海鬣蜥"},
{name:"科摩多",en:"Komodo",country:"印尼 INDONESIA",depth:"30m",vis:"15m",season:"4–6月",level:"進階",marine:"<b>蝠鱝、海龍</b>、礁鯊,強流富含養分"},
{name:"馬爾地夫",en:"Maldives",country:"馬爾地夫 MALDIVES",depth:"30m",vis:"30m",season:"12–4月",level:"初–進階",marine:"<b>鯨鯊、蝠鱝</b>、礁鯊、海龜"},
{name:"詩巴丹島",en:"Sipadan Island",country:"馬來西亞 MALAYSIA",depth:"40m",vis:"30m",season:"4–10月",level:"中–進階",marine:"<b>綠蠵龜、雙髻鯊</b>、梭魚群"},
{name:"索科羅島",en:"Socorro Island",country:"墨西哥 MEXICO",depth:"50m",vis:"30m",season:"11–5月",level:"進階",marine:"<b>巨型蝠鱝</b>、海豚、鯨魚"},
{name:"可可島",en:"Cocos Island",country:"哥斯大黎加 COSTA RICA",depth:"40m",vis:"30m",season:"6–11月",level:"進階",marine:"<b>雙髻鯊、鯨鯊</b>、大理石魟魚"}
];
const legEl = document.getElementById('legend');
spots.forEach((s,i) => {
const d = document.createElement('div'); d.className='leg-item'; d.id='leg-'+i;
d.innerHTML=`<div class="leg-num">${i+1}</div><div><div class="leg-name">${s.name}</div><div class="leg-loc">${s.en}</div></div>`;
d.onclick=()=>activateLegend(i); legEl.appendChild(d);
});
function showCard(id,e) {
e&&e.stopPropagation(); hideVisitedCard();
const s=spots[id];
document.getElementById('cBadge').textContent=id+1;
document.getElementById('cTitle').textContent=s.name;
document.getElementById('cCountry').textContent=s.en+' · '+s.country.split(' ')[1];
document.getElementById('cDepth').textContent=s.depth;
document.getElementById('cVis').textContent=s.vis;
document.getElementById('cSeason').textContent=s.season;
document.getElementById('cLevel').textContent=s.level;
document.getElementById('cMarine').innerHTML=s.marine;
e ? positionCard('infoCard',e) : pinCard('infoCard');
document.querySelectorAll('.leg-item').forEach(el=>el.classList.remove('active'));
document.getElementById('leg-'+id)?.classList.add('active');
}
function activateLegend(id) { hideVisitedCard(); showCard(id,null); }
function hideCard() {
document.getElementById('infoCard').classList.remove('show');
document.querySelectorAll('.leg-item').forEach(el=>el.classList.remove('active'));
}
function positionCard(id,e) {
const card=document.getElementById(id); card.classList.remove('show'); void card.offsetWidth;
let x=e.clientX+18, y=e.clientY-20;
if(x+240>window.innerWidth-284) x=e.clientX-250;
if(y+220>window.innerHeight) y=window.innerHeight-230;
if(y<60) y=60;
card.style.left=x+'px'; card.style.top=y+'px'; card.classList.add('show');
}
function pinCard(id) {
const card=document.getElementById(id);
card.style.left='60px'; card.style.top='76px';
card.classList.remove('show'); void card.offsetWidth; card.classList.add('show');
}
document.getElementById('mapContainer').addEventListener('click',e=>{
if(!e.target.closest('.marker-group')&&!e.target.closest('.visited-marker')){ hideCard(); hideVisitedCard(); }
});
document.addEventListener('click',e=>{ if(!e.target.closest('.search-section')) document.getElementById('searchResults').style.display='none'; });
document.getElementById('searchInput').addEventListener('keydown',e=>{ if(e.key==='Escape') document.getElementById('searchResults').style.display='none'; });
// ─── Setup banner ──────────────────────────────────────────────
function showSetupBanner() {
const b = document.createElement('div'); b.className='setup-banner';
b.innerHTML='⚠️ Firebase 尚未設定 — 目前使用<b>離線模式</b>,足跡只儲存在這台裝置<br>前往 <a href="https://console.firebase.google.com" target="_blank">Firebase Console</a> 建立專案並填入設定,即可啟用帳號與雲端同步';
document.body.appendChild(b);
setTimeout(()=>b.style.opacity='0.5',8000);
}
// ─── Particles ─────────────────────────────────────────────────
const pc=document.getElementById('particles');
for(let i=0;i<18;i++){
const p=document.createElement('div'); p.className='particle';
const sz=2+Math.random()*4;
p.style.cssText=`width:${sz}px;height:${sz}px;left:${Math.random()*100}%;bottom:${Math.random()*100}%;animation-duration:${8+Math.random()*12}s;animation-delay:${Math.random()*8}s`;
pc.appendChild(p);
}
function esc(s){ return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
// Init
if (!firebaseReady) { loadLocalVisited(); }
/*
════════════════════════════════════════════════════════
Firestore Security Rules(貼入 Firebase Console):
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid}/{document=**} {
allow read, write: if request.auth != null
&& request.auth.uid == uid;
}
}
}
════════════════════════════════════════════════════════
*/
</script>
</body>
</html>