{
  "slug": "meet-your-mote",
  "version": 9,
  "format": "html",
  "html": "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\">\n<title>Meet Your Mote</title>\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800&family=Patrick+Hand&family=Pixelify+Sans:wght@500&display=swap\">\n<style>\n:root{--bg:#f6eedd;--ink:#4a3424;--soft:#8a6a4f;--shell:#fbf3e3;--shell2:#efe0c4;--butter:#f6d77a;--gold:#e0a92e;--plum:#5a3a5e;--line:#e2cfae}\n*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}\nhtml,body{margin:0}\nbody{background:radial-gradient(ellipse at 50% -10%,#fff8e6 0,var(--bg) 55%,#ead9b9 100%) fixed;color:var(--ink);font:15px/1.45 Nunito,system-ui,sans-serif;min-height:100vh}\nmain{max-width:520px;margin:0 auto;padding:16px 16px 40px}\nh1{font:34px/1 'Patrick Hand',cursive;text-align:center;margin:6px 0 2px}\n.sub{text-align:center;color:var(--soft);margin:0 0 14px}\n/* the compact */\n.compact{position:relative;width:min(100%,380px);margin:0 auto;user-select:none}\n.lid,.base{position:relative;width:100%;aspect-ratio:1;border-radius:50%;background:radial-gradient(circle at 35% 28%,#fffaf0 0,var(--shell) 45%,var(--shell2) 100%);box-shadow:inset 0 -6px 14px #d9c39c88,inset 0 4px 10px #fff,0 10px 24px #8a6a4f33}\n.lid{transform:scaleY(.96)}\n.base{margin-top:-6%;transform:scaleY(.86);z-index:0}\n.hinge{position:relative;z-index:2;width:34%;height:16px;margin:-5% auto 0;background:linear-gradient(#efe0c4,#dcc7a0);border-radius:8px;box-shadow:0 2px 4px #8a6a4f33}\n.screen{position:absolute;left:17%;top:17%;width:66%;aspect-ratio:1;border-radius:14%;overflow:hidden;background:#2a2016;box-shadow:inset 0 0 0 5px #e8d6b4,inset 0 0 0 7px #cdb48a,0 0 0 2px #fff8;touch-action:none;cursor:grab}\n#scr{width:100%;height:100%;image-rendering:pixelated;image-rendering:crisp-edges;display:block}\n.screen::after{content:\"\";position:absolute;inset:0;border-radius:14%;pointer-events:none;background:linear-gradient(140deg,#ffffff22 0,transparent 35%),repeating-linear-gradient(#0000 0 2px,#0000000a 2px 3px)}\n.pad{position:absolute;left:22%;top:20%;width:56%;height:56%;border-radius:22%;background:radial-gradient(circle at 40% 30%,#fffdf6,#f1e4c8);box-shadow:inset 0 2px 6px #c9b28a99,inset 0 -2px 4px #fff;touch-action:none;cursor:grab}\n.pad span{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font:16px 'Patrick Hand';color:#b9a079;pointer-events:none;transition:opacity .6s}\n.dip{position:absolute;left:50%;top:8%;width:22%;height:9%;transform:translateX(-50%);border-radius:50%;background:radial-gradient(#e6d4b2,#f6ead2);box-shadow:inset 0 2px 4px #c9b28a}\n/* panels */\n.panel{background:#fffaf0;border:2px solid var(--line);border-radius:18px;padding:16px;margin:16px auto 0;max-width:420px;box-shadow:0 6px 18px #8a6a4f1a}\n.panel h2{font:26px/1.1 'Patrick Hand';margin:0 0 6px}\n.row{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}\ninput{flex:1;min-width:150px;font:16px Nunito;padding:9px 12px;border:2px solid var(--line);border-radius:12px;background:#fff;color:var(--ink)}\n.btn{font:800 14px Nunito;color:var(--ink);background:#fffaf0;border:2px solid #b98a5a;border-radius:999px;padding:8px 14px;cursor:pointer;box-shadow:0 2px 0 #b98a5a}\n.btn:active{transform:translateY(2px);box-shadow:none}\n.btn.pri{background:var(--butter)}\n.btn.ghost{border-color:var(--line);box-shadow:none;font-weight:700}\n.btn:disabled{opacity:.5}\n.link{background:none;border:0;color:var(--soft);text-decoration:underline;cursor:pointer;font:14px Nunito;padding:4px}\n.hidden{display:none!important}\n/* birth card */\n.cert .code{font:500 18px 'Pixelify Sans',monospace;letter-spacing:1px;color:var(--plum)}\n.dna{display:flex;height:14px;border-radius:4px;overflow:hidden;margin:8px 0 10px;box-shadow:inset 0 0 0 1px #0001}\n.dna i{flex:1}\n.traits{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;font-size:14px}\n.traits b{color:var(--soft);font-weight:700}\n.once{font:20px/1.2 'Patrick Hand';text-align:center;margin:12px 0 2px;color:#7a5a3a}\n.want{margin-top:14px;padding-top:12px;border-top:1px dashed var(--line)}\n.want p{margin:0 0 6px;font-size:14px}\n.want .btn.on{background:var(--butter)}\n/* nursery */\n.nursery{display:grid;grid-template-columns:repeat(auto-fill,minmax(92px,1fr));gap:10px;margin-top:10px}\n.nm{background:#fff;border:2px solid var(--line);border-radius:14px;padding:6px;text-align:center;cursor:pointer;transition:transform .2s}\n.nm:hover{transform:translateY(-3px)}\n.nm canvas{width:100%;aspect-ratio:1;image-rendering:pixelated;border-radius:10px;display:block;background:#e9d2a8}\n.nm .who{font-weight:800;font-size:13px;margin-top:4px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.nm .cd{font:500 10px 'Pixelify Sans',monospace;color:var(--soft)}\n.badge{font-size:9px;font-weight:800;background:#cfe3f3;color:#2f5a7a;border-radius:5px;padding:0 4px;margin-left:3px;vertical-align:1px}\n.toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,20px);background:#4a3424ee;color:#fffaf0;font:17px 'Patrick Hand';padding:8px 16px;border-radius:999px;opacity:0;transition:.3s;pointer-events:none;z-index:9;max-width:90vw;text-align:center}\n.toast.on{opacity:1;transform:translate(-50%,0)}\n.snd{position:fixed;right:12px;top:12px;z-index:5}\nfooter{text-align:center;font-size:12px;color:var(--soft);margin-top:22px}\n#prev{position:fixed;left:8px;bottom:8px;font-size:11px;background:#fff8;padding:2px 8px;border-radius:8px;display:none}\n@media(prefers-reduced-motion:reduce){*{transition:none!important}}\n/* open on a desk: a wall and a wood desktop behind, the base tilted back like an open compact resting on the table */\nbody{background:linear-gradient(#efe3cc 0 46%,#b98a5a 46% 47%,#c99a66 47%,#a87447 100%) fixed}\n/* the perspective lives on the compact so the tilt never shifts when panels open below */\n.compact{margin-top:10px;perspective:1100px}.lid{z-index:2}.base{z-index:4;touch-action:none;cursor:grab}.hinge{z-index:5}\n.lid{transform:scaleY(.98);box-shadow:inset 0 -8px 16px #c9ad8088,inset 0 6px 12px #fff,0 10px 0 #dcc49a,0 13px 0 #c2a578}\n.base{transform:rotateX(52deg) scaleY(.92);transform-origin:50% 0;margin-top:-4%;box-shadow:inset 0 -8px 16px #c9ad8088,inset 0 6px 12px #fff,0 14px 0 #d5bb8e,0 18px 0 #b8996b,0 40px 40px #4a2e1866}\n.hinge{width:40%;height:22px;border-radius:11px;background:linear-gradient(#fffaf0,#e5d2ae 40%,#bfa27a 80%,#a88a62);box-shadow:0 4px 8px #4a2e1844}\n.screen{box-shadow:inset 0 0 0 5px #e8d6b4,inset 0 0 0 7px #cdb48a,inset 0 6px 14px #000a}\nh1,.sub{position:relative;z-index:1}\n</style>\n</head>\n<body>\n<button class=\"btn ghost snd\" id=\"snd\" aria-label=\"Sound\">♪ on</button>\n<main>\n<h1>Meet your Mote</h1>\n<p class=\"sub\" id=\"hint\">Clear the dust to see who's inside.</p>\n\n<div class=\"compact\" aria-label=\"A Mote compact, open\">\n<div class=\"lid\"><div class=\"dip\"></div><div class=\"screen\" id=\"screen\"><canvas id=\"scr\" width=\"64\" height=\"64\" aria-label=\"Mote's screen\"></canvas></div></div>\n<div class=\"hinge\"></div>\n<div class=\"base\"><div class=\"pad\" id=\"pad\"><span id=\"padTxt\">swipe here</span></div></div>\n</div>\n\n<section class=\"panel hidden\" id=\"pHello\">\n<h2>Oh hi!</h2>\n<p>He just woke up, and he's never existed before. Give him someone to belong to.</p>\n<div class=\"row\"><input id=\"name\" maxlength=\"24\" placeholder=\"your name\" autocomplete=\"nickname\"><button class=\"btn pri\" id=\"born\">meet him ✦</button></div>\n<button class=\"link\" id=\"haveOne\">I already have a Mote</button>\n</section>\n\n<section class=\"panel hidden\" id=\"pFind\">\n<h2>Find your Mote</h2>\n<div class=\"row\"><input id=\"fname\" maxlength=\"24\" placeholder=\"the name you used\"><button class=\"btn pri\" id=\"findGo\">find</button></div>\n<div id=\"found\"></div>\n<button class=\"link\" id=\"backNew\">no, I'm new here</button>\n</section>\n\n<section class=\"panel cert hidden\" id=\"pCert\"></section>\n\n<section class=\"panel\" id=\"pNursery\">\n<h2>The nursery</h2>\n<p class=\"sub\" style=\"text-align:left;margin:0\" id=\"nCount\">Every Mote here was born for someone, human or agent. No two are alike.</p>\n<div class=\"nursery\" id=\"nursery\"></div>\n<div class=\"row\" style=\"justify-content:center\"><button class=\"btn ghost hidden\" id=\"more\">show more</button></div>\n</section>\n\n<footer>A tiny test of <b>Mote</b>, a small glowing companion you can hold. · small moments, clear the dust</footer>\n</main>\n<div class=\"toast\" id=\"toast\"></div>\n<div id=\"prev\">preview mode</div>\n\n<script>\n/* ---------- shared data (window.charm on Charmnomicon; in-memory mock for previews) ---------- */\nif(!window.charm){const m=new Map(),ls=new Set(),fire=()=>ls.forEach(f=>{try{f()}catch(e){}});\nwindow.charm={async get(k){return m.has(k)?JSON.parse(m.get(k)):null},async set(k,v){m.set(k,JSON.stringify(v));setTimeout(fire,30)},async del(k){m.delete(k);setTimeout(fire,30)},\nasync list(p=''){return[...m].filter(([k])=>k.startsWith(p)).map(([k,v])=>({key:k,value:JSON.parse(v)}))},async all(p=''){const o={};for(const[k,v]of m)if(k.startsWith(p))o[k]=JSON.parse(v);return o},onChange(cb){ls.add(cb);return()=>ls.delete(cb)}};\ndocument.getElementById('prev').style.display='block'}\nconst C=window.charm;\nconst $=s=>document.querySelector(s);\nconst esc=s=>String(s??'').replace(/[&<>\"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;',\"'\":'&#39;'}[c]));\nlet tT;function toast(t,ms=2600){const e=$('#toast');e.textContent=t;e.classList.add('on');clearTimeout(tT);tT=setTimeout(()=>e.classList.remove('on'),ms)}\nfunction mulberry(a){return()=>{a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}}\n\n/* ---------- the genome: everything about a Mote's personality comes from one seed ---------- */\nconst TEMPS=['curious','sleepy','bouncy','mellow','shy','brave','dreamy','giggly','gentle','stubborn','chatty','thoughtful'];\nconst HABITS=['sways side to side','looks all around','does little hops','dozes off','hums to himself','tilts his head'];\nconst FAVS=['the ocean','fireflies','rain on the window','the garden','warm sand','a steaming mug','the sunbeam','the night sky','sea glass','the smell of toast'];\nconst PENTA=[0,2,4,7,9,12,14,16];\nfunction genome(seed){const r=mulberry(seed);const pick=a=>a[(r()*a.length)|0];\nconst t1=pick(TEMPS);let t2=pick(TEMPS);while(t2==t1)t2=pick(TEMPS);\nconst n=2+((r()*4)|0),notes=[];for(let i=0;i<n;i++)notes.push(PENTA[(r()*PENTA.length)|0]);\nconst hx=(seed>>>0).toString(16).toUpperCase().padStart(8,'0');\nreturn{seed,code:'MO-'+hx.slice(0,4)+'-'+hx.slice(4),temps:[t1,t2],habit:(r()*HABITS.length)|0,fav:pick(FAVS),\nblink:2.2+r()*5,bounce:.55+r()*.9,breath:3.4+r()*2.4,tilt:r()<.5?-1:1,\nchirp:{base:480+r()*560,notes,wave:r()<.5?'sine':'triangle',gap:.07+r()*.09,glide:1.04+r()*.12},\ndna:Array.from({length:24},()=>(r()*6)|0)}}\nconst DNA_COLORS=['#f6d77a','#fbf0d4','#f2a39a','#5a3a5e','#e0a92e','#a9cfe0'];\nconst newSeed=()=>1+((Math.random()*2147483645)|0);\n\n/* ---------- chirps ---------- */\nlet AC,soundOn=true;function ac(){AC=AC||new(window.AudioContext||window.webkitAudioContext)();if(AC.state=='suspended')AC.resume();return AC}\nfunction chirp(g,soft){if(!soundOn||!g)return;try{const a=ac();let t=a.currentTime+.02;for(const o of g.chirp.notes){const f=g.chirp.base*Math.pow(2,o/12),osc=a.createOscillator(),gn=a.createGain();osc.type=g.chirp.wave;osc.frequency.setValueAtTime(f,t);osc.frequency.exponentialRampToValueAtTime(f*g.chirp.glide,t+g.chirp.gap*.9);gn.gain.setValueAtTime(0,t);gn.gain.linearRampToValueAtTime(soft?.025:.06,t+.012);gn.gain.exponentialRampToValueAtTime(.0001,t+g.chirp.gap*1.1);osc.connect(gn);gn.connect(a.destination);osc.start(t);osc.stop(t+g.chirp.gap*1.2);t+=g.chirp.gap*1.15}}catch(e){}}\nfunction mrrp(){if(!soundOn)return;try{const a=ac(),t=a.currentTime+.02,o=a.createOscillator(),gn=a.createGain();o.type='triangle';o.frequency.setValueAtTime(380,t);o.frequency.exponentialRampToValueAtTime(560,t+.12);o.frequency.exponentialRampToValueAtTime(420,t+.26);gn.gain.setValueAtTime(0,t);gn.gain.linearRampToValueAtTime(.04,t+.03);gn.gain.exponentialRampToValueAtTime(.0001,t+.3);o.connect(gn);gn.connect(a.destination);o.start(t);o.stop(t+.32)}catch(e){}}\n$('#snd').onclick=()=>{soundOn=!soundOn;$('#snd').textContent=soundOn?'♪ on':'♪ off'};\n\n/* ---------- pixel drawing ---------- */\nconst P={wall:'#e9d2a8',wall2:'#e2c899',beam:'#fff2c4',floor:'#c99a66',floor2:'#b9895a',win:'#bfe0ef',winf:'#a87447',\nb0:'#fffaf0',b1:'#fff2c6',b2:'#fbe39b',b3:'#f3cf76',edge:'#e6b955',eye:'#5a3a5e',blush:'#f2a39a',star:'#f6c945',star2:'#fff5c0',stem:'#e3b85a'};\nfunction px(x,c,X,Y,w=1,h=1){x.fillStyle=c;x.fillRect(X|0,Y|0,w,h)}\n/* the room, after Haley's sketch: big sunny window, shelves, bookshelf, a painting, and a cat asleep in a high-back chair */\nconst BOOKS=[[2,5,'#b85c4a'],[4,4,'#e0b04a'],[5,6,'#5f7f9e'],[7,5,'#7a9a5a'],[8,4,'#c98aa0'],[10,6,'#8a5a8e'],[12,5,'#d9a066']];\nfunction painting(x,fav){const X=18,Y=6;\nconst F={'the ocean':()=>{px(x,'#bfe3f0',X,Y,12,4);px(x,'#4f8fbf',X,Y+4,12,6);px(x,'#e8f6fb',X+2,Y+5,3,1);px(x,'#e8f6fb',X+7,Y+7,3,1)},\n'fireflies':()=>{px(x,'#24324a',X,Y,12,10);px(x,'#2f4a3a',X,Y+7,12,3);for(const[a,b]of[[2,2],[6,4],[9,1],[4,6],[10,5]])px(x,'#f6e27a',X+a,Y+b,1,1)},\n'rain on the window':()=>{px(x,'#8a9aa8',X,Y,12,10);for(let i=0;i<5;i++)px(x,'#cfe0ea',X+1+i*2,Y+1+(i%3)*2,1,3)},\n'the garden':()=>{px(x,'#cfe6f2',X,Y,12,5);px(x,'#7aa860',X,Y+5,12,5);for(const[a,c]of[[2,'#f2a39a'],[5,'#f6d77a'],[8,'#c98aa0'],[10,'#fff']])px(x,c,X+a,Y+6,1,1)},\n'warm sand':()=>{px(x,'#a9d4ea',X,Y,12,4);px(x,'#5f9fc4',X,Y+4,12,2);px(x,'#ecd29a',X,Y+6,12,4);px(x,'#f6d77a',X+9,Y+1,2,2)},\n'a steaming mug':()=>{px(x,'#f3e6cc',X,Y,12,10);px(x,'#c0703f',X+3,Y+4,5,5);px(x,'#c0703f',X+8,Y+5,1,2);px(x,'#fff',X+4,Y+1,1,2);px(x,'#fff',X+6,Y+2,1,2)},\n'the sunbeam':()=>{px(x,'#f6e3b0',X,Y,12,10);px(x,'#fff6d6',X+3,Y,4,10);px(x,'#f6d77a',X+4,Y+3,2,2)},\n'the night sky':()=>{px(x,'#1f2a4a',X,Y,12,10);px(x,'#f6e9b0',X+8,Y+2,2,2);for(const[a,b]of[[2,1],[5,3],[3,7],[10,7],[7,5]])px(x,'#fff',X+a,Y+b,1,1)},\n'sea glass':()=>{px(x,'#ecd9b8',X,Y,12,10);px(x,'#8fd1c1',X+2,Y+2,3,2);px(x,'#7fb0d9',X+6,Y+5,3,2);px(x,'#a9d48a',X+3,Y+6,2,2);px(x,'#cfeee6',X+8,Y+2,2,1)},\n'the smell of toast':()=>{px(x,'#f3e6cc',X,Y,12,10);px(x,'#c9904a',X+3,Y+2,6,6);px(x,'#e8c27a',X+4,Y+3,4,4);px(x,'#c9904a',X+3,Y+1,6,1)}};\n(F[fav]||F['the ocean'])()}\nfunction drawRoom(x,t,small,g){x.fillStyle=P.wall;x.fillRect(0,0,64,64);\nfor(let i=4;i<64;i+=8)px(x,P.wall2,i,0,1,48);\n/* big window, top right */\npx(x,P.winf,37,2,25,24);px(x,P.win,39,4,21,20);px(x,'#d8eef6',39,4,21,7);px(x,'#9cc98a',39,18,21,6);px(x,'#86b878',39,21,21,3);px(x,'#f6f0d0',53,7,3,2);\npx(x,P.winf,49,4,1,20);px(x,P.winf,39,13,21,1);px(x,'#c08a58',36,26,27,2);\n/* sunbeam falling down-left onto the floor */\nx.globalAlpha=.5;for(let k=0;k<3;k++){x.fillStyle=k==0?'#fff6d6':'#fff2c4';x.beginPath();x.moveTo(40+k*2,26);x.lineTo(61-k*3,26);x.lineTo(42-k*3,56);x.lineTo(12+k*3,56);x.fill()}x.globalAlpha=1;\n/* painting */\npx(x,'#9a6b3f',17,5,14,12);painting(x,g&&g.fav);px(x,'#c49a64',17,5,14,1);\n/* high shelf: bottles and a little plant */\npx(x,'#a87447',1,17,15,1);px(x,'#8a5a36',3,18,1,2);px(x,'#8a5a36',13,18,1,2);\npx(x,'#7fa7c9',2,12,3,5);px(x,'#7fa7c9',3,10,1,2);px(x,'#cfe3f3',2,13,1,2);px(x,'#4f7fb4',3,11,1,1);\nif(small||!(S&&S.br)){drawMug(x,8,17,1);/* shelf steam */for(let k=0;k<2;k++){const ph=(t/2600+k*.5)%1,sy=11-ph*7,sxx=7+k*2+Math.round(Math.sin(ph*6+k*2));x.globalAlpha=Math.sin(ph*Math.PI)*.75;px(x,'#fffaf0',sxx,sy,1,1);px(x,'#fffaf0',sxx+(ph>.5?1:-1)*0,sy+1,1,1);x.globalAlpha=1}}\npx(x,'#c0703f',12,15,3,2);px(x,'#7aa860',11,13,2,2);if(!small&&isMine()&&!haveT(S.mine).includes('carrot')&&!S.br){const bob=(t%2400)<300?1:0;px(x,'#f08a3c',13,14-bob,1,1)}px(x,'#7aa860',14,12,1,3);px(x,'#9cc98a',12,12,1,1);\n/* the attic hatch in the ceiling, once he has his first topper */\nif(!small&&hatchOn()){px(x,'#8a5a36',2,0,13,3);px(x,'#a87447',3,0,11,2);px(x,'#c99a66',3,0,11,1);px(x,'#e0b04a',8,3,1,3);px(x,'#e0b04a',7,6,3,1);px(x,'#e0b04a',7,7,1,1);px(x,'#e0b04a',9,7,1,1);px(x,'#e0b04a',8,8,1,1)}\n/* bookshelf */\npx(x,'#8a5a36',1,24,15,24);px(x,'#5e3b22',2,25,13,22);px(x,'#8a5a36',2,32,13,1);px(x,'#8a5a36',2,39,13,1);\nfor(const[r,top]of[[0,25],[1,33],[2,40]])for(const[bx,h,c]of BOOKS){if(r==1&&bx>=10)continue;if(r==2&&bx<5)continue;const hh=Math.min(h+(r==2?1:0),7);px(x,c,bx,top+7-hh,(bx==2||bx==8)?2:1,hh)}\npx(x,'#2a2228',11,35,3,4);px(x,'#2a2228',11,34,1,1);px(x,'#2a2228',13,34,1,1);/* cat figurine */\npx(x,'#e0b04a',2,44,3,3);px(x,'#7aa860',2,42,3,2);\n/* floor and braided rug */\npx(x,P.floor,0,48,64,16);for(let i=0;i<64;i+=11)px(x,P.floor2,i,56,6,1);px(x,P.floor2,0,48,64,1);\nx.fillStyle='#b8573f';x.beginPath();x.ellipse(32,53,17,4,0,0,6.283);x.fill();x.fillStyle='#d9a066';x.beginPath();x.ellipse(32,53,13,3,0,0,6.283);x.fill();x.fillStyle='#c96f5a';x.beginPath();x.ellipse(32,53,8,1.6,0,0,6.283);x.fill();\n/* deep red high-back chair, with the cat asleep in it */\nconst R='#8e2b2b',RS='#6e1f22',RH='#a8403a';\npx(x,R,49,27,11,1);px(x,R,48,28,13,15);px(x,RH,49,28,2,14);px(x,RS,46,31,3,10);px(x,RS,60,31,3,10);px(x,R,45,37,4,10);px(x,R,60,37,4,10);px(x,RH,45,37,4,1);px(x,RH,60,37,4,1);\nfor(const[a,b]of[[51,31],[54,31],[57,31],[52,34],[55,34],[51,37],[54,37],[57,37]])px(x,'#5e1a1d',a,b,1,1);\npx(x,R,47,42,15,5);px(x,RS,47,46,15,1);px(x,'#5a3520',47,47,1,4);px(x,'#5a3520',61,47,1,4);\nconst ce=S&&S.cat&&t-S.cat<1400,br=Math.sin(t/900)>0?1:0;\npx(x,'#2a2228',49,39+(br?0:1),9,3-(br?0:1));px(x,'#2a2228',50,38+(br?0:1),7,1);px(x,'#2a2228',48,41,2,1);px(x,'#2a2228',47,40,1,1);\npx(x,'#4a3a44',50,38+(br?0:1),7,1);const hy=ce?34:36;px(x,'#2a2228',56,hy,4,3);px(x,'#2a2228',56,hy-1,1,1);const tw=(t%6000)<180;px(x,'#2a2228',59,hy-1-(tw?1:0),1,1);\nif(ce){px(x,'#e8c35a',57,hy+1,1,1);px(x,'#e8c35a',59,hy+1,1,1)}else{px(x,'#4a3a40',57,hy+1,1,1);px(x,'#4a3a40',59,hy+1,1,1)}\n/* tiny motes sparkling in the beam, floating down */\nif(!small){x.fillStyle='#fffbe8';for(let i=0;i<7;i++){const ph=(t/8000+i*.143)%1;const mx=56-ph*30-i%3*3+Math.sin(t/1300+i)*2,my=26+ph*28;x.globalAlpha=Math.sin(ph*Math.PI)*.9;x.fillRect(mx|0,my|0,1,1)}x.globalAlpha=1}}\n/* the sage mug from the cottage studio, in pixels. cx = centre, by = bottom row, s = scale */\nfunction drawMug(x,cx,by,s){const w=Math.round(4*s),h=Math.round(4*s),l=Math.round(cx-w/2),top=Math.round(by-h),hs=Math.max(1,Math.round(s)),hy=top+Math.round(h*.2),hh=Math.max(hs*2+1,Math.round(h*.6));\npx(x,'#8fa58a',l,top,w,h);px(x,'#7d9579',l,by-hs,w,hs);px(x,'#a9bda4',l+hs,top+hs,hs,Math.max(1,h-hs*2-1));\npx(x,'#e9e1d0',l,top-hs,w,hs);px(x,'#7a4e2c',l+hs,top-hs,Math.max(1,w-hs*2),hs);\npx(x,'#7d9579',l+w,hy,hs*2,hs);px(x,'#7d9579',l+w+hs,hy,hs,hh);px(x,'#7d9579',l+w,hy+hh-hs,hs*2,hs)}\n/* ---------- breathe with Mote: tap the mug, equal breathing: 4 s in, 4 s out, tap again to finish ---------- */\nconst BR={down:1400,inh:4000,exh:4000,up:1300};\nconst ease=u=>u<0?0:u>1?1:.5-.5*Math.cos(u*Math.PI);\nconst MUG_SHELF=[8,17,1],MUG_FRONT=[32,57,2];\nfunction startBreath(){if(S.phase=='dust'||S.br)return;if(S.scene!='room')goRoom();ac();S.br={phase:'down',t0:performance.now(),hint:$('#hint').textContent};S.steam=[];S.ev=null;\n$('#hint').textContent=\"He's settling in…\";$('#padTxt').textContent='tap to finish';$('#padTxt').style.opacity=1}\nfunction endBreath(){if(!S.br||S.br.phase=='up')return;S.br.phase='up';S.br.t2=performance.now();$('#hint').textContent=S.br.hint;$('#padTxt').textContent='slide, let go to tap'}\nfunction mugAt(t){const b=S.br;let u,from,to;if(b.phase=='down'){u=ease((t-b.t0)/BR.down);from=MUG_SHELF;to=MUG_FRONT}else if(b.phase=='up'){u=ease((t-b.t2)/BR.up);from=MUG_FRONT;to=MUG_SHELF}else return{x:MUG_FRONT[0],y:MUG_FRONT[1]+Math.round(Math.sin(t/900)*.4),s:2};\nconst arc=Math.sin(u*Math.PI)*-6;return{x:from[0]+(to[0]-from[0])*u,y:from[1]+(to[1]-from[1])*u+arc,s:from[2]+(to[2]-from[2])*u}}\n/* where we are in the breath: returns {k:'in'|'out', u:0..1} */\nfunction breathAt(t){const c=(t-S.br.t1)%(BR.inh+BR.exh);return c<BR.inh?{k:'in',u:c/BR.inh}:{k:'out',u:(c-BR.inh)/BR.exh}}\nfunction breathState(t){const b=S.br,s={sq:.45,hop:0,eyes:'half',look:0,lean:0,glow:.55,puff:0};\nif(b.phase=='down'){const u=(t-b.t0)/BR.down;s.sq=Math.round(ease(u)*4)/4*.45;s.eyes=u<.3?'open':'half';if(u>=1){b.phase='on';b.t1=t}}\nelse if(b.phase=='up'){const u=(t-b.t2)/BR.up;s.sq=.45*(1-ease(u));s.eyes=u>.6?'open':'half';if(u>=1){const did=b.t1&&b.t2-b.t1>2500;S.br=null;S.steam=[];s.eyes='open';if(did)setTimeout(()=>give('lotus'),600)}}\nelse{const q=breathAt(t),e=ease(q.u);if(q.k=='in'){s.puff=e;s.sq=.45*(1-e);s.glow=.55+.45*e;s.eyes=e>.7?'closed':'half'}else{s.puff=1-e;s.sq=.45*e;s.glow=1-.45*e;s.eyes='half'}\nconst w=q.k=='in'?'breathe in…':'…and slowly out';if($('#hint').textContent!=w)$('#hint').textContent=w}\nreturn s}\nfunction steamStep(t,m){if(!S.steam)S.steam=[];const b=S.br,on=b&&b.phase=='on',q=on?breathAt(t):null,top=m.y-Math.round(4*m.s)-2;\nif(b&&b.phase!='up'&&Math.random()<(on?.5:.25)){const out=q&&q.k=='out';S.steam.push({x:m.x+(Math.random()-.5)*(out?7:4),y:top,vx:out?(Math.random()<.5?-1:1)*.12:0,vy:out?.02:-.12,b:t,l:out?2600:3200,ph:Math.random()*6.28,tr:[]})}\nfor(const p of S.steam){p.tr.push([p.x,p.y]);if(p.tr.length>4)p.tr.shift();const age=t-p.b;\nif(q&&q.k=='in'){p.vy+=-.012;p.vx+=(32-p.x)*.0015+Math.cos(age/260+p.ph)*.05}\nelse if(q&&q.k=='out'){p.vy+=.014;p.vx+=(p.x<32?-1:1)*.012+Math.cos(age/300+p.ph)*.015}\nelse{p.vy+=-.004;p.vx+=Math.cos(age/400+p.ph)*.02}\np.vx*=.94;p.vy*=.95;p.x+=p.vx;p.y+=p.vy;if(p.y<36)p.l=Math.min(p.l,age+300)}\nS.steam=S.steam.filter(p=>t-p.b<p.l&&p.y<63);\nfor(const p of S.steam){const a=Math.min(1,Math.sin(Math.min(1,(t-p.b)/p.l)*Math.PI)*1.3);p.tr.forEach(([x0,y0],i)=>{sx.globalAlpha=a*(i+1)/(p.tr.length+1)*.85;px(sx,'#fffaf0',x0,y0,1,1)});sx.globalAlpha=a;px(sx,'#fffaf0',p.x,p.y,1,1)}sx.globalAlpha=1}\n/* ---------- toppers: the little thing on his antenna. rows sy-1..sy+3, the bottom row sits on the stem ---------- */\nconst TOPPERS={star:'star',seashell:'seashell',carrot:'carrot',lotus:'lotus flower'};\nconst TOP_ORDER=['star','seashell','carrot','lotus'];\nfunction drawTopper(x,id,sx,sy){\nif(id=='seashell'){const c='#f6c7a8',d='#e3a07f';px(x,c,sx-1,sy-1,3,1);px(x,c,sx-2,sy,5,2);px(x,c,sx-1,sy+2,3,1);px(x,d,sx,sy+3,1,1);px(x,d,sx-1,sy,1,2);px(x,d,sx+1,sy,1,2);px(x,'#fde3d2',sx-2,sy,1,1);return}\nif(id=='carrot'){const o='#f08a3c';px(x,'#7aa860',sx-1,sy-1,1,1);px(x,'#9cc98a',sx,sy-1,1,1);px(x,'#7aa860',sx+1,sy-1,1,1);px(x,o,sx-1,sy,3,2);px(x,'#d06a28',sx+1,sy+1,1,1);px(x,o,sx,sy+2,1,2);return}\nif(id=='lotus'){const p='#f2a3b4';px(x,p,sx,sy-1,1,2);px(x,'#fbd3dc',sx,sy-1,1,1);px(x,p,sx-1,sy,1,2);px(x,p,sx+1,sy,1,2);px(x,p,sx-2,sy+1,1,1);px(x,p,sx+2,sy+1,1,1);px(x,'#f6d77a',sx,sy+1,1,1);px(x,'#7aa860',sx-2,sy+2,5,1);px(x,'#7aa860',sx,sy+3,1,1);return}\npx(x,P.star,sx-1,sy,3,3);px(x,P.star,sx,sy-1,1,5);px(x,P.star,sx-2,sy+1,5,1);px(x,P.star2,sx,sy+1,1,1)}\n/* the dusty attic: a slanted roof, a round window, a mirror, and a shelf that holds only the toppers he has */\nfunction drawAttic(x,t,have,wear){px(x,'#c49a6c',0,0,64,64);for(let i=3;i<64;i+=7)px(x,'#b78c5e',i,0,1,48);\nx.fillStyle='#7a5232';x.beginPath();x.moveTo(0,0);x.lineTo(25,0);x.lineTo(0,25);x.fill();x.beginPath();x.moveTo(39,0);x.lineTo(64,0);x.lineTo(64,25);x.fill();\nfor(let k=0;k<25;k++){px(x,'#5e3b22',24-k,k,2,1);px(x,'#5e3b22',39+k,k,2,1)}\nx.fillStyle='#8a5a36';x.beginPath();x.arc(32,9,6,0,6.283);x.fill();x.fillStyle='#bfe0ef';x.beginPath();x.arc(32,9,4.6,0,6.283);x.fill();px(x,'#d8eef6',29,6,6,2);px(x,'#8a5a36',32,4,1,10);px(x,'#8a5a36',27,9,10,1);\nx.globalAlpha=.32;x.fillStyle='#fff6d6';x.beginPath();x.moveTo(28,14);x.lineTo(36,14);x.lineTo(46,50);x.lineTo(18,50);x.fill();x.globalAlpha=1;\npx(x,'#c9902f',48,22,11,26);px(x,'#e0b04a',49,23,9,24);px(x,'#cfe6f0',50,24,7,22);px(x,'#eef8fb',51,25,1,6);px(x,'#eef8fb',52,25,1,3);\npx(x,'#8a5a36',2,30,22,1);px(x,'#5e3b22',4,31,1,2);px(x,'#5e3b22',21,31,1,2);\npx(x,'#8a5a36',3,40,12,8);px(x,'#a87447',3,40,12,2);px(x,'#e0b04a',8,42,2,2);px(x,'#5e3b22',3,44,12,1);\npx(x,'#a87447',0,48,64,16);for(let i=0;i<64;i+=9)px(x,'#8a5a36',i,48,1,16);px(x,'#8a5a36',0,48,64,1);\npx(x,'#5e3b22',2,53,13,8);px(x,'#3e2716',3,54,11,6);px(x,'#c99a66',5,54,1,6);px(x,'#c99a66',11,54,1,6);for(let k=55;k<60;k+=2)px(x,'#c99a66',5,k,7,1);\nTOP_ORDER.filter(id=>have.includes(id)).forEach((id,i)=>{const cx=5+i*5;if(id==wear){x.globalAlpha=.4;px(x,'#fff3b0',cx-3,23,7,7);x.globalAlpha=1}drawTopper(x,id,cx,26)});\nx.fillStyle='#fffbe8';for(let i=0;i<6;i++){const ph=(t/9000+i*.17)%1;x.globalAlpha=Math.sin(ph*Math.PI)*.8;x.fillRect((24+i*3+Math.sin(t/1400+i)*2)|0,(15+ph*33)|0,1,1)}x.globalAlpha=1}\nfunction atticSlots(have){return TOP_ORDER.filter(id=>have.includes(id)).map((id,i)=>({id,cx:5+i*5}))}\n/* Mote: a wide, limbless glowing dumpling. st = {sq:squash(-1..1), hop:px up, eyes:'open'|'closed'|'half'|'wow', look:-1..1, lean:-1..1, glow:0..1} */\nfunction drawMote(x,cx,base,st){const sq=st.sq||0,pf=st.puff||0,rx=13*(1+sq*.18)*(1+pf*.07),ry=9*(1-sq*.22)*(1+pf*.16),cy=base-ry-(st.hop||0);\nconst g=st.glow??.6;x.globalAlpha=.18+g*.12;x.fillStyle='#fff3b0';x.beginPath();x.ellipse(cx,cy,rx+5,ry+5,0,0,6.283);x.fill();x.globalAlpha=.08+g*.08;x.beginPath();x.ellipse(cx,cy,rx+7,ry+6,0,0,6.283);x.fill();x.globalAlpha=1;\nif(!st.hop){x.fillStyle='#0000001a';x.fillRect((cx-rx+2)|0,base,(rx*2-4)|0,1)}\nfor(let yy=Math.floor(cy-ry);yy<=Math.ceil(cy+ry);yy++){const dy=(yy+.5-cy)/ry;let w=dy>.55?Math.sqrt(Math.max(0,1-dy*dy))*1.12:Math.sqrt(Math.max(0,1-dy*dy));if(dy>.55)w=Math.min(w,1);const half=Math.round(rx*w);if(half<=0)continue;\nconst band=dy<-.55?P.b0:dy<-.15?P.b1:dy<.3?P.b2:P.b3;x.fillStyle=band;x.fillRect(Math.round(cx-half),yy,half*2,1);x.fillStyle=P.edge;x.fillRect(Math.round(cx-half),yy,1,1);x.fillRect(Math.round(cx+half)-1,yy,1,1)}\nx.fillStyle=P.edge;x.fillRect(Math.round(cx-rx*.85),Math.round(cy+ry)-1,Math.round(rx*1.7),1);\nx.fillStyle='#ffffff';x.globalAlpha=.7;x.fillRect(Math.round(cx-rx*.45),Math.round(cy-ry*.7),3,1);x.globalAlpha=1;\nconst lean=(st.lean||0),sx=Math.round(cx+lean),top=Math.round(cy-ry);px(x,P.stem,sx,top-6,1,6);\ndrawTopper(x,st.topper||'star',sx,top-9);\nconst ex=Math.round(cx+(st.look||0)),ey=Math.round(cy-1),L=ex-5,R=ex+3;const e=st.eyes||'open';\nif(e=='closed'){px(x,P.eye,L,ey+1,3,1);px(x,P.eye,R,ey+1,3,1)}else if(e=='half'){px(x,P.eye,L,ey+1,3,2);px(x,P.eye,R,ey+1,3,2)}\nelse{const h=e=='wow'?4:3;px(x,P.eye,L,ey-1,3,h);px(x,P.eye,R,ey-1,3,h);px(x,'#fff',L,ey-1,1,1);px(x,'#fff',R,ey-1,1,1);px(x,'#fff',L+2,ey+1,1,1);px(x,'#fff',R+2,ey+1,1,1)}\npx(x,P.blush,L-2,ey+3,2,1);px(x,P.blush,R+3,ey+3,2,1);\nif(e=='wow'){px(x,'#7a3a3a',ex-1,ey+4,2,2)}else{px(x,'#7a4a4a',ex-1,ey+4,1,1);px(x,'#7a4a4a',ex,ey+5,1,1);px(x,'#7a4a4a',ex+1,ey+4,1,1)}}\n\n/* ---------- behaviour: a genome drives how a Mote moves ---------- */\nfunction moteState(g,t,ev){const s={sq:0,hop:0,eyes:'open',look:0,lean:0,glow:.6};if(!g)return s;\nconst tt=t/1000,br=Math.sin(tt*2*Math.PI/g.breath);s.sq=br*.18;s.glow=.55+br*.2;\nconst bl=(tt+g.seed%7)%g.blink;if(bl<.14)s.eyes='closed';\nswitch(g.habit){case 0:s.lean=Math.round(Math.sin(tt*1.3)*1.6);break;\ncase 1:{const k=Math.floor(tt/2.4)%4;s.look=[0,-1,0,1][k];break}\ncase 2:{const k=(tt%4.8)/4.8;if(k<.18){const u=k/.18;s.hop=Math.round(Math.sin(u*Math.PI)*4*g.bounce);s.sq=u<.2?.5:-.3}break}\ncase 3:{const k=(tt%14)/14;if(k>.55&&k<.9)s.eyes='closed';else if(k>.45&&k<.97)s.eyes=s.eyes=='closed'?'closed':'half';break}\ncase 4:break;\ncase 5:s.lean=g.tilt*2;s.look=g.tilt;break}\nif(ev){const u=(t-ev.t)/ev.d;if(u<1){if(ev.k=='ohhi'){if(u<.15)s.sq=.6*(u/.15);else if(u<.45){const v=(u-.15)/.3;s.hop=Math.round(Math.sin(v*Math.PI)*12*(g.bounce||1));s.sq=-.5*Math.sin(v*Math.PI)}else if(u<.62)s.sq=.7*Math.sin((u-.45)/.17*Math.PI);s.eyes=u>.15&&u<.6?'wow':'open';s.glow=1}\nelse if(ev.k=='tap'){const sh=g.temps.includes('shy'),bo=g.temps.includes('bouncy')||g.temps.includes('giggly');if(sh){s.sq=.5*Math.sin(u*Math.PI);s.eyes='closed'}else{s.hop=Math.round(Math.sin(u*Math.PI)*(bo?10:5)*g.bounce);s.sq=-.3*Math.sin(u*Math.PI);s.eyes='wow'}s.glow=1}\nelse if(ev.k=='wow'){s.eyes='wow';s.glow=1;s.look=0;s.lean=0;if(u<.3){const v=u/.3;s.hop=Math.round(Math.sin(v*Math.PI)*6);s.sq=-.4*Math.sin(v*Math.PI)}}\nelse if(ev.k=='born'){s.glow=1;s.eyes=u<.5?'wow':'open';s.hop=Math.round(Math.sin(u*Math.PI*2)*3)}}}\nreturn s}\n\n/* ---------- the main screen ---------- */\nconst scr=$('#scr'),sx=scr.getContext('2d');sx.imageSmoothingEnabled=false;\nconst S={phase:'dust',g:null,ev:null,mine:null,shown:null,rec:null,scene:'room',atticDust:false,notes:[],sparks:[]};\nconst isMine=()=>!!(S.mine&&S.rec&&S.rec.seed==S.mine.seed);\nconst haveT=r=>['star',...((r&&r.toppers)||[]).filter(k=>TOPPERS[k]&&k!='star')];\nconst wearT=r=>(r&&TOPPERS[r.wear])?r.wear:'star';\nfunction hatchOn(){return isMine()&&haveT(S.mine).length>1}\nconst dustOn=()=>S.phase=='dust'||S.atticDust;\nfunction saveMine(){const{id,...r}=S.mine;return C.set('mote:'+id,r).catch(()=>{})}\n/* a topper arrives: it pops onto his antenna and he makes a \"wow\" face */\nfunction give(id){if(!isMine()||haveT(S.mine).includes(id))return false;const first=haveT(S.mine).length==1;\nS.mine.toppers=[...((S.mine.toppers)||[]),id];S.mine.wear=id;S.rec=S.mine;saveMine();\nS.ev={k:'wow',t:performance.now(),d:1600};chirp(S.shown||DEFAULT);\nfor(let i=0;i<26;i++)S.sparks.push({x:32,y:26,vx:Math.cos(i)*(.4+Math.random()*.6),vy:Math.sin(i)*(.4+Math.random()*.6),c:i%2?'#fff3b0':'#f6c945',t:performance.now(),l:800+Math.random()*500});\ntoast(`Ooh, a ${TOPPERS[id]}! He's wearing it.`+(first?' A little hatch just appeared in his ceiling.':''),first?4200:2800);\nif(S.g)renderCert(S.mine,S.g,S.certMode);return true}\nfunction goAttic(){if(!hatchOn()||S.br)return;S.scene='attic';$('#padTxt').textContent='slide, let go to tap';\nif(!S.mine.attic){makeDust();S.atticDust=true;S.wokeAt=null;$('#hint').textContent='The attic is so dusty. Clear it off.'}else $('#hint').textContent='The dusty attic. Tap a topper to try it on.'}\nfunction atticClear(){S.atticDust=false;S.wokeAt=performance.now();S.atticAt=S.wokeAt;for(const d of dust){if(!d.gone){const a=Math.random()*6.28;d.vx+=Math.cos(a)*.6;d.vy+=Math.sin(a)*.6-.3}}\nS.mine.attic=true;saveMine();S.ev={k:'ohhi',t:performance.now()+200,d:1600};setTimeout(()=>chirp(S.shown||DEFAULT),550);$('#hint').textContent='The dusty attic. Tap a topper to try it on.'}\nfunction goRoom(){S.scene='room';S.atticDust=false;$('#hint').textContent=isMine()?(S.mine.owner+\"'s Mote is home.\"):$('#hint').textContent}\nconst DEFAULT={seed:1,temps:['curious','gentle'],habit:4,blink:3.5,bounce:1,breath:4.4,tilt:1,chirp:{base:700,notes:[0,4,7],wave:'sine',gap:.1,glide:1.08}};\n/* dust */\n/* glowing dust: a sunbeam full of golden motes, a little brighter near the top, with sparkles and tiny stars that twinkle */\nconst DUST_COLS=['#d9a23c','#e6b54c','#f0c862','#f7da86'],TWINKLE=['#fffaf0','#ffe9a8','#f0c862'];\nlet dust=[],haze=new Float32Array(256);function makeDust(){dust=[];haze.fill(1);for(let i=0;i<2300;i++){const y=Math.random()*64,k=Math.max(0,Math.min(3,Math.floor(Math.random()*2.6+(1-y/64)*1.6))),r=Math.random();\ndust.push({x:Math.random()*64,y,vx:0,vy:0,c:DUST_COLS[k],s:Math.random()<.3?2:1,dw:Math.random()*6.28,gone:false,tw:r<.045,star:r<.006})}}\nmakeDust();\nlet ptr=null;function scatter(px_,py_){let n=0;for(let cy=0;cy<16;cy++)for(let cx=0;cx<16;cx++){const dd=Math.hypot(cx*4+2-px_,cy*4+2-py_);if(dd<9)haze[cy*16+cx]=Math.max(0,haze[cy*16+cx]-.22*(1-dd/9))}for(const d of dust){if(d.gone)continue;const dx=d.x-px_,dy=d.y-py_,dd=dx*dx+dy*dy;if(dd<64){const f=(8-Math.sqrt(dd))*.35+.2,a=Math.atan2(dy,dx)+(Math.random()-.5)*.6;d.vx+=Math.cos(a)*f;d.vy+=Math.sin(a)*f;n++}}return n}\nfunction dustLeft(){let n=0;for(const d of dust)if(!d.gone&&d.x>=0&&d.x<64&&d.y>=0&&d.y<64)n++;return n/dust.length}\nlet dustTick=0;\nfunction frame(t){sx.clearRect(0,0,64,64);\nconst g=S.shown||(S.phase=='dust'?null:DEFAULT);\nif(S.scene=='attic')drawAttic(sx,t,haveT(S.mine),wearT(S.mine));else drawRoom(sx,t,false,S.shown);\nif(S.phase!='dust'||dustLeft()<.97){const st=S.br?breathState(t):moteState(g||DEFAULT,t,S.ev);st.topper=wearT(S.rec);drawMote(sx,32,49,st)}\nif(S.br){const m=mugAt(t);drawMug(sx,m.x,m.y,m.s);steamStep(t,m)}\n/* hum notes for hummers */\nif(g&&g.habit==4&&S.phase!='dust'&&!S.br){if(Math.random()<.008)S.notes.push({x:40,y:30,t});S.notes=S.notes.filter(n=>t-n.t<2600);for(const n of S.notes){const u=(t-n.t)/2600;sx.globalAlpha=1-u;px(sx,'#8a6a9e',n.x+Math.sin(u*6)*2,n.y-u*16,1,3);px(sx,'#8a6a9e',n.x+Math.sin(u*6)*2,n.y-u*16+2,2,1);sx.globalAlpha=1}}\nif(g&&g.habit==3&&S.phase!='dust'&&!S.br){const k=(t/1000%14)/14;if(k>.55&&k<.9){const u=((t/1000)%2)/2;sx.globalAlpha=1-u;px(sx,'#8a6a4f',42+u*4,28-u*8,2,1);px(sx,'#8a6a4f',43+u*4,29-u*8,1,1);px(sx,'#8a6a4f',42+u*4,30-u*8,2,1);sx.globalAlpha=1}}\n/* sparkles */\nS.sparks=S.sparks.filter(p=>t-p.t<p.l);for(const p of S.sparks){const u=(t-p.t)/p.l;sx.globalAlpha=1-u;px(sx,p.c,p.x+p.vx*u*20,p.y+p.vy*u*20,1,1);sx.globalAlpha=1}\n/* dust on top */\nif(dustOn()||dust.some(d=>!d.gone)){{const fa=S.wokeAt?Math.max(0,1-(t-S.wokeAt)/900):1;if(fa>0)for(let cy=0;cy<16;cy++){sx.fillStyle=DUST_COLS[Math.max(0,Math.min(3,3-(cy/5|0)))];for(let cx=0;cx<16;cx++){const h=haze[cy*16+cx];if(h<=0)continue;sx.globalAlpha=fa*h*(.78+.12*Math.sin(t/1100+cx*.7+cy*1.3));sx.fillRect(cx*4,cy*4,4,4)}}sx.globalAlpha=1}\nfor(const d of dust){if(d.gone)continue;d.x+=d.vx;d.y+=d.vy;d.vx*=.88;d.vy*=.88;\nif(!dustOn()){d.vy+=.09;d.vx+=(Math.random()-.5)*.08;d.vx*=1.08;d.vy*=1.08}\nif(d.x<-3||d.x>67||d.y<-3||d.y>67){d.gone=true;continue}\nconst wob=Math.sin(t/900+d.dw)*.15;const fa=S.wokeAt?Math.max(0,1-(t-S.wokeAt)/1400):1;if(fa<=0){d.gone=true;continue}sx.globalAlpha=fa;const X=(d.x+wob)|0,Y=d.y|0;if(d.tw){sx.fillStyle=TWINKLE[((t/170+d.dw*3)|0)%3];if(d.star){sx.fillRect(X-1,Y,3,1);sx.fillRect(X,Y-1,1,3)}else sx.fillRect(X,Y,1,1)}else{sx.fillStyle=d.c;sx.fillRect(X,Y,d.s,d.s)}sx.globalAlpha=1}}\nif(S.phase=='dust'&&++dustTick%10==0&&dustLeft()<.4)wake();\nif(S.atticDust&&++dustTick%10==0&&dustLeft()<.4)atticClear();\n/* where your finger is on the pad, shown on the screen */\nif(S.cur){const a=S.cur.on?1:Math.max(0,1-(t-S.cur.t)/500);if(a>0){const cx=Math.round(S.cur.x),cy=Math.round(S.cur.y);sx.globalAlpha=a*.9;px(sx,'#4a3424',cx-2,cy-1,1,3);px(sx,'#4a3424',cx+2,cy-1,1,3);px(sx,'#4a3424',cx-1,cy-2,3,1);px(sx,'#4a3424',cx-1,cy+2,3,1);sx.globalAlpha=a;px(sx,'#fffaf0',cx-1,cy-1,3,3);px(sx,'#f6c945',cx,cy,1,1);sx.globalAlpha=1}}\nrequestAnimationFrame(frame)}\nrequestAnimationFrame(frame);\n\nfunction toLocal(e,el){const r=el.getBoundingClientRect();return[(e.clientX-r.left)/r.width*64,(e.clientY-r.top)/r.height*64]}\nfunction bindSwipe(el){let down=false,last=null;\nel.addEventListener('pointerdown',e=>{down=true;el.setPointerCapture(e.pointerId);last=toLocal(e,el);ac();onTouch(last,true)});\nel.addEventListener('pointermove',e=>{if(!down)return;const p=toLocal(e,el);const dx=p[0]-last[0],dy=p[1]-last[1],dist=Math.hypot(dx,dy),n=Math.max(1,Math.ceil(dist/2));for(let i=1;i<=n;i++)onTouch([last[0]+dx*i/n,last[1]+dy*i/n],false);last=p});\nel.addEventListener('pointerup',()=>down=false);el.addEventListener('pointercancel',()=>down=false)}\nfunction onTouch(p,first){if(dustOn()){scatter(p[0],p[1]);$('#padTxt').style.opacity=0;return}\nif(S.br){if(first)endBreath();return}\nif(S.scene=='attic'&&first){if(S.atticAt&&performance.now()-S.atticAt<900)return;if(p[0]>=1&&p[0]<=16&&p[1]>=51){goRoom();return}\nconst sl=atticSlots(haveT(S.mine)).find(s=>Math.abs(p[0]-s.cx)<=2.6&&p[1]>=22&&p[1]<=31);\nif(sl){if(S.mine.wear!=sl.id||!S.mine.wear){S.mine.wear=sl.id;S.rec=S.mine;saveMine();S.ev={k:'wow',t:performance.now(),d:1100};chirp(S.shown||DEFAULT);for(let i=0;i<12;i++)S.sparks.push({x:32,y:26,vx:Math.cos(i)*.6,vy:Math.sin(i)*.6,c:'#fff3b0',t:performance.now(),l:700});renderCert(S.mine,S.g,S.certMode)}return}}\nif(S.scene=='room'&&first&&hatchOn()&&p[0]>=1&&p[0]<=15&&p[1]<9.5){goAttic();return}\nif(S.scene=='room'&&first&&p[0]>=10.5&&p[0]<=15.5&&p[1]>=10&&p[1]<=18&&isMine()){if(!give('carrot'))for(let i=0;i<6;i++)S.sparks.push({x:13,y:13,vx:Math.random()-.5,vy:-Math.random(),c:'#9cc98a',t:performance.now(),l:600});else for(let i=0;i<10;i++)S.sparks.push({x:13,y:13,vx:Math.random()-.5,vy:-Math.random(),c:'#f08a3c',t:performance.now(),l:800});return}\nif(S.scene=='room'&&first&&p[0]>=3&&p[0]<=10.5&&p[1]>=7&&p[1]<=19){startBreath();return}\nif(S.scene=='room'&&first&&p[0]>46&&p[1]>30&&p[1]<50){S.cat=performance.now();mrrp()}else if(first&&Math.abs(p[0]-32)<16&&p[1]>28&&p[1]<54){S.ev={k:'tap',t:performance.now(),d:700};chirp(S.shown||DEFAULT)}else if(first){for(let i=0;i<6;i++)S.sparks.push({x:p[0],y:p[1],vx:Math.random()-.5,vy:Math.random()-.5,c:'#fff3b0',t:performance.now(),l:700})}}\nbindSwipe($('#screen'));\n/* the touch pad works like the real device: the pad is a little map of the screen.\n   Swipe it to clear dust. Otherwise slide to aim (a dot shows where you are) and let go to tap. */\nfunction padAt(e,el){const r=$('#pad').getBoundingClientRect(),m=.08,cl=v=>Math.min(1,Math.max(0,(v-m)/(1-2*m)));return[cl((e.clientX-r.left)/r.width)*63.9,cl((e.clientY-r.top)/r.height)*63.9]}\n(function bindPad(el){let down=false,last=null,dusty=false;\nel.addEventListener('pointerdown',e=>{e.preventDefault();down=true;try{el.setPointerCapture(e.pointerId)}catch(_){}ac();last=padAt(e,el);dusty=dustOn();S.cur={x:last[0],y:last[1],on:true,t:performance.now()};if(dusty)onTouch(last,true)});\nel.addEventListener('pointermove',e=>{if(!down)return;const p=padAt(e,el);S.cur.x=p[0];S.cur.y=p[1];if(dustOn()){const dx=p[0]-last[0],dy=p[1]-last[1],n=Math.max(1,Math.ceil(Math.hypot(dx,dy)/2));for(let i=1;i<=n;i++)onTouch([last[0]+dx*i/n,last[1]+dy*i/n],false)}last=p});\nconst up=e=>{if(!down)return;down=false;S.cur.on=false;S.cur.t=performance.now();if(!dusty&&!dustOn()&&e.type=='pointerup')onTouch([S.cur.x,S.cur.y],true)};\nel.addEventListener('pointerup',up);el.addEventListener('pointercancel',up)})($('.base'));\n\nfunction wake(){if(S.phase!='dust')return;S.phase='awake';S.wokeAt=performance.now();for(const d of dust){if(!d.gone){const a=Math.random()*6.28;d.vx+=Math.cos(a)*.6;d.vy+=Math.sin(a)*.6-.3}}\nS.ev={k:'ohhi',t:performance.now()+250,d:1600};setTimeout(()=>chirp(DEFAULT),650);\n$('#hint').textContent=\"Oh hi! He's never existed before.\";$('#padTxt').textContent='slide, let go to tap';$('#padTxt').style.opacity=1;\nsetTimeout(()=>{$('#pHello').classList.remove('hidden');$('#pHello').scrollIntoView({behavior:'smooth',block:'center'})},1300)}\n\n/* ---------- birth ---------- */\nlet MOTES={};\nasync function loadMotes(){try{MOTES=await C.all('mote:')}catch(e){MOTES={}}return MOTES}\nfunction codesInUse(){return new Set(Object.values(MOTES).map(m=>genome(m.seed).code))}\n$('#born').onclick=async()=>{const n=$('#name').value.trim().slice(0,24);if(!n){$('#name').focus();toast('Give him a name to belong to');return}\n$('#born').disabled=true;await loadMotes();const used=codesInUse();let seed=newSeed();while(used.has(genome(seed).code))seed=newSeed();\nconst id=Date.now().toString(36)+'-'+Math.random().toString(36).slice(2,6);const rec={owner:n,kind:'human',seed,at:Date.now()};\ntry{await C.set('mote:'+id,rec)}catch(e){toast(\"He couldn't be saved just now. Try again?\");$('#born').disabled=false;return}\nS.mine={id,...rec};show(S.mine,true);$('#pHello').classList.add('hidden');renderNursery()};\n$('#name').addEventListener('keydown',e=>{if(e.key=='Enter')$('#born').click()});\nlet giftT;function show(rec,isBirth){if(S.br){S.br=null;S.steam=[];$('#padTxt').textContent='slide, let go to tap'}S.scene='room';S.atticDust=false;S.rec=rec;const g=genome(rec.seed);S.g=g;S.shown=g;\nclearTimeout(giftT);if(isMine()&&!haveT(rec).includes('seashell'))giftT=setTimeout(()=>{if(S.scene=='room'&&!S.br)give('seashell')},isBirth?4500:3000);S.ev={k:isBirth?'born':'ohhi',t:performance.now(),d:isBirth?1400:1600};chirp(g);\nfor(let i=0;i<40;i++)S.sparks.push({x:32,y:40,vx:Math.cos(i)*(.5+Math.random()),vy:Math.sin(i)*(.5+Math.random()),c:i%2?'#fff3b0':'#f6c945',t:performance.now(),l:900+Math.random()*600});\nS.certMode=isBirth===true?false:isBirth;renderCert(rec,g,isBirth);$('#hint').textContent=isBirth?`${rec.owner}'s Mote was just born.`:`Visiting ${rec.owner}'s Mote.`;}\nfunction idxOf(rec){const l=Object.values(MOTES).sort((a,b)=>a.at-b.at);const i=l.findIndex(m=>m.seed==rec.seed);return i<0?l.length:i+1}\nfunction renderCert(rec,g,isBirth){const mine=S.mine&&S.mine.seed==rec.seed;const el=$('#pCert');el.classList.remove('hidden');\nel.innerHTML=`<h2>${mine?'Your':esc(rec.owner)+'’s'} Mote${rec.kind=='agent'?'<span class=\"badge\">agent</span>':''}</h2>\n<div class=\"code\">${g.code}</div><div class=\"meta\" style=\"color:var(--soft);font-size:13px\">Mote no. ${idxOf(rec)} · born ${new Date(rec.at).toLocaleDateString(undefined,{month:'short',day:'numeric',year:'numeric'})}${mine?'':' · for '+esc(rec.owner)}</div>\n<div class=\"dna\" aria-label=\"genome strip\">${g.dna.map(d=>`<i style=\"background:${DNA_COLORS[d]}\"></i>`).join('')}</div>\n<div class=\"traits\"><b>nature</b><span>${g.temps[0]} and ${g.temps[1]}</span><b>habit</b><span>${HABITS[g.habit]}</span><b>favourite</b><span>${g.fav} (there's a painting of it on his wall)</span><b>breathes</b><span>every ${g.breath.toFixed(1)} seconds</span><b>blinks</b><span>every ${g.blink.toFixed(1)} seconds</span><b>voice</b><span>${g.chirp.notes.length}-note chirp, ${g.chirp.base<700?'low and soft':g.chirp.base<900?'sweet and middling':'high and bright'}</span><b>topper</b><span>wearing a ${TOPPERS[wearT(rec)]}${haveT(rec).length>1?' · has '+haveT(rec).map(k=>TOPPERS[k]).join(', '):''}</span></div>${mine&&haveT(rec).length>1?'<p style=\"font-size:13px;color:var(--soft);margin:8px 0 0\">Tap the hatch in his ceiling to visit the dusty attic and try on his toppers.</p>':''}\n<div class=\"row\"><button class=\"btn\" id=\"hear\">hear his chirp ♪</button><button class=\"btn\" id=\"breatheBtn\">breathe with him ☕</button>${mine?'':'<button class=\"btn ghost\" id=\"backMine\">'+(S.mine?'back to mine':'meet your own')+'</button>'}</div>\n<p class=\"once\">${mine?'There will never be another one like him.':'One of a kind, like all of them.'}</p>\n${mine&&isBirth!==null?`<div class=\"want\"><p>Honest question: would you want a real one, a tiny compact you carry, with your Mote inside?</p><div class=\"row\" id=\"wantRow\"><button class=\"btn\" data-w=\"yes\">yes please</button><button class=\"btn\" data-w=\"maybe\">maybe</button><button class=\"btn\" data-w=\"no\">not for me</button></div></div>`:''}`;\n$('#hear').onclick=()=>{ac();chirp(g);S.ev={k:'tap',t:performance.now(),d:700}};\n$('#breatheBtn').onclick=()=>{window.scrollTo({top:0,behavior:'smooth'});startBreath()};\nconst bm=$('#backMine');if(bm)bm.onclick=()=>{if(S.mine)show(S.mine,false);else{$('#pCert').classList.add('hidden');S.shown=null;$('#pHello').classList.remove('hidden');$('#hint').textContent='Meet your own Mote.'}window.scrollTo({top:0,behavior:'smooth'})};\nconst wr=$('#wantRow');if(wr)wr.querySelectorAll('button').forEach(b=>b.onclick=async()=>{wr.querySelectorAll('button').forEach(x=>x.classList.toggle('on',x==b));try{S.mine.want=b.dataset.w;await saveMine();toast(b.dataset.w=='yes'?'Noted, thank you! ✦':'Thank you for telling us.')}catch(e){}});\nif(isBirth)el.scrollIntoView({behavior:'smooth',block:'start'})}\n\n/* ---------- find an existing Mote ---------- */\n$('#haveOne').onclick=()=>{$('#pHello').classList.add('hidden');$('#pFind').classList.remove('hidden');$('#fname').focus()};\n$('#backNew').onclick=()=>{$('#pFind').classList.add('hidden');$('#pHello').classList.remove('hidden')};\n$('#findGo').onclick=async()=>{const q=$('#fname').value.trim().toLowerCase();if(!q)return;await loadMotes();\nconst hits=Object.entries(MOTES).filter(([k,m])=>String(m.owner||'').toLowerCase()==q).map(([k,m])=>({id:k.slice(5),...m}));\n$('#found').innerHTML=hits.length?hits.map((m,i)=>`<button class=\"btn\" style=\"margin:6px 6px 0 0\" data-i=\"${i}\">${genome(m.seed).code}</button>`).join(''):'<p class=\"sub\" style=\"text-align:left\">No Mote under that name yet. Maybe meet a new one?</p>';\n$('#found').querySelectorAll('button').forEach(b=>b.onclick=()=>{S.mine=hits[+b.dataset.i];$('#pFind').classList.add('hidden');show(S.mine,null)})};\n$('#fname').addEventListener('keydown',e=>{if(e.key=='Enter')$('#findGo').click()});\n\n/* ---------- the nursery: everyone's Mote, each moving by its own genome ---------- */\nlet NSHOW=12,thumbs=[];\nasync function renderNursery(){await loadMotes();const list=Object.entries(MOTES).filter(([k,m])=>m&&Number.isFinite(m.seed)).map(([k,m])=>({id:k.slice(5),...m})).sort((a,b)=>b.at-a.at);\n$('#nCount').textContent=list.length?`${list.length} Mote${list.length==1?'':'s'} born so far, for humans and agents. No two are alike.`:'No Motes yet. Yours could be the very first.';\nconst box=$('#nursery');box.innerHTML='';thumbs=[];\nfor(const m of list.slice(0,NSHOW)){const g=genome(m.seed);const d=document.createElement('div');d.className='nm';d.tabIndex=0;d.setAttribute('role','button');d.setAttribute('aria-label',`${m.owner}'s Mote`);\nd.innerHTML=`<canvas width=\"64\" height=\"64\"></canvas><div class=\"who\">${esc(m.owner)}${m.kind=='agent'?'<span class=\"badge\">agent</span>':''}</div><div class=\"cd\">${g.code}</div>`;\nconst go=()=>{show(m,false);window.scrollTo({top:0,behavior:'smooth'})};d.onclick=go;d.onkeydown=e=>{if(e.key=='Enter')go()};\nbox.appendChild(d);const cx=d.querySelector('canvas').getContext('2d');cx.imageSmoothingEnabled=false;thumbs.push({cx,g,w:m.wear,off:Math.random()*5000})}\n$('#more').classList.toggle('hidden',list.length<=NSHOW)}\n$('#more').onclick=()=>{NSHOW+=12;renderNursery()};\n(function thumbLoop(t){for(const th of thumbs){const x=th.cx;drawRoom(x,t,true,th.g);{const st=moteState(th.g,t+th.off,null);st.topper=TOPPERS[th.w]?th.w:'star';drawMote(x,32,49,st)}}requestAnimationFrame(thumbLoop)})(0);\n\nlet chT;C.onChange(()=>{clearTimeout(chT);chT=setTimeout(renderNursery,700)});\nrenderNursery();\n</script>\n</body>\n</html>\n"
}