Xenova HF Staff commited on
Commit
cc7145c
·
verified ·
1 Parent(s): 2333566

Upload 3 files

Browse files
Files changed (3) hide show
  1. gemma-4-e2b.js +0 -0
  2. index.html +1508 -17
  3. landing.js +717 -0
gemma-4-e2b.js ADDED
The diff for this file is too large to render. See raw diff
 
index.html CHANGED
@@ -1,19 +1,1510 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
6
+ <meta name="color-scheme" content="dark" />
7
+ <title>Gemma 4 E2B · WebGPU</title>
8
+ <meta name="description" content="Gemma 4 E2B (QAT Mobile) running fully in your browser on WebGPU. Every kernel written and optimized by Fable 5." />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com">
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
+ <link href="https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600&family=Geist+Mono:wght@400;500&family=Instrument+Serif:ital@0;1&display=swap" rel="stylesheet">
12
+ <script type="importmap">
13
+ {
14
+ "imports": {
15
+ "three": "https://cdn.jsdelivr.net/npm/three@0.169.0/build/three.module.js",
16
+ "three/examples/jsm/": "https://cdn.jsdelivr.net/npm/three@0.169.0/examples/jsm/"
17
+ }
18
+ }
19
+ </script>
20
+ <style>
21
+ :root {
22
+ --bg: #020203;
23
+ --t1: rgba(255, 255, 255, 0.92);
24
+ --t2: rgba(255, 255, 255, 0.55);
25
+ --t3: rgba(255, 255, 255, 0.32);
26
+ --t4: rgba(255, 255, 255, 0.20);
27
+ --line: rgba(255, 255, 255, 0.08);
28
+ --line-soft: rgba(255, 255, 255, 0.06);
29
+ --panel: rgba(255, 255, 255, 0.03);
30
+ --panel-hover: rgba(255, 255, 255, 0.06);
31
+ --ok: #64ffa0;
32
+ --warn: #ffcd6b;
33
+ --danger: #ff7a6b;
34
+ --user-bubble: rgba(255, 255, 255, 0.065);
35
+
36
+ --display: "Instrument Serif", Georgia, "Times New Roman", serif;
37
+ --body: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
38
+ --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
39
+ --maxw: 820px;
40
+ }
41
+
42
+ * { box-sizing: border-box; margin: 0; padding: 0; }
43
+
44
+ html { height: 100%; }
45
+
46
+ body {
47
+ background: var(--bg);
48
+ color: var(--t1);
49
+ font-family: var(--body);
50
+ font-size: 16px;
51
+ font-weight: 400;
52
+ line-height: 1.6;
53
+ -webkit-font-smoothing: antialiased;
54
+ height: 100dvh;
55
+ overflow-x: hidden;
56
+ overflow-y: scroll;
57
+ scroll-behavior: smooth;
58
+ }
59
+
60
+ button, textarea, input { font: inherit; color: inherit; }
61
+ button { appearance: none; background: none; border: 0; cursor: pointer; }
62
+ a { color: inherit; text-decoration: none; }
63
+
64
+ ::selection { background: rgba(255, 255, 255, 0.18); }
65
+
66
+ body::-webkit-scrollbar { width: 0; }
67
+
68
+ .screen { min-height: 100dvh; position: relative; width: 100%; }
69
+
70
+ /* ====================================================================== */
71
+ /* LANDING */
72
+ /* ====================================================================== */
73
+
74
+ #landing {
75
+ display: flex;
76
+ flex-direction: column;
77
+ overflow: hidden;
78
+ }
79
+
80
+ #crt-frame {
81
+ position: absolute;
82
+ inset: 0;
83
+ z-index: 0;
84
+ overflow: hidden;
85
+ pointer-events: none;
86
+ opacity: 0;
87
+ transition: opacity 2.4s cubic-bezier(0.25, 0.1, 0.25, 1) 0.6s;
88
+ }
89
+ #crt-frame.visible { opacity: 1; }
90
+ #crt-frame canvas { display: block; width: 100% !important; height: 100% !important; pointer-events: none; }
91
+
92
+ .hero-fade {
93
+ position: absolute;
94
+ bottom: 0; left: 0;
95
+ width: 100%; height: 68%;
96
+ background: linear-gradient(to top, var(--bg) 0%, var(--bg) 14%, rgba(2, 2, 3, 0.55) 52%, transparent 100%);
97
+ z-index: 1;
98
+ pointer-events: none;
99
+ opacity: 0;
100
+ transition: opacity 2s ease 1s;
101
+ }
102
+ .hero-fade.in { opacity: 1; }
103
+
104
+ .hero-overlay {
105
+ position: relative;
106
+ z-index: 2;
107
+ flex: 1;
108
+ display: flex;
109
+ flex-direction: column;
110
+ pointer-events: none;
111
+ min-height: 100dvh;
112
+ }
113
+
114
+ /* used by the chat header's back-to-top link */
115
+ .brand-name {
116
+ font-family: var(--mono);
117
+ font-size: 12px;
118
+ font-weight: 500;
119
+ letter-spacing: 0.22em;
120
+ text-transform: uppercase;
121
+ color: var(--t1);
122
+ }
123
+
124
+ /* hero body — anchored to the bottom, over the darkened fade for legibility */
125
+ .hero-content {
126
+ flex: 1;
127
+ display: flex;
128
+ flex-direction: column;
129
+ justify-content: flex-end;
130
+ padding: 0 48px 18px;
131
+ pointer-events: none;
132
+ }
133
+ .eyebrow {
134
+ display: inline-flex;
135
+ align-items: center;
136
+ gap: 10px;
137
+ width: fit-content;
138
+ font-family: var(--mono);
139
+ font-size: 11px;
140
+ letter-spacing: 0.2em;
141
+ text-transform: uppercase;
142
+ color: var(--t3);
143
+ margin-bottom: 22px;
144
+ text-shadow: 0 2px 16px var(--bg);
145
+ }
146
+ .eyebrow::before {
147
+ content: "";
148
+ flex-shrink: 0;
149
+ width: 7px; height: 7px; border-radius: 50%;
150
+ background: var(--ok);
151
+ box-shadow: 0 0 12px rgba(100, 255, 160, 0.5);
152
+ animation: statusPulse 2.4s ease-in-out infinite;
153
+ }
154
+ .hero-h1 {
155
+ font-family: var(--display);
156
+ font-size: clamp(44px, 7.6vw, 100px);
157
+ font-weight: 400;
158
+ line-height: 0.98;
159
+ letter-spacing: -0.015em;
160
+ color: #fff;
161
+ margin-bottom: 30px;
162
+ max-width: 26ch;
163
+ text-shadow: 0 3px 40px var(--bg), 0 1px 14px rgba(2, 2, 3, 0.85);
164
+ }
165
+ .hero-h1 .thin { color: var(--t3); }
166
+
167
+ /* bottom row: description + stats (left), actions + credit (right) */
168
+ .hero-row {
169
+ display: flex;
170
+ align-items: flex-end;
171
+ justify-content: space-between;
172
+ gap: 56px;
173
+ }
174
+ .hero-main { display: flex; flex-direction: column; min-width: 0; }
175
+ .hero-sub {
176
+ font-size: 15px;
177
+ font-weight: 300;
178
+ line-height: 1.7;
179
+ color: var(--t2);
180
+ max-width: 52ch;
181
+ text-shadow: 0 2px 16px var(--bg), 0 1px 30px var(--bg);
182
+ margin-bottom: 26px;
183
+ }
184
+ .hero-sub b { color: var(--t1); font-weight: 500; }
185
+ .hero-stats { display: flex; flex-wrap: wrap; gap: 36px; }
186
+ .stat { display: flex; flex-direction: column; gap: 5px; }
187
+ .stat-val {
188
+ font-family: var(--display);
189
+ font-size: 30px;
190
+ font-weight: 400;
191
+ letter-spacing: -0.01em;
192
+ color: var(--t1);
193
+ line-height: 1;
194
+ text-shadow: 0 2px 16px var(--bg);
195
+ }
196
+ .stat-label {
197
+ font-family: var(--mono);
198
+ font-size: 10.5px;
199
+ letter-spacing: 0.12em;
200
+ text-transform: uppercase;
201
+ color: var(--t3);
202
+ }
203
+
204
+ /* right column */
205
+ .hero-side {
206
+ display: flex;
207
+ flex-direction: column;
208
+ align-items: flex-end;
209
+ gap: 18px;
210
+ flex-shrink: 0;
211
+ text-align: right;
212
+ }
213
+ .hero-actions {
214
+ display: flex;
215
+ align-items: center;
216
+ gap: 12px;
217
+ pointer-events: auto;
218
+ }
219
+
220
+ .btn-primary {
221
+ position: relative;
222
+ display: inline-flex;
223
+ align-items: center;
224
+ gap: 10px;
225
+ padding: 14px 28px;
226
+ color: #000;
227
+ font-size: 13.5px;
228
+ font-weight: 500;
229
+ letter-spacing: 0.01em;
230
+ border-radius: 100px;
231
+ border: 1px solid #fff;
232
+ white-space: nowrap;
233
+ overflow: hidden;
234
+ isolation: isolate;
235
+ transition: opacity 0.2s ease;
236
+ }
237
+ .btn-primary::before {
238
+ content: "";
239
+ position: absolute;
240
+ inset: 0;
241
+ background: #fff;
242
+ border-radius: inherit;
243
+ transform: scaleX(1);
244
+ transform-origin: left center;
245
+ transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
246
+ z-index: -1;
247
+ }
248
+ .btn-primary:hover:not(:disabled)::before { transform: scaleX(0); transform-origin: right center; }
249
+ .btn-primary:hover:not(:disabled) { color: #fff; }
250
+ .btn-primary svg { width: 14px; height: 14px; }
251
+ .btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
252
+
253
+ .btn-secondary {
254
+ display: inline-flex;
255
+ align-items: center;
256
+ gap: 9px;
257
+ padding: 14px 26px;
258
+ color: var(--t2);
259
+ font-size: 13.5px;
260
+ font-weight: 400;
261
+ border-radius: 100px;
262
+ border: 1px solid var(--line);
263
+ white-space: nowrap;
264
+ transition: border-color 0.25s ease, color 0.25s ease;
265
+ }
266
+ .btn-secondary:hover { border-color: rgba(255, 255, 255, 0.4); color: var(--t1); }
267
+ .btn-secondary svg { width: 12px; height: 12px; }
268
+
269
+ /* kernel credit + experimental note, in the right column */
270
+ .hero-foot {
271
+ display: flex;
272
+ flex-direction: column;
273
+ align-items: flex-end;
274
+ gap: 8px;
275
+ pointer-events: auto;
276
+ }
277
+ .kernel-note-cta {
278
+ width: fit-content;
279
+ font-size: 13px;
280
+ font-weight: 400;
281
+ color: var(--t2);
282
+ border-bottom: 1px solid var(--line);
283
+ padding-bottom: 2px;
284
+ transition: color 0.2s ease, border-color 0.2s ease;
285
+ }
286
+ .kernel-note-cta b { color: var(--t1); font-weight: 600; }
287
+ .kernel-note-cta:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.4); }
288
+ .hero-foot-note {
289
+ font-family: var(--mono);
290
+ font-size: 10px;
291
+ letter-spacing: 0.06em;
292
+ color: var(--t4);
293
+ }
294
+
295
+ /* scroll cue — sits at the very bottom of the hero, below the content */
296
+ .scroll-cue {
297
+ flex: 0 0 auto;
298
+ align-self: center;
299
+ display: flex;
300
+ flex-direction: column;
301
+ align-items: center;
302
+ gap: 9px;
303
+ padding-bottom: 18px;
304
+ pointer-events: none;
305
+ opacity: 0;
306
+ transition: opacity 0.8s ease 1.8s;
307
+ }
308
+ .scroll-cue.in { opacity: 1; }
309
+ .scroll-cue span {
310
+ font-family: var(--mono);
311
+ font-size: 9.5px;
312
+ letter-spacing: 0.2em;
313
+ text-transform: uppercase;
314
+ color: var(--t4);
315
+ }
316
+ .scroll-cue-line { width: 1px; height: 30px; background: var(--line); position: relative; overflow: hidden; }
317
+ .scroll-cue-line::after {
318
+ content: "";
319
+ position: absolute;
320
+ top: -100%; left: 0;
321
+ width: 100%; height: 100%;
322
+ background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.4), transparent);
323
+ animation: scrollDrop 2s ease-in-out infinite;
324
+ }
325
+
326
+ /* ====================================================================== */
327
+ /* CHAT */
328
+ /* ====================================================================== */
329
+
330
+ #chat {
331
+ display: flex;
332
+ flex-direction: column;
333
+ height: 100dvh;
334
+ background:
335
+ radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.035), transparent 55%),
336
+ var(--bg);
337
+ }
338
+
339
+ .chat-head {
340
+ position: relative;
341
+ flex: 0 0 auto;
342
+ border-bottom: 1px solid var(--line-soft);
343
+ background: rgba(2, 2, 3, 0.72);
344
+ backdrop-filter: blur(12px);
345
+ -webkit-backdrop-filter: blur(12px);
346
+ }
347
+ .chat-head-inner {
348
+ margin: 0 auto;
349
+ max-width: var(--maxw);
350
+ padding: 16px 28px;
351
+ display: flex;
352
+ align-items: center;
353
+ gap: 16px;
354
+ }
355
+ .to-top {
356
+ display: inline-flex;
357
+ align-items: center;
358
+ gap: 9px;
359
+ flex-shrink: 0;
360
+ transition: opacity 0.2s ease;
361
+ }
362
+ .to-top:hover { opacity: 0.7; }
363
+ .to-top svg { width: 13px; height: 13px; color: var(--t3); }
364
+ .to-top .brand-name { font-size: 11px; }
365
+
366
+ .status {
367
+ flex: 1;
368
+ min-width: 0;
369
+ display: flex;
370
+ align-items: center;
371
+ gap: 9px;
372
+ color: var(--t2);
373
+ font-size: 13px;
374
+ }
375
+ .status-dot {
376
+ width: 7px; height: 7px; border-radius: 50%;
377
+ background: var(--t4);
378
+ flex-shrink: 0;
379
+ transition: background 0.3s ease, box-shadow 0.3s ease;
380
+ }
381
+ .status.loading .status-dot { background: var(--warn); box-shadow: 0 0 10px rgba(255, 205, 107, 0.5); }
382
+ .status.ready .status-dot { background: var(--ok); box-shadow: 0 0 10px rgba(100, 255, 160, 0.5); }
383
+ .status.busy .status-dot { background: var(--ok); box-shadow: 0 0 10px rgba(100, 255, 160, 0.5); animation: statusPulse 1.1s ease-in-out infinite; }
384
+ .status.error .status-dot { background: var(--danger); box-shadow: 0 0 10px rgba(255, 122, 107, 0.5); }
385
+ .status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
386
+ .status-text strong { color: var(--t1); font-weight: 500; }
387
+
388
+ .chat-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
389
+ .head-btn {
390
+ display: inline-flex;
391
+ align-items: center;
392
+ gap: 7px;
393
+ padding: 8px 15px;
394
+ font-family: var(--mono);
395
+ font-size: 11px;
396
+ letter-spacing: 0.08em;
397
+ text-transform: uppercase;
398
+ color: var(--t2);
399
+ border: 1px solid var(--line);
400
+ border-radius: 100px;
401
+ transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
402
+ }
403
+ .head-btn:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.35); color: var(--t1); }
404
+ .head-btn:disabled { opacity: 0.35; cursor: not-allowed; }
405
+ .head-btn[hidden] { display: none; }
406
+ .head-btn.solid { background: #fff; color: #000; border-color: #fff; }
407
+ .head-btn.solid:hover:not(:disabled) { opacity: 0.85; color: #000; }
408
+
409
+ /* Absolutely positioned over the header's bottom edge so it can never affect layout —
410
+ no element shifts when loading starts or ends; the fill just fades out on completion. */
411
+ .bar {
412
+ position: absolute;
413
+ left: 0; right: 0; bottom: 0;
414
+ height: 2px;
415
+ overflow: hidden;
416
+ pointer-events: none;
417
+ }
418
+ .bar > div {
419
+ height: 100%;
420
+ width: 0%;
421
+ background: linear-gradient(90deg, var(--t2), #fff);
422
+ transition: opacity 0.4s ease; /* width is animated per-frame in JS (see stepProgressBar) */
423
+ }
424
+ .bar.done > div { opacity: 0; }
425
+
426
+ .thread-scroll {
427
+ flex: 1 1 auto;
428
+ min-height: 0;
429
+ overflow-y: auto;
430
+ scroll-behavior: smooth;
431
+ }
432
+ .thread {
433
+ margin: 0 auto;
434
+ max-width: var(--maxw);
435
+ min-height: 100%;
436
+ padding: 40px 28px 24px;
437
+ display: flex;
438
+ flex-direction: column;
439
+ gap: 32px;
440
+ }
441
+
442
+ .welcome {
443
+ margin: auto 0;
444
+ text-align: center;
445
+ padding: 4vh 0;
446
+ animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
447
+ }
448
+ .welcome h2 {
449
+ font-family: var(--display);
450
+ font-size: clamp(30px, 6vw, 46px);
451
+ font-weight: 400;
452
+ line-height: 1.05;
453
+ color: #fff;
454
+ margin-bottom: 14px;
455
+ }
456
+ .welcome h2 .thin { color: var(--t3); }
457
+ .welcome p { color: var(--t2); max-width: 46ch; margin: 0 auto 28px; font-weight: 300; }
458
+ .seeds { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
459
+ .seed {
460
+ padding: 9px 16px;
461
+ font-size: 13.5px;
462
+ color: var(--t2);
463
+ background: var(--panel);
464
+ border: 1px solid var(--line);
465
+ border-radius: 100px;
466
+ transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
467
+ }
468
+ .seed:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.3); color: var(--t1); background: var(--panel-hover); transform: translateY(-1px); }
469
+ .seed:disabled { opacity: 0.4; cursor: not-allowed; }
470
+
471
+ .msg { display: flex; flex-direction: column; animation: rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
472
+ .role {
473
+ display: flex;
474
+ align-items: center;
475
+ gap: 8px;
476
+ font-family: var(--mono);
477
+ font-size: 10.5px;
478
+ letter-spacing: 0.16em;
479
+ text-transform: uppercase;
480
+ margin-bottom: 10px;
481
+ }
482
+ .role::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
483
+ .msg.user { align-items: flex-end; }
484
+ .msg.user .role { color: var(--t3); }
485
+ .msg.user .role::before { background: var(--t3); }
486
+ .msg.assistant .role { color: var(--ok); }
487
+ .msg.assistant .role::before { background: var(--ok); }
488
+
489
+ .bubble { overflow-wrap: anywhere; }
490
+ .bubble.user {
491
+ background: var(--user-bubble);
492
+ border: 1px solid var(--line);
493
+ border-radius: 16px 16px 4px 16px;
494
+ padding: 12px 17px;
495
+ line-height: 1.55;
496
+ max-width: min(82%, 600px);
497
+ white-space: pre-wrap;
498
+ color: var(--t1);
499
+ }
500
+ .bubble.assistant { font-size: 16px; line-height: 1.72; color: var(--t1); max-width: 100%; }
501
+ .bubble.assistant > :first-child { margin-top: 0; }
502
+ .bubble.assistant > :last-child { margin-bottom: 0; }
503
+ .bubble.assistant p { margin: 0 0 0.9em; }
504
+ .bubble.assistant strong { color: #fff; font-weight: 600; }
505
+ .bubble.assistant em { font-style: italic; }
506
+ .bubble.assistant a { color: #8ab4ff; text-decoration: underline; text-underline-offset: 2px; }
507
+ .bubble.assistant a:hover { color: #aecbff; }
508
+ .bubble.assistant h1, .bubble.assistant h2, .bubble.assistant h3,
509
+ .bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 {
510
+ color: #fff; font-weight: 600; line-height: 1.25; margin: 1.3em 0 0.6em;
511
+ }
512
+ .bubble.assistant h1 { font-size: 1.5em; }
513
+ .bubble.assistant h2 { font-size: 1.3em; }
514
+ .bubble.assistant h3 { font-size: 1.13em; }
515
+ .bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 { font-size: 1em; }
516
+ .bubble.assistant ul, .bubble.assistant ol { margin: 0 0 0.9em; padding-left: 1.5em; }
517
+ .bubble.assistant li { margin: 0.25em 0; }
518
+ .bubble.assistant li::marker { color: var(--t3); }
519
+ .bubble.assistant blockquote {
520
+ margin: 0 0 0.9em; padding: 2px 0 2px 16px;
521
+ border-left: 2px solid var(--line); color: var(--t2);
522
+ }
523
+ .bubble.assistant hr { border: 0; border-top: 1px solid var(--line); margin: 1.3em 0; }
524
+ .bubble.assistant code {
525
+ font-family: var(--mono);
526
+ font-size: 0.85em;
527
+ background: var(--panel);
528
+ border: 1px solid var(--line);
529
+ border-radius: 5px;
530
+ padding: 1px 5px;
531
+ }
532
+ .bubble.assistant pre {
533
+ margin: 0 0 0.9em;
534
+ padding: 14px 16px;
535
+ background: #0a0a0c;
536
+ border: 1px solid var(--line);
537
+ border-radius: 12px;
538
+ overflow-x: auto;
539
+ }
540
+ .bubble.assistant pre code { background: none; border: 0; padding: 0; font-size: 0.82em; line-height: 1.6; }
541
+ .bubble.assistant table { border-collapse: collapse; margin: 0 0 0.9em; font-size: 0.92em; display: block; overflow-x: auto; }
542
+ .bubble.assistant th, .bubble.assistant td { border: 1px solid var(--line); padding: 6px 11px; text-align: left; }
543
+ .bubble.assistant th { background: var(--panel); color: var(--t1); font-weight: 600; }
544
+ .bubble.assistant pre::-webkit-scrollbar, .bubble.assistant table::-webkit-scrollbar { height: 8px; }
545
+ .bubble.assistant pre::-webkit-scrollbar-thumb, .bubble.assistant table::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
546
+
547
+ .meta {
548
+ font-family: var(--mono);
549
+ font-size: 10.5px;
550
+ letter-spacing: 0.04em;
551
+ color: var(--t3);
552
+ margin-top: 12px;
553
+ }
554
+
555
+ .thinking { display: inline-flex; gap: 5px; padding: 4px 0; }
556
+ .thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); opacity: 0.5; animation: bob 1.3s ease-in-out infinite; }
557
+ .thinking span:nth-child(2) { animation-delay: 0.18s; }
558
+ .thinking span:nth-child(3) { animation-delay: 0.36s; }
559
+
560
+ .caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 2px; vertical-align: -0.16em; background: var(--ok); animation: blink 1s steps(2) infinite; }
561
+
562
+ .composer-wrap {
563
+ flex: 0 0 auto;
564
+ background: linear-gradient(rgba(2, 2, 3, 0), var(--bg) 30%);
565
+ padding-top: 8px;
566
+ }
567
+ .composer { margin: 0 auto; max-width: var(--maxw); padding: 0 28px 22px; }
568
+ .field {
569
+ display: grid;
570
+ grid-template-columns: 1fr 44px;
571
+ align-items: flex-end;
572
+ gap: 8px;
573
+ background: var(--panel);
574
+ border: 1px solid var(--line);
575
+ border-radius: 18px;
576
+ padding: 8px 8px 8px 18px;
577
+ transition: border-color 0.2s ease, background 0.2s ease;
578
+ }
579
+ .field:focus-within { border-color: rgba(255, 255, 255, 0.28); background: rgba(255, 255, 255, 0.05); }
580
+ textarea {
581
+ background: transparent;
582
+ border: 0;
583
+ outline: none;
584
+ resize: none;
585
+ width: 100%;
586
+ min-height: 42px;
587
+ max-height: 180px;
588
+ padding: 8px 0;
589
+ color: var(--t1);
590
+ }
591
+ textarea::placeholder { color: var(--t3); }
592
+
593
+ .icon-button {
594
+ display: grid;
595
+ place-items: center;
596
+ width: 42px;
597
+ height: 42px;
598
+ border-radius: 13px;
599
+ transition: background 0.2s ease, opacity 0.2s ease, transform 0.1s ease;
600
+ }
601
+ .icon-button svg { width: 19px; height: 19px; }
602
+ .icon-button:active:not(:disabled) { transform: scale(0.94); }
603
+ .icon-button:disabled { opacity: 0.3; cursor: not-allowed; }
604
+ .send-button { background: #fff; color: #000; }
605
+ .send-button:hover:not(:disabled) { opacity: 0.86; }
606
+ .stop-button { background: rgba(255, 122, 107, 0.14); color: var(--danger); border: 1px solid rgba(255, 122, 107, 0.3); display: none; }
607
+ .stop-button:hover:not(:disabled) { background: rgba(255, 122, 107, 0.22); }
608
+
609
+ .composer-meta {
610
+ display: flex;
611
+ align-items: center;
612
+ justify-content: center;
613
+ gap: 12px;
614
+ margin: 10px 4px 0;
615
+ min-height: 22px;
616
+ font-family: var(--mono);
617
+ font-size: 10.5px;
618
+ letter-spacing: 0.04em;
619
+ text-transform: uppercase;
620
+ color: var(--t3);
621
+ }
622
+
623
+ .thread-scroll::-webkit-scrollbar { width: 10px; }
624
+ .thread-scroll::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--bg); border-radius: 10px; }
625
+
626
+ :focus-visible { outline: 1px solid rgba(255, 255, 255, 0.45); outline-offset: 3px; }
627
+ /* The composer already shows focus via .field:focus-within — suppress the textarea's own outline. */
628
+ textarea:focus, textarea:focus-visible { outline: none; }
629
+
630
+ /* ====================================================================== */
631
+ /* kernels overlay */
632
+ /* ====================================================================== */
633
+
634
+ .kx {
635
+ position: fixed;
636
+ inset: 0;
637
+ z-index: 50;
638
+ display: flex;
639
+ align-items: center;
640
+ justify-content: center;
641
+ padding: 28px;
642
+ }
643
+ .kx[hidden] { display: none; }
644
+ .kx-backdrop {
645
+ position: absolute;
646
+ inset: 0;
647
+ background: rgba(0, 0, 0, 0.62);
648
+ backdrop-filter: blur(6px);
649
+ -webkit-backdrop-filter: blur(6px);
650
+ animation: kxFade 0.25s ease;
651
+ }
652
+ .kx-panel {
653
+ position: relative;
654
+ display: flex;
655
+ flex-direction: column;
656
+ width: min(1080px, 100%);
657
+ height: min(86vh, 920px);
658
+ background: #0a0a0c;
659
+ border: 1px solid var(--line);
660
+ border-radius: 18px;
661
+ overflow: hidden;
662
+ box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.9);
663
+ animation: kxRise 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
664
+ }
665
+ .kx-head {
666
+ display: flex;
667
+ align-items: flex-start;
668
+ justify-content: space-between;
669
+ gap: 16px;
670
+ padding: 20px 22px;
671
+ border-bottom: 1px solid var(--line-soft);
672
+ }
673
+ .kx-title h3 { font-family: var(--display); font-weight: 400; font-size: 26px; color: #fff; line-height: 1; }
674
+ .kx-sub { display: block; margin-top: 7px; font-size: 12.5px; color: var(--t3); }
675
+ .kx-close {
676
+ display: grid;
677
+ place-items: center;
678
+ width: 34px; height: 34px;
679
+ flex-shrink: 0;
680
+ border-radius: 9px;
681
+ color: var(--t2);
682
+ border: 1px solid var(--line);
683
+ transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
684
+ }
685
+ .kx-close:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.35); background: var(--panel); }
686
+ .kx-close svg { width: 15px; height: 15px; }
687
+ .kx-body { flex: 1; display: grid; grid-template-columns: 236px 1fr; min-height: 0; }
688
+ .kx-side {
689
+ position: relative;
690
+ min-width: 0;
691
+ min-height: 0;
692
+ border-right: 1px solid var(--line-soft);
693
+ }
694
+ .kx-list {
695
+ height: 100%;
696
+ overflow-y: auto;
697
+ padding: 10px;
698
+ display: flex;
699
+ flex-direction: column;
700
+ gap: 2px;
701
+ }
702
+ /* fade hinting more kernels are scrollable below; fades out at the end of the list */
703
+ .kx-side::after {
704
+ content: "";
705
+ position: absolute;
706
+ left: 0; right: 1px; bottom: 0;
707
+ height: 54px;
708
+ background: linear-gradient(transparent, #0a0a0c 88%);
709
+ pointer-events: none;
710
+ opacity: 1;
711
+ transition: opacity 0.25s ease;
712
+ }
713
+ .kx-side.at-end::after { opacity: 0; }
714
+ .kx-item {
715
+ flex-shrink: 0;
716
+ text-align: left;
717
+ padding: 9px 12px;
718
+ border-radius: 8px;
719
+ font-family: var(--mono);
720
+ font-size: 12px;
721
+ line-height: 1.5;
722
+ color: var(--t2);
723
+ white-space: nowrap;
724
+ overflow: hidden;
725
+ text-overflow: ellipsis;
726
+ transition: background 0.15s ease, color 0.15s ease;
727
+ }
728
+ .kx-item:hover { background: var(--panel); color: var(--t1); }
729
+ .kx-item.active { background: var(--panel-hover); color: #fff; }
730
+ .kx-view { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
731
+ .kx-view-head {
732
+ display: flex;
733
+ align-items: center;
734
+ justify-content: space-between;
735
+ gap: 12px;
736
+ padding: 12px 18px;
737
+ border-bottom: 1px solid var(--line-soft);
738
+ }
739
+ .kx-name { font-family: var(--mono); font-size: 13px; color: var(--t1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
740
+ .kx-view-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
741
+ .kx-lines { font-family: var(--mono); font-size: 11px; color: var(--t4); }
742
+ .kx-copy {
743
+ font-family: var(--mono);
744
+ font-size: 11px;
745
+ text-transform: uppercase;
746
+ letter-spacing: 0.08em;
747
+ color: var(--t2);
748
+ border: 1px solid var(--line);
749
+ border-radius: 100px;
750
+ padding: 5px 13px;
751
+ transition: color 0.2s ease, border-color 0.2s ease;
752
+ }
753
+ .kx-copy:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.35); }
754
+ .kx-code {
755
+ flex: 1;
756
+ min-height: 0;
757
+ min-width: 0;
758
+ overflow: auto;
759
+ margin: 0;
760
+ padding: 18px 20px;
761
+ font-family: var(--mono);
762
+ font-size: 12.5px;
763
+ line-height: 1.65;
764
+ color: var(--t2);
765
+ tab-size: 2;
766
+ }
767
+ .kx-code code { white-space: pre; }
768
+ /* WGSL syntax highlight */
769
+ .k-cm { color: #5d6b6f; font-style: italic; }
770
+ .k-kw { color: #c792ea; }
771
+ .k-ty { color: #6fb3ff; }
772
+ .k-at { color: #ffb074; }
773
+ .k-nu { color: #7ee787; }
774
+ .kx-code::-webkit-scrollbar, .kx-list::-webkit-scrollbar { width: 10px; height: 10px; }
775
+ .kx-code::-webkit-scrollbar-thumb, .kx-list::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid #0a0a0c; border-radius: 10px; }
776
+ /* while the overlay is open, lock the page behind it so only the overlay's panes scroll */
777
+ body.kx-locked { overflow: hidden; }
778
+ @keyframes kxFade { from { opacity: 0; } to { opacity: 1; } }
779
+ @keyframes kxRise { from { opacity: 0; transform: translateY(12px) scale(0.99); } to { opacity: 1; transform: none; } }
780
+
781
+ @media (max-width: 760px) {
782
+ .kx { padding: 0; }
783
+ .kx-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
784
+ .kx-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
785
+ .kx-side { border-right: 0; border-bottom: 1px solid var(--line-soft); }
786
+ .kx-side::after { display: none; }
787
+ .kx-list { flex-direction: row; height: auto; overflow-x: auto; overflow-y: hidden; }
788
+ .kx-item { flex-shrink: 0; }
789
+ }
790
+
791
+ /* ====================================================================== */
792
+ /* entrance + keyframes */
793
+ /* ====================================================================== */
794
+
795
+ .anim { opacity: 0; transition: opacity 0.9s cubic-bezier(0.25, 0.1, 0.25, 1); }
796
+ .anim.in { opacity: 1; }
797
+ .eyebrow { transition-delay: 0.35s; }
798
+ .hero-h1 { transition-delay: 0.5s; }
799
+ .hero-row { transition-delay: 0.78s; }
800
+
801
+ @keyframes statusPulse {
802
+ 0%, 100% { opacity: 1; }
803
+ 50% { opacity: 0.3; }
804
+ }
805
+ @keyframes scrollDrop {
806
+ 0% { top: -100%; }
807
+ 55% { top: 100%; }
808
+ 100% { top: 100%; }
809
+ }
810
+ @keyframes rise {
811
+ from { opacity: 0; transform: translateY(10px); }
812
+ to { opacity: 1; transform: none; }
813
+ }
814
+ @keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
815
+ @keyframes bob {
816
+ 0%, 60%, 100% { opacity: 0.5; transform: translateY(0); }
817
+ 30% { opacity: 1; transform: translateY(-5px); }
818
+ }
819
+
820
+ @media (prefers-reduced-motion: reduce) {
821
+ *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
822
+ .anim, #crt-frame, .hero-fade, .scroll-cue { opacity: 1 !important; }
823
+ .caret { opacity: 1; }
824
+ }
825
+
826
+ /* ====================================================================== */
827
+ /* responsive */
828
+ /* ====================================================================== */
829
+
830
+ @media (max-width: 760px) {
831
+ .hero-content { padding: 0 22px 22px; }
832
+ .hero-h1 { font-size: clamp(38px, 12vw, 60px); margin-bottom: 24px; max-width: none; }
833
+ .hero-row { flex-direction: column; align-items: stretch; gap: 28px; }
834
+ .hero-side { align-items: flex-start; text-align: left; }
835
+ .hero-foot { align-items: flex-start; }
836
+ .hero-actions { flex-wrap: wrap; }
837
+ .hero-stats { gap: 22px 30px; }
838
+ .stat-val { font-size: 24px; }
839
+ .scroll-cue { display: none; }
840
+ .chat-head-inner { padding: 13px 18px; gap: 12px; }
841
+ .to-top .brand-name { display: none; }
842
+ .thread { padding: 28px 18px 20px; }
843
+ .composer { padding: 0 18px 18px; }
844
+ .bubble.user { max-width: 88%; }
845
+ .head-btn { padding: 8px 12px; }
846
+ }
847
+ </style>
848
+ </head>
849
+ <body>
850
+
851
+ <!-- ======================= LANDING ======================= -->
852
+ <section id="landing" class="screen">
853
+ <div id="crt-frame"></div>
854
+ <div class="hero-fade"></div>
855
+
856
+ <div class="hero-overlay">
857
+ <div class="hero-content">
858
+ <div class="eyebrow anim">On-device · WebGPU · agentic kernel optimization</div>
859
+ <h1 class="hero-h1 anim">Gemma 4 in your browser.<br><span class="thin">Kernels written by Fable 5.</span></h1>
860
+ <div class="hero-row anim">
861
+ <div class="hero-main">
862
+ <p class="hero-sub">
863
+ <b>Gemma&nbsp;4 E2B (QAT Mobile)</b> — effectively a 2.3B-parameter reasoning model — runs
864
+ fully on-device with WebGPU. Weights cache locally after the first load, and nothing you
865
+ type ever leaves your machine.
866
+ </p>
867
+ <div class="hero-stats">
868
+ <div class="stat"><span class="stat-val">2.3B</span><span class="stat-label">Effective params</span></div>
869
+ <div class="stat"><span class="stat-val">128K</span><span class="stat-label">Context window</span></div>
870
+ <div class="stat"><span class="stat-val">~250</span><span class="stat-label">tok/s · M4&nbsp;Max</span></div>
871
+ <div class="stat"><span class="stat-val">100%</span><span class="stat-label">On-device</span></div>
872
+ </div>
873
+ </div>
874
+ <div class="hero-side">
875
+ <div class="hero-actions">
876
+ <button class="btn-primary" id="loadBtn" type="button">
877
+ <span id="loadBtnLabel">Load model</span>
878
+ <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v9M4 7l4 4 4-4"/></svg>
879
+ </button>
880
+ <a class="btn-secondary" href="https://huggingface.co/google/gemma-4-E2B-it-qat-mobile-transformers" target="_blank" rel="noopener">Model card</a>
881
+ </div>
882
+ <div class="hero-foot">
883
+ <a class="kernel-note-cta" href="https://x.com/xenovacom/status/2065656427117437213" target="_blank" rel="noopener">WebGPU kernels <b>100% written &amp; optimized by Fable&nbsp;5</b> →</a>
884
+ <span class="hero-foot-note">Tuned for Apple M4 Max · experimental</span>
885
+ </div>
886
+ </div>
887
+ </div>
888
+ </div>
889
+
890
+ <div class="scroll-cue" id="scrollCue">
891
+ <span>Chat below</span>
892
+ <div class="scroll-cue-line"></div>
893
+ </div>
894
+ </div>
895
+ </section>
896
+
897
+ <!-- ======================= CHAT ======================= -->
898
+ <section id="chat" class="screen">
899
+ <header class="chat-head">
900
+ <div class="chat-head-inner">
901
+ <a class="to-top" href="#landing" id="toTop" title="Back to top">
902
+ <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M8 13V4M4 8l4-4 4 4"/></svg>
903
+ <span class="brand-name">Gemma 4 · E2B</span>
904
+ </a>
905
+ <div class="status" id="status">
906
+ <span class="status-dot"></span>
907
+ <span class="status-text" id="statusText">Not loaded</span>
908
+ </div>
909
+ <div class="chat-head-actions">
910
+ <button class="head-btn solid" id="headLoadBtn" type="button">Load model</button>
911
+ <button class="head-btn" id="kernelsBtn" type="button" hidden>View Kernels</button>
912
+ <button class="head-btn" id="clearBtn" type="button" disabled>Clear</button>
913
+ </div>
914
+ </div>
915
+ <div class="bar" id="bar"><div></div></div>
916
+ </header>
917
+
918
+ <div class="thread-scroll" id="threadScroll">
919
+ <div class="thread" id="thread">
920
+ <div class="welcome" id="welcome">
921
+ <h2>What's on your <span class="thin">mind today?</span></h2>
922
+ <p>Model runs entirely on your device.</p>
923
+ <div class="seeds">
924
+ <button class="seed" type="button" disabled>How does WebGPU differ from WebGL?</button>
925
+ <button class="seed" type="button" disabled>Write a haiku about on-device AI</button>
926
+ <button class="seed" type="button" disabled>What is quantization-aware training?</button>
927
+ </div>
928
+ </div>
929
+ </div>
930
+ </div>
931
+
932
+ <footer class="composer-wrap">
933
+ <div class="composer">
934
+ <div class="field">
935
+ <textarea id="input" rows="1" placeholder="Load the model to start chatting..." disabled></textarea>
936
+ <button class="icon-button send-button" id="sendBtn" type="button" disabled aria-label="Send message">
937
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></svg>
938
+ </button>
939
+ <button class="icon-button stop-button" id="stopBtn" type="button" aria-label="Stop generation">
940
+ <svg viewBox="0 0 24 24" fill="currentColor"><rect x="7" y="7" width="10" height="10" rx="1.5"/></svg>
941
+ </button>
942
+ </div>
943
+ <div class="composer-meta">
944
+ <span id="hint">Runs fully on-device — nothing leaves your machine</span>
945
+ <span id="liveStat"></span>
946
+ </div>
947
+ </div>
948
+ </footer>
949
+ </section>
950
+
951
+ <!-- ============ KERNELS OVERLAY ============ -->
952
+ <div class="kx" id="kernelsOverlay" hidden>
953
+ <div class="kx-backdrop" data-close></div>
954
+ <div class="kx-panel" role="dialog" aria-modal="true" aria-label="Rendered kernels">
955
+ <div class="kx-head">
956
+ <div class="kx-title">
957
+ <h3>Kernels</h3>
958
+ <span class="kx-sub" id="kxSub"></span>
959
+ </div>
960
+ <button class="kx-close" id="kxClose" type="button" aria-label="Close" data-close>
961
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg>
962
+ </button>
963
+ </div>
964
+ <div class="kx-body">
965
+ <div class="kx-side"><div class="kx-list" id="kxList"></div></div>
966
+ <div class="kx-view">
967
+ <div class="kx-view-head">
968
+ <span class="kx-name" id="kxName"></span>
969
+ <div class="kx-view-actions">
970
+ <span class="kx-lines" id="kxLines"></span>
971
+ <button class="kx-copy" id="kxCopy" type="button">Copy</button>
972
+ </div>
973
+ </div>
974
+ <pre class="kx-code"><code id="kxCode"></code></pre>
975
+ </div>
976
+ </div>
977
+ </div>
978
+ </div>
979
+
980
+ <!-- landing background animation (WebGL / three.js) -->
981
+ <script type="module" src="./landing.js"></script>
982
+
983
+ <!-- entrance sequencer (runs independently of the background so the hero shows even if
984
+ the WebGL/three.js scene fails to load) -->
985
+ <script>
986
+ (function () {
987
+ const fire = () => {
988
+ document.getElementById("crt-frame")?.classList.add("visible");
989
+ document.querySelector(".hero-fade")?.classList.add("in");
990
+ document.querySelectorAll(".anim").forEach((el) => el.classList.add("in"));
991
+ document.getElementById("scrollCue")?.classList.add("in");
992
+ };
993
+ requestAnimationFrame(() => requestAnimationFrame(fire));
994
+ })();
995
+ </script>
996
+
997
+ <!-- app logic -->
998
+ <script type="module">
999
+ import { Gemma4Mobile } from "./gemma-4-e2b.js";
1000
+
1001
+ // Streamed markdown → HTML. `streamdown` itself is React-only (peer deps react/react-dom plus a
1002
+ // mermaid + unified/remark/rehype dep tree), so we use `marked` — the very parser streamdown is
1003
+ // built on — loaded lazily from a CDN. Until it loads (or if the CDN is unreachable) we fall
1004
+ // back to the tiny inline renderer below, so chat never depends on it.
1005
+ let marked = null;
1006
+ import("https://esm.sh/marked@17")
1007
+ .then((m) => { marked = m.marked; marked.use({ gfm: true, breaks: true }); })
1008
+ .catch(() => { marked = null; });
1009
+
1010
+ const $ = (id) => document.getElementById(id);
1011
+ const landing = $("landing");
1012
+ const chat = $("chat");
1013
+ const threadScroll = $("threadScroll");
1014
+ const thread = $("thread");
1015
+ const loadBtn = $("loadBtn");
1016
+ const loadBtnLabel = $("loadBtnLabel");
1017
+ const headLoadBtn = $("headLoadBtn");
1018
+ const statusEl = $("status");
1019
+ const statusText = $("statusText");
1020
+ const bar = $("bar");
1021
+ const barFill = bar.firstElementChild;
1022
+ const input = $("input");
1023
+ const sendBtn = $("sendBtn");
1024
+ const stopBtn = $("stopBtn");
1025
+ const clearBtn = $("clearBtn");
1026
+ const hint = $("hint");
1027
+ const liveStat = $("liveStat");
1028
+ const kernelsBtn = $("kernelsBtn");
1029
+ const kernelsOverlay = $("kernelsOverlay");
1030
+
1031
+ let model = null;
1032
+ let kernels = [];
1033
+ let kxCopySource = "";
1034
+ let messages = [];
1035
+ let abortController = null;
1036
+ let isGenerating = false;
1037
+ let isLoading = false;
1038
+ let renderScheduled = false;
1039
+ let renderState = null;
1040
+ let targetProgress = 0; // latest monotonic load fraction [0,1]
1041
+ let shownProgress = 0; // currently rendered bar fraction (eased toward target each frame)
1042
+ let progressRaf = 0;
1043
+
1044
+ if (!navigator.gpu) {
1045
+ const msg = "WebGPU isn't available here. Try a recent Chrome, Edge, or Safari Technology Preview.";
1046
+ loadBtn.disabled = true;
1047
+ headLoadBtn.disabled = true;
1048
+ setStatus("error", msg);
1049
+ }
1050
+
1051
+ loadBtn.addEventListener("click", loadModel);
1052
+ headLoadBtn.addEventListener("click", loadModel);
1053
+ sendBtn.addEventListener("click", send);
1054
+ stopBtn.addEventListener("click", () => abortController?.abort());
1055
+ clearBtn.addEventListener("click", clearChat);
1056
+ kernelsBtn.addEventListener("click", openKernels);
1057
+ kernelsOverlay.addEventListener("click", (e) => { if (e.target.closest("[data-close]")) closeKernels(); });
1058
+ $("kxList").addEventListener("scroll", updateListFade, { passive: true });
1059
+ $("kxCopy").addEventListener("click", copyKernel);
1060
+ document.addEventListener("keydown", (e) => { if (e.key === "Escape" && !kernelsOverlay.hidden) closeKernels(); });
1061
+ $("toTop").addEventListener("click", (e) => { e.preventDefault(); landing.scrollIntoView({ behavior: "smooth" }); });
1062
+
1063
+ input.addEventListener("input", () => { autoGrow(); refreshSend(); });
1064
+ input.addEventListener("keydown", (e) => {
1065
+ if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); if (!sendBtn.disabled) send(); }
1066
+ });
1067
+ document.addEventListener("click", (e) => {
1068
+ const seed = e.target.closest(".seed");
1069
+ if (!seed || seed.disabled || !model || isGenerating) return;
1070
+ input.value = seed.textContent;
1071
+ send();
1072
+ });
1073
+
1074
+ function setStatus(state, text) {
1075
+ statusEl.className = "status" + (state ? " " + state : "");
1076
+ if (text !== undefined) statusText.innerHTML = text;
1077
+ }
1078
+
1079
+ async function loadModel() {
1080
+ if (model || isLoading) return;
1081
+ isLoading = true;
1082
+ loadBtn.disabled = true;
1083
+ headLoadBtn.disabled = true;
1084
+ loadBtnLabel.textContent = "Loading…";
1085
+ bar.classList.remove("done");
1086
+ setProgressImmediate(0.02);
1087
+ setStatus("loading", "Requesting WebGPU device…");
1088
+
1089
+ // Move the visitor down into the chat where progress + conversation live.
1090
+ chat.scrollIntoView({ behavior: "smooth" });
1091
+
1092
+ const started = performance.now();
1093
+ try {
1094
+ model = await Gemma4Mobile.load(null, { onProgress: updateLoadProgress });
1095
+ setStatus("loading", "Warming up kernels…");
1096
+ await model.warmup();
1097
+
1098
+ const seconds = ((performance.now() - started) / 1000).toFixed(1);
1099
+ setStatus("ready", `Ready in <strong>${seconds}s</strong> · on-device`);
1100
+ setProgressImmediate(1);
1101
+ bar.classList.add("done");
1102
+ loadBtnLabel.textContent = "Model loaded";
1103
+ headLoadBtn.style.display = "none";
1104
+ enableChat();
1105
+ } catch (error) {
1106
+ console.error(error);
1107
+ setStatus("error", `Failed to load: ${escapeHtml(String(error?.message ?? error))}`);
1108
+ bar.classList.add("done");
1109
+ loadBtn.disabled = false;
1110
+ headLoadBtn.disabled = false;
1111
+ loadBtnLabel.textContent = "Load model";
1112
+ isLoading = false;
1113
+ }
1114
+ }
1115
+
1116
+ function labelFor(status) {
1117
+ return {
1118
+ init: "Requesting WebGPU device…",
1119
+ tokenizer: "Loading tokenizer…",
1120
+ weights: "Downloading weights…",
1121
+ ready: "Ready.",
1122
+ }[status] ?? status;
1123
+ }
1124
+
1125
+ function updateLoadProgress(event) {
1126
+ if (event.status !== "weights") {
1127
+ setStatus("loading", labelFor(event.status));
1128
+ setPhaseProgress(event.status, event.fraction);
1129
+ return;
1130
+ }
1131
+ const kind = event.kind ?? inferProgressKind(event);
1132
+ const fraction = finiteNumber(event.fraction) ? clamp(event.fraction, 0, 1) : null;
1133
+ // Drive the bar off the BYTE download only. The "tensors" stream counts materialized tensors,
1134
+ // which races far ahead of the download (the many small tensors finish while the big embedding
1135
+ // weights are still downloading by size), so it would leap the bar past the real progress.
1136
+ // Tensor events still update the status text below.
1137
+ if (kind !== "tensors") setPhaseProgress("weights", fraction);
1138
+ setStatus("loading", formatWeightProgress(event, fraction));
1139
+ }
1140
+
1141
+ // Map each load phase onto an increasing slice of the bar (weights — the byte download — owns the
1142
+ // bulk). setProgressFraction's monotonic guard keeps it from ever dipping.
1143
+ function setPhaseProgress(status, frac) {
1144
+ const [lo, hi] = status === "weights"
1145
+ ? [0.04, 1.0]
1146
+ : ({ init: [0, 0.02], tokenizer: [0.02, 0.04], ready: [1, 1] }[status] ?? [0, 1]);
1147
+ const f = finiteNumber(frac) ? clamp(frac, 0, 1) : 0;
1148
+ setProgressFraction(lo + (hi - lo) * f);
1149
+ }
1150
+
1151
+ function formatWeightProgress(event, fraction) {
1152
+ const kind = event.kind ?? inferProgressKind(event);
1153
+ const pct = fraction === null ? "" : ` (${Math.round(fraction * 100)}%)`;
1154
+ const loaded = finiteNumber(event.loaded) ? event.loaded : null;
1155
+ const total = finiteNumber(event.total) ? event.total : null;
1156
+ if (kind === "bytes") {
1157
+ const verb = event.fromCache ? "Loading cached weights" : "Downloading weights";
1158
+ if (loaded !== null && total !== null) return `${verb}: ${formatBytes(loaded)} / ${formatBytes(total)}${pct}`;
1159
+ if (total !== null) return `${verb}: ${formatBytes(total)} total`;
1160
+ return `${escapeHtml(event.message || verb)}…`;
1161
+ }
1162
+ if (loaded !== null && total !== null) {
1163
+ const label = event.message ? ` (${escapeHtml(event.message)})` : "";
1164
+ return `Preparing GPU weights: ${formatInteger(loaded)} / ${formatInteger(total)} tensors${pct}${label}`;
1165
+ }
1166
+ return event.message ? `Preparing GPU weights: ${escapeHtml(event.message)}` : "Preparing GPU weights…";
1167
+ }
1168
+
1169
+ function inferProgressKind(event) {
1170
+ if (event.kind === "bytes" || event.kind === "tensors") return event.kind;
1171
+ if (finiteNumber(event.total) && event.total > 1_000_000) return "bytes";
1172
+ return "tensors";
1173
+ }
1174
+
1175
+ // Record the latest (monotonic) target and let a single rAF loop ease the bar toward it. This
1176
+ // coalesces bursts of byte-progress events into one write per frame and — unlike a fixed CSS
1177
+ // width transition — never lags behind fast progress (a big remaining gap is closed quickly).
1178
+ function setProgressFraction(value) {
1179
+ if (!finiteNumber(value)) return;
1180
+ targetProgress = Math.max(clamp(value, 0, 1), targetProgress); // monotonic — never hops backwards
1181
+ if (!progressRaf) progressRaf = requestAnimationFrame(stepProgressBar);
1182
+ }
1183
+
1184
+ function stepProgressBar() {
1185
+ const gap = targetProgress - shownProgress;
1186
+ shownProgress += gap < 0.0015 ? gap : gap * 0.3; // ~30% of the gap per frame; snap when nearly there
1187
+ barFill.style.width = `${(shownProgress * 100).toFixed(2)}%`;
1188
+ progressRaf = shownProgress < targetProgress ? requestAnimationFrame(stepProgressBar) : 0;
1189
+ }
1190
+
1191
+ function setProgressImmediate(value) {
1192
+ if (progressRaf) { cancelAnimationFrame(progressRaf); progressRaf = 0; }
1193
+ targetProgress = shownProgress = clamp(value, 0, 1);
1194
+ barFill.style.width = `${(shownProgress * 100).toFixed(2)}%`;
1195
+ }
1196
+
1197
+ function enableChat() {
1198
+ isLoading = false;
1199
+ input.disabled = false;
1200
+ input.placeholder = "Ask anything…";
1201
+ clearBtn.disabled = false;
1202
+ kernelsBtn.hidden = false;
1203
+ setSeedButtonsEnabled(true);
1204
+ refreshSend();
1205
+ input.focus();
1206
+ }
1207
+
1208
+ // ---- Kernels viewer: the real rendered WGSL the model compiled on this GPU ----
1209
+ function openKernels() {
1210
+ if (!model) return;
1211
+ kernels = model.runtime.getRenderedShaders?.() ?? [];
1212
+ const list = $("kxList");
1213
+ list.replaceChildren();
1214
+ $("kxSub").textContent = kernels.length
1215
+ ? `${kernels.length} WGSL compute shaders · written & optimized by Fable 5 · running on your GPU`
1216
+ : "No kernels compiled yet — send a message first.";
1217
+ kernels.forEach((k, i) => {
1218
+ const item = document.createElement("button");
1219
+ item.className = "kx-item";
1220
+ item.type = "button";
1221
+ item.textContent = k.name;
1222
+ item.addEventListener("click", () => selectKernel(i));
1223
+ list.appendChild(item);
1224
+ });
1225
+ if (kernels.length) selectKernel(0);
1226
+ else { $("kxName").textContent = ""; $("kxLines").textContent = ""; $("kxCode").textContent = ""; kxCopySource = ""; }
1227
+ kernelsOverlay.hidden = false;
1228
+ document.body.classList.add("kx-locked");
1229
+ $("kxList").scrollTop = 0;
1230
+ requestAnimationFrame(updateListFade);
1231
+ }
1232
+
1233
+ // Toggle the bottom fade on the kernel list: shown while there is more to scroll, hidden at the end.
1234
+ function updateListFade() {
1235
+ const list = $("kxList");
1236
+ const atEnd = list.scrollHeight <= list.clientHeight + 4
1237
+ || list.scrollTop >= list.scrollHeight - list.clientHeight - 4;
1238
+ list.parentElement.classList.toggle("at-end", atEnd);
1239
+ }
1240
+
1241
+ function selectKernel(i) {
1242
+ const k = kernels[i];
1243
+ if (!k) return;
1244
+ [...$("kxList").children].forEach((el, j) => el.classList.toggle("active", j === i));
1245
+ $("kxName").textContent = k.name;
1246
+ $("kxLines").textContent = `${k.source.split("\n").length} lines`;
1247
+ $("kxCode").innerHTML = highlightWgsl(k.source);
1248
+ $("kxCode").parentElement.scrollTop = 0;
1249
+ kxCopySource = k.source;
1250
+ }
1251
+
1252
+ function closeKernels() {
1253
+ kernelsOverlay.hidden = true;
1254
+ document.body.classList.remove("kx-locked");
1255
+ }
1256
+
1257
+ async function copyKernel() {
1258
+ if (!kxCopySource) return;
1259
+ try {
1260
+ await navigator.clipboard.writeText(kxCopySource);
1261
+ const btn = $("kxCopy");
1262
+ btn.textContent = "Copied";
1263
+ setTimeout(() => { btn.textContent = "Copy"; }, 1200);
1264
+ } catch { /* clipboard blocked — ignore */ }
1265
+ }
1266
+
1267
+ const WGSL_KEYWORDS = new Set(["fn","let","var","const","const_assert","struct","if","else","for","loop","return","break","continue","switch","case","default","while","override","enable","requires","discard","alias","true","false","workgroup","storage","uniform","function","private","read","write","read_write","bitcast"]);
1268
+ const WGSL_TYPES = new Set(["u32","i32","f32","f16","bool","vec2","vec3","vec4","mat2x2","mat3x3","mat4x4","mat2x3","mat3x2","mat2x4","mat4x2","mat3x4","mat4x3","array","atomic","ptr","sampler"]);
1269
+ const WGSL_TOKEN = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|(@[A-Za-z_]\w*)|([A-Za-z_]\w*)|(\d[\w.]*)|(\s+)|([\s\S])/g;
1270
+
1271
+ function highlightWgsl(src) {
1272
+ let out = "";
1273
+ WGSL_TOKEN.lastIndex = 0;
1274
+ let m;
1275
+ while ((m = WGSL_TOKEN.exec(src))) {
1276
+ const [tok, comment, attr, ident, num, ws] = m;
1277
+ if (comment) out += `<span class="k-cm">${escapeHtml(comment)}</span>`;
1278
+ else if (attr) out += `<span class="k-at">${escapeHtml(attr)}</span>`;
1279
+ else if (ident) {
1280
+ const cls = WGSL_KEYWORDS.has(ident) ? "k-kw" : WGSL_TYPES.has(ident) ? "k-ty" : null;
1281
+ out += cls ? `<span class="${cls}">${ident}</span>` : escapeHtml(ident);
1282
+ }
1283
+ else if (num) out += `<span class="k-nu">${escapeHtml(num)}</span>`;
1284
+ else if (ws) out += ws;
1285
+ else out += escapeHtml(tok);
1286
+ }
1287
+ return out;
1288
+ }
1289
+
1290
+ async function send() {
1291
+ const text = input.value.trim();
1292
+ if (!text || !model || isGenerating) return;
1293
+
1294
+ removeWelcome();
1295
+ input.value = "";
1296
+ autoGrow(); refreshSend();
1297
+
1298
+ appendUserMessage(text);
1299
+ messages.push({ role: "user", content: text });
1300
+
1301
+ const assistant = appendAssistantMessage();
1302
+ const bubble = assistant.querySelector(".bubble");
1303
+ bubble.innerHTML = '<span class="thinking"><span></span><span></span><span></span></span>';
1304
+ scrollDown();
1305
+
1306
+ setGenerating(true);
1307
+ abortController = new AbortController();
1308
+
1309
+ let reply = "";
1310
+ let startedAt = 0, firstTokenAt = 0, endedAt = 0, generatedTokens = 0;
1311
+
1312
+ try {
1313
+ const stream = model.generate(messages, { maxNewTokens: 4096, signal: abortController.signal });
1314
+ startedAt = performance.now();
1315
+ for await (const { text: full } of stream) {
1316
+ const now = performance.now();
1317
+ if (!firstTokenAt) firstTokenAt = now;
1318
+ generatedTokens++;
1319
+ reply = full;
1320
+ scheduleAssistantRender(bubble, reply);
1321
+ updateLiveStat({ startedAt, firstTokenAt, now, generatedTokens });
1322
+ }
1323
+ } catch (error) {
1324
+ console.error(error);
1325
+ if (!reply) reply = `_Stopped: ${String(error?.message ?? error)}_`;
1326
+ } finally {
1327
+ endedAt = performance.now();
1328
+ renderState = null; // cancel any pending coalesced render; show the final reply now
1329
+ renderAssistant(bubble, reply, false);
1330
+ appendMeta(assistant, { startedAt, firstTokenAt, endedAt, generatedTokens });
1331
+ scrollDown(); // the meta line is added after the reply — keep it in view
1332
+ messages.push({ role: "assistant", content: reply });
1333
+ setGenerating(false);
1334
+ liveStat.textContent = "";
1335
+ abortController = null;
1336
+ input.focus();
1337
+ }
1338
+ }
1339
+
1340
+ function setGenerating(on) {
1341
+ isGenerating = on;
1342
+ input.disabled = on;
1343
+ clearBtn.disabled = on;
1344
+ sendBtn.style.display = on ? "none" : "";
1345
+ stopBtn.style.display = on ? "grid" : "none";
1346
+ setStatus(on ? "busy" : "ready", on ? "Generating…" : "Ready · on-device");
1347
+ hint.textContent = on ? "Generating on-device…" : "Runs fully on-device — nothing leaves your machine";
1348
+ refreshSend();
1349
+ }
1350
+
1351
+ function updateLiveStat({ startedAt, firstTokenAt, now, generatedTokens }) {
1352
+ if (generatedTokens <= 1) { liveStat.textContent = `TTFT ${(firstTokenAt - startedAt).toFixed(0)} ms`; return; }
1353
+ const decodeSeconds = Math.max((now - firstTokenAt) / 1000, 1e-9);
1354
+ const tps = (generatedTokens - 1) / decodeSeconds;
1355
+ liveStat.textContent = `${tps.toFixed(0)} tok/s`;
1356
+ }
1357
+
1358
+ function clearChat() {
1359
+ messages = [];
1360
+ model?.reset();
1361
+ thread.replaceChildren(createWelcome());
1362
+ clearBtn.disabled = !model;
1363
+ setSeedButtonsEnabled(Boolean(model));
1364
+ input.focus();
1365
+ }
1366
+
1367
+ function appendUserMessage(text) {
1368
+ const msg = document.createElement("div");
1369
+ msg.className = "msg user";
1370
+ msg.appendChild(roleLabel("You"));
1371
+ const bubble = document.createElement("div");
1372
+ bubble.className = "bubble user";
1373
+ bubble.textContent = text;
1374
+ msg.appendChild(bubble);
1375
+ thread.appendChild(msg);
1376
+ scrollDown();
1377
+ return msg;
1378
+ }
1379
+
1380
+ function appendAssistantMessage() {
1381
+ const msg = document.createElement("div");
1382
+ msg.className = "msg assistant";
1383
+ msg.appendChild(roleLabel("Gemma"));
1384
+ const bubble = document.createElement("div");
1385
+ bubble.className = "bubble assistant";
1386
+ msg.appendChild(bubble);
1387
+ thread.appendChild(msg);
1388
+ return msg;
1389
+ }
1390
+
1391
+ function roleLabel(text) {
1392
+ const label = document.createElement("div");
1393
+ label.className = "role";
1394
+ label.textContent = text;
1395
+ return label;
1396
+ }
1397
+
1398
+ function appendMeta(msg, timing) {
1399
+ if (timing.generatedTokens <= 0) return;
1400
+ const stats = generationStats(timing);
1401
+ const meta = document.createElement("div");
1402
+ meta.className = "meta";
1403
+ const parts = [`${timing.generatedTokens} tok`, `TTFT ${stats.ttftMs.toFixed(0)} ms`];
1404
+ if (stats.decodeTokensPerSecond > 0) parts.push(`${stats.decodeTokensPerSecond.toFixed(1)} tok/s`);
1405
+ meta.textContent = parts.join(" · ");
1406
+ msg.appendChild(meta);
1407
+ }
1408
+
1409
+ function generationStats({ startedAt, firstTokenAt, endedAt, generatedTokens }) {
1410
+ if (generatedTokens <= 0 || !startedAt || !firstTokenAt || !endedAt) return { ttftMs: 0, decodeTokensPerSecond: 0 };
1411
+ const decodeTokens = Math.max(generatedTokens - 1, 0);
1412
+ const decodeSeconds = Math.max((endedAt - firstTokenAt) / 1000, 1e-9);
1413
+ return { ttftMs: firstTokenAt - startedAt, decodeTokensPerSecond: decodeTokens > 0 ? decodeTokens / decodeSeconds : 0 };
1414
+ }
1415
+
1416
+ // Coalesce streamed renders to one per animation frame — marked re-parses the full reply each
1417
+ // call, so parsing per token (≈250/s) would tax decode; rAF caps it to the display rate.
1418
+ function scheduleAssistantRender(bubble, raw) {
1419
+ renderState = { bubble, raw };
1420
+ if (renderScheduled) return;
1421
+ renderScheduled = true;
1422
+ requestAnimationFrame(() => {
1423
+ renderScheduled = false;
1424
+ if (!renderState) return;
1425
+ renderAssistant(renderState.bubble, renderState.raw, true);
1426
+ scrollDown();
1427
+ });
1428
+ }
1429
+
1430
+ function renderAssistant(bubble, raw, withCaret) {
1431
+ if (marked) {
1432
+ try {
1433
+ bubble.innerHTML = sanitizeHtml(marked.parse(raw || ""));
1434
+ if (withCaret) appendCaret(bubble);
1435
+ return;
1436
+ } catch { /* fall through to the simple renderer */ }
1437
+ }
1438
+ const safe = escapeHtml(raw || "");
1439
+ const paragraphs = safe.split(/\n{2,}/).map((p) => p.trim()).filter(Boolean);
1440
+ if (paragraphs.length === 0) { bubble.textContent = ""; return; }
1441
+ bubble.innerHTML = paragraphs.map((p) => `<p>${formatInline(p).replace(/\n/g, "<br>")}</p>`).join("");
1442
+ if (withCaret) appendCaret(bubble);
1443
+ }
1444
+
1445
+ function appendCaret(bubble) {
1446
+ const caret = document.createElement("span");
1447
+ caret.className = "caret";
1448
+ (bubble.querySelector("p:last-of-type") || bubble).appendChild(caret);
1449
+ }
1450
+
1451
+ // Strip anything executable from the model's markdown before inserting it (defence in depth — a
1452
+ // local model is the only content source, but raw <script>/event handlers/javascript: URLs are out).
1453
+ function sanitizeHtml(html) {
1454
+ const tpl = document.createElement("template");
1455
+ tpl.innerHTML = html;
1456
+ tpl.content.querySelectorAll("script,style,iframe,object,embed,link,meta,form").forEach((el) => el.remove());
1457
+ tpl.content.querySelectorAll("*").forEach((el) => {
1458
+ for (const attr of [...el.attributes]) {
1459
+ const name = attr.name.toLowerCase();
1460
+ if (name.startsWith("on") || ((name === "href" || name === "src") && /^\s*(javascript|data):/i.test(attr.value))) {
1461
+ el.removeAttribute(attr.name);
1462
+ }
1463
+ }
1464
+ });
1465
+ return tpl.innerHTML;
1466
+ }
1467
+
1468
+ function formatInline(text) {
1469
+ return text.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/`([^`]+?)`/g, "<code>$1</code>");
1470
+ }
1471
+
1472
+ function removeWelcome() { $("welcome")?.remove(); }
1473
+
1474
+ function createWelcome() {
1475
+ const welcome = document.createElement("div");
1476
+ welcome.className = "welcome";
1477
+ welcome.id = "welcome";
1478
+ welcome.innerHTML = `
1479
+ <h2>What's on your <span class="thin">mind today?</span></h2>
1480
+ <p>Model runs entirely on your device.</p>
1481
+ <div class="seeds">
1482
+ <button class="seed" type="button">How does WebGPU differ from WebGL?</button>
1483
+ <button class="seed" type="button">Write a haiku about on-device AI</button>
1484
+ <button class="seed" type="button">What is quantization-aware training?</button>
1485
+ </div>`;
1486
+ return welcome;
1487
+ }
1488
+
1489
+ function setSeedButtonsEnabled(enabled) {
1490
+ document.querySelectorAll(".seed").forEach((s) => { s.disabled = !enabled; });
1491
+ }
1492
+ function refreshSend() { sendBtn.disabled = isGenerating || !model || input.value.trim() === ""; }
1493
+ function autoGrow() { input.style.height = "auto"; input.style.height = `${Math.min(input.scrollHeight, 180)}px`; }
1494
+ function scrollDown() { threadScroll.scrollTop = threadScroll.scrollHeight; }
1495
+ function finiteNumber(v) { return typeof v === "number" && Number.isFinite(v); }
1496
+ function clamp(v, min, max) { return Math.min(max, Math.max(min, v)); }
1497
+ function formatInteger(v) { return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(v); }
1498
+ function formatBytes(bytes) {
1499
+ const units = ["B", "KB", "MB", "GB"]; let v = bytes, u = 0;
1500
+ while (v >= 1024 && u < units.length - 1) { v /= 1024; u++; }
1501
+ // GB shows 2 decimals (1.12 GB) so it ticks finely past 1 GB; smaller units keep 0–1.
1502
+ const digits = u === 3 ? 2 : (v >= 10 || u === 0 ? 0 : 1);
1503
+ return `${v.toFixed(digits)} ${units[u]}`;
1504
+ }
1505
+ function escapeHtml(v) {
1506
+ return v.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
1507
+ }
1508
+ </script>
1509
+ </body>
1510
  </html>
landing.js ADDED
@@ -0,0 +1,717 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import * as THREE from 'three';
2
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
3
+ import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
4
+ import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
5
+ import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
6
+ import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
7
+
8
+ // ============ DEVICE DETECTION ============
9
+ const isMobile = /Android|iPhone|iPad|iPod|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
10
+ || (navigator.maxTouchPoints > 1 && window.innerWidth < 1024);
11
+ const gpuTier = (() => {
12
+ const gl = document.createElement('canvas').getContext('webgl');
13
+ if (!gl) return 'low';
14
+ const ext = gl.getExtension('WEBGL_debug_renderer_info');
15
+ const gpu = ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL).toLowerCase() : '';
16
+ // Apple GPU = Apple Silicon (M1/M2/M3/M4) — these are high-tier
17
+ if (/apple gpu|apple m/.test(gpu)) return 'high';
18
+ // Low-tier: old Intel integrated, software renderers, old mobile chips
19
+ if (/swiftshader|llvmpipe|mali-4|adreno 3/.test(gpu)) return 'low';
20
+ if (/intel(?!.*(iris|uhd|arc))/.test(gpu)) return 'low';
21
+ // Mid-tier: mid-range mobile, Intel Iris/UHD, older discrete
22
+ if (/mali-g[567]|adreno [45]|intel (iris|uhd)|geforce (mx|gt)|radeon (rx )?(5[0-4]|vega 8)/.test(gpu)) return 'mid';
23
+ // Everything else (RTX, RX 6000+, Arc, etc.) = high
24
+ return 'high';
25
+ })();
26
+
27
+ const qualityPresets = {
28
+ low: { pixelRatio: 1.0, marchSteps: 48, aoSteps: 2, dotSize: 6.0, dotGap: 3.0, scanlines: 0.55, bloomEnabled: false },
29
+ mid: { pixelRatio: 1.25, marchSteps: 64, aoSteps: 3, dotSize: 5.0, dotGap: 2.5, scanlines: 0.75, bloomEnabled: true },
30
+ high: { pixelRatio: 1.5, marchSteps: 80, aoSteps: 3, dotSize: 5.0, dotGap: 2.5, scanlines: 0.75, bloomEnabled: true },
31
+ };
32
+ let currentTier = isMobile ? 'low' : gpuTier;
33
+ let quality = { ...qualityPresets[currentTier] };
34
+
35
+ // ============ SETTINGS ============
36
+ const settings = {
37
+ dither: { enabled: true, dotSize: quality.dotSize, dotGap: quality.dotGap, brightness: 0.85, contrast: 0.60, threshold: 0.03, dotColor: [1.0, 1.0, 1.0], bgColor: [0.00784, 0.00784, 0.01176] },
38
+ crosshatch: { enabled: false, intensity: 0.95, angle: 0.4363 },
39
+ bloom: { enabled: quality.bloomEnabled, intensity: 0.55, size: 1.50 },
40
+ crt: { enabled: true, curvature: 0.0, scanlines: quality.scanlines, vignette: 2.00, chroma: 0.0 },
41
+ scene: { gooeyness: 1.20, speed: 0.85 }
42
+ };
43
+
44
+ // ============ MOUSE TRACKING ============
45
+ const mouse = new THREE.Vector2(0, 0);
46
+ let mouseInScene = false;
47
+ let mousePressed = false;
48
+ let mouseSphereRadius = 0.0;
49
+ const mouseSphereTargetRadius = 0.55;
50
+ const mouseSphereClickRadius = 0.95;
51
+ const mouseWorld = new THREE.Vector3(0, 0, 0);
52
+ const mouseWorldTarget = new THREE.Vector3(0, 0, 0);
53
+ const mouseDamping = 0.15;
54
+
55
+ // ============ THREE.JS SETUP ============
56
+ const scene = new THREE.Scene();
57
+ scene.background = new THREE.Color(0x020203);
58
+
59
+ const crtFrame = document.getElementById('crt-frame');
60
+ const getSize = () => {
61
+ return { width: window.innerWidth, height: window.innerHeight };
62
+ };
63
+ let size = getSize();
64
+
65
+ const camera = new THREE.PerspectiveCamera(60, size.width / size.height, 0.1, 100);
66
+ camera.position.set(0, 0, 5);
67
+ const renderer = new THREE.WebGLRenderer({ antialias: false, powerPreference: 'high-performance' });
68
+ renderer.setSize(size.width, size.height);
69
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, quality.pixelRatio));
70
+ crtFrame.appendChild(renderer.domElement);
71
+
72
+ const controls = new OrbitControls(camera, renderer.domElement);
73
+ controls.enableDamping = true;
74
+ controls.dampingFactor = 0.05;
75
+ controls.enableZoom = false;
76
+ controls.enablePan = false;
77
+ controls.enableRotate = false;
78
+ controls.enabled = false; // prevent OrbitControls from capturing scroll/pointer events
79
+
80
+ // ============ INPUT EVENTS ============
81
+ let pageVisible = true;
82
+ // Render only while the hero canvas is actually on screen. When the chat view scrolls into
83
+ // place the background pauses itself (below), freeing the GPU for the WebGPU model so decode
84
+ // throughput isn't dragged down by the WebGL background.
85
+ let heroOnScreen = true;
86
+ const onPointerMove = (e) => {
87
+ mouseInScene = true;
88
+ const x = e.clientX ?? (e.touches && e.touches[0] ? e.touches[0].clientX : 0);
89
+ const y = e.clientY ?? (e.touches && e.touches[0] ? e.touches[0].clientY : 0);
90
+ mouse.x = (x / window.innerWidth) * 2 - 1;
91
+ mouse.y = -(y / window.innerHeight) * 2 + 1;
92
+ };
93
+ document.addEventListener('mousemove', onPointerMove, { passive: true });
94
+ document.addEventListener('touchmove', onPointerMove, { passive: true });
95
+ document.addEventListener('mouseenter', () => { mouseInScene = true; }, { passive: true });
96
+ document.addEventListener('mouseleave', () => { mouseInScene = false; }, { passive: true });
97
+ document.addEventListener('touchstart', (e) => { mouseInScene = true; mousePressed = true; onPointerMove(e); }, { passive: true });
98
+ document.addEventListener('touchend', () => { mousePressed = false; mouseInScene = false; }, { passive: true });
99
+ document.addEventListener('visibilitychange', () => {
100
+ pageVisible = !document.hidden;
101
+ if (document.hidden) mouseInScene = false;
102
+ });
103
+ // Pause the WebGL background as soon as the chat view dominates the screen, so it never competes
104
+ // with the WebGPU model for the GPU. Resume when scrolling back to the landing. Falls back to the
105
+ // hero canvas's own visibility if there is no #chat section on the page.
106
+ const chatSection = document.getElementById('chat');
107
+ if (chatSection) {
108
+ new IntersectionObserver(([entry]) => { heroOnScreen = entry.intersectionRatio < 0.4; }, { threshold: [0, 0.4, 1] }).observe(chatSection);
109
+ } else {
110
+ new IntersectionObserver(([entry]) => { heroOnScreen = entry.isIntersecting; }, { threshold: 0 }).observe(crtFrame);
111
+ }
112
+ document.addEventListener('mousedown', () => { mousePressed = true; }, { passive: true });
113
+ document.addEventListener('mouseup', () => { mousePressed = false; }, { passive: true });
114
+
115
+ // ============ RAYMARCHING QUAD ============
116
+ const quadGeometry = new THREE.PlaneGeometry(2, 2);
117
+ const quadMaterial = new THREE.ShaderMaterial({
118
+ uniforms: {
119
+ uTime: { value: 0 },
120
+ uResolution: { value: new THREE.Vector2(size.width, size.height) },
121
+ uCameraPos: { value: camera.position.clone() },
122
+ uCameraTarget: { value: new THREE.Vector3(0, 0, 0) },
123
+ uPixelRatio: { value: Math.min(window.devicePixelRatio, 1.5) },
124
+ uGooeyness: { value: settings.scene.gooeyness },
125
+ uSpeed: { value: settings.scene.speed },
126
+ uMouseSpherePos: { value: new THREE.Vector3(0, 0, 0) },
127
+ uMouseSphereRadius: { value: 0.0 },
128
+ },
129
+ vertexShader: `
130
+ varying vec2 vUv;
131
+ void main() {
132
+ vUv = uv;
133
+ gl_Position = vec4(position, 1.0);
134
+ }
135
+ `,
136
+ fragmentShader: `
137
+ precision highp float;
138
+ #define MARCH_STEPS ${quality.marchSteps}
139
+ #define AO_STEPS ${quality.aoSteps}
140
+ uniform float uTime;
141
+ uniform vec2 uResolution;
142
+ uniform vec3 uCameraPos;
143
+ uniform vec3 uCameraTarget;
144
+ uniform float uPixelRatio;
145
+ uniform float uGooeyness;
146
+ uniform float uSpeed;
147
+ uniform vec3 uMouseSpherePos;
148
+ uniform float uMouseSphereRadius;
149
+
150
+ varying vec2 vUv;
151
+
152
+ float smin(float a, float b, float k) {
153
+ float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
154
+ return mix(b, a, h) - k * h * (1.0 - h);
155
+ }
156
+
157
+ float sdSphere(vec3 p, vec3 center, float radius) {
158
+ return length(p - center) - radius;
159
+ }
160
+
161
+ float sceneCompound(vec3 p, float t, float k) {
162
+ // Two large primary blobs
163
+ float angle1 = t * 0.5;
164
+ float angle2 = t * 0.5 + 3.14159;
165
+ vec3 c1 = vec3(
166
+ cos(angle1) * 2.4 + sin(t * 0.25) * 0.3,
167
+ sin(angle1 * 0.6) * 0.8 + cos(t * 0.4) * 0.2,
168
+ sin(angle1 * 0.35) * 0.6
169
+ );
170
+ vec3 c2 = vec3(
171
+ cos(angle2) * 2.4 + sin(t * 0.3) * 0.3,
172
+ sin(angle2 * 0.6) * 0.8 - cos(t * 0.35) * 0.2,
173
+ sin(angle2 * 0.35) * 0.6
174
+ );
175
+ float s1 = sdSphere(p, c1, 1.2 + 0.07 * sin(t * 2.5));
176
+ float s2 = sdSphere(p, c2, 1.05 + 0.07 * cos(t * 2.0));
177
+
178
+ // Medium satellites
179
+ vec3 c3 = c1 + vec3(sin(t * 1.8) * 0.9, cos(t * 2.2) * 0.9, sin(t * 1.5) * 0.6);
180
+ vec3 c4 = c2 + vec3(-cos(t * 1.5) * 0.8, sin(t * 1.9) * 0.8, -cos(t * 1.7) * 0.5);
181
+ float s3 = sdSphere(p, c3, 0.55);
182
+ float s4 = sdSphere(p, c4, 0.5);
183
+
184
+ // Free-floating blobs
185
+ vec3 c5 = vec3(sin(t * 0.7) * 3.0, cos(t * 0.55) * 1.2, cos(t * 0.45) * 0.7);
186
+ vec3 c6 = vec3(-cos(t * 0.65) * 2.8, sin(t * 0.75) * 1.0, sin(t * 0.5) * 0.8);
187
+ float s5 = sdSphere(p, c5, 0.6);
188
+ float s6 = sdSphere(p, c6, 0.55);
189
+
190
+ float d = smin(s1, s2, k);
191
+ d = smin(d, s3, k * 0.7);
192
+ d = smin(d, s4, k * 0.7);
193
+ d = smin(d, s5, k * 0.8);
194
+ d = smin(d, s6, k * 0.8);
195
+ return d;
196
+ }
197
+
198
+ float sceneSDF(vec3 p) {
199
+ float t = uTime * uSpeed;
200
+ float k = uGooeyness;
201
+ float d = sceneCompound(p, t, k);
202
+ if (uMouseSphereRadius > 0.001) {
203
+ float ms = sdSphere(p, uMouseSpherePos, uMouseSphereRadius);
204
+ d = smin(d, ms, k * 0.8);
205
+ }
206
+ return d;
207
+ }
208
+
209
+ vec3 calcNormal(vec3 p) {
210
+ const float eps = 0.001;
211
+ vec2 h = vec2(eps, 0.0);
212
+ return normalize(vec3(
213
+ sceneSDF(p + h.xyy) - sceneSDF(p - h.xyy),
214
+ sceneSDF(p + h.yxy) - sceneSDF(p - h.yxy),
215
+ sceneSDF(p + h.yyx) - sceneSDF(p - h.yyx)
216
+ ));
217
+ }
218
+
219
+ float calcAO(vec3 pos, vec3 nor) {
220
+ float occ = 0.0;
221
+ float sca = 1.0;
222
+ for (int i = 0; i < AO_STEPS; i++) {
223
+ float h = 0.02 + 0.15 * float(i);
224
+ float d = sceneSDF(pos + h * nor);
225
+ occ += (h - d) * sca;
226
+ sca *= 0.9;
227
+ }
228
+ return clamp(1.0 - 3.0 * occ, 0.0, 1.0);
229
+ }
230
+
231
+ float fresnel(vec3 viewDir, vec3 normal, float power) {
232
+ return pow(1.0 - max(dot(viewDir, normal), 0.0), power);
233
+ }
234
+
235
+ // Fake directional shadow via downward AO probe
236
+ float cheapShadow(vec3 pos, vec3 lightDir) {
237
+ float d1 = sceneSDF(pos + lightDir * 0.15);
238
+ float d2 = sceneSDF(pos + lightDir * 0.4);
239
+ float d3 = sceneSDF(pos + lightDir * 0.8);
240
+ return clamp(0.3 + 0.7 * smoothstep(0.0, 0.3, min(min(d1, d2), d3)), 0.0, 1.0);
241
+ }
242
+
243
+ mat3 setCamera(vec3 ro, vec3 ta, float cr) {
244
+ vec3 cw = normalize(ta - ro);
245
+ vec3 cp = vec3(sin(cr), cos(cr), 0.0);
246
+ vec3 cu = normalize(cross(cw, cp));
247
+ vec3 cv = normalize(cross(cu, cw));
248
+ return mat3(cu, cv, cw);
249
+ }
250
+
251
+ void main() {
252
+ vec2 fragCoord = vUv * uResolution;
253
+ vec2 uv = (2.0 * fragCoord - uResolution) / uResolution.y;
254
+ vec3 ro = uCameraPos;
255
+ vec3 ta = uCameraTarget;
256
+ mat3 ca = setCamera(ro, ta, 0.0);
257
+ vec3 rd = ca * normalize(vec3(uv, 1.8));
258
+ float t = 0.0;
259
+ float d;
260
+ vec3 p;
261
+ bool hit = false;
262
+ for (int i = 0; i < MARCH_STEPS; i++) {
263
+ p = ro + rd * t;
264
+ d = sceneSDF(p);
265
+ if (d < 0.002) { hit = true; break; }
266
+ t += d * 0.9;
267
+ if (t > 15.0) break;
268
+ }
269
+ vec3 col = vec3(0.02, 0.02, 0.04);
270
+ col += vec3(0.03, 0.01, 0.06) * (1.0 - uv.y * 0.5);
271
+ if (hit) {
272
+ vec3 nor = calcNormal(p);
273
+ vec3 viewDir = normalize(ro - p);
274
+ vec3 lightPos1 = vec3(3.0, 4.0, 5.0);
275
+ vec3 lightPos2 = vec3(-4.0, 2.0, -3.0);
276
+ vec3 lightDir1 = normalize(lightPos1 - p);
277
+ vec3 lightDir2 = normalize(lightPos2 - p);
278
+ float diff1 = max(dot(nor, lightDir1), 0.0);
279
+ float diff2 = max(dot(nor, lightDir2), 0.0);
280
+ vec3 halfDir1 = normalize(lightDir1 + viewDir);
281
+ vec3 halfDir2 = normalize(lightDir2 + viewDir);
282
+ float spec1 = pow(max(dot(nor, halfDir1), 0.0), 64.0);
283
+ float spec2 = pow(max(dot(nor, halfDir2), 0.0), 32.0);
284
+ float sha1 = cheapShadow(p + nor * 0.01, lightDir1);
285
+ float sha2 = cheapShadow(p + nor * 0.01, lightDir2);
286
+ float ao = calcAO(p, nor);
287
+ float fres = fresnel(viewDir, nor, 3.0);
288
+ float sss = max(0.0, dot(viewDir, -lightDir1)) * 0.3;
289
+ vec3 baseColor1 = vec3(0.8, 0.15, 0.3);
290
+ vec3 baseColor2 = vec3(0.15, 0.4, 0.9);
291
+ vec3 baseColor3 = vec3(0.95, 0.5, 0.1);
292
+ float colorMix = sin(p.x * 1.5 + uTime * 0.5) * 0.5 + 0.5;
293
+ float colorMix2 = cos(p.y * 2.0 - uTime * 0.3) * 0.5 + 0.5;
294
+ vec3 baseColor = mix(baseColor1, baseColor2, colorMix);
295
+ baseColor = mix(baseColor, baseColor3, colorMix2 * 0.3);
296
+ vec3 diffuse = baseColor * (diff1 * sha1 * vec3(1.0, 0.95, 0.9) * 0.8 + diff2 * sha2 * vec3(0.4, 0.5, 0.9) * 0.4);
297
+ vec3 specular = vec3(1.0, 0.95, 0.9) * spec1 * sha1 * 0.7 + vec3(0.5, 0.6, 1.0) * spec2 * sha2 * 0.3;
298
+ vec3 ambient = baseColor * vec3(0.08, 0.06, 0.12) * ao;
299
+ vec3 rim = mix(vec3(0.4, 0.6, 1.0), vec3(1.0, 0.4, 0.6), colorMix) * fres * 0.6;
300
+ vec3 subsurface = baseColor * sss * vec3(1.0, 0.3, 0.2);
301
+ col = ambient + diffuse + specular + rim + subsurface;
302
+ float iridescence = fres * 0.4;
303
+ vec3 iriColor = vec3(
304
+ sin(dot(nor, vec3(1.0, 0.0, 0.0)) * 6.0 + uTime) * 0.5 + 0.5,
305
+ sin(dot(nor, vec3(0.0, 1.0, 0.0)) * 6.0 + uTime * 1.3) * 0.5 + 0.5,
306
+ sin(dot(nor, vec3(0.0, 0.0, 1.0)) * 6.0 + uTime * 0.7) * 0.5 + 0.5
307
+ );
308
+ col += iriColor * iridescence;
309
+ vec3 ref = reflect(-viewDir, nor);
310
+ float envRefl = smoothstep(-0.2, 1.0, ref.y) * 0.15;
311
+ col += vec3(0.3, 0.4, 0.8) * envRefl * fres;
312
+ }
313
+ col = col / (col + vec3(1.0));
314
+ col = pow(col, vec3(1.0 / 2.2));
315
+ float vig = 1.0 - 0.3 * dot(uv * 0.5, uv * 0.5);
316
+ col *= vig;
317
+ gl_FragColor = vec4(col, 1.0);
318
+ }
319
+ `,
320
+ depthWrite: false,
321
+ depthTest: false
322
+ });
323
+
324
+ const quad = new THREE.Mesh(quadGeometry, quadMaterial);
325
+ quad.name = 'raymarchQuad';
326
+ quad.frustumCulled = false;
327
+
328
+ const quadScene = new THREE.Scene();
329
+ const quadCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
330
+ quadScene.add(quad);
331
+
332
+ // ============ DOT MATRIX SHADER ============
333
+ const DotMatrixShader = {
334
+ uniforms: {
335
+ tDiffuse: { value: null },
336
+ uResolution: { value: new THREE.Vector2(size.width, size.height) },
337
+ uDotSize: { value: 5.0 },
338
+ uDotGap: { value: 2.5 },
339
+ uBrightness: { value: 0.85 },
340
+ uContrast: { value: 0.60 },
341
+ uThreshold: { value: 0.03 },
342
+ uDotColor: { value: new THREE.Vector3(1.0, 1.0, 1.0) },
343
+ uBgColor: { value: new THREE.Vector3(0.00784, 0.00784, 0.01176) },
344
+ uCrossEnabled: { value: 0.0 },
345
+ uCrossIntensity: { value: 0.95 },
346
+ uCrossAngle: { value: 0.4363 },
347
+ uBloomEnabled: { value: 1.0 },
348
+ uBloomIntensity: { value: 0.55 },
349
+ uBloomSize: { value: 1.50 },
350
+ uCrtEnabled: { value: 1.0 },
351
+ uCrtCurvature: { value: 0.0 },
352
+ uCrtScanlines: { value: 0.75 },
353
+ uCrtVignette: { value: 2.00 },
354
+ uCrtChroma: { value: 0.0 },
355
+ uDitherEnabled: { value: 1.0 },
356
+ uTime: { value: 0 }
357
+ },
358
+ vertexShader: `
359
+ varying vec2 vUv;
360
+ void main() {
361
+ vUv = uv;
362
+ gl_Position = vec4(position, 1.0);
363
+ }
364
+ `,
365
+ fragmentShader: `
366
+ precision highp float;
367
+ uniform sampler2D tDiffuse;
368
+ uniform vec2 uResolution;
369
+ uniform float uDotSize;
370
+ uniform float uDotGap;
371
+ uniform float uBrightness;
372
+ uniform float uContrast;
373
+ uniform float uThreshold;
374
+ uniform vec3 uDotColor;
375
+ uniform vec3 uBgColor;
376
+ uniform float uCrossEnabled;
377
+ uniform float uCrossIntensity;
378
+ uniform float uCrossAngle;
379
+ uniform float uBloomEnabled;
380
+ uniform float uBloomIntensity;
381
+ uniform float uBloomSize;
382
+ uniform float uCrtEnabled;
383
+ uniform float uCrtCurvature;
384
+ uniform float uCrtScanlines;
385
+ uniform float uCrtVignette;
386
+ uniform float uCrtChroma;
387
+ uniform float uDitherEnabled;
388
+ uniform float uTime;
389
+ varying vec2 vUv;
390
+
391
+ vec2 crtDistort(vec2 uv, float k) {
392
+ vec2 cc = uv - 0.5;
393
+ float r2 = dot(cc, cc);
394
+ float f = 1.0 + r2 * k * 0.01;
395
+ return cc * f + 0.5;
396
+ }
397
+
398
+ void main() {
399
+ vec2 uv = vUv;
400
+ if (uCrtEnabled > 0.5) {
401
+ uv = crtDistort(uv, uCrtCurvature);
402
+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
403
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
404
+ return;
405
+ }
406
+ }
407
+ vec3 col;
408
+ if (uCrtEnabled > 0.5 && uCrtChroma > 0.01) {
409
+ vec2 dir = (uv - 0.5) * uCrtChroma * 0.002;
410
+ col.r = texture2D(tDiffuse, uv + dir).r;
411
+ col.g = texture2D(tDiffuse, uv).g;
412
+ col.b = texture2D(tDiffuse, uv - dir).b;
413
+ } else {
414
+ col = texture2D(tDiffuse, uv).rgb;
415
+ }
416
+ if (uDitherEnabled < 0.5) {
417
+ if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
418
+ float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
419
+ col *= 1.0 - uCrtScanlines * (1.0 - scanline);
420
+ }
421
+ if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
422
+ vec2 vig = uv * (1.0 - uv);
423
+ float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
424
+ col *= vigMask;
425
+ }
426
+ gl_FragColor = vec4(col, 1.0);
427
+ return;
428
+ }
429
+ vec2 pixelCoord = uv * uResolution;
430
+ float spacing = uDotSize + uDotGap;
431
+ vec2 cell = floor(pixelCoord / spacing);
432
+ vec2 cellCenter = (cell + 0.5) * spacing;
433
+ vec2 sampleUV = cellCenter / uResolution;
434
+ vec3 cellCol;
435
+ if (uCrtEnabled > 0.5 && uCrtChroma > 0.01) {
436
+ vec2 dir = (sampleUV - 0.5) * uCrtChroma * 0.002;
437
+ cellCol.r = texture2D(tDiffuse, sampleUV + dir).r;
438
+ cellCol.g = texture2D(tDiffuse, sampleUV).g;
439
+ cellCol.b = texture2D(tDiffuse, sampleUV - dir).b;
440
+ } else {
441
+ cellCol = texture2D(tDiffuse, sampleUV).rgb;
442
+ }
443
+ float lum = dot(cellCol, vec3(0.299, 0.587, 0.114));
444
+ lum *= uBrightness;
445
+ lum = (lum - 0.5) * (1.0 / uContrast) + 0.5;
446
+ lum = clamp(lum, 0.0, 1.0);
447
+ vec3 bgColor = uBgColor;
448
+ if (lum < uThreshold) {
449
+ vec3 result = bgColor;
450
+ if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
451
+ float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
452
+ result *= 1.0 - uCrtScanlines * (1.0 - scanline) * 0.3;
453
+ }
454
+ if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
455
+ vec2 vig = uv * (1.0 - uv);
456
+ float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
457
+ result *= vigMask;
458
+ }
459
+ gl_FragColor = vec4(result, 1.0);
460
+ return;
461
+ }
462
+ float maxRadius = uDotSize * 0.5;
463
+ float minRadius = 0.4;
464
+ float lumCurve = pow(lum, uContrast);
465
+ float dotRadius = mix(minRadius, maxRadius, lumCurve);
466
+ vec2 d = pixelCoord - cellCenter;
467
+ vec2 absD = abs(d);
468
+ float cornerRadius = mix(0.8, 0.2, lumCurve);
469
+ float squareness = smoothstep(0.15, 0.7, lumCurve);
470
+ float circleDist = length(d);
471
+ float circleEdge = 1.0 - smoothstep(dotRadius - 0.5, dotRadius + 0.5, circleDist);
472
+ vec2 qd = absD - vec2(dotRadius - cornerRadius);
473
+ float rsDist = length(max(qd, 0.0)) + min(max(qd.x, qd.y), 0.0) - cornerRadius;
474
+ float squareEdge = 1.0 - smoothstep(-0.5, 0.5, rsDist);
475
+ float dotMask = mix(circleEdge, squareEdge, squareness);
476
+ vec3 brightColor = uDotColor;
477
+ vec3 midColor = uDotColor * 0.7;
478
+ vec3 dimColor = uDotColor * 0.25;
479
+ vec3 colNorm = cellCol / (max(max(cellCol.r, cellCol.g), cellCol.b) + 0.001);
480
+ vec3 dotColor;
481
+ if (lum > 0.65) {
482
+ dotColor = mix(brightColor, brightColor * colNorm * 1.5, 0.2);
483
+ dotColor *= 1.0 + (lum - 0.65) * 1.5;
484
+ } else if (lum > 0.25) {
485
+ float mt = (lum - 0.25) / 0.4;
486
+ dotColor = mix(midColor, brightColor, mt);
487
+ dotColor = mix(dotColor, dotColor * colNorm * 1.2, 0.15);
488
+ } else {
489
+ float st = lum / 0.25;
490
+ dotColor = mix(dimColor * 0.5, dimColor, st);
491
+ }
492
+ float shadowCrosshatch = 0.0;
493
+ if (uCrossEnabled > 0.5 && lum < 0.35) {
494
+ float crossSpacing = spacing * 0.7;
495
+ float ca = cos(uCrossAngle);
496
+ float sa = sin(uCrossAngle);
497
+ vec2 rotP = vec2(ca * pixelCoord.x - sa * pixelCoord.y, sa * pixelCoord.x + ca * pixelCoord.y);
498
+ vec2 crossCell = floor(rotP / crossSpacing);
499
+ vec2 crossCenter = (crossCell + 0.5) * crossSpacing;
500
+ float crossDist = length(rotP - crossCenter);
501
+ float shadowIntensity = smoothstep(0.35, 0.05, lum);
502
+ float crossRadius = mix(0.3, maxRadius * 0.35, shadowIntensity);
503
+ shadowCrosshatch = 1.0 - smoothstep(crossRadius - 0.4, crossRadius + 0.4, crossDist);
504
+ shadowCrosshatch *= shadowIntensity * uCrossIntensity;
505
+ }
506
+ float bloomMask = 0.0;
507
+ if (uBloomEnabled > 0.5 && lum > 0.6) {
508
+ float bloomRadius = dotRadius * uBloomSize;
509
+ float bloomDist = length(d);
510
+ bloomMask = (1.0 - smoothstep(bloomRadius - 1.0, bloomRadius + 1.0, bloomDist));
511
+ bloomMask *= smoothstep(0.6, 1.0, lum) * uBloomIntensity * 0.5;
512
+ }
513
+ vec3 result = bgColor;
514
+ vec3 crossColor = dimColor * 0.4;
515
+ result = mix(result, crossColor, shadowCrosshatch);
516
+ result += brightColor * bloomMask;
517
+ result = mix(result, dotColor, dotMask);
518
+ float innerMask = 0.0;
519
+ if (squareness > 0.5) {
520
+ vec2 qd2 = absD - vec2(dotRadius * 0.85 - cornerRadius);
521
+ float rsDist2 = length(max(qd2, 0.0)) + min(max(qd2.x, qd2.y), 0.0) - cornerRadius;
522
+ innerMask = 1.0 - smoothstep(-0.5, 0.5, rsDist2);
523
+ } else {
524
+ innerMask = 1.0 - smoothstep(dotRadius * 0.7 - 0.5, dotRadius * 0.7 + 0.5, circleDist);
525
+ }
526
+ float phosphorEdge = max(dotMask - innerMask, 0.0);
527
+ result += brightColor * phosphorEdge * 0.15 * lum;
528
+ if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
529
+ float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
530
+ result *= 1.0 - uCrtScanlines * (1.0 - scanline);
531
+ }
532
+ if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
533
+ vec2 vig = uv * (1.0 - uv);
534
+ float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
535
+ result *= vigMask;
536
+ }
537
+ if (uCrtEnabled > 0.5) {
538
+ result = result;
539
+ }
540
+ gl_FragColor = vec4(result, 1.0);
541
+ }
542
+ `
543
+ };
544
+
545
+ // ============ POST PROCESSING ============
546
+ // Use a standard RenderPass for the quad scene — the raymarching resolution
547
+ // is controlled by uResolution on the quad material (set to half-res),
548
+ // while the composer and dot-matrix shader run at full native resolution.
549
+ const composer = new EffectComposer(renderer);
550
+ composer.setSize(size.width, size.height);
551
+
552
+ const renderPass = new RenderPass(quadScene, quadCamera);
553
+ composer.addPass(renderPass);
554
+
555
+ const dotMatrixPass = new ShaderPass(DotMatrixShader);
556
+ composer.addPass(dotMatrixPass);
557
+ const outputPass = new OutputPass();
558
+ composer.addPass(outputPass);
559
+
560
+ // Dot matrix runs at full resolution for crisp patterns
561
+ dotMatrixPass.uniforms.uResolution.value.set(size.width, size.height);
562
+
563
+ // ============ SCROLL PARALLAX ============
564
+ let scrollY = 0;
565
+ let smoothScrollY = 0;
566
+
567
+ window.addEventListener('scroll', () => {
568
+ scrollY = window.scrollY;
569
+ }, { passive: true });
570
+
571
+ // ============ ANIMATION LOOP ============
572
+ const clock = new THREE.Clock();
573
+ const raycaster = new THREE.Raycaster();
574
+ const _forward = new THREE.Vector3();
575
+ let resizeTimeout = null;
576
+
577
+ // ============ FPS WATCHDOG — auto-downgrade if <30fps ============
578
+ const tierOrder = ['high', 'mid', 'low'];
579
+ let fpsFrames = 0;
580
+ let fpsStartTime = performance.now();
581
+ let fpsWatchdogActive = true;
582
+ const FPS_SAMPLE_WINDOW = 2000; // 2 seconds
583
+ const FPS_THRESHOLD = 30;
584
+
585
+ function downgradeQuality() {
586
+ const currentIndex = tierOrder.indexOf(currentTier);
587
+ if (currentIndex >= tierOrder.length - 1) {
588
+ // Already at lowest tier
589
+ fpsWatchdogActive = false;
590
+ return;
591
+ }
592
+ const nextTier = tierOrder[currentIndex + 1];
593
+ currentTier = nextTier;
594
+ quality = { ...qualityPresets[currentTier] };
595
+
596
+ // Apply new quality — update pixel ratio
597
+ const pr = Math.min(window.devicePixelRatio, quality.pixelRatio);
598
+ renderer.setPixelRatio(pr);
599
+ renderer.setSize(size.width, size.height);
600
+ composer.setSize(size.width, size.height);
601
+
602
+ // Update dot matrix uniforms
603
+ dotMatrixPass.uniforms.uDotSize.value = quality.dotSize;
604
+ dotMatrixPass.uniforms.uDotGap.value = quality.dotGap;
605
+ dotMatrixPass.uniforms.uCrtScanlines.value = quality.scanlines;
606
+ dotMatrixPass.uniforms.uBloomEnabled.value = quality.bloomEnabled ? 1.0 : 0.0;
607
+
608
+ // Reset watchdog for another sample window
609
+ fpsFrames = 0;
610
+ fpsStartTime = performance.now();
611
+
612
+ // If we hit the lowest tier, stop watching
613
+ if (currentIndex + 1 >= tierOrder.length - 1) {
614
+ fpsWatchdogActive = false;
615
+ }
616
+
617
+ // Update tier display
618
+ const tierEl = document.getElementById('settings-tier');
619
+ if (tierEl) tierEl.textContent = `GPU Tier: ${currentTier} (auto)`;
620
+ }
621
+
622
+ function animate() {
623
+ // Skip rendering when the tab is hidden or the hero has scrolled off screen (see heroOnScreen).
624
+ if (!pageVisible || !heroOnScreen) return;
625
+
626
+ const dt = Math.min(clock.getDelta(), 0.05); // Clamp delta to avoid huge jumps
627
+ const elapsed = clock.elapsedTime;
628
+ controls.update();
629
+
630
+ const targetR = mouseInScene ? (mousePressed ? mouseSphereClickRadius : mouseSphereTargetRadius) : 0.0;
631
+ const fadeSpeed = mouseInScene ? (mousePressed ? 10.0 : 6.0) : 3.0;
632
+ const step = Math.min(1.0, fadeSpeed * dt);
633
+ mouseSphereRadius += (targetR - mouseSphereRadius) * step;
634
+ if (mouseSphereRadius < 0.005 && !mouseInScene) mouseSphereRadius = 0.0;
635
+
636
+ raycaster.setFromCamera(mouse, camera);
637
+ const rayDir = raycaster.ray.direction;
638
+ const rayOrigin = raycaster.ray.origin;
639
+ _forward.subVectors(controls.target, camera.position).normalize();
640
+ const dist = camera.position.distanceTo(controls.target);
641
+ const t = dist / rayDir.dot(_forward);
642
+ mouseWorldTarget.copy(rayOrigin).addScaledVector(rayDir, t);
643
+ mouseWorld.lerp(mouseWorldTarget, mouseDamping);
644
+
645
+ // Smooth scroll interpolation for parallax
646
+ smoothScrollY += (scrollY - smoothScrollY) * 0.1;
647
+ const vh = window.innerHeight;
648
+ const scrollProgress = Math.min(smoothScrollY / vh, 1.0);
649
+
650
+ // Parallax: shift camera subtly as user scrolls (3D depth effect)
651
+ const baseZ = 5;
652
+ const baseCamY = 0;
653
+ camera.position.y = baseCamY + scrollProgress * 1.5;
654
+ camera.position.z = baseZ + scrollProgress * 0.8;
655
+ controls.target.y = scrollProgress * 0.8;
656
+
657
+ quadMaterial.uniforms.uMouseSpherePos.value.copy(mouseWorld);
658
+ quadMaterial.uniforms.uMouseSphereRadius.value = mouseSphereRadius;
659
+ quadMaterial.uniforms.uTime.value = elapsed;
660
+ quadMaterial.uniforms.uCameraPos.value.copy(camera.position);
661
+ quadMaterial.uniforms.uCameraTarget.value.copy(controls.target);
662
+ dotMatrixPass.uniforms.uTime.value = elapsed;
663
+
664
+ // Composer renders the quad scene via RenderPass, then applies dot matrix + CRT
665
+ composer.render();
666
+
667
+ // FPS watchdog — sample for 2s windows, downgrade if below threshold
668
+ if (fpsWatchdogActive) {
669
+ fpsFrames++;
670
+ const elapsed_ms = performance.now() - fpsStartTime;
671
+ if (elapsed_ms >= FPS_SAMPLE_WINDOW) {
672
+ const avgFps = (fpsFrames / elapsed_ms) * 1000;
673
+ if (avgFps < FPS_THRESHOLD) {
674
+ downgradeQuality();
675
+ } else {
676
+ // Performance is fine, stop watching
677
+ fpsWatchdogActive = false;
678
+ }
679
+ }
680
+ }
681
+ }
682
+
683
+ renderer.setAnimationLoop(animate);
684
+
685
+ // ============ RESIZE (debounced — render loop never pauses) ============
686
+ function handleResize() {
687
+ size = getSize();
688
+ camera.aspect = size.width / size.height;
689
+ camera.updateProjectionMatrix();
690
+
691
+ const pr = Math.min(window.devicePixelRatio, quality.pixelRatio);
692
+ renderer.setPixelRatio(pr);
693
+ renderer.setSize(size.width, size.height);
694
+
695
+ quadMaterial.uniforms.uResolution.value.set(size.width, size.height);
696
+ quadMaterial.uniforms.uPixelRatio.value = pr;
697
+ dotMatrixPass.uniforms.uResolution.value.set(size.width, size.height);
698
+
699
+ composer.setSize(size.width, size.height);
700
+ }
701
+
702
+ window.addEventListener('resize', () => {
703
+ clearTimeout(resizeTimeout);
704
+ // Immediately update the canvas CSS size so it fills the window (no black gaps)
705
+ // but defer the expensive framebuffer reallocation
706
+ renderer.domElement.style.width = window.innerWidth + 'px';
707
+ renderer.domElement.style.height = window.innerHeight + 'px';
708
+ resizeTimeout = setTimeout(handleResize, 200);
709
+ }, { passive: true });
710
+
711
+ // ============ DEFERRED INIT — pre-warm the shader after first paint ============
712
+ // Force one render so the first real frame doesn't stutter on shader compile.
713
+ if ('requestIdleCallback' in window) {
714
+ requestIdleCallback(() => composer.render(), { timeout: 1000 });
715
+ } else {
716
+ setTimeout(() => composer.render(), 200); // Safari fallback
717
+ }