Back to Duck Duck Duel
SOURCE / PINNED RELEASE

Made of little things.

Duck Duck Duel

Release
a9f7805c9f9b…
Author-recorded commit
132a2226863c…
License
Check the original source
Author’s source reference
nostr://npub1jh5607spfutdye9x6jmuzr32hkadz7z4ntehtvehc5wdl9hv0cvsws7un9/wss%3A%2F%2Fgit.napplet.soy%2F/n-96e9a84a0f2

The hash-verified playable HTML, which may contain bundled or minified code. This view does not execute it.

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Duck Duck Duel</title>
    <script type="module" crossorigin>function je(){const t=new Map;function e(o,l){if(t.has(o))throw new Error(`NAP domain "${o}" is already registered`);t.set(o,l)}function r(o){const l=o.type.indexOf(".");if(l<=0)return!1;const s=o.type.slice(0,l),i=t.get(s);return i?(i(o),!0):!1}function n(){return Array.from(t.keys())}return{registerNap:e,dispatch:r,getRegisteredDomains:n}}var We=je(),it=We.registerNap,xt="relay";function Bt(){var e;const t=window;if(!((e=t.napplet)!=null&&e.relay))throw new Error("window.napplet.relay is unavailable -- runtime did not inject the relay domain");return t.napplet.relay}function Ge(t,e,r,n){return Bt().subscribe(t,e,r,n)}function $e(t,e){return Bt().publish(t,e)}function ie(t){return Bt().query(t)}it(xt,t=>{});var se="identity";function le(){var e;const t=window;if(!((e=t.napplet)!=null&&e.identity))throw new Error("window.napplet.identity is unavailable -- runtime did not inject this domain");return t.napplet.identity}function ae(){return le().getPublicKey()}function ce(){return le().getProfile()}it(se,t=>{});var Ut="storage";it(Ut,t=>{});var Ht="resource";it(Ht,t=>{});var ue="cvm";it(ue,t=>{});var fe="webrtc";it(fe,async()=>{});var Kt="link";function qe(){var e;const t=window;if(!((e=t.napplet)!=null&&e.link))throw new Error("window.napplet.link is unavailable -- runtime did not inject this domain");return t.napplet.link}function de(t,e){return qe().open(t,e)}it(Kt,t=>{});function Ve(){const t=window;if(!t.napplet)throw new Error("window.napplet is unavailable -- runtime did not inject the napplet namespace");return t.napplet}function M(t){const r=Ve()[t];if(!r)throw new Error(`window.napplet.${String(t)} is unavailable -- runtime did not inject this domain`);return r}var he={getItem(t){return M("storage").getItem(t)},setItem(t,e){return M("storage").setItem(t,e)},removeItem(t){return M("storage").removeItem(t)},keys(){return M("storage").keys()},instance:{getItem(t){return M("storage").instance.getItem(t)},setItem(t,e){return M("storage").instance.setItem(t,e)},removeItem(t){return M("storage").instance.removeItem(t)},keys(){return M("storage").instance.keys()}}},Ct={get(){return M("config").get()},subscribe(t){return M("config").subscribe(t)},openSettings(t){M("config").openSettings(t)},registerSchema(t,e){return M("config").registerSchema(t,e)},onSchemaError(t){return M("config").onSchemaError(t)},get schema(){return M("config").schema}},ye={info(){return M("resource").info()},bytes(t,e){return M("resource").bytes(t,e)},bytesMany(t,e){return M("resource").bytesMany(t,e)},bytesAsObjectURL(t){return M("resource").bytesAsObjectURL(t)}},qt={discover(t){return M("cvm").discover(t)},request(t,e,r){return M("cvm").request(t,e,r)},listTools(t,e){return M("cvm").listTools(t,e)},callTool(t,e,r,n){return M("cvm").callTool(t,e,r,n)},listResources(t,e){return M("cvm").listResources(t,e)},readResource(t,e,r){return M("cvm").readResource(t,e,r)},close(t){return M("cvm").close(t)},onEvent(t){return M("cvm").onEvent(t)},registry:{list(t){return M("cvm").registry.list(t)},has(t,e){return M("cvm").registry.has(t,e)},describe(t,e){return M("cvm").registry.describe(t,e)},call(t,e,r,n){return M("cvm").registry.call(t,e,r,n)}}};function Qe(t,e){return!!(t!=null&&t[e])}function q(t){return Qe(window.napplet,t)}const Je="http://json-schema.org/draft-07/schema#",Ze=1,Xe="object",ze=!1,tn={textSize:{type:"integer",title:"Text size",description:"Base text size in pixels. Changes apply while the napplet is running.",minimum:10,maximum:20,default:13,"x-napplet-section":"Appearance","x-napplet-order":1},controlSize:{type:"integer",title:"Control height",description:"Choose compact controls or larger touch targets, in pixels.",minimum:24,maximum:44,default:28,"x-napplet-section":"Appearance","x-napplet-order":2},selectText:{type:"boolean",title:"Allow text selection",description:"Allow selecting interface text. Text inputs always remain selectable.",default:!1,"x-napplet-section":"Interaction"}},en={$schema:Je,$version:Ze,type:Xe,additionalProperties:ze,properties:tn};q("config")&&(async()=>{Ct.schema||await Ct.registerSchema(en);const t=Ct.subscribe(e=>{const r=document.documentElement.style,n=typeof e.textSize=="number"?e.textSize:13,o=typeof e.controlSize=="number"?e.controlSize:28;r.fontSize=`${n}px`,r.setProperty("--control-h",`${o}px`),r.setProperty("--napplet-text-selection",e.selectText===!0?"text":"none")});window.addEventListener("pagehide",()=>t.close(),{once:!0})})().catch(()=>{});const nn=1,rn="naddr1qvzqqqyf8ypzp90f5laqznck6fj2d49hcy8z40d669u9txhnwken03gum7twclseqqxkutfexejnjcfcx3snqe3j5wnrxy",on={pubkey:"60517f64548279854ee9a122531e4d1a413e3dc956e2d0a450217420623ca688",relays:["wss://relay.napplet.soy/"]},sn=[],At={version:nn,napplet:rn,provider:on,boards:sn},pe="duck-duel-highs-v1",ln="soy.boards.v1",Ft=q(ue);async function me(t,e){const r=At.provider?await qt.callTool(At.provider,t,e):await qt.registry.call(ln,t,e);if(r.isError)throw new Error((r.content??[]).filter(n=>n.type==="text").map(n=>n.text).join(`
`)||"Backend request failed");return r.structuredContent}async function an(t,e){if(!Ft||!Number.isFinite(t))return!1;try{return await me("soy_board_submit",{napplet:At.napplet,board:pe,score:Math.round(t),name:e}),!0}catch{return!1}}async function cn(t=3){if(!Ft)return null;try{const e=await me("soy_board_read",{napplet:At.napplet,board:pe,limit:t});return Array.isArray(e==null?void 0:e.rows)?e.rows:null}catch{return null}}const un="qpzry9x8gf2tvdw0s3jn54khce6mua7l",fn=[996825010,642813549,513874426,1027748829,705979059];function dn(t){let e=1;for(const r of t){const n=e>>25;e=(e&33554431)<<5^r;for(let o=0;o<5;o++)n>>o&1&&(e^=fn[o])}return e}function hn(t){const e=[];for(let r=0;r<t.length;r++)e.push(t.charCodeAt(r)>>5);e.push(0);for(let r=0;r<t.length;r++)e.push(t.charCodeAt(r)&31);return e}function yn(t){try{if(!/^[0-9a-fA-F]{64}$/.test(t))return null;const e=[];for(let g=0;g<t.length;g+=2)e.push(parseInt(t.slice(g,g+2),16));const r=[];let n=0,o=0;for(const g of e){for(n=n<<8|g,o+=8;o>=5;)o-=5,r.push(n>>o&31);n&=(1<<o)-1}o>0&&r.push(n<<5-o&31);const l="npub",s=[...hn(l),...r,0,0,0,0,0,0],i=dn(s)^1,c=[];for(let g=0;g<6;g++)c.push(i>>5*(5-g)&31);return l+"1"+[...r,...c].map(g=>un[g]).join("")}catch{return null}}const pn="npub1lqwh96qnf0m5q86dddj6yvjtrpnxtycjvhgzumvrjhhqhjp6qq4sjlnzwg",mn="f81d72e8134bf7401f4d6b65a2324b186665931265d02e6d8395ee0bc83a002b",at=`${pn}@npub.cash`,Nt=210,gn=1e3,ut=790,kt=210,ge="duckduel:solo-unlocked";let we=!1;const Vt="qpzry9x8gf2tvdw0s3jn54khce6mua7l",wn=[996825010,642813549,513874426,1027748829,705979059];function bn(t){let e=1;for(const r of t){const n=e>>25;e=(e&33554431)<<5^r;for(let o=0;o<5;o++)n>>o&1&&(e^=wn[o])}return e}function kn(t){const e=[];for(const r of t)e.push(r.charCodeAt(0)>>5);e.push(0);for(const r of t)e.push(r.charCodeAt(0)&31);return e}function En(t,e,r,n){let o=0,l=0;const s=[],i=(1<<r)-1;for(const c of t){if(c<0||c>>e)return null;for(o=o<<e|c,l+=e;l>=r;)l-=r,s.push(o>>l&i)}return l&&s.push(o<<r-l&i),s}function Tn(t,e){const r=En(e,8,5)??[],n=[...kn(t),...r,0,0,0,0,0,0],o=bn(n)^1;let l="";for(let s=0;s<6;s++)l+=Vt[o>>5*(5-s)&31];return`${t}1${r.map(s=>Vt[s]).join("")}${l}`}function be(t){const e=t.indexOf("@");if(e<=0||e===t.length-1)return null;const r=t.slice(0,e),n=t.slice(e+1);return n.includes(".")?`https://${n}/.well-known/lnurlp/${r}`:null}function An(t){const e=be(t);return e?Tn("lnurl",[...e].map(r=>r.charCodeAt(0))):null}function xn(t){var r;for(const n of t.tags??[])if(n[0]==="amount"&&n[1]){const o=Number.parseInt(n[1],10);if(Number.isFinite(o)&&o>0)return o}const e=(r=(t.tags??[]).find(n=>n[0]==="description"))==null?void 0:r[1];if(e){try{const l=(JSON.parse(e).tags??[]).find(s=>s[0]==="amount");if(l!=null&&l[1]){const s=Number.parseInt(l[1],10);if(Number.isFinite(s)&&s>0)return s}}catch{}const n=/^ln\S{0,3}?(\d+)([munp])?/i.exec(e);if(n){const o=Number.parseInt(n[1],10),l=n[2]==="m"?1e8:n[2]==="u"?1e5:n[2]==="n"?100:n[2]==="p"?.1:NaN;if(Number.isFinite(o)&&Number.isFinite(l))return Math.round(o*l)}}return null}async function vn(t,e,r){if(!q(xt))return null;try{const n=await ie({kinds:[9735],"#p":[t],since:r,limit:200});for(const o of n){const l=xn(o.event);if(l!==null&&l>=e)return!0}}catch{return null}return!1}async function ke(t,e){return vn(mn,t,e)}async function Cn(t,e){if(!t)return"no-address";if(!q(Kt))return"unavailable";const r=An(t);if(!r)return"no-address";try{const n=await de(`lightning:${r}`,{label:`Zap ${e} sats to ${t}`});return(n==null?void 0:n.status)==="opened"?"opened":"unavailable"}catch{return"unavailable"}}async function Ee(t){if(!t||!q(Kt))return"unavailable";try{const e=await de(`lightning:${t}`,{label:"Pay exact Lightning invoice"});return(e==null?void 0:e.status)==="opened"?"opened":"unavailable"}catch{return"unavailable"}}async function Te(t,e){if(!t||!q(Ht))return null;const r=be(t);if(!r)return null;try{const n=await ye.bytes(`${r}?amount=${e*1e3}`),o=JSON.parse(await n.text());if(typeof o.pr=="string"&&o.pr.startsWith("ln"))return{pr:o.pr,verify:typeof o.verify=="string"?o.verify:null}}catch{}return null}async function Ae(t){if(!q(Ht))return null;try{const e=await ye.bytes(t),r=JSON.parse(await e.text());return r.settled===!0||r.paid===!0?!0:r.settled===!1||r.paid===!1?!1:null}catch{return null}}async function xe(t){if(!t||!q(xt))return null;try{const e=await ie({kinds:[0],authors:[t],limit:1});for(const r of e)try{const n=JSON.parse(r.event.content);if(n.lud16)return n.lud16;if(n.lud06)return n.lud06}catch{}}catch{}return null}async function Sn(){if(we)return!0;if(!q(Ut))return!1;try{return await he.getItem(ge)==="1"}catch{return!1}}async function Rn(){if(we=!0,!!q(Ut))try{await he.setItem(ge,"1")}catch{}}const ct=function(t,e){let o=t;const l=dt[e];let s=null,i=0,c=null;const g=[],E={},b=function(h,m){i=o*4+17,s=(function(d){const p=new Array(d);for(let y=0;y<d;y+=1){p[y]=new Array(d);for(let k=0;k<d;k+=1)p[y][k]=null}return p})(i),w(0,0),w(i-7,0),w(0,i-7),T(),a(),N(h,m),o>=7&&L(h),c==null&&(c=W(o,l,g)),I(c,m)},w=function(h,m){for(let d=-1;d<=7;d+=1)if(!(h+d<=-1||i<=h+d))for(let p=-1;p<=7;p+=1)m+p<=-1||i<=m+p||(0<=d&&d<=6&&(p==0||p==6)||0<=p&&p<=6&&(d==0||d==6)||2<=d&&d<=4&&2<=p&&p<=4?s[h+d][m+p]=!0:s[h+d][m+p]=!1)},P=function(){let h=0,m=0;for(let d=0;d<8;d+=1){b(!0,d);const p=tt.getLostPoint(E);(d==0||h>p)&&(h=p,m=d)}return m},a=function(){for(let h=8;h<i-8;h+=1)s[h][6]==null&&(s[h][6]=h%2==0);for(let h=8;h<i-8;h+=1)s[6][h]==null&&(s[6][h]=h%2==0)},T=function(){const h=tt.getPatternPosition(o);for(let m=0;m<h.length;m+=1)for(let d=0;d<h.length;d+=1){const p=h[m],y=h[d];if(s[p][y]==null)for(let k=-2;k<=2;k+=1)for(let x=-2;x<=2;x+=1)k==-2||k==2||x==-2||x==2||k==0&&x==0?s[p+k][y+x]=!0:s[p+k][y+x]=!1}},L=function(h){const m=tt.getBCHTypeNumber(o);for(let d=0;d<18;d+=1){const p=!h&&(m>>d&1)==1;s[Math.floor(d/3)][d%3+i-8-3]=p}for(let d=0;d<18;d+=1){const p=!h&&(m>>d&1)==1;s[d%3+i-8-3][Math.floor(d/3)]=p}},N=function(h,m){const d=l<<3|m,p=tt.getBCHTypeInfo(d);for(let y=0;y<15;y+=1){const k=!h&&(p>>y&1)==1;y<6?s[y][8]=k:y<8?s[y+1][8]=k:s[i-15+y][8]=k}for(let y=0;y<15;y+=1){const k=!h&&(p>>y&1)==1;y<8?s[8][i-y-1]=k:y<9?s[8][15-y-1+1]=k:s[8][15-y-1]=k}s[i-8][8]=!h},I=function(h,m){let d=-1,p=i-1,y=7,k=0;const x=tt.getMaskFunction(m);for(let D=i-1;D>0;D-=2)for(D==6&&(D-=1);;){for(let B=0;B<2;B+=1)if(s[p][D-B]==null){let H=!1;k<h.length&&(H=(h[k]>>>y&1)==1),x(p,D-B)&&(H=!H),s[p][D-B]=H,y-=1,y==-1&&(k+=1,y=7)}if(p+=d,p<0||i<=p){p-=d,d=-d;break}}},_=function(h,m){let d=0,p=0,y=0;const k=new Array(m.length),x=new Array(m.length);for(let S=0;S<m.length;S+=1){const U=m[S].dataCount,$=m[S].totalCount-U;p=Math.max(p,U),y=Math.max(y,$),k[S]=new Array(U);for(let Z=0;Z<k[S].length;Z+=1)k[S][Z]=255&h.getBuffer()[Z+d];d+=U;const vt=tt.getErrorCorrectPolynomial($),Gt=yt(k[S],vt.getLength()-1).mod(vt);x[S]=new Array(vt.getLength()-1);for(let Z=0;Z<x[S].length;Z+=1){const $t=Z+Gt.getLength()-x[S].length;x[S][Z]=$t>=0?Gt.getAt($t):0}}let D=0;for(let S=0;S<m.length;S+=1)D+=m[S].totalCount;const B=new Array(D);let H=0;for(let S=0;S<p;S+=1)for(let U=0;U<m.length;U+=1)S<k[U].length&&(B[H]=k[U][S],H+=1);for(let S=0;S<y;S+=1)for(let U=0;U<m.length;U+=1)S<x[U].length&&(B[H]=x[U][S],H+=1);return B},W=function(h,m,d){const p=Qt.getRSBlocks(h,m),y=Jt();for(let x=0;x<d.length;x+=1){const D=d[x];y.put(D.getMode(),4),y.put(D.getLength(),tt.getLengthInBits(D.getMode(),h)),D.write(y)}let k=0;for(let x=0;x<p.length;x+=1)k+=p[x].dataCount;if(y.getLengthInBits()>k*8)throw"code length overflow. ("+y.getLengthInBits()+">"+k*8+")";for(y.getLengthInBits()+4<=k*8&&y.put(0,4);y.getLengthInBits()%8!=0;)y.putBit(!1);for(;!(y.getLengthInBits()>=k*8||(y.put(236,8),y.getLengthInBits()>=k*8));)y.put(17,8);return _(y,p)};E.addData=function(h,m){m=m||"Byte";let d=null;switch(m){case"Numeric":d=Ln(h);break;case"Alphanumeric":d=Pn(h);break;case"Byte":d=Nn(h);break;case"Kanji":d=Mn(h);break;default:throw"mode:"+m}g.push(d),c=null},E.isDark=function(h,m){if(h<0||i<=h||m<0||i<=m)throw h+","+m;return s[h][m]},E.getModuleCount=function(){return i},E.make=function(){if(o<1){let h=1;for(;h<40;h++){const m=Qt.getRSBlocks(h,l),d=Jt();for(let y=0;y<g.length;y++){const k=g[y];d.put(k.getMode(),4),d.put(k.getLength(),tt.getLengthInBits(k.getMode(),h)),k.write(d)}let p=0;for(let y=0;y<m.length;y++)p+=m[y].dataCount;if(d.getLengthInBits()<=p*8)break}o=h}b(!1,P())},E.createTableTag=function(h,m){h=h||2,m=typeof m>"u"?h*4:m;let d="";d+='<table style="',d+=" border-width: 0px; border-style: none;",d+=" border-collapse: collapse;",d+=" padding: 0px; margin: "+m+"px;",d+='">',d+="<tbody>";for(let p=0;p<E.getModuleCount();p+=1){d+="<tr>";for(let y=0;y<E.getModuleCount();y+=1)d+='<td style="',d+=" border-width: 0px; border-style: none;",d+=" border-collapse: collapse;",d+=" padding: 0px; margin: 0px;",d+=" width: "+h+"px;",d+=" height: "+h+"px;",d+=" background-color: ",d+=E.isDark(p,y)?"#000000":"#ffffff",d+=";",d+='"/>';d+="</tr>"}return d+="</tbody>",d+="</table>",d},E.createSvgTag=function(h,m,d,p){let y={};typeof arguments[0]=="object"&&(y=arguments[0],h=y.cellSize,m=y.margin,d=y.alt,p=y.title),h=h||2,m=typeof m>"u"?h*4:m,d=typeof d=="string"?{text:d}:d||{},d.text=d.text||null,d.id=d.text?d.id||"qrcode-description":null,p=typeof p=="string"?{text:p}:p||{},p.text=p.text||null,p.id=p.text?p.id||"qrcode-title":null;const k=E.getModuleCount()*h+m*2;let x,D,B,H,S="",U;for(U="l"+h+",0 0,"+h+" -"+h+",0 0,-"+h+"z ",S+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',S+=y.scalable?"":' width="'+k+'px" height="'+k+'px"',S+=' viewBox="0 0 '+k+" "+k+'" ',S+=' preserveAspectRatio="xMinYMin meet"',S+=p.text||d.text?' role="img" aria-labelledby="'+F([p.id,d.id].join(" ").trim())+'"':"",S+=">",S+=p.text?'<title id="'+F(p.id)+'">'+F(p.text)+"</title>":"",S+=d.text?'<description id="'+F(d.id)+'">'+F(d.text)+"</description>":"",S+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',S+='<path d="',B=0;B<E.getModuleCount();B+=1)for(H=B*h+m,x=0;x<E.getModuleCount();x+=1)E.isDark(B,x)&&(D=x*h+m,S+="M"+D+","+H+U);return S+='" stroke="transparent" fill="black"/>',S+="</svg>",S},E.createDataURL=function(h,m){h=h||2,m=typeof m>"u"?h*4:m;const d=E.getModuleCount()*h+m*2,p=m,y=d-m;return _n(d,d,function(k,x){if(p<=k&&k<y&&p<=x&&x<y){const D=Math.floor((k-p)/h),B=Math.floor((x-p)/h);return E.isDark(B,D)?0:1}else return 1})},E.createImgTag=function(h,m,d){h=h||2,m=typeof m>"u"?h*4:m;const p=E.getModuleCount()*h+m*2;let y="";return y+="<img",y+=' src="',y+=E.createDataURL(h,m),y+='"',y+=' width="',y+=p,y+='"',y+=' height="',y+=p,y+='"',d&&(y+=' alt="',y+=F(d),y+='"'),y+="/>",y};const F=function(h){let m="";for(let d=0;d<h.length;d+=1){const p=h.charAt(d);switch(p){case"<":m+="&lt;";break;case">":m+="&gt;";break;case"&":m+="&amp;";break;case'"':m+="&quot;";break;default:m+=p;break}}return m},O=function(h){h=typeof h>"u"?2:h;const d=E.getModuleCount()*1+h*2,p=h,y=d-h;let k,x,D,B,H;const S={"██":"█","█ ":"▀"," █":"▄","  ":" "},U={"██":"▀","█ ":"▀"," █":" ","  ":" "};let $="";for(k=0;k<d;k+=2){for(D=Math.floor((k-p)/1),B=Math.floor((k+1-p)/1),x=0;x<d;x+=1)H="█",p<=x&&x<y&&p<=k&&k<y&&E.isDark(D,Math.floor((x-p)/1))&&(H=" "),p<=x&&x<y&&p<=k+1&&k+1<y&&E.isDark(B,Math.floor((x-p)/1))?H+=" ":H+="█",$+=h<1&&k+1>=y?U[H]:S[H];$+=`
`}return d%2&&h>0?$.substring(0,$.length-d-1)+Array(d+1).join("▀"):$.substring(0,$.length-1)};return E.createASCII=function(h,m){if(h=h||1,h<2)return O(m);h-=1,m=typeof m>"u"?h*2:m;const d=E.getModuleCount()*h+m*2,p=m,y=d-m;let k,x,D,B;const H=Array(h+1).join("██"),S=Array(h+1).join("  ");let U="",$="";for(k=0;k<d;k+=1){for(D=Math.floor((k-p)/h),$="",x=0;x<d;x+=1)B=1,p<=x&&x<y&&p<=k&&k<y&&E.isDark(D,Math.floor((x-p)/h))&&(B=0),$+=B?H:S;for(D=0;D<h;D+=1)U+=$+`
`}return U.substring(0,U.length-1)},E.renderTo2dContext=function(h,m){m=m||2;const d=E.getModuleCount();for(let p=0;p<d;p++)for(let y=0;y<d;y++)h.fillStyle=E.isDark(p,y)?"black":"white",h.fillRect(y*m,p*m,m,m)},E};ct.stringToBytes=function(t){const e=[];for(let r=0;r<t.length;r+=1){const n=t.charCodeAt(r);e.push(n&255)}return e};ct.createStringToBytes=function(t,e){const r=(function(){const o=On(t),l=function(){const c=o.read();if(c==-1)throw"eof";return c};let s=0;const i={};for(;;){const c=o.read();if(c==-1)break;const g=l(),E=l(),b=l(),w=String.fromCharCode(c<<8|g),P=E<<8|b;i[w]=P,s+=1}if(s!=e)throw s+" != "+e;return i})(),n=63;return function(o){const l=[];for(let s=0;s<o.length;s+=1){const i=o.charCodeAt(s);if(i<128)l.push(i);else{const c=r[o.charAt(s)];typeof c=="number"?(c&255)==c?l.push(c):(l.push(c>>>8),l.push(c&255)):l.push(n)}}return l}};const Y={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},dt={L:1,M:0,Q:3,H:2},z={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},tt=(function(){const t=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],e=1335,r=7973,n=21522,o={},l=function(s){let i=0;for(;s!=0;)i+=1,s>>>=1;return i};return o.getBCHTypeInfo=function(s){let i=s<<10;for(;l(i)-l(e)>=0;)i^=e<<l(i)-l(e);return(s<<10|i)^n},o.getBCHTypeNumber=function(s){let i=s<<12;for(;l(i)-l(r)>=0;)i^=r<<l(i)-l(r);return s<<12|i},o.getPatternPosition=function(s){return t[s-1]},o.getMaskFunction=function(s){switch(s){case z.PATTERN000:return function(i,c){return(i+c)%2==0};case z.PATTERN001:return function(i,c){return i%2==0};case z.PATTERN010:return function(i,c){return c%3==0};case z.PATTERN011:return function(i,c){return(i+c)%3==0};case z.PATTERN100:return function(i,c){return(Math.floor(i/2)+Math.floor(c/3))%2==0};case z.PATTERN101:return function(i,c){return i*c%2+i*c%3==0};case z.PATTERN110:return function(i,c){return(i*c%2+i*c%3)%2==0};case z.PATTERN111:return function(i,c){return(i*c%3+(i+c)%2)%2==0};default:throw"bad maskPattern:"+s}},o.getErrorCorrectPolynomial=function(s){let i=yt([1],0);for(let c=0;c<s;c+=1)i=i.multiply(yt([1,et.gexp(c)],0));return i},o.getLengthInBits=function(s,i){if(1<=i&&i<10)switch(s){case Y.MODE_NUMBER:return 10;case Y.MODE_ALPHA_NUM:return 9;case Y.MODE_8BIT_BYTE:return 8;case Y.MODE_KANJI:return 8;default:throw"mode:"+s}else if(i<27)switch(s){case Y.MODE_NUMBER:return 12;case Y.MODE_ALPHA_NUM:return 11;case Y.MODE_8BIT_BYTE:return 16;case Y.MODE_KANJI:return 10;default:throw"mode:"+s}else if(i<41)switch(s){case Y.MODE_NUMBER:return 14;case Y.MODE_ALPHA_NUM:return 13;case Y.MODE_8BIT_BYTE:return 16;case Y.MODE_KANJI:return 12;default:throw"mode:"+s}else throw"type:"+i},o.getLostPoint=function(s){const i=s.getModuleCount();let c=0;for(let b=0;b<i;b+=1)for(let w=0;w<i;w+=1){let P=0;const a=s.isDark(b,w);for(let T=-1;T<=1;T+=1)if(!(b+T<0||i<=b+T))for(let L=-1;L<=1;L+=1)w+L<0||i<=w+L||T==0&&L==0||a==s.isDark(b+T,w+L)&&(P+=1);P>5&&(c+=3+P-5)}for(let b=0;b<i-1;b+=1)for(let w=0;w<i-1;w+=1){let P=0;s.isDark(b,w)&&(P+=1),s.isDark(b+1,w)&&(P+=1),s.isDark(b,w+1)&&(P+=1),s.isDark(b+1,w+1)&&(P+=1),(P==0||P==4)&&(c+=3)}for(let b=0;b<i;b+=1)for(let w=0;w<i-6;w+=1)s.isDark(b,w)&&!s.isDark(b,w+1)&&s.isDark(b,w+2)&&s.isDark(b,w+3)&&s.isDark(b,w+4)&&!s.isDark(b,w+5)&&s.isDark(b,w+6)&&(c+=40);for(let b=0;b<i;b+=1)for(let w=0;w<i-6;w+=1)s.isDark(w,b)&&!s.isDark(w+1,b)&&s.isDark(w+2,b)&&s.isDark(w+3,b)&&s.isDark(w+4,b)&&!s.isDark(w+5,b)&&s.isDark(w+6,b)&&(c+=40);let g=0;for(let b=0;b<i;b+=1)for(let w=0;w<i;w+=1)s.isDark(w,b)&&(g+=1);const E=Math.abs(100*g/i/i-50)/5;return c+=E*10,c},o})(),et=(function(){const t=new Array(256),e=new Array(256);for(let n=0;n<8;n+=1)t[n]=1<<n;for(let n=8;n<256;n+=1)t[n]=t[n-4]^t[n-5]^t[n-6]^t[n-8];for(let n=0;n<255;n+=1)e[t[n]]=n;const r={};return r.glog=function(n){if(n<1)throw"glog("+n+")";return e[n]},r.gexp=function(n){for(;n<0;)n+=255;for(;n>=256;)n-=255;return t[n]},r})(),yt=function(t,e){if(typeof t.length>"u")throw t.length+"/"+e;const r=(function(){let o=0;for(;o<t.length&&t[o]==0;)o+=1;const l=new Array(t.length-o+e);for(let s=0;s<t.length-o;s+=1)l[s]=t[s+o];return l})(),n={};return n.getAt=function(o){return r[o]},n.getLength=function(){return r.length},n.multiply=function(o){const l=new Array(n.getLength()+o.getLength()-1);for(let s=0;s<n.getLength();s+=1)for(let i=0;i<o.getLength();i+=1)l[s+i]^=et.gexp(et.glog(n.getAt(s))+et.glog(o.getAt(i)));return yt(l,0)},n.mod=function(o){if(n.getLength()-o.getLength()<0)return n;const l=et.glog(n.getAt(0))-et.glog(o.getAt(0)),s=new Array(n.getLength());for(let i=0;i<n.getLength();i+=1)s[i]=n.getAt(i);for(let i=0;i<o.getLength();i+=1)s[i]^=et.gexp(et.glog(o.getAt(i))+l);return yt(s,0).mod(o)},n},Qt=(function(){const t=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],e=function(o,l){const s={};return s.totalCount=o,s.dataCount=l,s},r={},n=function(o,l){switch(l){case dt.L:return t[(o-1)*4+0];case dt.M:return t[(o-1)*4+1];case dt.Q:return t[(o-1)*4+2];case dt.H:return t[(o-1)*4+3];default:return}};return r.getRSBlocks=function(o,l){const s=n(o,l);if(typeof s>"u")throw"bad rs block @ typeNumber:"+o+"/errorCorrectionLevel:"+l;const i=s.length/3,c=[];for(let g=0;g<i;g+=1){const E=s[g*3+0],b=s[g*3+1],w=s[g*3+2];for(let P=0;P<E;P+=1)c.push(e(b,w))}return c},r})(),Jt=function(){const t=[];let e=0;const r={};return r.getBuffer=function(){return t},r.getAt=function(n){const o=Math.floor(n/8);return(t[o]>>>7-n%8&1)==1},r.put=function(n,o){for(let l=0;l<o;l+=1)r.putBit((n>>>o-l-1&1)==1)},r.getLengthInBits=function(){return e},r.putBit=function(n){const o=Math.floor(e/8);t.length<=o&&t.push(0),n&&(t[o]|=128>>>e%8),e+=1},r},Ln=function(t){const e=Y.MODE_NUMBER,r=t,n={};n.getMode=function(){return e},n.getLength=function(s){return r.length},n.write=function(s){const i=r;let c=0;for(;c+2<i.length;)s.put(o(i.substring(c,c+3)),10),c+=3;c<i.length&&(i.length-c==1?s.put(o(i.substring(c,c+1)),4):i.length-c==2&&s.put(o(i.substring(c,c+2)),7))};const o=function(s){let i=0;for(let c=0;c<s.length;c+=1)i=i*10+l(s.charAt(c));return i},l=function(s){if("0"<=s&&s<="9")return s.charCodeAt(0)-48;throw"illegal char :"+s};return n},Pn=function(t){const e=Y.MODE_ALPHA_NUM,r=t,n={};n.getMode=function(){return e},n.getLength=function(l){return r.length},n.write=function(l){const s=r;let i=0;for(;i+1<s.length;)l.put(o(s.charAt(i))*45+o(s.charAt(i+1)),11),i+=2;i<s.length&&l.put(o(s.charAt(i)),6)};const o=function(l){if("0"<=l&&l<="9")return l.charCodeAt(0)-48;if("A"<=l&&l<="Z")return l.charCodeAt(0)-65+10;switch(l){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+l}};return n},Nn=function(t){const e=Y.MODE_8BIT_BYTE,r=ct.stringToBytes(t),n={};return n.getMode=function(){return e},n.getLength=function(o){return r.length},n.write=function(o){for(let l=0;l<r.length;l+=1)o.put(r[l],8)},n},Mn=function(t){const e=Y.MODE_KANJI,r=ct.stringToBytes;(function(l,s){const i=r(l);if(i.length!=2||(i[0]<<8|i[1])!=s)throw"sjis not supported."})("友",38726);const n=r(t),o={};return o.getMode=function(){return e},o.getLength=function(l){return~~(n.length/2)},o.write=function(l){const s=n;let i=0;for(;i+1<s.length;){let c=(255&s[i])<<8|255&s[i+1];if(33088<=c&&c<=40956)c-=33088;else if(57408<=c&&c<=60351)c-=49472;else throw"illegal char at "+(i+1)+"/"+c;c=(c>>>8&255)*192+(c&255),l.put(c,13),i+=2}if(i<s.length)throw"illegal char at "+(i+1)},o},ve=function(){const t=[],e={};return e.writeByte=function(r){t.push(r&255)},e.writeShort=function(r){e.writeByte(r),e.writeByte(r>>>8)},e.writeBytes=function(r,n,o){n=n||0,o=o||r.length;for(let l=0;l<o;l+=1)e.writeByte(r[l+n])},e.writeString=function(r){for(let n=0;n<r.length;n+=1)e.writeByte(r.charCodeAt(n))},e.toByteArray=function(){return t},e.toString=function(){let r="";r+="[";for(let n=0;n<t.length;n+=1)n>0&&(r+=","),r+=t[n];return r+="]",r},e},Dn=function(){let t=0,e=0,r=0,n="";const o={},l=function(i){n+=String.fromCharCode(s(i&63))},s=function(i){if(i<0)throw"n:"+i;if(i<26)return 65+i;if(i<52)return 97+(i-26);if(i<62)return 48+(i-52);if(i==62)return 43;if(i==63)return 47;throw"n:"+i};return o.writeByte=function(i){for(t=t<<8|i&255,e+=8,r+=1;e>=6;)l(t>>>e-6),e-=6},o.flush=function(){if(e>0&&(l(t<<6-e),t=0,e=0),r%3!=0){const i=3-r%3;for(let c=0;c<i;c+=1)n+="="}},o.toString=function(){return n},o},On=function(t){const e=t;let r=0,n=0,o=0;const l={};l.read=function(){for(;o<8;){if(r>=e.length){if(o==0)return-1;throw"unexpected end of file./"+o}const c=e.charAt(r);if(r+=1,c=="=")return o=0,-1;if(c.match(/^\s$/))continue;n=n<<6|s(c.charCodeAt(0)),o+=6}const i=n>>>o-8&255;return o-=8,i};const s=function(i){if(65<=i&&i<=90)return i-65;if(97<=i&&i<=122)return i-97+26;if(48<=i&&i<=57)return i-48+52;if(i==43)return 62;if(i==47)return 63;throw"c:"+i};return l},In=function(t,e){const r=t,n=e,o=new Array(t*e),l={};l.setPixel=function(g,E,b){o[E*r+g]=b},l.write=function(g){g.writeString("GIF87a"),g.writeShort(r),g.writeShort(n),g.writeByte(128),g.writeByte(0),g.writeByte(0),g.writeByte(0),g.writeByte(0),g.writeByte(0),g.writeByte(255),g.writeByte(255),g.writeByte(255),g.writeString(","),g.writeShort(0),g.writeShort(0),g.writeShort(r),g.writeShort(n),g.writeByte(0);const E=2,b=i(E);g.writeByte(E);let w=0;for(;b.length-w>255;)g.writeByte(255),g.writeBytes(b,w,255),w+=255;g.writeByte(b.length-w),g.writeBytes(b,w,b.length-w),g.writeByte(0),g.writeString(";")};const s=function(g){const E=g;let b=0,w=0;const P={};return P.write=function(a,T){if(a>>>T)throw"length over";for(;b+T>=8;)E.writeByte(255&(a<<b|w)),T-=8-b,a>>>=8-b,w=0,b=0;w=a<<b|w,b=b+T},P.flush=function(){b>0&&E.writeByte(w)},P},i=function(g){const E=1<<g,b=(1<<g)+1;let w=g+1;const P=c();for(let I=0;I<E;I+=1)P.add(String.fromCharCode(I));P.add(String.fromCharCode(E)),P.add(String.fromCharCode(b));const a=ve(),T=s(a);T.write(E,w);let L=0,N=String.fromCharCode(o[L]);for(L+=1;L<o.length;){const I=String.fromCharCode(o[L]);L+=1,P.contains(N+I)?N=N+I:(T.write(P.indexOf(N),w),P.size()<4095&&(P.size()==1<<w&&(w+=1),P.add(N+I)),N=I)}return T.write(P.indexOf(N),w),T.write(b,w),T.flush(),a.toByteArray()},c=function(){const g={};let E=0;const b={};return b.add=function(w){if(b.contains(w))throw"dup key:"+w;g[w]=E,E+=1},b.size=function(){return E},b.indexOf=function(w){return g[w]},b.contains=function(w){return typeof g[w]<"u"},b};return l},_n=function(t,e,r){const n=In(t,e);for(let i=0;i<e;i+=1)for(let c=0;c<t;c+=1)n.setPixel(c,i,r(c,i));const o=ve();n.write(o);const l=Dn(),s=o.toByteArray();for(let i=0;i<s.length;i+=1)l.writeByte(s[i]);return l.flush(),"data:image/gif;base64,"+l};ct.stringToBytes;const st={relay:!1,identity:!1,webrtc:!1};function Bn(t){Object.assign(st,t||{})}function Un(t){let e=1779033703^t.length;for(let r=0;r<t.length;r++)e=Math.imul(e^t.charCodeAt(r),3432918353),e=e<<13|e>>>19;return function(){return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^=e>>>16)>>>0}}function Hn(t){return function(){t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function Zt(t,e,r){const n=Un(t+":"+e+":"+r);return Hn(n())}function ft(t,e){return Math.floor(t()*e)}const C={TICK_RATE:60,ROUNDS:5,DUCKS_PER_ROUND:3,BULLETS_PER_ROUND:2,SPEED_MULT:[1,1.15,1.3,1.5,1.7],TURN_EVERY:[[40,70],[35,60],[30,50],[25,45],[20,40]],MOCKS:[1,1,2,2,3],DUCK_LIMIT:480,MOCK_WINDOW:720,DUCK_BASE_SPEED:2.2,MOCK_SPEED:1.4,PUMP_COOLDOWN:6,DUCK_R:34,MOCK_R:28,FALL:45,INTERMISSION:120,DUCK_SPAWN_AT:60,MOCK_SPAWN_BASE:90,MOCK_SPAWN_GAP:60,MATCH_END_DELAY:60,DUCK_POINTS:10,MULTI_MULT:1.5,MOCK_PENALTY:5,PF:{x0:20,x1:780,y0:40,y1:340}},rt=["#4fc3ff","#ffb340"],ot={N:[0,-1],NE:[.7071,-.7071],NW:[-.7071,-.7071],E:[1,0],W:[-1,0],SE:[.7071,.7071],SW:[-.7071,.7071]};function Kn(t){const e=t();return e<.2?ot.N:e<.45?ot.NE:e<.7?ot.NW:e<.82?ot.E:e<.94?ot.W:e<.97?ot.SE:ot.SW}function gt(t,e){const r=Math.max(1,e||1),n={seed:t,phase:"play",round:1,pc:r,tick:0,roundTick:0,interTick:0,interRound:2,birds:[],nextBirdId:0,ducksSpawned:0,mocksSpawned:0,roundEndAt:null,players:[],roundResults:[[],[],[],[],[]],shots:[],flashes:[],roundDone:!1,mockDog:!1,mockDogTick:0};for(let a=0;a<r;a++)n.players.push({shellsLeft:C.BULLETS_PER_ROUND,cooldown:0,blink:0,score:0,kills:0,mockHits:0,bulletsUsed:0});function o(a){const T=Zt(n.seed,n.round,a),L=C.DUCK_BASE_SPEED*C.SPEED_MULT[n.round-1]*(.9+T()*.2),N=ft(T,2),I=N===0?-30:830,_=300+ft(T,60),W=N===0?1:-1,F=C.TURN_EVERY[n.round-1],O=F[0]+ft(T,F[1]-F[0]+1),h={id:n.nextBirdId++,birdIndex:a,kind:"duck",state:"active",x:I,y:_,vx:W*L,vy:-L,speed:L,age:0,ageActive:0,turnEvery:O,nextTurnAt:n.roundTick+O,rnd:T,fallTick:0,rot:0,hitPid:-1};n.birds.push(h)}function l(a){const T=Zt(n.seed,n.round,3+a),L=100+ft(T,150),N=ft(T,2)?1:-1,I=T()*Math.PI*2,_={id:n.nextBirdId++,birdIndex:3+a,kind:"mock",state:"active",x:N===1?-20:820,y:L,y0:L,dir:N,vx:N*C.MOCK_SPEED,vy:0,speed:C.MOCK_SPEED,phase:I,age:0,ageActive:0,rnd:T,fallTick:0,rot:0,hitPid:-1};n.birds.push(_)}function s(){if(n.ducksSpawned===0&&n.roundTick>=C.DUCK_SPAWN_AT){for(let T=0;T<C.DUCKS_PER_ROUND;T++)o(T);n.ducksSpawned=C.DUCKS_PER_ROUND}const a=C.MOCKS[n.round-1];if(n.mocksSpawned<a){const T=C.MOCK_SPAWN_BASE+n.mocksSpawned*C.MOCK_SPAWN_GAP;n.roundTick>=T&&(l(n.mocksSpawned),n.mocksSpawned++)}}function i(a){if(a.state!=="active")return;a.state="fleeing";const T=a.x,L=800-a.x,N=a.y,I=450-a.y,_=Math.min(T,L,N,I),W=Math.max(a.speed*1.5,4);_===T?(a.vx=-W,a.vy=0):_===L?(a.vx=W,a.vy=0):_===N?(a.vx=0,a.vy=-W):(a.vx=0,a.vy=W)}function c(a,T){n.roundResults[n.round-1].push({r:T,p:T==="kill"?a.hitPid:-1})}function g(){for(const a of n.birds)if(a.age++,a.kind==="duck")if(a.state==="active")if(a.ageActive++,a.ageActive>=C.DUCK_LIMIT)i(a);else{if(n.roundTick>=a.nextTurnAt){const T=Kn(a.rnd);a.vx=T[0]*a.speed,a.vy=T[1]*a.speed,a.nextTurnAt+=a.turnEvery}a.x+=a.vx,a.y+=a.vy,a.x<C.PF.x0&&a.vx<0&&(a.x=C.PF.x0,a.vx=-a.vx),a.x>C.PF.x1&&a.vx>0&&(a.x=C.PF.x1,a.vx=-a.vx),a.y<C.PF.y0&&a.vy<0&&(a.y=C.PF.y0,a.vy=-a.vy),a.y>C.PF.y1&&a.vy>0&&(a.y=C.PF.y1,a.vy=-a.vy)}else a.state==="fleeing"?(a.x+=a.vx,a.y+=a.vy,(a.x<-60||a.x>860||a.y<-60||a.y>510)&&(a.state="dead",c(a,"escape"))):a.state==="falling"&&(a.fallTick++,a.vy+=.35,a.y+=a.vy,a.x+=a.vx*.3,a.rot+=.12*(a.vx>=0?1:-1),a.fallTick>=C.FALL&&(a.state="dead",c(a,"kill")));else a.state==="active"?(a.ageActive++,a.ageActive>=C.MOCK_WINDOW?a.state="dead":(a.x+=a.dir*C.MOCK_SPEED,a.x>820&&(a.x=-20),a.x<-20&&(a.x=820),a.y=a.y0+Math.sin(a.age*.05+a.phase)*30)):a.state==="fleeing"?(a.x+=a.vx,a.y+=a.vy,(a.x<-60||a.x>860||a.y<-60||a.y>510)&&(a.state="dead")):a.state==="falling"&&(a.fallTick++,a.vy+=.35,a.y+=a.vy,a.x+=a.vx*.3,a.rot+=.12,a.fallTick>=C.FALL&&(a.state="dead"));n.birds=n.birds.filter(a=>a.state!=="dead")}function E(){if(n.birds=[],n.flashes=[],n.round>=C.ROUNDS){n.phase="over";return}n.phase="inter",n.interTick=0,n.interRound=n.round+1}function b(a){n.phase="play",n.round=a,n.roundTick=0,n.ducksSpawned=0,n.mocksSpawned=0,n.roundEndAt=null,n.roundResults[a-1]=[];for(const T of n.players)T.shellsLeft=C.BULLETS_PER_ROUND,T.cooldown=0;n.roundDone=!1,n.mockDog=!1,n.mockDogTick=0}function w(){if(n.phase!=="over"){n.tick++;for(const a of n.players)a.cooldown>0&&a.cooldown--,a.blink>0&&a.blink--;for(const a of n.flashes)a.age++;n.flashes=n.flashes.filter(a=>a.age<45),n.phase==="play"?(n.roundTick++,s(),g(),n.roundResults[n.round-1].length===C.DUCKS_PER_ROUND&&(n.roundDone||(n.roundDone=!0,n.roundResults[n.round-1].filter(T=>T.r==="kill").length===0&&(n.mockDog=!0,n.mockDogTick=0)),n.round>=C.ROUNDS?(n.roundEndAt===null&&(n.roundEndAt=n.roundTick+C.MATCH_END_DELAY),n.roundTick>=n.roundEndAt&&(n.phase="over",n.birds=[])):E()),n.mockDog&&n.mockDogTick++):n.phase==="inter"&&(n.interTick++,n.mockDog&&n.mockDogTick++,n.interTick>=C.INTERMISSION&&b(n.interRound))}}function P(a,T,L){if(L=L|0,n.phase!=="play"||L<0||L>=r)return!1;a=Math.round(a*10)/10,T=Math.round(T*10)/10;const N=n.players[L];if(N.cooldown>0||N.shellsLeft<=0)return N.blink=6,!1;N.cooldown=C.PUMP_COOLDOWN,N.shellsLeft--,N.bulletsUsed++;const I=[];for(const O of n.birds){if(O.state!=="active")continue;const h=O.kind==="duck"?C.DUCK_R:C.MOCK_R,m=a-O.x,d=T-O.y;m*m+d*d<=h*h&&I.push(O)}const _=I.filter(O=>O.kind==="duck").length,W=I.filter(O=>O.kind==="mock").length;n.shots.push({tick:n.tick,pid:L,x:a,y:T,hit:I.length>0,ducksHit:_,mocksHit:W,birds:I.map(O=>({id:O.id,kind:O.kind}))});for(const O of I)O.state="falling",O.fallTick=0,O.vy=0,O.hitPid=L,O.kind==="duck"?N.kills++:(N.mockHits++,n.flashes.push({x:a,y:T,text:"-"+C.MOCK_PENALTY+" MOCK",age:0,color:"#ff4040"}));let F=0;if(_>0&&(F+=C.DUCK_POINTS+(_-1)*C.DUCK_POINTS*C.MULTI_MULT),F-=C.MOCK_PENALTY*W,N.score+=F,_>=2){const O=_===2?"DOUBLE! +":_===3?"TRIPLE! +":"MULTI! +";n.flashes.push({x:a,y:T-28,text:O+Math.round(F),age:0,color:rt[L]})}else _===1&&n.flashes.push({x:a,y:T-28,text:"+"+Math.round(F),age:0,color:rt[L]});for(const O of n.birds)O.state==="active"&&i(O);return!0}return{st:n,step:w,fire:P}}function Yt(t){let e=2166136261;const r=o=>{for(let l=0;l<o.length;l++)e^=o.charCodeAt(l),e=Math.imul(e,16777619)>>>0},n=t.birds.slice().sort((o,l)=>o.id-l.id);r(n.map(o=>Math.round(o.x)+","+Math.round(o.y)+","+o.state[0]).join(";"));for(const o of t.players)r("p"+Math.round(o.score)+","+o.kills+","+o.mockHits+","+o.bulletsUsed);return r("#"+t.tick+"r"+t.round+t.phase+t.roundResults.map(o=>o.length).join("")),(e>>>0).toString(16).padStart(8,"0")}let pt=null,f=null;function Ce(){return f||(pt=document.getElementById("cv"),f=pt.getContext("2d")),f}const J={x:400,y:225},Fn="#5c94fc",Yn="#00a800";function G(t,e,r,n,o,l){f.font="bold "+n+'px "Courier New",monospace',f.textAlign=l||"left",f.textBaseline="top",f.fillStyle="#000",f.fillText(t,e+2,r+2),f.fillStyle=o,f.fillText(t,e,r)}function St(t,e,r){f.fillStyle="rgba(255,255,255,0.85)",f.fillRect(t,e,70*r,18*r),f.fillRect(t+14*r,e-10*r,40*r,14*r),f.fillRect(t+24*r,e-18*r,20*r,10*r)}function Mt(t){f.save(),f.translate(t.x,t.y),t.state==="falling"?f.rotate(t.rot):t.vx<0&&f.scale(-1,1);const e=Math.floor(t.age/8)%2;f.fillStyle="#1d6f36",f.fillRect(-24,-6,8,10),f.fillStyle="#2e9e4f",f.fillRect(-20,-6,38,18),f.fillStyle="#d9f2d0",f.fillRect(-14,6,26,6),f.fillStyle="#2e9e4f",f.fillRect(12,-20,14,14),f.fillStyle="#ffd23f",f.fillRect(26,-15,10,5),f.fillStyle="#000000",f.fillRect(19,-17,4,4),f.fillStyle="#1d6f36",e===0?f.fillRect(-14,-14,18,10):f.fillRect(-14,-2,18,9),f.restore()}function jn(t){f.save(),f.translate(t.x,t.y),t.state==="falling"?f.rotate(t.rot):t.dir<0&&f.scale(-1,1);const e=Math.floor(t.age/12)%2;f.fillStyle="#6e4a24",f.fillRect(-18,-4,8,8),f.fillStyle="#8b5a2b",f.fillRect(-14,-4,28,14),f.fillStyle="#f5f0dc",f.fillRect(2,2,10,8),f.fillStyle="#8b5a2b",f.fillRect(8,-12,12,10),f.fillStyle="#000000",f.fillRect(14,-10,3,3),f.fillRect(20,-8,7,3),f.fillStyle="#6e4a24",e===0?f.fillRect(-10,-12,16,8):f.fillRect(-10,-2,16,7),f.restore()}function Se(t,e="laugh"){const r=e!=="proud";let n;if(r?t<15?n=t/15*50:t<45?n=50:t<60?n=50-(t-45)/15*50:n=0:n=t<15?t/15*50:50,n<=0)return;const o=400,l=350-n,s=r?t>=15&&t<45?Math.sin((t-15)*.4)*2:0:t>=15?Math.sin(t*.12)*1.5:0,i=l+s;f.save(),f.translate(o,i),f.fillStyle="#7a4a1a",f.fillRect(-22,-6,8,18),f.fillRect(14,-6,8,18),f.fillStyle="#c98a4a",f.fillRect(-18,-22,36,28),f.fillStyle="#e8c89a",f.fillRect(-12,-4,24,14),f.fillStyle="#000000",f.fillRect(-14,-16,8,3),f.fillRect(6,-16,8,3),f.fillRect(-4,-8,8,5),r&&t>=15&&t<45&&Math.floor((t-15)/6)%2===0?(f.fillStyle="#3a1a0a",f.fillRect(-7,0,14,9),f.fillStyle="#d6486a",f.fillRect(-5,4,10,4)):r?(f.fillStyle="#000000",f.fillRect(-7,2,14,3)):(f.fillStyle="#000000",f.fillRect(-7,2,14,3),f.fillRect(-9,-1,3,3),f.fillRect(6,-1,3,3)),r||(f.fillStyle="#c98a4a",f.fillRect(-42,-18,26,5),f.fillRect(16,-18,26,5),f.save(),f.translate(-20,-34),f.scale(.55,.55),Mt({x:0,y:0,state:"held",vx:-1,age:0,rot:0}),f.restore(),f.save(),f.translate(20,-34),f.scale(.55,.55),Mt({x:0,y:0,state:"held",vx:1,age:0,rot:0}),f.restore()),f.restore(),r&&t>=15&&t<45&&G("HA HA!",o+40,l-30,22,"#ffd23f","left")}let Tt=null;function Re(){Tt&&(clearInterval(Tt),Tt=null);const t=document.getElementById("over-dog");t&&t.classList.add("hidden")}function Wn(t="laugh"){Re();const e=document.getElementById("over-dog");if(!e||!e.getContext)return;e.classList.remove("hidden"),e.width=170,e.height=70;const r=e.getContext("2d");let n=0;const o=()=>{const l=f;f=r;try{r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,e.width,e.height),r.translate(t==="proud"?-315:-365,-245),Se(t==="proud"?n:n%60,t)}finally{f=l}n++};o(),Tt=setInterval(o,1e3/C.TICK_RATE)}function Rt(t,e,r){r?(f.fillStyle="#e0b23c",f.fillRect(t,e,12,22),f.fillStyle="#8a6210",f.fillRect(t,e+18,12,4)):(f.strokeStyle="#666666",f.lineWidth=2,f.strokeRect(t+1,e+1,10,20))}function Gn(t,e){const r=t.st;if(r.pc===1){const o=r.players[0];for(let i=0;i<C.BULLETS_PER_ROUND;i++)Rt(14+i*22,12,i<o.shellsLeft);G("R"+r.round+"/"+C.ROUNDS,400,10,22,"#ffffff","center");const l=r.roundResults[r.round-1]||[];for(let i=0;i<C.DUCKS_PER_ROUND;i++){const c=330+i*30;l[i]&&l[i].r==="kill"?(f.fillStyle="#00e000",f.fillRect(c,40,20,14)):l[i]&&l[i].r==="escape"?(f.fillStyle="#777777",f.fillRect(c,40,20,14)):(f.strokeStyle="#ffffff",f.lineWidth=2,f.strokeRect(c+1,41,18,12))}const s=o.score<0?"#ff5a5a":"#ffd700";G("SCORE "+Math.round(o.score),786,8,20,s,"right"),G("KILLS "+o.kills,786,32,16,"#ffffff","right"),G("MOCKS "+o.mockHits,786,52,16,"#ff5a5a","right")}else{const o=r.players[0],l=r.players[1];for(let c=0;c<C.BULLETS_PER_ROUND;c++)Rt(14+c*22,12,c<o.shellsLeft),Rt(762-c*22,12,c<l.shellsLeft);G((e?e[0]:"P1")+" "+Math.round(o.score),14,40,18,rt[0],"left");const s=l.score<o.score?"#fff":rt[1];G(Math.round(l.score)+" "+(e?e[1]:"P2"),786,40,18,s,"right"),G("R"+r.round+"/"+C.ROUNDS,400,10,22,"#ffffff","center");const i=r.roundResults[r.round-1]||[];for(let c=0;c<C.DUCKS_PER_ROUND;c++){const g=330+c*30,E=i[c];E&&E.r==="kill"?(f.fillStyle=E.p===0?rt[0]:E.p===1?rt[1]:"#00e000",f.fillRect(g,40,20,14)):E&&E.r==="escape"?(f.fillStyle="#777777",f.fillRect(g,40,20,14)):(f.strokeStyle="#ffffff",f.lineWidth=2,f.strokeRect(g+1,41,18,12))}G("K "+o.kills+" M "+o.mockHits,14,62,13,"rgba(255,255,255,.8)","left"),G("K "+l.kills+" M "+l.mockHits,786,62,13,"rgba(255,255,255,.8)","right")}G(r.seed.slice(0,8),786,428,14,"rgba(255,255,255,0.75)","right")}function Xt(t,e){f.beginPath(),f.arc(t,e,14,0,Math.PI*2),f.moveTo(t-22,e),f.lineTo(t+22,e),f.moveTo(t,e-22),f.lineTo(t,e+22)}function zt(t,e,r,n){f.strokeStyle="#000000",f.lineWidth=4,Xt(t,e),f.stroke(),f.strokeStyle=n>0?"#ff4040":r,f.lineWidth=2,Xt(t,e),f.stroke()}function $n(t,e,r,n){const o=t.st;f.fillStyle=Fn,f.fillRect(0,0,800,450),St(90,80,1.2),St(360,55,.8),St(640,100,1),f.fillStyle=Yn,f.fillRect(0,350,800,100),f.fillStyle="#00c000",f.fillRect(0,350,800,6);const l=o.birds.slice().sort((s,i)=>s.id-i.id);for(const s of l)s.kind==="duck"?Mt(s):jn(s);f.fillStyle="#00c000";for(let s=0;s<40;s++)f.fillRect(s*20+s*7%13,425,4,7);Gn(t,r);for(const s of o.flashes)f.globalAlpha=Math.max(0,1-s.age/45),G(s.text,s.x,s.y-s.age*.6,18,s.color,"center"),f.globalAlpha=1;if(o.phase==="play")if(e)for(const s of e)zt(s.x,s.y,s.color,s.blink);else zt(J.x,J.y,"#ffffff",o.players[0].blink);o.mockDog&&Se(o.mockDogTick),o.phase==="inter"&&o.interTick>=60&&(f.fillStyle="rgba(0,0,0,0.45)",f.fillRect(0,180,800,90),G("ROUND "+o.interRound+" Good Luck!",400,205,34,"#ffd700","center")),n&&G(n,14,428,13,"rgba(255,255,255,0.6)","left")}const A={PROTO:"dd2",MATCH_TAG:"duckduel",EPH_KIND:21e3,CODE_ALPHABET:"ABCDEFGHJKMNPQRSTUVWXYZ23456789",relay:!1,identity:null,webrtc:null,sub:null,bc:null,mode:null,status:"offline",statusDetail:"",evSeen:new Set};function qn(){const t=new Uint8Array(6);crypto.getRandomValues(t);let e="";for(const r of t)e+=A.CODE_ALPHABET[r%A.CODE_ALPHABET.length];return e}async function jt(){if(A.status="connecting",A.statusDetail="",A.mode=null,st.identity)try{const t=await ae();let e="";try{const n=await ce();e=n&&(n.name||n.displayName)||""}catch{}const r=t?yn(t):"";(t||e)&&(A.identity={pubkey:t||"",name:e,npub:r||""})}catch{}return st.relay?(A.relay=!0,A.webrtc=st.webrtc?{}:null,A.mode="nostr",A.status="online","nostr"):typeof BroadcastChannel<"u"?(A.mode="local",A.status="online",A.statusDetail="BroadcastChannel (no shell)","local"):(A.status="offline",A.statusDetail="no RELAY domain and no BroadcastChannel",null)}function wt(){if(A.identity&&A.identity.name)return A.identity.name.slice(0,12);const t=A.identity;return t&&t.npub?t.npub.slice(-6):t&&t.pubkey?t.pubkey.slice(-6):"YOU"}async function Wt(){const t=document.getElementById("board-box"),e=document.getElementById("board-list");if(!t||!e)return;const r=await cn(3);if(!r){t.classList.add("hidden");return}if(e.innerHTML="",r.length)r.forEach((n,o)=>{const l=document.createElement("li"),s=document.createElement("span");s.className="b-rank",s.textContent=o+1+".";const i=document.createElement("span");i.className="b-name",i.textContent=String(n.name||"?").slice(0,12);const c=document.createElement("span");c.className="b-score",c.textContent=String(Math.round(n.score)),l.append(s,i,c),e.appendChild(l)});else{const n=document.createElement("li");n.textContent="NO SCORES YET — BE THE FIRST",e.appendChild(n)}t.classList.remove("hidden")}async function Vn(t){if(!Ft||t<=0)return;await an(t,wt())&&Wt()}async function te(t){if(!A.relay)return{ok:!1,error:"no relay domain"};try{return await $e({kind:t.kind,content:t.content,tags:t.tags||[],created_at:t.created_at||Math.floor(Date.now()/1e3)}),{ok:!0}}catch(e){return A.statusDetail=String(e),{ok:!1,error:String(e)}}}async function Qn(t){if(!A.relay)return null;try{return Ge(t,e=>{const r=e&&e.event;r&&Zn(r,e.sidecar)},()=>{})}catch(e){return A.statusDetail="subscribe: "+String(e),null}}async function Jn(t){if(t)try{typeof t.close=="function"&&t.close()}catch{}}function Zn(t,e){if(!t||typeof t.content!="string")return;if(t.id){if(A.evSeen.has(t.id))return;A.evSeen.add(t.id),A.evSeen.size>512&&A.evSeen.clear()}let r=null;try{r=JSON.parse(t.content)}catch{return}!r||r.proto!==A.PROTO||De(r,t)}async function Q(t,e){if(e=e||{},t.proto=A.PROTO,t.code=u.code,t.pid===void 0&&(t.pid=v.myPid),t.name===void 0&&(t.name=wt()),A.bc){try{A.bc.postMessage(t)}catch{}return{ok:!0,local:!0}}if(!A.relay)return{ok:!1,error:"offline"};const r=JSON.stringify(t),n=[["t",Me()]],o=Math.floor(Date.now()/1e3);let l=await te({kind:e.kind||A.EPH_KIND,content:r,tags:n,created_at:o});return l&&l.ok===!1&&!e.noFallback?await te({kind:1,content:r,tags:n,created_at:o})||l:l||{ok:!0}}async function lt(){if(A.sub&&(await Jn(A.sub),A.sub=null),A.bc){try{A.bc.close()}catch{}A.bc=null}A.evSeen.clear()}async function Le(){A.sub||(A.relay?A.sub=await Qn([{kinds:[1,A.EPH_KIND],"#t":[Me()]}]):!A.bc&&typeof BroadcastChannel<"u"&&(A.bc=new BroadcastChannel("duckduel-"+A.PROTO),A.bc.onmessage=t=>{const e=t.data;!e||e.proto!==A.PROTO||De(e,null)}))}const u={mode:null,code:null,seed:null,peerHeard:-1/0,started:!1,cmdLog:[],appliedKeys:new Set,peerAim:{x:400,y:225},peerAimTarget:null,peerHash:null,hashOk:null,rivalName:null,rivalPubkey:null,rivalLud16:null,peerLeft:!1,beacon:null,joinTimer:null,entryPhase:!1,myPaid:!1,peerPaid:!1,waitBeacon:null};function Pe(t){return t.tick+":"+t.pid+":"+t.x+":"+t.y}function Xn(){if(!u.seed)return;const t=v.sim?v.sim.st.tick:0,e=u.cmdLog.slice().sort((o,l)=>o.tick-l.tick||o.pid-l.pid),r=gt(u.seed,2);let n=0;for(;r.st.tick<t&&r.st.phase!=="over"&&n++<2e5;){for(;e.length&&e[0].tick<=r.st.tick;){const o=e.shift();o.tick===r.st.tick&&r.fire(o.x,o.y,o.pid)}r.step()}for(;e.length&&e[0].tick<=r.st.tick;){const o=e.shift();o.tick===r.st.tick&&r.fire(o.x,o.y,o.pid)}v.sim=r,v.ui&&(v.ui.sim=r)}function Ne(t){if(!t||typeof t.tick!="number")return;const e=Pe(t);u.appliedKeys.has(e)||(u.appliedKeys.add(e),u.cmdLog.push(t),Xn())}function ee(t){if(Array.isArray(t))for(const e of t)e&&e.length===4&&e[1]!==v.myPid&&Ne({tick:e[0],pid:e[1],x:e[2],y:e[3]})}function Me(){return A.MATCH_TAG+"-"+(u.code||"").toLowerCase()}function zn(t){u.cmdLog.push(t),u.appliedKeys.add(Pe(t));const e=u.cmdLog.slice(-24).map(r=>[r.tick,r.pid,r.x,r.y]);Q({k:"shot",cmd:t,tail:e})}function tr(){if(!u.started)return;const t=u.cmdLog.slice(-24).map(e=>[e.tick,e.pid,e.x,e.y]);Q({k:"sync",tick:v.sim?v.sim.st.tick:0,aim:{x:Math.round(J.x),y:Math.round(J.y)},hash:v.sim?Yt(v.sim.st):null,tail:t})}function mt(t){Q({k:t})}function er(){Q({k:"join-probe"})}const nr=new Set(["hosting","join-probe","join","entry","paid","start","bye"]);function De(t,e){if(R.mode!=="online"&&!nr.has(t.k)||!u.code||t.code!==u.code||t.pid===v.myPid)return;u.peerHeard=Date.now(),e&&typeof e.pubkey=="string"&&e.pubkey&&(u.rivalPubkey=e.pubkey);const r=()=>!u.started||v.sim&&v.sim.st.phase==="over";t.k==="hosting"&&u.mode==="guest"&&!u.started?Q({k:"join",name:wt()}):t.k==="join-probe"&&u.mode==="host"&&!u.started?mt("hosting"):t.k==="join"&&u.mode==="host"&&r()?(u.rivalName=t.name||"CHALLENGER",It()):t.k==="entry"&&u.mode==="guest"&&r()?(u.entryPhase||Dt(),u.myPaid||Ot()):t.k==="paid"&&r()?(u.peerPaid=!0,u.mode==="guest"&&!u.entryPhase&&Dt(),u.mode==="host"&&u.myPaid?_t("host"):u.myPaid||(Ot(),j(u.mode==="host"?"OPPONENT IS PAID — YOUR TURN TO PAY.":"HOST IS PAID — YOUR ENTRY STARTS THE MATCH."))):t.k==="start"&&u.mode==="guest"&&r()?(u.seed=t.seed,u.rivalName=t.name||"HOST",_t("guest")):t.k==="shot"?(t.cmd&&Ne(t.cmd),ee(t.tail)):t.k==="sync"?(ee(t.tail),t.hash&&v.sim&&(u.peerHash={tick:t.tick,hash:t.hash},u.hashOk=t.tick===v.sim.st.tick?Yt(v.sim.st)===t.hash:null),t.aim&&(u.peerAimTarget={x:t.aim.x,y:t.aim.y,t:performance.now()})):t.k==="bye"&&(u.peerLeft=!0)}const v={sim:null,ui:null,myPid:0},R={scrStart:null,scrLobby:null,scrWait:null,scrOver:null,sim:null,running:!1,overShown:!1,mode:null,names:null};function nt(){const t=()=>{const e=new Uint8Array(16);crypto.getRandomValues(e);let r="";for(const n of e)r+=n.toString(16).padStart(2,"0");return r};return t()+t()}function Oe(t){const e=ct(0,"M");return e.addData(t),e.make(),e.createDataURL(6,8)}function rr(){const t=new URLSearchParams(location.search),e=(t.get("g")||t.get("seed")||"").toLowerCase().trim();return/^[0-9a-f]{8,64}$/.test(e)?e:null}function Ie(){Re();for(const t of["scr-start","scr-lobby","scr-wait","scr-pay","scr-over"]){const e=document.getElementById(t);e&&e.classList.add("hidden")}}function V(t){Ie(),document.getElementById(t).classList.remove("hidden")}function _e(){bt(),Ie(),R.running=!0,R.overShown=!1,v.ui=R}function X(){u.beacon&&(clearInterval(u.beacon),u.beacon=null),u.joinTimer&&(clearTimeout(u.joinTimer),u.joinTimer=null),u.waitBeacon&&(clearInterval(u.waitBeacon),u.waitBeacon=null),u.entryPhase=!1}function Dt(){u.entryPhase=!0,u.myPaid=!1,u.peerPaid=!1,u.waitBeacon&&clearInterval(u.waitBeacon),u.waitBeacon=setInterval(()=>{if(u.started||!u.entryPhase){X();return}u.myPaid?u.peerPaid||Q({k:"paid"}):u.mode==="host"&&Q({k:"entry"}),u.myPaid&&(u.peerLeft||Date.now()-u.peerHeard>2e4)&&j("OPPONENT LEFT — BACK TO THE MENU AND START A NEW DUEL.")},2e3)}function Ot(){Ke("DUEL ENTRY",Nt,"Both players are in — each pays a 210-sat entry and the duel starts the moment both confirm. Paying always means playing.",!0)}function It(){u.entryPhase||Dt(),Q({k:"entry"}),u.myPaid||Ot()}function ht(t){R.mode="solo",R.names=null,v.myPid=0,u.started=!1,u.code=null,X(),lt(),v.sim=gt(t,1),_e();try{history.replaceState(null,"",location.pathname+"?g="+t)}catch{}}async function or(){!A.relay&&!A.bc&&await jt(),u.mode="host",u.code=qn(),u.seed=nt(),u.started=!1,X(),v.myPid=0,document.getElementById("wait-code").textContent=u.code,document.getElementById("wait-title").innerHTML='MATCH <span class="code" id="wait-code">'+u.code+"</span>",document.getElementById("wait-msg").textContent="WAITING FOR CHALLENGER…",document.getElementById("wait-msg").classList.add("pulse"),V("scr-wait"),await lt(),await Le(),mt("hosting"),u.beacon=setInterval(()=>{if(u.started){X();return}mt("hosting")},2500)}async function ir(t){if(t=(t||"").toUpperCase().trim(),!/^[A-Z2-9]{6}$/.test(t)){document.getElementById("join-err").textContent="Code must be 6 characters (A-Z, 2-9).";return}!A.relay&&!A.bc&&await jt(),u.mode="guest",u.code=t,u.seed=null,u.started=!1,X(),v.myPid=1,document.getElementById("wait-code").textContent=t,document.getElementById("wait-title").innerHTML='MATCH <span class="code" id="wait-code">'+t+"</span>",document.getElementById("wait-msg").textContent="CONTACTING HOST…",document.getElementById("wait-msg").classList.add("pulse"),V("scr-wait"),await lt(),await Le(),er(),u.joinTimer=setTimeout(()=>{u.started||(document.getElementById("wait-msg").textContent="NO HOST FOUND — CHECK THE CODE AND RETRY",document.getElementById("wait-msg").classList.remove("pulse"))},8e3)}function _t(t){u.started=!0,X(),R.mode="online",v.myPid=t==="host"?0:1;const e=wt();R.names=t==="host"?[e,(u.rivalName||"CHALLENGER").slice(0,12)]:[(u.rivalName||"HOST").slice(0,12),e],v.sim=gt(u.seed,2),u.cmdLog=[],u.appliedKeys=new Set,u.peerAim={x:400,y:225,t:0},u.peerAimTarget=null,u.peerHash=null,u.hashOk=null,u.peerHeard=-1/0,u.peerLeft=!1,_e(),t==="host"&&Q({k:"start",seed:u.seed}),u.rivalPubkey&&!u.rivalLud16&&xe(u.rivalPubkey).then(r=>{u.rivalLud16=r}).catch(()=>{})}function ne(t){const e=pt.getBoundingClientRect();return{x:(t.clientX-e.left)*800/e.width,y:(t.clientY-e.top)*450/e.height}}function sr(t,e){!R.running||!v.sim||(R.mode==="solo"?v.sim.fire(t,e,0):R.mode==="online"&&v.sim.fire(t,e,v.myPid)&&zn({tick:v.sim.st.tick,pid:v.myPid,x:t,y:e}))}function lr(){Ce(),pt.addEventListener("pointermove",t=>{const e=ne(t);J.x=e.x,J.y=e.y}),pt.addEventListener("pointerdown",t=>{t.preventDefault();const e=ne(t);J.x=e.x,J.y=e.y,sr(e.x,e.y)}),window.addEventListener("keydown",t=>{t.key.toLowerCase()==="t"&&ar()})}function ar(){const t=v.sim&&v.sim.st.seed||"test",e=gt(t,1);let r=2166136261;const n=i=>{for(let c=0;c<i.length;c++)r^=i.charCodeAt(c),r=Math.imul(r,16777619)>>>0},o=i=>Math.round(i*100)/100;let l=0;for(;e.st.phase!=="over"&&l++<4e5;)if(e.step(),e.st.tick%30===0){const i=e.st.birds.slice().sort((c,g)=>c.birdIndex-g.birdIndex);n(i.map(c=>o(c.x)+","+o(c.y)).join(";")+"#"+e.st.tick)}const s=e.st;n("F"+s.tick+"k"+s.players[0].kills+"m"+s.players[0].mockHits+"b"+s.players[0].bulletsUsed+"s"+Math.round(s.players[0].score)),console.log("DETERMINISM "+s.seed+" "+(r>>>0).toString(16).padStart(8,"0")),console.log("ticks="+s.tick+" kills="+s.players[0].kills+" mocks="+s.players[0].mockHits+" bullets="+s.players[0].bulletsUsed+" score="+Math.round(s.players[0].score)),console.log("FINAL stateHash="+Yt(e.st))}function cr(){R.overShown=!0,R.running=!1;const t=v.sim.st,e=t.pc;document.getElementById("over-title").textContent=e>1?"DUEL OVER":"MATCH OVER";const r=[];let n=null;if(e===1){const l=t.players[0],s=t.shots.filter(E=>E.hit).length,i=l.bulletsUsed>0?Math.round(s/l.bulletsUsed*100):0,c=l.score<0?"neg":"pos";n=l.kills===0?"laugh":"proud";const g=l.kills===0?'<div class="neg" style="font-size:1.1em;letter-spacing:2px;margin-bottom:6px">THE MOCKING DOG LAUGHS AT YOU</div>':"";r.push(g+"KILLS "+l.kills+"/15<br>MOCKINGBIRDS "+l.mockHits+"<br>BULLETS "+l.bulletsUsed+"/10<br>ACCURACY "+i+'%<br>SCORE <span class="'+c+'">'+Math.round(l.score)+"</span>")}else{const l=[];l.push('<tr><th></th><th class="p0c">'+(R.names?R.names[0]:"P1")+'</th><th class="p1c">'+(R.names?R.names[1]:"P2")+"</th></tr>");const s=["KILLS","MOCKS","BULLETS","SCORE"],i=[[t.players[0].kills,t.players[1].kills],[t.players[0].mockHits,t.players[1].mockHits],[t.players[0].bulletsUsed,t.players[1].bulletsUsed],[Math.round(t.players[0].score),Math.round(t.players[1].score)]];for(let _=0;_<s.length;_++)l.push("<tr><td>"+s[_]+"</td><td>"+i[_][0]+"</td><td>"+i[_][1]+"</td></tr>");const c=Math.round(t.players[0].score),g=Math.round(t.players[1].score);let E;if(R.mode==="online"){const _=v.myPid===0?c:g,W=v.myPid===0?g:c;E=_>W?'<div class="pos" style="font-size:1.15em;letter-spacing:3px;margin-bottom:6px">YOU WIN!</div>':_<W?'<div class="neg" style="font-size:1.15em;letter-spacing:3px;margin-bottom:6px">YOU LOSE!</div>':'<div style="font-size:1.15em;letter-spacing:3px;margin-bottom:6px">DRAW!</div>'}else E=c===g?'<div style="font-size:1.15em;letter-spacing:3px;margin-bottom:6px">DRAW!</div>':'<div class="'+(c>g?"p0c":"p1c")+'" style="font-size:1.15em;letter-spacing:3px;margin-bottom:6px">'+(c>g?R.names?R.names[0]:"P1":R.names?R.names[1]:"P2")+" WINS!</div>";const b=t.players[0].kills+t.players[1].kills,w=c===g?-1:c>g?1:0,P=w<0?"":R.names?R.names[w]:"P"+(w+1),a=R.mode==="online"?v.myPid:0,T=w>=0&&w===a,L=w>=0&&w!==a,N=w<0&&b===0;let I="";T?I='<div class="neg" style="letter-spacing:2px;margin-top:6px">THE MOCKING DOG LAUGHS AT '+P+"</div>":N&&(I='<div class="neg" style="letter-spacing:2px;margin-top:6px">THE MOCKING DOG LAUGHS AT YOU BOTH</div>'),n=L?"proud":T||N?"laugh":null,r.push(E+'<table class="res">'+l.join("")+"</table>"+I)}document.getElementById("over-stats").innerHTML=r.join("");const o=document.getElementById("over-rounds");o.innerHTML="";for(let l=0;l<C.ROUNDS;l++){const i=(t.roundResults[l]||[]).filter(g=>g.r==="kill").length,c=document.createElement("span");c.textContent="R"+(l+1)+": "+i+"/3",o.appendChild(c)}V("scr-over"),n&&Wn(n),R.mode==="online"&&(Q({k:"bye"}),ur(Math.round(t.players[0].score),Math.round(t.players[1].score))),Vn(R.mode==="online"?Math.round(t.players[v.myPid===0?0:1].score):Math.round(t.players[0].score))}function ur(t,e){const r=document.getElementById("settle");if(r.innerHTML="",t===e)return;const n=t<e,o=document.createElement("div");if(o.className="err",o.style.minHeight="2.6em",r.appendChild(o),n){const l=document.createElement("div");l.className="hint",l.innerHTML="SETTLE THE WAGER — your "+gn+"-sat wager is due:<br>"+ut+" sats to "+(R.names?R.names[1-v.myPid]:"the winner")+" + "+kt+" sats to the dev",r.appendChild(l);const s=document.createElement("button");s.className="btn",s.textContent="ZAP WINNER "+ut+" SATS",s.addEventListener("click",()=>{(async()=>{let c=u.rivalLud16;!c&&u.rivalPubkey&&(o.textContent="Resolving rival's lightning address…",c=await xe(u.rivalPubkey),u.rivalLud16=c),await oe(c,ut,o,"Winner: ",r)})()});const i=document.createElement("button");i.className="btn warn",i.textContent="ZAP DEV "+kt+" SATS",i.addEventListener("click",()=>{oe(at,kt,o,"Dev: ",r)}),r.appendChild(s),r.appendChild(i)}else{const l=document.createElement("div");l.className="hint",l.innerHTML="YOU WON — "+ut+" sats are on their way from the loser's wallet (zap split: "+ut+" winner / "+kt+" dev).",r.appendChild(l)}}function fr(){R.mode!=="online"||!u.started||(Date.now()-u.peerHeard>12e3&&(A.statusDetail="peer silent — connection may be lost"),tr())}const K={sats:0,invoice:null,poll:null,duel:!1};function j(t){document.getElementById("pay-status").textContent=t}const Be=t=>new Promise(e=>setTimeout(e,t));function bt(){K.poll&&(clearInterval(K.poll),K.poll=null)}function Ue(){bt(),K.poll=setInterval(()=>{He()},3e3)}async function re(){if(bt(),K.duel){if(u.myPaid=!0,u.mode==="host"&&Q({k:"paid"}),u.mode==="host"&&u.peerPaid){j("BOTH PAID — STARTING…"),await Be(300),_t("host");return}j("PAID — WAITING FOR YOUR OPPONENT TO PAY. THE DUEL STARTS WHEN BOTH CONFIRM.");return}await Rn(),j("PAYMENT CONFIRMED — STARTING…"),setTimeout(()=>ht(nt()),600)}async function He(){if(K.invoice&&K.invoice.verify){j("CHECKING PAYMENT STATUS…");const r=await Ae(K.invoice.verify);if(r===!0){await re();return}j(r===!1?"NOT SETTLED YET — scan the QR or open your wallet, then CHECK again.":"CANNOT REACH THE STATUS ENDPOINT — try CHECK again.");return}j("CHECKING RELAYS FOR YOUR ZAP…");const t=Math.floor(Date.now()/1e3)-3600,e=await ke(K.sats*1e3,t);e===!0?await re():j(e===!1?"NO RECEIPT YET — pay from your wallet, then CHECK again.":"CANNOT VERIFY PAYMENTS IN THIS HOST — no relay or resource access. Use ?free=1 to play without paying while testing.")}async function Ke(t,e,r,n){const o=i=>document.getElementById(i);if(!o("scr-pay").classList.contains("hidden")&&K.duel===!!n)return;K.sats=e,K.invoice=null,K.duel=!!n,bt(),o("pay-title").textContent=t,o("pay-info").innerHTML=r+"<br>ENTRY FEE: <b>"+e+" SATS</b>",o("pay-dest").textContent=at,o("pay-qr").style.display="none",o("pay-qr-hint").style.display="none",o("pay-status").textContent="",V("scr-pay"),j("REQUESTING AN EXACT "+e+"-SAT INVOICE…");const s=await Te(at,e);s?(K.invoice=s,o("pay-qr").src=Oe(s.pr),o("pay-qr").style.display="",o("pay-qr-hint").style.display="",j("SCAN THE QR FOR EXACTLY "+e+" SATS (OR OPEN WALLET) — WAITING FOR PAYMENT…"+(K.duel&&u.peerPaid?" OPPONENT HAS ALREADY PAID.":"")),Ue()):j("EXACT INVOICE UNAVAILABLE — use the QR / wallet link and send EXACTLY "+e+" sats, then press CHECK.")}async function oe(t,e,r,n,o){r.textContent=n+"requesting exact "+e+"-sat invoice…";const l=await Te(t,e);if(l){let s=o.querySelector("img.qr-pay");s||(s=document.createElement("img"),s.className="qr-pay",o.appendChild(s)),s.src=Oe(l.pr),r.textContent=n+"scan for EXACTLY "+e+" sats (or open wallet)…",await Ee(l.pr)!=="opened"&&(r.textContent=n+"scan the QR to pay exactly "+e+" sats.");for(let c=0;c<15;c++)if(await Be(3e3),l.verify){if(await Ae(l.verify)===!0){r.textContent=n+"PAID ✓ "+e+" sats.";return}}else{const g=Math.floor(Date.now()/1e3)-600;if(await ke(e*1e3,g)===!0){r.textContent=n+"PAID ✓ "+e+" sats.";return}}r.textContent=n+"not settled yet — the QR stays here, pay it any time.";return}await Fe(t,e,r,n)}async function Fe(t,e,r,n){r.textContent=n+" opening wallet…";const o=await Cn(t,e);o==="opened"?r.textContent=n+" confirm the zap in your wallet ("+e+" sats).":o==="no-address"?r.textContent=n+" no lightning address — send "+e+" sats to "+at:r.textContent=n+" wallet link unavailable here. Send "+e+" sats manually to: "+(t||at)}let Et=0,Lt=0,Pt=0;function Ye(t){requestAnimationFrame(Ye),Et||(Et=t);let e=t-Et;Et=t,e>100&&(e=100),Lt+=e,Pt+=e;const r=1e3/C.TICK_RATE;let n=0;for(;Lt>=r&&n<12;)R.running&&v.sim.step(),Lt-=r,n++;if(u.peerAimTarget){const c=(performance.now()-u.peerAimTarget.t)/120;u.peerAim.x+=(u.peerAimTarget.x-u.peerAim.x)*Math.min(1,Math.max(0,c)),u.peerAim.y+=(u.peerAimTarget.y-u.peerAim.y)*Math.min(1,Math.max(0,c)),c>=1&&(u.peerAimTarget=null)}Pt>500&&(Pt=0,fr()),R.running&&v.sim.st.phase==="over"&&!R.overShown&&cr(),Ce();let o=null,l=null,s=null;if(R.mode==="online"){l=R.names;const i=rt[v.myPid],c=rt[1-v.myPid];o=[{x:J.x,y:J.y,color:i,blink:v.sim?v.sim.st.players[v.myPid].blink:0},{x:u.peerAim.x,y:u.peerAim.y,color:c,blink:0}];const g=Date.now()-u.peerHeard;s=(A.relay?"NOST":A.bc?"LOCAL":"OFF")+(A.status==="online"?" ●":" ○")+(g<4e3?" LIVE":" …")+(u.peerHash?u.hashOk===!1?" DESYNC":u.hashOk?" LOCK":" …":"")+(u.peerLeft?" PEER LEFT":"")}v.sim&&$n(v.sim,o,l,s)}function dr(){const t=e=>document.getElementById(e);t("btn-solo").addEventListener("click",async()=>{if(new URLSearchParams(location.search).get("free")==="1"||await Sn()){ht(nt());return}Ke("SOLO RUN",Nt,"One 210-sat zap unlocks solo play on this device, forever. Winner keeps the glory, dev keeps the lights on.")}),t("btn-pay").addEventListener("click",()=>{(async()=>{if(K.invoice){const e=await Ee(K.invoice.pr);j(e==="opened"?"CONFIRM THE PAYMENT IN YOUR WALLET — waiting for settlement…":"WALLET LINK UNAVAILABLE — scan the QR instead."),e==="opened"&&Ue();return}await Fe(at,Nt,t("pay-status"),"")})()}),t("btn-check").addEventListener("click",()=>{He()}),t("btn-pay-back").addEventListener("click",()=>{bt(),u.code&&(u.mode==="guest"&&mt("bye-host"),X(),setTimeout(lt,100),u.started=!1,u.code=null,u.myPaid=!1,u.peerPaid=!1),V("scr-start")}),t("btn-online").addEventListener("click",async()=>{V("scr-lobby");const e=t("online-hint");e.textContent="Checking for a Napplet host…";const r=await jt();r==="nostr"?(e.innerHTML="NAPLET HOST DETECTED — identity, signing and relay access are provided by the shell (NIP-5D / NAP-RELAY).<br>No keys or relay connections are handled by Duck Duel.",t("btn-create").textContent="CREATE MATCH",t("btn-join").textContent="JOIN MATCH"):r==="local"?(e.innerHTML="NO SHELL DETECTED — online duels currently work between two tabs/windows of this browser (BroadcastChannel).<br>Hosted inside a NIP-5D shell, the same buttons sync over Nostr relays via NAP-RELAY.",t("btn-create").textContent="CREATE MATCH (THIS BROWSER)",t("btn-join").textContent="JOIN MATCH (THIS BROWSER)"):e.textContent="NETWORK UNAVAILABLE — no NAP-RELAY domain and no BroadcastChannel in this browser."}),t("btn-lobby-back").addEventListener("click",()=>V("scr-start")),t("btn-create").addEventListener("click",()=>{or()}),t("btn-join").addEventListener("click",()=>{ir(t("inp-code").value)}),t("inp-code").addEventListener("input",e=>{e.target.value=e.target.value.toUpperCase().replace(/[^A-Z2-9]/g,"")}),t("btn-wait-back").addEventListener("click",()=>{mt("bye-host"),X(),setTimeout(lt,100),V("scr-start")}),t("btn-rematch").addEventListener("click",()=>{R.mode==="online"&&u.started?u.mode==="host"?(u.seed=nt(),u.rivalName=u.rivalName||"CHALLENGER",It()):(document.getElementById("wait-msg").textContent="WAITING FOR HOST REMATCH…",document.getElementById("wait-msg").classList.add("pulse"),V("scr-wait")):ht(nt())}),t("btn-new").addEventListener("click",()=>{ht(nt())}),t("btn-same").addEventListener("click",()=>{const e=v.sim?v.sim.st.seed:nt();R.mode==="online"?u.mode==="host"?(u.seed=e,It()):(document.getElementById("wait-msg").textContent="WAITING FOR HOST…",document.getElementById("wait-msg").classList.add("pulse"),V("scr-wait")):ht(e)}),t("btn-menu").addEventListener("click",()=>{X(),lt(),u.started=!1,u.code=null,V("scr-start"),Wt()})}function hr(){dr(),lr();const e=rr()||nt();v.sim=gt(e,1);const r=document.getElementById("seedline");r.textContent="seed: "+e,Wt(),st.identity&&(async()=>{try{const n=await ae();let o="";try{const l=await ce();o=l&&(l.name||l.displayName)||""}catch{}(n||o)&&(A.identity={pubkey:n||"",name:o},r.textContent="seed: "+e+" · "+wt())}catch{}})(),st.relay&&(r.textContent+=" · NAP-RELAY"),requestAnimationFrame(Ye)}Bn({relay:q(xt),identity:q(se),webrtc:q(fe)});hr();
</script>
    <style>html,body,#app{height:100%}html,body{margin:0;padding:0;background:#0b0b12;overflow:hidden}#app{position:fixed;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;justify-content:center}#stage{position:relative;width:min(100vw,calc(100vh * 16 / 9));aspect-ratio:16 / 9}#cv{display:block;width:100%;height:100%;touch-action:none;cursor:none;image-rendering:pixelated}.screen{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;justify-content:safe center;gap:14px;background:#040a1ec7;color:#fff;font-family:Courier New,monospace;text-align:center;cursor:default;padding:20px;box-sizing:border-box;overflow:hidden}.hidden{display:none!important}#scr-pay{gap:8px;padding-top:12px;padding-bottom:12px;overflow-x:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}h1{margin:0;font-size:clamp(26px,6vw,44px);letter-spacing:4px;color:gold;text-shadow:3px 3px 0 #000}h1.wordart{font-family:Arial Black,Arial Bold,Impact,Helvetica Neue,sans-serif;font-weight:900;font-style:italic;font-size:clamp(34px,7.5vw,60px);line-height:1.05;letter-spacing:1px;transform:rotate(-2deg) skew(-6deg);background:linear-gradient(to bottom,#fff8c4,#ffe23f 42%,#ffab00 62%,#ff6a00);-webkit-background-clip:text;background-clip:text;color:transparent;-webkit-text-stroke:2px #3a1500;filter:drop-shadow(3px 3px 0 #6b2a00) drop-shadow(6px 6px 0 #2e1000) drop-shadow(0 8px 10px rgba(0,0,0,.55))}h2{margin:0;font-size:clamp(16px,3vw,24px);letter-spacing:3px;color:#fff}.stats{font-size:clamp(12px,2.2vw,18px);line-height:1.7}.neg{color:#ff5a5a}.pos{color:#00ff7f}.btn{font-family:inherit;font-size:clamp(14px,2.4vw,20px);padding:10px 24px;background:#00a800;color:#fff;border:3px solid #fff;cursor:pointer;letter-spacing:2px}.btn.alt{background:#1565c0}.btn.warn{background:#b26a00}.btn:active{transform:translateY(2px)}.row{display:flex;gap:12px;flex-wrap:wrap;justify-content:center;align-items:center}.stack{display:flex;flex-direction:column;align-items:center;gap:14px}.seedbox{font-size:clamp(10px,1.6vw,13px);color:#9cc4ff;word-break:break-all;max-width:90%;line-height:1.6}.board-title{color:#ffd23f;letter-spacing:3px;margin-bottom:2px}#board-list{margin:0;padding:0;list-style:none}#board-list li{display:flex;gap:10px;justify-content:center}#board-list .b-rank{color:#ffd23f;min-width:2ch;text-align:right}#board-list .b-name{max-width:14ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}#board-list .b-score{min-width:6ch;text-align:right}.roundrow{display:flex;gap:8px;flex-wrap:wrap;justify-content:center;font-size:clamp(11px,1.8vw,15px)}.roundrow span{padding:4px 8px;border:2px solid #556}.inp{font-family:inherit;font-size:clamp(18px,3vw,26px);letter-spacing:6px;text-transform:uppercase;background:#101a33;color:#fff;border:3px solid #556;padding:8px 10px;width:10ch;text-align:center;border-radius:0}.inp:focus{outline:none;border-color:gold}.code{font-size:clamp(26px,5vw,42px);letter-spacing:10px;color:gold;text-shadow:3px 3px 0 #000;padding:4px 10px}.hint{font-size:clamp(10px,1.7vw,14px);color:#9cc4ff;line-height:1.7;max-width:94%}.pulse{animation:blink 1.1s infinite}@keyframes blink{50%{opacity:.35}}.p0c{color:#4fc3ff}.p1c{color:#ffb340}.err{color:#ff5a5a;font-size:clamp(11px,1.8vw,15px);min-height:1.2em}table.res{border-collapse:collapse;font-size:clamp(11px,1.8vw,16px)}table.res td,table.res th{border:1px solid #556;padding:4px 12px}#pay-qr,.qr-pay{display:block;width:min(165px,34vmin);height:auto;margin:8px auto 2px;background:#fff;border-radius:8px;padding:8px}#over-dog{display:block;width:min(190px,50vw);height:auto;margin:0 auto}
</style>
    <meta name="napplet-type" content="my-napplet">
    <meta name="napplet-config-schema" content="{&quot;$schema&quot;:&quot;http://json-schema.org/draft-07/schema#&quot;,&quot;$version&quot;:1,&quot;type&quot;:&quot;object&quot;,&quot;additionalProperties&quot;:false,&quot;properties&quot;:{&quot;textSize&quot;:{&quot;type&quot;:&quot;integer&quot;,&quot;title&quot;:&quot;Text size&quot;,&quot;description&quot;:&quot;Base text size in pixels. Changes apply while the napplet is running.&quot;,&quot;minimum&quot;:10,&quot;maximum&quot;:20,&quot;default&quot;:13,&quot;x-napplet-section&quot;:&quot;Appearance&quot;,&quot;x-napplet-order&quot;:1},&quot;controlSize&quot;:{&quot;type&quot;:&quot;integer&quot;,&quot;title&quot;:&quot;Control height&quot;,&quot;description&quot;:&quot;Choose compact controls or larger touch targets, in pixels.&quot;,&quot;minimum&quot;:24,&quot;maximum&quot;:44,&quot;default&quot;:28,&quot;x-napplet-section&quot;:&quot;Appearance&quot;,&quot;x-napplet-order&quot;:2},&quot;selectText&quot;:{&quot;type&quot;:&quot;boolean&quot;,&quot;title&quot;:&quot;Allow text selection&quot;,&quot;description&quot;:&quot;Allow selecting interface text. Text inputs always remain selectable.&quot;,&quot;default&quot;:false,&quot;x-napplet-section&quot;:&quot;Interaction&quot;}}}">
  </head>
  <body>
    <!--
      A napplet framed by the runtime: the host already shows the napplet's
      name, so there is no title header here. The stage is working surface
      from the first pixel and centers itself in any frame size.
    -->
    <main id="app">
      <div id="stage">
        <canvas id="cv" width="800" height="450"></canvas>

        <div id="scr-start" class="screen">
          <h1 class="wordart">DUCK DUCK DUEL</h1>
          <div class="stats">
            5 rounds &middot; 3 ducks &middot; 2 shots a round<br />
            Pierce a flock: 1 = 10, 2 = 25, 3 = 40 pts<br />
            Brown mockingbirds = &minus;5 &mdash; don't shoot them<br />
            Miss and the flock scatters
          </div>
          <div class="row">
            <button id="btn-solo" class="btn">SOLO</button>
            <button id="btn-online" class="btn warn">ONLINE DUEL</button>
          </div>
          <div class="seedbox" id="seedline"></div>
          <div class="seedbox">
            Press T to run the determinism self-test (see console)
          </div>
          <div class="seedbox board hidden" id="board-box">
            <div class="board-title">TOP DUCKS</div>
            <ol id="board-list"></ol>
          </div>
        </div>

        <div id="scr-lobby" class="screen hidden">
          <h2 id="lobby-title">ONLINE DUEL</h2>
          <div class="hint" id="online-hint">
            Checking for a Napplet host&hellip;
          </div>
          <div id="lobby-create" class="stack">
            <div class="hint">
              Create a match, then send the 6-character code to a friend.<br />They
              open this same napplet and choose JOIN MATCH.
            </div>
            <button id="btn-create" class="btn warn">CREATE MATCH</button>
          </div>
          <div id="lobby-join" class="stack">
            <div class="hint">
              Enter the 6-character match code from your rival.
            </div>
            <input
              id="inp-code"
              class="inp"
              maxlength="6"
              autocomplete="off"
              spellcheck="false"
              placeholder="______"
            />
            <button id="btn-join" class="btn warn">JOIN MATCH</button>
            <div class="err" id="join-err"></div>
          </div>
          <button id="btn-lobby-back" class="btn">BACK</button>
        </div>

        <div id="scr-wait" class="screen hidden">
          <h2 id="wait-title">
            MATCH <span class="code" id="wait-code"></span>
          </h2>
          <div class="stats pulse" id="wait-msg">
            WAITING FOR CHALLENGER&hellip;
          </div>
          <div class="hint" id="wait-hint">
            Stay on this screen. The match starts the instant your rival joins.
          </div>
          <button id="btn-wait-back" class="btn">CANCEL</button>
        </div>

        <div id="scr-pay" class="screen hidden">
          <h2 id="pay-title">PAY TO PLAY</h2>
          <div class="stats" id="pay-info"></div>
          <div class="hint" id="pay-dest"></div>
          <div class="row">
            <button id="btn-pay" class="btn warn">OPEN WALLET</button>
            <button id="btn-check" class="btn">I PAID &mdash; CHECK</button>
          </div>
          <img id="pay-qr" alt="Exact invoice QR — scan to pay the dev" />
          <div class="hint" id="pay-qr-hint">
            SCAN WITH ANY LIGHTNING WALLET &mdash; EXACT INVOICE, NO AMOUNT TO
            ENTER
          </div>
          <div class="err" id="pay-status"></div>
          <button id="btn-pay-back" class="btn">BACK</button>
        </div>

        <div id="scr-over" class="screen hidden">
          <h1 id="over-title">MATCH OVER</h1>
          <canvas
            id="over-dog"
            width="440"
            height="150"
            class="hidden"
          ></canvas>
          <div class="stats" id="over-stats"></div>
          <div class="roundrow" id="over-rounds"></div>
          <div class="row" id="settle"></div>
          <div class="row">
            <button id="btn-rematch" class="btn">REMATCH</button>
            <button id="btn-new" class="btn">NEW MATCH</button>
            <button id="btn-same" class="btn">SAME SEED</button>
            <button id="btn-menu" class="btn alt">MENU</button>
          </div>
        </div>
      </div>
    </main>
  </body>
</html>