@energy8platform/shell 0.6.6 → 0.7.1

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 (44) hide show
  1. package/dist/html.cjs.js +677 -109
  2. package/dist/html.cjs.js.map +1 -1
  3. package/dist/html.d.ts +207 -27
  4. package/dist/html.esm.js +670 -110
  5. package/dist/html.esm.js.map +1 -1
  6. package/dist/index.cjs.js +378 -22
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.d.ts +199 -26
  9. package/dist/index.esm.js +371 -23
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/pixi.cjs.js +952 -282
  12. package/dist/pixi.cjs.js.map +1 -1
  13. package/dist/pixi.d.ts +202 -28
  14. package/dist/pixi.esm.js +945 -283
  15. package/dist/pixi.esm.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/core/ShellController.ts +68 -16
  18. package/src/core/format.ts +8 -4
  19. package/src/core/icon-names.ts +30 -0
  20. package/src/core/index.ts +4 -0
  21. package/src/core/menu.ts +301 -0
  22. package/src/core/popover.ts +81 -0
  23. package/src/core/renderer.ts +13 -10
  24. package/src/core/state.ts +2 -1
  25. package/src/core/types.ts +15 -6
  26. package/src/core/version.ts +1 -1
  27. package/src/ui/html/HtmlRenderer.ts +31 -8
  28. package/src/ui/html/components/GameInfo.ts +1 -1
  29. package/src/ui/html/components/Menu.ts +153 -0
  30. package/src/ui/html/icons.ts +16 -15
  31. package/src/ui/html/primitives.ts +142 -0
  32. package/src/ui/html/shell.css.ts +21 -1
  33. package/src/ui/pixi/PixiRenderer.ts +32 -14
  34. package/src/ui/pixi/components/BottomBar.ts +80 -9
  35. package/src/ui/pixi/components/GameInfo.ts +1 -1
  36. package/src/ui/pixi/components/Menu.ts +167 -0
  37. package/src/ui/pixi/context.ts +3 -2
  38. package/src/ui/pixi/icons.ts +16 -15
  39. package/src/ui/pixi/pixi-icon.ts +15 -3
  40. package/src/ui/pixi/primitives/controls.ts +46 -0
  41. package/src/ui/pixi/primitives/popover.ts +163 -0
  42. package/src/ui/pixi/primitives/scroll.ts +9 -5
  43. package/src/ui/html/components/Settings.ts +0 -68
  44. package/src/ui/pixi/components/Settings.ts +0 -132
package/dist/pixi.esm.js CHANGED
@@ -51,6 +51,240 @@ class EventEmitter {
51
51
  }
52
52
  }
53
53
 
