CyberMax-tools commited on
Commit
e5ff8d3
·
verified ·
1 Parent(s): 8ca0645

Deploy pawfoil to the hub

Browse files
pawfoil/cmx.js CHANGED
@@ -129,7 +129,7 @@ export function pwa(game, btn) {
129
  let deferred = null;
130
  let wanted = false;
131
  const ios = /iphone|ipad|ipod/i.test(navigator.userAgent) && !/crios|fxios/i.test(navigator.userAgent);
132
- window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferred = e; if (wanted && btn) btn.hidden = false; });
133
  window.addEventListener('appinstalled', () => { count(game, 'install', 'prompt'); if (btn) btn.hidden = true; });
134
  if (btn) {
135
  btn.addEventListener('click', async () => {
@@ -137,10 +137,12 @@ export function pwa(game, btn) {
137
  deferred.prompt();
138
  const r = await deferred.userChoice.catch(() => null);
139
  if (r && r.outcome === 'accepted') btn.hidden = true;
 
140
  deferred = null;
141
  } else if (ios) {
142
  toast('Tap the Share button, then "Add to Home Screen".', 5000);
143
  count(game, 'install', 'ios-hint');
 
144
  }
145
  });
146
  }
 
129
  let deferred = null;
130
  let wanted = false;
131
  const ios = /iphone|ipad|ipod/i.test(navigator.userAgent) && !/crios|fxios/i.test(navigator.userAgent);
132
+ window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferred = e; if (wanted && btn && !store(`cmx-install-no:${game}`)) btn.hidden = false; });
133
  window.addEventListener('appinstalled', () => { count(game, 'install', 'prompt'); if (btn) btn.hidden = true; });
134
  if (btn) {
135
  btn.addEventListener('click', async () => {
 
137
  deferred.prompt();
138
  const r = await deferred.userChoice.catch(() => null);
139
  if (r && r.outcome === 'accepted') btn.hidden = true;
140
+ else if (r && r.outcome === 'dismissed') { store(`cmx-install-no:${game}`, 1); btn.hidden = true; } // "Not now" is remembered
141
  deferred = null;
142
  } else if (ios) {
143
  toast('Tap the Share button, then "Add to Home Screen".', 5000);
144
  count(game, 'install', 'ios-hint');
145
+ store(`cmx-install-no:${game}`, 1);
146
  }
147
  });
148
  }
pawfoil/funpass.js CHANGED
@@ -1,6 +1,6 @@
1
  // CyberMax Fun Pass: ONE optional supporter pass for every CyberMax game (copied into each game's web/ folder).
2
  // Free games stay free. The pass removes the supporter nudges and unlocks extra packs, the full archive and themes.
3
- // Monthly $2.99 · Yearly $19 · Lifetime $29.99 once (Stripe Payment Links, pack revenue/packs/stripe/fun-pass).
4
  // Buy: counted redirect https://data.cybermaxtools.com/buy/st-fun-pass-<plan>?s=game-<id> -> Stripe checkout.
5
  // After checkout Stripe sends the buyer to data.cybermaxtools.com/unlock/fun-pass?session_id=..., which checks
6
  // the Checkout Session (and, for a subscription, that it is still active) and returns to /games/ with #cmx-pro=<code>.
@@ -15,7 +15,7 @@ const RECHECK = 3 * 864e5; // subscriptions are re-checked every 3 days; a cance
15
  export const PLANS = [
16
  { id: 'monthly', label: 'Monthly', price: '$2.99', per: '/month', note: 'Cancel any time' },
17
  { id: 'yearly', label: 'Yearly', price: '$19', per: '/year', note: 'Save 47%', best: true },
18
- { id: 'unlock', label: 'Lifetime', price: '$29.99', per: ' once', note: 'Pay once, keep forever' },
19
  ];
20
  export const COMMON_PERKS = ['No supporter nudges, ever', 'Extra puzzle packs in every game', 'The full archive of past dailies', 'Custom colour themes'];
21
 
 
1
  // CyberMax Fun Pass: ONE optional supporter pass for every CyberMax game (copied into each game's web/ folder).
2
  // Free games stay free. The pass removes the supporter nudges and unlocks extra packs, the full archive and themes.
3
+ // Monthly $2.99 · Yearly $19 · Unlock all $4.99 once (Stripe Payment Links, pack revenue/packs/stripe/fun-pass).
4
  // Buy: counted redirect https://data.cybermaxtools.com/buy/st-fun-pass-<plan>?s=game-<id> -> Stripe checkout.
5
  // After checkout Stripe sends the buyer to data.cybermaxtools.com/unlock/fun-pass?session_id=..., which checks
6
  // the Checkout Session (and, for a subscription, that it is still active) and returns to /games/ with #cmx-pro=<code>.
 
15
  export const PLANS = [
16
  { id: 'monthly', label: 'Monthly', price: '$2.99', per: '/month', note: 'Cancel any time' },
17
  { id: 'yearly', label: 'Yearly', price: '$19', per: '/year', note: 'Save 47%', best: true },
18
+ { id: 'unlock', label: 'Unlock all', price: '$4.99', per: ' once', note: 'Pay once, keep forever' },
19
  ];
20
  export const COMMON_PERKS = ['No supporter nudges, ever', 'Extra puzzle packs in every game', 'The full archive of past dailies', 'Custom colour themes'];
21
 
pawfoil/game.js CHANGED
@@ -3,6 +3,7 @@
3
  import { makeCard, KINDS, RARITY, FRAMES, cleanPetName } from './core.js';
4
  import { count, store, toast, share, intents, download, canvasBlob, pwa, rr, themeToggle } from './cmx.js';
5
  import * as pass from './funpass.js';
 
6
 
7
  const GAME = 'pawfoil';
8
  const PATH = '/games/pawfoil/';
@@ -12,7 +13,8 @@ const g = cv.getContext('2d');
12
  const W = 750, H = 1050, ART = { x: 52, y: 128, w: 646, h: 430 };
13
  let photo = null, kind = store('pawfoil:kind') || 'dog', roll = 0, forced = null, ox = 0, oy = 0, zoom = 1, made = false;
14
 
15
- pass.init({ game: GAME, name: 'Pawfoil', perks: ['Pick any frame: Legendary gold holo on demand', 'Hide the CyberMax line on your cards'] });
 
16
  const install = pwa(GAME, $('install'));
17
  themeToggle($('theme'));
18
 
@@ -55,7 +57,8 @@ async function loadPhoto(blob, from) {
55
  } catch { toast('Could not read that image. Try a JPG or PNG.'); }
56
  }
57
  $('file').onchange = (e) => { const f = e.target.files[0]; if (f) loadPhoto(f, 'photo'); };
58
- $('sample').onclick = async () => { const r = await fetch('sample.jpg'); loadPhoto(await r.blob(), 'sample'); if (!$('name').value) $('name').value = 'Biscuit'; draw(); };
 
59
 
60
  // drag to move the photo inside the art box
61
  let drag = null;
@@ -169,3 +172,11 @@ window.__cmxShot = async (stage = 1) => {
169
 
170
  renderKinds();
171
  draw();
 
 
 
 
 
 
 
 
 
3
  import { makeCard, KINDS, RARITY, FRAMES, cleanPetName } from './core.js';
4
  import { count, store, toast, share, intents, download, canvasBlob, pwa, rr, themeToggle } from './cmx.js';
5
  import * as pass from './funpass.js';
6
+ import { initLadder, openDuel } from './ladder.js';
7
 
8
  const GAME = 'pawfoil';
9
  const PATH = '/games/pawfoil/';
 
13
  const W = 750, H = 1050, ART = { x: 52, y: 128, w: 646, h: 430 };
14
  let photo = null, kind = store('pawfoil:kind') || 'dog', roll = 0, forced = null, ox = 0, oy = 0, zoom = 1, made = false;
15
 
16
+ pass.init({ game: GAME, name: 'Pawfoil', perks: ['Duel ladder levels 21-30 (1-20 are free)', 'Pick any frame: Legendary gold holo on demand', 'Hide the CyberMax line on your cards'],
17
+ extra: 'The Fun Pass opens duel levels 21-30, past daily rivals, any card frame and extras in every CyberMax game.' });
18
  const install = pwa(GAME, $('install'));
19
  themeToggle($('theme'));
20
 
 
57
  } catch { toast('Could not read that image. Try a JPG or PNG.'); }
58
  }
59
  $('file').onchange = (e) => { const f = e.target.files[0]; if (f) loadPhoto(f, 'photo'); };
60
+ async function loadSample() { const r = await fetch('sample.jpg'); await loadPhoto(await r.blob(), 'sample'); if (!$('name').value) $('name').value = 'Biscuit'; draw(); }
61
+ $('sample').onclick = loadSample;
62
 
63
  // drag to move the photo inside the art box
64
  let drag = null;
 
172
 
173
  renderKinds();
174
  draw();
175
+
176
+ // Duel ladder: your current card (or the sample pet) duels 30 rivals. The art is copied canvas-to-canvas locally.
177
+ $('go-duel').onclick = () => { openDuel(); window.scrollTo({ top: 0 }); };
178
+ initLadder({
179
+ getCard: card,
180
+ ensurePet: async () => { if (!photo && !$('name').value.trim()) { try { await loadSample(); } catch { /* emoji art is fine */ } } },
181
+ drawArt: (c) => { const x = c.getContext('2d'); x.clearRect(0, 0, c.width, c.height); x.drawImage(cv, ART.x, ART.y, ART.w, ART.h, 0, 0, c.width, c.height); },
182
+ });
pawfoil/index.html CHANGED
@@ -1,11 +1,11 @@
1
  <!doctype html>
2
  <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
3
- <title>Pawfoil: free pet trading card maker, holo cards in seconds | CyberMax</title>
4
- <meta name="description" content="Turn your pet's photo into a shiny collectible trading card with funny stats and moves. Free HD download, no sign-up, no watermark grab: your photo never leaves your phone.">
5
  <link rel="canonical" href="https://cybermaxtools.com/games/pawfoil/">
6
  <meta property="og:type" content="website"><meta property="og:site_name" content="CyberMax">
7
- <meta property="og:title" content="Pawfoil: make your pet a holo trading card">
8
- <meta property="og:description" content="Photo in, collectible card out: stats, two funny moves, a rarity roll. Free HD download.">
9
  <meta property="og:url" content="https://cybermaxtools.com/games/pawfoil/">
10
  <meta property="og:image" content="https://cybermaxtools.com/games/pawfoil/og.png"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630">
11
  <meta name="twitter:card" content="summary_large_image"><meta name="twitter:image" content="https://cybermaxtools.com/games/pawfoil/og.png">
@@ -15,14 +15,19 @@
15
  <meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-title" content="Pawfoil">
16
  <link rel="stylesheet" href="fun.css"><link rel="stylesheet" href="style.css">
17
  <script>try{var t=localStorage.getItem('cm-theme');if(t)document.documentElement.dataset.theme=t}catch(e){}</script>
