Lashtw commited on
Commit
c968a41
·
1 Parent(s): 2be7c1d

feat(ui): implement western grand bazaar interactive modal, 4 NPC battles, and shared black-market panel

Browse files
Files changed (5) hide show
  1. css/bazaar.css +1494 -0
  2. index.html +1 -0
  3. js/bazaar-ui.js +1664 -0
  4. js/merchant-ui.js +203 -129
  5. tools/verify-integrity.mjs +49 -0
css/bazaar.css ADDED
@@ -0,0 +1,1494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ============================================================================
2
+ * css/bazaar.css
3
+ * 《攻城掠地・霸業征途》西域萬國大市集(Western Grand Bazaar)互動舞台樣式
4
+ * - 深曜藍黑金底 × 絲路琥珀金/孔雀綠/緋紅燈籠慶典視覺
5
+ * - 行動端鐵律:max-height: 88vh / 84vh、原生捲動流暢、所有觸控區 >= 44px
6
+ * ============================================================================ */
7
+
8
+ @keyframes bzFloatSlow {
9
+ 0%, 100% { transform: translateY(0px); }
10
+ 50% { transform: translateY(-5px); }
11
+ }
12
+
13
+ @keyframes bzPulseGlow {
14
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45), 0 4px 14px rgba(245, 158, 11, 0.25); }
15
+ 50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0), 0 6px 20px rgba(245, 158, 11, 0.45); }
16
+ }
17
+
18
+ @keyframes bzNearPulse {
19
+ 0%, 100% { transform: scale(1); opacity: 1; }
20
+ 50% { transform: scale(1.06); opacity: 0.85; }
21
+ }
22
+
23
+ @keyframes bzWalkAcross {
24
+ 0% {
25
+ left: 6%;
26
+ transform: translateY(0px) scale(0.92);
27
+ opacity: 0;
28
+ }
29
+ 12% {
30
+ opacity: 1;
31
+ }
32
+ 32% {
33
+ transform: translateY(-7px) scale(0.98);
34
+ }
35
+ 55% {
36
+ transform: translateY(0px) scale(1);
37
+ }
38
+ 78% {
39
+ transform: translateY(-6px) scale(1.03);
40
+ }
41
+ 100% {
42
+ left: 52%;
43
+ transform: translateY(0px) scale(1.06);
44
+ opacity: 1;
45
+ }
46
+ }
47
+
48
+ @keyframes bzExclaimPop {
49
+ 0% {
50
+ transform: translate(-50%, 16px) scale(0.2) rotate(-14deg);
51
+ opacity: 0;
52
+ }
53
+ 55% {
54
+ transform: translate(-50%, -10px) scale(1.26) rotate(8deg);
55
+ opacity: 1;
56
+ }
57
+ 78% {
58
+ transform: translate(-50%, -2px) scale(0.95) rotate(-4deg);
59
+ }
60
+ 100% {
61
+ transform: translate(-50%, -6px) scale(1.05) rotate(0deg);
62
+ opacity: 1;
63
+ }
64
+ }
65
+
66
+ @keyframes bzFlashIn {
67
+ 0% { opacity: 0; }
68
+ 30% { opacity: 0.92; }
69
+ 100% { opacity: 0; }
70
+ }
71
+
72
+ @keyframes bzShake {
73
+ 0%, 100% { transform: translateX(0); }
74
+ 20% { transform: translateX(-7px); }
75
+ 40% { transform: translateX(7px); }
76
+ 60% { transform: translateX(-5px); }
77
+ 80% { transform: translateX(5px); }
78
+ }
79
+
80
+ @keyframes bzLineShimmer {
81
+ 0%, 100% { box-shadow: inset 0 0 0 1.5px rgba(251, 191, 36, 0.8), 0 0 12px rgba(245, 158, 11, 0.35); }
82
+ 50% { box-shadow: inset 0 0 0 2px rgba(254, 240, 138, 0.95), 0 0 18px rgba(251, 191, 36, 0.62); }
83
+ }
84
+
85
+ @keyframes bzShatterBurst {
86
+ 0% { transform: scale(0.75); opacity: 0; }
87
+ 45% { transform: scale(1.08); opacity: 1; }
88
+ 100% { transform: scale(1); opacity: 1; }
89
+ }
90
+
91
+ @keyframes bzLanternParticle {
92
+ 0%, 100% { transform: translateY(0px) scale(1); opacity: 0.45; }
93
+ 50% { transform: translateY(-16px) scale(1.25); opacity: 0.9; }
94
+ }
95
+
96
+ /* ----------------------------------------------------------------------------
97
+ * 1. Modal Shell(深曜藍黑金底、捲動保護、置頂關閉鈕)
98
+ * ---------------------------------------------------------------------------- */
99
+ .modal.bazaar-modal {
100
+ max-width: 960px;
101
+ width: 96vw;
102
+ max-height: 88vh;
103
+ padding: 0;
104
+ overflow: hidden;
105
+ display: flex;
106
+ flex-direction: column;
107
+ background:
108
+ radial-gradient(circle at 14% 8%, rgba(245, 158, 11, 0.14), transparent 44%),
109
+ radial-gradient(circle at 86% 6%, rgba(20, 184, 166, 0.12), transparent 46%),
110
+ radial-gradient(circle at 50% 95%, rgba(239, 68, 68, 0.1), transparent 50%),
111
+ linear-gradient(165deg, #0f111a 0%, #15192b 54%, #0b0d15 100%);
112
+ border: 1.5px solid rgba(245, 158, 11, 0.5);
113
+ border-radius: 22px;
114
+ box-shadow: 0 28px 80px rgba(0, 0, 0, 0.78), 0 0 28px rgba(245, 158, 11, 0.16);
115
+ color: #f8fafc;
116
+ }
117
+
118
+ @media (max-height: 700px) {
119
+ .modal.bazaar-modal {
120
+ max-height: 84vh;
121
+ }
122
+ }
123
+
124
+ .modal.bazaar-modal .modal-body {
125
+ flex: 1 1 auto;
126
+ min-height: 0;
127
+ overflow-y: auto;
128
+ -webkit-overflow-scrolling: touch;
129
+ touch-action: pan-y;
130
+ padding: 0;
131
+ }
132
+
133
+ .modal.bazaar-modal .modal-body::-webkit-scrollbar {
134
+ width: 6px;
135
+ }
136
+
137
+ .modal.bazaar-modal .modal-body::-webkit-scrollbar-thumb {
138
+ background: rgba(245, 158, 11, 0.35);
139
+ border-radius: 99px;
140
+ }
141
+
142
+ .modal.bazaar-modal .modal-close,
143
+ .modal.bazaar-modal .modal-x {
144
+ position: sticky;
145
+ top: 0;
146
+ z-index: 120;
147
+ min-width: 44px;
148
+ min-height: 44px;
149
+ width: 44px;
150
+ height: 44px;
151
+ border-radius: 12px;
152
+ border: 1px solid rgba(245, 158, 11, 0.55);
153
+ background: rgba(15, 17, 26, 0.92);
154
+ color: #fde68a;
155
+ font-size: 18px;
156
+ font-weight: 800;
157
+ cursor: pointer;
158
+ display: inline-flex;
159
+ align-items: center;
160
+ justify-content: center;
161
+ touch-action: manipulation;
162
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
163
+ transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
164
+ }
165
+
166
+ .modal.bazaar-modal > .modal-x {
167
+ position: absolute;
168
+ top: 10px;
169
+ right: 12px;
170
+ z-index: 125;
171
+ }
172
+
173
+ .modal.bazaar-modal .modal-close:hover,
174
+ .modal.bazaar-modal .modal-x:hover {
175
+ background: rgba(245, 158, 11, 0.25);
176
+ border-color: #fbbf24;
177
+ color: #ffffff;
178
+ transform: scale(1.06);
179
+ }
180
+
181
+ /* ----------------------------------------------------------------------------
182
+ * 2. 置頂粘性導覽列與分頁切換
183
+ * ---------------------------------------------------------------------------- */
184
+ .bz-shell {
185
+ display: flex;
186
+ flex-direction: column;
187
+ min-height: 100%;
188
+ }
189
+
190
+ .bz-sticky-header {
191
+ position: sticky;
192
+ top: 0;
193
+ z-index: 110;
194
+ padding: 14px 62px 12px 18px;
195
+ background: linear-gradient(180deg, rgba(15, 17, 26, 0.97) 0%, rgba(19, 23, 38, 0.94) 100%);
196
+ backdrop-filter: blur(10px);
197
+ border-bottom: 1px solid rgba(245, 158, 11, 0.28);
198
+ }
199
+
200
+ .bz-head-top {
201
+ display: flex;
202
+ align-items: center;
203
+ justify-content: space-between;
204
+ gap: 12px;
205
+ flex-wrap: wrap;
206
+ }
207
+
208
+ .bz-title-wrap {
209
+ display: flex;
210
+ align-items: center;
211
+ gap: 10px;
212
+ min-width: 0;
213
+ }
214
+
215
+ .bz-title-emblem {
216
+ width: 42px;
217
+ height: 42px;
218
+ border-radius: 12px;
219
+ background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(20, 184, 166, 0.2));
220
+ border: 1px solid rgba(245, 158, 11, 0.55);
221
+ display: flex;
222
+ align-items: center;
223
+ justify-content: center;
224
+ font-size: 22px;
225
+ flex-shrink: 0;
226
+ }
227
+
228
+ .bz-title {
229
+ margin: 0;
230
+ font-size: 19px;
231
+ font-weight: 900;
232
+ color: #fef3c7;
233
+ letter-spacing: 0.4px;
234
+ }
235
+
236
+ .bz-subtitle {
237
+ font-size: 12.5px;
238
+ color: #94a3b8;
239
+ font-weight: 600;
240
+ margin-top: 2px;
241
+ }
242
+
243
+ .bz-status-pills {
244
+ display: flex;
245
+ align-items: center;
246
+ gap: 8px;
247
+ flex-wrap: wrap;
248
+ }
249
+
250
+ .bz-pill {
251
+ display: inline-flex;
252
+ align-items: center;
253
+ gap: 5px;
254
+ padding: 5px 11px;
255
+ border-radius: 99px;
256
+ font-size: 12.5px;
257
+ font-weight: 800;
258
+ border: 1px solid rgba(255, 255, 255, 0.14);
259
+ background: rgba(30, 41, 59, 0.85);
260
+ color: #f1f5f9;
261
+ }
262
+
263
+ .bz-pill-gold {
264
+ background: rgba(245, 158, 11, 0.18);
265
+ border-color: rgba(245, 158, 11, 0.5);
266
+ color: #fde68a;
267
+ }
268
+
269
+ .bz-pill-teal {
270
+ background: rgba(20, 184, 166, 0.16);
271
+ border-color: rgba(20, 184, 166, 0.48);
272
+ color: #5eead4;
273
+ }
274
+
275
+ .bz-pill-crimson {
276
+ background: rgba(239, 68, 68, 0.18);
277
+ border-color: rgba(239, 68, 68, 0.48);
278
+ color: #fca5a5;
279
+ }
280
+
281
+ .bz-tabs {
282
+ display: grid;
283
+ grid-template-columns: repeat(3, minmax(0, 1fr));
284
+ gap: 8px;
285
+ margin-top: 12px;
286
+ }
287
+
288
+ .bz-tab-btn {
289
+ min-height: 44px;
290
+ padding: 8px 10px;
291
+ border-radius: 12px;
292
+ border: 1px solid rgba(148, 163, 184, 0.22);
293
+ background: rgba(30, 41, 59, 0.55);
294
+ color: #cbd5e1;
295
+ font-size: 13.5px;
296
+ font-weight: 800;
297
+ cursor: pointer;
298
+ display: inline-flex;
299
+ align-items: center;
300
+ justify-content: center;
301
+ gap: 6px;
302
+ touch-action: manipulation;
303
+ transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
304
+ }
305
+
306
+ .bz-tab-btn:hover {
307
+ transform: translateY(-1px);
308
+ border-color: rgba(245, 158, 11, 0.55);
309
+ color: #fef3c7;
310
+ }
311
+
312
+ .bz-tab-btn.is-active {
313
+ background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(217, 119, 6, 0.22));
314
+ border-color: #f59e0b;
315
+ color: #fef08a;
316
+ box-shadow: 0 4px 14px rgba(245, 158, 11, 0.22);
317
+ }
318
+
319
+ .bz-content {
320
+ padding: 16px 18px 24px;
321
+ display: flex;
322
+ flex-direction: column;
323
+ gap: 16px;
324
+ }
325
+
326
+ /* ----------------------------------------------------------------------------
327
+ * 3. 開市前倒數封印面板
328
+ * ---------------------------------------------------------------------------- */
329
+ .bz-countdown-card {
330
+ position: relative;
331
+ border-radius: 18px;
332
+ overflow: hidden;
333
+ border: 1.5px solid rgba(245, 158, 11, 0.45);
334
+ background: linear-gradient(160deg, rgba(17, 24, 39, 0.95), rgba(15, 17, 26, 0.98));
335
+ padding: 20px;
336
+ display: flex;
337
+ flex-direction: column;
338
+ gap: 16px;
339
+ }
340
+
341
+ .bz-countdown-hero {
342
+ position: relative;
343
+ border-radius: 14px;
344
+ overflow: hidden;
345
+ height: clamp(170px, 28vh, 240px);
346
+ border: 1px solid rgba(245, 158, 11, 0.35);
347
+ }
348
+
349
+ .bz-countdown-hero img {
350
+ width: 100%;
351
+ height: 100%;
352
+ object-fit: cover;
353
+ filter: brightness(0.68) saturate(1.1);
354
+ }
355
+
356
+ .bz-countdown-seal {
357
+ position: absolute;
358
+ inset: 0;
359
+ display: flex;
360
+ flex-direction: column;
361
+ align-items: center;
362
+ justify-content: center;
363
+ text-align: center;
364
+ padding: 16px;
365
+ background: radial-gradient(circle, rgba(15, 17, 26, 0.58) 0%, rgba(15, 17, 26, 0.85) 100%);
366
+ }
367
+
368
+ .bz-countdown-clock {
369
+ font-size: clamp(24px, 4.5vw, 34px);
370
+ font-weight: 900;
371
+ color: #fbbf24;
372
+ letter-spacing: 1px;
373
+ text-shadow: 0 0 16px rgba(245, 158, 11, 0.55);
374
+ margin: 6px 0;
375
+ }
376
+
377
+ .bz-rule-grid {
378
+ display: grid;
379
+ grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
380
+ gap: 10px;
381
+ }
382
+
383
+ .bz-rule-tile {
384
+ padding: 12px 14px;
385
+ border-radius: 12px;
386
+ background: rgba(30, 41, 59, 0.58);
387
+ border: 1px solid rgba(245, 158, 11, 0.22);
388
+ font-size: 13px;
389
+ line-height: 1.55;
390
+ color: #e2e8f0;
391
+ }
392
+
393
+ .bz-rule-tile b {
394
+ color: #fde68a;
395
+ display: block;
396
+ margin-bottom: 4px;
397
+ }
398
+
399
+ /* ----------------------------------------------------------------------------
400
+ * 4. 市集奇遇控制卡、今日水位條、個人連線里程碑
401
+ * ---------------------------------------------------------------------------- */
402
+ .bz-hero-panel {
403
+ display: grid;
404
+ grid-template-columns: 1.35fr 1fr;
405
+ gap: 14px;
406
+ align-items: stretch;
407
+ }
408
+
409
+ .bz-card {
410
+ background: linear-gradient(155deg, rgba(24, 30, 49, 0.92), rgba(16, 20, 34, 0.96));
411
+ border: 1px solid rgba(245, 158, 11, 0.28);
412
+ border-radius: 16px;
413
+ padding: 14px 16px;
414
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
415
+ }
416
+
417
+ .bz-quota-head {
418
+ display: flex;
419
+ align-items: center;
420
+ justify-content: space-between;
421
+ gap: 8px;
422
+ flex-wrap: wrap;
423
+ margin-bottom: 8px;
424
+ }
425
+
426
+ .bz-quota-title {
427
+ font-size: 14px;
428
+ font-weight: 800;
429
+ color: #fde68a;
430
+ }
431
+
432
+ .bz-quota-val {
433
+ font-size: 13px;
434
+ font-weight: 800;
435
+ color: #5eead4;
436
+ }
437
+
438
+ .bz-quota-track {
439
+ position: relative;
440
+ height: 14px;
441
+ border-radius: 99px;
442
+ background: rgba(15, 23, 42, 0.9);
443
+ border: 1px solid rgba(148, 163, 184, 0.22);
444
+ overflow: hidden;
445
+ }
446
+
447
+ .bz-quota-cap {
448
+ position: absolute;
449
+ top: 0;
450
+ left: 0;
451
+ bottom: 0;
452
+ background: rgba(245, 158, 11, 0.24);
453
+ border-right: 2px dashed rgba(251, 191, 36, 0.85);
454
+ }
455
+
456
+ .bz-quota-fill {
457
+ position: relative;
458
+ z-index: 2;
459
+ height: 100%;
460
+ border-radius: 99px;
461
+ background: linear-gradient(90deg, #14b8a6, #fbbf24);
462
+ transition: width 0.35s ease;
463
+ }
464
+
465
+ .bz-quota-meta {
466
+ display: flex;
467
+ justify-content: space-between;
468
+ align-items: center;
469
+ gap: 8px;
470
+ flex-wrap: wrap;
471
+ margin-top: 8px;
472
+ font-size: 12px;
473
+ color: #94a3b8;
474
+ }
475
+
476
+ .bz-chain-chip {
477
+ display: inline-flex;
478
+ align-items: center;
479
+ gap: 6px;
480
+ padding: 4px 10px;
481
+ border-radius: 99px;
482
+ font-size: 12px;
483
+ font-weight: 800;
484
+ background: rgba(239, 68, 68, 0.16);
485
+ border: 1px solid rgba(239, 68, 68, 0.45);
486
+ color: #fca5a5;
487
+ }
488
+
489
+ .bz-chain-chip.is-clear {
490
+ background: rgba(20, 184, 166, 0.16);
491
+ border-color: rgba(20, 184, 166, 0.45);
492
+ color: #5eead4;
493
+ }
494
+
495
+ .bz-cta-card {
496
+ display: flex;
497
+ flex-direction: column;
498
+ justify-content: space-between;
499
+ gap: 10px;
500
+ }
501
+
502
+ .bz-btn-primary {
503
+ width: 100%;
504
+ min-height: 50px;
505
+ padding: 12px 16px;
506
+ border-radius: 14px;
507
+ border: 1px solid rgba(254, 240, 138, 0.65);
508
+ background: linear-gradient(135deg, #f59e0b 0%, #d97706 60%, #b45309 100%);
509
+ color: #ffffff;
510
+ font-size: 15.5px;
511
+ font-weight: 900;
512
+ cursor: pointer;
513
+ display: inline-flex;
514
+ align-items: center;
515
+ justify-content: center;
516
+ gap: 8px;
517
+ touch-action: manipulation;
518
+ animation: bzPulseGlow 2.4s ease-in-out infinite;
519
+ transition: transform 0.15s ease, filter 0.15s ease;
520
+ }
521
+
522
+ .bz-btn-primary:hover:not(:disabled) {
523
+ transform: translateY(-2px) scale(1.01);
524
+ filter: brightness(1.06);
525
+ }
526
+
527
+ .bz-btn-primary:disabled {
528
+ opacity: 0.5;
529
+ cursor: not-allowed;
530
+ animation: none;
531
+ }
532
+
533
+ .bz-btn-secondary {
534
+ min-height: 44px;
535
+ padding: 9px 14px;
536
+ border-radius: 12px;
537
+ border: 1px solid rgba(20, 184, 166, 0.5);
538
+ background: rgba(20, 184, 166, 0.16);
539
+ color: #5eead4;
540
+ font-size: 13.5px;
541
+ font-weight: 800;
542
+ cursor: pointer;
543
+ display: inline-flex;
544
+ align-items: center;
545
+ justify-content: center;
546
+ gap: 6px;
547
+ touch-action: manipulation;
548
+ transition: transform 0.14s ease, background 0.14s ease;
549
+ }
550
+
551
+ .bz-btn-secondary:hover:not(:disabled) {
552
+ transform: translateY(-1px);
553
+ background: rgba(20, 184, 166, 0.28);
554
+ }
555
+
556
+ .bz-btn-ghost {
557
+ min-height: 44px;
558
+ padding: 8px 14px;
559
+ border-radius: 11px;
560
+ border: 1px solid rgba(148, 163, 184, 0.35);
561
+ background: rgba(30, 41, 59, 0.72);
562
+ color: #e2e8f0;
563
+ font-size: 13px;
564
+ font-weight: 700;
565
+ cursor: pointer;
566
+ display: inline-flex;
567
+ align-items: center;
568
+ justify-content: center;
569
+ gap: 6px;
570
+ touch-action: manipulation;
571
+ transition: background 0.14s ease, border-color 0.14s ease;
572
+ }
573
+
574
+ .bz-btn-ghost:hover:not(:disabled) {
575
+ background: rgba(51, 65, 85, 0.85);
576
+ border-color: rgba(245, 158, 11, 0.55);
577
+ }
578
+
579
+ /* 個人連線進度條 5 / 15 / 30 / 60 / 90 / 120 */
580
+ .bz-milestones-strip {
581
+ display: grid;
582
+ grid-template-columns: repeat(6, minmax(0, 1fr));
583
+ gap: 8px;
584
+ }
585
+
586
+ .bz-pm-card {
587
+ padding: 9px 10px;
588
+ border-radius: 12px;
589
+ background: rgba(24, 30, 49, 0.85);
590
+ border: 1px solid rgba(148, 163, 184, 0.22);
591
+ display: flex;
592
+ flex-direction: column;
593
+ gap: 3px;
594
+ font-size: 11.5px;
595
+ }
596
+
597
+ .bz-pm-card.is-claimed {
598
+ background: linear-gradient(155deg, rgba(20, 184, 166, 0.18), rgba(245, 158, 11, 0.16));
599
+ border-color: rgba(20, 184, 166, 0.62);
600
+ }
601
+
602
+ .bz-pm-lines {
603
+ font-size: 13px;
604
+ font-weight: 900;
605
+ color: #fde68a;
606
+ display: flex;
607
+ align-items: center;
608
+ justify-content: space-between;
609
+ gap: 4px;
610
+ }
611
+
612
+ .bz-pm-name {
613
+ font-weight: 800;
614
+ color: #f1f5f9;
615
+ }
616
+
617
+ .bz-pm-desc {
618
+ color: #94a3b8;
619
+ line-height: 1.35;
620
+ }
621
+
622
+ /* ----------------------------------------------------------------------------
623
+ * 5. 十卷 5×5 賓果切換與盤面
624
+ * ---------------------------------------------------------------------------- */
625
+ .bz-scroll-tabs {
626
+ display: flex;
627
+ gap: 6px;
628
+ overflow-x: auto;
629
+ -webkit-overflow-scrolling: touch;
630
+ padding-bottom: 4px;
631
+ }
632
+
633
+ .bz-scroll-pill {
634
+ flex: 0 0 auto;
635
+ min-height: 44px;
636
+ padding: 6px 11px;
637
+ border-radius: 12px;
638
+ border: 1px solid rgba(148, 163, 184, 0.25);
639
+ background: rgba(24, 30, 49, 0.78);
640
+ color: #cbd5e1;
641
+ font-size: 12.5px;
642
+ font-weight: 800;
643
+ cursor: pointer;
644
+ display: inline-flex;
645
+ flex-direction: column;
646
+ align-items: center;
647
+ justify-content: center;
648
+ gap: 2px;
649
+ touch-action: manipulation;
650
+ transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
651
+ }
652
+
653
+ .bz-scroll-pill.is-active {
654
+ background: linear-gradient(145deg, rgba(245, 158, 11, 0.28), rgba(180, 83, 9, 0.25));
655
+ border-color: #fbbf24;
656
+ color: #fef3c7;
657
+ }
658
+
659
+ .bz-scroll-pill:hover {
660
+ transform: translateY(-1px);
661
+ border-color: rgba(245, 158, 11, 0.55);
662
+ }
663
+
664
+ .bz-near-tag {
665
+ display: inline-block;
666
+ padding: 1px 6px;
667
+ border-radius: 99px;
668
+ background: #ef4444;
669
+ color: #ffffff;
670
+ font-size: 10px;
671
+ font-weight: 900;
672
+ animation: bzNearPulse 1.3s ease-in-out infinite;
673
+ }
674
+
675
+ .bz-bingo-grid {
676
+ display: grid;
677
+ grid-template-columns: repeat(5, minmax(0, 1fr));
678
+ gap: 6px;
679
+ }
680
+
681
+ .bz-cell {
682
+ position: relative;
683
+ min-height: 62px;
684
+ padding: 6px 5px;
685
+ border-radius: 11px;
686
+ border: 1px solid rgba(148, 163, 184, 0.24);
687
+ background: linear-gradient(160deg, rgba(30, 41, 59, 0.85), rgba(15, 23, 42, 0.92));
688
+ color: #e2e8f0;
689
+ cursor: pointer;
690
+ display: flex;
691
+ flex-direction: column;
692
+ align-items: center;
693
+ justify-content: center;
694
+ text-align: center;
695
+ gap: 2px;
696
+ overflow: hidden;
697
+ touch-action: manipulation;
698
+ transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
699
+ }
700
+
701
+ .bz-cell:hover {
702
+ transform: translateY(-1px);
703
+ border-color: rgba(245, 158, 11, 0.7);
704
+ }
705
+
706
+ .bz-cell.is-selected {
707
+ outline: 2px solid #38bdf8;
708
+ outline-offset: 1px;
709
+ }
710
+
711
+ .bz-cell.is-free {
712
+ background: linear-gradient(145deg, rgba(245, 158, 11, 0.38), rgba(180, 83, 9, 0.34));
713
+ border-color: #fbbf24;
714
+ color: #fef3c7;
715
+ font-weight: 900;
716
+ }
717
+
718
+ .bz-cell.is-lit {
719
+ background: linear-gradient(155deg, rgba(20, 184, 166, 0.28), rgba(245, 158, 11, 0.22));
720
+ border-color: rgba(45, 212, 191, 0.78);
721
+ color: #f8fafc;
722
+ }
723
+
724
+ .bz-cell.is-locked {
725
+ background: linear-gradient(155deg, rgba(127, 29, 29, 0.55), rgba(69, 10, 10, 0.75));
726
+ border: 1.5px solid rgba(239, 68, 68, 0.88);
727
+ color: #fee2e2;
728
+ }
729
+
730
+ .bz-cell.is-line-win {
731
+ animation: bzLineShimmer 2s ease-in-out infinite;
732
+ }
733
+
734
+ .bz-cell-top {
735
+ width: 100%;
736
+ display: flex;
737
+ align-items: center;
738
+ justify-content: space-between;
739
+ font-size: 10px;
740
+ font-weight: 800;
741
+ opacity: 0.9;
742
+ }
743
+
744
+ .bz-cell-word {
745
+ width: 100%;
746
+ font-size: 12px;
747
+ font-weight: 800;
748
+ white-space: nowrap;
749
+ overflow: hidden;
750
+ text-overflow: ellipsis;
751
+ }
752
+
753
+ .bz-cell-zh {
754
+ width: 100%;
755
+ font-size: 10.5px;
756
+ color: #a7f3d0;
757
+ white-space: nowrap;
758
+ overflow: hidden;
759
+ text-overflow: ellipsis;
760
+ }
761
+
762
+ .bz-word-inspector {
763
+ margin-top: 10px;
764
+ padding: 12px 14px;
765
+ border-radius: 14px;
766
+ background: rgba(15, 23, 42, 0.82);
767
+ border: 1px solid rgba(20, 184, 166, 0.38);
768
+ display: flex;
769
+ align-items: center;
770
+ justify-content: space-between;
771
+ gap: 12px;
772
+ flex-wrap: wrap;
773
+ }
774
+
775
+ /* ----------------------------------------------------------------------------
776
+ * 6. 漫步西域街道過場動畫 (.bz-walk-stage)
777
+ * ---------------------------------------------------------------------------- */
778
+ .bz-walk-stage {
779
+ position: relative;
780
+ height: clamp(200px, 34vh, 300px);
781
+ border-radius: 18px;
782
+ overflow: hidden;
783
+ border: 1.5px solid rgba(245, 158, 11, 0.65);
784
+ background: #0f111a url('../assets/bazaar_street_bg.png?v=20261123_v2') center/cover no-repeat;
785
+ box-shadow: 0 18px 42px rgba(0, 0, 0, 0.6);
786
+ }
787
+
788
+ .bz-walk-stage::before {
789
+ content: '';
790
+ position: absolute;
791
+ inset: 0;
792
+ background: linear-gradient(180deg, rgba(15, 17, 26, 0.25) 0%, rgba(15, 17, 26, 0.15) 55%, rgba(15, 17, 26, 0.82) 100%);
793
+ pointer-events: none;
794
+ }
795
+
796
+ .bz-lantern-glow {
797
+ position: absolute;
798
+ width: 14px;
799
+ height: 14px;
800
+ border-radius: 99px;
801
+ background: radial-gradient(circle, #fde68a 0%, rgba(245, 158, 11, 0.65) 55%, transparent 100%);
802
+ pointer-events: none;
803
+ animation: bzLanternParticle 2.1s ease-in-out infinite;
804
+ }
805
+
806
+ .bz-walk-skip-btn {
807
+ position: absolute;
808
+ top: 12px;
809
+ right: 12px;
810
+ z-index: 10;
811
+ min-height: 44px;
812
+ min-width: 44px;
813
+ padding: 8px 14px;
814
+ border-radius: 99px;
815
+ border: 1px solid rgba(253, 230, 138, 0.7);
816
+ background: rgba(15, 17, 26, 0.85);
817
+ color: #fde68a;
818
+ font-size: 13px;
819
+ font-weight: 800;
820
+ cursor: pointer;
821
+ touch-action: manipulation;
822
+ }
823
+
824
+ .bz-walk-actor {
825
+ position: absolute;
826
+ bottom: 24px;
827
+ left: 6%;
828
+ z-index: 5;
829
+ width: clamp(86px, 15vw, 124px);
830
+ display: flex;
831
+ flex-direction: column;
832
+ align-items: center;
833
+ animation: bzWalkAcross 1.1s cubic-bezier(0.22, 0.85, 0.36, 1) forwards;
834
+ }
835
+
836
+ .bz-walk-actor img {
837
+ width: 100%;
838
+ height: auto;
839
+ object-fit: contain;
840
+ filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.65));
841
+ }
842
+
843
+ .bz-exclaim-burst {
844
+ position: absolute;
845
+ top: -42px;
846
+ left: 50%;
847
+ transform: translateX(-50%);
848
+ font-size: 38px;
849
+ line-height: 1;
850
+ filter: drop-shadow(0 0 14px rgba(251, 191, 36, 0.95));
851
+ opacity: 0;
852
+ }
853
+
854
+ .bz-exclaim-burst.is-show {
855
+ animation: bzExclaimPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
856
+ }
857
+
858
+ .bz-walk-caption {
859
+ position: absolute;
860
+ left: 16px;
861
+ right: 16px;
862
+ bottom: 12px;
863
+ z-index: 6;
864
+ text-align: center;
865
+ font-size: 14px;
866
+ font-weight: 800;
867
+ color: #fef3c7;
868
+ text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
869
+ }
870
+
871
+ .bz-walk-flash {
872
+ position: absolute;
873
+ inset: 0;
874
+ z-index: 15;
875
+ background: radial-gradient(circle, rgba(254, 240, 138, 0.92), rgba(245, 158, 11, 0.45));
876
+ pointer-events: none;
877
+ opacity: 0;
878
+ }
879
+
880
+ .bz-walk-flash.is-active {
881
+ animation: bzFlashIn 0.35s ease-out forwards;
882
+ }
883
+
884
+ /* ----------------------------------------------------------------------------
885
+ * 7. 四大角色對決競技場 (.bz-arena)
886
+ * ---------------------------------------------------------------------------- */
887
+ .bz-arena {
888
+ display: grid;
889
+ grid-template-columns: 260px minmax(0, 1fr);
890
+ gap: 16px;
891
+ align-items: start;
892
+ }
893
+
894
+ .bz-npc-panel {
895
+ border-radius: 16px;
896
+ border: 1px solid rgba(245, 158, 11, 0.38);
897
+ background: linear-gradient(170deg, rgba(24, 30, 50, 0.95), rgba(14, 17, 28, 0.98));
898
+ padding: 14px;
899
+ display: flex;
900
+ flex-direction: column;
901
+ align-items: center;
902
+ gap: 10px;
903
+ }
904
+
905
+ .bz-npc-portrait {
906
+ width: 100%;
907
+ max-width: 210px;
908
+ aspect-ratio: 896 / 1200;
909
+ border-radius: 14px;
910
+ overflow: hidden;
911
+ border: 1.5px solid rgba(245, 158, 11, 0.45);
912
+ background: radial-gradient(circle at 50% 35%, rgba(245, 158, 11, 0.16), rgba(15, 17, 26, 0.9));
913
+ }
914
+
915
+ .bz-npc-portrait img {
916
+ width: 100%;
917
+ height: 100%;
918
+ object-fit: cover;
919
+ display: block;
920
+ }
921
+
922
+ .bz-npc-name {
923
+ font-size: 15px;
924
+ font-weight: 900;
925
+ color: #fde68a;
926
+ text-align: center;
927
+ }
928
+
929
+ .bz-npc-role {
930
+ font-size: 12px;
931
+ color: #5eead4;
932
+ font-weight: 700;
933
+ text-align: center;
934
+ }
935
+
936
+ .bz-npc-bubble {
937
+ width: 100%;
938
+ padding: 10px 12px;
939
+ border-radius: 12px;
940
+ background: rgba(15, 23, 42, 0.85);
941
+ border: 1px solid rgba(148, 163, 184, 0.24);
942
+ font-size: 13px;
943
+ line-height: 1.5;
944
+ color: #f1f5f9;
945
+ }
946
+
947
+ .bz-battle-panel {
948
+ border-radius: 16px;
949
+ border: 1px solid rgba(245, 158, 11, 0.35);
950
+ background: linear-gradient(165deg, rgba(24, 30, 50, 0.92), rgba(15, 18, 30, 0.97));
951
+ padding: 16px;
952
+ display: flex;
953
+ flex-direction: column;
954
+ gap: 14px;
955
+ }
956
+
957
+ .bz-battle-top {
958
+ display: flex;
959
+ align-items: center;
960
+ justify-content: space-between;
961
+ gap: 10px;
962
+ flex-wrap: wrap;
963
+ }
964
+
965
+ .bz-word-banner {
966
+ padding: 14px 16px;
967
+ border-radius: 14px;
968
+ background: linear-gradient(145deg, rgba(20, 184, 166, 0.18), rgba(15, 23, 42, 0.92));
969
+ border: 1px solid rgba(20, 184, 166, 0.45);
970
+ display: flex;
971
+ flex-direction: column;
972
+ gap: 8px;
973
+ }
974
+
975
+ .bz-word-en-lg {
976
+ font-size: 26px;
977
+ font-weight: 900;
978
+ color: #ffffff;
979
+ letter-spacing: 0.4px;
980
+ }
981
+
982
+ .bz-options-grid {
983
+ display: grid;
984
+ grid-template-columns: repeat(2, minmax(0, 1fr));
985
+ gap: 10px;
986
+ }
987
+
988
+ .bz-opt-btn {
989
+ min-height: 52px;
990
+ padding: 10px 14px;
991
+ border-radius: 12px;
992
+ border: 1.5px solid rgba(148, 163, 184, 0.28);
993
+ background: rgba(30, 41, 59, 0.78);
994
+ color: #f8fafc;
995
+ font-size: 14.5px;
996
+ font-weight: 800;
997
+ text-align: left;
998
+ cursor: pointer;
999
+ display: flex;
1000
+ align-items: center;
1001
+ gap: 10px;
1002
+ touch-action: manipulation;
1003
+ transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
1004
+ }
1005
+
1006
+ .bz-opt-btn:hover:not(:disabled) {
1007
+ transform: translateY(-1px);
1008
+ border-color: #f59e0b;
1009
+ background: rgba(51, 65, 85, 0.9);
1010
+ }
1011
+
1012
+ .bz-opt-btn.is-correct {
1013
+ border-color: #10b981;
1014
+ background: rgba(16, 185, 129, 0.26);
1015
+ color: #d1fae5;
1016
+ }
1017
+
1018
+ .bz-opt-btn.is-wrong {
1019
+ border-color: #ef4444;
1020
+ background: rgba(239, 68, 68, 0.26);
1021
+ color: #fee2e2;
1022
+ animation: bzShake 0.36s ease;
1023
+ }
1024
+
1025
+ .bz-opt-tag {
1026
+ width: 28px;
1027
+ height: 28px;
1028
+ border-radius: 8px;
1029
+ background: rgba(245, 158, 11, 0.25);
1030
+ border: 1px solid rgba(245, 158, 11, 0.55);
1031
+ color: #fde68a;
1032
+ font-size: 13px;
1033
+ font-weight: 900;
1034
+ display: inline-flex;
1035
+ align-items: center;
1036
+ justify-content: center;
1037
+ flex-shrink: 0;
1038
+ }
1039
+
1040
+ /* 織毯娘子 5×5 配對消除 */
1041
+ .bz-pair-grid {
1042
+ display: grid;
1043
+ grid-template-columns: repeat(2, minmax(0, 1fr));
1044
+ gap: 10px;
1045
+ }
1046
+
1047
+ .bz-pair-col {
1048
+ display: flex;
1049
+ flex-direction: column;
1050
+ gap: 8px;
1051
+ }
1052
+
1053
+ .bz-pair-card {
1054
+ min-height: 54px;
1055
+ padding: 10px 12px;
1056
+ border-radius: 12px;
1057
+ border: 1.5px solid rgba(148, 163, 184, 0.3);
1058
+ background: rgba(30, 41, 59, 0.82);
1059
+ color: #f8fafc;
1060
+ font-size: 14px;
1061
+ font-weight: 800;
1062
+ text-align: left;
1063
+ cursor: pointer;
1064
+ display: flex;
1065
+ align-items: center;
1066
+ justify-content: space-between;
1067
+ gap: 8px;
1068
+ touch-action: manipulation;
1069
+ transition: transform 0.14s ease, border-color 0.14s ease, opacity 0.22s ease, background 0.14s ease;
1070
+ }
1071
+
1072
+ .bz-pair-card:hover:not(:disabled) {
1073
+ border-color: #2dd4bf;
1074
+ transform: translateY(-1px);
1075
+ }
1076
+
1077
+ .bz-pair-card.is-selected {
1078
+ border-color: #fbbf24;
1079
+ background: rgba(245, 158, 11, 0.25);
1080
+ box-shadow: 0 0 14px rgba(245, 158, 11, 0.35);
1081
+ }
1082
+
1083
+ .bz-pair-card.is-matched {
1084
+ border-color: #14b8a6;
1085
+ background: linear-gradient(135deg, rgba(20, 184, 166, 0.25), rgba(245, 158, 11, 0.2));
1086
+ color: #99f6e4;
1087
+ opacity: 0.45;
1088
+ transform: scale(0.97);
1089
+ cursor: default;
1090
+ }
1091
+
1092
+ .bz-pair-card.is-wrong-shake {
1093
+ border-color: #ef4444;
1094
+ background: rgba(239, 68, 68, 0.3);
1095
+ animation: bzShake 0.4s ease;
1096
+ }
1097
+
1098
+ /* 琵琶樂師語音按鈕 */
1099
+ .bz-pipa-btn {
1100
+ min-height: 56px;
1101
+ padding: 12px 20px;
1102
+ border-radius: 16px;
1103
+ border: 1.5px solid rgba(192, 132, 252, 0.72);
1104
+ background: linear-gradient(135deg, rgba(147, 51, 234, 0.45), rgba(79, 70, 229, 0.4));
1105
+ color: #f3e8ff;
1106
+ font-size: 16px;
1107
+ font-weight: 900;
1108
+ cursor: pointer;
1109
+ display: inline-flex;
1110
+ align-items: center;
1111
+ justify-content: center;
1112
+ gap: 10px;
1113
+ touch-action: manipulation;
1114
+ box-shadow: 0 8px 20px rgba(147, 51, 234, 0.28);
1115
+ transition: transform 0.15s ease, box-shadow 0.15s ease;
1116
+ }
1117
+
1118
+ .bz-pipa-btn:hover {
1119
+ transform: scale(1.02);
1120
+ box-shadow: 0 10px 26px rgba(168, 85, 247, 0.45);
1121
+ }
1122
+
1123
+ .bz-mute-toggle-btn {
1124
+ min-height: 44px;
1125
+ padding: 8px 12px;
1126
+ border-radius: 11px;
1127
+ border: 1px solid rgba(192, 132, 252, 0.45);
1128
+ background: rgba(30, 27, 75, 0.75);
1129
+ color: #e9d5ff;
1130
+ font-size: 12.5px;
1131
+ font-weight: 800;
1132
+ cursor: pointer;
1133
+ touch-action: manipulation;
1134
+ }
1135
+
1136
+ /* 星象學者羊皮紙與拼字寶石 */
1137
+ .bz-parchment-box {
1138
+ padding: 14px 16px;
1139
+ border-radius: 14px;
1140
+ background: linear-gradient(155deg, rgba(254, 243, 199, 0.12), rgba(217, 119, 6, 0.1));
1141
+ border: 1.5px solid rgba(245, 158, 11, 0.45);
1142
+ color: #fef3c7;
1143
+ font-size: 15.5px;
1144
+ line-height: 1.65;
1145
+ font-weight: 700;
1146
+ }
1147
+
1148
+ .bz-cloze-blank {
1149
+ display: inline-block;
1150
+ padding: 1px 10px;
1151
+ margin: 0 3px;
1152
+ border-radius: 8px;
1153
+ background: rgba(245, 158, 11, 0.25);
1154
+ border-bottom: 2px solid #fbbf24;
1155
+ color: #fde68a;
1156
+ font-weight: 900;
1157
+ }
1158
+
1159
+ .bz-scramble-slots {
1160
+ display: flex;
1161
+ flex-wrap: wrap;
1162
+ justify-content: center;
1163
+ gap: 8px;
1164
+ padding: 12px;
1165
+ border-radius: 14px;
1166
+ background: rgba(15, 23, 42, 0.75);
1167
+ border: 1px dashed rgba(245, 158, 11, 0.5);
1168
+ }
1169
+
1170
+ .bz-slot-btn {
1171
+ min-width: 40px;
1172
+ min-height: 46px;
1173
+ padding: 6px 10px;
1174
+ border-radius: 10px;
1175
+ border: 1.5px solid rgba(148, 163, 184, 0.38);
1176
+ background: rgba(30, 41, 59, 0.65);
1177
+ color: #94a3b8;
1178
+ font-size: 18px;
1179
+ font-weight: 900;
1180
+ cursor: pointer;
1181
+ touch-action: manipulation;
1182
+ }
1183
+
1184
+ .bz-slot-btn.is-filled {
1185
+ border-color: #fbbf24;
1186
+ background: linear-gradient(145deg, rgba(245, 158, 11, 0.34), rgba(180, 83, 9, 0.32));
1187
+ color: #fef3c7;
1188
+ }
1189
+
1190
+ .bz-scramble-gems {
1191
+ display: flex;
1192
+ flex-wrap: wrap;
1193
+ justify-content: center;
1194
+ gap: 8px;
1195
+ }
1196
+
1197
+ .bz-gem-btn {
1198
+ min-width: 44px;
1199
+ min-height: 48px;
1200
+ padding: 8px 12px;
1201
+ border-radius: 12px;
1202
+ border: 1.5px solid rgba(45, 212, 191, 0.6);
1203
+ background: linear-gradient(145deg, rgba(20, 184, 166, 0.25), rgba(15, 23, 42, 0.9));
1204
+ color: #ccfbf1;
1205
+ font-size: 18px;
1206
+ font-weight: 900;
1207
+ cursor: pointer;
1208
+ touch-action: manipulation;
1209
+ box-shadow: 0 4px 12px rgba(20, 184, 166, 0.22);
1210
+ transition: transform 0.12s ease, opacity 0.12s ease;
1211
+ }
1212
+
1213
+ .bz-gem-btn:hover:not(:disabled) {
1214
+ transform: translateY(-2px) scale(1.04);
1215
+ }
1216
+
1217
+ .bz-gem-btn:disabled {
1218
+ opacity: 0.25;
1219
+ cursor: default;
1220
+ }
1221
+
1222
+ .bz-shatter-burst {
1223
+ padding: 12px 14px;
1224
+ border-radius: 14px;
1225
+ background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(20, 184, 166, 0.25));
1226
+ border: 1.5px solid #fbbf24;
1227
+ color: #fef08a;
1228
+ font-weight: 900;
1229
+ animation: bzShatterBurst 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
1230
+ }
1231
+
1232
+ .bz-feedback-bar {
1233
+ padding: 11px 14px;
1234
+ border-radius: 12px;
1235
+ display: flex;
1236
+ align-items: center;
1237
+ justify-content: space-between;
1238
+ gap: 10px;
1239
+ flex-wrap: wrap;
1240
+ font-size: 13.5px;
1241
+ font-weight: 800;
1242
+ }
1243
+
1244
+ .bz-feedback-bar.is-ok {
1245
+ background: rgba(16, 185, 129, 0.2);
1246
+ border: 1px solid rgba(16, 185, 129, 0.55);
1247
+ color: #a7f3d0;
1248
+ }
1249
+
1250
+ .bz-feedback-bar.is-bad {
1251
+ background: rgba(239, 68, 68, 0.2);
1252
+ border: 1px solid rgba(239, 68, 68, 0.55);
1253
+ color: #fecaca;
1254
+ }
1255
+
1256
+ /* ----------------------------------------------------------------------------
1257
+ * 8. 13 道首破奪標紅榜牆與英雄榜 (.bz-board-wall)
1258
+ * ---------------------------------------------------------------------------- */
1259
+ .bz-board-wall {
1260
+ display: grid;
1261
+ grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
1262
+ gap: 9px;
1263
+ }
1264
+
1265
+ .bz-fb-banner {
1266
+ padding: 10px 12px;
1267
+ border-radius: 12px;
1268
+ border: 1px solid rgba(148, 163, 184, 0.25);
1269
+ background: rgba(24, 30, 49, 0.8);
1270
+ display: flex;
1271
+ flex-direction: column;
1272
+ gap: 4px;
1273
+ font-size: 12px;
1274
+ }
1275
+
1276
+ .bz-fb-banner.is-open {
1277
+ border-color: rgba(239, 68, 68, 0.52);
1278
+ background: linear-gradient(155deg, rgba(127, 29, 29, 0.28), rgba(24, 30, 49, 0.85));
1279
+ }
1280
+
1281
+ .bz-fb-banner.is-claimed {
1282
+ border-color: rgba(245, 158, 11, 0.68);
1283
+ background: linear-gradient(155deg, rgba(245, 158, 11, 0.2), rgba(20, 184, 166, 0.14));
1284
+ }
1285
+
1286
+ .bz-fb-pulse {
1287
+ display: inline-block;
1288
+ padding: 2px 7px;
1289
+ border-radius: 99px;
1290
+ background: rgba(239, 68, 68, 0.26);
1291
+ border: 1px solid rgba(248, 113, 113, 0.65);
1292
+ color: #fecaca;
1293
+ font-size: 11px;
1294
+ font-weight: 800;
1295
+ animation: bzNearPulse 1.5s ease-in-out infinite;
1296
+ }
1297
+
1298
+ .bz-table-wrap {
1299
+ overflow-x: auto;
1300
+ -webkit-overflow-scrolling: touch;
1301
+ border-radius: 14px;
1302
+ border: 1px solid rgba(245, 158, 11, 0.26);
1303
+ background: rgba(15, 20, 34, 0.85);
1304
+ }
1305
+
1306
+ .bz-rank-table {
1307
+ width: 100%;
1308
+ border-collapse: collapse;
1309
+ font-size: 13.5px;
1310
+ }
1311
+
1312
+ .bz-rank-table th,
1313
+ .bz-rank-table td {
1314
+ padding: 10px 12px;
1315
+ border-bottom: 1px solid rgba(148, 163, 184, 0.16);
1316
+ text-align: left;
1317
+ white-space: nowrap;
1318
+ }
1319
+
1320
+ .bz-rank-table th {
1321
+ color: #fde68a;
1322
+ font-size: 12px;
1323
+ font-weight: 800;
1324
+ background: rgba(30, 41, 59, 0.8);
1325
+ }
1326
+
1327
+ .bz-rank-table tr.is-me {
1328
+ background: rgba(245, 158, 11, 0.16);
1329
+ }
1330
+
1331
+ /* ----------------------------------------------------------------------------
1332
+ * 9. 戰後結算與黑市嵌合區
1333
+ * ---------------------------------------------------------------------------- */
1334
+ .bz-settle-list {
1335
+ display: flex;
1336
+ flex-direction: column;
1337
+ gap: 8px;
1338
+ }
1339
+
1340
+ .bz-settle-row {
1341
+ padding: 10px 12px;
1342
+ border-radius: 12px;
1343
+ background: rgba(15, 23, 42, 0.78);
1344
+ border: 1px solid rgba(148, 163, 184, 0.22);
1345
+ display: flex;
1346
+ align-items: center;
1347
+ justify-content: space-between;
1348
+ gap: 8px;
1349
+ flex-wrap: wrap;
1350
+ }
1351
+
1352
+ .bz-first-blood-hero {
1353
+ padding: 14px 16px;
1354
+ border-radius: 14px;
1355
+ background: linear-gradient(135deg, rgba(245, 158, 11, 0.34), rgba(239, 68, 68, 0.25));
1356
+ border: 1.5px solid #fbbf24;
1357
+ color: #fef3c7;
1358
+ font-weight: 900;
1359
+ box-shadow: 0 10px 28px rgba(245, 158, 11, 0.28);
1360
+ }
1361
+
1362
+ .bz-market-host .me-caravan-bar {
1363
+ display: flex;
1364
+ align-items: center;
1365
+ justify-content: space-between;
1366
+ gap: 12px;
1367
+ flex-wrap: wrap;
1368
+ padding: 12px 16px;
1369
+ margin-bottom: 12px;
1370
+ border-radius: 14px;
1371
+ background: linear-gradient(150deg, rgba(24, 30, 50, 0.94), rgba(15, 20, 34, 0.96));
1372
+ border: 1px solid rgba(245, 158, 11, 0.42);
1373
+ color: #f8fafc;
1374
+ }
1375
+
1376
+ .bz-market-host .me-caravan-bar-exp {
1377
+ width: 180px;
1378
+ height: 8px;
1379
+ border-radius: 99px;
1380
+ background: rgba(15, 23, 42, 0.9);
1381
+ overflow: hidden;
1382
+ border: 1px solid rgba(245, 158, 11, 0.35);
1383
+ }
1384
+
1385
+ .bz-market-host .me-caravan-bar-exp > span {
1386
+ display: block;
1387
+ height: 100%;
1388
+ background: linear-gradient(90deg, #14b8a6, #fbbf24);
1389
+ }
1390
+
1391
+ .bz-market-host .me-item-buy-btn {
1392
+ min-height: 44px;
1393
+ }
1394
+
1395
+ /* ----------------------------------------------------------------------------
1396
+ * 10. 行動端響應式規則 (@media)
1397
+ * ---------------------------------------------------------------------------- */
1398
+ @media (max-width: 768px) {
1399
+ .bz-sticky-header {
1400
+ padding: 12px 58px 10px 12px;
1401
+ }
1402
+
1403
+ .bz-title {
1404
+ font-size: 16.5px;
1405
+ }
1406
+
1407
+ .bz-tabs {
1408
+ gap: 6px;
1409
+ }
1410
+
1411
+ .bz-tab-btn {
1412
+ font-size: 12px;
1413
+ padding: 6px 6px;
1414
+ }
1415
+
1416
+ .bz-content {
1417
+ padding: 12px 12px 20px;
1418
+ }
1419
+
1420
+ .bz-hero-panel {
1421
+ grid-template-columns: 1fr;
1422
+ }
1423
+
1424
+ .bz-milestones-strip {
1425
+ grid-template-columns: repeat(2, minmax(0, 1fr));
1426
+ }
1427
+
1428
+ .bz-bingo-grid {
1429
+ gap: 4px;
1430
+ }
1431
+
1432
+ .bz-cell {
1433
+ min-height: 52px;
1434
+ padding: 4px 3px;
1435
+ }
1436
+
1437
+ .bz-cell-word {
1438
+ font-size: 10.5px;
1439
+ }
1440
+
1441
+ .bz-cell-zh {
1442
+ font-size: 9.5px;
1443
+ }
1444
+
1445
+ .bz-arena {
1446
+ grid-template-columns: 1fr;
1447
+ gap: 10px;
1448
+ }
1449
+
1450
+ .bz-npc-panel {
1451
+ display: grid;
1452
+ grid-template-columns: 68px minmax(0, 1fr);
1453
+ grid-template-rows: auto auto;
1454
+ align-items: center;
1455
+ gap: 8px 12px;
1456
+ padding: 10px 12px;
1457
+ }
1458
+
1459
+ .bz-npc-portrait {
1460
+ grid-row: 1 / 3;
1461
+ width: 68px;
1462
+ max-width: 68px;
1463
+ }
1464
+
1465
+ .bz-npc-name,
1466
+ .bz-npc-role {
1467
+ text-align: left;
1468
+ }
1469
+
1470
+ .bz-npc-bubble {
1471
+ grid-column: 1 / -1;
1472
+ font-size: 12.5px;
1473
+ padding: 8px 10px;
1474
+ }
1475
+
1476
+ .bz-options-grid {
1477
+ grid-template-columns: 1fr;
1478
+ }
1479
+
1480
+ .bz-pair-grid {
1481
+ gap: 8px;
1482
+ }
1483
+
1484
+ .bz-pair-card {
1485
+ padding: 8px 9px;
1486
+ font-size: 13px;
1487
+ }
1488
+ }
1489
+
1490
+ @media (max-height: 700px) {
1491
+ .bz-walk-stage {
1492
+ height: 190px;
1493
+ }
1494
+ }
index.html CHANGED
@@ -11,6 +11,7 @@
11
  <link rel="stylesheet" href="css/base.css?v=20261123_v2">
12
  <link rel="stylesheet" href="css/game.css?v=20261123_v2">
13
  <link rel="stylesheet" href="css/lottery.css?v=20261123_v2">
 
14
  <!-- KaTeX 數學式與科學記號渲染引擎 -->
15
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css">
16
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script>
 
11
  <link rel="stylesheet" href="css/base.css?v=20261123_v2">
12
  <link rel="stylesheet" href="css/game.css?v=20261123_v2">
13
  <link rel="stylesheet" href="css/lottery.css?v=20261123_v2">
14
+ <link rel="stylesheet" href="css/bazaar.css?v=20261123_v2">
15
  <!-- KaTeX 數學式與科學記號渲染引擎 -->
16
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css">
17
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script>
js/bazaar-ui.js ADDED
@@ -0,0 +1,1664 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ============================================================================
2
+ // js/bazaar-ui.js
3
+ // 西域萬國大市集(Western Grand Bazaar)完整互動介面模組
4
+ // - 開市前週一 07:00 倒數封印面板
5
+ // - 三大頁籤:市集奇遇&十卷賓果、本班 13 階首破英雄榜、西域黑市攤位嵌合
6
+ // - 漫步絲路街道驚嘆號過場動畫(支援略過)
7
+ // - 4 大角色專屬考單字對決舞台(阿卜杜勒/莎赫拉 5×5 配對/迦陵語音切換/伊本破鎖拼字)
8
+ // - 戰後結算、班級首破交易 sync 與計時器/語音嚴格清理
9
+ // ============================================================================
10
+ import { BAZAAR_CONFIG, MERCHANT, formatTitleBadge } from './config.js?v=20261123_v2';
11
+ import { $, $$, bind, esc, fmt, fmtDateTime, toast, openModal } from './util.js?v=20261123_v2';
12
+ import { getMerchantStatus } from './merchant.js?v=20261123_v2';
13
+ import { renderMerchantMarketPanel } from './merchant-ui.js?v=20261123_v2';
14
+ import {
15
+ ensureBazaarCycleState,
16
+ getBazaarQuotaInfo,
17
+ getWordMistakeChainState,
18
+ computeBazaarSummary,
19
+ generateBazaarEncounter,
20
+ recordBazaarItemOutcome,
21
+ settleBazaarEncounter,
22
+ loadEnglishWords,
23
+ speakWord,
24
+ } from './bazaar.js?v=20261123_v2';
25
+
26
+ const SCROLL_TITLES = ['卷壹', '卷貳', '卷參', '卷肆', '卷伍', '卷陸', '卷柒', '卷捌', '卷玖', '卷拾'];
27
+ const OPTION_LABELS = ['A', 'B', 'C', 'D'];
28
+ const BAZAAR_LINES = [
29
+ [0, 1, 2, 3, 4],
30
+ [5, 6, 7, 8, 9],
31
+ [10, 11, 12, 13, 14],
32
+ [15, 16, 17, 18, 19],
33
+ [20, 21, 22, 23, 24],
34
+ [0, 5, 10, 15, 20],
35
+ [1, 6, 11, 16, 21],
36
+ [2, 7, 12, 17, 22],
37
+ [3, 8, 13, 18, 23],
38
+ [4, 9, 14, 19, 24],
39
+ [0, 6, 12, 18, 24],
40
+ [4, 8, 12, 16, 20],
41
+ ];
42
+
43
+ let bazaarCtx = null;
44
+ let _audioCtx = null;
45
+
46
+ /**
47
+ * 註冊大市集 UI 外部上下文(getGame, getStudent, getClassInfo, getProgress, getDState, db, save, refreshUI, toast)
48
+ */
49
+ export function setupBazaarUI(context) {
50
+ bazaarCtx = context || null;
51
+ }
52
+
53
+ function playBazaarSfx(kind) {
54
+ try {
55
+ if (typeof window === 'undefined') return;
56
+ const AudioCtx = window.AudioContext || window.webkitAudioContext;
57
+ if (!AudioCtx) return;
58
+ if (!_audioCtx) _audioCtx = new AudioCtx();
59
+ if (_audioCtx.state === 'suspended') _audioCtx.resume().catch(() => { });
60
+ const now = _audioCtx.currentTime;
61
+ const tones = {
62
+ exclaim: [
63
+ { freq: 659.25, delay: 0, dur: 0.08, vol: 0.14, type: 'triangle' },
64
+ { freq: 987.77, delay: 0.07, dur: 0.16, vol: 0.16, type: 'triangle' },
65
+ ],
66
+ correct: [
67
+ { freq: 523.25, delay: 0, dur: 0.09, vol: 0.12, type: 'triangle' },
68
+ { freq: 783.99, delay: 0.07, dur: 0.14, vol: 0.14, type: 'triangle' },
69
+ ],
70
+ wrong: [
71
+ { freq: 220, delay: 0, dur: 0.18, vol: 0.11, type: 'sine' },
72
+ ],
73
+ shatter: [
74
+ { freq: 523.25, delay: 0, dur: 0.1, vol: 0.14, type: 'triangle' },
75
+ { freq: 659.25, delay: 0.07, dur: 0.1, vol: 0.15, type: 'triangle' },
76
+ { freq: 783.99, delay: 0.14, dur: 0.12, vol: 0.16, type: 'triangle' },
77
+ { freq: 1046.5, delay: 0.22, dur: 0.26, vol: 0.18, type: 'triangle' },
78
+ ],
79
+ }[kind] || [];
80
+
81
+ for (const st of tones) {
82
+ const osc = _audioCtx.createOscillator();
83
+ const gain = _audioCtx.createGain();
84
+ osc.type = st.type || 'triangle';
85
+ osc.frequency.setValueAtTime(st.freq, now + st.delay);
86
+ gain.gain.setValueAtTime(0.0001, now + st.delay);
87
+ gain.gain.exponentialRampToValueAtTime(st.vol, now + st.delay + 0.015);
88
+ gain.gain.exponentialRampToValueAtTime(0.0001, now + st.delay + st.dur);
89
+ osc.connect(gain);
90
+ gain.connect(_audioCtx.destination);
91
+ osc.start(now + st.delay);
92
+ osc.stop(now + st.delay + st.dur + 0.02);
93
+ }
94
+ } catch (e) { }
95
+ }
96
+
97
+ function safeSpeakWord(word) {
98
+ try {
99
+ speakWord(word);
100
+ } catch (e) { }
101
+ }
102
+
103
+ function cancelSpeech() {
104
+ try {
105
+ if (typeof window !== 'undefined' && window.speechSynthesis) {
106
+ window.speechSynthesis.cancel();
107
+ }
108
+ } catch (e) { }
109
+ }
110
+
111
+ function formatCountdown(msLeft) {
112
+ const sec = Math.max(0, Math.floor(msLeft / 1000));
113
+ const d = Math.floor(sec / 86400);
114
+ const h = Math.floor((sec % 86400) / 3600);
115
+ const m = Math.floor((sec % 3600) / 60);
116
+ const s = sec % 60;
117
+ const pad = (v) => String(v).padStart(2, '0');
118
+ return d > 0 ? `${d}天 ${pad(h)}:${pad(m)}:${pad(s)}` : `${pad(h)}:${pad(m)}:${pad(s)}`;
119
+ }
120
+
121
+ function getNpcMeta(npcId) {
122
+ const list = Array.isArray(BAZAAR_CONFIG.npcs) ? BAZAAR_CONFIG.npcs : [];
123
+ return list.find((n) => n.id === npcId) || list[0] || {
124
+ id: 'captain',
125
+ name: '商隊隊長・阿卜杜勒',
126
+ roleTitle: '極速喊價・經典四選一',
127
+ img: 'assets/leader_lv4_normal.png',
128
+ accent: '#f59e0b',
129
+ };
130
+ }
131
+
132
+ function getWinningCellSet(board, cycleState) {
133
+ const winSet = new Set();
134
+ if (!Array.isArray(board)) return winSet;
135
+ const isLit = (cell) => Boolean(cell && (cell.isFree || cycleState?.litWords?.[String(cell.n)]));
136
+ for (const line of BAZAAR_LINES) {
137
+ if (line.every((idx) => isLit(board[idx]))) {
138
+ for (const idx of line) winSet.add(idx);
139
+ }
140
+ }
141
+ return winSet;
142
+ }
143
+
144
+ function renderMaskedClozeHtml(rawText) {
145
+ const safe = esc(rawText || '');
146
+ return safe
147
+ .replace(/&lt;span class=&quot;word-blank&quot;[^&gt;]*&gt;______&lt;\/span&gt;/g, '<span class="bz-cloze-blank">______</span>')
148
+ .replace(/______/g, '<span class="bz-cloze-blank">______</span>');
149
+ }
150
+
151
+ /**
152
+ * 開啟西域萬國大市集互動主彈窗
153
+ */
154
+ export async function openBazaarEventModal(opts = {}) {
155
+ const getGame = () => opts.game || bazaarCtx?.getGame?.() || (typeof window !== 'undefined' ? window.student?.game : null);
156
+ const getStudent = () => opts.student || bazaarCtx?.getStudent?.() || (typeof window !== 'undefined' ? window.student : {}) || {};
157
+ const getClassInfo = () => opts.classInfo || bazaarCtx?.getClassInfo?.() || (typeof window !== 'undefined' ? window.classInfo : {}) || {};
158
+ const getProgress = () => opts.progress || bazaarCtx?.getProgress?.() || {};
159
+ const getDState = () => (typeof opts.getDState === 'function' ? opts.getDState() : bazaarCtx?.getDState?.());
160
+ const notify = (msg, type = 'info', ms = 2600) => (bazaarCtx?.toast || toast)(msg, type, ms);
161
+ const saveGame = async () => {
162
+ try {
163
+ await bazaarCtx?.save?.();
164
+ } catch (e) {
165
+ console.warn('[bazaar-ui] save failed:', e);
166
+ }
167
+ };
168
+ const refreshUI = () => {
169
+ try {
170
+ bazaarCtx?.refreshUI?.();
171
+ } catch (e) { }
172
+ };
173
+
174
+ const game = getGame();
175
+ if (!game) {
176
+ notify('🎪 軍帳資料尚未載入完成,請稍候重試!', 'info');
177
+ return;
178
+ }
179
+
180
+ const student = getStudent();
181
+ const uid = student?.uid || bazaarCtx?.getUid?.() || bazaarCtx?.getUser?.()?.uid || 'guest';
182
+ const initQuota = getBazaarQuotaInfo(getClassInfo(), opts.now || new Date());
183
+ const modeState = initQuota.modeState;
184
+
185
+ if (modeState.activeType !== 'bazaar' || !modeState.cycleId || !modeState.cycleConfig) {
186
+ notify('🎪 西域萬國大市集目前尚未巡抵本城,請依賽程靜待開放!', 'gold', 4000);
187
+ return;
188
+ }
189
+
190
+ const isCountdownInit = Boolean(modeState.isCountdown && !modeState.isForcedOpen);
191
+ let words = [];
192
+ try {
193
+ words = await loadEnglishWords();
194
+ } catch (err) {
195
+ console.warn('[bazaar-ui] loadEnglishWords error:', err);
196
+ }
197
+ if (!isCountdownInit && (!Array.isArray(words) || words.length === 0)) {
198
+ notify('🎪 西域萬國大市集:單字題庫載入中,請稍候重試!', 'gold');
199
+ return;
200
+ }
201
+
202
+ const wordsMap = new Map((Array.isArray(words) ? words : []).map((w) => [Number(w.n), w]));
203
+
204
+ let activeTab = opts.initialTab === 'leaderboard' || opts.initialTab === 'market' ? opts.initialTab : 'bazaar';
205
+ let activeScrollIdx = 0;
206
+ let inspectedWordN = null;
207
+ let countdownTimer = null;
208
+ let walkTimer = null;
209
+ let walkDoneTimer = null;
210
+ const activeTimeouts = new Set();
211
+ let isClosed = false;
212
+ let cachedClassDoc = null;
213
+ let cachedClassAt = 0;
214
+ let leaderboardLoading = false;
215
+ let leaderboardErr = null;
216
+
217
+ function scheduleTimeout(fn, ms) {
218
+ const id = setTimeout(() => {
219
+ activeTimeouts.delete(id);
220
+ if (!isClosed) fn();
221
+ }, ms);
222
+ activeTimeouts.add(id);
223
+ return id;
224
+ }
225
+
226
+ function clearTimers() {
227
+ if (countdownTimer) {
228
+ clearInterval(countdownTimer);
229
+ countdownTimer = null;
230
+ }
231
+ if (walkTimer) {
232
+ clearTimeout(walkTimer);
233
+ walkTimer = null;
234
+ }
235
+ if (walkDoneTimer) {
236
+ clearTimeout(walkDoneTimer);
237
+ walkDoneTimer = null;
238
+ }
239
+ for (const id of activeTimeouts) {
240
+ clearTimeout(id);
241
+ }
242
+ activeTimeouts.clear();
243
+ cancelSpeech();
244
+ }
245
+
246
+ const modal = openModal('', {
247
+ wide: true,
248
+ closable: true,
249
+ className: 'bazaar-modal',
250
+ onClose: () => {
251
+ isClosed = true;
252
+ clearTimers();
253
+ refreshUI();
254
+ },
255
+ });
256
+
257
+ const modalCard = modal.el.closest?.('.modal');
258
+ const closeBtn = modalCard?.querySelector?.('.modal-x');
259
+ if (closeBtn) {
260
+ closeBtn.classList.add('modal-close');
261
+ }
262
+ const container = modal.el;
263
+
264
+ function getHeaderHtml(cycleConfig, summary, showTabs = true) {
265
+ const mStatus = getMerchantStatus(game);
266
+ const m = game.merchant || {};
267
+ return `
268
+ <div class="bz-sticky-header">
269
+ <div class="bz-head-top">
270
+ <div class="bz-title-wrap">
271
+ <div class="bz-title-emblem">🎪</div>
272
+ <div>
273
+ <h2 class="bz-title">西域萬國大市集</h2>
274
+ <div class="bz-subtitle">${esc(cycleConfig?.title || '絲路十卷賓果慶典')}</div>
275
+ </div>
276
+ </div>
277
+ <div class="bz-status-pills" id="bzHeaderPills">
278
+ <span class="bz-pill bz-pill-gold">✨ 連線 ${summary.totalLines} / 120</span>
279
+ <span class="bz-pill bz-pill-teal">📜 點亮 ${summary.litCount} / ${BAZAAR_CONFIG.totalWordsPerCycle}</span>
280
+ <span class="bz-pill bz-pill-gold">🪙 ${mStatus.gold} 幣</span>
281
+ ${(m.coupons || 0) > 0 ? `<span class="bz-pill bz-pill-crimson">🎫 8折券 ×${m.coupons}</span>` : ''}
282
+ </div>
283
+ </div>
284
+ ${showTabs ? `
285
+ <div class="bz-tabs" role="tablist">
286
+ <button type="button" class="bz-tab-btn ${activeTab === 'bazaar' ? 'is-active' : ''}" data-bz-tab="bazaar">🎪 市集奇遇 & 十卷賓果</button>
287
+ <button type="button" class="bz-tab-btn ${activeTab === 'leaderboard' ? 'is-active' : ''}" data-bz-tab="leaderboard">🏆 本班連線英雄榜</button>
288
+ <button type="button" class="bz-tab-btn ${activeTab === 'market' ? 'is-active' : ''}" data-bz-tab="market">🏺 西域黑市攤位</button>
289
+ </div>
290
+ ` : ''}
291
+ </div>
292
+ `;
293
+ }
294
+
295
+ function bindHeaderTabs() {
296
+ $$('[data-bz-tab]', container).forEach((btn) => {
297
+ bind(btn, 'click', () => {
298
+ const nextTab = btn.dataset.bzTab;
299
+ if (!nextTab || nextTab === activeTab) return;
300
+ activeTab = nextTab;
301
+ showLobbyView();
302
+ });
303
+ });
304
+ }
305
+
306
+ function updateHeaderPills() {
307
+ const pillsEl = $('#bzHeaderPills', container);
308
+ if (!pillsEl) return;
309
+ const quota = getBazaarQuotaInfo(getClassInfo(), new Date());
310
+ const cycleId = quota.modeState.cycleId || modeState.cycleId;
311
+ const summary = computeBazaarSummary(game, uid, cycleId);
312
+ const mStatus = getMerchantStatus(game);
313
+ const m = game.merchant || {};
314
+ pillsEl.innerHTML = `
315
+ <span class="bz-pill bz-pill-gold">✨ 連線 ${summary.totalLines} / 120</span>
316
+ <span class="bz-pill bz-pill-teal">📜 點亮 ${summary.litCount} / ${BAZAAR_CONFIG.totalWordsPerCycle}</span>
317
+ <span class="bz-pill bz-pill-gold">🪙 ${mStatus.gold} 幣</span>
318
+ ${(m.coupons || 0) > 0 ? `<span class="bz-pill bz-pill-crimson">🎫 8折券 ×${m.coupons}</span>` : ''}
319
+ `;
320
+ }
321
+
322
+ // --------------------------------------------------------------------------
323
+ // 視圖 0:週一 07:00 開市前倒數封印面板
324
+ // --------------------------------------------------------------------------
325
+ function showCountdownView(quotaInfo) {
326
+ clearTimers();
327
+ const ms = quotaInfo.modeState;
328
+ const cycleCfg = ms.cycleConfig || modeState.cycleConfig;
329
+ const summary = computeBazaarSummary(game, uid, cycleCfg.id);
330
+ const remMs = Math.max(0, (ms.openAtMs || 0) - Date.now());
331
+
332
+ container.innerHTML = `
333
+ <div class="bz-shell">
334
+ ${getHeaderHtml(cycleCfg, summary, false)}
335
+ <div class="bz-content">
336
+ <div class="bz-countdown-card">
337
+ <div class="bz-countdown-hero">
338
+ <img src="assets/bazaar_camp.png?v=20261123_v2" alt="西域萬國大市集">
339
+ <div class="bz-countdown-seal">
340
+ <span class="bz-pill bz-pill-gold">🏮 西域商隊籌備開張中</span>
341
+ <div class="bz-countdown-clock" id="bzOpenCountdownVal">${formatCountdown(remMs)}</div>
342
+ <div style="font-size:13.5px;font-weight:700;color:#e2e8f0;">
343
+ 預計於週一 07:00(UTC+8)準時鳴鑼開市・範圍 #${String(cycleCfg.startN).padStart(3, '0')}~#${String(cycleCfg.endN).padStart(3, '0')}
344
+ </div>
345
+ </div>
346
+ </div>
347
+
348
+ <div class="bz-rule-grid">
349
+ <div class="bz-rule-tile">
350
+ <b>📜 十卷 5×5 個人賓果盤</b>
351
+ 本期 240 個單字隨機洗入 10 卷賓果(中央賜福自動點亮),共 120 條連線等你開圖!
352
+ </div>
353
+ <div class="bz-rule-tile">
354
+ <b>⏳ 每日 07:00 水位累積</b>
355
+ 週一 50 格 → 週二 100 格 → 週三 150 格 → 週四 200 格 → 週五起全 240 格開通,不怕追不上進度。
356
+ </div>
357
+ <div class="bz-rule-tile">
358
+ <b>⚔️ 四大名師奇遇&三鎖錯題</b>
359
+ 遇見阿卜杜勒、織毯娘子、琵琶樂師或星象學者;答錯上 3 道紅鏈,敲裂前兩鎖照樣贈糧草!
360
+ </div>
361
+ <div class="bz-rule-tile">
362
+ <b>🏆 13 階首破賞 & 120 線宗師</b>
363
+ 全班首破 1、10、20…120 線各搶 1 枚金兵符;個人集滿 120 線加封「${esc(cycleCfg.grandTitle)}」!
364
+ </div>
365
+ </div>
366
+
367
+ <button type="button" class="bz-btn-primary" disabled>
368
+ 🔒 尚未開市・靜待週一 07:00 準時啟航
369
+ </button>
370
+ </div>
371
+ </div>
372
+ </div>
373
+ `;
374
+
375
+ countdownTimer = setInterval(() => {
376
+ if (isClosed) {
377
+ clearTimers();
378
+ return;
379
+ }
380
+ const nextQuota = getBazaarQuotaInfo(getClassInfo(), new Date());
381
+ if (!nextQuota.modeState.isCountdown || nextQuota.modeState.isForcedOpen) {
382
+ clearTimers();
383
+ showLobbyView();
384
+ return;
385
+ }
386
+ const left = Math.max(0, (nextQuota.modeState.openAtMs || 0) - Date.now());
387
+ const clockEl = $('#bzOpenCountdownVal', container);
388
+ if (clockEl) clockEl.textContent = formatCountdown(left);
389
+ }, 1000);
390
+ }
391
+
392
+ // --------------------------------------------------------------------------
393
+ // 視圖 1:大廳主控台(含三大頁籤)
394
+ // --------------------------------------------------------------------------
395
+ function showLobbyView() {
396
+ clearTimers();
397
+ const quota = getBazaarQuotaInfo(getClassInfo(), new Date());
398
+ if (quota.modeState.isCountdown && !quota.modeState.isForcedOpen) {
399
+ showCountdownView(quota);
400
+ return;
401
+ }
402
+
403
+ const cycleCfg = quota.modeState.cycleConfig || modeState.cycleConfig;
404
+ const cycleId = cycleCfg.id;
405
+ const cycleState = ensureBazaarCycleState(game, cycleId);
406
+ const summary = computeBazaarSummary(game, uid, cycleId);
407
+
408
+ let bodyHtml = '';
409
+ if (activeTab === 'bazaar') {
410
+ bodyHtml = renderBazaarTabHtml(quota, cycleCfg, cycleState, summary);
411
+ } else if (activeTab === 'leaderboard') {
412
+ bodyHtml = renderLeaderboardTabHtml(cycleCfg, cycleId);
413
+ } else {
414
+ bodyHtml = renderMarketTabHtml();
415
+ }
416
+
417
+ container.innerHTML = `
418
+ <div class="bz-shell">
419
+ ${getHeaderHtml(cycleCfg, summary, true)}
420
+ <div class="bz-content" id="bzTabContent">
421
+ ${bodyHtml}
422
+ </div>
423
+ </div>
424
+ `;
425
+
426
+ bindHeaderTabs();
427
+ if (activeTab === 'bazaar') {
428
+ bindBazaarTabEvents(quota, cycleCfg, cycleState, summary);
429
+ } else if (activeTab === 'leaderboard') {
430
+ bindLeaderboardTabEvents(cycleId);
431
+ ensureClassLeaderboardLoaded(cycleId, false);
432
+ } else {
433
+ bindMarketTabEvents();
434
+ }
435
+ }
436
+
437
+ function renderBazaarTabHtml(quota, cycleCfg, cycleState, summary) {
438
+ const totalWords = BAZAAR_CONFIG.totalWordsPerCycle || 240;
439
+ const maxQuota = Math.max(0, quota.maxLitQuota || 0);
440
+ const remQuota = Math.max(0, maxQuota - summary.litCount);
441
+ const litPct = Math.min(100, Math.round((summary.litCount / totalWords) * 100));
442
+ const capPct = Math.min(100, Math.round((maxQuota / totalWords) * 100));
443
+
444
+ let ctaLabel = '';
445
+ if (remQuota > 0 && summary.litCount < totalWords) {
446
+ ctaLabel = `🚶 漫步西域大市集(今日尚可點亮 ${remQuota} 格)`;
447
+ } else if (summary.tappableChainWords.length > 0) {
448
+ ctaLabel = `🔨 錯題敲鎖特訓(不佔今日額度・尚有 ${summary.tappableChainWords.length} 字可敲)`;
449
+ } else {
450
+ ctaLabel = '📖 自由複習巡遊(溫故知新・賺金幣砍折扣)';
451
+ }
452
+
453
+ const nextUnlockText = quota.nextUnlockAtMs
454
+ ? `下次 07:00 解鎖(剩 ${formatCountdown(Math.max(0, quota.nextUnlockAtMs - Date.now()))})`
455
+ : '本期 240 單字已全數開通!';
456
+
457
+ const milestonesHtml = (BAZAAR_CONFIG.personalMilestones || []).map((pm) => {
458
+ const claimed = Boolean(cycleState.claimedLines?.[String(pm.lines)]);
459
+ const curProg = Math.min(pm.lines, summary.totalLines);
460
+ return `
461
+ <div class="bz-pm-card ${claimed ? 'is-claimed' : ''}">
462
+ <div class="bz-pm-lines">
463
+ <span>${pm.lines} 線</span>
464
+ <span>${claimed ? '✅' : `${curProg}/${pm.lines}`}</span>
465
+ </div>
466
+ <div class="bz-pm-name">${esc(pm.label)}</div>
467
+ <div class="bz-pm-desc">${esc(pm.desc)}</div>
468
+ </div>
469
+ `;
470
+ }).join('');
471
+
472
+ const scrollPillsHtml = (summary.boards || []).map((board, sIdx) => {
473
+ const litInBoard = board.filter((c) => c.isFree || cycleState.litWords?.[String(c.n)]).length;
474
+ const isNear = Array.isArray(summary.nearBingoScrolls) && summary.nearBingoScrolls.includes(sIdx);
475
+ const linesOn = summary.scrollLines?.[sIdx] || 0;
476
+ return `
477
+ <button type="button" class="bz-scroll-pill ${sIdx === activeScrollIdx ? 'is-active' : ''}" data-scroll-idx="${sIdx}">
478
+ <span>${SCROLL_TITLES[sIdx] || `卷${sIdx + 1}`} ${isNear ? '<span class="bz-near-tag">聽牌</span>' : ''}</span>
479
+ <span style="font-size:11px;color:#94a3b8;">${litInBoard}/25${linesOn > 0 ? ` · ${linesOn}線` : ''}</span>
480
+ </button>
481
+ `;
482
+ }).join('');
483
+
484
+ const curBoard = summary.boards?.[activeScrollIdx] || [];
485
+ const winSet = getWinningCellSet(curBoard, cycleState);
486
+ const cellsHtml = curBoard.map((cell, idx) => {
487
+ const isWin = winSet.has(idx);
488
+ if (cell.isFree) {
489
+ return `
490
+ <button type="button" class="bz-cell is-free ${isWin ? 'is-line-win' : ''}" data-cell-free="1">
491
+ <div class="bz-cell-top"><span>★</span><span>FREE</span></div>
492
+ <div style="font-size:18px;line-height:1;">🐪</div>
493
+ <div class="bz-cell-word">賜福</div>
494
+ </button>
495
+ `;
496
+ }
497
+ const wObj = wordsMap.get(Number(cell.n));
498
+ const isLit = Boolean(cycleState.litWords?.[String(cell.n)]);
499
+ const chain = getWordMistakeChainState(game, cell.n);
500
+ const cls = isLit ? 'is-lit' : (chain.isLockedMistake ? 'is-locked' : 'is-unlit');
501
+ const selectedCls = inspectedWordN === cell.n ? 'is-selected' : '';
502
+ const badge = isLit ? '✨' : (chain.isLockedMistake ? `⛓️ ${chain.progress}/3` : '○');
503
+ return `
504
+ <button type="button" class="bz-cell ${cls} ${isWin ? 'is-line-win' : ''} ${selectedCls}" data-word-n="${cell.n}">
505
+ <div class="bz-cell-top">
506
+ <span>#${String(cell.n).padStart(3, '0')}</span>
507
+ <span>${badge}</span>
508
+ </div>
509
+ <div class="bz-cell-word">${esc(wObj?.word || `#${cell.n}`)}</div>
510
+ <div class="bz-cell-zh">${isLit ? esc(wObj?.zh || '') : (chain.isLockedMistake ? '宿敵鎖鏈' : '點擊聽音')}</div>
511
+ </button>
512
+ `;
513
+ }).join('');
514
+
515
+ const inspectedObj = inspectedWordN ? wordsMap.get(Number(inspectedWordN)) : null;
516
+ const inspectedChain = inspectedWordN ? getWordMistakeChainState(game, inspectedWordN) : null;
517
+ const inspectedLit = inspectedWordN ? Boolean(cycleState.litWords?.[String(inspectedWordN)]) : false;
518
+
519
+ const inspectorHtml = inspectedObj
520
+ ? `
521
+ <div class="bz-word-inspector">
522
+ <div style="min-width:0;flex:1;">
523
+ <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
524
+ <span class="bz-pill bz-pill-gold">#${String(inspectedObj.n).padStart(3, '0')}</span>
525
+ <b style="font-size:18px;color:#ffffff;">${esc(inspectedObj.word)}</b>
526
+ ${inspectedObj.ipa ? `<span style="color:#94a3b8;font-size:13px;">${esc(inspectedObj.ipa)}</span>` : ''}
527
+ ${inspectedObj.pos ? `<span style="color:#5eead4;font-size:12.5px;font-weight:700;">(${esc(inspectedObj.pos)})</span>` : ''}
528
+ <span class="bz-pill ${inspectedLit ? 'bz-pill-teal' : (inspectedChain?.isLockedMistake ? 'bz-pill-crimson' : '')}">
529
+ ${inspectedLit ? '✨ 已點亮' : (inspectedChain?.isLockedMistake ? `⛓️ 鎖鏈 ${inspectedChain.progress}/3` : '未點亮')}
530
+ </span>
531
+ </div>
532
+ <div style="margin-top:4px;font-size:14px;font-weight:700;color:#fde68a;">${esc(inspectedObj.zh)}</div>
533
+ ${inspectedObj.ex ? `<div style="margin-top:3px;font-size:12.5px;color:#cbd5e1;">${esc(inspectedObj.ex)}</div>` : ''}
534
+ </div>
535
+ <button type="button" class="bz-btn-secondary" id="btnInspectorSpeak" data-speak-word="${esc(inspectedObj.word)}">🔊 重播發音</button>
536
+ </div>
537
+ `
538
+ : `
539
+ <div class="bz-word-inspector">
540
+ <div style="font-size:13px;color:#cbd5e1;">💡 點擊上方賓果盤任意單字格,即可朗讀美語發音並預覽單字釋義與鎖鏈狀態!</div>
541
+ </div>
542
+ `;
543
+
544
+ return `
545
+ <div class="bz-hero-panel">
546
+ <div class="bz-card">
547
+ <div class="bz-quota-head">
548
+ <span class="bz-quota-title">📊 今日點亮水位</span>
549
+ <span class="bz-quota-val">已點亮 ${summary.litCount} / 上限 ${maxQuota} 格(共 ${totalWords} 字)</span>
550
+ </div>
551
+ <div class="bz-quota-track">
552
+ <div class="bz-quota-cap" style="width:${capPct}%;"></div>
553
+ <div class="bz-quota-fill" style="width:${litPct}%;"></div>
554
+ </div>
555
+ <div class="bz-quota-meta">
556
+ <span>🕒 ${nextUnlockText}</span>
557
+ <span class="bz-chain-chip ${summary.activeChainWords.length === 0 ? 'is-clear' : ''}">
558
+ ${summary.activeChainWords.length === 0
559
+ ? '🛡️ 目前無宿敵紅鏈錯題'
560
+ : `⛓️ 剩餘錯題鎖鏈:${summary.activeChainWords.length} 字(可敲鎖 ${summary.tappableChainWords.length} 字)`}
561
+ </span>
562
+ </div>
563
+ </div>
564
+
565
+ <div class="bz-card bz-cta-card">
566
+ <div style="font-size:13px;color:#e2e8f0;line-height:1.5;">
567
+ 每次漫步隨機邂逅西域四大奇人,完成 5 題考驗即可點亮賓果、粉碎錯題鏈並砍出黑市折扣!
568
+ </div>
569
+ <button type="button" class="bz-btn-primary" id="btnStartBazaarWalk">
570
+ ${ctaLabel}
571
+ </button>
572
+ </div>
573
+ </div>
574
+
575
+ <div class="bz-card">
576
+ <div class="bz-quota-head" style="margin-bottom:10px;">
577
+ <span class="bz-quota-title">🎁 個人連線里程碑寶箱(${summary.totalLines} / 120 線)</span>
578
+ <span style="font-size:12px;color:#94a3b8;">達標於結算時自動領取入袋</span>
579
+ </div>
580
+ <div class="bz-milestones-strip">
581
+ ${milestonesHtml}
582
+ </div>
583
+ </div>
584
+
585
+ <div class="bz-card">
586
+ <div class="bz-quota-head" style="margin-bottom:10px;">
587
+ <span class="bz-quota-title">📜 十卷 5×5 賓果圖卷(${SCROLL_TITLES[activeScrollIdx] || ''}・本卷已完成 ${summary.scrollLines?.[activeScrollIdx] || 0} / 12 線)</span>
588
+ <span style="font-size:12px;color:#5eead4;">點擊格位聽發音</span>
589
+ </div>
590
+ <div class="bz-scroll-tabs">
591
+ ${scrollPillsHtml}
592
+ </div>
593
+ <div class="bz-bingo-grid" style="margin-top:10px;">
594
+ ${cellsHtml}
595
+ </div>
596
+ ${inspectorHtml}
597
+ </div>
598
+ `;
599
+ }
600
+
601
+ function bindBazaarTabEvents(quota, cycleCfg, cycleState, summary) {
602
+ bind($('#btnStartBazaarWalk', container), 'click', () => {
603
+ startWalkCutscene();
604
+ });
605
+
606
+ $$('[data-scroll-idx]', container).forEach((btn) => {
607
+ bind(btn, 'click', () => {
608
+ const idx = Number(btn.dataset.scrollIdx);
609
+ if (Number.isFinite(idx) && idx >= 0 && idx < 10) {
610
+ activeScrollIdx = idx;
611
+ showLobbyView();
612
+ }
613
+ });
614
+ });
615
+
616
+ $$('[data-word-n]', container).forEach((cellBtn) => {
617
+ bind(cellBtn, 'click', () => {
618
+ const n = Number(cellBtn.dataset.wordN);
619
+ const wObj = wordsMap.get(n);
620
+ if (wObj) safeSpeakWord(wObj.word);
621
+ inspectedWordN = n;
622
+ showLobbyView();
623
+ });
624
+ });
625
+
626
+ $$('[data-cell-free]', container).forEach((freeBtn) => {
627
+ bind(freeBtn, 'click', () => {
628
+ notify('🐪 中央「西域賜福」格永遠自動點亮,助主帥加速連成橫豎斜線!', 'gold', 2400);
629
+ });
630
+ });
631
+
632
+ const speakBtn = $('#btnInspectorSpeak', container);
633
+ if (speakBtn) {
634
+ bind(speakBtn, 'click', () => {
635
+ safeSpeakWord(speakBtn.dataset.speakWord);
636
+ });
637
+ }
638
+ }
639
+
640
+ // --------------------------------------------------------------------------
641
+ // 視圖 1B:本班連線英雄榜(13 道首破牆 + 同學排行,20 秒快取)
642
+ // --------------------------------------------------------------------------
643
+ async function ensureClassLeaderboardLoaded(cycleId, forceRefresh = false) {
644
+ const nowMs = Date.now();
645
+ if (!forceRefresh && cachedClassDoc && (nowMs - cachedClassAt) < 20000) {
646
+ return;
647
+ }
648
+ const db = bazaarCtx?.db;
649
+ const classCode = student?.classCode;
650
+ if (!db || typeof db.getClass !== 'function' || !classCode) {
651
+ cachedClassDoc = getClassInfo() || {};
652
+ cachedClassAt = nowMs;
653
+ return;
654
+ }
655
+
656
+ leaderboardLoading = true;
657
+ leaderboardErr = null;
658
+ if (activeTab === 'leaderboard') renderLeaderboardBodyOnly(cycleId);
659
+
660
+ try {
661
+ const clsDoc = await db.getClass(classCode);
662
+ cachedClassDoc = clsDoc || getClassInfo() || {};
663
+ cachedClassAt = Date.now();
664
+ } catch (err) {
665
+ leaderboardErr = err?.message || '讀取班級榜單失敗';
666
+ cachedClassDoc = cachedClassDoc || getClassInfo() || {};
667
+ } finally {
668
+ leaderboardLoading = false;
669
+ if (!isClosed && activeTab === 'leaderboard') {
670
+ renderLeaderboardBodyOnly(cycleId);
671
+ }
672
+ }
673
+ }
674
+
675
+ function renderLeaderboardTabHtml(cycleCfg, cycleId) {
676
+ const sourceCls = cachedClassDoc || getClassInfo() || {};
677
+ const cycleData = sourceCls?.bazaarCycles?.[cycleId] || {};
678
+ const firstMilestones = (cycleData.firstMilestones && typeof cycleData.firstMilestones === 'object')
679
+ ? cycleData.firstMilestones
680
+ : {};
681
+ const entriesObj = (cycleData.entries && typeof cycleData.entries === 'object')
682
+ ? cycleData.entries
683
+ : {};
684
+
685
+ const firstBloodWallHtml = (BAZAAR_CONFIG.firstBloodLines || []).map((lineGoal) => {
686
+ const winner = firstMilestones[String(lineGoal)];
687
+ if (winner) {
688
+ const isMe = winner.uid === uid;
689
+ return `
690
+ <div class="bz-fb-banner is-claimed">
691
+ <div style="display:flex;justify-content:space-between;align-items:center;gap:4px;">
692
+ <b style="color:#fde68a;">🏆 ${lineGoal} 線首破</b>
693
+ <span style="font-size:11px;color:#5eead4;">✅ 已賞</span>
694
+ </div>
695
+ <div style="font-weight:800;color:#ffffff;">
696
+ ${winner.seat ? `${esc(winner.seat)}號 ` : ''}${esc(winner.name || '無名小將')} ${isMe ? '⭐' : ''}
697
+ </div>
698
+ <div style="font-size:11px;color:#94a3b8;">${fmtDateTime(winner.at)}</div>
699
+ </div>
700
+ `;
701
+ }
702
+ return `
703
+ <div class="bz-fb-banner is-open">
704
+ <div style="display:flex;justify-content:space-between;align-items:center;gap:4px;">
705
+ <b style="color:#fecaca;">🏆 ${lineGoal} 線首破</b>
706
+ </div>
707
+ <div><span class="bz-fb-pulse">🔥 首破賞 1 兵符</span></div>
708
+ <div style="font-size:11px;color:#94a3b8;">尚無人搶下,速速衝線!</div>
709
+ </div>
710
+ `;
711
+ }).join('');
712
+
713
+ const sortedEntries = Object.values(entriesObj)
714
+ .filter((e) => e && typeof e === 'object')
715
+ .sort((a, b) => {
716
+ const diffLines = (Number(b.lines) || 0) - (Number(a.lines) || 0);
717
+ if (diffLines !== 0) return diffLines;
718
+ const diffLit = (Number(b.litCount) || 0) - (Number(a.litCount) || 0);
719
+ if (diffLit !== 0) return diffLit;
720
+ const diffCleared = (Number(b.clearedMistakes) || 0) - (Number(a.clearedMistakes) || 0);
721
+ if (diffCleared !== 0) return diffCleared;
722
+ return (Number(a.updatedAt) || 0) - (Number(b.updatedAt) || 0);
723
+ });
724
+
725
+ let rankingRowsHtml = '';
726
+ if (sortedEntries.length === 0) {
727
+ rankingRowsHtml = `
728
+ <tr>
729
+ <td colspan="5" style="text-align:center;padding:24px;color:#cbd5e1;white-space:normal;">
730
+ 🌟 英雄榜虛位以待!快點擊「漫步西域大市集」點亮第一批單字、搶下全班首破大將金兵符吧!
731
+ </td>
732
+ </tr>
733
+ `;
734
+ } else {
735
+ rankingRowsHtml = sortedEntries.map((entry, idx) => {
736
+ const rankBadge = idx === 0 ? '🥇' : (idx === 1 ? '🥈' : (idx === 2 ? '🥉' : `#${idx + 1}`));
737
+ const isMe = entry.uid === uid;
738
+ const titleHtml = entry.title ? ` ${formatTitleBadge(entry.title, { size: 'sm' })}` : '';
739
+ return `
740
+ <tr class="${isMe ? 'is-me' : ''}">
741
+ <td style="font-weight:900;">${rankBadge}</td>
742
+ <td>
743
+ <span style="font-weight:800;color:#ffffff;">${entry.seat ? `${esc(entry.seat)}號 ` : ''}${esc(entry.name || '將士')}${isMe ? '(你)' : ''}</span>
744
+ ${titleHtml}
745
+ </td>
746
+ <td style="font-weight:900;color:#fbbf24;">${Number(entry.lines) || 0} 線</td>
747
+ <td style="color:#5eead4;font-weight:800;">${Number(entry.litCount) || 0} / 240</td>
748
+ <td style="color:#fca5a5;font-weight:700;">${Number(entry.clearedMistakes) || 0} 字</td>
749
+ </tr>
750
+ `;
751
+ }).join('');
752
+ }
753
+
754
+ return `
755
+ <div class="bz-card">
756
+ <div class="bz-quota-head" style="margin-bottom:10px;">
757
+ <div>
758
+ <span class="bz-quota-title">🏆 全班 13 階連線首破賞金牆</span>
759
+ <div style="font-size:12px;color:#94a3b8;margin-top:2px;">各里程碑僅全班第 1 位達標之同學可奪得大將金兵符 ×1(教師與 20 號測試帳不計入競榜)</div>
760
+ </div>
761
+ <button type="button" class="bz-btn-ghost" id="btnRefreshBazaarBoard" ${leaderboardLoading ? 'disabled' : ''}>
762
+ ${leaderboardLoading ? '⏳ 刷新中…' : '🔄 重新整理'}
763
+ </button>
764
+ </div>
765
+ ${leaderboardErr ? `<div style="margin-bottom:8px;font-size:12.5px;color:#fca5a5;">⚠️ ${esc(leaderboardErr)}(目前顯示本機快取資料)</div>` : ''}
766
+ <div class="bz-board-wall">
767
+ ${firstBloodWallHtml}
768
+ </div>
769
+ </div>
770
+
771
+ <div class="bz-card">
772
+ <div class="bz-quota-head" style="margin-bottom:10px;">
773
+ <span class="bz-quota-title">📜 ${esc(cycleCfg?.title || '當期')}・同袍連線龍虎榜</span>
774
+ <span style="font-size:12px;color:#94a3b8;">共 ${sortedEntries.length} 位將士登榜</span>
775
+ </div>
776
+ <div class="bz-table-wrap">
777
+ <table class="bz-rank-table">
778
+ <thead>
779
+ <tr>
780
+ <th>名次</th>
781
+ <th>主帥 / 稱號</th>
782
+ <th>賓果連線</th>
783
+ <th>點亮單字</th>
784
+ <th>破除紅鏈</th>
785
+ </tr>
786
+ </thead>
787
+ <tbody>
788
+ ${rankingRowsHtml}
789
+ </tbody>
790
+ </table>
791
+ </div>
792
+ </div>
793
+ `;
794
+ }
795
+
796
+ function renderLeaderboardBodyOnly(cycleId) {
797
+ const contentEl = $('#bzTabContent', container);
798
+ if (!contentEl) return;
799
+ const quota = getBazaarQuotaInfo(getClassInfo(), new Date());
800
+ const cycleCfg = quota.modeState.cycleConfig || modeState.cycleConfig;
801
+ contentEl.innerHTML = renderLeaderboardTabHtml(cycleCfg, cycleId);
802
+ bindLeaderboardTabEvents(cycleId);
803
+ }
804
+
805
+ function bindLeaderboardTabEvents(cycleId) {
806
+ const refreshBtn = $('#btnRefreshBazaarBoard', container);
807
+ if (refreshBtn) {
808
+ bind(refreshBtn, 'click', () => {
809
+ ensureClassLeaderboardLoaded(cycleId, true);
810
+ });
811
+ }
812
+ }
813
+
814
+ // --------------------------------------------------------------------------
815
+ // 視圖 1C:西域黑市攤位(嵌合 renderMerchantMarketPanel)
816
+ // --------------------------------------------------------------------------
817
+ function renderMarketTabHtml() {
818
+ const mStatus = getMerchantStatus(game);
819
+ if (!mStatus.marketUnlocked) {
820
+ return `
821
+ <div class="bz-card" style="text-align:center;padding:28px 20px;display:flex;flex-direction:column;align-items:center;gap:14px;">
822
+ <div style="font-size:46px;line-height:1;">🏺</div>
823
+ <h3 style="margin:0;font-size:20px;font-weight:900;color:#fde68a;">今日西域黑市攤位尚未揭幕</h3>
824
+ <div style="max-width:480px;font-size:13.5px;color:#cbd5e1;line-height:1.6;">
825
+ 先漫步西域大市集完成 1 場奇遇挑戰(5 題全對立享 <b>2 折極限底價</b>,依答對題數享 2~9 折),即可立刻解鎖今日 20 項胡商奇珍異寶!
826
+ </div>
827
+ <button type="button" class="bz-btn-primary" id="btnUnlockMarketViaWalk" style="max-width:320px;">
828
+ 🚶 立即漫步奇遇並議價解鎖
829
+ </button>
830
+ </div>
831
+ `;
832
+ }
833
+ return `<div id="bzMarketHost" class="bz-market-host"></div>`;
834
+ }
835
+
836
+ function bindMarketTabEvents() {
837
+ const unlockBtn = $('#btnUnlockMarketViaWalk', container);
838
+ if (unlockBtn) {
839
+ bind(unlockBtn, 'click', () => {
840
+ startWalkCutscene();
841
+ });
842
+ return;
843
+ }
844
+ const hostEl = $('#bzMarketHost', container);
845
+ if (hostEl) {
846
+ renderMerchantMarketPanel(hostEl, {
847
+ game,
848
+ getDState,
849
+ showCaravanBar: true,
850
+ onAfterBuy: async () => {
851
+ await saveGame();
852
+ refreshUI();
853
+ updateHeaderPills();
854
+ },
855
+ });
856
+ }
857
+ }
858
+
859
+ // --------------------------------------------------------------------------
860
+ // 視圖 2:漫步西域街道驚嘆號過場演出
861
+ // --------------------------------------------------------------------------
862
+ function startWalkCutscene() {
863
+ clearTimers();
864
+ let session = null;
865
+ try {
866
+ session = generateBazaarEncounter(
867
+ game,
868
+ words,
869
+ uid,
870
+ getClassInfo(),
871
+ opts.now || new Date(),
872
+ { progress: getProgress() }
873
+ );
874
+ } catch (err) {
875
+ notify(err?.message || '暫時無法開啟市集奇遇,請稍候重試!', 'error', 3500);
876
+ showLobbyView();
877
+ return;
878
+ }
879
+
880
+ const npc = getNpcMeta(session.npcId);
881
+ const cycleCfg = getBazaarQuotaInfo(getClassInfo(), new Date()).modeState.cycleConfig || modeState.cycleConfig;
882
+ const summary = computeBazaarSummary(game, uid, session.cycleId);
883
+ const walkerImg = `assets/camel_caravan.png?v=20261123_v2`;
884
+
885
+ container.innerHTML = `
886
+ <div class="bz-shell">
887
+ ${getHeaderHtml(cycleCfg, summary, false)}
888
+ <div class="bz-content">
889
+ <div class="bz-walk-stage">
890
+ <span class="bz-lantern-glow" style="left:16%;top:26%;animation-delay:0s;"></span>
891
+ <span class="bz-lantern-glow" style="left:48%;top:18%;animation-delay:0.7s;"></span>
892
+ <span class="bz-lantern-glow" style="left:78%;top:28%;animation-delay:1.3s;"></span>
893
+
894
+ <button type="button" class="bz-walk-skip-btn" id="btnSkipBazaarWalk">⚡ 略過動畫</button>
895
+
896
+ <div class="bz-walk-actor">
897
+ <div class="bz-exclaim-burst" id="bzWalkExclaim">❗</div>
898
+ <img src="${walkerImg}" alt="漫步商隊">
899
+ </div>
900
+
901
+ <div class="bz-walk-caption" id="bzWalkCaption">🐪 主帥一行人漫步熱鬧的西域萬國大市集,駝鈴清脆響起……</div>
902
+ <div class="bz-walk-flash" id="bzWalkFlash"></div>
903
+ </div>
904
+ </div>
905
+ </div>
906
+ `;
907
+
908
+ let transitioned = false;
909
+ const goBattle = () => {
910
+ if (transitioned || isClosed) return;
911
+ transitioned = true;
912
+ clearTimers();
913
+ startNpcEncounter(session);
914
+ };
915
+
916
+ bind($('#btnSkipBazaarWalk', container), 'click', goBattle);
917
+
918
+ walkTimer = setTimeout(() => {
919
+ if (isClosed || transitioned) return;
920
+ const exclaimEl = $('#bzWalkExclaim', container);
921
+ const captionEl = $('#bzWalkCaption', container);
922
+ const flashEl = $('#bzWalkFlash', container);
923
+ if (exclaimEl) exclaimEl.classList.add('is-show');
924
+ if (captionEl) captionEl.textContent = `❗ 前方金帳之中,竟然遇見了【${npc.name}】!`;
925
+ playBazaarSfx('exclaim');
926
+
927
+ walkDoneTimer = setTimeout(() => {
928
+ if (flashEl) flashEl.classList.add('is-active');
929
+ scheduleTimeout(goBattle, 260);
930
+ }, 620);
931
+ }, 1050);
932
+ }
933
+
934
+ // --------------------------------------------------------------------------
935
+ // 視圖 3:四大角色專屬對決舞台
936
+ // --------------------------------------------------------------------------
937
+ function startNpcEncounter(session) {
938
+ clearTimers();
939
+ const npc = getNpcMeta(session.npcId);
940
+ const cycleCfg = getBazaarQuotaInfo(getClassInfo(), new Date()).modeState.cycleConfig || modeState.cycleConfig;
941
+
942
+ if (session.npcId === 'weaver' && session.pairBoard) {
943
+ startWeaverPairBattle(session, npc, cycleCfg);
944
+ return;
945
+ }
946
+
947
+ let curIdx = 0;
948
+ let isMuteMode = false;
949
+ let isLocked = false;
950
+ let scramblePicked = [];
951
+ let npcSpeech = getNpcOpeningLine(session.npcId, session.mode);
952
+
953
+ function renderQuestionStage() {
954
+ if (isClosed) return;
955
+ if (curIdx >= session.items.length) {
956
+ enterSettlement(session);
957
+ return;
958
+ }
959
+
960
+ const item = session.items[curIdx];
961
+ const wObj = item.wordObj || {};
962
+ const summary = computeBazaarSummary(game, uid, session.cycleId);
963
+ const chainState = getWordMistakeChainState(game, item.n);
964
+
965
+ let itemTag = '';
966
+ if (item.isFiller) {
967
+ itemTag = '<span class="bz-pill">📖 溫故複習題</span>';
968
+ } else if (chainState.isLockedMistake) {
969
+ itemTag = `<span class="bz-pill bz-pill-crimson">${chainState.progress === 2 ? '🔥 宿敵鎖鏈 2/3・終極破鎖!' : `⛓️ 宿敵鎖鏈 ${chainState.progress}/3`}</span>`;
970
+ } else if (item.canLightToday) {
971
+ itemTag = '<span class="bz-pill bz-pill-teal">✨ 答對立即點亮賓果格</span>';
972
+ } else {
973
+ itemTag = '<span class="bz-pill">📜 單字實戰</span>';
974
+ }
975
+
976
+ let mainHtml = '';
977
+ if (item.questionMode === 'mc_zh') {
978
+ mainHtml = `
979
+ <div class="bz-word-banner">
980
+ <div style="display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;">
981
+ <div>
982
+ <span class="bz-word-en-lg">${esc(wObj.word)}</span>
983
+ ${wObj.ipa ? `<span style="margin-left:8px;color:#94a3b8;font-size:14px;">${esc(wObj.ipa)}</span>` : ''}
984
+ ${wObj.pos ? `<span style="margin-left:6px;color:#5eead4;font-size:13px;font-weight:800;">(${esc(wObj.pos)})</span>` : ''}
985
+ </div>
986
+ <button type="button" class="bz-btn-secondary" id="btnBzSpeakCur">🔊 聽發音</button>
987
+ </div>
988
+ ${wObj.ex ? `
989
+ <div style="font-size:13px;color:#e2e8f0;line-height:1.5;border-top:1px dashed rgba(148,163,184,0.28);padding-top:8px;">
990
+ <div>${esc(wObj.ex)}</div>
991
+ ${item.maskedEx ? `<div style="color:#fde68a;margin-top:3px;">${renderMaskedClozeHtml(item.maskedEx)}</div>` : ''}
992
+ </div>
993
+ ` : ''}
994
+ </div>
995
+ <div style="font-size:14.5px;font-weight:800;color:#fef3c7;">📜 請選出這個單字最精準的中文釋義:</div>
996
+ <div class="bz-options-grid">
997
+ ${(item.options || []).map((opt, oIdx) => `
998
+ <button type="button" class="bz-opt-btn" data-opt-idx="${oIdx}">
999
+ <span class="bz-opt-tag">${OPTION_LABELS[oIdx] || oIdx + 1}</span>
1000
+ <span>${esc(opt)}</span>
1001
+ </button>
1002
+ `).join('')}
1003
+ </div>
1004
+ `;
1005
+ if (!item.answered) safeSpeakWord(wObj.word);
1006
+ } else if (item.questionMode === 'audio_mc') {
1007
+ const activeOpts = isMuteMode ? (item.muteOptions || []) : (item.options || []);
1008
+ mainHtml = `
1009
+ <div class="bz-word-banner" style="align-items:center;text-align:center;">
1010
+ ${isMuteMode ? `
1011
+ <div style="font-size:12.5px;color:#e9d5ff;font-weight:800;">🔇 目前為無聲模式(看中文選英文)</div>
1012
+ <div style="font-size:24px;font-weight:900;color:#fef3c7;">${esc(item.mutePromptText || wObj.zh)}</div>
1013
+ ${wObj.pos ? `<div style="font-size:13px;color:#5eead4;font-weight:700;">(${esc(wObj.pos)})</div>` : ''}
1014
+ ${item.mutePromptSub ? `<div style="font-size:13px;color:#cbd5e1;">${esc(item.mutePromptSub)}</div>` : ''}
1015
+ ` : `
1016
+ <div style="font-size:14px;font-weight:800;color:#e9d5ff;">${esc(item.promptText)}</div>
1017
+ <button type="button" class="bz-pipa-btn" id="btnPipaPlay">
1018
+ 🎻 撥弦聆聽琵琶美語發音 ${wObj.pos ? `(${esc(wObj.pos)})` : ''}
1019
+ </button>
1020
+ <div style="font-size:12px;color:#94a3b8;">請仔細聆聽發音,選出正確對應的英文單字與釋義</div>
1021
+ `}
1022
+ </div>
1023
+ <div class="bz-options-grid">
1024
+ ${activeOpts.map((opt, oIdx) => `
1025
+ <button type="button" class="bz-opt-btn" data-opt-idx="${oIdx}">
1026
+ <span class="bz-opt-tag">${OPTION_LABELS[oIdx] || oIdx + 1}</span>
1027
+ <span>${esc(opt)}</span>
1028
+ </button>
1029
+ `).join('')}
1030
+ </div>
1031
+ `;
1032
+ if (!isMuteMode && !item.answered) safeSpeakWord(wObj.word);
1033
+ } else if (item.questionMode === 'scramble_en') {
1034
+ const tiles = Array.isArray(item.scrambleTiles) && item.scrambleTiles.length
1035
+ ? item.scrambleTiles
1036
+ : String(wObj.word || '').split('');
1037
+ const usedTileSet = new Set(scramblePicked);
1038
+ const slotsHtml = tiles.map((_, sIdx) => {
1039
+ const tIdx = scramblePicked[sIdx];
1040
+ const ch = tIdx !== undefined ? tiles[tIdx] : '';
1041
+ return `<button type="button" class="bz-slot-btn ${ch ? 'is-filled' : ''}" data-slot-idx="${sIdx}" ${ch ? '' : 'disabled'}>${ch ? esc(ch) : '_'}</button>`;
1042
+ }).join('');
1043
+ const gemsHtml = tiles.map((ch, tIdx) => `
1044
+ <button type="button" class="bz-gem-btn" data-gem-idx="${tIdx}" ${usedTileSet.has(tIdx) ? 'disabled' : ''}>${esc(ch)}</button>
1045
+ `).join('');
1046
+
1047
+ mainHtml = `
1048
+ <div class="bz-parchment-box">
1049
+ <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;margin-bottom:6px;">
1050
+ <span class="bz-pill bz-pill-crimson">💥 2/3 鎖鏈終極破鎖試煉</span>
1051
+ <button type="button" class="bz-btn-ghost" id="btnScrambleSpeak" style="min-height:44px;">🔊 聽音提示</button>
1052
+ </div>
1053
+ <div style="font-size:16px;font-weight:900;color:#fde68a;">
1054
+ ${esc(item.promptText)} ${item.promptSub ? `<span style="color:#5eead4;font-size:13.5px;">${esc(item.promptSub)}</span>` : ''}
1055
+ </div>
1056
+ ${item.maskedEx ? `<div style="margin-top:6px;font-size:13.5px;color:#e2e8f0;">${renderMaskedClozeHtml(item.maskedEx)}</div>` : ''}
1057
+ </div>
1058
+
1059
+ <div class="bz-scramble-slots" id="bzScrambleSlots">${slotsHtml}</div>
1060
+ <div class="bz-scramble-gems" id="bzScrambleGems">${gemsHtml}</div>
1061
+
1062
+ <div style="display:flex;gap:8px;flex-wrap:wrap;justify-content:center;">
1063
+ <button type="button" class="bz-btn-ghost" id="btnScrambleBack" ${scramblePicked.length === 0 || item.answered ? 'disabled' : ''}>⌫ 退一格</button>
1064
+ <button type="button" class="bz-btn-ghost" id="btnScrambleClear" ${scramblePicked.length === 0 || item.answered ? 'disabled' : ''}>🔄 重排清空</button>
1065
+ <button type="button" class="bz-btn-primary" id="btnScrambleSubmit" style="flex:1;min-width:190px;" ${scramblePicked.length < tiles.length || item.answered ? 'disabled' : ''}>
1066
+ ✨ 確認破鎖送出 (${scramblePicked.length}/${tiles.length})
1067
+ </button>
1068
+ </div>
1069
+ `;
1070
+ } else {
1071
+ // scholar cloze_en
1072
+ mainHtml = `
1073
+ <div class="bz-parchment-box">
1074
+ <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:6px;">
1075
+ <span style="font-size:12.5px;color:#fde68a;font-weight:800;">📜 星象古卷殘篇</span>
1076
+ ${wObj.pos ? `<span style="font-size:12px;color:#5eead4;">詞性:${esc(wObj.pos)}</span>` : ''}
1077
+ </div>
1078
+ <div>${renderMaskedClozeHtml(item.promptText)}</div>
1079
+ ${item.promptSub ? `<div style="margin-top:8px;font-size:13px;color:#cbd5e1;border-top:1px dashed rgba(245,158,11,0.3);padding-top:6px;">💡 中文線索:${esc(item.promptSub)}</div>` : ''}
1080
+ </div>
1081
+ <div class="bz-options-grid">
1082
+ ${(item.options || []).map((opt, oIdx) => `
1083
+ <button type="button" class="bz-opt-btn" data-opt-idx="${oIdx}">
1084
+ <span class="bz-opt-tag">${OPTION_LABELS[oIdx] || oIdx + 1}</span>
1085
+ <span>${esc(opt)}</span>
1086
+ </button>
1087
+ `).join('')}
1088
+ </div>
1089
+ `;
1090
+ }
1091
+
1092
+ const portraitSrc = `${npc.img}?v=20261123_v2`;
1093
+
1094
+ container.innerHTML = `
1095
+ <div class="bz-shell">
1096
+ ${getHeaderHtml(cycleCfg, summary, false)}
1097
+ <div class="bz-content">
1098
+ <div class="bz-arena">
1099
+ <aside class="bz-npc-panel">
1100
+ <div class="bz-npc-portrait">
1101
+ <img src="${portraitSrc}" alt="${esc(npc.name)}">
1102
+ </div>
1103
+ <div class="bz-npc-name">${esc(npc.name)}</div>
1104
+ <div class="bz-npc-role">${esc(npc.roleTitle)}</div>
1105
+ <div class="bz-npc-bubble" id="bzNpcBubble">「${esc(npcSpeech)}」</div>
1106
+ </aside>
1107
+
1108
+ <section class="bz-battle-panel">
1109
+ <div class="bz-battle-top">
1110
+ <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
1111
+ <span class="bz-pill bz-pill-gold">第 ${curIdx + 1} / ${session.items.length} 題</span>
1112
+ ${itemTag}
1113
+ </div>
1114
+ ${item.questionMode === 'audio_mc' ? `
1115
+ <button type="button" class="bz-mute-toggle-btn" id="btnToggleLutistMute">
1116
+ ${isMuteMode ? '🔊 切回語音模式' : '🔇 無聲切換:看中文選英文'}
1117
+ </button>
1118
+ ` : ''}
1119
+ </div>
1120
+
1121
+ ${mainHtml}
1122
+
1123
+ <div id="bzArenaFeedback" class="hidden"></div>
1124
+ </section>
1125
+ </div>
1126
+ </div>
1127
+ </div>
1128
+ `;
1129
+
1130
+ bindBattleEvents(item, wObj);
1131
+ }
1132
+
1133
+ function bindBattleEvents(item, wObj) {
1134
+ const btnSpeakCur = $('#btnBzSpeakCur', container);
1135
+ if (btnSpeakCur) bind(btnSpeakCur, 'click', () => safeSpeakWord(wObj.word));
1136
+
1137
+ const btnPipa = $('#btnPipaPlay', container);
1138
+ if (btnPipa) bind(btnPipa, 'click', () => safeSpeakWord(wObj.word));
1139
+
1140
+ const btnMute = $('#btnToggleLutistMute', container);
1141
+ if (btnMute) {
1142
+ bind(btnMute, 'click', () => {
1143
+ if (isLocked || item.answered) return;
1144
+ isMuteMode = !isMuteMode;
1145
+ cancelSpeech();
1146
+ renderQuestionStage();
1147
+ });
1148
+ }
1149
+
1150
+ if (item.questionMode === 'scramble_en') {
1151
+ const tiles = Array.isArray(item.scrambleTiles) && item.scrambleTiles.length
1152
+ ? item.scrambleTiles
1153
+ : String(wObj.word || '').split('');
1154
+
1155
+ const btnScrambleSpeak = $('#btnScrambleSpeak', container);
1156
+ if (btnScrambleSpeak) bind(btnScrambleSpeak, 'click', () => safeSpeakWord(wObj.word));
1157
+
1158
+ $$('[data-gem-idx]', container).forEach((gemBtn) => {
1159
+ bind(gemBtn, 'click', () => {
1160
+ if (isLocked || item.answered) return;
1161
+ const gIdx = Number(gemBtn.dataset.gemIdx);
1162
+ if (!Number.isFinite(gIdx) || scramblePicked.includes(gIdx)) return;
1163
+ scramblePicked.push(gIdx);
1164
+ renderQuestionStage();
1165
+ });
1166
+ });
1167
+
1168
+ $$('[data-slot-idx]', container).forEach((slotBtn) => {
1169
+ bind(slotBtn, 'click', () => {
1170
+ if (isLocked || item.answered) return;
1171
+ const sIdx = Number(slotBtn.dataset.slotIdx);
1172
+ if (!Number.isFinite(sIdx) || sIdx < 0 || sIdx >= scramblePicked.length) return;
1173
+ scramblePicked.splice(sIdx, 1);
1174
+ renderQuestionStage();
1175
+ });
1176
+ });
1177
+
1178
+ bind($('#btnScrambleBack', container), 'click', () => {
1179
+ if (isLocked || item.answered || scramblePicked.length === 0) return;
1180
+ scramblePicked.pop();
1181
+ renderQuestionStage();
1182
+ });
1183
+
1184
+ bind($('#btnScrambleClear', container), 'click', () => {
1185
+ if (isLocked || item.answered || scramblePicked.length === 0) return;
1186
+ scramblePicked = [];
1187
+ renderQuestionStage();
1188
+ });
1189
+
1190
+ bind($('#btnScrambleSubmit', container), 'click', () => {
1191
+ if (isLocked || item.answered || scramblePicked.length < tiles.length) return;
1192
+ const assembled = scramblePicked.map((idx) => tiles[idx]).join('');
1193
+ const isCorrect = assembled.trim().toLowerCase() === String(wObj.word || '').trim().toLowerCase();
1194
+ finalizeAnswer(item, wObj, isCorrect, assembled, -1);
1195
+ });
1196
+ return;
1197
+ }
1198
+
1199
+ $$('[data-opt-idx]', container).forEach((optBtn) => {
1200
+ bind(optBtn, 'click', () => {
1201
+ if (isLocked || item.answered) return;
1202
+ const chosenIdx = Number(optBtn.dataset.optIdx);
1203
+ const targetIdx = (item.questionMode === 'audio_mc' && isMuteMode)
1204
+ ? (item.muteAnswerIndex ?? item.answerIndex)
1205
+ : item.answerIndex;
1206
+ const activeList = (item.questionMode === 'audio_mc' && isMuteMode)
1207
+ ? (item.muteOptions || [])
1208
+ : (item.options || []);
1209
+ const isCorrect = chosenIdx === targetIdx;
1210
+ finalizeAnswer(item, wObj, isCorrect, activeList[chosenIdx] || '', chosenIdx, targetIdx);
1211
+ });
1212
+ });
1213
+ }
1214
+
1215
+ function finalizeAnswer(item, wObj, isCorrect, chosenText, chosenIdx = -1, targetIdx = item.answerIndex) {
1216
+ isLocked = true;
1217
+ const outcome = recordBazaarItemOutcome(game, session, curIdx, isCorrect, chosenText);
1218
+ updateHeaderPills();
1219
+ saveGame();
1220
+
1221
+ const optBtns = $$('[data-opt-idx]', container);
1222
+ optBtns.forEach((btn) => {
1223
+ btn.disabled = true;
1224
+ const idx = Number(btn.dataset.optIdx);
1225
+ if (idx === targetIdx) btn.classList.add('is-correct');
1226
+ else if (idx === chosenIdx && !isCorrect) btn.classList.add('is-wrong');
1227
+ });
1228
+
1229
+ if (outcome?.chainShattered) {
1230
+ playBazaarSfx('shatter');
1231
+ } else {
1232
+ playBazaarSfx(isCorrect ? 'correct' : 'wrong');
1233
+ }
1234
+
1235
+ npcSpeech = isCorrect
1236
+ ? (outcome?.chainShattered
1237
+ ? `好一記星辰破鎖!【${wObj.word}】的宿敵紅鏈徹底碎裂了!`
1238
+ : `好身手!${wObj.word} 正是「${wObj.zh}」!`)
1239
+ : `可惜了,【${wObj.word}】其實是「${wObj.zh}」,先記進錯題本磨練吧!`;
1240
+
1241
+ const bubbleEl = $('#bzNpcBubble', container);
1242
+ if (bubbleEl) bubbleEl.textContent = `「${npcSpeech}」`;
1243
+
1244
+ const fbEl = $('#bzArenaFeedback', container);
1245
+ if (fbEl) {
1246
+ fbEl.classList.remove('hidden');
1247
+ let msg = '';
1248
+ if (outcome?.chainShattered) {
1249
+ msg = `💥 宿敵紅鏈爆裂淨化!【${esc(wObj.word)}】${outcome.newlyLit ? '已同步點亮賓果格!' : '鎖鏈全解!'}`;
1250
+ } else if (outcome?.newlyLit) {
1251
+ msg = `✨ 答對並點亮賓果格【${esc(wObj.word)} — ${esc(wObj.zh)}】!`;
1252
+ } else if (outcome?.chainCracked) {
1253
+ msg = `🔨 敲裂鎖鏈 ${outcome.chainBefore}/3 → ${outcome.chainAfter}/3!獲贈 +${fmt(outcome.grainBonus)} 糧草!`;
1254
+ } else if (isCorrect) {
1255
+ msg = `✓ 答對!【${esc(wObj.word)} — ${esc(wObj.zh)}】`;
1256
+ } else {
1257
+ msg = `⛓️ 答錯!正解為【${esc(wObj.word)} — ${esc(wObj.zh)}】`;
1258
+ }
1259
+
1260
+ const shatterBanner = outcome?.chainShattered
1261
+ ? `<div class="bz-shatter-burst">💥 鎖鏈爆裂!星盤認證【${esc(wObj.word)}】徹底克服!</div>`
1262
+ : '';
1263
+
1264
+ fbEl.innerHTML = `
1265
+ ${shatterBanner}
1266
+ <div class="bz-feedback-bar ${isCorrect ? 'is-ok' : 'is-bad'}" style="margin-top:${shatterBanner ? '8px' : '0'};">
1267
+ <span>${msg}</span>
1268
+ <button type="button" class="bz-btn-primary" id="btnBzNextQuestion" style="width:auto;min-height:44px;padding:8px 16px;">
1269
+ ${curIdx + 1 >= session.items.length ? '前往結算 ➔' : '下一題 ➔'}
1270
+ </button>
1271
+ </div>
1272
+ `;
1273
+
1274
+ let advanced = false;
1275
+ const goNext = () => {
1276
+ if (advanced || isClosed) return;
1277
+ advanced = true;
1278
+ isLocked = false;
1279
+ scramblePicked = [];
1280
+ curIdx += 1;
1281
+ renderQuestionStage();
1282
+ };
1283
+
1284
+ bind($('#btnBzNextQuestion', container), 'click', goNext);
1285
+ scheduleTimeout(goNext, isCorrect ? 1050 : 1650);
1286
+ }
1287
+ }
1288
+
1289
+ renderQuestionStage();
1290
+ }
1291
+
1292
+ // --------------------------------------------------------------------------
1293
+ // 織毯娘子・莎赫拉專屬:左 5 英卡 × 右 5 中卡點擊配對消除
1294
+ // --------------------------------------------------------------------------
1295
+ function startWeaverPairBattle(session, npc, cycleCfg) {
1296
+ const leftCards = session.pairBoard.leftCards || [];
1297
+ const rightCards = session.pairBoard.rightCards || [];
1298
+ const matchedSet = new Set();
1299
+ const firstAttemptFailedSet = new Set();
1300
+ let selectedLeft = null;
1301
+ let selectedRight = null;
1302
+ let wrongFlash = null;
1303
+ let isAnimating = false;
1304
+ let weaverSpeech = '來看看我的波斯錦毯吧!點選左邊英文單字聽發音,再配對右邊正確的中文釋義!';
1305
+
1306
+ function renderWeaverBoard() {
1307
+ if (isClosed) return;
1308
+ const summary = computeBazaarSummary(game, uid, session.cycleId);
1309
+ const portraitSrc = `${npc.img}?v=20261123_v2`;
1310
+
1311
+ const leftHtml = leftCards.map((card) => {
1312
+ const isMatched = matchedSet.has(card.itemIndex);
1313
+ const isSelected = selectedLeft === card.itemIndex;
1314
+ const isWrong = wrongFlash && wrongFlash.leftIdx === card.itemIndex;
1315
+ return `
1316
+ <button type="button" class="bz-pair-card ${isMatched ? 'is-matched' : ''} ${isSelected ? 'is-selected' : ''} ${isWrong ? 'is-wrong-shake' : ''}" data-pair-left="${card.itemIndex}" ${isMatched ? 'disabled' : ''}>
1317
+ <span style="min-width:0;">
1318
+ <div style="font-size:15px;font-weight:900;">${esc(card.word)}</div>
1319
+ <div style="font-size:11px;color:#94a3b8;">${esc(card.pos)} ${esc(card.ipa)}</div>
1320
+ </span>
1321
+ <span style="font-size:15px;">${isMatched ? '✅' : '🔊'}</span>
1322
+ </button>
1323
+ `;
1324
+ }).join('');
1325
+
1326
+ const rightHtml = rightCards.map((card) => {
1327
+ const isMatched = matchedSet.has(card.itemIndex);
1328
+ const isSelected = selectedRight === card.itemIndex;
1329
+ const isWrong = wrongFlash && wrongFlash.rightIdx === card.itemIndex;
1330
+ return `
1331
+ <button type="button" class="bz-pair-card ${isMatched ? 'is-matched' : ''} ${isSelected ? 'is-selected' : ''} ${isWrong ? 'is-wrong-shake' : ''}" data-pair-right="${card.itemIndex}" ${isMatched ? 'disabled' : ''}>
1332
+ <span style="font-size:14px;font-weight:800;">${esc(card.zh)}</span>
1333
+ <span>${isMatched ? '✨' : '🧶'}</span>
1334
+ </button>
1335
+ `;
1336
+ }).join('');
1337
+
1338
+ container.innerHTML = `
1339
+ <div class="bz-shell">
1340
+ ${getHeaderHtml(cycleCfg, summary, false)}
1341
+ <div class="bz-content">
1342
+ <div class="bz-arena">
1343
+ <aside class="bz-npc-panel">
1344
+ <div class="bz-npc-portrait">
1345
+ <img src="${portraitSrc}" alt="${esc(npc.name)}">
1346
+ </div>
1347
+ <div class="bz-npc-name">${esc(npc.name)}</div>
1348
+ <div class="bz-npc-role">${esc(npc.roleTitle)}</div>
1349
+ <div class="bz-npc-bubble">「${esc(weaverSpeech)}」</div>
1350
+ </aside>
1351
+
1352
+ <section class="bz-battle-panel">
1353
+ <div class="bz-battle-top">
1354
+ <span class="bz-pill bz-pill-teal">🧶 錦繡配對進度:${matchedSet.size} / ${session.items.length}</span>
1355
+ <span style="font-size:12px;color:#94a3b8;">初試即配對成功可點亮賓果;錯配也能繼續配完學習</span>
1356
+ </div>
1357
+
1358
+ <div class="bz-pair-grid">
1359
+ <div class="bz-pair-col">${leftHtml}</div>
1360
+ <div class="bz-pair-col">${rightHtml}</div>
1361
+ </div>
1362
+ </section>
1363
+ </div>
1364
+ </div>
1365
+ </div>
1366
+ `;
1367
+
1368
+ bindWeaverEvents();
1369
+ }
1370
+
1371
+ function evaluatePairIfReady() {
1372
+ if (selectedLeft === null || selectedRight === null || isAnimating) return;
1373
+ const leftIdx = selectedLeft;
1374
+ const rightIdx = selectedRight;
1375
+ const leftCard = leftCards.find((c) => c.itemIndex === leftIdx);
1376
+ const rightCard = rightCards.find((c) => c.itemIndex === rightIdx);
1377
+
1378
+ if (leftIdx === rightIdx) {
1379
+ matchedSet.add(leftIdx);
1380
+ if (!session.items[leftIdx]?.answered && !firstAttemptFailedSet.has(leftIdx)) {
1381
+ recordBazaarItemOutcome(game, session, leftIdx, true, rightCard?.zh || '');
1382
+ updateHeaderPills();
1383
+ saveGame();
1384
+ }
1385
+ playBazaarSfx('correct');
1386
+ weaverSpeech = `織得漂亮!「${leftCard?.word}」正是「${rightCard?.zh}」!`;
1387
+ selectedLeft = null;
1388
+ selectedRight = null;
1389
+ renderWeaverBoard();
1390
+
1391
+ if (matchedSet.size >= session.items.length) {
1392
+ isAnimating = true;
1393
+ scheduleTimeout(() => {
1394
+ enterSettlement(session);
1395
+ }, 550);
1396
+ }
1397
+ } else {
1398
+ firstAttemptFailedSet.add(leftIdx);
1399
+ if (!session.items[leftIdx]?.answered) {
1400
+ recordBazaarItemOutcome(game, session, leftIdx, false, rightCard?.zh || '');
1401
+ updateHeaderPills();
1402
+ saveGame();
1403
+ }
1404
+ playBazaarSfx('wrong');
1405
+ weaverSpeech = `線頭纏錯囉!「${leftCard?.word}」不是「${rightCard?.zh}」,再點一次英卡聽發音試試看!`;
1406
+ wrongFlash = { leftIdx, rightIdx };
1407
+ selectedLeft = null;
1408
+ selectedRight = null;
1409
+ isAnimating = true;
1410
+ renderWeaverBoard();
1411
+ scheduleTimeout(() => {
1412
+ wrongFlash = null;
1413
+ isAnimating = false;
1414
+ renderWeaverBoard();
1415
+ }, 440);
1416
+ }
1417
+ }
1418
+
1419
+ function bindWeaverEvents() {
1420
+ $$('[data-pair-left]', container).forEach((btn) => {
1421
+ bind(btn, 'click', () => {
1422
+ if (isAnimating) return;
1423
+ const idx = Number(btn.dataset.pairLeft);
1424
+ if (matchedSet.has(idx)) return;
1425
+ const card = leftCards.find((c) => c.itemIndex === idx);
1426
+ if (card) safeSpeakWord(card.word);
1427
+ selectedLeft = (selectedLeft === idx) ? null : idx;
1428
+ if (selectedLeft !== null && selectedRight !== null) {
1429
+ evaluatePairIfReady();
1430
+ } else {
1431
+ renderWeaverBoard();
1432
+ }
1433
+ });
1434
+ });
1435
+
1436
+ $$('[data-pair-right]', container).forEach((btn) => {
1437
+ bind(btn, 'click', () => {
1438
+ if (isAnimating) return;
1439
+ const idx = Number(btn.dataset.pairRight);
1440
+ if (matchedSet.has(idx)) return;
1441
+ selectedRight = (selectedRight === idx) ? null : idx;
1442
+ if (selectedLeft !== null && selectedRight !== null) {
1443
+ evaluatePairIfReady();
1444
+ } else {
1445
+ renderWeaverBoard();
1446
+ }
1447
+ });
1448
+ });
1449
+ }
1450
+
1451
+ renderWeaverBoard();
1452
+ }
1453
+
1454
+ function getNpcOpeningLine(npcId, mode) {
1455
+ if (mode === 'chain_drill') {
1456
+ return '今日額度已滿,但這幾道錯題紅鏈正等著你親手敲開!';
1457
+ }
1458
+ if (npcId === 'lutist') return '閉上雙眼聆聽琵琶伴奏的美語聲律,猜猜這是哪個單字?';
1459
+ if (npcId === 'scholar') return '觀星測字,從大漠殘卷中補上正確單字;若逢 2/3 鎖鏈,便以星盤寶石破鎖吧!';
1460
+ return '客官請接招!答對這 5 個單字就能點亮賓果、順手砍出黑市超值折扣!';
1461
+ }
1462
+
1463
+ // --------------------------------------------------------------------------
1464
+ // 視圖 4:戰後結算 & 班級 13 階首破原子同步
1465
+ // --------------------------------------------------------------------------
1466
+ async function enterSettlement(session) {
1467
+ clearTimers();
1468
+ const classInfo = getClassInfo();
1469
+ const now = opts.now || new Date();
1470
+ const settle = settleBazaarEncounter(game, uid, session, classInfo, now);
1471
+ if (!settle) {
1472
+ showLobbyView();
1473
+ return;
1474
+ }
1475
+
1476
+ const cycleCfg = getBazaarQuotaInfo(classInfo, now).modeState.cycleConfig || modeState.cycleConfig;
1477
+ const npc = getNpcMeta(session.npcId);
1478
+ const linesDelta = Math.max(0, (settle.linesAfter || 0) - (settle.linesBefore || 0));
1479
+
1480
+ const itemRowsHtml = (session.items || []).map((it) => {
1481
+ const o = it.outcome || {};
1482
+ let statusBadge = '';
1483
+ if (o.chainShattered) {
1484
+ statusBadge = `<span class="bz-pill bz-pill-gold">💥 粉碎宿敵鎖鏈${o.newlyLit ? '・✨點亮' : ''}</span>`;
1485
+ } else if (o.newlyLit) {
1486
+ statusBadge = '<span class="bz-pill bz-pill-teal">✨ 點亮賓果格</span>';
1487
+ } else if (o.chainCracked) {
1488
+ statusBadge = `<span class="bz-pill bz-pill-gold">🔨 敲裂鎖鏈 ${o.chainBefore}/3 → ${o.chainAfter}/3(+${fmt(o.grainBonus)} 糧草)</span>`;
1489
+ } else if (o.chainReset) {
1490
+ statusBadge = '<span class="bz-pill bz-pill-crimson">⛓️ 答錯鎖上紅鏈 (0/3)</span>';
1491
+ } else if (it.isCorrect) {
1492
+ statusBadge = '<span class="bz-pill">✓ 答對熟記</span>';
1493
+ } else {
1494
+ statusBadge = '<span class="bz-pill bz-pill-crimson">✕ 複習失誤</span>';
1495
+ }
1496
+
1497
+ return `
1498
+ <div class="bz-settle-row">
1499
+ <div>
1500
+ <b style="color:#ffffff;">#${String(it.n).padStart(3, '0')} ${esc(it.wordObj?.word || '')}</b>
1501
+ <span style="margin-left:8px;color:#cbd5e1;font-size:13px;">${esc(it.wordObj?.zh || '')}</span>
1502
+ </div>
1503
+ <div>${statusBadge}</div>
1504
+ </div>
1505
+ `;
1506
+ }).join('');
1507
+
1508
+ const chestsHtml = Array.isArray(settle.newPersonalMilestones) && settle.newPersonalMilestones.length > 0
1509
+ ? `
1510
+ <div class="bz-card" style="border-color:rgba(20,184,166,0.65);background:linear-gradient(155deg,rgba(20,184,166,0.16),rgba(15,23,42,0.92));">
1511
+ <div class="bz-quota-title" style="margin-bottom:8px;">🎁 個人連線寶箱解鎖!</div>
1512
+ <div style="display:flex;flex-direction:column;gap:6px;">
1513
+ ${settle.newPersonalMilestones.map((pm) => `
1514
+ <div style="font-size:13.5px;color:#f8fafc;">
1515
+ ✅ <b>${pm.lines} 線・${esc(pm.label)}</b>:${esc(pm.desc)}
1516
+ ${pm.title ? `(已自動佩戴稱號【${esc(pm.title)}】!)` : ''}
1517
+ </div>
1518
+ `).join('')}
1519
+ </div>
1520
+ </div>
1521
+ `
1522
+ : '';
1523
+
1524
+ container.innerHTML = `
1525
+ <div class="bz-shell">
1526
+ ${getHeaderHtml(cycleCfg, settle.summary, false)}
1527
+ <div class="bz-content">
1528
+ <div class="bz-card" style="text-align:center;">
1529
+ <div style="font-size:40px;line-height:1;">🎊</div>
1530
+ <h3 style="margin:6px 0 4px;font-size:21px;font-weight:900;color:#fde68a;">
1531
+ ${esc(npc.name)}・奇遇結算戰報
1532
+ </h3>
1533
+ <div style="display:flex;justify-content:center;gap:10px;flex-wrap:wrap;margin-top:10px;">
1534
+ <span class="bz-pill bz-pill-gold">✨ 連線:${settle.linesBefore} ➔ ${settle.linesAfter} 線${linesDelta > 0 ? ` (+${linesDelta})` : ''}</span>
1535
+ <span class="bz-pill bz-pill-teal">📜 已點亮:${settle.litAfter} / 240</span>
1536
+ <span class="bz-pill bz-pill-gold">🪙 金幣 +${settle.merchantCoinsEarned}(EXP +${settle.merchantExpEarned})</span>
1537
+ <span class="bz-pill bz-pill-crimson">🏷️ 本場 ${esc(settle.roundDiscountLabel)}・今日最低享【${esc(settle.discountLabel || '原價')}】</span>
1538
+ </div>
1539
+ ${settle.weekendCouponGranted ? '<div style="margin-top:8px;font-size:13px;font-weight:800;color:#fca5a5;">🎫 週末限定好禮:額外獲贈胡商 8 折特許券 ×1!</div>' : ''}
1540
+ </div>
1541
+
1542
+ <div id="bzSettleFirstBloodSlot"></div>
1543
+
1544
+ ${chestsHtml}
1545
+
1546
+ <div class="bz-card">
1547
+ <div class="bz-quota-title" style="margin-bottom:8px;">📝 本場 5 題作答明細</div>
1548
+ <div class="bz-settle-list">${itemRowsHtml}</div>
1549
+ </div>
1550
+
1551
+ <div style="display:flex;gap:10px;flex-wrap:wrap;">
1552
+ <button type="button" class="bz-btn-primary" id="btnSettleWalkAgain" style="flex:1.2;min-width:190px;">🚶 再漫步一場</button>
1553
+ <button type="button" class="bz-btn-secondary" id="btnSettleGoMarket" style="flex:1;min-width:160px;">🏺 前往西域黑市逛逛</button>
1554
+ <button type="button" class="bz-btn-ghost" id="btnSettleBackLobby" style="flex:1;min-width:150px;">📜 返回十卷賓果盤</button>
1555
+ </div>
1556
+ </div>
1557
+ </div>
1558
+ `;
1559
+
1560
+ bind($('#btnSettleWalkAgain', container), 'click', () => startWalkCutscene());
1561
+ bind($('#btnSettleGoMarket', container), 'click', () => {
1562
+ activeTab = 'market';
1563
+ showLobbyView();
1564
+ });
1565
+ bind($('#btnSettleBackLobby', container), 'click', () => {
1566
+ activeTab = 'bazaar';
1567
+ showLobbyView();
1568
+ });
1569
+
1570
+ // 非同步上報班級 13 階首破與排行榜,並同步 blueprints / firstBloodWon
1571
+ const fbSlot = $('#bzSettleFirstBloodSlot', container);
1572
+ const db = bazaarCtx?.db;
1573
+ const classCode = student?.classCode;
1574
+ const quotaNow = getBazaarQuotaInfo(classInfo, now);
1575
+ const cycleState = ensureBazaarCycleState(game, settle.cycleId);
1576
+
1577
+ if (db && typeof db.recordBazaarProgress === 'function' && classCode && uid && uid !== 'guest') {
1578
+ if (fbSlot) {
1579
+ fbSlot.innerHTML = '<div style="font-size:12.5px;color:#94a3b8;text-align:center;">⏳ 正在同步班級連線榜單與檢核首破賞賜…</div>';
1580
+ }
1581
+ try {
1582
+ const res = await db.recordBazaarProgress(
1583
+ classCode,
1584
+ {
1585
+ uid,
1586
+ seat: student?.seat ?? null,
1587
+ name: student?.name || '將士',
1588
+ role: student?.role || 'student',
1589
+ },
1590
+ settle.cycleId,
1591
+ {
1592
+ totalLines: settle.linesAfter,
1593
+ litCount: settle.litAfter,
1594
+ clearedMistakes: cycleState.clearedMistakes,
1595
+ title: game.curTitle || '',
1596
+ nowMs: Date.now(),
1597
+ openAtMs: quotaNow.modeState.openAtMs,
1598
+ isForcedOpen: quotaNow.modeState.isForcedOpen,
1599
+ localGame: game,
1600
+ }
1601
+ );
1602
+
1603
+ if (res?.nextStudentGame) {
1604
+ const remoteBp = Number(res.nextStudentGame.blueprints);
1605
+ if (Number.isFinite(remoteBp)) {
1606
+ game.blueprints = Math.max(Number(game.blueprints) || 0, remoteBp);
1607
+ }
1608
+ const remoteFb = res.nextStudentGame.bazaar?.cycles?.[settle.cycleId]?.firstBloodWon;
1609
+ if (remoteFb && typeof remoteFb === 'object') {
1610
+ Object.assign(cycleState.firstBloodWon, remoteFb);
1611
+ }
1612
+ }
1613
+
1614
+ if (res?.firstMilestones || res?.leaderboardEntries) {
1615
+ const prevCls = cachedClassDoc || getClassInfo() || {};
1616
+ cachedClassDoc = {
1617
+ ...prevCls,
1618
+ bazaarCycles: {
1619
+ ...(prevCls.bazaarCycles || {}),
1620
+ [settle.cycleId]: {
1621
+ ...(prevCls.bazaarCycles?.[settle.cycleId] || {}),
1622
+ firstMilestones: res.firstMilestones || prevCls.bazaarCycles?.[settle.cycleId]?.firstMilestones || {},
1623
+ entries: res.leaderboardEntries || prevCls.bazaarCycles?.[settle.cycleId]?.entries || {},
1624
+ },
1625
+ },
1626
+ };
1627
+ cachedClassAt = Date.now();
1628
+ }
1629
+
1630
+ if (Array.isArray(res?.newlyWonMilestones) && res.newlyWonMilestones.length > 0) {
1631
+ playBazaarSfx('shatter');
1632
+ const wonText = res.newlyWonMilestones.map((m) => `${m}線`).join('、');
1633
+ notify(`🏆 金榜奪標大捷!搶下全班 ${wonText} 首破,御賜金兵符 +${res.tallyAwarded} 枚!`, 'gold', 5000);
1634
+ if (!isClosed && fbSlot) {
1635
+ fbSlot.innerHTML = `
1636
+ <div class="bz-first-blood-hero">
1637
+ 🏆 金榜奪標大捷!主帥率先全班突破 【${esc(wonText)}】,御賜大將金兵符 +${res.tallyAwarded} 枚(已入庫)!
1638
+ </div>
1639
+ `;
1640
+ }
1641
+ } else if (!isClosed && fbSlot) {
1642
+ fbSlot.innerHTML = '';
1643
+ }
1644
+ } catch (err) {
1645
+ console.warn('[bazaar-ui] recordBazaarProgress failed:', err);
1646
+ if (!isClosed && fbSlot) {
1647
+ fbSlot.innerHTML = '<div style="font-size:12px;color:#fca5a5;text-align:center;">⚠️ 班級排行榜暫時無法連線同步,本機進度已安全保留。</div>';
1648
+ }
1649
+ }
1650
+ }
1651
+
1652
+ await saveGame();
1653
+ refreshUI();
1654
+ }
1655
+
1656
+ // 預設啟動邏輯
1657
+ if (isCountdownInit) {
1658
+ showCountdownView(initQuota);
1659
+ } else {
1660
+ showLobbyView();
1661
+ }
1662
+ }
1663
+
1664
+ if (typeof window !== 'undefined') window.openBazaarEvent = openBazaarEventModal;
js/merchant-ui.js CHANGED
@@ -103,8 +103,8 @@ if (typeof window !== 'undefined') window.openTodayWords = openTodayWordsModal;
103
  // ==========================================================================
