@vibechain/os 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/AGENTS.md +76 -48
  2. package/README.md +131 -54
  3. package/SECURITY.md +45 -20
  4. package/dist/app-client.d.ts +4 -1
  5. package/dist/app-client.js +4 -1
  6. package/dist/app-host.d.ts +111 -9
  7. package/dist/app-host.js +339 -58
  8. package/dist/app-protocol.d.ts +2 -0
  9. package/dist/app-runtime.d.ts +18 -2
  10. package/dist/app-runtime.js +75 -11
  11. package/dist/app-wire.d.ts +194 -0
  12. package/dist/app-wire.js +253 -0
  13. package/dist/browser.d.ts +2 -0
  14. package/dist/browser.js +2 -0
  15. package/dist/bundle.js +6 -6
  16. package/dist/canvas.d.ts +2 -2
  17. package/dist/canvas.js +3 -1
  18. package/dist/check.d.ts +12 -0
  19. package/dist/check.js +167 -0
  20. package/dist/cli-publish.d.ts +24 -0
  21. package/dist/cli-publish.js +288 -0
  22. package/dist/cli-session.d.ts +108 -0
  23. package/dist/cli-session.js +245 -0
  24. package/dist/cli.d.ts +10 -0
  25. package/dist/cli.js +46 -10
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.js +3 -0
  28. package/dist/listing.d.ts +3 -3
  29. package/dist/listing.js +1 -1
  30. package/dist/loop.d.ts +18 -2
  31. package/dist/loop.js +13 -1
  32. package/dist/manifest.d.ts +90 -4
  33. package/dist/manifest.js +340 -5
  34. package/dist/os.d.ts +56 -0
  35. package/dist/os.js +354 -0
  36. package/dist/preview-parent.d.ts +36 -0
  37. package/dist/preview-parent.js +122 -11
  38. package/dist/preview-ui.js +1 -1
  39. package/dist/preview.js +25 -7
  40. package/dist/redact.d.ts +6 -0
  41. package/dist/redact.js +16 -0
  42. package/dist/runtime-policy.d.ts +20 -0
  43. package/dist/runtime-policy.js +45 -0
  44. package/dist/scaffold.d.ts +13 -2
  45. package/dist/scaffold.js +95 -31
  46. package/dist/submit-notice.d.ts +26 -0
  47. package/dist/submit-notice.js +34 -0
  48. package/dist/templates/plain/game.js +18 -0
  49. package/dist/testing.d.ts +63 -0
  50. package/dist/testing.js +157 -1
  51. package/dist/transport.d.ts +20 -0
  52. package/dist/transport.js +71 -19
  53. package/dist/vibemarket-os.js +1 -0
  54. package/dist/worker.d.ts +18 -0
  55. package/dist/worker.js +34 -0
  56. package/examples/paw-beat/README.md +20 -8
  57. package/examples/paw-beat/cat.ts +665 -89
  58. package/examples/paw-beat/game.ts +162 -28
  59. package/examples/paw-beat/index.html +114 -40
  60. package/examples/paw-beat/main.ts +264 -149
  61. package/examples/paw-beat/music.ts +314 -65
  62. package/examples/paw-beat/stage.ts +560 -0
  63. package/examples/paw-beat/store/icon.png +0 -0
  64. package/examples/paw-beat/store/screenshot-1.webp +0 -0
  65. package/examples/paw-beat/store/screenshot-2.webp +0 -0
  66. package/examples/paw-beat/vibemarket.json +2 -2
  67. package/examples/vibexp-app/README.md +7 -7
  68. package/examples/vibexp-app/index.html +3 -2
  69. package/examples/vibexp-app/plain/game.ts +20 -0
  70. package/examples/vibexp-app/plain/index.html +6 -0
  71. package/examples/vibexp-app/plain/vibemarket.json +17 -0
  72. package/examples/vibexp-app/src/main.ts +46 -31
  73. package/examples/vibexp-app/store/icon.png +0 -0
  74. package/examples/vibexp-app/three/README.md +21 -0
  75. package/examples/vibexp-app/three/index.html +4 -0
  76. package/examples/vibexp-app/three/src/main.ts +45 -0
  77. package/examples/vibexp-app/three/vibemarket.json +19 -0
  78. package/examples/vibexp-app/vibemarket.json +17 -11
  79. package/package.json +6 -2
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Paw Beat rules. Pure TypeScript: no DOM, no renderer, no audio, no SDK. main.ts feeds
3
3
  * in the song clock and key presses and reads state out, so every rule is unit-testable.