18
- <script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"Pawfoil","url":"https://cybermaxtools.com/games/pawfoil/","image":"https://cybermaxtools.com/games/pawfoil/og.png","description":"Free pet trading card maker: your pet's photo becomes a collectible card with stats, moves and a rarity roll. Runs in the browser; photos never leave the device.","applicationCategory":"MultimediaApplication","operatingSystem":"Any","publisher":{"@type":"Organization","name":"CyberMax","url":"https://cybermaxtools.com/"},"offers":[{"@type":"Offer","price":"0","priceCurrency":"USD","description":"Free HD card"},{"@type":"Offer","price":"2.99","priceCurrency":"USD","description":"CyberMax Fun Pass, monthly"}]}</script>
 
 
 
19
  </head><body>
20
  <div class="wrap wide">
21
  <header class="top"><a class="brand" href="https://cybermaxtools.com/games/"><svg viewBox="0 0 512 512" aria-hidden="true"><clipPath id="lg"><rect width="512" height="512" rx="116"/></clipPath><g clip-path="url(#lg)"><rect width="512" height="512" fill="#FF6A3D"/><path d="M512 250V512H250Z" fill="#D9481F"/></g><g transform="translate(86 86) scale(3.4)"><path d="M66 27 A27 27 0 1 0 66 73" fill="none" stroke="#11141B" stroke-width="17" stroke-linecap="round"/><rect x="66" y="41" width="20" height="18" rx="4" fill="#11141B"/></g></svg>CyberMax</a>
22
  <nav><a href="https://cybermaxtools.com/games/">Games</a></nav><button class="icon" id="theme" type="button" aria-label="Switch light or dark">◐</button></header>
23
  <main>
24
- <h1>Make your pet a holo trading card <span class="pro-badge">PASS</span></h1>
25
- <p class="muted lede">Add a photo, type a name, roll for rarity. Stats and moves are made for your pet. Free HD download; your photo never leaves this device.</p>
 
 
26
  <div class="maker">
27
  <section class="controls panel">
28
  <label class="photo"><input type="file" id="file" accept="image/*"><span class="btn">📷 Choose a photo</span></label>
@@ -38,26 +43,61 @@
38
  </section>
39
  <section class="preview">
40
  <div class="tilt" id="tilt"><canvas id="card" width="750" height="1050" aria-label="Your pet's trading card"></canvas><div class="holo" id="holo"></div></div>
41
- <div class="row share"><button class="btn" id="dl" type="button">⬇ Download HD card</button><button class="btn ghost" id="share" type="button">Share</button><a class="btn ghost sm" id="sx" target="_blank" rel="noopener">X</a><a class="btn ghost sm" id="sb" target="_blank" rel="noopener">Bluesky</a><a class="btn ghost sm" id="sw" target="_blank" rel="noopener">WhatsApp</a></div>
42
  <div class="row"><button class="btn ghost sm" id="install" type="button" hidden>📲 Add to Home Screen</button><button class="btn pass sm" id="pass-btn" type="button">✨ Fun Pass</button></div>
43
  </section>
44
  </div>
45
- <div class="nudge"><span>Want a Legendary every time? The <b>Fun Pass</b> lets you pick any frame, hides the CyberMax line and works in every CyberMax game.</span><button class="btn pass sm" data-pass="nudge" type="button">See the pass</button></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- <section class="seo">
48
- <h2>How Pawfoil works</h2>
49
- <p>Pick a photo of your dog, cat, bunny, bird or any pet. Pawfoil frames it as a collectible trading card with HP, six stats (Cuteness is always high), a type and two funny moves like <i>Sock Heist</i> or <i>3 AM Zoomies</i>. Each roll draws a rarity: Common, Rare, Epic (holo) or Legendary (gold holo). Roll again until you love it, then download the HD PNG or share it.</p>
50
- <h3>Private: your photo stays on your device</h3>
51
- <p>The card is drawn in your browser. Your photo is never uploaded, stored or seen by anyone but you. No account, no email.</p>
52
- <h3>Free, with an optional Fun Pass</h3>
53
- <p>Every card is free in full HD. The optional <b>CyberMax Fun Pass</b> ($2.99/month, $19/year, or $29.99 for life) lets you pick any frame (Legendary on demand), hides the small CyberMax line on the card, and unlocks extras in every CyberMax game.</p>
54
- <h3>FAQ</h3>
55
- <p><b>Can I print it?</b> Yes: the download is 750×1050 px, a standard 2.5×3.5 inch card at 300 dpi. <b>Why not an AI card generator?</b> Pawfoil uses your real photo (no strange AI faces), is instant, works offline and needs no sign-up. <b>Is it really free?</b> Yes, the HD download is free; the pass only adds extras.</p>
56
- <h2>More free games from CyberMax</h2>
57
- <div class="more"><a href="https://cybermaxtools.com/games/kenwren/"><b>Kenwren</b><span>How well do your friends know you?</span></a><a href="https://cybermaxtools.com/games/pathmoor/"><b>Pathmoor</b><span>Daily path puzzle</span></a><a href="https://cybermaxtools.com/games/whirlane/"><b>Whirlane</b><span>One-tap orbit dodger</span></a></div>
 
 
 
 
 
 
 
 
 
 
58
  </section>
59
  </main>
60
  <footer>© 2026 CyberMax · <a href="https://cybermaxtools.com/games/">Games</a> · <a href="https://cybermaxtools.com/toys/">Toys</a> · <a href="https://cybermaxtools.com/store/">Store</a> · <a href="https://cybermaxtools.com/privacy">Privacy</a> · <a href="https://cybermaxtools.com/terms">Terms</a></footer>
61
  </div>
 
62
  <script type="module" src="game.js"></script>
63
- <!-- cybermax-count:start --><script>(function(){try{var u="https://data.cybermaxtools.com/v?p="+encodeURIComponent(location.host+location.pathname)+"&r="+encodeURIComponent((document.referrer||"").split("/")[2]||"")+(function(){var q=new URLSearchParams(location.search),s=q.get("utm_source");return s?"&us="+encodeURIComponent(s)+"&uc="+encodeURIComponent(q.get("utm_campaign")||""):""})();navigator.sendBeacon?navigator.sendBeacon(u):(new Image).src=u}catch(e){}})()</script><!-- cybermax-count:end --></body></html>
 
1
  <!doctype html>
2
  <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
3
+ <title>Pawfoil: Free Pet Trading Card Maker, Turn Your Pet Into a Holo Card</title>
4
+ <meta name="description" content="Make your pet a free holo trading card, then duel it up a ladder of 30 rival pets. Stats, moves, rarity rolls, daily rival. Photo stays on your phone.">
5
  <link rel="canonical" href="https://cybermaxtools.com/games/pawfoil/">
6
  <meta property="og:type" content="website"><meta property="og:site_name" content="CyberMax">
7
+ <meta property="og:title" content="Pawfoil: Free Pet Trading Card Maker">
8
+ <meta property="og:description" content="Make your pet a free holo trading card, then duel it up a ladder of 30 rival pets. Stats, moves, rarity rolls, daily rival. Photo stays on your phone.">
9
  <meta property="og:url" content="https://cybermaxtools.com/games/pawfoil/">
10
  <meta property="og:image" content="https://cybermaxtools.com/games/pawfoil/og.png"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630">
11
  <meta name="twitter:card" content="summary_large_image"><meta name="twitter:image" content="https://cybermaxtools.com/games/pawfoil/og.png">
 
15
  <meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-title" content="Pawfoil">
16
  <link rel="stylesheet" href="fun.css"><link rel="stylesheet" href="style.css">
17
  <script>try{var t=localStorage.getItem('cm-theme');if(t)document.documentElement.dataset.theme=t}catch(e){}</script>
18
+ <meta name="twitter:title" content="Pawfoil: Free Pet Trading Card Maker">
19
+ <meta name="twitter:description" content="Make your pet a free holo trading card, then duel it up a ladder of 30 rival pets. Stats, moves, rarity rolls, daily rival. Photo stays on your phone.">
20
+ <style>.h1kw{display:block;font-size:.42em;font-weight:600;opacity:.75;letter-spacing:.01em;margin-top:.15em}.seo ol,.seo ul{padding-left:1.2em}.seo li{margin:.25em 0}</style>
21
+ <script type="application/ld+json">{"@context": "https://schema.org", "@graph": [{"@type": "VideoGame", "@id": "https://cybermaxtools.com/games/pawfoil/#game", "name": "Pawfoil", "alternateName": "Pet trading card maker free", "url": "https://cybermaxtools.com/games/pawfoil/", "image": "https://cybermaxtools.com/games/pawfoil/og.png", "description": "Pawfoil turns a photo of your dog, cat, bunny or any pet into a collectible holo trading card with HP, stats, a type and two funny moves. Roll for rarity, download the HD card or share it, then duel your card's stats against 30 rival pet cards and a daily rival. The card is drawn in your browser, so your photo never leaves your device.", "genre": ["Creative", "Card maker", "Pets"], "gamePlatform": ["Web browser", "Android", "iOS", "Windows", "macOS", "ChromeOS"], "applicationCategory": "Game", "operatingSystem": "Any (web browser)", "playMode": "SinglePlayer", "inLanguage": "en", "isAccessibleForFree": true, "offers": {"@type": "Offer", "price": "0", "priceCurrency": "USD"}, "author": {"@type": "Organization", "name": "CyberMax", "url": "https://cybermaxtools.com/"}, "publisher": {"@type": "Organization", "name": "CyberMax"}, "datePublished": "2026-10-02", "keywords": "Pet trading card maker free, free pet trading card maker, unblocked, no download, browser game", "trailer": {"@id": "https://cybermaxtools.com/games/pawfoil/#video"}}, {"@type": "FAQPage", "@id": "https://cybermaxtools.com/games/pawfoil/#faq", "mainEntity": [{"@type": "Question", "name": "Is Pawfoil free?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: every HD card, the daily rival and duel levels 1-20 are free."}}, {"@type": "Question", "name": "Is my photo uploaded?", "acceptedAnswer": {"@type": "Answer", "text": "No, the card is drawn on your device."}}, {"@type": "Question", "name": "Do I need a photo to duel?", "acceptedAnswer": {"@type": "Answer", "text": "No, you can duel with the built-in sample pet."}}, {"@type": "Question", "name": "Can I print it?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, 750×1050 px, a standard card at 300 dpi."}}, {"@type": "Question", "name": "Do I need an app?", "acceptedAnswer": {"@type": "Answer", "text": "No, it works in any browser."}}]}, {"@type": "VideoObject", "name": "Pawfoil demo: Make your pet a holo trading card", "description": "A 15-second screen recording of the live Pawfoil page: Add a pet photo (here: the built-in sample); Give it a name; Your holo card, made on your phone; Roll again for a new card. Real result, no voice.", "thumbnailUrl": ["https://cybermax.cybermax-tools.workers.dev/media/demos/pawfoil/poster.jpg"], "uploadDate": "2026-10-02T18:07:57+00:00", "duration": "PT15S", "contentUrl": "https://cybermax.cybermax-tools.workers.dev/media/demos/pawfoil/demo-16x9.mp4", "embedUrl": "https://cybermaxtools.com/games/pawfoil/", "inLanguage": "en", "publisher": {"@type": "Organization", "name": "CyberMax", "logo": {"@type": "ImageObject", "url": "https://cybermax.cybermax-tools.workers.dev/store/img/favicon.webp"}}, "@id": "https://cybermaxtools.com/games/pawfoil/#video"}]}</script>
22
  </head><body>