104
  // 開啟商隊好感度等級與各級所需 EXP 總覽彈窗
105
  // ==========================================================================
106
- export function openCaravanLevelsModal() {
107
- const game = merchantCtx?.getGame?.();
108
  const status = getMerchantStatus(game);
109
  const levels = MERCHANT.levels || [];
110
  const currentExp = status.exp;
@@ -1028,9 +1028,65 @@ export async function openMerchantEventModal() {
1028
  renderCurrentCard();
1029
  }
1030
 
1031
- // 視圖 3:西域集市(20項商品陳列、即時價格折算、購買發放)
1032
  function showMarketView() {
1033
  if (arenaTimer) { clearInterval(arenaTimer); arenaTimer = null; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1034
  const status = getMerchantStatus(game);
1035
  const m = game.merchant || {};
1036
  const mult = typeof m.todayMult === 'number' ? m.todayMult : 1.0;
@@ -1038,149 +1094,167 @@ export async function openMerchantEventModal() {
1038
  ? m.todayDiscount
1039
  : (mult <= 1.0 ? 0.2 : mult / 5);
1040
  const discountLabel = m.todayDiscountLabel || `${Math.round(discount * 10)}折`;
1041
- let useCoupon = false;
1042
-
1043
- function renderMarket() {
1044
- const items = MERCHANT.items || [];
1045
- const currentDState = merchantCtx?.getDState?.();
1046
- const currentCPS = currentDState ? totalProd(game, currentDState) : 100;
1047
-
1048
- const itemsHtml = items.map(it => {
1049
- const isLevelMet = status.currentLv.lv >= it.lv;
1050
- const effectiveLimit = (it.id === 'goldTally' && status.currentLv.lv >= 6) ? 2 : it.limit;
1051
- const curWeek = status.dayInfo.week || status.dayInfo.unit || 1;
1052
- const buyRecord = (m.buys && m.buys[it.id]) || { count: 0, week: curWeek, total: 0 };
1053
- const weekCount = buyRecord.week === curWeek ? (buyRecord.count || 0) : 0;
1054
- const totalCount = buyRecord.total || 0;
1055
- const isLimitMet = (it.limitType === 'once' && totalCount >= effectiveLimit) ||
1056
- (it.limitType === 'tier' && totalCount >= effectiveLimit) ||
1057
- (it.limitType === 'week' && weekCount >= effectiveLimit);
1058
-
1059
- const origPrice = it.cost * 5;
1060
- let finalCost = Math.round(origPrice * discount);
1061
- if (useCoupon && (m.coupons || 0) > 0) {
1062
- finalCost = Math.max(1, Math.round(finalCost * (MERCHANT.discountCouponRate || 0.8)));
1063
- }
1064
 
1065
- const canAfford = (m.gold || 0) >= finalCost;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
 
1067
- let buyBtnText = `🪙 以 ${finalCost} 幣換購`;
1068
- let btnDisabled = false;
1069
 
1070
- if (!isLevelMet) {
1071
- buyBtnText = `🔒 需 Lv.${it.lv} 解鎖`;
1072
- btnDisabled = true;
1073
- } else if (isLimitMet) {
1074
- buyBtnText = it.limitType === 'once' ? '已達終生限購' : (it.limitType === 'tier' ? '已達階段上限' : '本週限額已滿');
1075
- btnDisabled = true;
1076
- } else if (!canAfford) {
1077
- buyBtnText = `金幣不足 (${finalCost}幣)`;
1078
- btnDisabled = true;
1079
- }
1080
 
1081
- const limitText = it.limitType === 'once'
1082
- ? `終生限購 (${totalCount}/${effectiveLimit})`
1083
- : (it.limitType === 'tier'
1084
- ? `階段限購 (${totalCount}/${effectiveLimit})`
1085
- : `每週限購 (${weekCount}/${effectiveLimit})`);
1086
-
1087
- const priceShowHtml = discount < 1.0 || (useCoupon && m.coupons > 0)
1088
- ? `<span class="me-item-price" style="color:#34d399;">${finalCost} 幣 <small style="font-size:11px; color:#fbbf24;">(${discountLabel})</small></span>
1089
- <span class="me-item-orig-price">原標價 ${origPrice}</span>`
1090
- : `<span class="me-item-price">${origPrice} 金幣</span>`;
1091
-
1092
- return `
1093
- <div class="me-item-card ${isLevelMet ? '' : 'locked'}">
1094
- <div class="me-item-top">
1095
- <div class="me-item-icon">${it.icon}</div>
1096
- <div class="me-item-info">
1097
- <div style="display:flex; justify-content:space-between; align-items:center;">
1098
- <h4 class="me-item-name">${esc(it.name)}</h4>
1099
- <span style="font-size:11px; padding:2px 8px; border-radius:6px; background:rgba(255,255,255,0.08); color:#94a3b8;">Lv.${it.lv}</span>
1100
- </div>
1101
- <div class="me-item-desc">${esc(it.desc)}</div>
1102
- </div>
1103
- </div>
1104
- <div class="me-item-foot">
1105
- <div class="me-item-price-box">
1106
- ${priceShowHtml}
1107
- <small style="font-size:11px; color:#64748b;">${limitText}</small>
 
 
 
1108
  </div>
1109
- <button class="me-item-buy-btn" data-buy-id="${it.id}" ${btnDisabled ? 'disabled' : ''}>
1110
- ${buyBtnText}
1111
- </button>
1112
  </div>
1113
  </div>
1114
- `;
1115
- }).join('');
1116
-
1117
- container.innerHTML = `
1118
- <div class="me-wrap">
1119
- ${renderNavHeader('西域商隊', '胡商萬里奇珍異寶・各取所需壯大我軍')}
1120
-
1121
- <div class="me-market-header">
1122
- <div style="display:flex; align-items:center; gap:12px; flex-wrap:wrap;">
1123
- <span class="me-pill ${discount <= 0.2 ? 'me-pill-level' : 'me-pill-coupon'}">
1124
- 🏷️ 今日交涉折扣:<b>${discountLabel}</b>(5倍原標價 ➔ 砍至 ${discountLabel})
1125
- </span>
1126
- ${m.coupons > 0 ? `
1127
- <label class="me-coupon-toggle">
1128
- <input type="checkbox" id="chkUseCoupon" ${useCoupon ? 'checked' : ''}>
1129
- <span>抵用 8 折特許券(現有 ${m.coupons} 張)</span>
1130
- </label>
1131
- ` : ''}
1132
  </div>
1133
- <button class="btn btn-sm btn-ghost" id="btnBackToIntro">← 返回商隊大廳</button>
1134
- </div>
1135
-
1136
- <div class="me-items-grid">
1137
- ${itemsHtml}
1138
  </div>
1139
  </div>
1140
  `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1141
 
1142
- bind($('#btnBackToIntro', container), 'click', () => {
1143
- showIntroView();
1144
- });
1145
-
1146
- const btnNavMarket = $('#btnNavCaravanLevels', container);
1147
- if (btnNavMarket) {
1148
- bind(btnNavMarket, 'click', () => {
1149
- openCaravanLevelsModal();
1150
- });
1151
- }
1152
-
1153
- const couponChk = $('#chkUseCoupon', container);
1154
- if (couponChk) {
1155
- bind(couponChk, 'change', (e) => {
1156
- useCoupon = e.target.checked;
1157
- renderMarket();
1158
- });
1159
- }
1160
-
1161
- $$('.me-item-buy-btn', container).forEach(btn => {
1162
- bind(btn, 'click', () => {
1163
- const itemId = btn.dataset.buyId;
1164
- if (!itemId) return;
1165
- const buyRes = buyMerchantItem(game, itemId, useCoupon, currentCPS);
1166
- if (!buyRes.success) {
1167
- toast(buyRes.reason || '購買失敗', 'error');
1168
- return;
1169
- }
1170
 
1171
- if (merchantCtx) {
1172
- merchantCtx.onPurchase?.(buyRes);
1173
- }
1174
- toast(`✨ 購得【${buyRes.item.name}】���${buyRes.effectMsg}`, 'gold', 3500);
1175
- renderMarket();
1176
- });
1177
  });
1178
  }
1179
 
1180
- renderMarket();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1181
  }
1182
 
1183
- // 預設進入活動大廳
1184
- showIntroView();
1185
  }
1186
  if (typeof window !== 'undefined') window.openMerchantEvent = openMerchantEventModal;
 
103
  // ==========================================================================
104
  // 開啟商隊好感度等級與各級所需 EXP 總覽彈窗
105
  // ==========================================================================
106
+ export function openCaravanLevelsModal(overrideGame = null) {
107
+ const game = overrideGame || merchantCtx?.getGame?.() || (typeof window !== 'undefined' ? window.student?.game : null);
108
  const status = getMerchantStatus(game);
109
  const levels = MERCHANT.levels || [];
110
  const currentExp = status.exp;
 
1028
  renderCurrentCard();
1029
  }
1030
 
1031
+ // 視圖 3:西域集市(20項商品陳列、即時價格折算、購買發放 — 委派共用面板 renderMerchantMarketPanel)
1032
  function showMarketView() {
1033
  if (arenaTimer) { clearInterval(arenaTimer); arenaTimer = null; }
1034
+ container.innerHTML = `
1035
+ <div class="me-wrap">
1036
+ <div id="meMarketNavSlot"></div>
1037
+ <div id="meMarketPanelSlot"></div>
1038
+ </div>
1039
+ `;
1040
+ const navSlot = $('#meMarketNavSlot', container);
1041
+ const panelSlot = $('#meMarketPanelSlot', container);
1042
+
1043
+ function syncNav() {
1044
+ if (!navSlot) return;
1045
+ navSlot.innerHTML = renderNavHeader('西域商隊', '胡商萬里奇珍異寶・各取所需壯大我軍');
1046
+ const btnNavMarket = $('#btnNavCaravanLevels', navSlot);
1047
+ if (btnNavMarket) {
1048
+ bind(btnNavMarket, 'click', () => {
1049
+ openCaravanLevelsModal(game);
1050
+ });
1051
+ }
1052
+ }
1053
+
1054
+ syncNav();
1055
+ renderMerchantMarketPanel(panelSlot, {
1056
+ game,
1057
+ getDState: () => merchantCtx?.getDState?.(),
1058
+ showCaravanBar: false,
1059
+ headerExtraHtml: `<button class="btn btn-sm btn-ghost" id="btnBackToIntro">← 返回商隊大廳</button>`,
1060
+ onMount: (root) => {
1061
+ bind($('#btnBackToIntro', root), 'click', () => {
1062
+ showIntroView();
1063
+ });
1064
+ },
1065
+ onAfterBuy: () => {
1066
+ syncNav();
1067
+ },
1068
+ });
1069
+ }
1070
+
1071
+ // 預設進入活動大廳
1072
+ showIntroView();
1073
+ }
1074
+
1075
+ // ==========================================================================
1076
+ // 抽離共用:20 項西域黑市商品陳列與購買面板(可供西域商隊與西域萬國大市集嵌合)
1077
+ // ==========================================================================
1078
+ export function renderMerchantMarketPanel(hostEl, opts = {}) {
1079
+ if (!hostEl) return;
1080
+ const game = opts.game || merchantCtx?.getGame?.() || (typeof window !== 'undefined' ? window.student?.game : null);
1081
+ if (!game) {
1082
+ hostEl.innerHTML = '<div class="me-market-empty" style="padding:16px;text-align:center;color:#94a3b8;">尚未載入商隊資料,請稍後再試。</div>';
1083
+ return;
1084
+ }
1085
+
1086
+ let useCoupon = Boolean(opts.useCoupon);
1087
+ const showCaravanBar = opts.showCaravanBar !== false;
1088
+
1089
+ function renderPanel() {
1090
  const status = getMerchantStatus(game);
1091
  const m = game.merchant || {};
1092
  const mult = typeof m.todayMult === 'number' ? m.todayMult : 1.0;
 
1094
  ? m.todayDiscount
1095
  : (mult <= 1.0 ? 0.2 : mult / 5);
1096
  const discountLabel = m.todayDiscountLabel || `${Math.round(discount * 10)}折`;
1097
+ if ((m.coupons || 0) <= 0) useCoupon = false;
1098
+
1099
+ const items = MERCHANT.items || [];
1100
+ const currentDState = typeof opts.getDState === 'function' ? opts.getDState() : merchantCtx?.getDState?.();
1101
+ const currentCPS = currentDState ? totalProd(game, currentDState) : 100;
1102
+
1103
+ let expPct = 100;
1104
+ let expHint = '已達最高��感等級';
1105
+ if (status.nextLv) {
1106
+ const prevNeed = Number(status.currentLv.expNeed) || 0;
1107
+ const nextNeed = Number(status.nextLv.expNeed) || 1;
1108
+ const span = Math.max(1, nextNeed - prevNeed);
1109
+ expPct = Math.min(100, Math.max(0, Math.round(((status.exp - prevNeed) / span) * 100)));
1110
+ expHint = `距 Lv.${status.nextLv.lv} ${esc(status.nextLv.name)} 尚需 ${Math.max(0, nextNeed - status.exp)} EXP`;
1111
+ }
 
 
 
 
 
 
 
 
1112
 
1113
+ const caravanBarHtml = showCaravanBar ? `
1114
+ <div class="me-caravan-bar">
1115
+ <div style="display:flex;align-items:center;gap:10px;flex-wrap:wrap;">
1116
+ <span class="me-pill me-pill-level">⭐ Lv.${status.currentLv.lv} ${esc(status.currentLv.name)}</span>
1117
+ <div style="display:flex;flex-direction:column;gap:4px;">
1118
+ <div style="font-size:12px;font-weight:700;color:#cbd5e1;">好感經驗:${status.exp} EXP(${expHint})</div>
1119
+ <div class="me-caravan-bar-exp"><span style="width:${expPct}%;"></span></div>
1120
+ </div>
1121
+ </div>
1122
+ <div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
1123
+ <span class="me-pill me-pill-gold">🪙 <b>${status.gold}</b> 幣</span>
1124
+ ${(m.coupons || 0) > 0 ? `<span class="me-pill me-pill-coupon">🎫 8折券 ×${m.coupons}</span>` : ''}
1125
+ <button type="button" class="btn btn-sm btn-ghost" id="btnMarketCaravanLevels" style="min-height:44px;">🔍 等級特權</button>
1126
+ </div>
1127
+ </div>
1128
+ ` : '';
1129
+
1130
+ const itemsHtml = items.map(it => {
1131
+ const isLevelMet = status.currentLv.lv >= it.lv;
1132
+ const effectiveLimit = (it.id === 'goldTally' && status.currentLv.lv >= 6) ? 2 : it.limit;
1133
+ const curWeek = status.dayInfo.week || status.dayInfo.unit || 1;
1134
+ const buyRecord = (m.buys && m.buys[it.id]) || { count: 0, week: curWeek, total: 0 };
1135
+ const weekCount = buyRecord.week === curWeek ? (buyRecord.count || 0) : 0;
1136
+ const totalCount = buyRecord.total || 0;
1137
+ const isLimitMet = (it.limitType === 'once' && totalCount >= effectiveLimit) ||
1138
+ (it.limitType === 'tier' && totalCount >= effectiveLimit) ||
1139
+ (it.limitType === 'week' && weekCount >= effectiveLimit);
1140
+
1141
+ const origPrice = it.cost * 5;
1142
+ let finalCost = Math.round(origPrice * discount);
1143
+ if (useCoupon && (m.coupons || 0) > 0) {
1144
+ finalCost = Math.max(1, Math.round(finalCost * (MERCHANT.discountCouponRate || 0.8)));
1145
+ }
1146
 
1147
+ const canAfford = (m.gold || 0) >= finalCost;
 
1148
 
1149
+ let buyBtnText = `🪙 以 ${finalCost} 幣換購`;
1150
+ let btnDisabled = false;
 
 
 
 
 
 
 
 
1151
 
1152
+ if (!isLevelMet) {
1153
+ buyBtnText = `🔒 需 Lv.${it.lv} 解鎖`;
1154
+ btnDisabled = true;
1155
+ } else if (isLimitMet) {
1156
+ buyBtnText = it.limitType === 'once' ? '已達終生限購' : (it.limitType === 'tier' ? '已達階段上限' : '本週限額已滿');
1157
+ btnDisabled = true;
1158
+ } else if (!canAfford) {
1159
+ buyBtnText = `金幣不足 (${finalCost}幣)`;
1160
+ btnDisabled = true;
1161
+ }
1162
+
1163
+ const limitText = it.limitType === 'once'
1164
+ ? `終生限購 (${totalCount}/${effectiveLimit})`
1165
+ : (it.limitType === 'tier'
1166
+ ? `階段限購 (${totalCount}/${effectiveLimit})`
1167
+ : `每週限購 (${weekCount}/${effectiveLimit})`);
1168
+
1169
+ const priceShowHtml = discount < 1.0 || (useCoupon && m.coupons > 0)
1170
+ ? `<span class="me-item-price" style="color:#059669;">${finalCost} 幣 <small style="font-size:11px; color:#b45309;">(${discountLabel})</small></span>
1171
+ <span class="me-item-orig-price">原標價 ${origPrice}</span>`
1172
+ : `<span class="me-item-price">${origPrice} 金幣</span>`;
1173
+
1174
+ return `
1175
+ <div class="me-item-card ${isLevelMet ? '' : 'locked'}">
1176
+ <div class="me-item-top">
1177
+ <div class="me-item-icon">${it.icon}</div>
1178
+ <div class="me-item-info">
1179
+ <div style="display:flex; justify-content:space-between; align-items:center;">
1180
+ <h4 class="me-item-name">${esc(it.name)}</h4>
1181
+ <span style="font-size:11px; padding:2px 8px; border-radius:6px; background:rgba(15,23,42,0.08); color:#475569; font-weight:700;">Lv.${it.lv}</span>
1182
  </div>
1183
+ <div class="me-item-desc">${esc(it.desc)}</div>
 
 
1184
  </div>
1185
  </div>
1186
+ <div class="me-item-foot">
1187
+ <div class="me-item-price-box">
1188
+ ${priceShowHtml}
1189
+ <small style="font-size:11px; color:#64748b;">${limitText}</small>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1190
  </div>
1191
+ <button type="button" class="me-item-buy-btn" data-buy-id="${it.id}" ${btnDisabled ? 'disabled' : ''}>
1192
+ ${buyBtnText}
1193
+ </button>
 
 
1194
  </div>
1195
  </div>
1196
  `;
1197
+ }).join('');
1198
+
1199
+ hostEl.innerHTML = `
1200
+ ${caravanBarHtml}
1201
+ <div class="me-market-header">
1202
+ <div style="display:flex; align-items:center; gap:12px; flex-wrap:wrap;">
1203
+ <span class="me-pill ${discount <= 0.2 ? 'me-pill-level' : 'me-pill-coupon'}">
1204
+ 🏷️ 今日交涉折扣:<b>${discountLabel}</b>(5倍原標價 ➔ 砍至 ${discountLabel})
1205
+ </span>
1206
+ ${(m.coupons || 0) > 0 ? `
1207
+ <label class="me-coupon-toggle">
1208
+ <input type="checkbox" id="chkUseCoupon" ${useCoupon ? 'checked' : ''}>
1209
+ <span>抵用 8 折特許券(現有 ${m.coupons} 張)</span>
1210
+ </label>
1211
+ ` : ''}
1212
+ </div>
1213
+ ${opts.headerExtraHtml || ''}
1214
+ </div>
1215
+ <div class="me-items-grid">
1216
+ ${itemsHtml}
1217
+ </div>
1218
+ `;
1219
 
1220
+ const btnLevels = $('#btnMarketCaravanLevels', hostEl);
1221
+ if (btnLevels) {
1222
+ bind(btnLevels, 'click', () => openCaravanLevelsModal(game));
1223
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1224
 
1225
+ const couponChk = $('#chkUseCoupon', hostEl);
1226
+ if (couponChk) {
1227
+ bind(couponChk, 'change', (e) => {
1228
+ useCoupon = Boolean(e.target.checked);
1229
+ renderPanel();
 
1230
  });
1231
  }
1232
 
1233
+ $$('.me-item-buy-btn', hostEl).forEach((btn) => {
1234
+ bind(btn, 'click', async () => {
1235
+ const itemId = btn.dataset.buyId;
1236
+ if (!itemId) return;
1237
+ const buyRes = buyMerchantItem(game, itemId, useCoupon, currentCPS);
1238
+ if (!buyRes.success) {
1239
+ toast(buyRes.reason || '購買失敗', 'error');
1240
+ return;
1241
+ }
1242
+ if (!opts.skipContextPurchase && merchantCtx) {
1243
+ merchantCtx.onPurchase?.(buyRes);
1244
+ }
1245
+ toast(`✨ 購得【${buyRes.item.name}】!${buyRes.effectMsg}`, 'gold', 3500);
1246
+ renderPanel();
1247
+ if (typeof opts.onAfterBuy === 'function') {
1248
+ await opts.onAfterBuy(buyRes);
1249
+ }
1250
+ });
1251
+ });
1252
+
1253
+ if (typeof opts.onMount === 'function') {
1254
+ opts.onMount(hostEl);
1255
+ }
1256
  }
1257
 
1258
+ renderPanel();
 
1259
  }
1260
  if (typeof window !== 'undefined') window.openMerchantEvent = openMerchantEventModal;
tools/verify-integrity.mjs CHANGED
@@ -126,6 +126,8 @@ import {
126
  recordBazaarItemOutcome,
127
  settleBazaarEncounter,
128
  } from '../js/bazaar.js';
 
 
129
  import { computeStudentAudit, cumStarCost } from '../.agents/skills/student-resource-audit/scripts/audit-student.js';
130
 
131
  const ROOT = process.cwd();
@@ -2848,4 +2850,51 @@ ok('西域萬國大市集核心引擎 js/bazaar.js 匯出契約與存檔 Schema
2848
  }
2849
  ok('西域萬國大市集資料庫 HWM 守衛與班級 13 階首破原子交易檢驗 100% 通過');
2850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2851
  console.log(`\n🎉 全部 ${passedChecks} 大項工程防呆檢驗 100% 通過!可安全部署上線。`);
 
126
  recordBazaarItemOutcome,
127
  settleBazaarEncounter,
128
  } from '../js/bazaar.js';
129
+ import { renderMerchantMarketPanel } from '../js/merchant-ui.js';
130
+ import { setupBazaarUI, openBazaarEventModal } from '../js/bazaar-ui.js';
131
  import { computeStudentAudit, cumStarCost } from '../.agents/skills/student-resource-audit/scripts/audit-student.js';
132
 
133
  const ROOT = process.cwd();
 
2850
  }