4
+ *
5
+ * The song's shape lives here too, as plain data: its sections and its lead melody. music.ts
6
+ * plays them, createChart writes the steps from them and the stage colours itself by them,
7
+ * so what you hear, what you press and what you see cannot drift apart.
4
8
  */
5
9
 
6
10
  export const LANES = ["left", "down", "up", "right"] as const;
@@ -8,13 +12,80 @@ export type Lane = typeof LANES[number];
8
12
 
9
13
  export const BPM = 120;
10
14
  export const BEAT_SECONDS = 60 / BPM;
11
- /** Four silent beats to count in, then 112 beats of steps: one minute in all. */
15
+ export const BEATS_PER_BAR = 4;
16
+ /** One bar of count-in clicks, then 28 bars of song: just under a minute in all. */
12
17
  export const COUNT_IN_BEATS = 4;
13
18
  export const SONG_BEATS = 116;
14
19
  export const SONG_SECONDS = SONG_BEATS * BEAT_SECONDS;
15
20
  /** The host accepts integer scores up to this value. */
16
21
  export const SCORE_LIMIT = 1_000_000_000;
17
22
 
23
+ // ---- The song's sections ----
24
+
25
+ export type SectionName = "count-in" | "intro" | "build" | "drop" | "breakdown" | "finale" | "outro";
26
+ export interface Section { readonly name: SectionName; readonly start: number; readonly beats: number }
27
+ /** In order, back to back, from beat 0 to SONG_BEATS. */
28
+ export const SECTIONS: readonly Section[] = [
29
+ { name: "count-in", start: 0, beats: 4 },
30
+ { name: "intro", start: 4, beats: 16 },
31
+ { name: "build", start: 20, beats: 16 },
32
+ { name: "drop", start: 36, beats: 32 },
33
+ { name: "breakdown", start: 68, beats: 16 },
34
+ { name: "finale", start: 84, beats: 24 },
35
+ { name: "outro", start: 108, beats: 8 },
36
+ ];
37
+
38
+ /** The section playing at `beat` (clamped to the song). */
39
+ export function sectionAt(beat: number): Section {
40
+ for (let index = SECTIONS.length - 1; index > 0; index--) if (beat >= SECTIONS[index]!.start) return SECTIONS[index]!;
41
+ return SECTIONS[0]!;
42
+ }
43
+
44
+ // ---- The lead melody ----
45
+
46
+ /**
47
+ * One note of the tune, in song beats. `degree` is a step of the A natural minor scale with
48
+ * 0 = A4 (so 4 = E5, 7 = A5). `voice` says which instrument plays it: the lead carries the tune
49
+ * in the drop, finale and outro; the pluck teases it in the intro; the bell echoes it in the breakdown.
50
+ */
51
+ export type Voice = "lead" | "pluck" | "bell";
52
+ export interface TuneNote { readonly beat: number; readonly length: number; readonly degree: number; readonly voice: Voice }
53
+
54
+ /** Two bars of tune: [start, length, degree], with start and length in eighth notes. */
55
+ type Phrase = readonly (readonly [number, number, number])[];
56
+ // The call, over A minor then F: a leap up to A5, a fall back to E, then a settle on C.
57
+ const CALL_A: Phrase = [[0, 2, 4], [2, 1, 7], [3, 1, 6], [4, 2, 4], [6, 1, 3], [7, 1, 4], [8, 3, 2], [11, 1, 3], [12, 1, 2], [13, 1, 0], [14, 2, 2]];
58
+ // Over C then G it climbs to C6 and stops on D, a question.
59
+ const CALL_B: Phrase = [[0, 2, 6], [2, 1, 4], [3, 1, 6], [4, 3, 9], [7, 1, 8], [8, 3, 7], [11, 1, 6], [12, 4, 3]];
60
+ // Three ways to answer it; the seed picks one, so each round's drop ends a little differently.
61
+ const ANSWERS: readonly Phrase[] = [
62
+ [[0, 2, 6], [2, 1, 4], [3, 1, 6], [4, 2, 9], [6, 1, 8], [7, 1, 7], [8, 3, 8], [11, 1, 6], [12, 4, 4]],
63
+ [[0, 1, 4], [1, 1, 6], [2, 2, 9], [4, 2, 8], [6, 1, 7], [7, 1, 6], [8, 2, 8], [10, 2, 7], [12, 4, 6]],
64
+ [[0, 2, 9], [2, 1, 8], [3, 1, 6], [4, 2, 4], [6, 2, 6], [8, 2, 3], [10, 1, 4], [11, 1, 6], [12, 4, 8]],
65
+ ];
66
+ // G, A, B over the G chord, then home to A over A minor: the ending resolves.
67
+ const CADENCE: Phrase = [[0, 3, 6], [3, 1, 7], [4, 4, 8], [8, 8, 7]];
68
+
69
+ /** The whole tune for one round, ordered by beat. Deterministic per seed. */
70
+ export function createTune(seed: number): TuneNote[] {
71
+ const tune: TuneNote[] = [];
72
+ const place = (phrase: Phrase, start: number, voice: Voice, onBeatOnly = false) => {
73
+ for (const [at, length, degree] of phrase) {
74
+ if (onBeatOnly && at % 2 === 1) continue;
75
+ tune.push({ beat: start + at / 2, length: length / 2, degree, voice });
76
+ }
77
+ };
78
+ const answer = ANSWERS[(seed >>> 0) % ANSWERS.length]!;
79
+ place(CALL_A, 12, "pluck"); // the second half of the intro hints at the tune
80
+ place(CALL_A, 36, "lead"); place(CALL_B, 44, "lead"); place(CALL_A, 52, "lead"); place(answer, 60, "lead"); // drop
81
+ place(CALL_A, 68, "bell", true); place(CALL_B, 76, "bell", true); // breakdown: the tune's downbeats, softly
82
+ place(CALL_A, 84, "lead"); place(CALL_B, 92, "lead"); place(CALL_A, 100, "lead"); // finale
83
+ place(CADENCE, 108, "lead"); // outro
84
+ return tune;
85
+ }
86
+
87
+ // ---- Judging ----
88
+
18
89
  /** How close to the beat a press must land, in seconds, and what it pays. */