23
  <div class="wrap wide">
24
  <header class="top"><a class="brand" href="https://cybermaxtools.com/games/"><svg viewBox="0 0 512 512" aria-hidden="true"><clipPath id="lg"><rect width="512" height="512" rx="116"/></clipPath><g clip-path="url(#lg)"><rect width="512" height="512" fill="#FF6A3D"/><path d="M512 250V512H250Z" fill="#D9481F"/></g><g transform="translate(86 86) scale(3.4)"><path d="M66 27 A27 27 0 1 0 66 73" fill="none" stroke="#11141B" stroke-width="17" stroke-linecap="round"/><rect x="66" y="41" width="20" height="18" rx="4" fill="#11141B"/></g></svg>CyberMax</a>
25
  <nav><a href="https://cybermaxtools.com/games/">Games</a></nav><button class="icon" id="theme" type="button" aria-label="Switch light or dark">◐</button></header>
26
  <main>
27
+ <h1>Make your pet a holo trading card <span class="pro-badge">PASS</span> <small class="h1kw">Free pet trading card maker</small></h1>
28
+ <p class="muted lede">Add a photo, type a name, roll for rarity, then duel your card up a ladder of 30 rival pets. Free HD download; your photo never leaves this device.</p>
29
+ <div class="modes" role="tablist" aria-label="Mode"><button class="mode" id="tab-make" role="tab" type="button" aria-selected="true">🖼️ Make a card</button><button class="mode" id="tab-duel" role="tab" type="button" aria-selected="false">⚔️ Duel ladder</button></div>
30
+ <div id="mk">
31
  <div class="maker">
32
  <section class="controls panel">
33
  <label class="photo"><input type="file" id="file" accept="image/*"><span class="btn">📷 Choose a photo</span></label>
 
43
  </section>
44
  <section class="preview">
45
  <div class="tilt" id="tilt"><canvas id="card" width="750" height="1050" aria-label="Your pet's trading card"></canvas><div class="holo" id="holo"></div></div>
46
+ <div class="row share"><button class="btn" id="dl" type="button">⬇ Download HD card</button><button class="btn ghost" id="share" type="button">Share</button><button class="btn" id="go-duel" type="button">⚔️ Duel with this card</button><a class="btn ghost sm" id="sx" target="_blank" rel="noopener">X</a><a class="btn ghost sm" id="sb" target="_blank" rel="noopener">Bluesky</a><a class="btn ghost sm" id="sw" target="_blank" rel="noopener">WhatsApp</a></div>
47
  <div class="row"><button class="btn ghost sm" id="install" type="button" hidden>📲 Add to Home Screen</button><button class="btn pass sm" id="pass-btn" type="button">✨ Fun Pass</button></div>
48
  </section>
49
  </div>
50
+ <div class="nudge"><span>Want a Legendary every time? The <b>Fun Pass</b> lets you pick any frame, hides the CyberMax line, opens duel levels 21-30 and works in every CyberMax game.</span><button class="btn pass sm" data-pass="nudge" type="button">See the pass</button></div>
51
+ </div>
52
+ <section id="duel" class="duel" hidden aria-label="Duel ladder">
53
+ <div class="dbar"><p class="goal" id="goal" aria-live="polite"></p>
54
+ <div class="dtools"><span class="badge" id="streak" title="Daily streak">🔥 0</span><button class="icon-btn" id="restart" type="button" aria-label="Restart duel (R)" title="Restart (R)" hidden>↻</button><button class="icon-btn" id="to-map" type="button" aria-label="Level map" title="Map">🗺️</button><button class="icon-btn" id="mute" type="button" aria-label="Mute sound" aria-pressed="false">🔊</button></div></div>
55
+ <div id="map" class="dmap">
56
+ <div class="daily"><button class="daily-tile" id="daily-tile" type="button"></button>
57
+ <div class="past"><label class="small">Past daily # <input id="daily-num" type="number" min="1" inputmode="numeric"></label><button class="btn ghost sm" id="daily-past" type="button">Play (Fun Pass)</button></div></div>
58
+ <p class="muted small maprule">Each rival shows the cards it will play. Answer each with one of your six stats, once each. Higher number wins; ties go to the rival. Rival numbers are matched to your card, so every pet gets a fair climb. <span id="stars-total"></span></p>
59
+ <div id="levels"></div>
60
+ <p class="muted small">Levels 1-20 are free. Levels 21-30 come with the CyberMax Fun Pass; a level you reached stays open.</p>
61
+ </div>
62
+ <div id="arena" class="arena" hidden>
63
+ <div class="rival" id="rival"></div>
64
+ <p class="lbl">Rival plays, in order</p>
65
+ <div class="rounds" id="rounds"></div>
66
+ <p class="pending" id="pending" hidden></p>
67
+ <div class="me"><canvas id="me-art" width="240" height="160" aria-hidden="true"></canvas><div><b id="me-name"></b><span class="muted small" id="me-sub"></span><span class="small" id="score-now"></span></div></div>
68
+ <p class="lbl">Your stats: tap one</p>
69
+ <div class="stats" id="stats" role="group" aria-label="Your stats: tap one to play it"></div>
70
+ <button class="btn ghost sm move" id="move" type="button" aria-pressed="false" hidden></button>
71
+ <div class="hand" id="hand" hidden aria-hidden="true">👆</div>
72
+ </div>
73
+ <div id="result" class="result panel" hidden aria-live="polite"></div>
74
+ </section>
75
 
76
+ <section class="seo" id="guide">
77
+ <h2>Pawfoil: pet trading card maker free</h2>
78
+ <p>Pawfoil turns a photo of your dog, cat, bunny or any pet into a collectible holo trading card with HP, stats, a type and two funny moves. Roll for rarity, download the HD card or share it, then duel your card&#x27;s stats against 30 rival pet cards and a daily rival. The card is drawn in your browser, so your photo never leaves your device.</p>
79
+ <h2>How to play Pawfoil</h2>
80
+ <ol><li>Pick a photo of your pet (or use the sample pet).</li><li>Pawfoil frames it as a trading card with stats and moves.</li><li>Roll for rarity: Common, Rare, Epic holo or Legendary gold.</li><li>Download the HD PNG or share it.</li><li>Open the Duel ladder: answer each rival card with one of your six stats; higher number wins, ties go to the rival.</li></ol>
81
+ <h3>Controls</h3>
82
+ <p><b>Phone and tablet:</b> Pick a photo from your gallery, tilt your phone to see the holo effect.</p>
83
+ <p><b>Desktop, laptop and Chromebook:</b> Choose an image file and move the mouse over the card for the holo effect.</p>
84
+ <h2>Pawfoil tips and strategy</h2>
85
+ <ul><li>In a duel, beat each rival card with your smallest stat that still wins.</li><li>Throw your weakest stat at a rival card you can&#x27;t beat.</li><li>Crown rounds are worth 2 points: save a big stat for them.</li><li>The 750×1050 download prints as a standard 2.5×3.5 inch card.</li></ul>
86
+ <h2>Game modes</h2>
87
+ <ul><li>Free HD cards.</li><li>Duel ladder: levels 1-20 free, a new twist every 5 levels, a boss every 10th, 1-3 stars.</li><li>Daily rival (free): the same rival for everyone each day, with a streak.</li><li>Fun Pass: duel levels 21-30, past daily rivals, pick any frame, Legendary on demand.</li></ul>
88
+ <p>Free to play with no ads and no sign-up. The optional <a href="https://cybermaxtools.com/games/#pass">CyberMax Fun Pass</a> ($2.99/month, $19/year or $29.99 for life) adds cosmetic extras and bonus modes in every CyberMax game.</p>
89
+ <h2>Pawfoil FAQ</h2>
90
+ <h3>Is Pawfoil free?</h3><p>Yes: every HD card, the daily rival and duel levels 1-20 are free.</p>
91
+ <h3>Is my photo uploaded?</h3><p>No, the card is drawn on your device.</p>
92
+ <h3>Do I need a photo to duel?</h3><p>No, you can duel with the built-in sample pet.</p>
93
+ <h3>Can I print it?</h3><p>Yes, 750×1050 px, a standard card at 300 dpi.</p>
94
+ <h3>Do I need an app?</h3><p>No, it works in any browser.</p>
95
+ <h2>Similar free games</h2>
96
+ <div class="more"><a href="https://cybermaxtools.com/games/kenwren/"><b>Kenwren</b><span>How well do your friends know you?</span></a><a href="https://cybermaxtools.com/games/brimbloom/"><b>Brimbloom</b><span>Stop the bloom on the brim</span></a><a href="https://cybermaxtools.com/games/latchkite/"><b>Latchkite</b><span>Let go at the right moment, catch the next peg</span></a><a href="https://cybermaxtools.com/games/"><b>All CyberMax games</b><span>Free browser games, no download</span></a></div>
97
  </section>
98
  </main>
99
  <footer>© 2026 CyberMax · <a href="https://cybermaxtools.com/games/">Games</a> · <a href="https://cybermaxtools.com/toys/">Toys</a> · <a href="https://cybermaxtools.com/store/">Store</a> · <a href="https://cybermaxtools.com/privacy">Privacy</a> · <a href="https://cybermaxtools.com/terms">Terms</a></footer>
100
  </div>
101
+ <canvas id="fx" aria-hidden="true"></canvas>
102
  <script type="module" src="game.js"></script>