2851
  ok('西域萬國大市集資料庫 HWM 守衛與班級 13 階首破原子交易檢驗 100% 通過');
2852
 
2853
+ // ----------------------------------------------------------------------------
2854
+ // 27. 西域萬國大市集 UI 契約、共用黑市面板、行動端 RWD 樣式與 index.html 載入檢驗 (Bazaar Task 5)
2855
+ // ----------------------------------------------------------------------------
2856
+ {
2857
+ assert.equal(typeof renderMerchantMarketPanel, 'function', 'js/merchant-ui.js 必須匯出 renderMerchantMarketPanel');
2858
+ assert.equal(typeof setupBazaarUI, 'function', 'js/bazaar-ui.js 必須匯出 setupBazaarUI');
2859
+ assert.equal(typeof openBazaarEventModal, 'function', 'js/bazaar-ui.js 必須匯出 openBazaarEventModal');
2860
+
2861
+ const bazaarCssPath = path.join(ROOT, 'css/bazaar.css');
2862
+ assert.ok(fs.existsSync(bazaarCssPath), '必須存在 css/bazaar.css');
2863
+ const bazaarCss = fs.readFileSync(bazaarCssPath, 'utf8');
2864
+ assert.ok(bazaarCss.includes('88vh'), 'css/bazaar.css 必須規範彈窗 max-height: 88vh');
2865
+ assert.ok(bazaarCss.includes('84vh'), 'css/bazaar.css 必須於矮螢幕媒體查詢規範 max-height: 84vh');
2866
+ assert.ok(bazaarCss.includes('-webkit-overflow-scrolling: touch'), 'css/bazaar.css 必須包含 -webkit-overflow-scrolling: touch');
2867
+ assert.ok(bazaarCss.includes('@media'), 'css/bazaar.css 必須包含 @media 行動端響應式規則');
2868
+ assert.ok(bazaarCss.includes('.modal-close'), 'css/bazaar.css 必須包含 .modal-close 置頂關閉按鈕樣式');
2869
+ assert.ok(bazaarCss.includes('.bz-walk-stage'), 'css/bazaar.css 必須包含 .bz-walk-stage 漫步過場樣式');
2870
+ assert.ok(bazaarCss.includes('.bz-bingo-grid'), 'css/bazaar.css 必須包含 .bz-bingo-grid 十卷賓果樣式');
2871
+ assert.ok(bazaarCss.includes('.bz-arena'), 'css/bazaar.css 必須包含 .bz-arena 四角色對決樣式');
2872
+ assert.ok(bazaarCss.includes('.bz-board-wall'), 'css/bazaar.css 必須包含 .bz-board-wall 首破英雄榜樣式');
2873
+
2874
+ const indexHtml = fs.readFileSync(path.join(ROOT, 'index.html'), 'utf8');
2875
+ assert.ok(
2876
+ indexHtml.includes(`css/bazaar.css?v=${APP_BUILD_VERSION}`),
2877
+ `index.html 必須正確載入 css/bazaar.css?v=${APP_BUILD_VERSION}`
2878
+ );
2879
+
2880
+ // 安全渲染煙霧檢查:renderMerchantMarketPanel 應可無錯誤渲染全部 20 項黑市商品
2881
+ const fakeMarketHost = {
2882
+ innerHTML: '',
2883
+ querySelector: () => null,
2884
+ querySelectorAll: () => [],
2885
+ };
2886
+ const smokeGame = newGame();
2887
+ smokeGame.merchant.marketUnlocked = true;
2888
+ smokeGame.merchant.gold = 200;
2889
+ smokeGame.merchant.todayDiscount = 0.2;
2890
+ smokeGame.merchant.todayDiscountLabel = '2折';
2891
+ renderMerchantMarketPanel(null);
2892
+ renderMerchantMarketPanel(fakeMarketHost, { game: smokeGame });
2893
+ for (const item of MERCHANT.items) {
2894
+ assert.ok(fakeMarketHost.innerHTML.includes(item.id), `renderMerchantMarketPanel 應渲染黑市商品 ${item.id}`);
2895
+ }
2896
+ setupBazaarUI({ getGame: () => smokeGame, getClassInfo: () => ({}), getStudent: () => ({ uid: 'smoke' }) });
2897
+ }
2898
+ ok('西域萬國大市集 UI 契約、共用黑市面板、行動端 RWD 樣式與 index.html 載入檢驗 100% 通過');
2899
+
2900
  console.log(`\n🎉 全部 ${passedChecks} 大項工程防呆檢驗 100% 通過!可安全部署上線。`);