19
90
  const WINDOWS = [
20
91
  { judgement: "perfect", within: 0.05, points: 100 },
@@ -47,6 +118,30 @@ export interface DanceGame {
47
118
  press(lane: Lane): NoteView | null;
48
119
  }
49
120
 
121
+ /** Every ten steps in a row adds 10% to each step, up to double. */
122
+ export function comboMultiplier(combo: number): number {
123
+ return Math.min(2, 1 + Math.floor(Math.max(0, combo) / 10) * 0.1);
124
+ }
125
+
126
+ /** Combo counts that earn a callout and a celebration. */
127
+ export const COMBO_MILESTONES: readonly number[] = [10, 25, 50, 75, 100];
128
+
129
+ export type Grade = "S" | "A" | "B" | "C" | "D";
130
+ export interface RoundResult { readonly accuracy: number; readonly grade: Grade; readonly fullCombo: boolean }
131
+
132
+ /**
133
+ * Accuracy is the share of the best possible timing, in percent to one decimal: a perfect
134
+ * counts fully, a great 70%, a good 40% and a miss nothing. The grade follows from it; S also
135
+ * needs every step hit.
136
+ */
137
+ export function gradeRound(counts: Readonly<Record<Judgement, number>>): RoundResult {
138
+ const total = counts.perfect + counts.great + counts.good + counts.miss;
139
+ const accuracy = total === 0 ? 0 : Math.round((1000 * (counts.perfect + 0.7 * counts.great + 0.4 * counts.good)) / total) / 10;
140
+ const fullCombo = total > 0 && counts.miss === 0;
141
+ const grade: Grade = accuracy >= 95 && fullCombo ? "S" : accuracy >= 88 ? "A" : accuracy >= 75 ? "B" : accuracy >= 55 ? "C" : "D";
142
+ return { accuracy, grade, fullCombo };
143
+ }
144
+
50
145
  /** Small deterministic generator, so a seed replays the same steps. */
51
146
  function random(seed: number): () => number {
52
147
  let state = seed >>> 0;
@@ -58,37 +153,76 @@ function random(seed: number): () => number {
58
153
  };
59
154
  }
60
155
 
156
+ /** The other paw of a jump: left with right, up with down. */
157
+ const MIRROR: Readonly<Record<Lane, Lane>> = { left: "right", right: "left", up: "down", down: "up" };
158
+ /** The neighbour with the same sense (up and right read as "higher", down and left as "lower"). */
159
+ const NEIGHBOUR: Readonly<Record<Lane, Lane>> = { up: "right", right: "up", down: "left", left: "down" };
160
+ /** Four-beat walking patterns for the sections without a tune to follow. */
161
+ const WALKS: readonly (readonly Lane[])[] = [
162
+ ["left", "right", "left", "right"], ["down", "up", "down", "up"], ["left", "down", "up", "right"],
163
+ ["right", "up", "down", "left"], ["left", "up", "right", "down"], ["up", "left", "down", "right"],
164
+ ];
165
+
61
166
  /**
62
- * Write the steps for one song. It warms up on the beat, adds off-beat steps in the
63
- * middle and two-paw jumps near the end. The same lane never repeats on an off-beat,
64
- * so every pattern is playable with four keys.
167
+ * Write the steps for one round from the song itself:
168
+ * - intro: half notes, then every beat, on the kick;
169
+ * - build: every beat, in walking patterns;
170
+ * - drop: the lead melody's rhythm, with arrows that follow its shape (a step up is ↑, a leap
171
+ * up is →, a step down ↓, a leap down ←), keeping every on-beat note and most off-beat ones;
172
+ * - breakdown: half notes on the bell, then a bar of quarters to lead back in;
173
+ * - finale: every note of the melody, with two-paw jumps on the bar downbeats;
174
+ * - outro: the closing cadence and a final jump on the last chord.
175
+ * No lane ever follows itself and a jump's two lanes are never the next step's, so every
176
+ * pattern is playable with four keys.
65
177
  */
66
178
  export function createChart(seed: number): Note[] {
67
179
  const next = random(seed), notes: Note[] = [];
68
- const pick = (avoid?: Lane): Lane => {
69
- const pool = LANES.filter(lane => lane !== avoid);
70
- return pool[Math.floor(next() * pool.length)] ?? "left";
71
- };
72
- let previous: Lane | undefined;
73
- for (let beat = COUNT_IN_BEATS; beat < SONG_BEATS - 2; beat++) {
74
- const progress = (beat - COUNT_IN_BEATS) / (SONG_BEATS - COUNT_IN_BEATS);
75
- // Leave a breath at the end of every eight-beat phrase.
76
- if (beat % 8 === 7 && progress < 0.75) continue;
77
- const lane = pick(previous);
180
+ let previous: Lane | undefined, jumpPartner: Lane | undefined;
181
+ const add = (beat: number, wanted: Lane, jump = false) => {
182
+ // The wanted lane, or the nearest one in sense that uses none of the lanes just pressed.
183
+ const used = (lane: Lane) => lane === previous || lane === jumpPartner;
184
+ const lane = [wanted, NEIGHBOUR[wanted], MIRROR[wanted], MIRROR[NEIGHBOUR[wanted]]].find(lane => !used(lane) && !(jump && used(MIRROR[lane]))) ?? wanted;
78
185
  notes.push({ time: beat * BEAT_SECONDS, lane });
79
186
  previous = lane;
80
- if (progress > 0.7 && next() < 0.3) {
81
- // A jump: a second paw on the same beat.
82
- notes.push({ time: beat * BEAT_SECONDS, lane: pick(lane) });
83
- } else if (progress > 0.3 && next() < 0.4) {
84
- const between = pick(previous);
85
- notes.push({ time: (beat + 0.5) * BEAT_SECONDS, lane: between });
86
- previous = between;
187
+ jumpPartner = undefined;
188
+ if (jump) {
189
+ notes.push({ time: beat * BEAT_SECONDS, lane: MIRROR[lane] });
190
+ jumpPartner = MIRROR[lane];
87
191
  }
88
- }
192
+ };
193
+ const walk = (from: number, to: number, every: number) => {
194
+ let pattern = WALKS[0]!;
195
+ for (let beat = from, step = 0; beat < to; beat += every, step++) {
196
+ if (step % 4 === 0) pattern = WALKS[Math.floor(next() * WALKS.length)] ?? WALKS[0]!;
197
+ add(beat, pattern[step % 4]!);
198
+ }
199
+ };
200
+
201
+ const tune = createTune(seed).filter(note => note.voice === "lead");
202
+ let lastDegree = 4;
203
+ const sing = (from: number, to: number) => {
204
+ for (const note of tune) {
205
+ if (note.beat < from || note.beat >= to) continue;
206
+ const section = sectionAt(note.beat).name, offBeat = note.beat % 1 !== 0;
207
+ const rise = note.degree - lastDegree;
208
+ lastDegree = note.degree;
209
+ // The drop leaves out about a third of its off-beat notes; the finale and outro keep them all.
210
+ if (section === "drop" && offBeat && next() < 0.35) continue;
211
+ const shaped: Lane = rise >= 3 ? "right" : rise > 0 ? "up" : rise <= -3 ? "left" : rise < 0 ? "down" : next() < 0.5 ? "left" : "right";
212
+ add(note.beat, shaped, (section === "finale" && note.beat % BEATS_PER_BAR === 0) || note.beat === SONG_BEATS - 4);
213
+ }
214
+ };
215
+ walk(4, 12, 2); // intro: half notes
216
+ walk(12, 36, 1); // the rest of the intro and the build: every beat
217
+ sing(36, 68); // drop
218
+ walk(68, 80, 2); // breakdown
219
+ walk(80, 84, 1); // and a bar of quarters back in
220
+ sing(84, SONG_BEATS); // finale and outro
89
221
  return notes;
90
222
  }
91
223
 
224
+ const NONE: readonly NoteView[] = Object.freeze([]);
225
+
92
226
  export function createGame(seed = 1): DanceGame {
93
227
  const chart = createChart(seed);
94
228
  const judged: (Judgement | null)[] = chart.map(() => null);
@@ -102,19 +236,20 @@ export function createGame(seed = 1): DanceGame {
102
236
  return { time, score, combo, bestCombo, counts: { ...counts }, finished: time >= SONG_SECONDS };
103
237
  },
104
238
  advance(next) {
105
- if (!Number.isFinite(next) || next <= time) return [];
239
+ if (!Number.isFinite(next) || next <= time) return NONE;
106
240
  time = Math.min(next, SONG_SECONDS);
107
- const missed: NoteView[] = [];
241
+ // Called every frame, so it allocates only when something was actually missed.
242
+ let missed: NoteView[] | undefined;
108
243
  for (let index = firstOpen; index < chart.length && chart[index]!.time < time - MISS_AFTER; index++) {
109
244
  if (judged[index] === null) {
110
245
  judged[index] = "miss";
111
246
  counts.miss += 1;
112
247
  combo = 0;
113
- missed.push(view(index));
248
+ (missed ??= []).push(view(index));
114
249
  }
115
250
  }
116
251
  while (firstOpen < chart.length && judged[firstOpen] !== null) firstOpen++;
117
- return missed;
252
+ return missed ?? NONE;
118
253
  },
119
254
  each(from, to, visit) {
120
255
  // Binary search for the first note at or after `from`.
@@ -143,8 +278,7 @@ export function createGame(seed = 1): DanceGame {
143
278
  counts[window.judgement] += 1;
144
279
  combo += 1;
145
280
  bestCombo = Math.max(bestCombo, combo);
146
- // Every ten steps in a row adds 10%, up to double.
147
- score = Math.min(SCORE_LIMIT, score + Math.round(window.points * Math.min(2, 1 + Math.floor(combo / 10) * 0.1)));
281
+ score = Math.min(SCORE_LIMIT, score + Math.round(window.points * comboMultiplier(combo)));
148
282
  return view(best);
149
283
  },
150
284
  };
@@ -5,59 +5,133 @@
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <title>Paw Beat</title>
7
7
  <style>
8
- html, body { margin: 0; height: 100%; overflow: hidden; background: #150f24; color: #fff6ea; font: 16px/1.4 system-ui, sans-serif; }
9
- canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
10
- .hud { position: fixed; left: 0; right: 0; top: 0; display: flex; gap: 24px; padding: 12px 16px; pointer-events: none; font-weight: 700; text-shadow: 0 1px 2px #000a; }
11
- .hud span { font-variant-numeric: tabular-nums; font-size: 22px; }
12
- .hud small { display: block; font-weight: 500; opacity: .7; letter-spacing: .08em; font-size: 11px; }
13
- #call { position: fixed; left: 0; right: 0; top: 22%; text-align: center; font: 800 40px system-ui, sans-serif; letter-spacing: .04em; pointer-events: none; opacity: 0; text-shadow: 0 2px 8px #000c; }
14
- #call.show { animation: pop .45s ease-out; }
15
- #call[data-kind="perfect"] { color: #ffd166; }
16
- #call[data-kind="great"] { color: #7bd88f; }
17
- #call[data-kind="good"] { color: #4cc9f0; }
18
- #call[data-kind="miss"] { color: #ff5c8a; }
19
- @keyframes pop { 0% { opacity: 1; transform: scale(1.25); } 100% { opacity: 0; transform: scale(1); } }
20
- @media (prefers-reduced-motion: reduce) { #call.show { animation: none; opacity: 1; } }
21
- .pads { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px; }
22
- .pads button { margin: 0; padding: 14px 0; border-radius: 14px; border: 2px solid #ffffff38; background: #ffffff14; color: #fff; font: 700 24px system-ui, sans-serif; touch-action: none; }
23
- .pads button:active, .pads button.down { background: #ffffff40; }
24
- .card { position: fixed; inset: 0; display: grid; place-items: center; background: #150f24e0; text-align: center; padding: 24px; }
25
- .card[hidden], .hud[hidden], .pads[hidden] { display: none; }
26
- .card h1 { font-size: 46px; margin: 0 0 8px; }
27
- .card p { max-width: 440px; margin: 8px auto; opacity: .85; }
28
- .card button { margin-top: 16px; border: 0; border-radius: 999px; padding: 14px 30px; font: 700 18px system-ui, sans-serif; background: #ffd166; color: #150f24; cursor: pointer; }
8
+ :root { --ink: #0d0918; --paper: #fff6ea; --gold: #ffd166; --left: #ff5c8a; --down: #4cc9f0; --up: #ffd166; --right: #7bd88f; --unit: min(1vw, 1.6vh); }
9
+ html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--paper); font: 16px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }
10
+ canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
11
+ [hidden] { display: none !important; }
12
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
13
+ button { font: inherit; color: inherit; cursor: pointer; }
29
14
  button:disabled { opacity: .5; cursor: default; }
30
15
  button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
31
- kbd { padding: 1px 6px; border-radius: 5px; background: #ffffff26; font: inherit; }
16
+ .primary { border: 0; border-radius: 999px; padding: .7em 1.6em; font-weight: 800; font-size: clamp(14px, calc(var(--unit) * 2.2), 20px); background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #b8891f; }
17
+ .primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8891f; }
18
+
19
+ /* Heads-up display: score at the left, the song's progress in the middle, sound at the right. */
20
+ .hud { position: fixed; left: 0; right: 0; top: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 2.4vw; padding: max(6px, 1.4vh) max(8px, 2vw); pointer-events: none; text-shadow: 0 1px 3px #000c; }
21
+ .hud small { display: block; font-size: clamp(9px, calc(var(--unit) * 1.3), 12px); letter-spacing: .12em; opacity: .7; font-weight: 600; }
22
+ .score { font-weight: 800; font-size: clamp(16px, calc(var(--unit) * 3.4), 34px); font-variant-numeric: tabular-nums; line-height: 1; }
23
+ .score em { font-style: normal; font-size: .5em; color: var(--gold); margin-left: .35em; vertical-align: .35em; }
24
+ .progress { margin-top: clamp(4px, 1.2vh, 12px); height: clamp(5px, 1vh, 9px); border-radius: 9px; background: #ffffff1f; overflow: hidden; display: flex; position: relative; }
25
+ .progress i { display: block; height: 100%; background: #ffffff14; border-right: 1px solid #0d091899; }
26
+ .progress b { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, var(--left), var(--gold)); border-radius: 9px; }
27
+ .sound { pointer-events: auto; position: fixed; top: max(6px, 1.2vh); right: max(8px, 2vw); z-index: 3; border: 2px solid #ffffff40; background: #0d0918b3; border-radius: 999px; padding: .3em .8em; font-size: clamp(11px, calc(var(--unit) * 1.6), 15px); font-weight: 700; }
28
+ .sound[aria-pressed="false"] { opacity: .75; }
29
+ .hud .spacer { width: clamp(70px, 12vw, 130px); }
30
+
31
+ /* Judgement and combo: placed by main.ts in the gap in front of the cat, between the inner targets. */
32
+ .callout { position: fixed; left: 0; top: 0; transform: translate(-50%, -100%); text-align: center; pointer-events: none; text-shadow: 0 2px 6px #000d; white-space: nowrap; }
33
+ #call { font-weight: 900; letter-spacing: .04em; font-size: clamp(14px, calc(var(--unit) * 3.6), 38px); opacity: 0; }
34
+ #call[data-kind="perfect"] { color: var(--gold); }
35
+ #call[data-kind="great"] { color: var(--right); }
36
+ #call[data-kind="good"] { color: var(--down); }
37
+ #call[data-kind="miss"] { color: #b9aec9; }
38
+ #call[data-kind="count"] { color: var(--paper); font-size: clamp(22px, calc(var(--unit) * 7), 72px); }
39
+ .combo { font-weight: 900; font-variant-numeric: tabular-nums; font-size: clamp(16px, calc(var(--unit) * 4.2), 44px); line-height: 1; }
40
+ .combo small { display: block; font-size: .36em; letter-spacing: .2em; opacity: .8; font-weight: 700; }
41
+ .combo.milestone { color: var(--gold); }
42
+
43
+ .pads { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: max(4px, 1vw); padding: max(4px, 1vh) max(6px, 1.5vw); }
44
+ .pads button { padding: clamp(4px, 1.6vh, 14px) 0; border-radius: 14px; border: 2px solid; background: #0d091866; font-weight: 900; font-size: clamp(14px, calc(var(--unit) * 3), 28px); line-height: 1; touch-action: none; }
45
+ .pads [data-lane="left"] { border-color: var(--left); color: var(--left); }
46
+ .pads [data-lane="down"] { border-color: var(--down); color: var(--down); }
47
+ .pads [data-lane="up"] { border-color: var(--up); color: var(--up); }
48
+ .pads [data-lane="right"] { border-color: var(--right); color: var(--right); }
49
+ .pads button.down { background: currentColor; }
50
+ .pads button.down span { color: var(--ink); }
51
+
52
+ /* Cards: at the left on wide windows (Biscuit dances on the right), a bottom sheet on tall ones. */
53
+ .card { position: fixed; left: 0; top: 0; bottom: 0; width: min(48%, 460px); display: flex; flex-direction: column; justify-content: center; gap: clamp(4px, 1.6vh, 16px); padding: max(10px, 2.5vh) max(12px, 3vw); box-sizing: border-box; background: linear-gradient(90deg, #0d0918f2 60%, #0d091800); }
54
+ @media (max-aspect-ratio: 23/20) {
55
+ .card { top: auto; right: 0; width: auto; max-height: 62%; justify-content: flex-end; background: linear-gradient(0deg, #0d0918f2 65%, #0d091800); padding-top: 8vh; text-align: center; align-items: center; }
56
+ }
57
+ .card p { margin: 0; max-width: 34em; opacity: .9; font-size: clamp(11px, calc(var(--unit) * 1.8), 16px); }
58
+ .logo { margin: 0; font-size: clamp(26px, calc(var(--unit) * 7.5), 76px); line-height: .95; font-weight: 900; letter-spacing: -.02em; }
59
+ .logo span:nth-child(1) { color: var(--left); } .logo span:nth-child(2) { color: var(--gold); }
60
+ .how { display: flex; gap: clamp(4px, 1vw, 10px); align-items: center; flex-wrap: wrap; }
61
+ .key { display: inline-grid; place-items: center; width: clamp(24px, calc(var(--unit) * 5), 46px); aspect-ratio: 1; border-radius: 10px; border: 2px solid currentColor; font-weight: 900; font-size: clamp(13px, calc(var(--unit) * 2.6), 24px); background: #ffffff0d; }
62
+ .key small { font-size: .45em; opacity: .8; display: block; margin-top: -.2em; }
63
+ .best { color: var(--gold); font-weight: 700; }
64
+ .grade { font-size: clamp(40px, calc(var(--unit) * 13), 130px); line-height: .9; font-weight: 900; color: var(--gold); text-shadow: 0 4px 0 #0007; }
65
+ .final { font-size: clamp(18px, calc(var(--unit) * 4.4), 44px); font-weight: 900; font-variant-numeric: tabular-nums; }
66
+ .final mark { background: var(--gold); color: var(--ink); border-radius: 999px; padding: .1em .55em; font-size: .4em; vertical-align: .45em; margin-left: .4em; white-space: nowrap; display: inline-block; }
67
+ .stats { display: grid; grid-template-columns: repeat(3, auto); gap: .25em 1.2em; margin: 0; font-size: clamp(11px, calc(var(--unit) * 1.7), 16px); }
68
+ .stats div { display: flex; flex-direction: column; }
69
+ .stats dt { opacity: .7; font-size: .8em; letter-spacing: .06em; }
70
+ .stats dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }
71
+ /* Very short windows keep the essentials: title and start, or grade, score, accuracy and best combo. */
72
+ @media (max-height: 330px) {
73
+ .tagline, .how, .note, .stats div:nth-child(n+3) { display: none; }
74
+ .stats { grid-template-columns: repeat(2, auto); }
75
+ }
76
+ .overlay { position: fixed; inset: 0; display: grid; place-items: center; text-align: center; background: #0d0918e8; padding: 16px; z-index: 4; }
32
77
  </style>
33
78
  </head>
34
79
  <body>
35
80
  <canvas id="scene" aria-label="Biscuit the cat dancing on a stage, with step arrows moving toward four targets."></canvas>
81
+
36
82
  <div class="hud" id="hud" hidden>
37
- <div><small>SCORE</small><span id="score">0</span></div>
38
- <div><small>COMBO</small><span id="combo">0</span></div>
39
- <div><small>TIME</small><span id="time">58</span></div>
83
+ <div><small>SCORE</small><div class="score"><span id="score">0</span><em id="multiplier" hidden></em></div></div>
84
+ <div class="progress" role="progressbar" aria-label="Song progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="progress"><i style="flex: 4"></i><i style="flex: 16"></i><i style="flex: 16"></i><i style="flex: 32"></i><i style="flex: 16"></i><i style="flex: 24"></i><i style="flex: 8; border: 0"></i><b id="played"></b></div>
85
+ <div class="spacer"></div>
40
86
  </div>
41
- <div id="call" role="status" aria-live="polite"></div>
87
+ <button class="sound" id="sound" type="button" aria-pressed="true">♪ Sound on</button>
88
+
89
+ <div class="callout" id="callout" aria-hidden="true">
90
+ <div id="call"></div>
91
+ <div class="combo" id="combo" hidden><span id="combo-count">0</span><small id="combo-label">COMBO</small></div>
92
+ </div>
93
+ <div class="sr" id="say" role="status" aria-live="polite"></div>
94
+
42
95
  <div class="pads" id="pads" hidden>
43
- <button type="button" data-lane="left" aria-label="Left step">←</button>
44
- <button type="button" data-lane="down" aria-label="Down step">↓</button>
45
- <button type="button" data-lane="up" aria-label="Up step">↑</button>
46
- <button type="button" data-lane="right" aria-label="Right step">→</button>
96
+ <button type="button" data-lane="left" aria-label="Left step"><span>←</span></button>
97
+ <button type="button" data-lane="down" aria-label="Down step"><span>↓</span></button>
98
+ <button type="button" data-lane="up" aria-label="Up step"><span>↑</span></button>
99
+ <button type="button" data-lane="right" aria-label="Right step"><span>→</span></button>
47
100
  </div>
48
- <section class="card" id="intro">
49
- <div>
50
- <h1>Paw Beat</h1>
51
- <p>Arrows slide toward the targets. Press the matching key as each one lands: <kbd>←</kbd> <kbd>↓</kbd> <kbd>↑</kbd> <kbd>→</kbd> or <kbd>A</kbd> <kbd>S</kbd> <kbd>W</kbd> <kbd>D</kbd>, or tap the pads. Biscuit dances every step you hit.</p>
52
- <p id="best"></p>
53
- <button id="start" type="button" disabled>Connecting…</button>
101
+
102
+ <section class="card" id="intro" aria-labelledby="title">
103
+ <h1 class="logo" id="title"><span>Paw</span> <span>Beat</span></h1>
104
+ <p class="tagline">Arrows slide toward the outlines. Press the matching key as each one lands, and Biscuit dances the step.</p>
105
+ <div class="how" aria-label="Keys: arrow keys or A, S, W and D">
106
+ <span class="key" style="color: var(--left)">←<small>A</small></span>
107
+ <span class="key" style="color: var(--down)">↓<small>S</small></span>
108
+ <span class="key" style="color: var(--up)">↑<small>W</small></span>
109
+ <span class="key" style="color: var(--right)">→<small>D</small></span>
54
110
  </div>
111
+ <p class="note">Or tap the pads. Perfect timing scores most, and every ten in a row adds 10%. <kbd>M</kbd> mutes.</p>
112
+ <p class="best" id="best">One song, about a minute.</p>
113
+ <div><button class="primary" id="start" type="button" disabled>Connecting…</button></div>
114
+ </section>
115
+
116
+ <section class="card" id="done" hidden aria-labelledby="grade">
117
+ <div class="grade" id="grade" aria-label="Grade">A</div>
118
+ <div class="final"><span id="done-score">0</span><mark id="new-best" hidden>New best!</mark><mark id="full-combo" hidden>Full combo</mark></div>
119
+ <dl class="stats">
120
+ <div><dt>ACCURACY</dt><dd id="accuracy">0%</dd></div>
121
+ <div><dt>BEST COMBO</dt><dd id="done-combo">0</dd></div>
122
+ <div><dt>PERFECT</dt><dd id="done-perfect">0</dd></div>
123
+ <div><dt>GREAT</dt><dd id="done-great">0</dd></div>
124
+ <div><dt>GOOD</dt><dd id="done-good">0</dd></div>
125
+ <div><dt>MISSED</dt><dd id="done-miss">0</dd></div>
126
+ </dl>
127
+ <p class="note" id="sent"></p>
128
+ <div><button class="primary" id="again" type="button">Dance again</button></div>
55
129
  </section>
56
- <section class="card" id="done" hidden>
130
+
131
+ <section class="overlay" id="lost" hidden>
57
132
  <div>
58
- <h1 id="done-score">0</h1>
59
- <p id="done-note"></p>
60
- <button id="again" type="button">Dance again</button>
133
+ <p id="lost-text">The graphics stopped. Waiting for them to come back…</p>
134
+ <p><button class="primary" id="resume" type="button" hidden>Continue</button></p>
61
135
  </div>
62
136
  </section>
63
137
  <script type="module" src="./game.js"></script>