103
+ </body></html>
pawfoil/ladder.js ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Pawfoil Duel Ladder UI: map, duel table, result + share card, daily rival, streak, sounds and particles.
2
+ // Uses the card from the maker (or the built-in sample pet). The photo is only copied canvas-to-canvas on this
3
+ // device for the small card preview; it is never uploaded and never put in the share image. (c) 2026 CyberMax.
4
+ import { LEVELS, FREE_LEVELS, TWISTS, buildDuel, newPlay, playRound, done, playScore, stars, dailySpec, cleanProgress, playable, lockReason,
5
+ recordLevel, keepWithPass, totalStars, bumpStreak, currentStreak, parseLink, linkPath, grid, playValue } from './levels.js';
6
+ import { FRAMES } from './core.js';
7
+ import { count, store, toast, share, today, dayNumber, rr, canvasBlob } from './cmx.js';
8
+ import * as pass from './funpass.js';
9
+
10
+ const GAME = 'pawfoil', PATH = '/games/pawfoil/';
11
+ const $ = (id) => document.getElementById(id);
12
+ const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
13
+ const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
14
+ let H = null; // hooks from game.js: getCard(), drawArt(canvas), ensurePet()
15
+ let prog = cleanProgress(store('pawfoil:ladder'));
16
+ let daily = store('pawfoil:daily') || {};
17
+ let muted = !!store('pawfoil:mute');
18
+ let cur = null; // { spec, duel, play, target, link, armed, day }
19
+ let started = false;
20
+ const TODAY = () => dayNumber(today());
21
+
22
+ // ------------------------------------------------------------------ sound (WebAudio synth, no files)
23
+ let ac = null;
24
+ function tone(f, t = 0.09, type = 'square', vol = 0.05, when = 0, slide = 0) {
25
+ if (muted) return;
26
+ try {
27
+ ac = ac || new (window.AudioContext || window.webkitAudioContext)();
28
+ const o = ac.createOscillator(), g = ac.createGain(), s = ac.currentTime + when;
29
+ o.type = type; o.frequency.setValueAtTime(f, s); if (slide) o.frequency.exponentialRampToValueAtTime(f * slide, s + t);
30
+ g.gain.setValueAtTime(vol, s); g.gain.exponentialRampToValueAtTime(0.0001, s + t);
31
+ o.connect(g).connect(ac.destination); o.start(s); o.stop(s + t + 0.03);
32
+ } catch { /* no audio */ }
33
+ }
34
+ const sfx = {
35
+ tap: () => tone(660, 0.04, 'triangle', 0.04),
36
+ win: () => { tone(523, 0.08, 'square', 0.045); tone(784, 0.12, 'square', 0.045, 0.07); },
37
+ lose: () => tone(180, 0.22, 'sawtooth', 0.05, 0, 0.6),
38
+ clear: (n) => [523, 659, 784, 1047].slice(0, 1 + n).forEach((f, i) => tone(f, 0.14, 'triangle', 0.06, i * 0.11)),
39
+ fail: () => { tone(300, 0.15, 'sawtooth', 0.05); tone(200, 0.3, 'sawtooth', 0.05, 0.14, 0.7); },
40
+ };
41
+
42
+ // ------------------------------------------------------------------ particles + shake
43
+ const fx = $('fx'), fg = fx.getContext('2d');
44
+ let parts = [], raf = 0;
45
+ function burst(el, n = 18, colors = ['#FFB547', '#FF6A3D', '#5BA8E8', '#2FD3A0', '#E5C8FF']) {
46
+ if (!el) return;
47
+ const r = el.getBoundingClientRect(), x = r.left + r.width / 2, y = r.top + r.height / 2;
48
+ for (let i = 0; i < n; i++) { const a = Math.random() * Math.PI * 2, s = 2 + Math.random() * 5; parts.push({ x, y, vx: Math.cos(a) * s, vy: Math.sin(a) * s - 2, life: 1, c: colors[i % colors.length], sz: 3 + Math.random() * 4 }); }
49
+ if (!raf) raf = requestAnimationFrame(tick);
50
+ }
51
+ function tick() {
52
+ const dpr = window.devicePixelRatio || 1;
53
+ if (fx.width !== innerWidth * dpr) { fx.width = innerWidth * dpr; fx.height = innerHeight * dpr; }
54
+ fg.setTransform(dpr, 0, 0, dpr, 0, 0); fg.clearRect(0, 0, innerWidth, innerHeight);
55
+ parts = parts.filter((p) => (p.life -= 0.022) > 0);
56
+ for (const p of parts) { p.x += p.vx; p.y += p.vy; p.vy += 0.18; fg.globalAlpha = p.life; fg.fillStyle = p.c; fg.fillRect(p.x, p.y, p.sz, p.sz); }
57
+ fg.globalAlpha = 1;
58
+ raf = parts.length ? requestAnimationFrame(tick) : 0;
59
+ }
60
+ function shake(el) {
61
+ if (reduced() || !el) return;
62
+ el.classList.remove('shake'); void el.offsetWidth; el.classList.add('shake');
63
+ }
64
+
65
+ // ------------------------------------------------------------------ progress
66
+ function save() { if (pass.isPro()) prog = keepWithPass(prog); store('pawfoil:ladder', prog); }
67
+ const target = () => (cur && cur.target != null ? cur.target : null);
68
+
69
+ // ------------------------------------------------------------------ map
70
+ function showStreak() {
71
+ const st = currentStreak(daily.streak, TODAY());
72
+ $('streak').textContent = `🔥 ${st}`;
73
+ $('streak').title = `Daily streak: ${st} day${st === 1 ? '' : 's'} in a row`;
74
+ }
75
+ function renderMap() {
76
+ const day = TODAY(), pro = pass.isPro();
77
+ showStreak();
78
+ $('daily-past').textContent = pro ? 'Play' : 'Play (Fun Pass)';
79
+ $('stars-total').textContent = `⭐ ${totalStars(prog)}/${LEVELS.length * 3}`;
80
+ const dd = daily.res && daily.res.day === day ? daily.res : null;
81
+ $('daily-tile').innerHTML = `<b>📅 Daily rival #${day}</b><span>${dd ? `Done: ${'★'.repeat(dd.stars)}${'☆'.repeat(3 - dd.stars)} · ${dd.score}. Play again for a better score.` : 'Same rival for everyone today. Keep your streak going.'}</span>`;
82
+ const el = $('levels'); el.innerHTML = '';
83
+ for (const tw of TWISTS) {
84
+ const h = document.createElement('div'); h.className = 'tier';
85
+ h.innerHTML = `<b>${tw.icon} ${esc(tw.name)}</b> <span>${esc(tw.rule)}</span>${tw.from > FREE_LEVELS ? ' <em>Fun Pass</em>' : ''}`;
86
+ el.appendChild(h);
87
+ const row = document.createElement('div'); row.className = 'lvrow';
88
+ for (const lv of LEVELS.filter((l) => l.twist === tw)) {
89
+ const b = document.createElement('button'), why = lockReason(lv.n, prog, pro), s = prog.stars[lv.n] || 0;
90
+ b.type = 'button'; b.className = `lv${lv.boss ? ' boss' : ''}${why ? ' locked' : ''}${s ? ' done' : ''}`; b.dataset.lv = lv.n;
91
+ b.setAttribute('aria-label', `Level ${lv.n}${lv.boss ? ' boss' : ''}${why === 'pass' ? ', needs the Fun Pass' : why ? ', locked' : `, ${s} stars`}`);
92
+ b.innerHTML = `<span class="em">${why === 'pass' ? '🔒' : lv.rival.emoji}</span><b>${lv.n}</b><small>${why ? (why === 'pass' ? 'Pass' : '·') : '★'.repeat(s) + '☆'.repeat(3 - s)}</small>`;
93
+ b.onclick = () => (why === 'pass' ? pass.open(`level-${lv.n}`) : why ? toast(`Clear level ${lv.n - 1} first.`) : startLevel(lv.n));
94
+ row.appendChild(b);
95
+ }
96
+ el.appendChild(row);
97
+ }
98
+ const next = Math.min(prog.reached, LEVELS.length);
99
+ $('goal').innerHTML = `🎯 Climb 30 rival cards. Levels 1-${FREE_LEVELS} free · next: <b>level ${next}</b>`;
100
+ show('map');
101
+ }
102
+ function show(view) { $('map').hidden = view !== 'map'; $('arena').hidden = view !== 'arena'; $('result').hidden = view !== 'result'; $('restart').hidden = view === 'map'; }
103
+
104
+ // ------------------------------------------------------------------ duel
105
+ async function begin(spec, opts = {}) {
106
+ await H.ensurePet();
107
+ const card = H.getCard();
108
+ cur = { spec, duel: buildDuel(spec, card), play: newPlay(), target: opts.target ?? null, link: !!opts.link, armed: false, day: opts.day || 0, card };
109
+ if (!started) { started = true; count(GAME, 'play', 'duel'); }
110
+ renderArena();
111
+ if (innerWidth < 760) { const m = document.querySelector('.modes'); if (m && m.getBoundingClientRect().top !== 0) m.scrollIntoView({ block: 'start' }); } // whole duel on one phone screen
112
+ }
113
+ function startLevel(n, opts = {}) {
114
+ if (!playable(n, prog, pass.isPro(), !!opts.link)) { if (lockReason(n, prog, pass.isPro()) === 'pass') pass.open(`level-${n}`); else toast(`Clear level ${n - 1} first.`); return; }
115
+ if (n > FREE_LEVELS && pass.isPro()) { prog.kept = Math.max(prog.kept, n); save(); }
116
+ return begin(LEVELS[n - 1], opts);
117
+ }
118
+ function startDaily(day = TODAY(), opts = {}) {
119
+ if (day !== TODAY() && !opts.link && !pass.isPro()) { pass.open('archive'); return; }
120
+ return begin(dailySpec(day), { ...opts, day });
121
+ }
122
+ function restart() { if (!cur) return; cur.play = newPlay(); cur.armed = false; sfx.tap(); renderArena(); }
123
+
124
+ function goalText(d) {
125
+ const bits = [`🎯 Win <b>${d.need}</b> of ${d.max} point${d.max > 1 ? 's' : ''}`, 'ties go to the rival'];
126
+ if (d.arena) bits.push(`🏟️ ${esc(d.arena[0])} +${d.arena[1]}`);
127
+ if (d.boost) bits.push(`⚡ move +${d.boost} once`);
128
+ if (d.comeback) bits.push(`🔥 lose → next +${d.comeback}`);
129
+ if (d.rounds.some((r) => r.pts > 1)) bits.push('👑 = 2 points');
130
+ if (target() != null) bits.push(`<b class="beat">Beat ${target()}</b>`);
131
+ return bits.join(' · ');
132
+ }
133
+ function renderArena() {
134
+ const { duel: d, play: p, spec } = cur, R = spec.rival, F = FRAMES[R.rarity] || FRAMES.common;
135
+ $('goal').innerHTML = goalText(d);
136
+ const title = spec.daily ? `Daily rival #${cur.day}` : `Level ${d.n}${d.boss ? ' · Boss' : ''}`;
137
+ $('rival').style.setProperty('--fa', F.a); $('rival').style.setProperty('--fb', F.b); $('rival').style.setProperty('--fi', F.ink);
138
+ $('rival').innerHTML = `<div class="rv-em">${R.emoji}</div><div class="rv-tx"><small>${esc(title)} · ${spec.twist.icon} ${esc(spec.twist.name)}</small><b>${esc(R.name)}</b><span>${esc(R.type)}-type · ${esc(R.rarity)}</span></div>`;
139
+ $('rounds').innerHTML = d.rounds.map((r, i) => {
140
+ const res = p.log[i], now = i === p.ri;
141
+ const val = r.fog && !res ? `${Math.floor(r.v / 10)}?` : r.v;
142
+ return `<div class="rd${now ? ' now' : ''}${res ? (res.win ? ' won' : ' lost') : ''}${r.fog && !res ? ' fog' : ''}"><small>${r.pts > 1 ? '👑 ' : ''}${esc(r.stat)}</small><b>${val}</b>${res ? `<i>${res.win ? '✓' : '✗'} ${res.v}</i>` : '<i>&nbsp;</i>'}</div>`;
143
+ }).join('');
144
+ $('score-now').textContent = `${p.points} pt${p.points === 1 ? '' : 's'} · ${playScore(p)}`;
145
+ const c = cur.card;
146
+ $('me-name').textContent = c.name; $('me-sub').textContent = `${c.type}-type ${c.kindLabel} · ${c.rarityLabel}`;
147
+ H.drawArt($('me-art'));
148
+ const sb = $('stats'); sb.innerHTML = '';
149
+ d.mine.forEach((v, i) => {
150
+ const b = document.createElement('button'), used = p.used.includes(i), eff = playValue(d, i, cur.armed, p.pending), plus = eff - v;
151
+ b.type = 'button'; b.className = `st${used ? ' used' : ''}${d.arena && d.names[i] === d.arena[0] ? ' home' : ''}`; b.disabled = used || done(d, p); b.dataset.i = i;
152
+ const res = p.log.find((r) => r.stat === i);
153
+ b.innerHTML = `<small>${esc(d.names[i])}${d.arena && d.names[i] === d.arena[0] ? ' 🏟️' : ''}</small><b>${used ? res.v : eff}</b>${!used && plus ? `<em>+${plus}</em>` : ''}${used ? `<i>${res.win ? '✓' : '✗'}</i>` : ''}<kbd>${i + 1}</kbd>`;
154
+ b.onclick = () => pick(i);
155
+ sb.appendChild(b);
156
+ });
157
+ const mv = $('move');
158
+ mv.hidden = !d.boost;
159
+ if (d.boost) {
160
+ mv.disabled = p.boostUsed || done(d, p);
161
+ mv.setAttribute('aria-pressed', String(cur.armed));
162
+ mv.innerHTML = `⚡ ${esc(c.moves[0].name)} <b>+${d.boost}</b>${p.boostUsed ? ' (used)' : cur.armed ? ' (armed: tap a stat)' : ''}`;
163
+ }
164
+ $('pending').hidden = !p.pending;
165
+ $('pending').textContent = p.pending ? `🔥 Underdog: +${p.pending} on your next stat` : '';
166
+ show('arena');
167
+ hint();
168
+ }
169
+ function hint() {
170
+ const h = $('hand');
171
+ const tut = cur && !cur.spec.daily && cur.duel.n === 1 && !prog.stars[1] && cur.play.ri < 3;
172
+ if (!tut) { h.hidden = true; return; }
173
+ // point at the smallest stat that wins this round (the move the tutorial teaches), else the lowest one
174
+ const { duel: d, play: p } = cur, rv = d.rounds[p.ri].v;
175
+ const free = d.mine.map((v, i) => i).filter((i) => !p.used.includes(i)).sort((a, b) => d.mine[a] - d.mine[b]);
176
+ const i = free.find((k) => playValue(d, k, false, p.pending) > rv) ?? free[0];
177
+ const btn = document.querySelector(`#stats .st[data-i="${i}"]`), box = $('arena').getBoundingClientRect(), r = btn.getBoundingClientRect();
178
+ h.style.left = `${r.left - box.left + r.width / 2 - 18}px`; h.style.top = `${r.top - box.top + r.height * 0.55}px`; h.hidden = false;
179
+ }
180
+ function pick(i) {
181
+ const { duel: d, play: p } = cur;
182
+ const res = playRound(d, p, i, cur.armed);
183
+ if (!res) return;
184
+ cur.armed = false;
185
+ renderArena();
186
+ const tile = document.querySelectorAll('#rounds .rd')[res.round];
187
+ if (res.win) { sfx.win(); burst(tile, res.pts > 1 ? 30 : 16); } else { sfx.lose(); shake($('arena')); }
188
+ if (navigator.vibrate) try { navigator.vibrate(res.win ? 8 : [30, 30, 30]); } catch { /* */ }
189
+ if (done(d, p)) setTimeout(finish, 380);
190
+ }
191
+ $('move').onclick = () => { if (!cur || cur.play.boostUsed) return; cur.armed = !cur.armed; sfx.tap(); renderArena(); };
192
+
193
+ // ------------------------------------------------------------------ result
194
+ function finish() {
195
+ const { duel: d, play: p, spec } = cur, sc = playScore(p), st = stars(p.points, d);
196
+ let line = '';
197
+ if (spec.daily) {
198
+ if (cur.day === TODAY()) {
199
+ daily.streak = bumpStreak(daily.streak, cur.day);
200
+ const prev = daily.res && daily.res.day === cur.day ? daily.res : null;
201
+ if (!prev || sc > prev.score) daily.res = { day: cur.day, score: sc, stars: st, grid: grid(p) };
202
+ store('pawfoil:daily', daily);
203
+ showStreak();
204
+ }
205
+ count(GAME, 'win', 'daily');
206
+ } else {
207
+ const before = prog.reached;
208
+ prog = recordLevel(prog, d.n, st, sc, pass.isPro()); save();
209
+ if (st) count(GAME, 'win', `level-${d.n}`);
210
+ if (prog.reached > before && d.n === FREE_LEVELS) line = 'You cleared every free level! Levels 21-30 come with the Fun Pass.';
211
+ }
212
+ const beat = target() != null ? (sc > target() ? `<p class="beat ok">You beat ${target()}! 🎉</p>` : `<p class="beat">Target was ${target()}. ${target() - sc + 1} more to beat it.</p>`) : '';
213
+ const nextN = d.n + 1, nextOk = !spec.daily && st > 0 && nextN <= LEVELS.length;
214
+ const nextWhy = nextOk ? lockReason(nextN, prog, pass.isPro()) : null;
215
+ $('result').innerHTML = `<div class="res-stars">${[0, 1, 2].map((k) => `<span class="${k < st ? 'on' : ''}">★</span>`).join('')}</div>
216
+ <h3>${st ? (st === 3 ? 'Perfect duel!' : 'Duel won!') : 'Not this time'}</h3>
217
+ <p class="res-grid">${grid(p)}</p>
218
+ <p><b>${p.points}/${d.max}</b> points (needed ${d.need}, best possible ${d.opt}) · score <b>${sc}</b></p>${beat}${line ? `<p>${esc(line)}</p>` : ''}
219
+ <div class="row res-btns">${nextOk ? `<button class="btn" id="r-next" type="button">${nextWhy === 'pass' ? '🔒 Level ' + nextN + ': Fun Pass' : '▶ Next: level ' + nextN}</button>` : ''}
220
+ <button class="btn${nextOk ? ' ghost' : ''}" id="r-retry" type="button">↻ Retry</button><button class="btn ghost" id="r-share" type="button">Share result</button><button class="btn ghost" id="r-map" type="button">🗺 Map</button></div>`;
221
+ show('result');
222
+ if (st) { sfx.clear(st); burst($('result').querySelector('.res-stars'), 40); } else { sfx.fail(); shake($('result')); }
223
+ if ($('r-next')) $('r-next').onclick = () => (nextWhy === 'pass' ? pass.open(`level-${nextN}`) : startLevel(nextN));
224
+ $('r-retry').onclick = () => { restart(); };
225
+ $('r-map').onclick = renderMap;
226
+ $('r-share').onclick = () => shareResult();
227
+ if (st && (spec.daily || d.n >= 5)) pass.afterWin($('result'), spec.daily ? 'daily' : `level-${d.n}`); // not on the first tutorial levels
228
+ }
229
+
230
+ export function shareText(c = cur) {
231
+ const { duel: d, play: p, spec } = c, st = stars(p.points, d), sc = playScore(p);
232
+ const head = spec.daily ? `Pawfoil Daily #${c.day}` : `Pawfoil Duel · Level ${d.n}`;
233
+ const streak = spec.daily ? currentStreak(daily.streak, TODAY()) : 0;
234
+ return { text: `${head} ${'⭐'.repeat(st)}${'☆'.repeat(3 - st)}\n${c.card.name} vs ${spec.rival.name}: ${grid(p)} ${p.points}/${d.max} · ${sc}${streak ? `\n🔥 ${streak}-day streak` : ''}\nBeat my score:`,
235
+ path: linkPath(PATH, spec.daily ? { seed: c.day, score: sc } : { lvl: d.n, score: sc }) };
236
+ }
237
+ async function shareResult() {
238
+ const { text, path } = shareText();
239
+ const blob = await canvasBlob(scoreCard());
240
+ await share(GAME, text, path, blob, 'pawfoil-duel.png');
241
+ count(GAME, 'share', cur.spec.daily ? 'daily' : 'duel');
242
+ }
243
+ /** 1080x1080 result card: no photo (it stays on your device), just names, emoji, grid and score. */
244
+ function scoreCard() {
245
+ const c = document.createElement('canvas'); c.width = 1080; c.height = 1080;
246
+ const g = c.getContext('2d'), { duel: d, play: p, spec } = cur, st = stars(p.points, d), F = FRAMES[cur.card.rarity] || FRAMES.common;
247
+ const bg = g.createLinearGradient(0, 0, 1080, 1080); bg.addColorStop(0, '#1B1430'); bg.addColorStop(1, '#3A1F5C'); g.fillStyle = bg; g.fillRect(0, 0, 1080, 1080);
248
+ g.textAlign = 'center'; g.fillStyle = '#FFE9A8'; g.font = '900 64px system-ui, sans-serif';
249
+ g.fillText(spec.daily ? `Daily rival #${cur.day}` : `Duel ladder · level ${d.n}`, 540, 120);
250
+ const card = (x, em, name, sub, col) => {
251
+ g.fillStyle = col.a; rr(g, x, 190, 400, 440, 30); g.fill(); g.fillStyle = 'rgba(255,255,255,.5)'; rr(g, x + 16, 206, 368, 408, 22); g.fill();
252
+ g.font = '170px system-ui, "Apple Color Emoji", "Segoe UI Emoji", sans-serif'; g.fillStyle = '#000'; g.fillText(em, x + 200, 420);
253
+ g.fillStyle = col.ink; g.font = '900 44px system-ui, sans-serif'; g.fillText(name.slice(0, 14), x + 200, 520); g.font = '700 28px system-ui, sans-serif'; g.fillText(sub, x + 200, 570);
254
+ };
255
+ card(90, cur.card.emoji, cur.card.name, `${cur.card.rarityLabel} ${cur.card.kindLabel}`, F);
256
+ card(590, spec.rival.emoji, spec.rival.name, `${spec.rival.type}-type`, FRAMES[spec.rival.rarity] || FRAMES.common);
257
+ g.fillStyle = '#fff'; g.font = '900 60px system-ui, sans-serif'; g.fillText('VS', 540, 430);
258
+ p.log.forEach((r, i) => { const n = p.log.length, x = 540 - (n * 110 - 20) / 2 + i * 110; g.fillStyle = r.win ? (r.pts > 1 ? '#FFB547' : '#2FD3A0') : '#FF5C5C'; rr(g, x, 680, 90, 90, 18); g.fill(); });
259
+ g.fillStyle = '#FFE9A8'; g.font = '900 90px system-ui, sans-serif'; g.fillText('★'.repeat(st) + '☆'.repeat(3 - st), 540, 890);
260
+ g.fillStyle = '#fff'; g.font = '800 46px system-ui, sans-serif'; g.fillText(`${p.points}/${d.max} points · score ${playScore(p)}`, 540, 960);
261
+ g.font = '600 30px system-ui, sans-serif'; g.globalAlpha = 0.8; g.fillText('Beat it: cybermaxtools.com/games/pawfoil', 540, 1030); g.globalAlpha = 1;
262
+ return c;
263
+ }
264
+
265
+ // ------------------------------------------------------------------ setup
266
+ function setMute() { $('mute').textContent = muted ? '🔇' : '🔊'; $('mute').setAttribute('aria-pressed', String(muted)); }
267
+ export function openDuel() { tab('duel'); if (!cur || $('map').hidden === false) renderMap(); }
268
+ function tab(which) {
269
+ const duel = which === 'duel';
270
+ $('duel').hidden = !duel; $('mk').hidden = duel;
271
+ $('tab-duel').setAttribute('aria-selected', String(duel)); $('tab-make').setAttribute('aria-selected', String(!duel));
272
+ store('pawfoil:tab', which);
273
+ }
274
+
275
+ export function initLadder(hooks) {
276
+ H = hooks;
277
+ showStreak();
278
+ setMute();
279
+ $('mute').onclick = () => { muted = !muted; store('pawfoil:mute', muted); setMute(); sfx.tap(); };
280
+ $('restart').onclick = restart;
281
+ $('to-map').onclick = renderMap;
282
+ $('tab-duel').onclick = () => { tab('duel'); renderMap(); };
283
+ $('tab-make').onclick = () => tab('make');
284
+ $('daily-tile').onclick = () => startDaily();
285
+ $('daily-past').onclick = () => {
286
+ const n = Number($('daily-num').value);
287
+ if (!Number.isInteger(n) || n < 1 || n > TODAY()) { toast(`Pick a daily from 1 to ${TODAY()}.`); return; }
288
+ startDaily(n);
289
+ };
290
+ $('daily-num').max = String(TODAY()); $('daily-num').value = String(Math.max(1, TODAY() - 1));
291
+ document.addEventListener('keydown', (e) => {
292
+ if ($('duel').hidden || e.target.closest('input,textarea') || e.metaKey || e.ctrlKey || e.altKey) return;
293
+ if (/^[1-6]$/.test(e.key) && !$('arena').hidden) { e.preventDefault(); pick(Number(e.key) - 1); }
294
+ else if ((e.key === 'r' || e.key === 'R') && cur) { e.preventDefault(); restart(); }
295
+ else if ((e.key === 'm' || e.key === 'M') && cur && cur.duel.boost) $('move').click();
296
+ });
297
+ addEventListener('resize', () => { if (cur && !$('arena').hidden) hint(); });
298
+ pass.onChange((pro) => { if (pro) { prog = keepWithPass(prog); store('pawfoil:ladder', prog); } if (!$('duel').hidden && !$('map').hidden) renderMap(); });
299
+ // beat-my-score links: ?lvl=<n>&score=<n> or ?seed=<daily #>&score=<n>
300
+ const L = parseLink(location.search, TODAY() + 1);
301
+ if (L.lvl || L.seed) {
302
+ tab('duel');
303
+ if (L.lvl) {
304
+ if (playable(L.lvl, prog, pass.isPro(), true)) startLevel(L.lvl, { target: L.score, link: true });
305
+ else { renderMap(); pass.open(`link-level-${L.lvl}`); }
306
+ } else startDaily(L.seed, { target: L.score, link: true });
307
+ if (L.score != null) toast(`A friend scored ${L.score}. Beat it!`, 3000);
308
+ } else if (store('pawfoil:tab') === 'duel') { tab('duel'); renderMap(); }
309
+ }
310
+
311
+ // test/screenshot hooks (no effect on normal play)
312
+ window.__pawDuel = { get cur() { return cur; }, get prog() { return prog; }, shareText: () => shareText(), scoreCard: () => scoreCard().toDataURL(), pick, restart, renderMap, startLevel, startDaily };
pawfoil/levels.js ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Pawfoil Duel Ladder: pure game logic (no DOM). Your pet card's six stats duel a ladder of 30 hand-made rival cards.
2
+ // Each duel: the rival shows the 5 (boss: 6) stat cards it will play, in order. You answer each with one of your own
3
+ // stats (each once). Higher number wins the round; ties go to the rival. Plan the match-ups, sacrifice your weakest stat
4
+ // on rounds you can't win. Rival numbers are set relative to YOUR card's stats (by rank), so every pet, Common or
5
+ // Legendary, gets the same fair puzzle. A new twist every 5 levels, a boss every 10th. (c) 2026 CyberMax.
6
+ import { rng, hash } from './cmx.js';
7
+
8
+ export const FREE_LEVELS = 20;
9
+ export const STAT_NAMES = ['Cuteness', 'Chaos', 'Snack drive', 'Nap power', 'Zoomies', 'Loyalty']; // same as core.js STATS
10
+
11
+ // Twists: one new rule every 5 levels (shown on the map and in the goal line).
12
+ export const TWISTS = [
13
+ { from: 1, id: 'basics', name: 'First duels', icon: '🃏', rule: 'Win rounds with a higher number. Ties go to the rival.' },
14
+ { from: 6, id: 'arena', name: 'Home turf', icon: '🏟️', rule: 'One stat gets a home-turf bonus.' },
15
+ { from: 11, id: 'fog', name: 'Fog', icon: '🌫️', rule: 'Some rival cards are face down: you only see the tens digit.' },
16
+ { from: 16, id: 'boost', name: 'Power move', icon: '⚡', rule: 'Once per duel, your move adds a bonus to one stat.' },
17
+ { from: 21, id: 'crown', name: 'Crown rounds', icon: '👑', rule: 'Crown rounds are worth 2 points.' },
18
+ { from: 26, id: 'comeback', name: 'Underdog', icon: '🔥', rule: 'Lose a round and your next stat gets a bonus.' },
19
+ ];
20
+ export const twistOf = (n) => [...TWISTS].reverse().find((t) => n >= t.from) || TWISTS[0];
21
+
22
+ // 30 rival cards (original characters). Bosses (10, 20, 30) are every pet's nemeses.
23
+ export const RIVALS = [
24
+ ['Pip', '🐹', 'Snack', 'common'], ['Noodle', '🌭', 'Zoomies', 'common'], ['Miso', '🐱', 'Nap', 'common'], ['Clover', '🐰', 'Hop', 'common'], ['Kiwi', '🐦', 'Song', 'common'],
25
+ ['Duchess Fluff', '🐈', 'Royal', 'rare'], ['Turbo', '🐕', 'Zoomies', 'rare'], ['Pickles', '🐹', 'Snack', 'rare'], ['Captain Whiskers', '😼', 'Chaos', 'rare'], ['The Vacuum', '🌀', 'Boss', 'legendary'],
26
+ ['Shadow', '🐈‍⬛', 'Shadow', 'rare'], ['Mochi', '🐕', 'Loyal', 'rare'], ['Pepper', '🦜', 'Chaos', 'rare'], ['Gizmo', '🦎', 'Mystery', 'rare'], ['Waffles', '🐶', 'Snack', 'epic'],
27
+ ['Biscotti', '🐶', 'Nap', 'epic'], ['Sir Hops-a-Lot', '🐰', 'Royal', 'epic'], ['Luna', '🐺', 'Shadow', 'epic'], ['Mango', '🐤', 'Sky', 'epic'], ['Bath Time', '🛁', 'Boss', 'legendary'],
28
+ ['Tofu', '🐢', 'Nap', 'epic'], ['Ziggy', '🦔', 'Chaos', 'epic'], ['Princess Purrsia', '🐈', 'Royal', 'epic'], ['Rocket', '🐕', 'Zoomies', 'epic'], ['Bubbles', '🐠', 'Mystery', 'epic'],
29
+ ['Nugget', '🐥', 'Fluff', 'legendary'], ['Professor Hoot', '🦉', 'Sky', 'legendary'], ['Thunder Paws', '🐕‍🦺', 'Loyal', 'legendary'], ['Empress Meowgaret', '🐈', 'Royal', 'legendary'], ['The Vet', '🩺', 'Boss', 'legendary'],
30
+ ].map(([name, emoji, type, rarity]) => ({ name, emoji, type, rarity }));
31
+
32
+ // Hand-tuned level table. A round is [rank, delta, flags]: the rival plays (your rank-th best stat + delta).
33
+ // rank 0 = your highest stat, 5 = your lowest. flags: f = face down (fog), 2 = crown round (2 points).
34
+ // need = points to clear (1 star); 3 stars = the best possible result for your card (found by solve()).
35
+ const L = (rounds, need, o = {}) => ({ rounds, need, ...o });
36
+ export const LEVELS = [
37
+ // 1-5 First duels: see every rival card, match them up.
38
+ L([[5, -3], [4, -3], [3, -3], [2, -3], [0, 6]], 2),
39
+ L([[0, 4], [3, -2], [1, -2], [4, -2], [2, -2]], 2),
40
+ L([[1, -1], [0, -1], [2, -1], [3, -1], [4, -1]], 3),
41
+ L([[2, 1], [0, -2], [4, 1], [1, -2], [5, 0]], 2),
42
+ L([[3, 2], [1, 1], [0, 8], [2, 1], [4, 1]], 2),
43
+ // 6-10 Home turf: one stat gets a bonus. 10 = boss (6 rounds, no spare stat).
44
+ L([[0, 5], [2, -1], [3, -1], [4, -1], [1, -1]], 3, { arena: ['Zoomies', 15] }),
45
+ L([[0, 3], [0, -3], [1, 2], [3, 0], [5, 0]], 2, { arena: ['Nap power', 15] }),
46
+ L([[1, 3], [2, 3], [3, 3], [4, 3], [0, 10]], 2, { arena: ['Snack drive', 12] }),
47
+ L([[0, 12], [1, 1], [2, 1], [3, 1], [5, -5]], 3, { arena: ['Chaos', 15] }),
48
+ L([[0, -1], [1, -1], [2, 1], [3, 1], [4, 1], [5, 1]], 4, { arena: ['Loyalty', 10], boss: true }),
49
+ // 11-15 Fog: some rival cards are face down.
50
+ L([[3, -2, 'f'], [1, -2], [0, 6], [2, -2, 'f'], [4, -2]], 3),
51
+ L([[0, -1, 'f'], [2, 2], [1, -1], [4, 2, 'f'], [5, -1]], 3),
52
+ L([[2, 1, 'f'], [1, 1, 'f'], [3, 1], [0, 9], [4, 1, 'f']], 3),
53
+ L([[0, 0, 'f'], [1, 0, 'f'], [2, 0, 'f'], [3, 0], [4, 0]], 3),
54
+ L([[0, 4, 'f'], [1, 3], [2, 3, 'f'], [3, 3], [4, 3, 'f']], 3, { arena: ['Cuteness', 10] }),
55
+ // 16-20 Power move: once per duel, your card's move adds a bonus.
56
+ L([[0, 8], [1, -1], [2, -1], [3, -1], [4, -1]], 4, { boost: 15 }),
57
+ L([[0, 10], [0, 6], [1, -1], [2, -1], [3, -1]], 3, { boost: 12 }),
58
+ L([[1, 4], [0, 12], [2, 4], [3, 4], [5, 4]], 3, { boost: 20 }),
59
+ L([[0, 3, 'f'], [0, -2], [2, 5, 'f'], [3, 2], [4, 2]], 3, { boost: 15 }),
60
+ L([[0, 6], [1, 2], [2, 2], [0, -3], [3, 2], [4, 2]], 4, { boost: 15, arena: ['Nap power', 10], boss: true }),
61
+ // 21-25 Crown rounds: worth 2 points.
62
+ L([[0, -4], [1, -1], [2, -1], [3, -1], [0, -2, '2']], 4),
63
+ L([[1, -2], [0, 7, '2'], [2, -1], [0, -2], [3, -1]], 4, { boost: 10 }),
64
+ L([[1, -1, 'f'], [2, -1], [0, -1], [3, -1], [1, -1, '2f']], 4),
65
+ L([[0, 8, '2'], [0, 0], [1, 0, '2'], [2, 0], [3, 0]], 4, { boost: 10 }),
66
+ L([[0, -1], [1, -1], [2, -1], [3, -1], [0, -3, '2']], 4),
67
+ // 26-30 Underdog: losing a round powers up your next stat. 30 = final boss with every twist.
68
+ L([[3, -2], [0, 6], [1, -1], [2, -1], [4, -1]], 3, { comeback: 12 }),
69
+ L([[4, -3], [3, -2], [0, 9, '2'], [1, -1], [2, -1]], 4, { comeback: 12 }),
70
+ L([[1, -2, 'f'], [0, 8], [2, -1], [0, 7, 'f'], [3, -1]], 3, { comeback: 10, arena: ['Zoomies', 10] }),
71
+ L([[2, -2], [0, 12], [1, 5, '2'], [3, -1], [0, -1]], 4, { comeback: 8, boost: 10 }),
72
+ L([[0, 10], [0, 3, '2'], [1, 4, 'f'], [2, 4], [0, -2, 'f'], [3, 4, '2']], 5, { comeback: 10, boost: 12, arena: ['Cuteness', 8], boss: true }),
73
+ ].map((lv, i) => ({ ...lv, n: i + 1, rival: RIVALS[i], twist: twistOf(i + 1) }));
74
+
75
+ /** Your six stats sorted high to low (ties keep card order). */
76
+ export function ranked(card) {
77
+ return card.stats.map((st, i) => ({ s: st.s, v: st.v, i })).sort((a, b) => b.v - a.v || a.i - b.i);
78
+ }
79
+
80
+ /** Build a concrete duel for a level (or daily spec) and a card: rival numbers, flags, need and the best result. */
81
+ export function buildDuel(spec, card) {
82
+ const r = ranked(card);
83
+ const rounds = spec.rounds.map(([k, d, f = ''], i) => ({
84
+ v: Math.max(1, r[Math.max(0, Math.min(5, k))].v + d), fog: f.includes('f'), pts: f.includes('2') ? 2 : 1,
85
+ stat: STAT_NAMES[(i + (spec.n || 0)) % 6],
86
+ }));
87
+ const duel = { n: spec.n || 0, rival: spec.rival, twist: spec.twist, rounds, arena: spec.arena || null, boost: spec.boost || 0, comeback: spec.comeback || 0, boss: !!spec.boss,
88
+ mine: card.stats.map((st) => st.v), names: card.stats.map((st) => st.s) };
89
+ const best = solve(duel);
90
+ duel.max = rounds.reduce((a, b) => a + b.pts, 0);
91
+ duel.opt = best.points;
92
+ duel.optScore = best.score;
93
+ duel.need = Math.max(1, Math.min(spec.need, best.points));
94
+ return duel;
95
+ }
96
+
97
+ /** Value of playing stat i (with optional power move) given the current bonus state. */
98
+ export function playValue(duel, i, useBoost, pending = 0) {
99
+ let v = duel.mine[i];
100
+ if (duel.arena && duel.names[i] === duel.arena[0]) v += duel.arena[1];
101
+ if (useBoost) v += duel.boost;
102
+ return v + pending;
103
+ }
104
+
105
+ /** Best possible (points, then score) for a duel: exhaustive search, at most 6! x boost choices. */
106
+ export function solve(duel) {
107
+ const R = duel.rounds.length, n = duel.mine.length;
108
+ let best = { points: -1, score: -1 };
109
+ const go = (ri, used, boostLeft, pending, pts, margin) => {
110
+ if (ri === R) { const sc = score(pts, margin); if (pts > best.points || (pts === best.points && sc > best.score)) best = { points: pts, score: sc }; return; }
111
+ const rv = duel.rounds[ri];
112
+ for (let i = 0; i < n; i++) {
113
+ if (used & (1 << i)) continue;
114
+ for (const b of boostLeft ? [false, true] : [false]) {
115
+ const v = playValue(duel, i, b, pending), win = v > rv.v;
116
+ go(ri + 1, used | (1 << i), boostLeft && !b, !win && duel.comeback ? duel.comeback : 0, pts + (win ? rv.pts : 0), margin + (win ? v - rv.v : 0));
117
+ }
118
+ }
119
+ };
120
+ go(0, 0, !!duel.boost, 0, 0, 0);
121
+ return best;
122
+ }
123
+
124
+ /** Score = 100 per point + the total winning margin (a tie-breaker that rewards strong wins). */
125
+ export const score = (points, margin) => points * 100 + margin;
126
+
127
+ /** Fresh play state for a duel. */
128
+ export const newPlay = () => ({ ri: 0, used: [], boostUsed: false, pending: 0, points: 0, margin: 0, log: [] });
129
+
130
+ /** Play stat i in the current round. Returns the round result; mutates play. */
131
+ export function playRound(duel, play, i, useBoost = false) {
132
+ if (play.ri >= duel.rounds.length || play.used.includes(i) || i < 0 || i >= duel.mine.length) return null;
133
+ const b = !!(useBoost && duel.boost && !play.boostUsed);
134
+ const rv = duel.rounds[play.ri], v = playValue(duel, i, b, play.pending), win = v > rv.v;
135
+ const res = { round: play.ri, stat: i, v, rival: rv.v, win, tie: v === rv.v, pts: win ? rv.pts : 0, boost: b, bonus: play.pending };
136
+ play.used.push(i); play.ri++; if (b) play.boostUsed = true;
137
+ play.pending = !win && duel.comeback ? duel.comeback : 0;
138
+ if (win) { play.points += rv.pts; play.margin += v - rv.v; }
139
+ play.log.push(res);
140
+ return res;
141
+ }
142
+ export const done = (duel, play) => play.ri >= duel.rounds.length;
143
+ export const playScore = (play) => score(play.points, play.margin);
144
+
145
+ /** 0-3 stars: 1 = cleared (need), 2 = cleared and at most one point short of the best, 3 = the best possible for your card. */
146
+ export function stars(points, duel) {
147
+ if (points < duel.need) return 0;
148
+ if (points >= duel.opt) return 3;
149
+ return points >= duel.opt - 1 ? 2 : 1;
150
+ }
151
+
152
+ // ------------------------------------------------------------------ daily rival
153
+ /** The daily duel for puzzle number `day` (same rival and rounds for everyone that day). */
154
+ export function dailySpec(day) {
155
+ const r = rng(hash(`pawfoil-daily:${day}`));
156
+ const rival = RIVALS[Math.floor(r() * RIVALS.length)];
157
+ const kinds = ['basics', 'arena', 'fog', 'boost', 'crown', 'comeback'];
158
+ const tw = kinds[Math.floor(r() * kinds.length)];
159
+ const rounds = [];
160
+ for (let i = 0; i < 5; i++) {
161
+ const k = Math.floor(r() * 5);
162
+ const d = -4 + Math.floor(r() * 10) + (k === 0 && r() < 0.5 ? 6 : 0);
163
+ rounds.push([k, d, tw === 'fog' && r() < 0.5 ? 'f' : tw === 'crown' && i === 4 - Math.floor(r() * 2) ? '2' : '']);
164
+ }
165
+ const o = {};
166
+ if (tw === 'arena') o.arena = [STAT_NAMES[1 + Math.floor(r() * 5)], 10 + Math.floor(r() * 3) * 2];
167
+ if (tw === 'boost') o.boost = 10 + Math.floor(r() * 3) * 5;
168
+ if (tw === 'comeback') o.comeback = 8 + Math.floor(r() * 3) * 2;
169
+ return { n: 0, day, rounds, need: 3, rival, twist: TWISTS.find((t) => t.id === tw), daily: true, ...o };
170
+ }
171
+
172
+ // ------------------------------------------------------------------ progression (saved by the UI with store())
173
+ export const newProgress = () => ({ reached: 1, kept: 0, stars: {}, best: {} });
174
+ export function cleanProgress(p) {
175
+ const o = newProgress();
176
+ if (!p || typeof p !== 'object') return o;
177
+ const int = (x, lo, hi) => (Number.isInteger(x) && x >= lo && x <= hi ? x : null);
178
+ o.reached = int(p.reached, 1, LEVELS.length + 1) || 1;
179
+ o.kept = int(p.kept, 0, LEVELS.length + 1) || 0;
180
+ for (const [k, v] of Object.entries(p.stars || {})) if (int(+k, 1, LEVELS.length) && int(v, 0, 3) !== null) o.stars[+k] = v;
181
+ for (const [k, v] of Object.entries(p.best || {})) if (int(+k, 1, LEVELS.length) && int(v, 0, 9999) !== null) o.best[+k] = v;
182
+ return o;
183
+ }
184
+ /** Can level n be played? Free: 1-20 once reached (or opened from a friend's link). 21+: Fun Pass, or already reached
185
+ * while the pass was on (never taken away). */
186
+ export function playable(n, prog, pro, viaLink = false) {
187
+ if (!Number.isInteger(n) || n < 1 || n > LEVELS.length) return false;
188
+ if (n > FREE_LEVELS && !pro && n > prog.kept) return false;
189
+ return n <= prog.reached || (viaLink && n <= FREE_LEVELS) || (viaLink && pro);
190
+ }
191
+ /** Why a level is closed: 'pass' (needs the Fun Pass) or 'order' (clear the one before first). */
192
+ export const lockReason = (n, prog, pro) => (playable(n, prog, pro) ? null : n > FREE_LEVELS && !pro && n > prog.kept ? 'pass' : 'order');
193
+ /** Record a finished level; returns the updated progress (never lowers stars, best or reached). */
194
+ export function recordLevel(prog, n, st, sc, pro) {
195
+ const p = cleanProgress(prog);
196
+ if (st > (p.stars[n] || 0)) p.stars[n] = st;
197
+ if (sc > (p.best[n] || 0)) p.best[n] = Math.min(9999, sc);
198
+ if (st > 0) p.reached = Math.max(p.reached, Math.min(LEVELS.length + 1, n + 1));
199
+ if (pro) p.kept = Math.max(p.kept, p.reached);
200
+ return p;
201
+ }
202
+ /** Keep levels reached while the pass is on (called whenever the pass is on). */
203
+ export function keepWithPass(prog) { const p = cleanProgress(prog); p.kept = Math.max(p.kept, p.reached); return p; }
204
+ export const totalStars = (prog) => Object.values(prog.stars).reduce((a, b) => a + b, 0);
205
+
206
+ // ------------------------------------------------------------------ streak (consecutive days the daily was finished)
207
+ export function bumpStreak(st, day) {
208
+ const s = st && Number.isInteger(st.last) ? { last: st.last, streak: Number.isInteger(st.streak) ? st.streak : 0, best: Number.isInteger(st.best) ? st.best : 0 } : { last: 0, streak: 0, best: 0 };
209
+ if (s.last === day) return s;
210
+ s.streak = s.last === day - 1 ? s.streak + 1 : 1;
211
+ s.last = day; s.best = Math.max(s.best, s.streak);
212
+ return s;
213
+ }
214
+ export const currentStreak = (st, day) => (st && Number.isInteger(st.last) && Number.isInteger(st.streak) && st.last >= day - 1 ? st.streak : 0);
215
+
216
+ // ------------------------------------------------------------------ "beat my score" links
217
+ /** Parse ?seed=<daily #>&score=<n>&lvl=<level>. Anything malformed or out of range is ignored. */
218
+ export function parseLink(search, maxDay = 100000) {
219
+ let q;
220
+ try { q = new URLSearchParams(search || ''); } catch { return {}; }
221
+ const int = (k, lo, hi) => { const s = q.get(k); if (s == null || !/^\d{1,6}$/.test(s)) return null; const v = Number(s); return v >= lo && v <= hi ? v : null; };
222
+ const out = {};
223
+ const lvl = int('lvl', 1, LEVELS.length), seed = int('seed', 1, maxDay), sc = int('score', 0, 9999);
224
+ if (lvl) out.lvl = lvl; else if (seed) out.seed = seed;
225
+ if (sc !== null && (out.lvl || out.seed)) out.score = sc;
226
+ return out;
227
+ }
228
+ /** Path (with query) for a beat-my-score link. */
229
+ export function linkPath(base, { lvl, seed, score: sc }) {
230
+ const q = new URLSearchParams();
231
+ if (lvl) q.set('lvl', String(lvl)); else if (seed) q.set('seed', String(seed));
232
+ if (Number.isInteger(sc)) q.set('score', String(sc));
233
+ return `${base}?${q}`;
234
+ }
235
+ /** Emoji result grid: 🟩 won, 🟨 won a crown round, 🟥 lost. */
236
+ export function grid(play) {
237
+ return play.log.map((r) => (r.win ? (r.pts > 1 ? '🟨' : '🟩') : '🟥')).join('');
238
+ }
pawfoil/style.css CHANGED
@@ -16,3 +16,64 @@
16
  .tilt.foil .holo{opacity:.55}
