@invonetwork/web-sdk 3.26.0 → 3.27.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.
package/dist/game.js ADDED
@@ -0,0 +1,1034 @@
1
+ export { SDK_VERSION } from './chunk-3YDO7GSH.js';
2
+ import { newEventId } from './chunk-VP3OK4J4.js';
3
+
4
+ // src/game/client.ts
5
+ var InvoGameError = class extends Error {
6
+ constructor(code, message, status) {
7
+ super(message);
8
+ this.name = "InvoGameError";
9
+ this.code = code;
10
+ this.status = status;
11
+ }
12
+ };
13
+ var InvoGameEconomy = class {
14
+ constructor(options = {}) {
15
+ this.player = null;
16
+ this.wallet = null;
17
+ this.catalog = null;
18
+ this.setupRequired = false;
19
+ this.missingSecrets = [];
20
+ this.token = null;
21
+ this.listeners = /* @__PURE__ */ new Map();
22
+ this.pendingEarn = 0;
23
+ this.pendingEarnReason = "earned in play";
24
+ this.earnTimer = null;
25
+ this.base = (options.baseUrl ?? "/api/invo").replace(/\/+$/, "");
26
+ this.storage = options.storage === void 0 ? safeLocalStorage() : options.storage;
27
+ this.storageKey = options.storageKey ?? "invo.game.session";
28
+ this.fetchImpl = options.fetch ?? ((input, init) => fetch(input, init));
29
+ this.earnFlushMs = options.earnFlushMs ?? 750;
30
+ this.pollMs = options.purchasePollMs ?? 2e3;
31
+ this.purchaseTimeoutMs = options.purchaseTimeoutMs ?? 15 * 60 * 1e3;
32
+ }
33
+ /** Subscribe; returns the unsubscribe function. */
34
+ on(type, listener) {
35
+ let set = this.listeners.get(type);
36
+ if (!set) this.listeners.set(type, set = /* @__PURE__ */ new Set());
37
+ set.add(listener);
38
+ return () => set.delete(listener);
39
+ }
40
+ emit(type, value) {
41
+ for (const l of this.listeners.get(type) ?? []) {
42
+ try {
43
+ l(value);
44
+ } catch (err) {
45
+ console.error("[invo] listener failed", err);
46
+ }
47
+ }
48
+ }
49
+ get signedIn() {
50
+ return this.token !== null && this.player !== null;
51
+ }
52
+ /**
53
+ * Load the catalog, learn whether INVO is set up, restore a saved session, and resume a
54
+ * checkout the player is returning from (`?invo_purchase=` in the URL). Call once at boot.
55
+ */
56
+ async init() {
57
+ const health = await this.request("GET", "/health").catch(() => null);
58
+ this.setupRequired = health?.setupRequired === true;
59
+ this.missingSecrets = health?.missing ?? [];
60
+ this.emit("setup", { required: this.setupRequired, missing: this.missingSecrets });
61
+ this.catalog = await this.request("GET", "/catalog");
62
+ this.emit("catalog", this.catalog);
63
+ const saved = this.storage?.getItem(this.storageKey) ?? null;
64
+ if (saved && !this.setupRequired) {
65
+ this.token = saved;
66
+ try {
67
+ const wallet = await this.request("GET", "/wallet");
68
+ const player = this.readStoredPlayer();
69
+ this.player = player;
70
+ this.setWallet(wallet);
71
+ this.emit("session", player);
72
+ } catch {
73
+ this.clearSession();
74
+ }
75
+ }
76
+ this.resumeReturningCheckout();
77
+ }
78
+ /**
79
+ * Ask the server again whether its INVO secrets are set (after you add them and restart).
80
+ * Returns true when INVO is connected; emits `setup` when that changes.
81
+ */
82
+ async checkSetup() {
83
+ const health = await this.request("GET", "/health").catch(() => null);
84
+ if (!health) return !this.setupRequired;
85
+ const required = health.setupRequired === true;
86
+ const missing = health.missing ?? [];
87
+ if (required !== this.setupRequired || missing.join() !== this.missingSecrets.join()) {
88
+ this.setupRequired = required;
89
+ this.missingSecrets = missing;
90
+ this.emit("setup", { required, missing });
91
+ }
92
+ return !required;
93
+ }
94
+ /** Sign in (first time: email + phone; INVO creates the player). */
95
+ async signIn(input) {
96
+ const session = await this.request("POST", "/session", input);
97
+ this.token = session.sessionToken;
98
+ this.player = session.player;
99
+ this.storage?.setItem(this.storageKey, session.sessionToken);
100
+ this.storage?.setItem(`${this.storageKey}.player`, JSON.stringify(session.player));
101
+ this.setWallet(session.wallet);
102
+ this.emit("session", session.player);
103
+ return session.player;
104
+ }
105
+ async signOut() {
106
+ await this.flushEarnings().catch(() => void 0);
107
+ if (this.token) await this.request("POST", "/session/end").catch(() => void 0);
108
+ this.clearSession();
109
+ }
110
+ /** Re-read the wallet from the server. */
111
+ async refresh() {
112
+ if (!this.token) return null;
113
+ const wallet = await this.request("GET", "/wallet");
114
+ this.setWallet(wallet);
115
+ return wallet;
116
+ }
117
+ /** How many of an item the player owns (from the last server answer). */
118
+ quantity(itemId) {
119
+ return this.wallet?.inventory[itemId] ?? 0;
120
+ }
121
+ owns(itemId) {
122
+ return this.quantity(itemId) > 0;
123
+ }
124
+ item(itemId) {
125
+ return this.catalog?.items.find((i) => i.id === itemId);
126
+ }
127
+ balance(kind) {
128
+ return this.wallet ? this.wallet[kind] : null;
129
+ }
130
+ /** Whether the last known balance covers the item (the server decides for real). */
131
+ canAfford(itemId, quantity = 1) {
132
+ const item = this.item(itemId);
133
+ const bal = item ? this.balance(item.currency)?.balance : null;
134
+ return !!item && typeof bal === "number" && bal >= item.price * quantity;
135
+ }
136
+ /**
137
+ * Buy an item. Safe to retry: one `clientRequestId` per tap, reused if the network drops,
138
+ * so the player is charged once.
139
+ */
140
+ async buyItem(itemId, options = {}) {
141
+ await this.flushEarnings().catch(() => void 0);
142
+ const clientRequestId = newEventId();
143
+ const body = { clientRequestId, quantity: options.quantity ?? 1 };
144
+ let result;
145
+ try {
146
+ result = await this.request("POST", `/items/${encodeURIComponent(itemId)}/buy`, body);
147
+ } catch (err) {
148
+ if (err instanceof InvoGameError && err.status === 0) {
149
+ result = await this.request("POST", `/items/${encodeURIComponent(itemId)}/buy`, body);
150
+ } else {
151
+ throw err;
152
+ }
153
+ }
154
+ this.setWallet(result.wallet);
155
+ this.emit("item", result);
156
+ return result;
157
+ }
158
+ /**
159
+ * Buy premium currency with real money through INVO's hosted checkout.
160
+ *
161
+ * Call it directly from a click handler: the checkout window is opened before anything
162
+ * else so the browser does not block it. If popups are blocked it falls back to a full-page
163
+ * redirect, and {@link init} resumes the purchase when the player comes back.
164
+ *
165
+ * Resolves when INVO's signed webhook has credited the purchase (or it failed, was
166
+ * cancelled, or timed out). The wallet refreshes itself.
167
+ */
168
+ buyPremium(packId, options = {}) {
169
+ const mode = options.mode ?? "popup";
170
+ let popup = null;
171
+ if (mode === "popup" && typeof window !== "undefined") {
172
+ popup = window.open("", "invo_checkout", "width=480,height=760");
173
+ if (popup) {
174
+ try {
175
+ popup.document.title = "INVO secure checkout";
176
+ popup.document.body.style.cssText = "background:#121418;color:#E9ECF2;font:16px system-ui;display:grid;place-items:center;height:100vh;margin:0";
177
+ popup.document.body.textContent = "Opening secure checkout\u2026";
178
+ } catch {
179
+ }
180
+ }
181
+ }
182
+ return (async () => {
183
+ let checkout;
184
+ try {
185
+ checkout = await this.request("POST", "/checkout", { packId });
186
+ } catch (err) {
187
+ popup?.close();
188
+ throw err;
189
+ }
190
+ if (popup && !popup.closed) {
191
+ popup.location.href = checkout.checkoutUrl;
192
+ } else {
193
+ sessionStorageSafe()?.setItem("invo.game.pendingPurchase", JSON.stringify({ ref: checkout.purchaseRef, packId }));
194
+ window.location.assign(checkout.checkoutUrl);
195
+ return { purchaseRef: checkout.purchaseRef, packId, status: "pending", credited: null };
196
+ }
197
+ return this.waitForPurchase(checkout.purchaseRef, packId, popup);
198
+ })();
199
+ }
200
+ /** Poll a checkout until the server reports the webhook result. */
201
+ async waitForPurchase(purchaseRef, packId, popup) {
202
+ const started = Date.now();
203
+ let closedAt = null;
204
+ for (; ; ) {
205
+ await sleep(this.pollMs);
206
+ let p = null;
207
+ try {
208
+ p = await this.request("GET", `/purchases/${encodeURIComponent(purchaseRef)}`);
209
+ } catch {
210
+ }
211
+ if (p && p.status !== "pending") {
212
+ if (popup && !popup.closed) popup.close();
213
+ await this.refresh().catch(() => void 0);
214
+ const update = { purchaseRef, packId, status: p.status, credited: p.credited };
215
+ this.emit("purchase", update);
216
+ return update;
217
+ }
218
+ if (popup && popup.closed && closedAt === null) closedAt = Date.now();
219
+ if (closedAt !== null && Date.now() - closedAt > 2e4) {
220
+ const update = { purchaseRef, packId, status: "cancelled", credited: null };
221
+ this.emit("purchase", update);
222
+ return update;
223
+ }
224
+ if (Date.now() - started > this.purchaseTimeoutMs) {
225
+ const update = { purchaseRef, packId, status: "timeout", credited: null };
226
+ this.emit("purchase", update);
227
+ return update;
228
+ }
229
+ }
230
+ }
231
+ /**
232
+ * Credit soft currency the player earned. Calls are batched; the balance updates when the
233
+ * server answers. The server rate-limits earnings, so a real game should compute rewards on
234
+ * its server for anything valuable; this is for casual play loops.
235
+ */
236
+ earn(amount, reason = "earned in play") {
237
+ if (!this.token || !Number.isFinite(amount) || amount <= 0) return;
238
+ this.pendingEarn += Math.floor(amount);
239
+ this.pendingEarnReason = reason;
240
+ if (!this.earnTimer) this.earnTimer = setTimeout(() => void this.flushEarnings(), this.earnFlushMs);
241
+ }
242
+ /** Send batched earnings now. */
243
+ async flushEarnings() {
244
+ if (this.earnTimer) {
245
+ clearTimeout(this.earnTimer);
246
+ this.earnTimer = null;
247
+ }
248
+ const amount = this.pendingEarn;
249
+ if (!amount || !this.token) return;
250
+ this.pendingEarn = 0;
251
+ const eventId = newEventId();
252
+ try {
253
+ const res = await this.request("POST", "/earn", { amount, eventId, reason: this.pendingEarnReason });
254
+ if (this.wallet) this.setWallet({ ...this.wallet, soft: res.soft, asOf: (/* @__PURE__ */ new Date()).toISOString() });
255
+ } catch (err) {
256
+ if (err instanceof InvoGameError) this.emit("error", err);
257
+ }
258
+ }
259
+ /** Report a loyalty event (sessions, milestones, registered custom events) through the server. */
260
+ async reportEvent(eventType, payload = {}) {
261
+ if (!this.token) return;
262
+ await this.request("POST", "/events", { eventType, payload, eventId: newEventId() });
263
+ }
264
+ /** The player's loyalty cards. `available: false` when the game has no loyalty program. */
265
+ async rewards() {
266
+ return this.request("GET", "/rewards");
267
+ }
268
+ // ------------------------------------------------------------------ internals
269
+ setWallet(wallet) {
270
+ this.wallet = wallet;
271
+ this.emit("wallet", wallet);
272
+ }
273
+ readStoredPlayer() {
274
+ try {
275
+ const raw = this.storage?.getItem(`${this.storageKey}.player`);
276
+ return raw ? JSON.parse(raw) : null;
277
+ } catch {
278
+ return null;
279
+ }
280
+ }
281
+ clearSession() {
282
+ this.token = null;
283
+ this.player = null;
284
+ this.wallet = null;
285
+ this.storage?.removeItem(this.storageKey);
286
+ this.storage?.removeItem(`${this.storageKey}.player`);
287
+ this.emit("session", null);
288
+ }
289
+ resumeReturningCheckout() {
290
+ if (typeof window === "undefined" || !this.token) return;
291
+ const url = new URL(window.location.href);
292
+ const ref = url.searchParams.get("invo_purchase");
293
+ const pending = sessionStorageSafe()?.getItem("invo.game.pendingPurchase");
294
+ const saved = pending ? JSON.parse(pending) : null;
295
+ if (!ref && !saved) return;
296
+ sessionStorageSafe()?.removeItem("invo.game.pendingPurchase");
297
+ url.searchParams.delete("invo_purchase");
298
+ url.searchParams.delete("invo_status");
299
+ window.history.replaceState(null, "", url.toString());
300
+ const purchaseRef = ref ?? saved.ref;
301
+ void this.waitForPurchase(purchaseRef, saved?.packId ?? "", null).catch(() => void 0);
302
+ }
303
+ async request(method, path, body) {
304
+ const headers = { accept: "application/json" };
305
+ if (body !== void 0) headers["content-type"] = "application/json";
306
+ if (this.token) headers["authorization"] = `Bearer ${this.token}`;
307
+ let res;
308
+ try {
309
+ res = await this.fetchImpl(`${this.base}${path}`, { method, headers, body: body === void 0 ? void 0 : JSON.stringify(body) });
310
+ } catch {
311
+ throw new InvoGameError("NETWORK", "Can't reach the game server. Check your connection.", 0);
312
+ }
313
+ const text = await res.text();
314
+ let parsed = void 0;
315
+ try {
316
+ parsed = text ? JSON.parse(text) : void 0;
317
+ } catch {
318
+ }
319
+ if (!res.ok) {
320
+ const e = parsed?.error;
321
+ const err = new InvoGameError(e?.code ?? "HTTP_" + res.status, e?.message ?? `Request failed (${res.status}).`, res.status);
322
+ if (res.status === 401 && path !== "/session") this.clearSession();
323
+ if (err.code === "INVO_SETUP_REQUIRED") {
324
+ this.setupRequired = true;
325
+ this.emit("setup", { required: true, missing: this.missingSecrets });
326
+ }
327
+ throw err;
328
+ }
329
+ return parsed;
330
+ }
331
+ };
332
+ function sleep(ms) {
333
+ return new Promise((r) => setTimeout(r, ms));
334
+ }
335
+ function safeLocalStorage() {
336
+ try {
337
+ return typeof localStorage === "undefined" ? null : localStorage;
338
+ } catch {
339
+ return null;
340
+ }
341
+ }
342
+ function sessionStorageSafe() {
343
+ try {
344
+ return typeof sessionStorage === "undefined" ? null : sessionStorage;
345
+ } catch {
346
+ return null;
347
+ }
348
+ }
349
+
350
+ // src/game/ui.ts
351
+ var STYLE_ID = "invo-ui-styles";
352
+ var CONSOLE_URL = { sandbox: "https://dev.console.invo.network", production: "https://console.invo.network" };
353
+ var stroke = (d, size = 18) => `<svg viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${d}</svg>`;
354
+ var ICONS = {
355
+ plus: stroke('<path d="M12 5v14M5 12h14"/>', 14),
356
+ close: stroke('<path d="M6 6l12 12M18 6L6 18"/>', 16),
357
+ bag: stroke('<path d="M6 7h12l1 13H5L6 7z"/><path d="M9 7a3 3 0 0 1 6 0"/>', 16),
358
+ user: stroke('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>', 16),
359
+ mail: stroke('<rect x="3" y="5" width="18" height="14" rx="3"/><path d="M3 8l9 6 9-6"/>', 16),
360
+ phone: stroke('<rect x="7" y="2" width="10" height="20" rx="3"/><path d="M11 18h2"/>', 16),
361
+ lock: stroke('<rect x="5" y="11" width="14" height="10" rx="2.5"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>', 14),
362
+ check: stroke('<path d="M5 12.5l4.5 4.5L19 7.5"/>', 14),
363
+ info: stroke('<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>', 14),
364
+ alert: stroke('<path d="M12 3l10 18H2L12 3z"/><path d="M12 10v4M12 17h.01"/>', 14),
365
+ copy: stroke('<rect x="9" y="9" width="12" height="12" rx="2.5"/><path d="M5 15V5a2 2 0 0 1 2-2h8"/>', 13),
366
+ external: stroke('<path d="M14 4h6v6M20 4l-9 9"/><path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/>', 13)
367
+ };
368
+ var svgId = 0;
369
+ function gemSvg(size) {
370
+ const id = `invo-gem-${++svgId}`;
371
+ return `<svg viewBox="0 0 24 24" width="${size}" height="${size}" aria-hidden="true"><defs><linearGradient id="${id}" x1="0" y1="0" x2="1" y2="1"><stop offset="0" style="stop-color:color-mix(in srgb,var(--invo-gold) 45%,#fff)"/><stop offset=".5" style="stop-color:var(--invo-gold)"/><stop offset="1" style="stop-color:color-mix(in srgb,var(--invo-gold) 65%,#000)"/></linearGradient></defs><path d="M7 3.5h10l4.5 6L12 21.5 2.5 9.5z" fill="url(#${id})"/><path d="M2.5 9.5h19M7 3.5l5 6 5-6M12 9.5v12" stroke="#000" stroke-opacity=".22" stroke-width="1" fill="none"/><path d="M7 3.5h10l-1.5 2H8.5z" fill="#fff" fill-opacity=".35"/></svg>`;
372
+ }
373
+ function coinSvg(size) {
374
+ const id = `invo-coin-${++svgId}`;
375
+ return `<svg viewBox="0 0 24 24" width="${size}" height="${size}" aria-hidden="true"><defs><radialGradient id="${id}" cx=".35" cy=".3" r=".8"><stop offset="0" style="stop-color:color-mix(in srgb,var(--invo-teal) 40%,#fff)"/><stop offset=".55" style="stop-color:var(--invo-teal)"/><stop offset="1" style="stop-color:color-mix(in srgb,var(--invo-teal) 55%,#000)"/></radialGradient></defs><circle cx="12" cy="12" r="10" fill="url(#${id})"/><circle cx="12" cy="12" r="6.5" fill="none" stroke="#000" stroke-opacity=".2" stroke-width="1.5"/><circle cx="12" cy="12" r="6.5" fill="none" stroke="#fff" stroke-opacity=".25" stroke-width=".8" transform="translate(-.4 -.4)"/></svg>`;
376
+ }
377
+ var CSS = `
378
+ .invo-ui{--invo-bg:#0E1014;--invo-surface:#20242C;--invo-gold:#F4C04A;--invo-teal:#3FD0C9;--invo-text:#EEF1F6;--invo-muted:#98A1B3;--invo-danger:#FF7A7A;--invo-line:rgba(255,255,255,.08);--invo-line-2:rgba(255,255,255,.14);--invo-font:Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;--invo-ease:cubic-bezier(.2,.8,.2,1);position:absolute;inset:0;pointer-events:none;font-family:var(--invo-font);color:var(--invo-text);z-index:50;font-size:14px;line-height:1.4;letter-spacing:-.005em;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
379
+ .invo-ui *{box-sizing:border-box}.invo-ui svg{display:block;flex:none}.invo-ui button{font-family:inherit}
380
+ .invo-ui :focus-visible{outline:2px solid var(--invo-teal);outline-offset:2px}
381
+
382
+ .invo-hud{position:absolute;top:max(12px,env(safe-area-inset-top));display:flex;align-items:center;gap:6px;padding:5px;border-radius:999px;pointer-events:auto;max-width:calc(100% - 24px);background:linear-gradient(180deg,rgba(32,36,44,.84),rgba(16,18,23,.84));border:1px solid var(--invo-line);box-shadow:inset 0 1px 0 rgba(255,255,255,.06),0 12px 32px -8px rgba(0,0,0,.55);backdrop-filter:blur(16px) saturate(150%);-webkit-backdrop-filter:blur(16px) saturate(150%)}
383
+ .invo-hud.right{right:12px}.invo-hud.left{left:12px}
384
+ .invo-badge{display:inline-flex;align-items:center;gap:7px;height:26px;padding:0 10px;border-radius:999px;font:700 10px/1 var(--invo-font);letter-spacing:.14em;text-transform:uppercase;color:var(--invo-teal);background:rgba(63,208,201,.09);border:1px solid rgba(63,208,201,.26);white-space:nowrap}
385
+ .invo-badge[hidden]{display:none}
386
+ .invo-dot{width:6px;height:6px;border-radius:50%;background:currentColor;flex:none;animation:invo-ping 2.4s var(--invo-ease) infinite}
387
+ .invo-pill{position:relative;display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 13px 0 9px;border-radius:999px;background:rgba(255,255,255,.035);border:1px solid var(--invo-line);font-weight:650;font-variant-numeric:tabular-nums;white-space:nowrap}
388
+ .invo-pill.premium{padding-right:4px}
389
+ .invo-cur{filter:drop-shadow(0 2px 6px rgba(0,0,0,.4))}
390
+ .invo-amt{display:inline-block;min-width:1ch}
391
+ .invo-amt.bump{animation:invo-bump .55s var(--invo-ease)}
392
+ .invo-pill.premium .invo-amt.bump{color:var(--invo-gold)}.invo-pill.soft .invo-amt.bump{color:var(--invo-teal)}
393
+ .invo-delta{position:absolute;left:50%;top:calc(100% + 4px);font:800 12px var(--invo-font);pointer-events:none;white-space:nowrap;animation:invo-delta 1.3s var(--invo-ease) forwards}
394
+ .invo-pill.premium .invo-delta{color:var(--invo-gold)}.invo-pill.soft .invo-delta{color:var(--invo-teal)}
395
+ .invo-plus{display:grid;place-items:center;width:26px;height:26px;padding:0;border:0;border-radius:50%;cursor:pointer;color:#1A1405;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 3px 10px -2px rgba(244,192,74,.55);transition:transform .18s var(--invo-ease),box-shadow .18s}
396
+ .invo-plus:hover{transform:scale(1.1) rotate(90deg);box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 5px 16px -2px rgba(244,192,74,.7)}
397
+ .invo-sep{width:1px;height:20px;background:var(--invo-line-2);margin:0 2px}
398
+
399
+ .invo-btn{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:8px;height:42px;padding:0 18px;border-radius:12px;border:1px solid var(--invo-line-2);background:rgba(255,255,255,.045);color:var(--invo-text);font:650 14px var(--invo-font);letter-spacing:-.005em;cursor:pointer;white-space:nowrap;transition:transform .14s var(--invo-ease),box-shadow .2s,background .2s,border-color .2s,filter .2s}
400
+ .invo-btn:hover{background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.22)}
401
+ .invo-btn:active{transform:translateY(1px) scale(.985)}
402
+ .invo-btn.gold{border:0;color:#1A1405;background:linear-gradient(180deg,#FFDB82 0%,var(--invo-gold) 52%,color-mix(in srgb,var(--invo-gold) 82%,#8a5a00) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.6),inset 0 -1px 0 rgba(0,0,0,.14),0 8px 20px -8px rgba(244,192,74,.7)}
403
+ .invo-btn.teal{border:0;color:#04201E;background:linear-gradient(180deg,color-mix(in srgb,var(--invo-teal) 60%,#fff) 0%,var(--invo-teal) 52%,color-mix(in srgb,var(--invo-teal) 80%,#00403c) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.55),inset 0 -1px 0 rgba(0,0,0,.14),0 8px 20px -8px rgba(63,208,201,.65)}
404
+ .invo-btn.gold:hover,.invo-btn.teal:hover{filter:brightness(1.06) saturate(1.05)}
405
+ .invo-btn.block{width:100%;height:48px;border-radius:14px;font-size:15px}
406
+ .invo-btn.sm{height:36px;padding:0 14px;border-radius:10px;font-size:13px}
407
+ .invo-btn[disabled]{cursor:not-allowed;opacity:.45;filter:none;box-shadow:none;transform:none}
408
+ .invo-btn.done,.invo-btn.done[disabled]{opacity:1;color:var(--invo-teal);background:rgba(63,208,201,.08);border:1px solid rgba(63,208,201,.28);box-shadow:none}
409
+ .invo-btn.done::before{content:"";width:13px;height:13px;background:currentColor;-webkit-mask:var(--invo-check) center/contain no-repeat;mask:var(--invo-check) center/contain no-repeat}
410
+ .invo-ui{--invo-check:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E")}
411
+ .invo-btn.busy{color:transparent!important}
412
+ .invo-btn.busy::after{content:"";position:absolute;width:16px;height:16px;border-radius:50%;border:2px solid rgba(255,255,255,.25);border-top-color:#fff;animation:invo-spin .7s linear infinite}
413
+ .invo-btn.gold.busy::after{border-color:rgba(26,20,5,.2);border-top-color:#1A1405}.invo-btn.teal.busy::after{border-color:rgba(4,32,30,.2);border-top-color:#04201E}
414
+ .invo-hbtn{height:34px;padding:0 13px;border-radius:999px;border-color:transparent;background:transparent;font-size:13.5px;gap:7px}
415
+ .invo-hbtn:hover{background:rgba(255,255,255,.07);border-color:var(--invo-line)}
416
+ .invo-account[data-initial]::before{content:attr(data-initial);display:grid;place-items:center;width:24px;height:24px;margin-left:-7px;border-radius:50%;color:#04201E;font:800 11px var(--invo-font);background:linear-gradient(140deg,color-mix(in srgb,var(--invo-teal) 55%,#fff),var(--invo-teal));box-shadow:0 0 0 2px rgba(63,208,201,.18)}
417
+
418
+ .invo-overlay{position:absolute;inset:0;display:grid;place-items:center;padding:20px;pointer-events:auto;background:radial-gradient(120% 90% at 50% 0%,rgba(10,12,16,.55),rgba(4,5,8,.86));backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);animation:invo-fade .22s ease-out}
419
+ .invo-dialog{position:relative;width:min(660px,100%);max-height:min(760px,calc(100% - 8px));overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.15) transparent;padding:26px;border-radius:26px;background:radial-gradient(120% 60% at 50% -10%,rgba(63,208,201,.07),transparent 60%),linear-gradient(180deg,rgba(33,37,45,.98),rgba(19,21,26,.99));border:1px solid var(--invo-line);box-shadow:0 50px 120px -30px rgba(0,0,0,.8),0 0 0 1px rgba(0,0,0,.45),inset 0 1px 0 rgba(255,255,255,.07);animation:invo-pop .34s var(--invo-ease)}
420
+ .invo-dialog::before{content:"";position:absolute;left:28px;right:28px;top:0;height:1px;background:linear-gradient(90deg,transparent,var(--invo-gold) 30%,var(--invo-teal) 70%,transparent);opacity:.75}
421
+ .invo-dialog.narrow{width:min(450px,100%)}
422
+ .invo-dialog:focus{outline:none}
423
+ .invo-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:22px}
424
+ .invo-eyebrow{display:flex;align-items:center;gap:8px;margin:0 0 8px;font:700 11px/1 var(--invo-font);letter-spacing:.16em;text-transform:uppercase;color:var(--invo-teal)}
425
+ .invo-dialog h2{margin:0;font-size:24px;line-height:1.15;font-weight:760;letter-spacing:-.025em}
426
+ .invo-sub{margin:8px 0 0;color:var(--invo-muted);font-size:14px;line-height:1.5;max-width:46ch}
427
+ .invo-x{display:grid;place-items:center;width:38px;height:38px;flex:none;border-radius:50%;border:1px solid var(--invo-line);background:rgba(255,255,255,.03);color:var(--invo-muted);cursor:pointer;transition:transform .25s var(--invo-ease),color .2s,background .2s}
428
+ .invo-x:hover{color:var(--invo-text);background:rgba(255,255,255,.08);transform:rotate(90deg)}
429
+
430
+ .invo-tabs{display:inline-flex;flex-wrap:wrap;gap:4px;padding:4px;margin-bottom:18px;border-radius:13px;background:rgba(0,0,0,.28);border:1px solid var(--invo-line)}
431
+ .invo-tab{height:32px;padding:0 15px;border:0;border-radius:9px;background:transparent;color:var(--invo-muted);font:600 13px var(--invo-font);text-transform:capitalize;cursor:pointer;transition:color .15s,background .2s,box-shadow .2s}
432
+ .invo-tab:hover{color:var(--invo-text)}
433
+ .invo-tab[aria-selected=true]{color:var(--invo-text);background:var(--invo-surface);box-shadow:inset 0 1px 0 rgba(255,255,255,.07),0 4px 14px -4px rgba(0,0,0,.6)}
434
+
435
+ .invo-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(186px,1fr));gap:14px}
436
+ .invo-card{--c:var(--invo-teal);position:relative;display:flex;flex-direction:column;border-radius:20px;overflow:hidden;background:linear-gradient(180deg,rgba(255,255,255,.035),rgba(255,255,255,.01)),var(--invo-surface);border:1px solid var(--invo-line);transition:transform .25s var(--invo-ease),border-color .25s,box-shadow .25s;animation:invo-rise .4s var(--invo-ease) backwards}
437
+ .invo-card:nth-child(2){animation-delay:.04s}.invo-card:nth-child(3){animation-delay:.08s}.invo-card:nth-child(4){animation-delay:.12s}.invo-card:nth-child(n+5){animation-delay:.16s}
438
+ .invo-card:hover{transform:translateY(-4px);border-color:color-mix(in srgb,var(--c) 45%,transparent);box-shadow:0 22px 44px -22px color-mix(in srgb,var(--c) 70%,transparent)}
439
+ .invo-card.owned{border-color:color-mix(in srgb,var(--c) 30%,transparent)}
440
+ .invo-art{position:relative;height:136px;display:grid;place-items:center;overflow:hidden;background:radial-gradient(60% 80% at 50% 38%,color-mix(in srgb,var(--c) 34%,transparent),transparent 72%);border-bottom:1px solid var(--invo-line)}
441
+ .invo-art::before{content:"";position:absolute;inset:0;background-image:linear-gradient(rgba(255,255,255,.04) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.04) 1px,transparent 1px);background-size:18px 18px;-webkit-mask-image:radial-gradient(circle at 50% 42%,#000 10%,transparent 70%);mask-image:radial-gradient(circle at 50% 42%,#000 10%,transparent 70%)}
442
+ .invo-glyph{position:relative;display:grid;place-items:center;width:74px;height:74px;border-radius:24px;font-size:34px;line-height:1;color:rgba(10,12,16,.82);background:linear-gradient(150deg,color-mix(in srgb,var(--c) 55%,#fff) 0%,var(--c) 50%,color-mix(in srgb,var(--c) 65%,#000) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.65),inset 0 -3px 0 rgba(0,0,0,.14),0 16px 34px -8px color-mix(in srgb,var(--c) 75%,transparent);transform:rotate(-6deg);transition:transform .4s var(--invo-ease)}
443
+ .invo-card:hover .invo-glyph{transform:rotate(0) scale(1.07)}
444
+ .invo-chip{position:absolute;top:10px;display:inline-flex;align-items:center;gap:5px;height:22px;padding:0 9px;border-radius:999px;font:700 10px/1 var(--invo-font);letter-spacing:.1em;text-transform:uppercase}
445
+ .invo-chip.cat{left:10px;color:var(--invo-muted);background:rgba(0,0,0,.4);border:1px solid var(--invo-line);backdrop-filter:blur(6px)}
446
+ .invo-chip.own{right:10px;color:#04201E;background:var(--invo-teal);box-shadow:0 4px 12px -2px rgba(63,208,201,.55)}
447
+ .invo-cbody{display:flex;flex-direction:column;gap:6px;padding:14px 16px 0;flex:1}
448
+ .invo-card h3{margin:0;font-size:15.5px;font-weight:720;letter-spacing:-.015em}
449
+ .invo-card p{margin:0;color:var(--invo-muted);font-size:12.5px;line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
450
+ .invo-pips{display:flex;gap:4px;margin-top:6px}
451
+ .invo-pip{flex:1;height:4px;border-radius:3px;background:rgba(255,255,255,.08);transition:background .3s}
452
+ .invo-pip.on{background:var(--c);box-shadow:0 0 10px -1px color-mix(in srgb,var(--c) 80%,transparent)}
453
+ .invo-cfoot{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:14px 16px 16px}
454
+ .invo-price{display:inline-flex;align-items:center;gap:7px;font-size:17px;font-weight:780;letter-spacing:-.01em;font-variant-numeric:tabular-nums}
455
+ .invo-empty{padding:40px 16px;text-align:center;color:var(--invo-muted);border:1px dashed var(--invo-line-2);border-radius:18px}
456
+
457
+ .invo-packs{display:grid;grid-template-columns:repeat(auto-fit,minmax(176px,1fr));gap:14px}
458
+ .invo-pack{position:relative;display:flex;flex-direction:column;align-items:center;text-align:center;padding:30px 16px 16px;border-radius:20px;background:radial-gradient(90% 70% at 50% 0%,rgba(244,192,74,.13),transparent 70%),var(--invo-surface);border:1px solid var(--invo-line);transition:transform .25s var(--invo-ease),border-color .25s,box-shadow .25s;animation:invo-rise .4s var(--invo-ease) backwards}
459
+ .invo-pack:nth-child(2){animation-delay:.05s}.invo-pack:nth-child(3){animation-delay:.1s}
460
+ .invo-pack:hover{transform:translateY(-4px);border-color:rgba(244,192,74,.45);box-shadow:0 22px 44px -22px rgba(244,192,74,.6)}
461
+ .invo-pack.best{border-color:rgba(244,192,74,.5);background:radial-gradient(90% 80% at 50% 0%,rgba(244,192,74,.22),transparent 70%),var(--invo-surface)}
462
+ .invo-ribbon{position:absolute;top:-1px;left:50%;transform:translateX(-50%);padding:6px 12px;border-radius:0 0 10px 10px;font:800 10px/1 var(--invo-font);letter-spacing:.14em;text-transform:uppercase;color:#1A1405;white-space:nowrap;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:0 6px 16px -6px rgba(244,192,74,.8)}
463
+ .invo-stack{display:flex;align-items:flex-end;justify-content:center;height:62px;margin-bottom:12px;filter:drop-shadow(0 12px 18px rgba(244,192,74,.32))}
464
+ .invo-stack svg+svg{margin-left:-16px}.invo-stack svg:nth-child(2){transform:translateY(-10px) scale(1.12)}
465
+ .invo-pamt{font-size:30px;font-weight:820;line-height:1;letter-spacing:-.03em;color:var(--invo-gold);font-variant-numeric:tabular-nums}
466
+ .invo-pname{margin:6px 0 16px;color:var(--invo-muted);font-size:13px}
467
+ .invo-pack .invo-btn{width:100%}
468
+
469
+ .invo-status{display:flex;align-items:center;gap:10px;margin-top:16px;padding:12px 14px;border-radius:14px;font-size:13px;color:var(--invo-muted);background:rgba(255,255,255,.03);border:1px solid var(--invo-line)}
470
+ .invo-status:empty{display:none}
471
+ .invo-spinner{width:14px;height:14px;flex:none;border-radius:50%;border:2px solid rgba(255,255,255,.14);border-top-color:var(--invo-teal);animation:invo-spin .8s linear infinite}
472
+ .invo-secure{display:flex;align-items:center;justify-content:center;gap:7px;margin:18px 0 0;color:var(--invo-muted);font-size:12px}
473
+ .invo-secure svg{color:var(--invo-teal)}
474
+
475
+ .invo-field{display:flex;flex-direction:column;gap:8px;margin-bottom:14px}
476
+ .invo-field label{display:flex;justify-content:space-between;align-items:baseline;font-size:12.5px;font-weight:650;color:var(--invo-text)}
477
+ .invo-field label small{font-size:12px;font-weight:500;color:var(--invo-muted)}
478
+ .invo-inwrap{position:relative}
479
+ .invo-inwrap svg{position:absolute;left:15px;top:50%;transform:translateY(-50%);color:var(--invo-muted);pointer-events:none;transition:color .15s}
480
+ .invo-inwrap:focus-within svg{color:var(--invo-teal)}
481
+ .invo-input{width:100%;height:50px;padding:0 14px 0 44px;border-radius:14px;border:1px solid var(--invo-line-2);background:rgba(0,0,0,.3);color:var(--invo-text);font:500 15px var(--invo-font);transition:border-color .15s,box-shadow .2s,background .2s}
482
+ .invo-input::placeholder{color:rgba(152,161,179,.55)}
483
+ .invo-input:focus{outline:none;border-color:var(--invo-teal);background:rgba(0,0,0,.42);box-shadow:0 0 0 4px rgba(63,208,201,.14)}
484
+ .invo-error{display:flex;align-items:center;gap:8px;margin:2px 0 14px;padding:10px 12px;border-radius:12px;font-size:13px;color:var(--invo-danger);background:rgba(255,122,122,.08);border:1px solid rgba(255,122,122,.24)}
485
+ .invo-error:empty{display:none}
486
+ .invo-callout{display:flex;align-items:flex-start;gap:10px;margin-top:16px;padding:12px 14px;border-radius:14px;font-size:12.5px;line-height:1.5;color:color-mix(in srgb,var(--invo-teal) 45%,#fff);background:rgba(63,208,201,.06);border:1px solid rgba(63,208,201,.2)}
487
+ .invo-callout svg{margin-top:2px;color:var(--invo-teal)}
488
+
489
+ .invo-steps{display:flex;flex-direction:column;gap:10px;margin:0;padding:0;list-style:none;counter-reset:invo-step}
490
+ .invo-step{display:grid;grid-template-columns:34px 1fr;gap:14px;padding:16px;border-radius:18px;background:rgba(255,255,255,.025);border:1px solid var(--invo-line);animation:invo-rise .4s var(--invo-ease) backwards}
491
+ .invo-step:nth-child(2){animation-delay:.05s}.invo-step:nth-child(3){animation-delay:.1s}
492
+ .invo-step::before{counter-increment:invo-step;content:counter(invo-step);display:grid;place-items:center;width:34px;height:34px;border-radius:11px;font:800 14px var(--invo-font);color:#1A1405;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 6px 14px -6px rgba(244,192,74,.7)}
493
+ .invo-step h4{margin:3px 0 4px;font-size:15px;font-weight:700;letter-spacing:-.01em}
494
+ .invo-step p{margin:0;color:var(--invo-muted);font-size:13px;line-height:1.5}
495
+ .invo-keys{display:flex;flex-direction:column;gap:8px;margin-top:12px}
496
+ .invo-key{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:6px 6px 6px 12px;border-radius:11px;background:rgba(0,0,0,.36);border:1px solid var(--invo-line)}
497
+ .invo-code{font:600 12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--invo-gold);overflow:hidden;text-overflow:ellipsis}
498
+ .invo-copy{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;flex:none;border-radius:8px;border:1px solid var(--invo-line-2);background:rgba(255,255,255,.03);color:var(--invo-muted);font:600 12px var(--invo-font);cursor:pointer;transition:color .15s,border-color .15s}
499
+ .invo-copy:hover{color:var(--invo-text)}.invo-copy.ok{color:var(--invo-teal);border-color:rgba(63,208,201,.4)}
500
+ .invo-link{display:inline-flex;align-items:center;gap:6px;margin-top:10px;color:var(--invo-teal);font-weight:650;font-size:13px;text-decoration:none}
501
+ .invo-link:hover{text-decoration:underline;text-underline-offset:3px}
502
+ .invo-live{display:flex;align-items:center;gap:10px;margin-top:16px;padding:13px 15px;border-radius:14px;font-size:13px;color:var(--invo-muted);border:1px dashed var(--invo-line-2)}
503
+ .invo-live .invo-dot{width:8px;height:8px;color:var(--invo-gold)}
504
+ .invo-live.ok{color:var(--invo-teal);border-style:solid;border-color:rgba(63,208,201,.35);background:rgba(63,208,201,.06)}
505
+ .invo-live.ok .invo-dot{color:var(--invo-teal);animation:none}
506
+
507
+ .invo-toasts{position:absolute;left:50%;bottom:max(20px,env(safe-area-inset-bottom));transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:8px;width:min(440px,calc(100% - 24px));pointer-events:none}
508
+ .invo-toast{display:flex;align-items:center;gap:11px;max-width:100%;padding:10px 16px 10px 10px;border-radius:16px;font-weight:620;font-size:13.5px;background:rgba(26,29,36,.94);border:1px solid var(--invo-line-2);box-shadow:0 20px 44px -14px rgba(0,0,0,.7);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);animation:invo-toast .38s var(--invo-ease)}
509
+ .invo-ti{display:grid;place-items:center;width:26px;height:26px;flex:none;border-radius:9px;color:var(--invo-muted);background:rgba(255,255,255,.06)}
510
+ .invo-toast.success .invo-ti{color:var(--invo-teal);background:rgba(63,208,201,.14)}
511
+ .invo-toast.error .invo-ti{color:var(--invo-danger);background:rgba(255,122,122,.14)}
512
+ .invo-toast.out{animation:invo-toast-out .26s ease-in forwards}
513
+
514
+ @keyframes invo-fade{from{opacity:0}to{opacity:1}}
515
+ @keyframes invo-pop{from{opacity:0;transform:translateY(16px) scale(.97)}to{opacity:1;transform:none}}
516
+ @keyframes invo-sheet{from{transform:translateY(100%)}to{transform:none}}
517
+ @keyframes invo-rise{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
518
+ @keyframes invo-spin{to{transform:rotate(360deg)}}
519
+ @keyframes invo-ping{0%{box-shadow:0 0 0 0 currentColor}70%,100%{box-shadow:0 0 0 6px transparent}}
520
+ @keyframes invo-bump{0%{transform:none}30%{transform:scale(1.22)}100%{transform:none}}
521
+ @keyframes invo-delta{0%{opacity:0;transform:translate(-50%,-4px)}15%{opacity:1;transform:translate(-50%,0)}100%{opacity:0;transform:translate(-50%,10px)}}
522
+ @keyframes invo-toast{from{opacity:0;transform:translateY(12px) scale(.97)}to{opacity:1;transform:none}}
523
+ @keyframes invo-toast-out{to{opacity:0;transform:translateY(8px) scale(.98)}}
524
+
525
+ @media (max-width:560px){
526
+ .invo-hbtn .invo-label{display:none}.invo-hbtn{padding:0 10px}.invo-account[data-initial]::before{margin:0 -3px}
527
+ .invo-pill{padding:0 10px 0 8px;gap:6px}.invo-hud .invo-badge .invo-label{display:none}.invo-hud .invo-badge{padding:0 8px}
528
+ .invo-overlay{place-items:end stretch;padding:0}
529
+ .invo-dialog,.invo-dialog.narrow{width:100%;max-height:90%;border-radius:26px 26px 0 0;padding:22px 18px calc(22px + env(safe-area-inset-bottom));animation:invo-sheet .38s var(--invo-ease)}
530
+ .invo-dialog h2{font-size:21px}
531
+ .invo-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
532
+ .invo-art{height:124px}.invo-glyph{width:56px;height:56px;font-size:26px;border-radius:18px;margin-top:10px}.invo-chip.cat{display:none}
533
+ .invo-cfoot{flex-direction:column;align-items:stretch;gap:10px}.invo-cfoot .invo-btn{width:100%}
534
+ }
535
+ @media (prefers-reduced-motion:reduce){.invo-ui *,.invo-ui *::before,.invo-ui *::after{animation:none!important;transition:none!important}}
536
+ `;
537
+ function el(tag, cls, text) {
538
+ const node = document.createElement(tag);
539
+ if (cls) node.className = cls;
540
+ if (text !== void 0) node.textContent = text;
541
+ return node;
542
+ }
543
+ function svg(markup, cls = "invo-ico") {
544
+ const span = el("span", cls);
545
+ span.innerHTML = markup;
546
+ span.style.display = "inline-grid";
547
+ return span;
548
+ }
549
+ function formatAmount(n) {
550
+ if (n === null || n === void 0) return "\u2014";
551
+ return Math.round(n).toLocaleString();
552
+ }
553
+ function initialOf(name) {
554
+ return (name.trim()[0] ?? "?").toUpperCase();
555
+ }
556
+ function mountInvoUI(container, economy, options = {}) {
557
+ if (!document.getElementById(STYLE_ID)) {
558
+ const style = el("style");
559
+ style.id = STYLE_ID;
560
+ style.textContent = CSS;
561
+ document.head.appendChild(style);
562
+ }
563
+ if (getComputedStyle(container).position === "static") container.style.position = "relative";
564
+ const root = el("div", "invo-ui");
565
+ const t = options.theme ?? {};
566
+ const vars = [
567
+ ["--invo-bg", t.background],
568
+ ["--invo-surface", t.surface],
569
+ ["--invo-gold", t.gold],
570
+ ["--invo-teal", t.teal],
571
+ ["--invo-text", t.text],
572
+ ["--invo-muted", t.muted],
573
+ ["--invo-font", t.font]
574
+ ];
575
+ for (const [k, v] of vars) if (v) root.style.setProperty(k, v);
576
+ container.appendChild(root);
577
+ const premiumName = () => economy.catalog?.premium.name ?? "Gems";
578
+ const softName = () => economy.catalog?.soft.name ?? "Coins";
579
+ const hud = el("div", `invo-hud ${options.hudPosition === "top-left" ? "left" : "right"}`);
580
+ const sandboxBadge = el("span", "invo-badge");
581
+ sandboxBadge.append(el("span", "invo-dot"), el("span", "invo-label", "Sandbox"));
582
+ sandboxBadge.title = "INVO sandbox: test money only.";
583
+ sandboxBadge.hidden = true;
584
+ const premiumPill = el("div", "invo-pill premium");
585
+ const premiumAmt = el("span", "invo-amt", "\u2014");
586
+ const plus = el("button", "invo-plus");
587
+ plus.type = "button";
588
+ plus.append(svg(ICONS.plus));
589
+ premiumPill.append(svg(gemSvg(18), "invo-cur"), premiumAmt, plus);
590
+ const softPill = el("div", "invo-pill soft");
591
+ const softAmt = el("span", "invo-amt", "\u2014");
592
+ softPill.append(svg(coinSvg(18), "invo-cur"), softAmt);
593
+ const shopBtn = el("button", "invo-btn invo-hbtn");
594
+ shopBtn.type = "button";
595
+ shopBtn.append(svg(ICONS.bag), el("span", "invo-label", "Shop"));
596
+ shopBtn.hidden = !!options.hideShopButton;
597
+ const accountBtn = el("button", "invo-btn invo-hbtn invo-account");
598
+ accountBtn.type = "button";
599
+ hud.append(sandboxBadge, premiumPill, softPill, el("span", "invo-sep"), shopBtn, accountBtn);
600
+ root.append(hud);
601
+ const toasts = el("div", "invo-toasts");
602
+ toasts.setAttribute("role", "status");
603
+ toasts.setAttribute("aria-live", "polite");
604
+ root.append(toasts);
605
+ const shown = { premium: null, soft: null };
606
+ function showBalance(kind, pill, amt, value) {
607
+ const next = value ?? null;
608
+ const prev = shown[kind];
609
+ amt.textContent = formatAmount(next);
610
+ shown[kind] = next;
611
+ if (prev === null || next === null || prev === next) return;
612
+ amt.classList.remove("bump");
613
+ void amt.offsetWidth;
614
+ amt.classList.add("bump");
615
+ const delta = el("span", "invo-delta", `${next > prev ? "+" : "\u2212"}${formatAmount(Math.abs(next - prev))}`);
616
+ pill.append(delta);
617
+ setTimeout(() => delta.remove(), 1300);
618
+ }
619
+ function renderHud() {
620
+ const w = economy.wallet;
621
+ showBalance("premium", premiumPill, premiumAmt, economy.player ? w?.premium.balance : null);
622
+ showBalance("soft", softPill, softAmt, economy.player ? w?.soft.balance : null);
623
+ premiumPill.title = premiumName();
624
+ softPill.title = softName();
625
+ plus.setAttribute("aria-label", `Get more ${premiumName()}`);
626
+ sandboxBadge.hidden = !economy.catalog?.sandbox;
627
+ accountBtn.replaceChildren();
628
+ if (economy.player) {
629
+ accountBtn.dataset["initial"] = initialOf(economy.player.name);
630
+ accountBtn.append(el("span", "invo-label", economy.player.name));
631
+ accountBtn.title = `Signed in as ${economy.player.email}. Click to sign out.`;
632
+ } else {
633
+ delete accountBtn.dataset["initial"];
634
+ accountBtn.append(svg(ICONS.user), el("span", "invo-label", "Sign in"));
635
+ accountBtn.title = "Sign in to save progress and buy items.";
636
+ }
637
+ }
638
+ let overlay = null;
639
+ let lastFocus = null;
640
+ let onDialogClose = null;
641
+ function openDialog(spec, build) {
642
+ close();
643
+ lastFocus = document.activeElement;
644
+ overlay = el("div", "invo-overlay");
645
+ const dialog = el("div", `invo-dialog${spec.narrow ? " narrow" : ""}`);
646
+ dialog.setAttribute("role", "dialog");
647
+ dialog.setAttribute("aria-modal", "true");
648
+ dialog.setAttribute("aria-label", spec.title);
649
+ dialog.tabIndex = -1;
650
+ const head = el("div", "invo-head");
651
+ const titles = el("div");
652
+ if (spec.eyebrow) titles.append(el("div", "invo-eyebrow", spec.eyebrow));
653
+ titles.append(el("h2", void 0, spec.title));
654
+ if (spec.subtitle) titles.append(el("p", "invo-sub", spec.subtitle));
655
+ const x = el("button", "invo-x");
656
+ x.type = "button";
657
+ x.setAttribute("aria-label", "Close");
658
+ x.append(svg(ICONS.close));
659
+ x.onclick = () => close();
660
+ head.append(titles, x);
661
+ const body = el("div");
662
+ dialog.append(head, body);
663
+ overlay.append(dialog);
664
+ overlay.addEventListener("pointerdown", (e) => {
665
+ if (e.target === overlay) close();
666
+ });
667
+ root.append(overlay);
668
+ build(body);
669
+ options.onModalChange?.(true);
670
+ (dialog.querySelector("input") ?? dialog).focus({ preventScroll: true });
671
+ }
672
+ function close() {
673
+ if (!overlay) return;
674
+ onDialogClose?.();
675
+ onDialogClose = null;
676
+ overlay.remove();
677
+ overlay = null;
678
+ options.onModalChange?.(false);
679
+ if (lastFocus instanceof HTMLElement) lastFocus.focus({ preventScroll: true });
680
+ }
681
+ function toast(message, tone = "info") {
682
+ const node = el("div", `invo-toast ${tone}`);
683
+ node.append(svg(tone === "success" ? ICONS.check : tone === "error" ? ICONS.alert : ICONS.info, "invo-ti"), el("span", void 0, message));
684
+ toasts.append(node);
685
+ setTimeout(() => {
686
+ node.classList.add("out");
687
+ setTimeout(() => node.remove(), 260);
688
+ }, tone === "error" ? 5e3 : 3200);
689
+ }
690
+ function requireSignIn(then) {
691
+ if (economy.setupRequired) {
692
+ openSetup();
693
+ return false;
694
+ }
695
+ if (!economy.signedIn) {
696
+ openSignIn(then);
697
+ return false;
698
+ }
699
+ return true;
700
+ }
701
+ function openSetup() {
702
+ openDialog(
703
+ {
704
+ title: "Connect INVO",
705
+ eyebrow: "Developer setup",
706
+ subtitle: "Your game already runs. Add your sandbox keys to switch on sign-in, the shop and payments."
707
+ },
708
+ (body) => {
709
+ const steps = el("ol", "invo-steps");
710
+ const step = (title, text, extra) => {
711
+ const li = el("li", "invo-step");
712
+ const content = el("div");
713
+ content.append(el("h4", void 0, title), el("p", void 0, text));
714
+ if (extra) content.append(extra);
715
+ li.append(content);
716
+ steps.append(li);
717
+ };
718
+ const link = el("a", "invo-link");
719
+ link.href = economy.catalog?.sandbox === false ? CONSOLE_URL.production : CONSOLE_URL.sandbox;
720
+ link.target = "_blank";
721
+ link.rel = "noopener noreferrer";
722
+ link.append(document.createTextNode("Open the INVO console"), svg(ICONS.external));
723
+ step(economy.catalog?.sandbox === false ? "Get your production keys" : "Get your sandbox keys", "In the INVO console, open your game's settings and copy the game secret and the webhook signing secret.", link);
724
+ const keys = el("div", "invo-keys");
725
+ for (const name of economy.missingSecrets.length ? economy.missingSecrets : ["INVO_GAME_SECRET", "INVO_WEBHOOK_SECRET"]) {
726
+ const row = el("div", "invo-key");
727
+ const copy = el("button", "invo-copy");
728
+ copy.type = "button";
729
+ copy.append(svg(ICONS.copy), el("span", void 0, "Copy"));
730
+ copy.onclick = async () => {
731
+ try {
732
+ await navigator.clipboard.writeText(name);
733
+ copy.classList.add("ok");
734
+ copy.lastElementChild.textContent = "Copied";
735
+ setTimeout(() => {
736
+ copy.classList.remove("ok");
737
+ copy.lastElementChild.textContent = "Copy";
738
+ }, 1600);
739
+ } catch {
740
+ }
741
+ };
742
+ row.append(el("span", "invo-code", name), copy);
743
+ keys.append(row);
744
+ }
745
+ step("Add them as secrets", "On Replit: Tools \u2192 Secrets. Anywhere else: environment variables. Never put them in your code.", keys);
746
+ step("Restart the server", "Stop and run again. This page notices on its own.");
747
+ body.append(steps);
748
+ const live = el("div", "invo-live");
749
+ const liveText = el("span", void 0, "Waiting for your keys\u2026");
750
+ live.append(el("span", "invo-dot"), liveText);
751
+ body.append(live);
752
+ const timer = setInterval(async () => {
753
+ if (!await economy.checkSetup()) return;
754
+ clearInterval(timer);
755
+ live.classList.add("ok");
756
+ liveText.textContent = "Connected to INVO. You're ready to test.";
757
+ await economy.init().catch(() => void 0);
758
+ renderHud();
759
+ setTimeout(() => {
760
+ if (live.isConnected) {
761
+ close();
762
+ toast("INVO connected", "success");
763
+ }
764
+ }, 1400);
765
+ }, 3e3);
766
+ onDialogClose = () => clearInterval(timer);
767
+ }
768
+ );
769
+ }
770
+ function openSignIn(after) {
771
+ openDialog(
772
+ { title: "Sign in", eyebrow: "Player account", subtitle: "Save your progress and unlock the shop on any device.", narrow: true },
773
+ (body) => {
774
+ const form = el("form");
775
+ form.noValidate = false;
776
+ const field = (label, hint, type, name2, placeholder, autocomplete, icon) => {
777
+ const wrap = el("div", "invo-field");
778
+ const id = `invo-${name2}`;
779
+ const l = el("label");
780
+ l.htmlFor = id;
781
+ l.append(document.createTextNode(label));
782
+ if (hint) l.append(el("small", void 0, hint));
783
+ const box = el("div", "invo-inwrap");
784
+ const input = el("input", "invo-input");
785
+ input.id = id;
786
+ input.type = type;
787
+ input.name = name2;
788
+ input.placeholder = placeholder;
789
+ input.autocomplete = autocomplete;
790
+ box.append(svg(icon), input);
791
+ wrap.append(l, box);
792
+ form.append(wrap);
793
+ return input;
794
+ };
795
+ const email = field("Email", "", "email", "email", "you@example.com", "email", ICONS.mail);
796
+ const phone = field("Phone", "first sign-in only", "tel", "phone", "+1 555 555 0111", "tel", ICONS.phone);
797
+ const name = field("Player name", "optional", "text", "name", "What should we call you?", "nickname", ICONS.user);
798
+ email.required = true;
799
+ const error = el("div", "invo-error");
800
+ const submit = el("button", "invo-btn teal block", "Continue");
801
+ submit.type = "submit";
802
+ form.append(error, submit);
803
+ if (economy.catalog?.sandbox) {
804
+ const note = el("div", "invo-callout");
805
+ note.append(svg(ICONS.info), el("span", void 0, "Sandbox mode: use test details. No real money moves."));
806
+ form.append(note);
807
+ }
808
+ const secure = el("p", "invo-secure");
809
+ secure.append(svg(ICONS.lock), document.createTextNode("Secured by INVO"));
810
+ form.append(secure);
811
+ form.onsubmit = async (e) => {
812
+ e.preventDefault();
813
+ submit.disabled = true;
814
+ submit.classList.add("busy");
815
+ error.textContent = "";
816
+ try {
817
+ await economy.signIn({ email: email.value.trim(), phone: phone.value.trim() || void 0, name: name.value.trim() || void 0 });
818
+ close();
819
+ toast(`Welcome, ${economy.player?.name ?? "player"}`, "success");
820
+ after?.();
821
+ } catch (err) {
822
+ error.textContent = err instanceof Error ? err.message : "Sign-in failed.";
823
+ } finally {
824
+ submit.disabled = false;
825
+ submit.classList.remove("busy");
826
+ }
827
+ };
828
+ body.append(form);
829
+ }
830
+ );
831
+ }
832
+ function openBuyCurrency() {
833
+ if (!requireSignIn(openBuyCurrency)) return;
834
+ const catalog = economy.catalog;
835
+ openDialog(
836
+ { title: `Get ${premiumName()}`, eyebrow: "Top up", subtitle: `${premiumName()} unlock premium items. Pick a pack; you'll pay on INVO's secure checkout.` },
837
+ (body) => {
838
+ const status = el("div", "invo-status");
839
+ const packs = el("div", "invo-packs");
840
+ (catalog?.premium.packs ?? []).forEach((pack, i) => packs.append(packCard(pack, i, status)));
841
+ body.append(packs, status);
842
+ const secure = el("p", "invo-secure");
843
+ secure.append(svg(ICONS.lock), document.createTextNode("Secure checkout by INVO. Your balance updates the moment payment is confirmed."));
844
+ body.append(secure);
845
+ }
846
+ );
847
+ }
848
+ function setStatus(status, text, waiting) {
849
+ status.replaceChildren();
850
+ if (!text) return;
851
+ if (waiting) status.append(el("span", "invo-spinner"));
852
+ status.append(el("span", void 0, text));
853
+ }
854
+ function packCard(pack, index, status) {
855
+ const card = el("div", `invo-pack${pack.badge ? " best" : ""}`);
856
+ if (pack.badge) card.append(el("span", "invo-ribbon", pack.badge));
857
+ const stack = el("div", "invo-stack");
858
+ const gems = Math.min(3, index + 1);
859
+ for (let g = 0; g < gems; g++) stack.append(svg(gemSvg(gems === 1 ? 52 : 44), "invo-cur"));
860
+ card.append(stack);
861
+ card.append(el("div", "invo-pamt", pack.amount ? pack.amount.toLocaleString() : pack.name));
862
+ card.append(el("div", "invo-pname", pack.amount ? `${premiumName()} \xB7 ${pack.name}` : premiumName()));
863
+ const buy = el("button", "invo-btn gold", `$${pack.usdAmount}`);
864
+ buy.type = "button";
865
+ buy.onclick = () => {
866
+ buy.disabled = true;
867
+ buy.classList.add("busy");
868
+ setStatus(status, "Waiting for payment. Finish in the checkout window.", true);
869
+ economy.buyPremium(pack.id).then((u) => {
870
+ if (u.status === "credited") {
871
+ setStatus(status, "", false);
872
+ close();
873
+ } else if (u.status === "pending") {
874
+ setStatus(status, "Taking you to checkout\u2026", true);
875
+ } else {
876
+ setStatus(status, u.status === "cancelled" ? "Checkout closed. Nothing was charged." : `Purchase ${u.status}.`, false);
877
+ }
878
+ }).catch((err) => {
879
+ setStatus(status, err instanceof Error ? err.message : "Checkout failed.", false);
880
+ }).finally(() => {
881
+ buy.disabled = false;
882
+ buy.classList.remove("busy");
883
+ });
884
+ };
885
+ card.append(buy);
886
+ return card;
887
+ }
888
+ function openShop(category) {
889
+ const catalog = economy.catalog;
890
+ if (!catalog) return;
891
+ const cats = options.categories ?? Array.from(new Set(catalog.items.map((i) => i.category)));
892
+ let active = category && cats.includes(category) ? category : "all";
893
+ openDialog(
894
+ { title: "Shop", eyebrow: "Powered by INVO", subtitle: `Spend ${premiumName()} or ${softName()}. Everything you buy is saved to your account.` },
895
+ (body) => {
896
+ const tabs = el("div", "invo-tabs");
897
+ tabs.setAttribute("role", "tablist");
898
+ const grid = el("div", "invo-grid");
899
+ const tabFor = (key, label) => {
900
+ const b = el("button", "invo-tab", label);
901
+ b.type = "button";
902
+ b.setAttribute("role", "tab");
903
+ b.setAttribute("aria-selected", String(key === active));
904
+ b.onclick = () => {
905
+ active = key;
906
+ tabs.querySelectorAll(".invo-tab").forEach((n) => n.setAttribute("aria-selected", "false"));
907
+ b.setAttribute("aria-selected", "true");
908
+ renderGrid();
909
+ };
910
+ tabs.append(b);
911
+ };
912
+ if (cats.length > 1) {
913
+ tabFor("all", "All");
914
+ for (const c of cats) tabFor(c, c);
915
+ }
916
+ const renderGrid = () => {
917
+ const items = catalog.items.filter((i) => active === "all" || i.category === active);
918
+ if (!items.length) grid.replaceChildren(el("div", "invo-empty", "Nothing here yet."));
919
+ else grid.replaceChildren(...items.map(itemCard));
920
+ };
921
+ renderGrid();
922
+ const unsub = economy.on("wallet", () => {
923
+ renderGrid();
924
+ grid.querySelectorAll(".invo-card").forEach((c) => c.style.animation = "none");
925
+ });
926
+ onDialogClose = unsub;
927
+ if (cats.length > 1) body.append(tabs);
928
+ body.append(grid);
929
+ }
930
+ );
931
+ }
932
+ function itemCard(item) {
933
+ const owned = economy.quantity(item.id);
934
+ const max = item.maxOwned ?? 1;
935
+ const card = el("div", `invo-card${owned > 0 ? " owned" : ""}`);
936
+ card.style.setProperty("--c", item.color ?? (item.currency === "premium" ? "var(--invo-gold)" : "var(--invo-teal)"));
937
+ const art = el("div", "invo-art");
938
+ art.append(el("span", "invo-chip cat", item.category));
939
+ if (owned > 0) {
940
+ const chip = el("span", "invo-chip own");
941
+ chip.append(svg(ICONS.check), document.createTextNode(max > 1 ? `${owned}/${max}` : "Owned"));
942
+ art.append(chip);
943
+ }
944
+ art.append(el("div", "invo-glyph", item.icon ?? "\u25C6"));
945
+ card.append(art);
946
+ const cbody = el("div", "invo-cbody");
947
+ cbody.append(el("h3", void 0, item.name), el("p", void 0, item.description ?? ""));
948
+ if (max > 1) {
949
+ const pips = el("div", "invo-pips");
950
+ pips.title = `${owned} of ${max} owned`;
951
+ for (let i = 0; i < Math.min(max, 10); i++) pips.append(el("span", `invo-pip${i < owned ? " on" : ""}`));
952
+ cbody.append(pips);
953
+ }
954
+ card.append(cbody);
955
+ const foot = el("div", "invo-cfoot");
956
+ const price = el("div", `invo-price ${item.currency}`);
957
+ price.append(svg(item.currency === "premium" ? gemSvg(18) : coinSvg(18), "invo-cur"), document.createTextNode(item.price.toLocaleString()));
958
+ price.title = `${item.price.toLocaleString()} ${item.currency === "premium" ? premiumName() : softName()}`;
959
+ const soldOut = owned >= max;
960
+ const cannotAfford = economy.signedIn && !economy.canAfford(item.id);
961
+ const btn = el("button", `invo-btn sm ${soldOut ? "done" : item.currency === "premium" ? "gold" : "teal"}`);
962
+ btn.type = "button";
963
+ const shortBy = item.price - (economy.balance(item.currency)?.balance ?? 0);
964
+ btn.textContent = soldOut ? max === 1 ? "Owned" : "Maxed" : !cannotAfford ? "Buy" : item.currency === "premium" ? `Get ${premiumName()}` : `Need ${shortBy.toLocaleString()}`;
965
+ if (cannotAfford && item.currency === "soft" && !soldOut) btn.className = "invo-btn sm";
966
+ btn.disabled = soldOut;
967
+ btn.onclick = async () => {
968
+ if (!requireSignIn(() => openShop(item.category))) return;
969
+ if (!economy.canAfford(item.id)) {
970
+ if (item.currency === "premium") openBuyCurrency();
971
+ else toast(`Not enough ${softName()} yet. Keep playing!`, "info");
972
+ return;
973
+ }
974
+ btn.disabled = true;
975
+ btn.classList.add("busy");
976
+ try {
977
+ await economy.buyItem(item.id);
978
+ toast(`${item.name} unlocked`, "success");
979
+ } catch (err) {
980
+ toast(err instanceof InvoGameError || err instanceof Error ? err.message : "Purchase failed.", "error");
981
+ btn.disabled = false;
982
+ btn.classList.remove("busy");
983
+ }
984
+ };
985
+ foot.append(price, btn);
986
+ card.append(foot);
987
+ return card;
988
+ }
989
+ plus.onclick = () => openBuyCurrency();
990
+ shopBtn.onclick = () => openShop();
991
+ accountBtn.onclick = async () => {
992
+ if (economy.setupRequired) return openSetup();
993
+ if (!economy.signedIn) return openSignIn();
994
+ await economy.signOut();
995
+ toast("Signed out", "info");
996
+ };
997
+ const onKey = (e) => {
998
+ if (e.key === "Escape" && overlay) {
999
+ e.stopPropagation();
1000
+ close();
1001
+ }
1002
+ };
1003
+ document.addEventListener("keydown", onKey, true);
1004
+ const offs = [
1005
+ economy.on("wallet", renderHud),
1006
+ economy.on("session", renderHud),
1007
+ economy.on("catalog", renderHud),
1008
+ economy.on("setup", renderHud),
1009
+ economy.on("error", (err) => toast(err.message, "error")),
1010
+ // Popup and redirect checkouts both end here, so the confirmation shows exactly once.
1011
+ economy.on("purchase", (u) => {
1012
+ if (u.status === "credited") toast(`+${formatAmount(u.credited)} ${premiumName()} added`, "success");
1013
+ })
1014
+ ];
1015
+ renderHud();
1016
+ return {
1017
+ root,
1018
+ openShop,
1019
+ openBuyCurrency,
1020
+ openSignIn: () => openSignIn(),
1021
+ close,
1022
+ toast,
1023
+ destroy() {
1024
+ close();
1025
+ offs.forEach((off) => off());
1026
+ document.removeEventListener("keydown", onKey, true);
1027
+ root.remove();
1028
+ }
1029
+ };
1030
+ }
1031
+
1032
+ export { InvoGameEconomy, InvoGameError, mountInvoUI };
1033
+ //# sourceMappingURL=game.js.map
1034
+ //# sourceMappingURL=game.js.map