-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
661 lines (589 loc) · 52.9 KB
/
Copy pathindex.html
File metadata and controls
661 lines (589 loc) · 52.9 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
<!DOCTYPE html>
<html lang="en">
<script>
(function () {
try {
var mode = localStorage.getItem('chexThemeMode') || 'dark';
var color = localStorage.getItem('chexThemeColor') || 'blue';
var theme = (mode === 'dark' && color === 'blue') ? 'dark-blue' : (mode + '-' + color);
if (theme !== 'dark-blue') document.documentElement.setAttribute('data-theme', theme);
} catch (e) {}
})();
</script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>Chex</title>
<meta name="title" content="Chex - Beyond 64 Squares">
<meta name="description" content="A Modern Chess Experience. Play offline, challenge friends, explore different variants, and analyze your games.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://usamagulzar.github.io/chex/">
<meta property="og:title" content="Chex - Beyond 64 Squares">
<meta property="og:description" content="A Modern Chess Experience. Play offline, challenge friends, explore different variants, and analyze your games.">
<meta property="og:image" content="https://usamagulzar.github.io/chex/preview.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:url" content="https://usamagulzar.github.io/chex/">
<meta name="twitter:title" content="Chex - Beyond 64 Squares">
<meta name="twitter:description" content="A Modern Chess Experience. Play offline, challenge friends, explore different variants, and analyze your games.">
<meta name="twitter:image" content="https://usamagulzar.github.io/chex/preview.png">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>♟</text></svg>">
<!-- PWA: manifest + icons -->
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png">
<link rel="mask-icon" href="icons/icon-maskable-512.png" color="#4d90f0">
<!-- PWA: theming -->
<meta name="theme-color" content="#302e2b">
<meta name="color-scheme" content="dark">
<!-- PWA: standalone / installed-app behavior -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Chex">
<meta name="application-name" content="Chex">
<meta name="msapplication-TileColor" content="#302e2b">
<meta name="msapplication-TileImage" content="icons/icon-144.png">
<script src="https://www.gstatic.com/firebasejs/10.9.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.9.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.9.0/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.9.0/firebase-database-compat.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="game-wrap">
<!-- Left Panel -->
<div class="left-panel side-panel" id="leftPanel">
<!-- Top Branding & Auth Card -->
<div class="card" id="brandingCard">
<div class="card-hd" style="justify-content: space-between;">
<span style="display:flex; align-items:center;">
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:5px;"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="3" y1="9" x2="21" y2="9"></line><line x1="9" y1="21" x2="9" y2="9"></line></svg>
Chex
</span>
<button class="btn" id="installAppBtn" onclick="window.triggerInstallPrompt()" title="Install Chex as an app" style="flex: 0 0 auto; padding: 6px 12px; font-size: 0.72rem; min-width: unset; background: transparent; border: 1px solid var(--border); color: var(--dim); border-radius: 12px; box-shadow: none; display: none; align-items: center; gap: 4px; text-transform: none; letter-spacing: normal; font-weight: 600; line-height: 1.4;">
<svg viewBox="0 0 24 24" width="12" height="12" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
Install App
</button>
</div>
<div class="status-body" style="flex-direction: row; align-items: center; justify-content: space-between; padding: 14px 16px;">
<div style="flex-shrink: 0; display: flex; align-items: center; align-self: stretch; padding: 4px 0;">
<svg class="chex-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 125 57"
width="500" height="228" aria-label="Chessology" role="img">
<path fill="currentColor" fill-rule="nonzero" d="M28.5 7.5 L27.5 7.47 26.49 7.49 25.49 7.54 24.49 7.65 23.49 7.79 22.51 7.98 21.53 8.21 20.56 8.49 19.61 8.8 18.67 9.16 17.75 9.56 16.84 10 15.96 10.48 15.09 10.99 14.25 11.55 13.44 12.13 12.65 12.76 11.89 13.42 11.16 14.11 10.46 14.83 9.8 15.58 9.16 16.36 8.56 17.17 8 18 6.95 19.74 6.05 21.57 5.33 23.48 4.78 25.44 4.42 27.44 4.23 29.47 4.23 31.51 4.41 33.53 4.78 35.54 5.32 37.5 6.04 39.4 6.93 41.24 7.98 42.98 9.19 44.62 10.54 46.15 12.02 47.55 13.62 48.8 15.33 49.91 17.13 50.86 19.01 51.64 20.95 52.25 22.94 52.68 24.96 52.93 27 53 27.93 52.92 28.84 52.82 29.72 52.69 30.59 52.53 31.44 52.35 32.27 52.13 33.08 51.89 33.88 51.62 34.65 51.33 35.4 51.01 36.13 50.66 36.84 50.28 37.54 49.88 38.21 49.45 38.87 48.99 39.5 48.5 44.5 43.5 46 41 41.5 38.5 40 38 39.23 39.24 38.34 40.4 37.35 41.48 36.26 42.46 35.08 43.33 33.83 44.08 32.51 44.71 31.14 45.22 29.73 45.59 28.29 45.83 26.83 45.94 25.36 45.9 23.91 45.73 22.48 45.42 21.09 44.98 19.74 44.4 18.46 43.71 17.24 42.89 16.11 41.97 15.07 40.94 14.13 39.82 13.3 38.62 12.59 37.34 12 36 11.53 34.64 11.16 33.26 10.89 31.87 10.72 30.48 10.65 29.09 10.67 27.7 10.79 26.32 11 24.96 11.3 23.62 11.69 22.31 12.16 21.04 12.72 19.8 13.36 18.61 14.08 17.47 14.88 16.38 15.76 15.36 16.71 14.4 17.74 13.52 18.83 12.72 20 12 20.51 11.64 21.02 11.31 21.55 11.02 22.09 10.75 22.65 10.52 23.21 10.31 23.79 10.14 24.38 10 24.97 9.89 25.59 9.81 26.21 9.77 26.84 9.75 27.49 9.77 28.15 9.81 28.82 9.89 29.5 10 29.69 9.63 29.89 9.29 30.1 8.96 30.31 8.66 30.54 8.37 30.77 8.1 31 7.85 31.25 7.62 31.5 7.42 31.77 7.23 32.04 7.06 32.31 6.91 32.6 6.78 32.89 6.66 33.19 6.57 33.5 6.5 32.5 10.5 32.99 10.69 33.46 10.9 33.91 11.12 34.34 11.34 34.76 11.58 35.15 11.84 35.52 12.1 35.88 12.38 36.21 12.66 36.52 12.96 36.82 13.27 37.09 13.59 37.35 13.93 37.59 14.27 37.8 14.63 38 15 38.07 15.28 38.14 15.52 38.2 15.72 38.25 15.88 38.3 16.02 38.36 16.14 38.41 16.23 38.46 16.31 38.51 16.38 38.56 16.44 38.62 16.49 38.68 16.55 38.75 16.61 38.83 16.68 38.91 16.76 39.01 16.86 39.11 16.98 39.23 17.12 39.36 17.29 39.5 17.5 42 20.5 43.5 23 43.5 24.5 43 26 40 27 39.93 26.85 39.85 26.7 39.78 26.56 39.7 26.42 39.61 26.27 39.53 26.13 39.44 26 39.34 25.86 39.25 25.73 39.15 25.59 39.05 25.46 38.95 25.34 38.84 25.21 38.73 25.09 38.62 24.97 38.5 24.85 38.39 24.73 38.27 24.62 38.14 24.51 38.02 24.4 37.89 24.3 37.76 24.2 37.63 24.1 37.5 24 37.34 23.88 37.18 23.77 37.01 23.66 36.84 23.56 36.66 23.47 36.49 23.38 36.31 23.3 36.12 23.22 35.93 23.16 35.75 23.1 35.55 23.04 35.36 23 35.17 22.96 34.97 22.92 34.77 22.9 34.58 22.88 34.38 22.87 34.18 22.87 33.98 22.87 33.78 22.88 33.59 22.9 33.39 22.93 33.19 22.96 33 23 32.69 23.03 32.38 23.04 32.07 23.02 31.76 22.99 31.45 22.94 31.15 22.87 30.85 22.79 30.55 22.68 30.27 22.56 29.99 22.41 29.72 22.25 29.47 22.08 29.22 21.89 28.99 21.68 28.76 21.46 28.56 21.23 28.37 20.98 28.19 20.73 28.03 20.46 27.89 20.18 27.76 19.9 27.66 19.6 27.57 19.3 27.5 19 27.44 18.79 27.39 18.61 27.36 18.45 27.34 18.32 27.33 18.2 27.32 18.11 27.31 18.03 27.3 17.97 27.28 17.92 27.25 17.88 27.2 17.84 27.14 17.81 27.05 17.79 26.94 17.76 26.8 17.73 26.62 17.7 26.41 17.67 26.15 17.62 25.85 17.57 25.5 17.5 26 21.5 28 24 28 29 28.25 29.58 28.55 30.13 28.88 30.66 29.25 31.16 29.64 31.66 30.05 32.14 30.48 32.62 30.9 33.11 31.33 33.61 31.75 34.12 32.15 34.66 32.54 35.23 32.89 35.83 33.21 36.47 33.48 37.16 33.71 37.9 33.88 38.69 33.99 39.56 34.03 40.49 34 41.5 35.5 40 36 39 35.99 38.44 35.95 37.9 35.88 37.37 35.78 36.84 35.66 36.33 35.51 35.84 35.33 35.35 35.12 34.88 34.89 34.41 34.63 33.96 34.35 33.52 34.03 33.09 33.69 32.68 33.32 32.27 32.92 31.88 32.5 31.5 31 30 30.82 29.75 30.66 29.48 30.51 29.21 30.38 28.94 30.26 28.65 30.16 28.36 30.07 28.06 30 27.75 29.95 27.43 29.91 27.11 29.88 26.78 29.88 26.44 29.88 26.09 29.91 25.73 29.95 25.37 30 25 30.5 25.06 30.96 25.11 31.39 25.14 31.78 25.15 32.13 25.15 32.46 25.14 32.77 25.12 33.05 25.1 33.31 25.08 33.56 25.06 33.8 25.05 34.03 25.04 34.26 25.03 34.48 25.05 34.71 25.07 34.94 25.11 35.19 25.17 35.44 25.26 35.71 25.36 36 25.5 36.29 25.66 36.56 25.84 36.8 26.04 37.03 26.25 37.24 26.47 37.44 26.7 37.61 26.93 37.78 27.16 37.93 27.4 38.06 27.62 38.19 27.85 38.3 28.06 38.41 28.25 38.51 28.43 38.6 28.59 38.69 28.73 38.77 28.84 38.85 28.93 38.92 28.98 39 29 39.25 29.06 39.5 29.1 39.75 29.13 40 29.16 40.25 29.17 40.5 29.16 40.75 29.15 41 29.12 41.25 29.09 41.5 29.04 41.75 28.98 42 28.91 42.25 28.82 42.5 28.73 42.75 28.62 43 28.5 43.24 28.49 43.48 28.47 43.7 28.43 43.91 28.38 44.1 28.3 44.29 28.22 44.46 28.12 44.62 28 44.78 27.87 44.91 27.72 45.04 27.55 45.16 27.38 45.26 27.18 45.35 26.97 45.43 26.74 45.5 26.5 45.71 26 45.88 25.53 46.01 25.11 46.11 24.72 46.18 24.35 46.22 24.01 46.22 23.69 46.2 23.39 46.14 23.1 46.06 22.81 45.96 22.53 45.82 22.25 45.67 21.97 45.49 21.67 45.29 21.37 45.07 21.04 44.83 20.7 44.57 20.33 44.29 19.93 44 19.5 40 14 39.8 13.63 39.59 13.27 39.37 12.91 39.12 12.56 38.87 12.22 38.59 11.89 38.3 11.57 38 11.25 37.68 10.94 37.34 10.64 36.99 10.35 36.62 10.06 36.24 9.79 35.84 9.52 35.43 9.25 35 9 36 3.5 35.56 3.51 35.13 3.54 34.71 3.59 34.28 3.66 33.86 3.74 33.45 3.85 33.03 3.98 32.62 4.12 32.22 4.29 31.82 4.48 31.42 4.68 31.03 4.91 30.64 5.15 30.26 5.41 29.88 5.7 29.5 6 28.5 7.5 Z M17.5 40.5 L16 37 15.84 36.43 15.7 35.86 15.56 35.28 15.45 34.7 15.34 34.12 15.25 33.54 15.17 32.95 15.11 32.36 15.06 31.77 15.03 31.18 15.01 30.59 15 30 15.01 29.41 15.03 28.82 15.06 28.23 15.11 27.64 15.17 27.05 15.25 26.46 15.34 25.88 15.45 25.3 15.56 24.72 15.7 24.14 15.84 23.57 16 23 20 16.5 21 15 24 13 26 12 25.56 12.07 25.13 12.15 24.71 12.24 24.28 12.34 23.86 12.46 23.45 12.59 23.03 12.72 22.62 12.88 22.22 13.04 21.82 13.21 21.42 13.4 21.03 13.59 20.64 13.8 20.26 14.02 19.88 14.26 19.5 14.5 18 16 17.63 16.38 17.27 16.77 16.93 17.16 16.59 17.56 16.27 17.97 15.96 18.39 15.66 18.82 15.38 19.25 15.1 19.69 14.84 20.14 14.58 20.6 14.34 21.06 14.12 21.54 13.9 22.02 13.69 22.5 13.5 23 13.38 23.43 13.27 23.85 13.16 24.28 13.06 24.71 12.98 25.15 12.9 25.58 12.83 26.02 12.77 26.46 12.72 26.9 12.67 27.34 12.64 27.78 12.61 28.22 12.6 28.66 12.59 29.1 12.59 29.55 12.6 29.99 12.62 30.43 12.65 30.87 12.68 31.31 12.73 31.75 12.78 32.19 12.85 32.63 12.92 33.07 13 33.5 13.1 33.84 13.22 34.17 13.34 34.5 13.46 34.83 13.6 35.15 13.74 35.47 13.89 35.79 14.05 36.1 14.22 36.41 14.39 36.72 14.57 37.02 14.75 37.32 14.95 37.61 15.15 37.9 15.36 38.18 15.57 38.46 15.79 38.74 16.02 39.01 16.25 39.27 16.49 39.53 16.73 39.78 16.98 40.03 17.24 40.27 17.5 40.5 Z M36.5 17 L36.49 16.64 36.45 16.3 36.38 15.98 36.28 15.69 36.16 15.42 36.01 15.17 35.83 14.95 35.62 14.75 35.39 14.57 35.13 14.42 34.85 14.29 34.53 14.19 34.19 14.11 33.82 14.05 33.42 14.01 33 14 33.5 15.5 33.56 15.68 33.63 15.85 33.71 16.01 33.78 16.16 33.86 16.29 33.95 16.41 34.03 16.53 34.12 16.62 34.22 16.71 34.32 16.79 34.42 16.85 34.53 16.91 34.64 16.95 34.76 16.98 34.88 16.99 35 17 36.5 17 Z M51 42.5 L51 17 56.5 17 56.5 27 67 27 67 17 72.5 17 72.5 42.5 67 42.5 67 32 56.5 32 56.5 42.5 51 42.5 Z M78 42.5 L78 17 94.5 17 94.5 22 83.5 22 83.5 27.5 93.5 27.5 93.5 32 83.5 32 83.5 37.5 94.5 37.5 94.5 42.5 78 42.5 Z M96 42.5 L105 29.5 96.5 17 103 17 109 26 114.5 17 120.5 17 112.5 29.5 121.5 42.5 114.5 42.5 108.5 33.5 102.5 42.5 96 42.5 Z M96 42.5 Z"/>
</svg>
</div>
<!-- Right Side: Auth Container -->
<div id="headerAuthBox" style="display: flex; flex-direction: column; align-items: flex-end; gap: 8px;">
<!-- User Info Row -->
<div style="display: flex; align-items: center; gap: 6px;">
<svg viewBox="0 0 24 24" width="14" height="14" stroke="var(--dim)" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
<circle cx="12" cy="7" r="4"></circle>
</svg>
<span id="authUsernameDisplay" style="color: var(--text); font-family: 'Inter', sans-serif; font-weight: 700; font-size: 0.95rem;">Guest</span>
</div>
<!-- Actions Row -->
<div style="display: flex; gap: 6px;">
<button class="btn primary" id="googleSignInBtn" style="padding: 4px 12px; font-size: 0.75rem; min-width: unset; border-radius: 12px; display: flex; align-items: center; gap: 4px;">
<svg viewBox="0 0 24 24" width="12" height="12" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"></path>
<polyline points="10 17 15 12 10 7"></polyline>
<line x1="15" y1="12" x2="3" y2="12"></line>
</svg>
Sign in
</button>
<button class="btn" id="googleSignOutBtn" style="padding: 4px 10px; font-size: 0.7rem; min-width: unset; background: transparent; border: 1px solid var(--border); color: var(--dim); border-radius: 12px; box-shadow: none; display: none;">Sign out</button>
</div>
</div>
</div>
</div>
<!-- Setup Flow -->
<div class="card" id="setupCard">
<!-- Step 1: Main Menu -->
<div class="setup-step" id="stepMode">
<div class="card-hd">
Play Chex
</div>
<div class="status-body" style="padding:14px 14px 0;">
<div class="segmented-control" id="modeTabBar">
<button class="segmented-btn active" id="modeTabOnlineBtn">
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><circle cx="12" cy="12" r="10"/><path d="M2 12h20M12 2a15 15 0 0 1 0 20 15 15 0 0 1 0-20"/></svg>
Online
</button>
<button class="segmented-btn" id="modeOfflineBtn">
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/></svg>
Offline
</button>
<button class="segmented-btn" id="showGameHistoryBtn">
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>
History
</button>
</div>
</div>
<div class="status-body" style="padding:14px; gap:10px">
<!-- Online Challenge Section -->
<div class="join-code-wrap">
<input type="text" id="connIdInput" class="join-code-input" placeholder="Opponent Username" autocomplete="off" spellcheck="false" style="text-transform:none; letter-spacing:0px; font-family:'Inter',sans-serif; font-weight:600; font-size:1.1rem; padding:4px; margin-bottom:8px;">
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="diceChessToggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><rect x="2" y="2" width="20" height="20" rx="3"/><circle cx="8" cy="8" r="1.5" fill="currentColor"/><circle cx="16" cy="8" r="1.5" fill="currentColor"/><circle cx="8" cy="16" r="1.5" fill="currentColor"/><circle cx="16" cy="16" r="1.5" fill="currentColor"/><circle cx="12" cy="12" r="1.5" fill="currentColor"/></svg> Dice Chess</label></div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="fogOfWarToggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/><path d="M22 22 2 2" stroke-opacity="0.5"/></svg> Fog of War</label></div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="draftModeToggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg> Draft Mode</label></div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="chess960Toggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><path d="M6 21h12M8 21V10l4-6 4 6v11M9 14h6"/></svg> Chess960</label></div>
<div class="settings-row">
<label class="toggle-label"><input type="checkbox" id="identityTheftToggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><ellipse cx="8" cy="12" rx="3.5" ry="2.5"/><ellipse cx="16" cy="12" rx="3.5" ry="2.5"/><path d="M11.5 12h1"/><path d="M2 10c1-3 4-4 6-4s3 1 4 1 2-1 4-1 5 1 6 4"/></svg> Identity Theft</label>
<select id="identityTheftMode" class="select-input"><option value="steal">Steal</option><option value="append">Append</option></select>
</div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="handAndBrainToggle"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><path d="M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"/><path d="M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"/><path d="M15 13a4.5 4.5 0 0 0-3-4"/><path d="M17.599 6.5a3 3 0 0 0 .399-1.375"/><path d="M9 13a4.5 4.5 0 0 1 3-4"/><path d="M6.401 6.5a3 3 0 0 1-.399-1.375"/></svg> Hand and Brain</label></div>
<button class="btn primary" id="sendChallengeBtn" style="width:100%; margin-top:8px; font-size:.9rem; padding:10px;">Send Challenge</button>
</div>
</div>
</div>
<!-- Offline Variants (shown inline when offline) -->
<div class="setup-step" id="stepOfflineVariants" style="display:none">
<div class="card-hd">
<button class="back-btn" id="backToModeFromOfflineBtn">‹ Back</button>
Play Offline
</div>
<div class="status-body" style="gap:8px; padding:12px">
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="diceChessToggleOffline"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><rect x="2" y="2" width="20" height="20" rx="3"/><circle cx="8" cy="8" r="1.5" fill="currentColor"/><circle cx="16" cy="8" r="1.5" fill="currentColor"/><circle cx="8" cy="16" r="1.5" fill="currentColor"/><circle cx="16" cy="16" r="1.5" fill="currentColor"/><circle cx="12" cy="12" r="1.5" fill="currentColor"/></svg> Dice Chess</label></div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="draftModeToggleOffline"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg> Draft Mode</label></div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="chess960ToggleOffline"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><path d="M6 21h12M8 21V10l4-6 4 6v11M9 14h6"/></svg> Chess960</label></div>
<div class="settings-row">
<label class="toggle-label"><input type="checkbox" id="identityTheftToggleOffline"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><ellipse cx="8" cy="12" rx="3.5" ry="2.5"/><ellipse cx="16" cy="12" rx="3.5" ry="2.5"/><path d="M11.5 12h1"/><path d="M2 10c1-3 4-4 6-4s3 1 4 1 2-1 4-1 5 1 6 4"/></svg> Identity Theft</label>
<select id="identityTheftModeOffline" class="select-input"><option value="steal">Steal</option><option value="append">Append</option></select>
</div>
<div class="settings-row"><label class="toggle-label"><input type="checkbox" id="handAndBrainToggleOffline"> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:3px"><path d="M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"/><path d="M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"/><path d="M15 13a4.5 4.5 0 0 0-3-4"/><path d="M17.599 6.5a3 3 0 0 0 .399-1.375"/><path d="M9 13a4.5 4.5 0 0 1 3-4"/><path d="M6.401 6.5a3 3 0 0 1-.399-1.375"/></svg> Hand and Brain</label></div>
<div class="settings-row" style="flex-direction: column; align-items: stretch; gap: 4px; margin-top:4px;">
<label style="font-size:0.75rem; color:var(--dim)">Time Control:</label>
<select id="clockSelectOffline" style="display:none;">
<option value="0|0">Unlimited (0+0)</option>
<option value="3|0">Blitz 3+0</option>
<option value="5|0">Blitz 5+0</option>
<option value="10|0">Rapid 10+0</option>
<option value="10|5">Rapid 10+5</option>
<option value="custom">Custom...</option>
</select>
<div class="time-control-grid" id="tcGridOffline">
<button type="button" class="tc-btn active" data-val="0|0">Unlimited</button>
<button type="button" class="tc-btn" data-val="3|0">3 min</button>
<button type="button" class="tc-btn" data-val="5|0">5 min</button>
<button type="button" class="tc-btn" data-val="10|0">10 min</button>
<button type="button" class="tc-btn" data-val="10|5">10+5</button>
<button type="button" class="tc-btn" data-val="custom">Custom</button>
</div>
</div>
<div id="customClockUIOffline" style="display:none; flex-direction:column; gap:4px; margin-top:4px;">
<div class="custom-clock-row">
<span>White:</span>
<input type="number" id="wTimeOff" placeholder="Min" class="custom-clock-input" min="0">
<span style="flex:0;color:var(--dim)">+</span>
<input type="number" id="wIncOff" placeholder="Sec" class="custom-clock-input" min="0">
</div>
<div class="custom-clock-row">
<span>Black:</span>
<input type="number" id="bTimeOff" placeholder="Min" class="custom-clock-input" min="0">
<span style="flex:0;color:var(--dim)">+</span>
<input type="number" id="bIncOff" placeholder="Sec" class="custom-clock-input" min="0">
</div>
</div>
<div style="display: flex; gap: 8px; margin-top: 8px;">
<button class="btn primary" id="playBtn" onclick="window.app.startGameNormal()" style="flex: 2; font-size:.9rem; padding:10px;">▶ Play</button>
<button class="btn" id="startFromPosBtn" onclick="window.app.startGameFromCurrent()" style="flex: 3; font-size:.78rem; padding:10px; white-space: nowrap;">Start from Pos</button>
</div>
</div>
</div>
<!-- Game History Screen -->
<div class="setup-step" id="stepGameHistory" style="display:none">
<div class="card-hd">
<button class="back-btn" id="backToModeFromHistoryBtn" style="padding: 2px 8px; font-size: 0.8rem; background: transparent; border: 1px solid var(--border); border-radius: 4px; color: var(--text); cursor: pointer; float: left; margin-right: 8px;">‹ Back</button>
Game History
</div>
<div class="status-body" id="gameHistoryList" style="padding:12px; max-height:280px; overflow-y:auto; display:flex; flex-direction:column; gap:8px;">
<!-- History items will be dynamically injected here -->
</div>
</div>
<!-- Step: Waiting for Host -->
<div class="setup-step" id="stepWaitHost" style="display:none">
<div class="card-hd">Waiting for Host</div>
<div class="status-body" style="gap:10px; padding:20px; text-align:center;">
<div style="font-size: 1.5rem; color: var(--gold); margin-bottom: 8px;">⏳</div>
<div style="font-size: 0.8rem; color: var(--text);">Waiting for the host to start the game...</div>
</div>
</div>
</div>
<!-- Game Controls Card -->
<div class="card" id="gameActionsCard" style="display:none">
<div class="card-hd">Game Controls</div>
<div class="status-body" style="padding:10px;">
<div class="status-txt" id="statusTxt" style="font-size:0.9rem; margin-bottom:8px; text-align:center;">White to move</div>
<div class="btn-row" style="flex-wrap: wrap; gap: 6px;">
<button class="btn" id="resignBtn" onclick="window.app.resignGame()" style="display:none; color: #ff4444; flex: 1;">Resign</button>
<button class="btn" id="drawBtn" onclick="window.app.offerDraw()" style="display:none; color: #44aaff; flex: 1;">Draw</button>
<button class="btn" id="undoBtn" onclick="undoMove()" style="display:none; flex: 1;"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>Undo</button>
<button class="btn" id="rematchBtnStatus" onclick="window.app.rematch()" style="display:none; color: var(--gold); flex: 1;"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><path d="M17 1l4 4-4 4"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><path d="M7 23l-4-4 4-4"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>Rematch</button>
<button class="btn" id="returnToMenuBtn" onclick="window.app.goToMenu()" style="display:none; color: var(--dim); flex: 1;"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>Menu</button>
</div>
</div>
</div>
<!-- Draft Placement UI Card -->
<div class="card" id="draftUI" style="display:none"></div>
<!-- Board Editor Placement UI Card -->
<div class="card" id="editorUI" style="display:none"></div>
</div>
<div class="board-col">
<!-- Black player (top) -->
<div class="player-bar" id="barB">
<div class="p-info">
<div class="p-avatar b">B</div>
<span class="p-name" id="nameB">Black</span>
<div class="turn-dot"></div>
</div>
<div class="p-right">
<div class="p-caps" id="capB"></div>
<div class="p-score" id="scoreB"></div>
<div class="p-clock" id="clockB" style="display:none; font-family:'JetBrains Mono',monospace; font-size:0.85rem; font-weight:700; padding:2px 6px; border-radius:4px; margin-left:6px;"></div>
</div>
</div>
<div class="board-outer">
<div style="display: flex; flex-direction: column;">
<div class="board-frame">
<div id="evalBar" class="eval-bar" style="display:none;">
<div id="evalFill" class="eval-fill"></div>
<div id="evalText" class="eval-text">0.0</div>
</div>
<div class="board" id="boardEl"></div>
</div>
</div>
</div>
<!-- White player (bottom) -->
<div class="player-bar" id="barW">
<div class="p-info">
<div class="p-avatar w">W</div>
<span class="p-name" id="nameW">White</span>
<div class="turn-dot"></div>
</div>
<div class="p-right">
<div class="p-caps" id="capW"></div>
<div class="p-score" id="scoreW"></div>
<div class="p-clock" id="clockW" style="display:none; font-family:'JetBrains Mono',monospace; font-size:0.85rem; font-weight:700; padding:2px 6px; border-radius:4px; margin-left:6px;"></div>
</div>
</div>
</div>
<!-- Right Panel -->
<div class="right-panel side-panel" id="rightPanel">
<!-- Move History Card -->
<div class="card hist-card">
<div class="card-hd" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<span><svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:5px"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>Move History</span>
<select id="branchSelect" class="select-input" style="font-size: 0.75rem; padding: 2px 6px; width: auto; max-width: 140px; display: none; height: 24px; margin: 0;"></select>
</div>
<div class="hist-body" id="histBody"></div>
<div class="hist-footer">
<button class="hist-nav-btn" id="histPrevBtn" title="Previous move" aria-label="Previous move">
<svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m15 18-6-6 6-6"/></svg>
</button>
<button class="hist-clear-btn" id="histClearBtn" title="Clear board and start a new game" aria-label="Clear board">
<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>
<span>Clear Board</span>
</button>
<button class="hist-nav-btn" id="histNextBtn" title="Next move" aria-label="Next move">
<svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
</button>
</div>
</div>
<!-- Settings Card -->
<div class="card">
<div class="card-hd"><svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:5px"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>Settings</div>
<div class="status-body" style="padding:10px;">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: 0.72rem;">
<label class="toggle-label" style="font-size: 0.72rem; display: flex; align-items: center; gap: 4px; white-space: nowrap;"><input type="checkbox" id="soundToggleBtn" checked> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/><path d="M19.07 4.93a10 10 0 0 1 0 14.14"/><path d="M15.54 8.46a5 5 0 0 1 0 7.07"/></svg> Sound</label>
<label class="toggle-label" style="font-size: 0.72rem; display: flex; align-items: center; gap: 4px; white-space: nowrap;"><input type="checkbox" id="showBestMoveToggle" checked> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg> Best Move</label>
<label class="toggle-label" style="font-size: 0.72rem; display: flex; align-items: center; gap: 4px; white-space: nowrap;"><input type="checkbox" id="showEvalBarToggle" checked> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="4" height="18" rx="1"/><rect x="10" y="8" width="4" height="13" rx="1"/><rect x="17" y="12" width="4" height="9" rx="1"/></svg> Eval Bar</label>
<label class="toggle-label" style="font-size: 0.72rem; display: flex; align-items: center; gap: 4px; white-space: nowrap;"><input type="checkbox" id="showHintsToggle" checked> <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="3" fill="currentColor" stroke="none"/></svg> Hints</label>
</div>
<div style="margin-top:8px;">
<div style="font-size: 0.68rem; color: var(--dim); margin-bottom:6px;">Local Perspective</div>
<div class="segmented-control" id="passPlaySeg">
<button class="segmented-btn active" data-val="static">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18M3 15h18M9 3v18"/></svg>Static
</button>
<button class="segmented-btn" data-val="rotate">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg>Rotate
</button>
<button class="segmented-btn" data-val="bothSides">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px; margin-right:4px;"><path d="M12 2v9"/><path d="m9 8 3 3 3-3"/><path d="M12 22v-9"/><path d="m9 16 3-3 3 3"/></svg>Opposite
</button>
</div>
</div>
<div class="settings-row" style="margin-top:8px; display:flex; gap:8px;">
<button class="btn" id="modeToggleBtn" style="flex:1; display:flex; align-items:center; justify-content:center; gap:6px; font-size:0.72rem;">
<svg id="modeToggleIcon" viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
<span id="modeToggleLabel">Dark</span>
</button>
<button class="btn" id="colorToggleBtn" style="flex:1; display:flex; align-items:center; justify-content:center; gap:6px; font-size:0.72rem;">
<svg id="colorToggleIcon" viewBox="0 0 24 24" width="13" height="13" fill="currentColor" stroke="none"><circle cx="12" cy="12" r="9"/></svg>
<span id="colorToggleLabel">Blue</span>
</button>
</div>
</div>
</div>
<!-- Import / Export Card -->
<div class="card" id="importExportCard">
<div class="card-hd"><svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:5px"><polyline points="8 17 12 21 16 17"/><line x1="12" y1="12" x2="12" y2="21"/><path d="M20.88 18.09A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.29"/></svg>Import / Export</div>
<div class="status-body" style="padding:10px">
<div class="btn-row" style="flex-wrap: wrap; gap: 4px;">
<button class="btn primary" id="importBtn" onclick="document.getElementById('importOv').classList.add('show')" title="Import FEN/PGN" style="display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 10px; font-size: 0.72rem;"><svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg> Import</button>
<button class="btn" id="copyFenBtn" onclick="triggerExportFen()" title="Copy FEN" style="display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 10px; font-size: 0.72rem;"><svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg> FEN</button>
<button class="btn" onclick="triggerExportPgn()" title="Copy PGN" style="display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 10px; font-size: 0.72rem;"><svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg> PGN</button>
<button class="btn" id="editBoardBtn" onclick="window.app.toggleBoardEditor()" title="Edit Board" style="display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 10px; font-size: 0.72rem;"><svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 1 1 3 3L12 15l-4 1 1-4z"></path></svg> <span id="editBtnText">Edit</span></button>
</div>
</div>
</div>
</div>
<!-- About Developer (footer) - own row on desktop, pushed to the very end
of the page on mobile via the .dev-footer order rule -->
<div class="dev-footer">
<span>Usama Gulzar</span>
<span style="opacity:0.4">·</span>
<a href="https://github.com/usamagulzar" target="_blank" rel="noopener" onmouseover="this.style.color='var(--gold)'" onmouseout="this.style.color='var(--muted)'">GitHub</a>
<span style="opacity:0.4">·</span>
<a href="mailto:ugulzar.pk@gmail.com" onmouseover="this.style.color='var(--gold)'" onmouseout="this.style.color='var(--muted)'">Email</a>
</div>
</div>
<!-- Import Overlay -->
<div class="overlay" id="importOv">
<div class="promo-dlg" style="max-width: 400px; width: 100%;">
<h3>Import FEN / PGN</h3>
<textarea id="fenPgnInput" placeholder="Paste FEN or PGN here..." style="width:100%; height:120px; background:var(--panel2); border:1px solid var(--border); border-radius:6px; padding:8px; color:var(--text); font-family:'JetBrains Mono',monospace; font-size:0.75rem; resize:vertical; margin-bottom:12px; outline:none"></textarea>
<div class="btn-row">
<button class="btn" onclick="document.getElementById('importOv').classList.remove('show'); document.getElementById('fenPgnInput').value=''">Cancel</button>
<button class="btn primary" onclick="triggerImport()">Import Game</button>
</div>
</div>
</div>
<!-- Promotion Overlay -->
<div class="overlay" id="promoOv">
<div class="promo-dlg">
<h3>Promote Pawn</h3>
<div class="promo-row" id="promoRow"></div>
</div>
</div>
<!-- Challenge Setup Overlay (Time Control + Color, shown after pressing Send Challenge) -->
<div class="overlay" id="challengeSetupOv">
<div class="promo-dlg" style="max-width: 360px; width: 100%; text-align:left;">
<h3 style="margin-bottom:12px;">Challenge Settings</h3>
<div class="settings-row" style="flex-direction: column; align-items: stretch; gap: 4px;">
<label style="font-size:0.75rem; color:var(--dim)">Time Control:</label>
<select id="clockSelectLobby" style="display:none;">
<option value="0|0">Unlimited (0+0)</option>
<option value="3|0">Blitz 3+0</option>
<option value="5|0">Blitz 5+0</option>
<option value="10|0">Rapid 10+0</option>
<option value="10|5">Rapid 10+5</option>
<option value="custom">Custom...</option>
</select>
<div class="time-control-grid" id="tcGridLobby">
<button type="button" class="tc-btn active" data-val="0|0">Unlimited</button>
<button type="button" class="tc-btn" data-val="3|0">3 min</button>
<button type="button" class="tc-btn" data-val="5|0">5 min</button>
<button type="button" class="tc-btn" data-val="10|0">10 min</button>
<button type="button" class="tc-btn" data-val="10|5">10+5</button>
<button type="button" class="tc-btn" data-val="custom">Custom</button>
</div>
</div>
<div id="customClockUILobby" style="display:none; flex-direction:column; gap:4px; margin-top:4px;">
<div class="custom-clock-row">
<span>White:</span>
<input type="number" id="wTimeLobby" placeholder="Min" class="custom-clock-input" min="0">
<span style="flex:0;color:var(--dim)">+</span>
<input type="number" id="wIncLobby" placeholder="Sec" class="custom-clock-input" min="0">
</div>
<div class="custom-clock-row">
<span>Black:</span>
<input type="number" id="bTimeLobby" placeholder="Min" class="custom-clock-input" min="0">
<span style="flex:0;color:var(--dim)">+</span>
<input type="number" id="bIncLobby" placeholder="Sec" class="custom-clock-input" min="0">
</div>
</div>
<div style="font-size: 0.72rem; color: var(--dim); margin-top:14px; margin-bottom: 2px;">Your Color:</div>
<div class="segmented-control" id="lobbyColorSeg">
<button class="segmented-btn active" data-color="random">Random</button>
<button class="segmented-btn" data-color="w">White</button>
<button class="segmented-btn" data-color="b">Black</button>
</div>
<div class="btn-row" style="margin-top:18px;">
<button class="btn" id="cancelChallengeSetupBtn" style="flex:1; background:var(--panel); color:var(--fg); border:1px solid var(--border);">Cancel</button>
<button class="btn primary" id="confirmChallengeSetupBtn" style="flex:1;">Confirm</button>
</div>
</div>
</div>
<!-- Identity Theft Power Select Overlay -->
<div class="overlay" id="powerSelectOverlay">
<div class="promo-dlg" style="max-width: 300px;">
<h3 style="margin-bottom:8px;">Identity Theft Limit</h3>
<p style="font-size:0.8rem; color:var(--dim); margin-bottom:16px;">Select exactly 2 powers to keep.</p>
<div class="promo-row" id="powerSelectContainer" style="flex-wrap: wrap; justify-content: center; margin-bottom: 16px;">
</div>
<button class="btn primary" id="confirmPowerSelectBtn" style="width:100%;" disabled>Confirm Selection</button>
</div>
</div>
<!-- Challenge Popup (Bottom Right) -->
<div class="challenge-popup" id="challengePopup" style="display:none;">
<div class="card-hd">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:6px"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
Game Challenge
</div>
<div class="challenge-body">
<div class="challenge-sender-row">
<div class="challenge-avatar" id="challengeSenderAvatar"></div>
<div>
<div class="challenge-sender-name" id="challengeSenderName"></div>
<div class="challenge-sender-sub">wants to play a game</div>
</div>
</div>
<div class="challenge-details" id="challengeDetailsList"></div>
<div class="btn-row">
<button class="btn primary" id="acceptChallengeBtn" style="flex:1;">Accept</button>
<button class="btn" id="declineChallengeBtn" style="flex:1; background:var(--panel); color:var(--fg); border:1px solid var(--border);">Decline</button>
</div>
</div>
</div>
<!-- Proposal Popup (Bottom Right) -->
<div class="challenge-popup" id="proposalPopup" style="display:none;">
<div class="card-hd" id="proposalTitle">Request</div>
<div class="status-body" style="padding:14px; gap:8px;">
<div id="proposalText" style="font-size:0.8rem; color:var(--text); margin-bottom:4px;">Opponent requested an undo.</div>
<div class="btn-row">
<button class="btn primary" id="acceptProposalBtn" style="flex:1;">Accept</button>
<button class="btn" id="declineProposalBtn" style="flex:1; background:var(--panel); color:var(--fg); border:1px solid var(--border);">Decline</button>
</div>
</div>
</div>
<!-- Game End Banner Overlay -->
<div class="result-banner" id="resultBanner">
<div class="result-box">
<div class="result-title" id="resultTitle"></div>
<div class="result-sub" id="resultSub"></div>
<button class="btn primary" id="rematchBtn" style="margin-top:8px; width:100%;" onclick="window.app.rematch()">Rematch</button>
<button class="btn" style="margin-top:6px; width:100%;" onclick="window.app.goToMenu()">Menu</button>
<button class="btn" id="reviewBtn" style="margin-top:6px; width:100%;" onclick="window.app.hideResultBanner()">Review</button>
</div>
</div>
<!-- Claim Username Modal -->
<div id="claimModal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.6); z-index:9999; flex-direction:column; align-items:center; justify-content:center;">
<div class="card" style="width:90%; max-width:320px; padding:20px; text-align:center;">
<h3 style="margin-top:0; color:var(--gold);">Claim Username</h3>
<p style="font-size:0.8rem; color:var(--dim); margin-bottom:16px;">Pick a unique username for your account.</p>
<input type="text" id="claimUsernameInput" class="join-code-input" placeholder="e.g. chessmaster99" style="text-transform:none; letter-spacing:1px; font-size:1rem; margin-bottom:8px;">
<div id="claimError" style="color:var(--check-light); font-size:0.75rem; min-height:16px; margin-bottom:8px;"></div>
<button class="btn primary" id="claimSubmitBtn" style="width:100%;">Claim</button>
</div>
</div>
<!-- External scripts & dependencies -->
<script src="js/svg.js"></script>
<script src="js/audio.js"></script>
<script src="js/ui.js"></script>
<script src="js/timer.js"></script>
<script src="js/analysis.js"></script>
<script src="js/engine.js"></script>
<script src="js/variants.js"></script>
<script src="js/history.js"></script>
<script src="js/multiplayer.js"></script>
<script src="js/auth.js"></script>
<script src="js/app.js"></script>
<script>
(function () {
const MODE_ICONS = {
dark: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
light: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>'
};
const COLOR_HEX = { blue: '#3a7ce0', pink: '#e0397c' };
function themeString(mode, color) {
return (mode === 'dark' && color === 'blue') ? 'dark-blue' : `${mode}-${color}`;
}
function applyTheme(mode, color) {
const theme = themeString(mode, color);
if (theme === 'dark-blue') {
document.documentElement.removeAttribute('data-theme');
} else {
document.documentElement.setAttribute('data-theme', theme);
}
const modeLabel = document.getElementById('modeToggleLabel');
const modeIcon = document.getElementById('modeToggleIcon');
const colorLabel = document.getElementById('colorToggleLabel');
const colorIcon = document.getElementById('colorToggleIcon');
if (modeLabel) modeLabel.textContent = mode === 'dark' ? 'Dark' : 'Light';
if (modeIcon) modeIcon.innerHTML = MODE_ICONS[mode];
if (colorLabel) colorLabel.textContent = color === 'blue' ? 'Blue' : 'Pink';
if (colorIcon) colorIcon.style.color = COLOR_HEX[color];
try {
localStorage.setItem('chexThemeMode', mode);
localStorage.setItem('chexThemeColor', color);
} catch (e) {}
if (window.app && typeof window.app.renderBoard === 'function') window.app.renderBoard();
if (window.analysis && typeof window.analysis.drawArrow === 'function') window.analysis.drawArrow();
}
document.addEventListener('DOMContentLoaded', () => {
let mode = 'dark', color = 'blue';
try {
mode = localStorage.getItem('chexThemeMode') || 'dark';
color = localStorage.getItem('chexThemeColor') || 'blue';
} catch (e) {}
applyTheme(mode, color);
const modeBtn = document.getElementById('modeToggleBtn');
if (modeBtn) modeBtn.addEventListener('click', () => { mode = mode === 'dark' ? 'light' : 'dark'; applyTheme(mode, color); });
const colorBtn = document.getElementById('colorToggleBtn');
if (colorBtn) colorBtn.addEventListener('click', () => { color = color === 'blue' ? 'pink' : 'blue'; applyTheme(mode, color); });
});
})();
</script>
<script>
document.addEventListener('DOMContentLoaded', () => {
if (window.auth) window.auth.init();
window.app.init();
window.ui.init();
});
function refreshBoardSvgs() {
// Nudge WebKit to recompute SVG scaling instead of holding a stale, distorted frame
document.querySelectorAll('.chex-logo, #arrowOverlay').forEach(el => {
el.style.display = 'none';
void el.offsetHeight; // force layout
el.style.display = '';
});
}
if (window.visualViewport) {
window.visualViewport.addEventListener('resize', refreshBoardSvgs);
} else {
window.addEventListener('resize', refreshBoardSvgs);
}
// --- PWA: service worker registration ---
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js').catch((err) => {
console.warn('Service worker registration failed:', err);
});
});
}
// --- PWA: capture the install prompt so we can trigger it from our own UI
// instead of relying on the browser's native (and easy-to-miss) mini-infobar.
let deferredInstallPrompt = null;
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredInstallPrompt = e;
const installBtn = document.getElementById('installAppBtn');
if (installBtn) installBtn.style.display = 'inline-flex';
});
window.addEventListener('appinstalled', () => {
deferredInstallPrompt = null;
const installBtn = document.getElementById('installAppBtn');
if (installBtn) installBtn.style.display = 'none';
});
window.triggerInstallPrompt = async function () {
if (!deferredInstallPrompt) return;
deferredInstallPrompt.prompt();
await deferredInstallPrompt.userChoice;
deferredInstallPrompt = null;
const installBtn = document.getElementById('installAppBtn');
if (installBtn) installBtn.style.display = 'none';
};
</script>
</body>
</html>