17
  .share{justify-content:center}
18
  .controls .chips{flex-wrap:wrap!important;overflow:visible!important;margin:0!important;padding:0!important}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  .tilt.foil .holo{opacity:.55}
17
  .share{justify-content:center}
18
  .controls .chips{flex-wrap:wrap!important;overflow:visible!important;margin:0!important;padding:0!important}
19
+ /* Duel ladder */
20
+ .modes{display:flex;gap:6px;margin:0 0 14px;background:var(--chip);padding:4px;border-radius:14px;width:max-content;max-width:100%}
21
+ .mode{border:0;background:none;color:var(--ink);font:inherit;font-weight:800;font-size:15px;padding:10px 16px;border-radius:11px;cursor:pointer;min-height:44px}
22
+ .mode[aria-selected=true]{background:var(--card);box-shadow:var(--shadow)}
23
+ .duel{max-width:620px;margin:0 auto}
24
+ .dbar{display:flex;gap:8px;align-items:flex-start;justify-content:space-between;margin-bottom:10px}
25
+ .goal{margin:0;font-size:15px;line-height:1.4;padding:8px 12px;border-radius:12px;background:var(--card);border:1px solid var(--line);flex:1}
26
+ .goal .beat{color:var(--acc)}
27
+ .dtools{display:flex;gap:4px;align-items:center;flex:0 0 auto}
28
+ .icon-btn{min-width:44px;min-height:44px;border-radius:12px;border:1.5px solid var(--line);background:var(--card);color:var(--ink);font-size:20px;cursor:pointer}
29
+ .badge{font-weight:800;font-size:15px;padding:0 6px;white-space:nowrap}
30
+ .daily{display:flex;flex-direction:column;gap:6px;margin-bottom:10px}
31
+ .daily-tile{display:flex;flex-direction:column;gap:2px;text-align:left;width:100%;padding:14px 16px;border-radius:16px;border:0;cursor:pointer;font:inherit;color:#11141B;background:linear-gradient(135deg,#FFE9A8,#E8A93A);box-shadow:var(--shadow)}
32
+ .daily-tile b{font-size:18px}.daily-tile span{font-size:14px}
33
+ .past{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.past input{width:80px;font:inherit;padding:6px 8px;border-radius:8px;border:1.5px solid var(--line);background:var(--bg);color:var(--ink)}
34
+ .maprule{margin:6px 0 4px}
35
+ .tier{margin:14px 0 6px;font-size:14px}.tier b{font-size:16px}.tier span{color:var(--muted)}.tier em{font-style:normal;font-weight:800;font-size:12px;background:linear-gradient(135deg,#FFB547,#FF6A3D);color:#11141B;border-radius:999px;padding:1px 7px}
36
+ .lvrow{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}
37
+ .lv{display:flex;flex-direction:column;align-items:center;gap:0;padding:8px 2px 6px;border-radius:14px;border:1.5px solid var(--line);background:var(--card);color:var(--ink);font:inherit;cursor:pointer;min-height:76px}
38
+ .lv .em{font-size:22px;line-height:1.1}.lv b{font-size:16px}.lv small{font-size:12px;color:#E8A93A;letter-spacing:1px}
39
+ .lv.done{border-color:#E8A93A}.lv.boss{background:linear-gradient(160deg,var(--card),rgba(155,91,232,.18));border-color:#9B5BE8}
40
+ .lv.locked{opacity:.5}.lv.locked small{color:var(--muted)}
41
+ .arena{position:relative;display:flex;flex-direction:column;gap:10px}
42
+ .rival{display:flex;gap:12px;align-items:center;padding:10px 14px;border-radius:18px;background:linear-gradient(135deg,var(--fa),var(--fb));color:var(--fi)}
43
+ .rv-em{font-size:44px;line-height:1;background:rgba(255,255,255,.55);border-radius:14px;padding:6px 10px}
44
+ .rv-tx{display:flex;flex-direction:column;line-height:1.25}.rv-tx b{font-size:20px}.rv-tx small,.rv-tx span{font-size:13px;font-weight:700;opacity:.85}
45
+ .rounds{display:grid;grid-template-columns:repeat(auto-fit,minmax(0,1fr));gap:6px}
46
+ .rd{display:flex;flex-direction:column;align-items:center;padding:6px 2px;border-radius:12px;background:var(--card);border:2px solid var(--line);min-width:0}
47
+ .rd small{font-size:11px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
48
+ .rd b{font-size:26px;line-height:1.1}.rd i{font-style:normal;font-size:12px;font-weight:800}
49
+ .rd.now{border-color:var(--acc);box-shadow:0 0 0 3px rgba(255,106,61,.25);animation:pulse 1s ease-in-out infinite}
50
+ .rd.won{background:rgba(47,211,160,.16);border-color:var(--ok)}.rd.won i{color:var(--ok)}
51
+ .rd.lost{background:rgba(255,92,92,.12);border-color:var(--bad)}.rd.lost i{color:var(--bad)}
52
+ .rd.fog b{color:var(--muted)}
53
+ @keyframes pulse{50%{transform:translateY(-2px)}}
54
+ .pending{margin:0;text-align:center;font-weight:800;color:var(--acc)}
55
+ .me{display:flex;gap:12px;align-items:center}
56
+ .me canvas{width:96px;height:64px;border-radius:10px;object-fit:cover;flex:0 0 auto;background:#1B1430}
57
+ .me div{display:flex;flex-direction:column;line-height:1.3}.me b{font-size:18px}
58
+ .stats{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
59
+ .st{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0;min-height:72px;padding:6px 4px;border-radius:14px;border:2px solid var(--line);background:var(--card);color:var(--ink);font:inherit;cursor:pointer;touch-action:manipulation}
60
+ .st:hover:not(:disabled){border-color:var(--acc)}.st:active:not(:disabled){transform:scale(.97)}
61
+ .st small{font-size:12px;font-weight:700;color:var(--muted)}.st b{font-size:26px;line-height:1.1}
62
+ .st em{position:absolute;top:4px;right:6px;font-style:normal;font-size:11px;font-weight:800;color:var(--ok)}
63
+ .st i{font-style:normal;font-weight:900}.st.home{border-color:#5BA8E8}
64
+ .st kbd{position:absolute;top:4px;left:6px;font:700 10px system-ui;color:var(--muted);opacity:.7}
65
+ .st.used{opacity:.45;cursor:default}
66
+ .move[aria-pressed=true]{background:var(--acc);color:#11141B;border-color:var(--acc)}
67
+ .hand{position:absolute;font-size:36px;pointer-events:none;animation:tapme .9s ease-in-out infinite;z-index:3;filter:drop-shadow(0 3px 4px rgba(0,0,0,.35))}
68
+ @keyframes tapme{0%,100%{transform:translateY(0)}50%{transform:translateY(-12px)}}
69
+ .result{text-align:center;margin-top:4px}
70
+ .res-stars{font-size:54px;letter-spacing:6px;line-height:1}.res-stars span{color:var(--line)}.res-stars span.on{color:#E8A93A}
71
+ .result h3{margin:6px 0 2px;font-size:24px}.res-grid{font-size:26px;letter-spacing:2px;margin:4px 0}
72
+ .beat{font-weight:800}.beat.ok{color:var(--ok)}
73
+ .res-btns{justify-content:center}
74
+ .shake{animation:shake .32s linear}
75
+ @keyframes shake{20%{transform:translateX(-7px)}40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(3px)}}
76
+ #fx{position:fixed;inset:0;width:100vw;height:100vh;pointer-events:none;z-index:50}
77
+ @media (prefers-reduced-motion:reduce){.shake,.rd.now,.hand{animation:none}}
78
+ @media (max-width:420px){.rd b{font-size:22px}.st b{font-size:24px}.goal{font-size:14px}}
79
+ .lbl{margin:0 0 -6px;font-size:12px;font-weight:800;letter-spacing:.04em;text-transform:uppercase;color:var(--muted)}
pawfoil/sw.js CHANGED
@@ -1,8 +1,8 @@
1
  // CyberMax game service worker: the game works offline after the first visit. Cache-first for the game's own files,
2
  // network-first for the page itself (so updates arrive), never caches API calls or other sites. (c) 2026 CyberMax.
3
  const GAME = 'pawfoil';
4
- const CACHE = `cmx-${GAME}-aef686760a`;
5
- const FILES = ["index.html", "cmx.js", "core.js", "fun.css", "funpass.js", "game.js", "icon-192.png", "icon-512.png", "icon-maskable.png", "icon.svg", "index.html", "manifest.webmanifest", "sample.jpg", "style.css"];
6
 
7
  self.addEventListener('install', (e) => {
8
  e.waitUntil(caches.open(CACHE).then((c) => c.addAll(FILES)).then(() => self.skipWaiting()));
 
1
  // CyberMax game service worker: the game works offline after the first visit. Cache-first for the game's own files,
2
  // network-first for the page itself (so updates arrive), never caches API calls or other sites. (c) 2026 CyberMax.
3
  const GAME = 'pawfoil';
4
+ const CACHE = `cmx-${GAME}-06edb7823f`;
5
+ const FILES = ["index.html", "cmx.js", "core.js", "fun.css", "funpass.js", "game.js", "icon-192.png", "icon-512.png", "icon-maskable.png", "icon.svg", "index.html", "ladder.js", "levels.js", "manifest.webmanifest", "sample.jpg", "style.css"];
6
 
7
  self.addEventListener('install', (e) => {
8
  e.waitUntil(caches.open(CACHE).then((c) => c.addAll(FILES)).then(() => self.skipWaiting()));