54
+ // AUTO-GENERATED from ../../icons.svg by scripts/gen-icons-from-svg.mjs — do not edit by hand.
55
+ // Sharp monochrome icon set: each glyph is a 24×24 viewBox fragment using currentColor
56
+ // (hollow shapes use fill-rule="evenodd"). Coordinates are baked into the 24×24 space (no
57
+ // <g transform>), so the same fragment renders identically in the DOM <svg> and in Pixi's
58
+ // GraphicsContext.svg. To change an icon: edit icons.svg, then run
59
+ // `node scripts/gen-icons-from-svg.mjs`.
60
+ // The single glyph-name union, shared by core (menu items) and both renderers.
61
+ const ICON_NAMES = [
62
+ 'spin',
63
+ 'turbo1',
64
+ 'autoplay',
65
+ 'stop',
66
+ 'menu',
67
+ 'minus',
68
+ 'plus',
69
+ 'gift',
70
+ 'info',
71
+ 'soundOn',
72
+ 'soundOff',
73
+ 'close',
74
+ 'back',
75
+ 'chevronRight',
76
+ 'ticket',
77
+ 'turbo2',
78
+ 'turboOff',
79
+ 'chevronUp',
80
+ 'chevronDown',
81
+ ];
82
+
83
+ const PRESET_IDS = ['sound', 'music', 'sfx', 'gameInfo'];
84
+ function isPresetId(id) {
85
+ return PRESET_IDS.includes(id);
86
+ }
87
+ /** The rows shown when `ShellConfig.menu` is omitted — today's Settings content, minus master. */
88
+ const DEFAULT_MENU = [
89
+ { id: 'sound' },
90
+ { id: 'music' },
91
+ { id: 'sfx' },
92
+ { type: 'separator' },
93
+ { id: 'gameInfo' },
94
+ ];
95
+ const isSeparator = (i) => i.type === 'separator';
96
+ /** Range bounds with defaults: 0..1 like a volume slider, step = a twentieth of the span. */
97
+ function rangeBounds(item) {
98
+ const min = item.min ?? 0;
99
+ const max = item.max ?? 1;
100
+ const derivedStep = (max - min) / 20;
101
+ // A declared `step` must be a genuinely positive number. `??` alone doesn't catch this: an
102
+ // explicit 0 (or a negative value) is not null/undefined, so it would sail through unchanged —
103
+ // and a renderer's position math divides by it (Pixi's fromUnit: `(raw-min)/step`), turning the
104
+ // slider's value into NaN, which then reaches `state.menu` and the `settingChange` payload.
105
+ const step = item.step != null && item.step > 0 ? item.step : derivedStep;
106
+ return { min, max, step };
107
+ }
108
+ /** Initial values for CUSTOM items (presets keep their own homes). Values already in `prev` win, so
109
+ * a later `setMenu()` with the same ids does not reset what the player has changed. */
110
+ function seedMenuValues(items, prev = {}) {
111
+ const out = {};
112
+ for (const item of items) {
113
+ if (isSeparator(item))
114
+ continue;
115
+ const type = item.type;
116
+ if (!type || isPresetId(item.id))
117
+ continue;
118
+ // A previous value only carries over when its runtime type still matches this item's kind.
119
+ // Without this guard, reconfiguring the same id from a toggle to a range (or back) would seed
120
+ // a boolean into a slider's position math (or a stale number into a checkbox) — a legitimate
121
+ // reconfiguration, not a config error, so it falls through to the item's own default instead
122
+ // of warning.
123
+ const prevValue = prev[item.id];
124
+ if (type === 'toggle') {
125
+ out[item.id] = typeof prevValue === 'boolean' ? prevValue : (item.value ?? false);
126
+ }
127
+ else if (type === 'range') {
128
+ const r = item;
129
+ out[item.id] = typeof prevValue === 'number' ? prevValue : (r.value ?? rangeBounds(r).min);
130
+ }
131
+ }
132
+ return out;
133
+ }
134
+ const percent = (v) => `${Math.round(v * 100)}%`;
135
+ function safeIcon(name) {
136
+ return name && ICON_NAMES.includes(name) ? name : undefined;
137
+ }
138
+ /** Every drop/collision warning goes through here so the message style stays uniform. */
139
+ function warn(message) {
140
+ console.warn(`[shell] ${message}`);
141
+ }
142
+ /** Expand the configured list into render-ready rows. A config mistake — an unknown preset id, an
143
+ * unrecognized custom `type`, or an invalid range span — is dropped with one warning rather than
144
+ * silently misbehaving: a typo must be visible, not silently invisible. A custom id that collides
145
+ * with a reserved preset id also warns, but keeps its row (see `custom()`). */
146
+ function resolveMenu(host) {
147
+ const rows = [];
148
+ for (const item of host.menu) {
149
+ if (isSeparator(item)) {
150
+ rows.push({ kind: 'separator' });
151
+ continue;
152
+ }
153
+ const type = item.type;
154
+ if (!type) {
155
+ const row = preset(host, item);
156
+ if (row)
157
+ rows.push(row);
158
+ else
159
+ warn(`unknown menu preset id "${item.id}" — item skipped`);
160
+ continue;
161
+ }
162
+ const row = custom(host, item, type);
163
+ if (row)
164
+ rows.push(row);
165
+ }
166
+ return rows;
167
+ }
168
+ function preset(host, item) {
169
+ const disabled = item.disabled ?? false;
170
+ const label = host.t(item.label ?? DEFAULT_LABELS[item.id] ?? item.id);
171
+ switch (item.id) {
172
+ case 'sound':
173
+ return {
174
+ kind: 'toggle',
175
+ id: 'sound',
176
+ label,
177
+ disabled,
178
+ icon: (v) => safeIcon(item.icon) ?? (v ? 'soundOn' : 'soundOff'),
179
+ get: () => host.getMenuValue('sound') !== false,
180
+ set: (v) => host.setMenuValue('sound', v),
181
+ };
182
+ case 'music':
183
+ case 'sfx': {
184
+ const id = item.id;
185
+ return {
186
+ kind: 'range',
187
+ id,
188
+ label,
189
+ icon: safeIcon(item.icon),
190
+ disabled,
191
+ min: 0,
192
+ max: 1,
193
+ step: 0.05,
194
+ get: () => Number(host.getMenuValue(id) ?? 1),
195
+ set: (v) => host.setMenuValue(id, v),
196
+ format: percent,
197
+ };
198
+ }
199
+ case 'gameInfo':
200
+ return {
201
+ kind: 'button',
202
+ id: 'gameInfo',
203
+ label,
204
+ icon: safeIcon(item.icon) ?? 'info',
205
+ disabled,
206
+ chevron: true,
207
+ select: () => host.actions.openInfo(),
208
+ };
209
+ default:
210
+ return null;
211
+ }
212
+ }
213
+ const DEFAULT_LABELS = {
214
+ sound: 'Sound',
215
+ music: 'Music',
216
+ sfx: 'SFX',
217
+ gameInfo: 'Game info',
218
+ };
219
+ function custom(host, item, type) {
220
+ // Same store, different semantics: the real preset's get() and a custom row's get() disagree
221
+ // (see the preset cases below vs. the toggle case here). Routing does not change — Task 4's
222
+ // ShellHost is what actually owns the value — this warning just makes the clash visible.
223
+ if (isPresetId(item.id)) {
224
+ warn(`menu item id "${item.id}" collides with a built-in preset id — preset ids are reserved`);
225
+ }
226
+ const disabled = item.disabled ?? false;
227
+ const label = host.t(item.label ?? item.id);
228
+ const icon = safeIcon(item.icon);
229
+ if (type === 'toggle') {
230
+ const it = item;
231
+ return {
232
+ kind: 'toggle',
233
+ id: it.id,
234
+ label,
235
+ disabled,
236
+ icon: () => icon,
237
+ get: () => host.getMenuValue(it.id) === true,
238
+ set: (v) => {
239
+ host.setMenuValue(it.id, v);
240
+ it.onChange?.(v);
241
+ },
242
+ };
243
+ }
244
+ if (type === 'range') {
245
+ const it = item;
246
+ const { min, max, step } = rangeBounds(it);
247
+ if (max <= min) {
248
+ // A renderer's position math ((value - min) / (max - min)) turns this into Infinity/NaN —
249
+ // drop the row instead, exactly like an unknown preset id.
250
+ warn(`menu item "${it.id}" has invalid range bounds (min ${min}, max ${max}) — item skipped`);
251
+ return null;
252
+ }
253
+ return {
254
+ kind: 'range',
255
+ id: it.id,
256
+ label,
257
+ icon,
258
+ disabled,
259
+ min,
260
+ max,
261
+ step,
262
+ get: () => Number(host.getMenuValue(it.id) ?? min),
263
+ set: (v) => {
264
+ host.setMenuValue(it.id, v);
265
+ it.onChange?.(v);
266
+ },
267
+ format: it.format ?? (min === 0 && max === 1 ? percent : (v) => String(v)),
268
+ };
269
+ }
270
+ if (type === 'button') {
271
+ const it = item;
272
+ return {
273
+ kind: 'button',
274
+ id: it.id,
275
+ label,
276
+ icon,
277
+ disabled,
278
+ chevron: it.chevron ?? false,
279
+ select: () => it.onSelect?.(),
280
+ };
281
+ }
282
+ // Neither toggle, range, nor button — a typo'd `type` used to fall through to an unconditional
283
+ // button row with no onSelect. Drop it visibly instead.
284
+ warn(`menu item "${item.id}" has unknown type "${type}" — item skipped`);
285
+ return null;
286
+ }
287
+
54
288
  function createInitialState(config) {
55
289
  return {
56
290
  mode: config.mode,
@@ -67,10 +301,10 @@ function createInitialState(config) {
67
301
  bonus: null,
68
302
  activeFeature: null,
69
303
  volumes: {
70
- master: clampVolume(config.volumes?.master),
71
304
  music: clampVolume(config.volumes?.music),
72
305
  sfx: clampVolume(config.volumes?.sfx),
73
306
  },
307
+ menu: seedMenuValues(config.menu ?? DEFAULT_MENU),
74
308
  };
75
309
  }
76
310
  /** Clamp a configured volume to 0..1, defaulting to full (1) when unset/invalid. */
@@ -168,15 +402,19 @@ function resolveTheme(theme = {}) {
168
402
  * trailing zeros are trimmed down to (but never past) `minDecimals`, so small wins keep their
169
403
  * significant digits. Balance / bet / prices stay fixed at `minDecimals`.
170
404
  *
405
+ * Separators default to the platform convention — `.` decimal, `,` thousands (`€1,234.50`).
406
+ * A comma decimal is NOT safe as a default: players read "2,50" as 250 and believe they were
407
+ * paid far more than they were. Games that need another convention pass `currency.separator`.
408
+ *
171
409
  * Example with `maxDecimals: 4, minDecimals: 2`:
172
- * fixed → 0.0673 → 0,07 0.3 → 0,30
173
- * variable → 0.0673 → 0,0673 0.067 → 0,067 0.3 → 0,30 0 → 0,00
410
+ * fixed → 0.0673 → 0.07 0.3 → 0.30
411
+ * variable → 0.0673 → 0.0673 0.067 → 0.067 0.3 → 0.30 0 → 0.00
174
412
  */
175
413
  function formatCurrency(value, currency, variableDecimals = false) {
176
414
  const maxDecimals = currency.maxDecimals ?? 2;
177
415
  const minDecimals = Math.max(0, Math.min(maxDecimals, currency.minDecimals ?? maxDecimals));
178
- const thousands = currency.separator?.thousands ?? '.';
179
- const decimal = currency.separator?.decimal ?? ',';
416
+ const thousands = currency.separator?.thousands ?? ',';
417
+ const decimal = currency.separator?.decimal ?? '.';
180
418
  const safe = Number.isFinite(value) ? value : 0;
181
419
  // fixed callers round at minDecimals; variable callers round at maxDecimals then trim back down.
182
420
  const places = variableDecimals ? maxDecimals : minDecimals;
@@ -1454,7 +1692,7 @@ class KeyboardController {
1454
1692
 
1455
1693
  // AUTO-GENERATED by scripts/gen-version.mjs — do not edit. Mirrors package.json "version".
1456
1694
  /** The @energy8platform/shell package version, stamped into the game-info footer. */
1457
- const PACKAGE_VERSION = '0.6.6';
1695
+ const PACKAGE_VERSION = '0.7.1';
1458
1696
 
1459
1697
  /** Apply defaults to the raw config (the mount target lives on the renderer, not here). */
1460
1698
  function resolveConfig(config) {
@@ -1472,6 +1710,7 @@ function resolveConfig(config) {
1472
1710
  theme: config.theme,
1473
1711
  onBonusBuy: config.onBonusBuy,
1474
1712
  volumes: config.volumes,
1713
+ menu: config.menu,
1475
1714
  version: config.version ?? '1.0.0',
1476
1715
  isSocial: config.isSocial ?? false,
1477
1716
  replay: config.replay ?? config.mode === 'replay',
@@ -1492,8 +1731,9 @@ class ShellController extends EventEmitter {
1492
1731
  i18n;
1493
1732
  kbd;
1494
1733
  overlay = null;
1495
- soundRefresh = null;
1496
- volumeRefresh = null;
1734
+ menuItems;
1735
+ menuRefresh = null;
1736
+ overlayKind = null;
1497
1737
  prevBalance;
1498
1738
  prevWin;
1499
1739
  destroyed = false;
@@ -1504,6 +1744,7 @@ class ShellController extends EventEmitter {
1504
1744
  this.config = resolveConfig(config);
1505
1745
  this.i18n = createI18n({ language: this.config.language, isSocial: this.config.isSocial });
1506
1746
  this.state = createInitialState(this.config);
1747
+ this.menuItems = this.config.menu ?? DEFAULT_MENU;
1507
1748
  this.tokens = resolveTheme(this.config.theme);
1508
1749
  this.prevBalance = this.state.balance;
1509
1750
  this.prevWin = this.state.win;
@@ -1637,14 +1878,21 @@ class ShellController extends EventEmitter {
1637
1878
  show(req) {
1638
1879
  this.closeModal();
1639
1880
  this.overlay = this.renderer.openOverlay(req) ?? null;
1881
+ this.overlayKind = this.overlay ? req.kind : null;
1640
1882
  }
1883
+ /** Open the bar menu. Called again while it is open, it closes it — the burger toggles. */
1641
1884
  openMenu() {
1885
+ if (this.overlayKind === 'menu') {
1886
+ this.closeModal();
1887
+ return;
1888
+ }
1642
1889
  this.emit('menuOpen');
1643
- this.openSettings();
1890
+ this.show({ kind: 'menu' });
1644
1891
  }
1892
+ /** @deprecated The Settings overlay is gone — this opens the bar menu. */
1645
1893
  openSettings() {
1646
1894
  this.emit('settingsOpen');
1647
- this.show({ kind: 'settings' });
1895
+ this.openMenu();
1648
1896
  }
1649
1897
  openInfo() {
1650
1898
  this.emit('infoOpen');
@@ -1676,35 +1924,72 @@ class ShellController extends EventEmitter {
1676
1924
  if (!this.overlay)
1677
1925
  return;
1678
1926
  this.overlay = null;
1679
- this.soundRefresh = null;
1680
- this.volumeRefresh = null;
1927
+ this.overlayKind = null;
1928
+ this.menuRefresh = null;
1681
1929
  this.renderer.closeOverlay();
1682
1930
  }
1683
1931
  // ── sound ──────────────────────────────────────────────────────────────────
1684
1932
  setSound(on) {
1685
1933
  this.soundOn = on;
1686
1934
  this.emit('settingChange', { key: 'sound', value: on });
1687
- this.soundRefresh?.(on);
1688
- this.renderer.refreshSoundIcon?.(on);
1689
- }
1690
- setSoundRefresh(fn) {
1691
- this.soundRefresh = fn;
1935
+ this.menuRefresh?.('sound', on);
1692
1936
  }
1693
1937
  // ── volume ─────────────────────────────────────────────────────────────────
1694
1938
  getVolume(key) {
1695
1939
  return this.state.volumes[key];
1696
1940
  }
1697
1941
  /** Set a volume slider (0..1). Shared by the slider control (drag) and game code (public API):
1698
- * clamps, stores so a reopened Settings overlay reflects it, emits `settingChange`, and
1699
- * live-updates the slider if the overlay is currently open. */
1942
+ * clamps, stores so a reopened menu popover reflects it, emits `settingChange`, and
1943
+ * live-updates the slider if the menu is currently open. */
1700
1944
  setVolume(key, value) {
1701
1945
  const v = Math.max(0, Math.min(1, value));
1702
1946
  this.state.volumes[key] = v;
1703
1947
  this.emit('settingChange', { key, value: v });
1704
- this.volumeRefresh?.(key, v);
1705
- }
1706
- setVolumeRefresh(fn) {
1707
- this.volumeRefresh = fn;
1948
+ this.menuRefresh?.(key, v);
1949
+ }
1950
+ // ── menu ───────────────────────────────────────────────────────────────────
1951
+ get menu() {
1952
+ return this.menuItems;
1953
+ }
1954
+ /** Replace the item list. Values of ids already in state are kept; new ids are seeded. */
1955
+ setMenu(items) {
1956
+ this.menuItems = items;
1957
+ this.state.menu = seedMenuValues(items, this.state.menu);
1958
+ if (this.overlayKind === 'menu')
1959
+ this.show({ kind: 'menu' });
1960
+ }
1961
+ getMenuValue(id) {
1962
+ if (id === 'sound')
1963
+ return this.soundOn;
1964
+ if (id === 'music' || id === 'sfx')
1965
+ return this.state.volumes[id];
1966
+ return this.state.menu[id];
1967
+ }
1968
+ /** Set a menu value. Presets route to their own homes so there is never a second copy. */
1969
+ setMenuValue(id, value) {
1970
+ if (id === 'sound') {
1971
+ this.setSound(value !== false);
1972
+ return;
1973
+ }
1974
+ if (id === 'music' || id === 'sfx') {
1975
+ this.setVolume(id, Number(value));
1976
+ return;
1977
+ }
1978
+ const next = typeof value === 'number' ? this.clampRange(id, value) : value;
1979
+ this.state.menu[id] = next;
1980
+ this.emit('settingChange', { key: id, value: next });
1981
+ this.menuRefresh?.(id, next);
1982
+ }
1983
+ setMenuRefresh(fn) {
1984
+ this.menuRefresh = fn;
1985
+ }
1986
+ /** Clamp to the declared bounds of a custom `range` item (a non-range id passes through). */
1987
+ clampRange(id, value) {
1988
+ const item = this.menuItems.find((i) => i.id === id);
1989
+ if (!item || item.type !== 'range')
1990
+ return value;
1991
+ const { min, max } = rangeBounds(item);
1992
+ return Math.max(min, Math.min(max, value));
1708
1993
  }
1709
1994
  // ── features ─────────────────────────────────────────────────────────────────
1710
1995
  activateFeature(bonus) {
@@ -1814,6 +2099,11 @@ class ShellController extends EventEmitter {
1814
2099
  if (this.destroyed)
1815
2100
  return Promise.resolve();
1816
2101
  this.destroyed = true;
2102
+ // With the menu (or any overlay) open at teardown, `menuRefresh` / `overlay` / `overlayKind`
2103
+ // would otherwise survive the renderer's destroy — so a later setVolume()/setSound() call
2104
+ // invokes a stale row updater against already-destroyed Pixi Graphics (or a detached DOM node)
2105
+ // and throws. Run BEFORE the renderer teardown below, while it can still close cleanly.
2106
+ this.closeModal();
1817
2107
  if (typeof document !== 'undefined') {
1818
2108
  this.kbd?.detach();
1819
2109
  document.removeEventListener('pointerdown', this.pullFocus, true);
@@ -1823,6 +2113,64 @@ class ShellController extends EventEmitter {
1823
2113
  }
1824
2114
  }
1825
2115
 
2116
+ /** Geometry for the bar-menu popover. Pure math over rectangles so the DOM and Pixi renderers
2117
+ * place it identically — the renderers only supply measured sizes and apply the result. */
2118
+ const POPOVER = {
2119
+ /** Keep-out from the surface edges. */
2120
+ margin: 8,
2121
+ /** Space between the anchor and the card. */
2122
+ gap: 8,
2123
+ /** Minimum distance from the arrow tip to either rounded corner. */
2124
+ arrowInset: 14,
2125
+ /** A card shorter than this does not fit — flip to the other side instead. */
2126
+ minH: 120,
2127
+ minW: 220,
2128
+ maxW: 320,
2129
+ };
2130
+ const clamp$1 = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
2131
+ /** Card width: content width clamped to [minW, maxW] and never wider than the surface. */
2132
+ function popoverWidth(surfaceW, contentW) {
2133
+ const hi = Math.min(POPOVER.maxW, surfaceW - POPOVER.margin * 2);
2134
+ return Math.max(0, clamp$1(contentW, Math.min(POPOVER.minW, hi), hi));
2135
+ }
2136
+ /** Place the card above the `anchor` (below if it does not fit), left-aligned to it and clamped
2137
+ * inside the surface. `anchor === null` (no bar / hidden shell) centres it, arrow off.
2138
+ *
2139
+ * `anchor` drives PLACEMENT (x, y, maxH, below) — normally the bar's whole plaque ("plate"), so the
2140
+ * card sits flush with the bar as a whole rather than with whichever control opened it. `pointer` is
2141
+ * the (optional) rect the ARROW points at — normally the burger button, which can sit anywhere
2142
+ * inside the plate. Defaults to `anchor` when omitted, so every caller that only ever had one rect
2143
+ * (i.e. every caller before `pointer` existed) keeps behaving exactly as it did before. */
2144
+ function placePopover(anchor, surface, size, pointer = null) {
2145
+ const { margin, gap, arrowInset, minH } = POPOVER;
2146
+ if (!anchor) {
2147
+ const maxH = Math.max(0, surface.h - margin * 2);
2148
+ const h = Math.min(size.h, maxH);
2149
+ const rawY = (surface.h - h) / 2;
2150
+ const y = clamp$1(rawY, margin, Math.max(margin, surface.h - h - margin));
2151
+ return {
2152
+ x: Math.max(margin, (surface.w - size.w) / 2),
2153
+ y,
2154
+ maxH,
2155
+ arrowX: -1,
2156
+ below: false,
2157
+ };
2158
+ }
2159
+ const spaceAbove = anchor.y - gap - margin;
2160
+ const spaceBelow = surface.h - (anchor.y + anchor.h) - gap - margin;
2161
+ // Prefer above; flip only when the card would be squeezed below its usable minimum AND there is
2162
+ // genuinely more room on the other side.
2163
+ const below = spaceAbove < Math.min(size.h, minH) && spaceBelow > spaceAbove;
2164
+ const maxH = Math.max(0, below ? spaceBelow : spaceAbove);
2165
+ const h = Math.min(size.h, maxH);
2166
+ const x = clamp$1(anchor.x, margin, Math.max(margin, surface.w - size.w - margin));
2167
+ const rawY = below ? anchor.y + anchor.h + gap : anchor.y - gap - h;
2168
+ const y = clamp$1(rawY, margin, Math.max(margin, surface.h - h - margin));
2169
+ const arrowAnchor = pointer ?? anchor;
2170
+ const arrowX = clamp$1(arrowAnchor.x + arrowAnchor.w / 2 - x, arrowInset, Math.max(arrowInset, size.w - arrowInset));
2171
+ return { x, y, maxH, arrowX, below };
2172
+ }
2173
+
1826
2174
  const NO_INSET = { top: 0, right: 0, bottom: 0, left: 0 };
1827
2175
  /** Create a shell with an explicit renderer instance (custom or a built-in HtmlRenderer/PixiRenderer).
1828
2176
  * Built-in renderers also have the createGameShell/createPixiShell sugar in /html and /pixi.
@@ -2292,25 +2640,25 @@ function roundedPath(g, x, y, w, h, [tl, tr, br, bl]) {
2292
2640
  // GraphicsContext.svg. To change an icon: edit icons.svg, then run
2293
2641
  // `node scripts/gen-icons-from-svg.mjs`.
2294
2642
  const SVGS = {
2295
- spin: `<g fill="currentColor" fill-rule="evenodd"><path d="M13.57 8.41C13.3 8.31 13.51 7.09 13.59 6.65C13.61 6.56 13.55 6.48 13.46 6.48C12.32 6.45 5.74 6.61 4.16 14.85C4.15 14.9 4 15.16 3.8 14.91C3.27 14.23 2.43 12.08 3.46 9.16C6.01 1.92 13 3.07 13.79 3.23C13.83 3.23 13.86 3.2 13.86 3.17C13.85 2.86 13.82 1.68 14.17 1.64C14.51 1.6 19.04 5.61 18.96 5.95C18.86 6.36 13.83 8.51 13.57 8.41Z"/><path d="M10.43 15.59C10.7 15.69 10.49 16.91 10.41 17.35C10.39 17.44 10.45 17.52 10.54 17.52C11.68 17.55 18.26 17.39 19.84 9.15C19.85 9.1 20 8.84 20.2 9.09C20.73 9.77 21.57 11.92 20.54 14.85C17.99 22.08 11 20.93 10.21 20.77C10.17 20.77 10.13 20.8 10.14 20.83C10.15 21.14 10.18 22.32 9.83 22.36C9.49 22.4 4.96 18.39 5.04 18.05C5.14 17.64 10.17 15.49 10.43 15.59Z"/></g>`,
2296
- turbo1: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.81 2.62L14.41 8.21C14.15 8.64 14.46 9.2 14.97 9.2L18.84 9.21C19.42 9.21 19.72 9.9 19.32 10.31L8.02 22.19C7.89 22.33 7.72 22.4 7.53 22.4L7.53 22.4C7.08 22.39 6.77 21.93 6.93 21.5L9.91 13.91C10.08 13.48 9.76 13.01 9.29 13.01L5.11 13.06C4.61 13.06 4.28 12.53 4.53 12.09L10.07 1.94C10.19 1.73 10.41 1.6 10.65 1.6L17.26 1.62C17.77 1.62 18.08 2.18 17.81 2.62Z"/></g>`,
2297
- autoplay: `<g fill="currentColor" fill-rule="evenodd"><path d="M19.97 12.41C20.22 11.94 20.95 11.88 20.97 12.47C21.14 16.4 18.71 19.92 14.44 20.97C8.59 22.4 5.29 18.55 5.28 18.52C5.2 18.33 4.41 19.77 4.19 19.59C3.81 19.28 3.78 14.9 3.9 14.78C4.01 14.67 8.39 14.95 8.48 15.31C8.58 15.64 7.2 16.1 7.4 16.38C9.14 18.67 15.82 20.29 19.97 12.41Z"/><path d="M9.3 15.36L9.3 8.67C9.3 8.32 9.97 7.74 10.58 8.14C15.83 11.56 16 11.46 16.01 12.04C16.02 12.61 15.12 12.98 10.63 15.91C10.32 16.11 9.29 15.72 9.29 15.36Z"/><path d="M4.03 11.59C3.78 12.06 3.05 12.12 3.03 11.53C2.86 7.6 5.29 4.08 9.56 3.03C15.41 1.6 18.71 5.45 18.72 5.48C18.8 5.67 19.59 4.23 19.81 4.41C20.19 4.72 20.22 9.1 20.1 9.22C19.99 9.33 15.61 9.05 15.52 8.69C15.42 8.36 16.8 7.9 16.6 7.62C14.86 5.33 8.18 3.71 4.03 11.59Z"/></g>`,
2643
+ spin: `<g fill="currentColor" fill-rule="evenodd"><path d="M13.57 8.41C13.3 8.31 13.51 7.09 13.59 6.65C13.61 6.56 13.55 6.48 13.46 6.48C12.32 6.45 5.74 6.61 4.16 14.85C4.15 14.9 4 15.16 3.8 14.91C3.27 14.23 2.43 12.08 3.46 9.16C6.01 1.92 13 3.07 13.79 3.23C13.83 3.23 13.86 3.2 13.86 3.17C13.85 2.86 13.82 1.68 14.17 1.64C14.51 1.6 19.04 5.61 18.96 5.95C18.86 6.36 13.83 8.51 13.57 8.41L13.57 8.41Z"/><path d="M10.43 15.59C10.7 15.69 10.49 16.91 10.41 17.35C10.39 17.44 10.45 17.52 10.54 17.52C11.68 17.55 18.26 17.39 19.84 9.15C19.85 9.1 20 8.84 20.2 9.09C20.73 9.77 21.57 11.92 20.54 14.85C17.99 22.08 11 20.93 10.21 20.77C10.17 20.77 10.13 20.8 10.14 20.83C10.15 21.14 10.18 22.32 9.83 22.36C9.49 22.4 4.96 18.39 5.04 18.05C5.14 17.64 10.17 15.49 10.43 15.59L10.43 15.59L10.43 15.59Z"/></g>`,
2644
+ turbo1: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.81 2.62L14.41 8.21C14.15 8.64 14.46 9.2 14.97 9.2L18.84 9.21C19.42 9.21 19.72 9.9 19.32 10.31L8.02 22.19C7.89 22.33 7.72 22.4 7.53 22.4L7.53 22.4C7.08 22.39 6.77 21.93 6.93 21.5L9.91 13.91C10.08 13.48 9.76 13.01 9.29 13.01L5.11 13.06C4.61 13.06 4.28 12.53 4.53 12.09L10.07 1.94C10.19 1.73 10.41 1.6 10.65 1.6L17.26 1.62C17.77 1.62 18.08 2.18 17.81 2.62L17.81 2.62Z"/></g>`,
2645
+ autoplay: `<g fill="currentColor" fill-rule="evenodd"><path d="M19.97 12.41C20.22 11.94 20.95 11.88 20.97 12.47C21.14 16.4 18.71 19.92 14.44 20.97C8.59 22.4 5.29 18.55 5.28 18.52C5.2 18.33 4.41 19.77 4.19 19.59C3.81 19.28 3.78 14.9 3.9 14.78C4.01 14.67 8.39 14.95 8.48 15.31C8.58 15.64 7.2 16.1 7.4 16.38C9.14 18.67 15.82 20.29 19.97 12.41L19.97 12.41Z"/><path d="M9.3 15.36L9.3 8.67C9.3 8.32 9.97 7.74 10.58 8.14C15.83 11.56 16 11.46 16.01 12.04C16.02 12.61 15.12 12.98 10.63 15.91C10.32 16.11 9.29 15.72 9.29 15.36L9.3 15.36Z"/><path d="M4.03 11.59C3.78 12.06 3.05 12.12 3.03 11.53C2.86 7.6 5.29 4.08 9.56 3.03C15.41 1.6 18.71 5.45 18.72 5.48C18.8 5.67 19.59 4.23 19.81 4.41C20.19 4.72 20.22 9.1 20.1 9.22C19.99 9.33 15.61 9.05 15.52 8.69C15.42 8.36 16.8 7.9 16.6 7.62C14.86 5.33 8.18 3.71 4.03 11.59L4.03 11.59Z"/></g>`,
2298
2646
  stop: `<g fill="currentColor" fill-rule="evenodd"><rect x="1.6" y="1.6" width="20.8" height="20.8" rx="2.9"/></g>`,
2299
2647
  menu: `<g fill="currentColor" fill-rule="evenodd"><rect x="1.61" y="3.81" width="20.79" height="4.47" rx="2.23"/><rect x="1.6" y="9.77" width="20.79" height="4.46" rx="2.23"/><rect x="1.6" y="15.72" width="20.79" height="4.47" rx="2.23"/></g>`,
2300
2648
  minus: `<g fill="currentColor" fill-rule="evenodd"><rect x="1.6" y="9.86" width="20.8" height="4.28" rx="2.11"/></g>`,
2301
- plus: `<g fill="currentColor" fill-rule="evenodd"><path d="M19.72 14.37L13.84 14.37L13.84 20.33C13.84 21.48 12.89 22.4 11.74 22.36C10.61 22.36 9.7 21.45 9.7 20.33L9.7 14.37L3.67 14.37C2.52 14.37 1.6 13.42 1.63 12.27C1.63 11.15 2.55 10.23 3.67 10.23L9.7 10.23L9.7 4.28C9.71 1.61 13.83 1.6 13.84 4.28L13.84 10.23L19.72 10.23C22.39 10.24 22.4 14.36 19.72 14.37Z"/></g>`,
2649
+ plus: `<g fill="currentColor" fill-rule="evenodd"><path d="M19.72 14.37L13.84 14.37L13.84 20.33C13.84 21.48 12.89 22.4 11.74 22.36C10.61 22.36 9.7 21.45 9.7 20.33L9.7 14.37L3.67 14.37C2.52 14.37 1.6 13.42 1.63 12.27C1.63 11.15 2.55 10.23 3.67 10.23L9.7 10.23L9.7 4.28C9.71 1.61 13.83 1.6 13.84 4.28L13.84 10.23L19.72 10.23C22.39 10.24 22.4 14.36 19.72 14.37L19.72 14.37Z"/></g>`,
2302
2650
  gift: `<rect x="4" y="9" width="16" height="11" rx="2" fill="currentColor"/><path d="M9 9c-1.35 -0.31 -2.18 -1.65 -1.87 -3s1.65 -2.18 3 -1.87c0.93 0.22 1.65 0.94 1.87 1.87c0.31 -1.35 1.65 -2.18 3 -1.87c1.35 0.31 2.18 1.65 1.87 3c-0.22 0.93 -0.94 1.65 -1.87 1.87h-6Z" fill="currentColor"/><rect x="11" y="9" width="2" height="11" fill="rgba(0,0,0,.35)"/>`,
2303
- info: `<g fill="currentColor" fill-rule="evenodd"><circle cx="11.98" cy="4.27" r="2.67"/><path d="M16.05 21.09L16.05 21.54C16.05 22.02 15.67 22.4 15.19 22.4L8.89 22.4C8.42 22.4 8.04 22.02 8.04 21.54L8.04 20.98C8.04 20.5 8.42 20.12 8.89 20.12L8.89 20.12C9.13 20.12 9.32 19.93 9.32 19.7L9.32 11.59C9.32 11.29 9.08 11.05 8.8 11.05C8.33 11.05 7.95 10.67 7.95 10.19L7.95 9.18C7.95 8.7 8.33 8.32 8.8 8.32L9.32 8.32C9.32 8.32 13.8 8.32 13.8 8.32C14.27 8.32 14.65 8.71 14.65 9.18L14.65 19.7C14.65 19.93 14.84 20.12 15.07 20.12L15.07 20.12C15.61 20.12 16.05 20.56 16.05 21.09Z"/></g>`,
2304
- soundOn: `<g fill="currentColor" fill-rule="evenodd"><path d="M1.6 15.04L1.6 9.18C1.6 8.75 1.95 8.4 2.38 8.4L5.03 8.4C5.21 8.4 5.39 8.36 5.56 8.28L11.6 5.26C12.12 5 12.73 5.38 12.73 5.96L12.73 18.27C12.73 18.85 12.12 19.22 11.6 18.96L5.56 15.94C5.39 15.86 5.22 15.82 5.03 15.82L2.38 15.82C1.95 15.82 1.6 15.47 1.6 15.04Z"/><path d="M16.01 12.11C16.04 12.36 15.67 14.7 14.7 15.23C13.92 15.42 13.54 14.77 13.86 14.1C14.89 12.56 14.88 11.66 13.86 10.13C13.54 9.46 13.92 8.8 14.7 8.99C15.67 9.53 16.06 11.81 16.01 12.11Z"/><path d="M19.15 12.12C19.2 12.51 18.6 16.4 17.3 17.05C16.32 17.54 15.99 16.87 16.42 15.81C17.8 13.4 17.59 9.93 16.42 8.41C15.73 7.5 16.34 6.58 17.26 7.18C18.74 8.15 19.21 11.64 19.15 12.12Z"/><path d="M22.4 12.16C22.16 15.18 21 17.95 19.71 18.82C18.73 19.48 18.22 18.42 18.93 17.32C20.96 14.17 21.92 9.95 18.9 6.29C18.13 5.35 19.35 4.52 20.11 5.48C21.43 7.14 22.33 9.14 22.4 12.16Z"/></g>`,
2651
+ info: `<g fill="currentColor" fill-rule="evenodd"><circle cx="11.98" cy="4.27" r="2.67"/><path d="M16.05 21.09L16.05 21.54C16.05 22.02 15.67 22.4 15.19 22.4L8.89 22.4C8.42 22.4 8.04 22.02 8.04 21.54L8.04 20.98C8.04 20.5 8.42 20.12 8.89 20.12L8.89 20.12C9.13 20.12 9.32 19.93 9.32 19.7L9.32 11.59C9.32 11.29 9.08 11.05 8.8 11.05C8.33 11.05 7.95 10.67 7.95 10.19L7.95 9.18C7.95 8.7 8.33 8.32 8.8 8.32L13.8 8.32C14.27 8.32 14.65 8.71 14.65 9.18L14.65 19.7C14.65 19.93 14.84 20.12 15.07 20.12L15.07 20.12C15.61 20.12 16.05 20.56 16.05 21.09L16.05 21.09Z"/></g>`,
2652
+ soundOn: `<g fill="currentColor" fill-rule="evenodd"><path d="M1.6 15.04L1.6 9.18C1.6 8.75 1.95 8.4 2.38 8.4L5.03 8.4C5.21 8.4 5.39 8.36 5.56 8.28L11.6 5.26C12.12 5 12.73 5.38 12.73 5.96L12.73 18.27C12.73 18.85 12.12 19.22 11.6 18.96L5.56 15.94C5.39 15.86 5.22 15.82 5.03 15.82L2.38 15.82C1.95 15.82 1.6 15.47 1.6 15.04L1.6 15.04Z"/><path d="M16.01 12.11C16.04 12.36 15.67 14.7 14.7 15.23C13.92 15.42 13.54 14.77 13.86 14.1C14.89 12.56 14.88 11.66 13.86 10.13C13.54 9.46 13.92 8.8 14.7 8.99C15.67 9.53 16.06 11.81 16.01 12.11Z"/><path d="M19.15 12.12C19.2 12.51 18.6 16.4 17.3 17.05C16.32 17.54 15.99 16.87 16.42 15.81C17.8 13.4 17.59 9.93 16.42 8.41C15.73 7.5 16.34 6.58 17.26 7.18C18.74 8.15 19.21 11.64 19.15 12.12L19.15 12.12Z"/><path d="M22.4 12.16C22.16 15.18 21 17.95 19.71 18.82C18.73 19.48 18.22 18.42 18.93 17.32C20.96 14.17 21.92 9.95 18.9 6.29C18.13 5.35 19.35 4.52 20.11 5.48C21.43 7.14 22.33 9.14 22.4 12.16L22.4 12.16Z"/></g>`,
2305
2653
  soundOff: `<g fill="currentColor" fill-rule="evenodd"><path d="M1.6 14.77L1.6 9.23C1.6 8.82 1.93 8.49 2.34 8.49L4.85 8.49C5.02 8.49 5.19 8.45 5.34 8.38L11.06 5.52C11.55 5.27 12.12 5.63 12.12 6.18L12.12 17.82C12.12 18.37 11.55 18.73 11.06 18.48L5.34 15.62C5.19 15.55 5.02 15.51 4.85 15.51L2.34 15.51C1.93 15.51 1.6 15.18 1.6 14.77Z"/><path d="M21.95 16.53C21.5 16.98 20.78 16.98 20.33 16.53L17.79 13.99L15.25 16.54C14.8 16.99 14.07 16.99 13.62 16.54C13.17 16.09 13.17 15.36 13.62 14.92L16.17 12.37L13.63 9.83C13.18 9.38 13.18 8.65 13.63 8.21C13.85 7.98 14.14 7.87 14.44 7.87C14.73 7.87 15.02 7.98 15.25 8.21L17.79 10.75L20.33 8.21C20.77 7.76 21.5 7.76 21.95 8.21C22.17 8.44 22.28 8.73 22.28 9.02C22.28 9.32 22.17 9.61 21.95 9.83L19.41 12.37L21.95 14.91C22.4 15.36 22.4 16.08 21.95 16.53Z"/></g>`,
2306
- close: `<g fill="currentColor" fill-rule="evenodd"><path d="M21.39 21.37C20.38 22.38 18.74 22.38 17.73 21.37L12.01 15.64L6.27 21.38C5.26 22.39 3.62 22.39 2.61 21.38C1.6 20.38 1.6 18.74 2.61 17.73L8.35 11.99L2.62 6.25C1.61 5.24 1.61 3.61 2.62 2.6C3.12 2.09 3.79 1.84 4.45 1.84C5.11 1.84 5.77 2.09 6.28 2.6L12.01 8.33L17.72 2.62C18.73 1.61 20.37 1.61 21.38 2.62C21.89 3.12 22.14 3.78 22.14 4.44C22.14 5.11 21.89 5.77 21.38 6.27L15.67 11.99L21.39 17.71C22.4 18.72 22.4 20.36 21.39 21.37Z"/></g>`,
2307
- back: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.49 2.32L17.49 2.32C18.2 3.03 18.2 4.19 17.49 4.9L11.68 10.71C10.97 11.42 10.97 12.58 11.68 13.29L17.49 19.1C18.21 19.81 18.21 20.97 17.49 21.69L17.49 21.69C16.78 22.4 15.62 22.4 14.91 21.69L7.8 14.58L7.8 14.58C7.8 14.58 6.51 13.29 6.51 13.29C5.79 12.58 5.79 11.42 6.51 10.71L14.9 2.31C15.62 1.6 16.77 1.6 17.49 2.31Z"/></g>`,
2308
- chevronRight: `<g fill="currentColor" fill-rule="evenodd"><path d="M6.51 21.68L6.51 21.68C5.8 20.97 5.8 19.81 6.51 19.1L12.32 13.29C13.03 12.58 13.03 11.42 12.32 10.71L6.51 4.9C5.79 4.19 5.79 3.03 6.51 2.31L6.51 2.31C7.22 1.6 8.38 1.6 9.09 2.31L16.2 9.42L16.2 9.42C16.2 9.42 17.49 10.71 17.49 10.71C18.21 11.42 18.21 12.58 17.49 13.29L9.1 21.69C8.38 22.4 7.23 22.4 6.51 21.69Z"/></g>`,
2654
+ close: `<g fill="currentColor" fill-rule="evenodd"><path d="M21.39 21.37C20.38 22.38 18.74 22.38 17.73 21.37L12.01 15.64L6.27 21.38C5.26 22.39 3.62 22.39 2.61 21.38C1.6 20.38 1.6 18.74 2.61 17.73L8.35 11.99L2.62 6.25C1.61 5.24 1.61 3.61 2.62 2.6C3.12 2.09 3.79 1.84 4.45 1.84C5.11 1.84 5.77 2.09 6.28 2.6L12.01 8.33L17.72 2.62C18.73 1.61 20.37 1.61 21.38 2.62C21.89 3.12 22.14 3.78 22.14 4.44C22.14 5.11 21.89 5.77 21.38 6.27L15.67 11.99L21.39 17.71C22.4 18.72 22.4 20.36 21.39 21.37L21.39 21.37Z"/></g>`,
2655
+ back: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.49 2.32L17.49 2.32C18.2 3.03 18.2 4.19 17.49 4.9L11.68 10.71C10.97 11.42 10.97 12.58 11.68 13.29L17.49 19.1C18.21 19.81 18.21 20.97 17.49 21.69L17.49 21.69C16.78 22.4 15.62 22.4 14.91 21.69L7.8 14.58L7.8 14.58L6.51 13.29C5.79 12.58 5.79 11.42 6.51 10.71L14.9 2.31C15.62 1.6 16.77 1.6 17.49 2.31L17.49 2.31Z"/></g>`,
2656
+ chevronRight: `<g fill="currentColor" fill-rule="evenodd"><path d="M6.51 21.68L6.51 21.68C5.8 20.97 5.8 19.81 6.51 19.1L12.32 13.29C13.03 12.58 13.03 11.42 12.32 10.71L6.51 4.9C5.79 4.19 5.79 3.03 6.51 2.31L6.51 2.31C7.22 1.6 8.38 1.6 9.09 2.31L16.2 9.42L16.2 9.42L17.49 10.71C18.21 11.42 18.21 12.58 17.49 13.29L9.1 21.69C8.38 22.4 7.23 22.4 6.51 21.69L6.51 21.69Z"/></g>`,
2309
2657
  ticket: `<path d="M1.72 9.48L19.64 4.67L20.28 7.07C19.19 7.8 18.82 9 19.11 10.09C19.41 11.19 20.33 12.04 21.64 12.13L22.28 14.52L4.36 19.32L3.72 16.93C4.81 16.2 5.18 15 4.89 13.91C4.59 12.81 3.67 11.96 2.36 11.87L1.72 9.48Z" fill="none" stroke="currentColor" stroke-width="1.84" stroke-linejoin="miter"/><path d="M12.57 7.17L9.75 13.26L11.92 12.4L11.84 16.74L14.85 10.06L12.38 11.1Z" fill="currentColor"/>`,
2310
- turbo2: `<g fill="currentColor" fill-rule="evenodd"><path d="M8.24 8.81L3.92 7.68C3.88 7.67 3.88 7.61 3.92 7.61L9.66 6.45C9.8 6.43 9.89 6.56 9.83 6.68L8.86 8.35C8.67 8.73 8.33 8.83 8.24 8.81Z"/><path d="M20.58 3.04L17.34 8.38C17.09 8.8 17.39 9.33 17.87 9.33L21.57 9.33C22.12 9.33 22.4 9.99 22.02 10.39L11.24 21.73C11.12 21.86 10.95 21.93 10.77 21.92L10.77 21.92C10.34 21.92 10.04 21.47 10.2 21.07L13.04 13.82C13.21 13.41 12.9 12.96 12.45 12.97L8.46 13.01C7.98 13.01 7.67 12.5 7.9 12.08L13.2 2.4C13.31 2.2 13.52 2.07 13.75 2.07L20.05 2.09C20.54 2.1 20.84 2.63 20.58 3.04Z"/><path d="M5.96 12.68L1.64 11.54C1.6 11.54 1.6 11.47 1.64 11.47L7.38 10.31C7.52 10.3 7.61 10.42 7.55 10.55L6.58 12.22C6.39 12.59 6.05 12.69 5.96 12.68Z"/><path d="M9.67 16.66L5.35 15.53C5.31 15.52 5.31 15.46 5.35 15.46L11.09 14.3C11.22 14.28 11.32 14.41 11.26 14.53L10.29 16.2C10.1 16.58 9.76 16.68 9.67 16.66Z"/></g>`,
2311
- turboOff: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.81 2.62L14.41 8.21C14.15 8.64 14.46 9.2 14.97 9.2L18.84 9.21C19.42 9.21 19.72 9.9 19.32 10.31L8.02 22.19C7.89 22.33 7.72 22.4 7.53 22.4L7.53 22.4C7.08 22.39 6.77 21.93 6.93 21.5L9.91 13.91C10.08 13.48 9.76 13.01 9.29 13.01L5.11 13.06C4.61 13.06 4.28 12.53 4.53 12.09L10.07 1.94C10.19 1.73 10.41 1.6 10.65 1.6L17.26 1.62C17.77 1.62 18.08 2.18 17.81 2.62Z"/></g>`,
2312
- chevronUp: `<g fill="currentColor" fill-rule="evenodd"><path d="M21.68 17.49L21.68 17.49C20.97 18.2 19.81 18.2 19.1 17.49L13.29 11.68C12.58 10.97 11.42 10.97 10.71 11.68L4.9 17.49C4.19 18.21 3.03 18.21 2.31 17.49L2.31 17.49C1.6 16.78 1.6 15.62 2.31 14.91L9.42 7.8L9.42 7.8C9.42 7.8 10.71 6.51 10.71 6.51C11.42 5.79 12.58 5.79 13.29 6.51L21.69 14.9C22.4 15.62 22.4 16.77 21.69 17.49Z"/></g>`,
2313
- chevronDown: `<g fill="currentColor" fill-rule="evenodd"><path d="M2.32 6.51L2.32 6.51C3.03 5.8 4.19 5.8 4.9 6.51L10.71 12.32C11.42 13.03 12.58 13.03 13.29 12.32L19.1 6.51C19.82 5.79 20.97 5.79 21.69 6.51L21.69 6.51C22.4 7.22 22.4 8.38 21.69 9.09L14.58 16.19L14.58 16.2C14.58 16.2 13.29 17.49 13.29 17.49C12.58 18.21 11.42 18.21 10.71 17.49L2.31 9.1C1.6 8.38 1.6 7.23 2.31 6.51Z"/></g>`,
2658
+ turbo2: `<g fill="currentColor" fill-rule="evenodd"><path d="M8.24 8.81L3.92 7.68C3.88 7.67 3.88 7.61 3.92 7.61L9.66 6.45C9.8 6.43 9.89 6.56 9.83 6.68L8.86 8.35C8.67 8.73 8.33 8.83 8.24 8.81L8.24 8.81Z"/><path d="M20.58 3.04L17.34 8.38C17.09 8.8 17.39 9.33 17.87 9.33L21.57 9.33C22.12 9.33 22.4 9.99 22.02 10.39L11.24 21.73C11.12 21.86 10.95 21.93 10.77 21.92L10.77 21.92C10.34 21.92 10.04 21.47 10.2 21.07L13.04 13.82C13.21 13.41 12.9 12.96 12.45 12.97L8.46 13.01C7.98 13.01 7.67 12.5 7.9 12.08L13.2 2.4C13.31 2.2 13.52 2.07 13.75 2.07L20.05 2.09C20.54 2.1 20.84 2.63 20.58 3.04L20.58 3.04Z"/><path d="M5.96 12.68L1.64 11.54C1.6 11.54 1.6 11.47 1.64 11.47L7.38 10.31C7.51 10.3 7.61 10.42 7.55 10.55L6.58 12.22C6.39 12.59 6.05 12.69 5.96 12.68L5.96 12.68Z"/><path d="M9.67 16.66L5.35 15.53C5.31 15.52 5.31 15.46 5.35 15.46L11.09 14.3C11.22 14.28 11.32 14.41 11.26 14.53L10.29 16.2C10.1 16.58 9.76 16.68 9.67 16.66L9.67 16.66Z"/></g>`,
2659
+ turboOff: `<g fill="currentColor" fill-rule="evenodd"><path d="M17.81 2.62L14.41 8.21C14.15 8.64 14.46 9.2 14.97 9.2L18.84 9.21C19.42 9.21 19.72 9.9 19.32 10.31L8.02 22.19C7.89 22.33 7.72 22.4 7.53 22.4L7.53 22.4C7.08 22.39 6.77 21.93 6.93 21.5L9.91 13.91C10.08 13.48 9.76 13.01 9.29 13.01L5.11 13.06C4.61 13.06 4.28 12.53 4.53 12.09L10.07 1.94C10.19 1.73 10.41 1.6 10.65 1.6L17.26 1.62C17.77 1.62 18.08 2.18 17.81 2.62L17.81 2.62Z"/></g>`,
2660
+ chevronUp: `<g fill="currentColor" fill-rule="evenodd"><path d="M21.68 17.49L21.68 17.49C20.97 18.2 19.81 18.2 19.1 17.49L13.29 11.68C12.58 10.97 11.42 10.97 10.71 11.68L4.9 17.49C4.19 18.21 3.03 18.21 2.31 17.49L2.31 17.49C1.6 16.78 1.6 15.62 2.31 14.91L9.42 7.8L9.42 7.8L10.71 6.51C11.42 5.79 12.58 5.79 13.29 6.51L21.69 14.9C22.4 15.62 22.4 16.77 21.69 17.49L21.69 17.49Z"/></g>`,
2661
+ chevronDown: `<g fill="currentColor" fill-rule="evenodd"><path d="M2.32 6.51L2.32 6.51C3.03 5.8 4.19 5.8 4.9 6.51L10.71 12.32C11.42 13.03 12.58 13.03 13.29 12.32L19.1 6.51C19.82 5.79 20.97 5.79 21.69 6.51L21.69 6.51C22.4 7.22 22.4 8.38 21.69 9.09L14.58 16.19L14.58 16.2L13.29 17.49C12.58 18.21 11.42 18.21 10.71 17.49L2.31 9.1C1.6 8.38 1.6 7.23 2.31 6.51L2.32 6.51L2.32 6.51Z"/></g>`,
2314
2662
  };
2315
2663
  /** A standalone, parseable SVG document with `currentColor` resolved to `color`.
2316
2664
  * Used by the Pixi renderer to build vector geometry via GraphicsContext.svg(). */
@@ -2346,10 +2694,10 @@ class IconView extends Container {
2346
2694
  gfx;
2347
2695
  _size;
2348
2696
  _color;
2349
- iconName;
2697
+ _iconName;
2350
2698
  constructor(name, size, color = '#ffffff') {
2351
2699
  super();
2352
- this.iconName = name;
2700
+ this._iconName = name;
2353
2701
  this._size = size;
2354
2702
  this._color = color;
2355
2703
  this.gfx = new Graphics(context(name, color));
@@ -2365,11 +2713,22 @@ class IconView extends Container {
2365
2713
  get size() {
2366
2714
  return this._size;
2367
2715
  }
2716
+ get iconName() {
2717
+ return this._iconName;
2718
+ }
2368
2719
  setColor(color) {
2369
2720
  if (color === this._color)
2370
2721
  return;
2371
2722
  this._color = color;
2372
- this.gfx.context = context(this.iconName, color);
2723
+ this.gfx.context = context(this._iconName, color);
2724
+ }
2725
+ /** Swap the glyph in place (e.g. the menu's sound row flips soundOn/soundOff on toggle) — same
2726
+ * cached-context rebuild as setColor, keyed on the new name instead of a new colour. */
2727
+ setIcon(name) {
2728
+ if (name === this._iconName)
2729
+ return;
2730
+ this._iconName = name;
2731
+ this.gfx.context = context(name, this._color);
2373
2732
  }
2374
2733
  setSize(size) {
2375
2734
  if (size === this._size)
@@ -3101,6 +3460,11 @@ class BottomBar extends Container {
3101
3460
  spin;
3102
3461
  autoBtn;
3103
3462
  turboBtn;
3463
+ menuBtn;
3464
+ /** The menu's PLATE, in LOCAL coordinates relative to `inner` — the continuous dark panel (wide)
3465
+ * or the controls row (mobile). Set at the point `applyFit()`/`applyFitMobile()` compute it;
3466
+ * `menuPlate()` converts it to screen space lazily (see that method's doc comment for why). */
3467
+ plateRect = null;
3104
3468
  constructor(host) {
3105
3469
  super();
3106
3470
  this.host = host;
@@ -3110,6 +3474,58 @@ class BottomBar extends Container {
3110
3474
  else
3111
3475
  this.buildWide();
3112
3476
  }
3477
+ /** Screen-space rect of the burger — the menu popover's POINTER (the arrow's target only; see
3478
+ * `menuPlate` for what drives placement). `measureSize()` (the button's own nominal box, e.g.
3479
+ * 36×36) rather than the built-in `getSize()` (the glyph's ink bounds only) so a burger whose icon
3480
+ * doesn't fill its box still reports its true hit-box size; multiplied by `inner.scale` — `getSize`
3481
+ * /`measureSize` only reflect the node's OWN scale (always 1 here), not the ancestor `inner.scale`
3482
+ * the bar's whole fit-scale lives on, so the UNMULTIPLIED width/height would silently overstate the
3483
+ * burger's true on-screen footprint on a scaled-down bar and skew the arrow off-centre. */
3484
+ menuAnchor() {
3485
+ if (!this.menuBtn || this.menuBtn.destroyed)
3486
+ return null;
3487
+ const p = this.menuBtn.getGlobalPosition();
3488
+ const s = this.inner.scale.x;
3489
+ const size = this.menuBtn.measureSize();
3490
+ return { x: p.x, y: p.y, w: size.w * s, h: size.h * s };
3491
+ }
3492
+ /** Screen-space rect of the menu's PLATE — the continuous dark panel (wide) or the controls row
3493
+ * (mobile), NOT the burger itself and NOT (mobile) the info pill below it. Drives the popover's
3494
+ * x/y/maxH/below; the burger (`menuAnchor`) drives only the arrow. Resolved lazily on every call,
3495
+ * like `menuAnchor` — `PixiRenderer.renderBar()` destroys and rebuilds this BottomBar on every
3496
+ * resize and ~20 other state changes, so a value captured once would go stale. `plateRect` is
3497
+ * local to `inner`; `getGlobalPosition` + `inner.scale` convert it to screen space (`outer*` on the
3498
+ * mobile FlexBox and the wide panel's own drawn rect are both LOCAL sizes, unaffected by `inner`'s
3499
+ * ancestor scale, same reasoning as `menuAnchor` above). */
3500
+ menuPlate() {
3501
+ // Pixi v8's Container.destroy() nulls `_position`/`_scale`, so `inner.scale.x` /
3502
+ // `inner.getGlobalPosition()` on a destroyed bar throws — guard for symmetry with menuAnchor()
3503
+ // above, which already returns null once its button is destroyed. Not reachable today
3504
+ // (PixiRenderer.renderBar() destroys and reassigns `this.bar` synchronously, in the same call),
3505
+ // but the asymmetry is a trap for a future caller that holds a reference across a render.
3506
+ if (this.destroyed)
3507
+ return null;
3508
+ if (!this.plateRect)
3509
+ return null;
3510
+ const s = this.inner.scale.x;
3511
+ const origin = this.inner.getGlobalPosition();
3512
+ return {
3513
+ x: origin.x + this.plateRect.x * s,
3514
+ y: origin.y + this.plateRect.y * s,
3515
+ w: this.plateRect.w * s,
3516
+ h: this.plateRect.h * s,
3517
+ };
3518
+ }
3519
+ /** The scale factor the bar currently applies to itself (`inner.scale`) — shared with the menu
3520
+ * popover so its typography/padding/row-heights scale in lockstep with the bar's own chrome,
3521
+ * instead of ignoring the viewport like a fixed-local-size card would. */
3522
+ fitScale() {
3523
+ // Same destroyed guard as menuPlate()/menuAnchor() above, and the same neutral fallback a
3524
+ // scale factor should have (1 = no scaling) rather than throwing.
3525
+ if (this.destroyed)
3526
+ return 1;
3527
+ return this.inner.scale.x;
3528
+ }
3113
3529
  // ── wide / landscape ──────────────────────────────────────────────────────
3114
3530
  buildWide() {
3115
3531
  const { state, tokens } = this.host;
@@ -3120,13 +3536,14 @@ class BottomBar extends Container {
3120
3536
  this.buy = isBase ? (this.buildBuy(BUY_W, 13, 3) ?? undefined) : undefined;
3121
3537
  // LEFT info group: menu · balance · (Total win) · (Win)
3122
3538
  const left = new FlexBox({ direction: 'row', align: 'center', gap: ZONE_GAP });
3123
- left.add(new IconButton('menu', {
3539
+ this.menuBtn = new IconButton('menu', {
3124
3540
  size: 36,
3125
3541
  glyph: 30,
3126
3542
  color: '#ffffff',
3127
3543
  hover: tokens.accent,
3128
3544
  onTap: () => this.host.actions.openMenu(),
3129
- }));
3545
+ });
3546
+ left.add(this.menuBtn);
3130
3547
  if (!state.replay) {
3131
3548
  const bal = readout(this.host, 'Balance', this.host.fmt(state.balance));
3132
3549
  this.balanceValue = bal.valueText;
@@ -3315,6 +3732,7 @@ class BottomBar extends Container {
3315
3732
  hover: tokens.accent,
3316
3733
  onTap: () => this.host.actions.openMenu(),
3317
3734
  });
3735
+ this.menuBtn = menu;
3318
3736
  // autoplay is a base-mode control only — hidden in free spins / replay (matches the DOM bar)
3319
3737
  if (isBase && config.features.autoplay) {
3320
3738
  this.autoBtn = new IconButton('autoplay', {
@@ -3550,6 +3968,8 @@ class BottomBar extends Container {
3550
3968
  this.panelBg.clear();
3551
3969
  roundedPath(this.panelBg, panelX, SPIN_POP, panelRight - panelX, BAR_H, [12, 12, 12, 12]);
3552
3970
  this.panelBg.fill(tokens.bar);
3971
+ // The menu's plate — the whole continuous dark panel, local to `inner` (see menuPlate()).
3972
+ this.plateRect = { x: panelX, y: SPIN_POP, w: panelRight - panelX, h: BAR_H };
3553
3973
  if (this.buy)
3554
3974
  this.buy.position.set(OUTER_PAD, panelCenterY - BUY_W / 2);
3555
3975
  left.position.set(panelX + PANEL_PAD, panelCenterY - left.outerHeight / 2);
@@ -3582,6 +4002,18 @@ class BottomBar extends Container {
3582
4002
  // SPIN hero), inflating the controls row so it overlaps the info row below it.
3583
4003
  controls.setLayoutSize(rowW, M_CTRL_H);
3584
4004
  info.setLayoutSize(rowW, M_INFO_H);
4005
+ // The menu's plate — the controls row (NOT the info pill below it), local to `inner`. Read from
4006
+ // `controls.outerWidth/outerHeight` (its own nominal box), NOT the FlexBox's own bounds (which
4007
+ // would include the SPIN/FS hero popping out both above AND below it — see menuPlate()'s doc
4008
+ // comment) — but the TOP edge is deliberately extended upward by `pop`, the same hero pop-out
4009
+ // amount reserved as `topPad` above, so the plate the popover math sees is the row's true visual
4010
+ // extent on the side that matters: without this, the card's bottom (only `gap` above the plate's
4011
+ // top) can clip the top ~(pop-gap)px of the hero's arc, since 62px M_CTRL_H is 11px shorter than
4012
+ // the 84px hero. The BOTTOM edge is left alone — the hero's symmetric under-pop is a separate,
4013
+ // unrelated concern (the info pill sits right below with its own small gap) and extending it too
4014
+ // would perturb the `below`-placement branch (spaceBelow) for no benefit. A no-op when `pop` is 0
4015
+ // (no hero shown — e.g. replay without free spins).
4016
+ this.plateRect = { x: 0, y: topPad - pop, w: controls.outerWidth, h: controls.outerHeight + pop };
3585
4017
  const s = rowW > 0 ? Math.max(0.4, Math.min(1, avail / rowW)) : 1;
3586
4018
  this.inner.scale.set(s);
3587
4019
  this.inner.position.set((W - rowW * s) / 2, H - localBottom * s - M_PAD_BOTTOM);
@@ -3612,7 +4044,8 @@ class ScrollBox extends Container {
3612
4044
  this.canvas = canvas;
3613
4045
  this.addChild(this.content);
3614
4046
  // maskG is added to the scene only while scrolling (see refresh) — a leftover unused mask
3615
- // graphic renders as a white rect, and a masked container blocks pointer events to its children.
4047
+ // graphic renders as a white rect. (Masking does NOT gate pointer events to the content, despite
4048
+ // what an earlier version of this comment claimed — see the correction in refresh() below.)
3616
4049
  this.eventMode = 'static';
3617
4050
  this.on('pointerdown', this.onDown);
3618
4051
  this.on('globalpointermove', this.onMove);
@@ -3646,10 +4079,13 @@ class ScrollBox extends Container {
3646
4079
  const b = this.content.getLocalBounds();
3647
4080
  const contentH = b.height + b.y; // content laid out from y≈0 downward
3648
4081
  this.maxScroll = Math.max(0, contentH - this.viewH);
3649
- // Only clip + grab pointer/drag when the content actually overflows: a masked container blocks
3650
- // pointer events to its children in Pixi v8, so when it fits we leave it unmasked and passive →
3651
- // interactive controls (settings sliders/buttons) work. Tall scrolling content (game info) that
3652
- // does get masked has no interactive children, so nothing is lost there.
4082
+ // Only clip + grab pointer/drag when the content actually overflows. (An earlier version of this
4083
+ // comment claimed a masked container blocks pointer events to its children in Pixi v8 that's
4084
+ // false: EventBoundary's hitPruneFn only prunes a point OUTSIDE the mask/hitArea, so interactive
4085
+ // children stay reachable anywhere inside the visible viewport; see tests/pixi/bet-picker-fit.test.ts
4086
+ // and tests/pixi/menu.test.ts, which hit-test an overflowing, masked list on purpose to prove it.
4087
+ // We still only mask + grab the pointer when scrollable, since an unmasked, passive box is
4088
+ // simpler and cheaper when there's nothing to clip or drag.)
3653
4089
  const scrollable = this.maxScroll > 0;
3654
4090
  if (scrollable) {
3655
4091
  this.addChild(this.maskG);
@@ -3709,152 +4145,135 @@ class ScrollBox extends Container {
3709
4145
  }
3710
4146
  }
3711
4147
 
3712
- function clamp(min, pref, max) {
3713
- return Math.max(min, Math.min(max, pref));
3714
- }
3715
- /** Small rounded icon nav button — the overlay header back/close and row chevrons.
3716
- * `.ge-ov-nav`: 32×32, radius 9, plaque-dark bg, white icon, hover → glass bg + accent icon. */
3717
- function navButton(host, iconName, onTap, size = 32) {
3718
- const root = new Container();
3719
- const bg = new Graphics();
3720
- const draw = (hover) => {
3721
- bg.clear();
3722
- bg.roundRect(0, 0, size, size, 9);
3723
- bg.fill(hover ? host.tokens.plaqueGlass : host.tokens.plaqueDark);
3724
- };
3725
- draw(false);
3726
- const gs = Math.round(size * 0.5625); // glyph tracks the box (default 32 → 18, unchanged)
3727
- const glyph = makeIcon(iconName, gs, '#ffffff');
3728
- glyph.position.set((size - gs) / 2, (size - gs) / 2);
3729
- root.addChild(bg, glyph);
3730
- root.eventMode = 'static';
3731
- root.cursor = 'pointer';
3732
- root.hitArea = new Rectangle(0, 0, size, size);
3733
- attachHover(root, () => {
3734
- draw(true);
3735
- glyph.setColor(host.tokens.accent);
3736
- }, () => {
3737
- draw(false);
3738
- glyph.setColor('#ffffff');
3739
- });
3740
- attachPress(root, 0.92, onTap);
3741
- return root;
3742
- }
3743
- /** Full-screen overlay: frosted dark veil, fixed header (title + back/close), scrolling body.
3744
- * The body is rebuilt on resize so it reflows like the CSS overlay. */
3745
- class Overlay extends Container {
4148
+ /** Light-dismiss popover: a transparent full-screen hit rect + a rounded card with an arrow.
4149
+ * No veil, no frosted snapshot — the game stays visible and unblurred behind it. */
4150
+ class Popover extends Container {
3746
4151
  tag;
4152
+ dismissLayer = new Graphics();
4153
+ card = new Container();
4154
+ bg = new Graphics();
4155
+ arrow = new Graphics();
4156
+ scroll;
3747
4157
  host;
3748
4158
  opts;
3749
- veil = new Graphics();
3750
- header = new Container();
3751
- scroll;
3752
- titleNode = new Container();
3753
- nav = new Container();
3754
- w = 0;
3755
- h = 0;
3756
- headerH = 44;
3757
- /** Expose the scroll box for keyboard/test access. */
3758
- get scrollContent() { return this.scroll; }
4159
+ _cardX = 0;
4160
+ _cardY = 0;
4161
+ _cardW = 0;
4162
+ _arrowX = -1;
3759
4163
  constructor(host, opts) {
3760
4164
  super();
3761
4165
  this.host = host;
3762
4166
  this.opts = opts;
3763
4167
  this.tag = opts.tag;
3764
4168
  this.scroll = new ScrollBox(host.canvas);
3765
- this.addChild(this.veil, this.scroll, this.header);
3766
- this.veil.eventMode = 'static'; // swallow clicks to the game behind
4169
+ this.card.addChild(this.bg, this.arrow, this.scroll);
4170
+ this.addChild(this.dismissLayer, this.card);
4171
+ this.dismissLayer.eventMode = 'static';
4172
+ this.dismissLayer.on('pointertap', () => this.opts.onClose());
4173
+ // Taps on the card must not fall through to the dismiss layer.
4174
+ this.card.eventMode = 'static';
4175
+ // `e` itself is undefined when a caller (or test) emits the event with no payload, so guard the
4176
+ // property access, not just the call.
4177
+ this.card.on('pointertap', (e) => e?.stopPropagation?.());
3767
4178
  this.resize(host.screenW, host.screenH);
3768
4179
  }
4180
+ get cardX() { return this._cardX; }
4181
+ get cardY() { return this._cardY; }
4182
+ get cardWidth() { return this._cardW; }
4183
+ get arrowX() { return this._arrowX; }
4184
+ get arrowVisible() { return this.arrow.visible; }
3769
4185
  resize(w, h) {
3770
- this.w = w;
3771
- this.h = h;
3772
- const vh = h / 100;
3773
- this.headerH = clamp(40, 6.4 * vh, 52);
3774
- // veil
3775
- this.veil.clear();
3776
- this.veil.rect(0, 0, w, h);
3777
- this.veil.fill(this.host.tokens.backdrop);
3778
- this.veil.hitArea = new Rectangle(0, 0, w, h);
3779
- this.buildHeader();
3780
- this.layoutBody();
3781
- }
3782
- buildHeader() {
3783
- this.header.removeChildren().forEach((c) => c.destroy({ children: true }));
3784
- const pad = 10;
3785
- // back or spacer (left), centred title, close (right)
3786
- const left = this.opts.onBack
3787
- ? navButton(this.host, 'back', () => this.opts.onBack())
3788
- : new Container();
3789
- const close = navButton(this.host, 'close', () => this.opts.onClose());
3790
- const titleSize = clamp(13, 2.6 * (this.h / 100), 16);
3791
- const title = makeText(this.opts.title, {
3792
- size: titleSize,
3793
- weight: '800',
3794
- color: '#ffffff',
3795
- letterSpacing: titleSize * 0.04,
3796
- upper: true,
3797
- align: 'center',
3798
- });
3799
- title.anchor.set(0.5);
3800
- title.position.set(this.w / 2, this.headerH / 2 + pad / 2);
3801
- left.position.set(pad, (this.headerH - 32) / 2 + pad / 2);
3802
- close.position.set(this.w - 32 - pad, (this.headerH - 32) / 2 + pad / 2);
3803
- this.header.addChild(title, left, close);
3804
- }
3805
- layoutBody() {
3806
- const top = this.headerH + 6;
3807
- const sidePad = clamp(16, 4 * (this.w / 100), 24);
3808
- const vPad = clamp(6, 2 * (this.h / 100), 16);
3809
- const bodyW = Math.min(800, this.w - sidePad * 2);
3810
- this.scroll.position.set(0, top);
3811
- this.scroll.setViewport(this.w, this.h - top);
3812
- this.scroll.content.removeChildren().forEach((c) => c.destroy({ children: true }));
3813
- const content = this.opts.build(bodyW);
4186
+ this.dismissLayer.clear();
4187
+ this.dismissLayer.rect(0, 0, w, h).fill({ color: 0x000000, alpha: 0 });
4188
+ this.dismissLayer.hitArea = new Rectangle(0, 0, w, h);
4189
+ const s = this.opts.scale?.() ?? 1;
4190
+ const pad = 8;
4191
+ // Width is content-driven (spec: clamped to [220, min(320, surfaceWidth-16)]), so the real
4192
+ // content has to be measured before we know the final width to lay it out at. Probe-build once
4193
+ // at the SMALLEST allowed inner width purely to measure natural size, then throw that copy away
4194
+ // and build the kept one at the resolved final width. Measured in LOCAL (unscaled) units, like
4195
+ // every other Pixi size in this file — `s` only converts to screen units where placement needs
4196
+ // it (the card carries the scale as a single transform, same as the DOM's card).
4197
+ //
4198
+ // The probe deliberately measures at the MINIMUM, not the maximum: a decorative row (the menu's
4199
+ // separator) draws its divider line at exactly the width `build()` is called with it has no
4200
+ // content-driven size of its own, unlike every real row, which ignores that parameter and sizes
4201
+ // from its icon/label/control regardless. Probing at the maximum would make that separator line
4202
+ // alone measure near-maximum and dominate `naturalWidth`, pegging the card at ~maxW for every
4203
+ // menu that has a separator — which the default menu always does. Probing at the minimum cannot
4204
+ // distort the result the other way: content narrower than the probe still clamps to minW either
4205
+ // way (nothing above changes), and content wider than the probe always wins the max() the layout
4206
+ // takes over row widths, so real content still drives growth past minW correctly.
4207
+ const probeW = POPOVER.minW - pad * 2;
4208
+ const probe = this.opts.build(probeW);
4209
+ const measured = probe instanceof FlexBox ? probe.measureSize().w : probe.getSize().width;
4210
+ probe.destroy({ children: true });
4211
+ // Resolve the ON-SCREEN width (screen units, clamped against the surface), then convert back to
4212
+ // LOCAL for the actual content layout — mirrors the DOM's naturalW·s → resolvedW → style.width÷s.
4213
+ const screenW = popoverWidth(w, (measured + pad * 2) * s);
4214
+ const localW = s > 0 ? screenW / s : screenW;
4215
+ const content = this.opts.build(localW - pad * 2);
3814
4216
  if (content instanceof FlexBox)
3815
- content.setLayoutSize(bodyW, undefined);
3816
- content.position.set((this.w - bodyW) / 2, vPad);
4217
+ content.setLayoutSize(localW - pad * 2, undefined);
4218
+ const contentH = content.getSize().height; // local units
4219
+ // The plate falls back to the pointer when it can't be resolved (no distinct plaque), and to the
4220
+ // centred/arrow-less layout when neither resolves — placePopover itself already defaults the
4221
+ // ARROW to `pointer ?? plate`, so passing the pointer through unconditionally is enough there.
4222
+ // A DEGENERATE (fully zero-sized) plate counts as unresolved too, matching the DOM renderer's
4223
+ // rectOf(): `??` only falls through on null/undefined, so a real-but-{w:0,h:0} rect (e.g. read
4224
+ // before the bar's first layout pass) would otherwise silently win over a perfectly good pointer.
4225
+ const pointerRect = this.opts.pointer?.() ?? null;
4226
+ const rawPlate = this.opts.plate();
4227
+ const plateRect = rawPlate && !(rawPlate.w <= 0 && rawPlate.h <= 0) ? rawPlate : pointerRect;
4228
+ const p = placePopover(plateRect, { w, h }, { w: screenW, h: (contentH + pad * 2) * s }, pointerRect);
4229
+ const maxHLocal = s > 0 ? p.maxH / s : p.maxH;
4230
+ const cardH = Math.min(contentH + pad * 2, maxHLocal); // local units
4231
+ this.scroll.content.removeChildren().forEach((c) => c.destroy({ children: true }));
4232
+ this.scroll.position.set(pad, pad);
4233
+ this.scroll.setViewport(localW - pad * 2, cardH - pad * 2);
3817
4234
  this.scroll.content.addChild(content);
3818
4235
  this.scroll.refresh();
3819
- }
3820
- /** Handle keyboard navigation while this overlay is the top layer. */
4236
+ this.bg.clear();
4237
+ this.bg.roundRect(0, 0, localW, cardH, 18);
4238
+ this.bg.fill(this.host.tokens.plaqueDark);
4239
+ // Arrow: a 14×7 triangle (local units — it lives inside the scaled card) on the edge that faces
4240
+ // the plate.
4241
+ this.arrow.clear();
4242
+ this.arrow.visible = p.arrowX >= 0;
4243
+ if (this.arrow.visible) {
4244
+ const arrowXLocal = s > 0 ? p.arrowX / s : p.arrowX;
4245
+ const edge = p.below ? 0 : cardH; // the card edge the arrow sits on
4246
+ const tip = p.below ? -7 : cardH + 7; // the tip, pointing at the pointer (or the plate)
4247
+ this.arrow.moveTo(arrowXLocal - 7, edge);
4248
+ this.arrow.lineTo(arrowXLocal + 7, edge);
4249
+ this.arrow.lineTo(arrowXLocal, tip);
4250
+ this.arrow.fill(this.host.tokens.plaqueDark);
4251
+ }
4252
+ // The card carries the scale as ONE transform around its own (0,0) local origin — equivalent to
4253
+ // the DOM's transform-origin:top left — so `p.x`/`p.y` (screen units) remain its visual top-left
4254
+ // regardless of `s`, and every local size above (background rect, scroll viewport, arrow) scales
4255
+ // with it automatically.
4256
+ this.card.scale.set(s);
4257
+ this.card.position.set(p.x, p.y);
4258
+ this._cardX = p.x;
4259
+ this._cardY = p.y;
4260
+ this._cardW = screenW;
4261
+ this._arrowX = p.arrowX;
4262
+ }
4263
+ /** Arrow keys scroll a long list; everything else (Escape included) goes to the controller. */
3821
4264
  onKey(e) {
3822
- const viewH = this.h - (this.headerH + 6); // body viewport height
3823
- const lineStep = 60;
3824
- const pageStep = Math.floor(viewH * 0.9);
3825
- switch (e.code) {
3826
- case 'ArrowDown':
3827
- this.scroll.scrollBy(lineStep);
3828
- return true;
3829
- case 'ArrowUp':
3830
- this.scroll.scrollBy(-lineStep);
3831
- return true;
3832
- case 'PageDown':
3833
- this.scroll.scrollBy(pageStep);
3834
- return true;
3835
- case 'PageUp':
3836
- this.scroll.scrollBy(-pageStep);
3837
- return true;
3838
- case 'Space':
3839
- if (e.shiftKey) {
3840
- this.scroll.scrollBy(-pageStep);
3841
- }
3842
- else {
3843
- this.scroll.scrollBy(pageStep);
3844
- }
3845
- return true;
3846
- case 'Home':
3847
- this.scroll.scrollBy(-999999);
3848
- return true;
3849
- case 'End':
3850
- this.scroll.scrollBy(999999);
3851
- return true;
3852
- default:
3853
- return false;
4265
+ if (e.code === 'ArrowDown') {
4266
+ this.scroll.scrollBy(40);
4267
+ return true;
3854
4268
  }
4269
+ if (e.code === 'ArrowUp') {
4270
+ this.scroll.scrollBy(-40);
4271
+ return true;
4272
+ }
4273
+ return false;
3855
4274
  }
3856
4275
  fit() {
3857
- /* overlays scroll; no card fit needed */
4276
+ this.resize(this.host.screenW, this.host.screenH);
3858
4277
  }
3859
4278
  onRemove() {
3860
4279
  this.scroll.destroy({ children: true });
@@ -3980,6 +4399,49 @@ class Slider extends Container {
3980
4399
  return { w: this.w, h: 24 };
3981
4400
  }
3982
4401
  }
4402
+ /** Pill switch — the Pixi twin of the DOM `.ge-toggle`. 42×24, knob 20, accent when on. */
4403
+ class Toggle extends Container {
4404
+ track = new Graphics();
4405
+ knob = new Graphics();
4406
+ _value;
4407
+ onChange;
4408
+ accent;
4409
+ offFill;
4410
+ constructor(value, onChange, accent = '#8b5cf6', off = 'rgba(255,255,255,.22)') {
4411
+ super();
4412
+ this._value = value;
4413
+ this.onChange = onChange;
4414
+ this.accent = accent;
4415
+ this.offFill = off;
4416
+ this.addChild(this.track, this.knob);
4417
+ this.eventMode = 'static';
4418
+ this.cursor = 'pointer';
4419
+ this.hitArea = new Rectangle(0, 0, 42, 24);
4420
+ this.on('pointertap', () => this.onChange(!this._value));
4421
+ this.paint();
4422
+ }
4423
+ get value() {
4424
+ return this._value;
4425
+ }
4426
+ setValue(v) {
4427
+ this._value = v;
4428
+ this.paint();
4429
+ }
4430
+ paint() {
4431
+ this.track.clear();
4432
+ this.track.roundRect(0, 0, 42, 24, 12);
4433
+ this.track.fill(this._value ? this.accent : this.offFill);
4434
+ this.knob.clear();
4435
+ this.knob.circle(this._value ? 30 : 12, 12, 10);
4436
+ this.knob.fill('#ffffff');
4437
+ }
4438
+ measureSize() {
4439
+ return { w: 42, h: 24 };
4440
+ }
4441
+ setLayoutSize() {
4442
+ /* fixed size */
4443
+ }
4444
+ }
3983
4445
  /** Picker chip — `.ge-chip`. Selected = accent bg + accent border. */
3984
4446
  class Chip extends Container {
3985
4447
  id;
@@ -4028,112 +4490,297 @@ class Chip extends Container {
4028
4490
  }
4029
4491
  }
4030
4492
 
4031
- /** Settings overlay sound on/off, volume sliders, and a Game info link. */
4032
- function openSettings(host) {
4033
- return new Overlay(host, {
4034
- tag: 'settings',
4035
- title: host.t('Settings'),
4493
+ /** The bar menu as a Pixi popover. Same rows, same order as the DOM — both come from resolveMenu.
4494
+ *
4495
+ * `getAnchor` (the burger — the arrow's POINTER), `getPlate` (the bar's plaque — drives placement)
4496
+ * and `getScale` (the bar's own fit-scale) are all FUNCTIONS, resolved lazily on every reposition —
4497
+ * never a captured `BottomBar` instance. `PixiRenderer.renderBar()` destroys and rebuilds the
4498
+ * BottomBar on every resize AND on ~20 other state changes, in the SAME resize handler that then
4499
+ * repositions this popover. A captured instance would already be destroyed by the time `resize()`
4500
+ * next runs, so `menuAnchor()`/`menuPlate()` on it would return `null` and the card would silently
4501
+ * recentre with its arrow hidden — the exact bug the DOM renderer shipped and fixed the same way
4502
+ * (see `html/Menu.ts`'s plate/pointer callbacks). Passing getters means every call reads whichever
4503
+ * bar is CURRENT. `getPlate`/`getScale` are optional so every pre-existing caller (which only ever
4504
+ * passed `getAnchor`) keeps behaving exactly as it did before the plate/pointer/scale split. */
4505
+ function openMenu(host, getAnchor, getPlate, getScale) {
4506
+ const updaters = {};
4507
+ const layer = new Popover(host, {
4508
+ tag: 'menu',
4509
+ plate: () => getPlate?.() ?? null,
4510
+ pointer: () => getAnchor?.() ?? null,
4511
+ scale: () => getScale?.() ?? 1,
4036
4512
  onClose: () => host.closeLayer(),
4037
- build: (w) => buildBody$1(host, w),
4513
+ build: (width) => {
4514
+ const col = new FlexBox({ direction: 'column', align: 'stretch', gap: 6 });
4515
+ for (const row of resolveMenu(host))
4516
+ col.add(buildRow(host, row, width, updaters));
4517
+ return col;
4518
+ },
4038
4519
  });
4520
+ host.setMenuRefresh((id, v) => updaters[id]?.(v));
4521
+ return layer;
4522
+ }
4523
+ function label(text) {
4524
+ return makeText(text, { size: 13, weight: '600', color: '#ffffff' });
4039
4525
  }
4040
- function buildBody$1(host, width) {
4041
- const col = new FlexBox({ direction: 'column', align: 'stretch', gap: 10 });
4042
- // Sound on/off backed by the shell's shared `soundOn` state so this toggle and the Shift+M
4043
- // hotkey stay in sync; `setSound` emits `settingChange({ key: 'sound' })` and refreshes the icon.
4044
- const soundOn0 = host.soundOn ?? true;
4045
- const speaker = new IconButton(soundOn0 ? 'soundOn' : 'soundOff', {
4046
- size: 36,
4047
- glyph: 24,
4048
- color: host.tokens.plaqueLabel,
4049
- hover: host.tokens.accent,
4050
- activeColor: '#ffffff',
4051
- active: soundOn0,
4052
- onTap: () => host.setSound?.(!(host.soundOn ?? true)),
4526
+ function rowBox(host, name, column = false) {
4527
+ const box = new FlexBox({
4528
+ direction: column ? 'column' : 'row',
4529
+ align: column ? 'stretch' : 'center',
4530
+ gap: column ? 8 : 10,
4531
+ padding: { top: 10, bottom: 10, left: 12, right: 12 },
4532
+ minHeight: column ? undefined : 44,
4533
+ background: { fill: host.tokens.plaqueGlass, radius: 14 },
4053
4534
  });
4054
- // Live-update the speaker when sound changes from here OR via Shift+M (shell clears on close).
4055
- host.setSoundRefresh?.((on) => {
4056
- if (speaker.destroyed)
4057
- return; // overlay torn down but refresher not yet cleared (push-over edge)
4058
- speaker.setIcon(on ? 'soundOn' : 'soundOff');
4059
- speaker.active = on;
4535
+ box.label = name;
4536
+ return box;
4537
+ }
4538
+ function buildRow(host, row, width, updaters) {
4539
+ if (row.kind === 'separator') {
4540
+ const sep = new Container();
4541
+ sep.label = 'menu-sep';
4542
+ const line = new Graphics().rect(4, 6, width - 8, 1).fill(host.tokens.plaqueLine);
4543
+ line.alpha = 0.5;
4544
+ sep.addChild(line);
4545
+ return sep;
4546
+ }
4547
+ if (row.kind === 'button') {
4548
+ const box = rowBox(host, `menu-row-${row.id}`);
4549
+ if (row.icon)
4550
+ box.add(makeIcon(row.icon, 20, '#ffffff'));
4551
+ const text = label(row.label);
4552
+ box.add(text);
4553
+ box.add(new Spacer(), { grow: 1 });
4554
+ if (row.chevron)
4555
+ box.add(makeIcon('chevronRight', 16, host.tokens.muted));
4556
+ if (!row.disabled) {
4557
+ box.setInteractive(true);
4558
+ box.on('pointertap', () => {
4559
+ host.closeLayer();
4560
+ row.select();
4561
+ });
4562
+ attachHover(box, () => { box.setBgFill(host.tokens.plaqueGlassHover); text.style.fill = host.tokens.accent; }, () => { box.setBgFill(host.tokens.plaqueGlass); text.style.fill = '#ffffff'; });
4563
+ }
4564
+ else {
4565
+ box.alpha = 0.5;
4566
+ }
4567
+ return box;
4568
+ }
4569
+ if (row.kind === 'toggle') {
4570
+ const box = rowBox(host, `menu-row-${row.id}`);
4571
+ const glyph = row.icon(row.get());
4572
+ const iconNode = glyph ? makeIcon(glyph, 20, '#ffffff') : null;
4573
+ if (iconNode)
4574
+ box.add(iconNode);
4575
+ box.add(label(row.label));
4576
+ box.add(new Spacer(), { grow: 1 });
4577
+ // Disabled: neutralise the write-through at the source (a no-op onChange) rather than relying
4578
+ // solely on eventMode — Toggle wires its own pointertap listener unconditionally in its
4579
+ // constructor, so a stray direct emit must still be harmless, not just unreachable by real hits.
4580
+ const toggle = new Toggle(row.get(), row.disabled ? () => { } : (v) => row.set(v), host.tokens.accent, host.tokens.plaqueLine);
4581
+ box.add(toggle);
4582
+ updaters[row.id] = (v) => {
4583
+ const on = v === true;
4584
+ toggle.setValue(on);
4585
+ const next = row.icon(on);
4586
+ if (iconNode && next)
4587
+ iconNode.setIcon(next);
4588
+ };
4589
+ if (row.disabled) {
4590
+ box.alpha = 0.5;
4591
+ toggle.eventMode = 'none'; // dimmed + inert — mirrors the button branch's disabled treatment
4592
+ }
4593
+ return box;
4594
+ }
4595
+ const box = rowBox(host, `menu-row-${row.id}`, true);
4596
+ const head = new FlexBox({ direction: 'row', align: 'center' });
4597
+ const value = makeText(row.format(row.get()), { size: 12, weight: '700', color: host.tokens.plaqueLabel });
4598
+ head.add(label(row.label));
4599
+ head.add(new Spacer(), { grow: 1 });
4600
+ head.add(value);
4601
+ // Slider works in 0..1; map to the row's declared bounds, snapping to the MIN-anchored lattice
4602
+ // (min + k·step). Snapping to a bare multiple of step instead (Math.round(raw/step)*step) drifts
4603
+ // off `min` whenever min isn't itself a multiple of step — the common case, since the default step
4604
+ // is (max-min)/20: e.g. min:1,max:10 gives step 0.45, and the bare-multiple formula would emit 0.9
4605
+ // at the far left, BELOW the declared min. Clamp guards any float overshoot past either end.
4606
+ const toUnit = (v) => (row.max === row.min ? 0 : (v - row.min) / (row.max - row.min));
4607
+ const fromUnit = (u) => {
4608
+ const raw = row.min + u * (row.max - row.min);
4609
+ const snapped = row.min + Math.round((raw - row.min) / row.step) * row.step;
4610
+ return Math.max(row.min, Math.min(row.max, snapped));
4611
+ };
4612
+ // Disabled: same reasoning as the toggle branch above — a no-op onInput, not just eventMode.
4613
+ const slider = new Slider(host, toUnit(row.get()), row.disabled ? () => { } : (u) => {
4614
+ const v = fromUnit(u);
4615
+ value.text = row.format(v);
4616
+ head.layout(); // the readout's text just changed width (e.g. "5%" → "100%") — reposition it
4617
+ row.set(v);
4060
4618
  });
4061
- col.add(glassRow(host, [textNode(host, host.t('Sound')), new Spacer(), speaker]));
4062
- // Volume sliders — positions read from the shell's stored volumes (stateful across opens); the
4063
- // registered refreshers let `host.setVolume()` from game code move the thumbs live.
4064
- const updaters = {};
4065
- col.add(sliderRow(host, width, 'master', host.t('Master volume'), updaters));
4066
- col.add(sliderRow(host, width, 'music', host.t('Music'), updaters));
4067
- col.add(sliderRow(host, width, 'sfx', host.t('SFX'), updaters));
4068
- host.setVolumeRefresh?.((key, v) => updaters[key]?.(v));
4069
- // Game info link
4070
- const infoIcon = makeIcon('info', 22, '#ffffff');
4071
- const infoLabel = textNode(host, host.t('Game info'));
4072
- const chevron = makeIcon('chevronRight', 20, host.tokens.muted);
4073
- const infoRow = glassRow(host, [infoIcon, infoLabel, new Spacer(), chevron], { button: true, onTap: () => host.actions.openInfo() });
4074
- col.add(infoRow);
4075
- return col;
4619
+ updaters[row.id] = (v) => {
4620
+ const n = Number(v);
4621
+ value.text = row.format(n);
4622
+ head.layout();
4623
+ slider.setValue(toUnit(n));
4624
+ };
4625
+ box.add(head);
4626
+ box.add(slider);
4627
+ if (row.disabled) {
4628
+ box.alpha = 0.5;
4629
+ slider.eventMode = 'none';
4630
+ }
4631
+ return box;
4076
4632
  }
4077
- function textNode(host, text) {
4078
- return makeText(text, { size: 14, weight: '600', color: '#ffffff' });
4633
+
4634
+ function clamp(min, pref, max) {
4635
+ return Math.max(min, Math.min(max, pref));
4079
4636
  }
4080
- /** A full-width glass row holding the given children (label/controls), align-centred. */
4081
- function glassRow(host, children, opts = {}) {
4082
- const row = new FlexBox({
4083
- direction: 'row',
4084
- align: 'center',
4085
- gap: 12,
4086
- // .ge-ov-row { padding: clamp(11px,2.2vh,15px) 16px } — 15 at desktop; minHeight matches the
4087
- // DOM row's effective height (driven by the tallest child's line box, not just the em box).
4088
- padding: { top: 15, bottom: 15, left: 16, right: 16 },
4089
- minHeight: 60,
4090
- background: { fill: host.tokens.plaqueGlass, radius: 16 },
4637
+ /** Small rounded icon nav button the overlay header back/close and row chevrons.
4638
+ * `.ge-ov-nav`: 32×32, radius 9, plaque-dark bg, white icon, hover → glass bg + accent icon. */
4639
+ function navButton(host, iconName, onTap, size = 32) {
4640
+ const root = new Container();
4641
+ const bg = new Graphics();
4642
+ const draw = (hover) => {
4643
+ bg.clear();
4644
+ bg.roundRect(0, 0, size, size, 9);
4645
+ bg.fill(hover ? host.tokens.plaqueGlass : host.tokens.plaqueDark);
4646
+ };
4647
+ draw(false);
4648
+ const gs = Math.round(size * 0.5625); // glyph tracks the box (default 32 → 18, unchanged)
4649
+ const glyph = makeIcon(iconName, gs, '#ffffff');
4650
+ glyph.position.set((size - gs) / 2, (size - gs) / 2);
4651
+ root.addChild(bg, glyph);
4652
+ root.eventMode = 'static';
4653
+ root.cursor = 'pointer';
4654
+ root.hitArea = new Rectangle(0, 0, size, size);
4655
+ attachHover(root, () => {
4656
+ draw(true);
4657
+ glyph.setColor(host.tokens.accent);
4658
+ }, () => {
4659
+ draw(false);
4660
+ glyph.setColor('#ffffff');
4091
4661
  });
4092
- for (const c of children)
4093
- row.add(c, c instanceof Spacer ? { grow: 1 } : {});
4094
- if (opts.button) {
4095
- row.setInteractive(true); // full-box hit area hover + tap across the whole row, not just the icon/label
4096
- if (opts.onTap)
4097
- row.on('pointertap', opts.onTap);
4098
- // hover: brighter glass + accent text (DOM button.ge-ov-row:hover)
4099
- const texts = children.filter((c) => c instanceof Text);
4100
- const orig = texts.map((t) => t.style.fill);
4101
- attachHover(row, () => {
4102
- row.setBgFill(host.tokens.plaqueGlassHover);
4103
- texts.forEach((t) => (t.style.fill = host.tokens.accent));
4104
- }, () => {
4105
- row.setBgFill(host.tokens.plaqueGlass);
4106
- texts.forEach((t, i) => (t.style.fill = orig[i]));
4662
+ attachPress(root, 0.92, onTap);
4663
+ return root;
4664
+ }
4665
+ /** Full-screen overlay: frosted dark veil, fixed header (title + back/close), scrolling body.
4666
+ * The body is rebuilt on resize so it reflows like the CSS overlay. */
4667
+ class Overlay extends Container {
4668
+ tag;
4669
+ host;
4670
+ opts;
4671
+ veil = new Graphics();
4672
+ header = new Container();
4673
+ scroll;
4674
+ titleNode = new Container();
4675
+ nav = new Container();
4676
+ w = 0;
4677
+ h = 0;
4678
+ headerH = 44;
4679
+ /** Expose the scroll box for keyboard/test access. */
4680
+ get scrollContent() { return this.scroll; }
4681
+ constructor(host, opts) {
4682
+ super();
4683
+ this.host = host;
4684
+ this.opts = opts;
4685
+ this.tag = opts.tag;
4686
+ this.scroll = new ScrollBox(host.canvas);
4687
+ this.addChild(this.veil, this.scroll, this.header);
4688
+ this.veil.eventMode = 'static'; // swallow clicks to the game behind
4689
+ this.resize(host.screenW, host.screenH);
4690
+ }
4691
+ resize(w, h) {
4692
+ this.w = w;
4693
+ this.h = h;
4694
+ const vh = h / 100;
4695
+ this.headerH = clamp(40, 6.4 * vh, 52);
4696
+ // veil
4697
+ this.veil.clear();
4698
+ this.veil.rect(0, 0, w, h);
4699
+ this.veil.fill(this.host.tokens.backdrop);
4700
+ this.veil.hitArea = new Rectangle(0, 0, w, h);
4701
+ this.buildHeader();
4702
+ this.layoutBody();
4703
+ }
4704
+ buildHeader() {
4705
+ this.header.removeChildren().forEach((c) => c.destroy({ children: true }));
4706
+ const pad = 10;
4707
+ // back or spacer (left), centred title, close (right)
4708
+ const left = this.opts.onBack
4709
+ ? navButton(this.host, 'back', () => this.opts.onBack())
4710
+ : new Container();
4711
+ const close = navButton(this.host, 'close', () => this.opts.onClose());
4712
+ const titleSize = clamp(13, 2.6 * (this.h / 100), 16);
4713
+ const title = makeText(this.opts.title, {
4714
+ size: titleSize,
4715
+ weight: '800',
4716
+ color: '#ffffff',
4717
+ letterSpacing: titleSize * 0.04,
4718
+ upper: true,
4719
+ align: 'center',
4107
4720
  });
4721
+ title.anchor.set(0.5);
4722
+ title.position.set(this.w / 2, this.headerH / 2 + pad / 2);
4723
+ left.position.set(pad, (this.headerH - 32) / 2 + pad / 2);
4724
+ close.position.set(this.w - 32 - pad, (this.headerH - 32) / 2 + pad / 2);
4725
+ this.header.addChild(title, left, close);
4726
+ }
4727
+ layoutBody() {
4728
+ const top = this.headerH + 6;
4729
+ const sidePad = clamp(16, 4 * (this.w / 100), 24);
4730
+ const vPad = clamp(6, 2 * (this.h / 100), 16);
4731
+ const bodyW = Math.min(800, this.w - sidePad * 2);
4732
+ this.scroll.position.set(0, top);
4733
+ this.scroll.setViewport(this.w, this.h - top);
4734
+ this.scroll.content.removeChildren().forEach((c) => c.destroy({ children: true }));
4735
+ const content = this.opts.build(bodyW);
4736
+ if (content instanceof FlexBox)
4737
+ content.setLayoutSize(bodyW, undefined);
4738
+ content.position.set((this.w - bodyW) / 2, vPad);
4739
+ this.scroll.content.addChild(content);
4740
+ this.scroll.refresh();
4741
+ }
4742
+ /** Handle keyboard navigation while this overlay is the top layer. */
4743
+ onKey(e) {
4744
+ const viewH = this.h - (this.headerH + 6); // body viewport height
4745
+ const lineStep = 60;
4746
+ const pageStep = Math.floor(viewH * 0.9);
4747
+ switch (e.code) {
4748
+ case 'ArrowDown':
4749
+ this.scroll.scrollBy(lineStep);
4750
+ return true;
4751
+ case 'ArrowUp':
4752
+ this.scroll.scrollBy(-lineStep);
4753
+ return true;
4754
+ case 'PageDown':
4755
+ this.scroll.scrollBy(pageStep);
4756
+ return true;
4757
+ case 'PageUp':
4758
+ this.scroll.scrollBy(-pageStep);
4759
+ return true;
4760
+ case 'Space':
4761
+ if (e.shiftKey) {
4762
+ this.scroll.scrollBy(-pageStep);
4763
+ }
4764
+ else {
4765
+ this.scroll.scrollBy(pageStep);
4766
+ }
4767
+ return true;
4768
+ case 'Home':
4769
+ this.scroll.scrollBy(-999999);
4770
+ return true;
4771
+ case 'End':
4772
+ this.scroll.scrollBy(999999);
4773
+ return true;
4774
+ default:
4775
+ return false;
4776
+ }
4777
+ }
4778
+ fit() {
4779
+ /* overlays scroll; no card fit needed */
4780
+ }
4781
+ onRemove() {
4782
+ this.scroll.destroy({ children: true });
4108
4783
  }
4109
- return row;
4110
- }
4111
- /** A column row: head (label + live % value) over a draggable slider. */
4112
- function sliderRow(host, bodyWidth, key, label, updaters) {
4113
- const row = new FlexBox({
4114
- direction: 'column',
4115
- align: 'stretch',
4116
- gap: 10,
4117
- padding: { top: 15, bottom: 15, left: 16, right: 16 },
4118
- background: { fill: host.tokens.plaqueGlass, radius: 16 },
4119
- });
4120
- const head = new FlexBox({ direction: 'row', align: 'center', justify: 'space-between' });
4121
- const initial = host.getVolume(key);
4122
- const valueText = makeText(`${Math.round(initial * 100)}%`, { size: 13, weight: '700', color: host.tokens.plaqueLabel });
4123
- head.add(makeText(label, { size: 14, weight: '600', color: '#ffffff' }));
4124
- head.add(new Spacer(), { grow: 1 });
4125
- head.add(valueText);
4126
- const slider = new Slider(host, initial, (v) => {
4127
- valueText.text = `${Math.round(v * 100)}%`;
4128
- host.setVolume(key, v);
4129
- });
4130
- updaters[key] = (v) => {
4131
- valueText.text = `${Math.round(v * 100)}%`;
4132
- slider.setValue(v);
4133
- };
4134
- row.add(head);
4135
- row.add(slider);
4136
- return row;
4137
4784
  }
4138
4785
 
4139
4786
  /** Default order key for the auto-injected hotkeys section: just after `controls` (-1). */
@@ -4146,7 +4793,7 @@ function openGameInfo(host) {
4146
4793
  onClose: () => host.closeLayer(),
4147
4794
  onBack: () => {
4148
4795
  host.closeLayer();
4149
- host.actions.openSettings();
4796
+ host.actions.openMenu();
4150
4797
  },
4151
4798
  build: (w) => buildBody(host, w),
4152
4799
  });
@@ -5953,6 +6600,15 @@ class PixiRenderer {
5953
6600
  this.bar = new BottomBar(this.ctx);
5954
6601
  this.barLayer.addChild(this.bar);
5955
6602
  this.bar.applyFit();
6603
+ // renderBar() runs on every resize AND on ~20 other state changes (bet/win/turbo/mode/…), any of
6604
+ // which can change the bar's own fitScale()/menuPlate() (e.g. a WIN pill appearing mid-autoplay
6605
+ // retriggers the wide layout's overflow-tightening branch). Only onResize used to reposition the
6606
+ // open layer, so a live bar-content change while the menu was open left it at the stale
6607
+ // scale/position until the next resize. Every ShellLayer's resize() only re-reads current
6608
+ // geometry and re-fits/re-centres itself — none of them call back into renderBar() (verified:
6609
+ // Popover, CardModal, Overlay, BuyBonusOverlay) — so this cannot recurse; `currentLayer` is
6610
+ // `null` whenever nothing is open, so this cannot throw either.
6611
+ this.currentLayer?.resize?.(this.screenW, this.screenH);
5956
6612
  }
5957
6613
  setLayout() {
5958
6614
  this.renderBar();
@@ -5986,8 +6642,13 @@ class PixiRenderer {
5986
6642
  openOverlay(req) {
5987
6643
  let layer = null;
5988
6644
  switch (req.kind) {
5989
- case 'settings':
5990
- layer = openSettings(this.ctx);
6645
+ case 'menu':
6646
+ // Getters, not `this.bar` by value: renderBar() destroys/rebuilds the bar on every resize
6647
+ // and ~20 other state changes, in the same resize handler that then repositions this popover
6648
+ // — see Menu.ts's openMenu doc comment for why this must stay lazy. menuAnchor (the burger)
6649
+ // is the arrow's pointer; menuPlate (the plaque) drives placement; fitScale is the same
6650
+ // factor BottomBar applies to its own content via `inner.scale`.
6651
+ layer = openMenu(this.ctx, () => this.bar?.menuAnchor() ?? null, () => this.bar?.menuPlate() ?? null, () => this.bar?.fitScale() ?? 1);
5991
6652
  break;
5992
6653
  case 'gameInfo':
5993
6654
  layer = openGameInfo(this.ctx);
@@ -6010,7 +6671,7 @@ class PixiRenderer {
6010
6671
  }
6011
6672
  if (!layer)
6012
6673
  return;
6013
- this.pushLayer(layer);
6674
+ this.pushLayer(layer, { backdrop: req.kind !== 'menu' });
6014
6675
  const built = layer;
6015
6676
  return {
6016
6677
  onKey: built.onKey ? built.onKey.bind(built) : undefined,
@@ -6020,10 +6681,6 @@ class PixiRenderer {
6020
6681
  closeOverlay() {
6021
6682
  this.closeLayer();
6022
6683
  }
6023
- refreshSoundIcon(_on) {
6024
- // No-op: the open Settings overlay registers its icon updater via host.setSoundRefresh, which
6025
- // the controller's setSound path drives. The renderer has nothing extra to refresh.
6026
- }
6027
6684
  /** Fade out (≈250ms, like GameShell's REMOVE_FADE_MS) then tear down; resolves when removed. */
6028
6685
  destroy() {
6029
6686
  if (this.destroyed)
@@ -6047,9 +6704,12 @@ class PixiRenderer {
6047
6704
  });
6048
6705
  }
6049
6706
  // ── layer stack ────────────────────────────────────────────────────────────
6050
- pushLayer(node) {
6707
+ pushLayer(node, opts) {
6051
6708
  this.clearLayer();
6052
- this.makeBackdrop(); // frosted snapshot of the scene behind (the DOM's backdrop-filter:blur)
6709
+ // Light-dismiss layers (the menu popover) opt out with `{ backdrop: false }` no frosted
6710
+ // snapshot, the game stays visible behind them. Every other caller is unaffected (defaults on).
6711
+ if (opts?.backdrop !== false)
6712
+ this.makeBackdrop(); // frosted snapshot (the DOM's backdrop-filter:blur)
6053
6713
  this.currentLayer = node;
6054
6714
  this.modalLayer.addChild(node);
6055
6715
  this.fitModals();
@@ -6171,6 +6831,7 @@ class PixiRenderer {
6171
6831
  get tokens() { return host.tokens; },
6172
6832
  get layout() { return host.layout; },
6173
6833
  get soundOn() { return host.soundOn; },
6834
+ get menu() { return host.menu; },
6174
6835
  get actions() { return host.actions; },
6175
6836
  openReplay: (opts) => host.openReplay(opts),
6176
6837
  t: (s) => host.t(s),
@@ -6178,17 +6839,18 @@ class PixiRenderer {
6178
6839
  emit: host.emit.bind(host),
6179
6840
  notifyResize: (w, h) => host.notifyResize(w, h),
6180
6841
  setSound: (on) => host.setSound(on),
6181
- setSoundRefresh: (fn) => host.setSoundRefresh(fn),
6182
6842
  getVolume: (key) => host.getVolume(key),
6183
6843
  setVolume: (key, v) => host.setVolume(key, v),
6184
- setVolumeRefresh: (fn) => host.setVolumeRefresh(fn),
6844
+ getMenuValue: (id) => host.getMenuValue(id),
6845
+ setMenuValue: (id, v) => host.setMenuValue(id, v),
6846
+ setMenuRefresh: (fn) => host.setMenuRefresh(fn),
6185
6847
  // — Pixi-specific surface —
6186
6848
  get ticker() { return self.app.ticker; },
6187
6849
  get canvas() { return self.app.canvas; },
6188
6850
  get screenW() { return self.app.screen.width; },
6189
6851
  get screenH() { return self.app.screen.height; },
6190
6852
  render: () => self.renderBar(),
6191
- pushLayer: (node) => self.pushLayer(node),
6853
+ pushLayer: (node, opts) => self.pushLayer(node, opts),
6192
6854
  // Route component-initiated closes through the controller (not straight to self.closeLayer) so
6193
6855
  // it clears its OverlayHandle. Otherwise the handle goes stale: hasOpenLayer() stays true and
6194
6856
  // keydowns keep routing to onKey on a destroyed overlay → write to a torn-down ScrollBox.
@@ -6222,5 +6884,5 @@ function removePixiShell() {
6222
6884
  return shell.destroy();
6223
6885
  }
6224
6886
 
6225
- export { DEFAULT_ACCENT, PACKAGE_VERSION, PixiRenderer, SCHEMES, ShellController, createI18n, createPixiShell, createShell, normalizeLang, removePixiShell, resolveConfig, resolveTheme, socialize };
6887
+ export { DEFAULT_ACCENT, DEFAULT_MENU, PACKAGE_VERSION, POPOVER, PixiRenderer, SCHEMES, ShellController, createI18n, createPixiShell, createShell, isPresetId, normalizeLang, placePopover, popoverWidth, rangeBounds, removePixiShell, resolveConfig, resolveMenu, resolveTheme, seedMenuValues, socialize };
6226
6888
  //# sourceMappingURL=pixi.esm.js.map