Back to Faultline
SOURCE / PINNED RELEASE

Made of little things.

Faultline

Release
da1ffaa5624c…
Author-recorded commit
60f5f03189db…
License
Check the original source
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6932b12c78c

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, viewport-fit=cover" />
    <meta name="theme-color" content="#151a19" />
    <title>Faultline</title>
    <script type="module" crossorigin>var Os=Object.defineProperty;var _s=(s,e,t)=>e in s?Os(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var m=(s,e,t)=>_s(s,typeof e!="symbol"?e+"":e,t);const Us={moveX:[{axis:0},{button:14,scale:-1},{button:15}],moveY:[{axis:1},{button:12,scale:-1},{button:13}],aimX:[{axis:2}],aimY:[{axis:3}],jump:[{button:0}],fire:[{button:7}],pause:[{button:9}]};function Zt(s){const e=Object.create(null);for(const[t,i]of Object.entries(s))e[t]=i.map(a=>{const c="button"in a?a.button:a.axis;if(!Number.isInteger(c)||c<0||a.scale!==void 0&&![1,-1].includes(a.scale))throw new Error("Controller bindings need nonnegative integer indices and a scale of 1 or -1.");return{...a}});return e}const Qt=(s,e=-1)=>Number.isFinite(s)?Math.max(e,Math.min(1,s)):0;function js(s=Us,e={}){const t=Zt(s),i=e.deadZone??.18,a=e.buttonThreshold??.5;if(!Number.isFinite(i)||i<0||i>=1||!Number.isFinite(a)||a<=0||a>1)throw new Error("Use a dead zone from 0 up to (excluding) 1 and a button threshold above 0 through 1.");let c=new Map,r=!1,o=!1;const n=new Map,l=()=>{r=!1},h=typeof window<"u"?window:void 0;h==null||h.addEventListener("blur",l),h==null||h.document.addEventListener("visibilitychange",l);const p=e.active??(()=>!!h&&!h.document.hidden&&h.document.hasFocus()),u=e.read??(()=>{if(typeof navigator>"u"||!navigator.getGamepads)throw new Error("Gamepad API unavailable");return navigator.getGamepads()});function f(b){const d=[...c.keys()];return c.clear(),n.clear(),r=!1,{status:b,players:[],connected:[],disconnected:d}}return{poll(){var S;if(o)return f("closed");let b;try{b=Array.from(u()).filter(M=>!!(M!=null&&M.connected))}catch(M){return f(M instanceof Error&&M.name==="SecurityError"?"blocked":"unavailable")}const d=p(),g=new Map,y=[],k=[];for(const M of b){const z=c.get(M.index),w=(z==null?void 0:z.id)===M.id&&z.mapping===M.mapping;w||(y.push(M.index),n.delete(M.index));const R=n.get(M.index),T=M.mapping==="standard"||(R==null?void 0:R.id)===M.id,V=(R==null?void 0:R.bindings)??t,se=M.axes.map(L=>d?Qt(L):0),ce=M.buttons.map(L=>d?Qt(L.value,0):0),v=Object.create(null);for(const[L,F]of Object.entries(V)){let B=0,N=0;if(d&&T)for(const Z of F){let Me="button"in Z?ce[Z.button]??0:se[Z.axis]??0;"axis"in Z&&(Me=Math.sign(Me)*Math.max(0,(Math.abs(Me)-i)/(1-i))),Me*=Z.scale??1,B=Math.max(B,Me),N=Math.min(N,Me)}const P=B===-N?0:B>-N?B:N,O=Math.abs(P)>=a,ie=w&&!!((S=z.actions[L])!=null&&S.down);v[L]={value:P,down:O,pressed:d&&r&&w&&O&&!ie,released:ie&&!O}}g.set(M.index,{index:M.index,id:M.id,mapping:M.mapping,mapped:T,axes:se,buttons:ce,actions:v})}for(const[M,z]of c){const w=g.get(M);(!w||w.id!==z.id||w.mapping!==z.mapping)&&(k.push(M),w||n.delete(M))}return c=g,r=d,{status:d?g.size?"ready":"waiting":"inactive",players:structuredClone([...g.values()]),connected:y,disconnected:k}},remap(b,d){const g=c.get(b);if(!g||o)throw new Error("Connect and poll this controller before mapping it.");n.set(b,{id:g.id,bindings:Zt(d)}),r=!1},reset:l,dispose(){o=!0,f("closed"),h==null||h.removeEventListener("blur",l),h==null||h.document.removeEventListener("visibilitychange",l)}}}const Hs=s=>[...s.querySelectorAll("button:enabled, select:enabled, input:enabled")].filter(e=>e.getClientRects().length&&getComputedStyle(e).visibility!=="hidden");function rt(s){s&&(s.focus({preventScroll:!0}),s.scrollIntoView({block:"nearest",inline:"nearest"}))}class Gs{constructor(e){m(this,"key","");m(this,"remembered","");m(this,"editor");this.dialog=e}root(){return this.editor??(this.dialog.open?this.dialog:document.getElementById("shell"))}reset(e){e!==this.key&&(this.closeEditor(),this.key=e,this.remembered="")}id(e){var t;return e.dataset.room??(e.id||e.getAttribute("aria-label")||((t=e.textContent)==null?void 0:t.trim())||"")}select(e=0,t=!1){const i=this.root(),a=document.activeElement;if(!e&&a instanceof HTMLElement&&i.contains(a)&&a.matches("button:enabled, select:enabled, input:enabled")&&a.getClientRects().length){this.remembered=this.id(a);return}const c=Hs(i);if(!c.length)return;const r=document.activeElement;let o=c.indexOf(r);if(o<0)o=c.findIndex(n=>this.remembered&&this.id(n)===this.remembered),o<0&&(o=c.findIndex(n=>n.matches("#host, .primary, [data-key]"))),rt(c[Math.max(0,o)]);else if(e){if(t&&r instanceof HTMLSelectElement){this.changeOption(r,e);return}const n=this.editor&&!t?Number(this.editor.dataset.columns):1;rt(c[(o+e*n+c.length)%c.length])}this.remembered=this.id(document.activeElement)}changeOption(e,t){const i=[...e.options].filter(c=>!c.disabled);if(!i.length)return;const a=i.findIndex(c=>c.selected);e.value=i[(a+t+i.length)%i.length].value,e.dispatchEvent(new Event("change",{bubbles:!0}))}activate(){const e=document.activeElement;if(!(e instanceof HTMLElement)||!this.root().contains(e))return this.select();e instanceof HTMLSelectElement?this.changeOption(e,1):e instanceof HTMLInputElement&&e.type==="text"?this.edit(e):e.click()}closeEditor(){return this.editor?(this.editor.close(),this.editor.remove(),this.editor=void 0,!0):!1}edit(e){const t=e.getAttribute("aria-label")==="Room code",i=document.createElement("dialog");i.className="pad-editor",i.setAttribute("aria-label",t?"Enter room code":"Edit name");const a=document.createElement("h2");a.textContent=i.getAttribute("aria-label");const c=document.createElement("output");let r=e.value;const o=()=>{c.textContent=r||"–"},n=document.createElement("div");n.className="pad-keys";const l=t?4:6;i.dataset.columns=String(l),n.style.gridTemplateColumns="repeat("+l+",1fr)";const h=(g,y)=>{const k=document.createElement("button");return k.type="button",k.textContent=g,k.onclick=y,n.append(k),k},p=t?"0123456789abcdef":"abcdefghijklmnopqrstuvwxyz0123456789";let u=!1;const f=g=>g.replace(/-/g,"").slice(0,32).replace(/^(.{8})(.+)$/,"$1-$2").replace(/^(.{13})(.+)$/,"$1-$2").replace(/^(.{18})(.+)$/,"$1-$2").replace(/^(.{23})(.+)$/,"$1-$2"),b=g=>{r=t?f(r+g):(r+g).slice(0,e.maxLength),o()};for(const g of p)h(g,()=>b(u?g.toUpperCase():g)).dataset.key=g;t||(h("Shift",()=>{u=!u;for(const g of n.querySelectorAll("[data-key]"))g.textContent=u?g.dataset.key.toUpperCase():g.dataset.key}),h("Space",()=>b(" ")),h("-",()=>b("-"))),h("Delete",()=>{r=t?f(r.replace(/-/g,"").slice(0,-1)):r.slice(0,-1),o()}),h("Clear",()=>{r="",o()}),h("Done",()=>{e.value=r,e.dispatchEvent(new Event("input",{bubbles:!0})),this.closeEditor(),rt(e)});const d=document.createElement("small");d.textContent="D-pad to move · A to select · B to cancel",i.append(a,c,n,d),i.oncancel=g=>{g.preventDefault(),this.closeEditor()},document.body.append(i),this.editor=i,o(),i.showModal(),rt(n.firstElementChild)}}const es=()=>{var s;return(s=window.napplet)==null?void 0:s.gamepad},Ks=(s=0)=>Math.sign(s)*Math.max(0,(Math.abs(s)-.18)/.82);function Ys(s,e,t){const i=js({},{read:()=>{var y;return typeof navigator.getGamepads=="function"?navigator.getGamepads():((y=es())==null?void 0:y.getGamepads())??[]},active:()=>{var y;return!document.hidden&&document.hasFocus()&&((y=es())==null?void 0:y.focused)!==!1}}),a=new Gs(e);let c=-1,r="",o=0,n=!1,l="",h=0,p=!1,u=0,f=0;function b(){s.clearPad(),p&&t.scores(!1),p=n=!1,o=0,l=""}const d=()=>document.body.classList.remove("pad-mode"),g=y=>{u=requestAnimationFrame(g);const k=Math.min((y-f)/1e3,.05);f=y;const S=i.poll(),M=S.players.find(P=>P.mapped&&P.index===c)??S.players.find(P=>P.mapped);if(S.status!=="ready"||!M){c!==-1&&(c=-1,s.active&&document.body.classList.contains("pad-mode")&&t.menu(),b(),d());return}const z=t.screen();(z!==r||M.index!==c||S.connected.includes(M.index))&&(b(),a.reset(z),r=z,c=M.index);const w=M.buttons.reduce((P,O,ie)=>ie<17&&O>=.5?P|1<<ie:P,0),[R,T,V,se]=[0,1,2,3].map(P=>Ks(M.axes[P]));if(!n){n=!w&&!R&&!T&&!V&&!se,o=w;return}const ce=w&~o;o=w;const v=P=>!!(w&1<<P),L=P=>!!(ce&1<<P);if((w||R||T||V||se)&&document.body.classList.add("pad-mode"),r==="playing"||r==="observing"){if(L(9)){b(),t.menu();return}p!==v(8)&&(p=v(8),t.scores(p)),s.active&&s.gamepad(R,-T,V,se,k,w,ce);return}if(!document.body.classList.contains("pad-mode"))return;if(L(1)||L(9)){a.closeEditor()||t.back();return}if(a.select(),L(0)){a.activate();return}const F=Number(v(15))-Number(v(14))||(Math.abs(R)>.48?Math.sign(R):0),B=Number(v(13))-Number(v(12))||(Math.abs(T)>.48?Math.sign(T):0),N=B?B>0?"down":"up":F?F>0?"right":"left":"";N&&(N!==l||y>=h)&&(a.select(B||F,!B),h=y+(N===l?135:360)),l=N};u=requestAnimationFrame(g),document.addEventListener("pointerdown",d),document.addEventListener("keydown",d),window.addEventListener("blur",b),window.addEventListener("pagehide",()=>{cancelAnimationFrame(u),b(),i.dispose(),a.closeEditor(),document.removeEventListener("pointerdown",d),document.removeEventListener("keydown",d),window.removeEventListener("blur",b)},{once:!0})}function $s(){const s=new Map;function e(a,c){if(s.has(a))throw new Error(`NAP domain "${a}" is already registered`);s.set(a,c)}function t(a){const c=a.type.indexOf(".");if(c<=0)return!1;const r=a.type.slice(0,c),o=s.get(r);return o?(o(a),!0):!1}function i(){return Array.from(s.keys())}return{registerNap:e,dispatch:t,getRegisteredDomains:i}}var Vs=$s(),Xs=Vs.registerNap,Ws="storage";function fs(){var e;const s=window;if(!((e=s.napplet)!=null&&e.storage))throw new Error("window.napplet.storage is unavailable -- runtime did not inject this domain");return s.napplet.storage}function Js(s){return fs().instance.getItem(s)}function Zs(s){return fs().instance.removeItem(s)}Xs(Ws,s=>{});function Qs(){const s=window;if(!s.napplet)throw new Error("window.napplet is unavailable -- runtime did not inject the napplet namespace");return s.napplet}function A(s){const t=Qs()[s];if(!t)throw new Error(`window.napplet.${String(s)} is unavailable -- runtime did not inject this domain`);return t}var ts={getItem(s){return A("storage").getItem(s)},setItem(s,e){return A("storage").setItem(s,e)},removeItem(s){return A("storage").removeItem(s)},keys(){return A("storage").keys()},instance:{getItem(s){return A("storage").instance.getItem(s)},setItem(s,e){return A("storage").instance.setItem(s,e)},removeItem(s){return A("storage").instance.removeItem(s)},keys(){return A("storage").instance.keys()}}},ei={createSession(s){return A("media").createSession(s)},updateSession(s,e){A("media").updateSession(s,e)},destroySession(s){A("media").destroySession(s)},reportState(s,e){A("media").reportState(s,e)},reportCapabilities(s,e){A("media").reportCapabilities(s,e)},sendCommand(s,e,t){A("media").sendCommand(s,e,t)},onCommand(s,e){return A("media").onCommand(s,e)},onState(s,e){return A("media").onState(s,e)},onCapabilities(s,e){return A("media").onCapabilities(s,e)},onControls(s,e){return A("media").onControls(s,e)}},At={getPublicKey(){return A("identity").getPublicKey()},onChanged(s){return A("identity").onChanged(s)},getRelays(){return A("identity").getRelays()},getProfile(){return A("identity").getProfile()},getFollows(){return A("identity").getFollows()},getList(s){return A("identity").getList(s)},getZaps(){return A("identity").getZaps()},getMutes(){return A("identity").getMutes()},getBlocked(){return A("identity").getBlocked()},getBadges(){return A("identity").getBadges()}},Rt={get(){return A("config").get()},subscribe(s){return A("config").subscribe(s)},openSettings(s){A("config").openSettings(s)},registerSchema(s,e){return A("config").registerSchema(s,e)},onSchemaError(s){return A("config").onSchemaError(s)},get schema(){return A("config").schema}},ti={discover(s){return A("cvm").discover(s)},request(s,e,t){return A("cvm").request(s,e,t)},listTools(s,e){return A("cvm").listTools(s,e)},callTool(s,e,t,i){return A("cvm").callTool(s,e,t,i)},listResources(s,e){return A("cvm").listResources(s,e)},readResource(s,e,t){return A("cvm").readResource(s,e,t)},close(s){return A("cvm").close(s)},onEvent(s){return A("cvm").onEvent(s)},registry:{list(s){return A("cvm").registry.list(s)},has(s,e){return A("cvm").registry.has(s,e)},describe(s,e){return A("cvm").registry.describe(s,e)},call(s,e,t,i){return A("cvm").registry.call(s,e,t,i)}}},Ne={open(s){return A("webrtc").open(s)},send(s,e){return A("webrtc").send(s,e)},close(s,e){return A("webrtc").close(s,e)},onEvent(s){return A("webrtc").onEvent(s)}};function si(s,e){return!!(s!=null&&s[e])}function ze(s){return si(window.napplet,s)}const Le=s=>typeof s=="string"?Array.from(s.replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/gu,"").trim()).slice(0,24).join("").trimEnd():"",Lt=s=>typeof s=="string"&&/^[a-f0-9]{64}$/.test(s);class ii{constructor(e,t){m(this,"alias","");m(this,"toggleCrouch",!0);m(this,"profileSelected",!1);m(this,"profile");m(this,"loading",!1);m(this,"message","");m(this,"canProfile",ze("identity"));m(this,"epoch",0);m(this,"revision",0);m(this,"scope",0);m(this,"saved",Promise.resolve());m(this,"sub");if(this.changed=e,this.scopeChanged=t,this.restore(),this.canProfile)try{this.sub=At.onChanged(()=>{this.epoch++,this.scope++,this.revision++,this.profile=void 0,this.profileSelected=!1,this.loading=!1,this.alias="",this.toggleCrouch=!0,this.message="",this.scopeChanged(),this.changed(),this.restore()})}catch{}window.addEventListener("pagehide",()=>{var i;this.epoch++,(i=this.sub)==null||i.close()},{once:!0})}async restore(){const e=this.revision;if(ze("storage"))try{const t=await ts.getItem("player-preferences");if(!t||e!==this.revision)return;const i=JSON.parse(t);this.alias=Le(i==null?void 0:i.alias),this.toggleCrouch=(i==null?void 0:i.crouch)!=="hold",(i==null?void 0:i.useNostr)===!0&&this.canProfile?await this.useProfile():this.changed()}catch{}}save(e,t){if(this.revision++,this.alias=Le(e),this.toggleCrouch=t,this.changed(),ze("storage")){const i=JSON.stringify({alias:this.alias,crouch:t?"toggle":"hold",useNostr:this.profileSelected}),a=this.scope;this.saved=this.saved.then(async()=>{a===this.scope&&await ts.setItem("player-preferences",i)}).catch(()=>{})}}useAlias(){this.epoch++,this.revision++,this.profileSelected=!1,this.profile=void 0,this.loading=!1,this.message="",this.changed()}async useProfile(){this.revision++,this.profileSelected=!0;const e=++this.epoch;this.loading=!0,this.profile=void 0,this.message="Loading profile…",this.changed();try{const t=await At.getPublicKey();if(e!==this.epoch)return;if(!Lt(t))throw Error("Sign in through the host to use a Nostr profile.");this.profile={key:t,name:"Nostr "+t.slice(0,8)},this.changed();const i=await At.getProfile().catch(()=>null);if(e!==this.epoch)return;const a=Le(i==null?void 0:i.displayName)||Le(i==null?void 0:i.display_name)||Le(i==null?void 0:i.name);this.profile={key:t,name:a||"Nostr "+t.slice(0,8)},this.message=a?"Using "+a+".":"No profile name found. Using your shortened public key."}catch(t){if(e!==this.epoch)return;this.message=t instanceof Error&&t.message.startsWith("Sign in")?t.message:"Profile unavailable. You can play under an alias."}finally{e===this.epoch&&(this.loading=!1,this.changed())}}}function ni(s){const t=2*s/4+1,i=new Float32Array(t*t);for(let a=0;a<t;a++)for(let c=0;c<t;c++){const r=c*4-s,o=a*4-s,n=(l,h,p,u,f)=>f*Math.exp(-(((r-l)/p)**2+((o-h)/u)**2));i[a*t+c]=.3+n(-22,9,15,23,7)+n(24,-18,22,14,8)+n(-7,-38,24,13,4)+n(28,33,20,18,5)}return{extent:s,spacing:4,side:t,heights:i}}function te(s,e,t){if(!s)return 0;const i=Math.min(s.side-1,Math.max(0,(e+s.extent)/s.spacing)),a=Math.min(s.side-1,Math.max(0,(t+s.extent)/s.spacing)),c=Math.min(s.side-2,Math.floor(i)),r=Math.min(s.side-2,Math.floor(a)),o=r*s.side+c,n=i-c,l=a-r,h=s.heights[o],p=s.heights[o+1],u=s.heights[o+s.side],f=s.heights[o+s.side+1];return n+l<=1?h+(p-h)*n+(u-h)*l:f+(u-f)*(1-n)+(p-f)*(1-l)}function ps(s,e,t,i){if(!s)return 1/0;const a=[[e[0]+s.extent,t[0]],[e[2]+s.extent,t[2]],[e[0]+e[2]+2*s.extent,t[0]+t[2]]],c=a.map(([l,h])=>Math.abs(h)<1e-8?1/0:((h>0?Math.floor(l/s.spacing+1e-8)+1:Math.ceil(l/s.spacing-1e-8)-1)*s.spacing-l)/h),r=a.map(([,l])=>s.spacing/Math.abs(l));let o=0,n=e[1]-te(s,e[0],e[2]);if(n<=0)return 0;for(;o<i;){const l=Math.min(i,...c),h=e[1]+t[1]*l-te(s,e[0]+t[0]*l,e[2]+t[2]*l);if(h<=0)return o+(l-o)*n/(n-h);for(let p=0;p<3;p++)c[p]<=l+1e-7&&(c[p]+=r[p]);o=l,n=h}return 1/0}const oi={glass:.12,drywall:.55,plywood:1.15,brick:4.8};function ge(s,e,t,i,a,c,r,o,n={}){s.push({x:e,y:t,z:i,w:a,h:c,d:r,color:o,solid:!0,...n})}function ai(){const s=[],e=(r,o,n,l,h,p,u,f={})=>ge(s,r,o,n,l,h,p,u,f);e(0,-.5,0,48,.5,48,"#9a9b93");for(const r of[-1,1])e(0,0,r*23,46,3.8,.55,"#a47664",{material:"brick"}),e(r*23,0,0,.55,3.8,46,"#a47664",{material:"brick"});e(0,3.75,0,46,.18,46,"#d1d0bb",{roof:!0});const t={material:"plywood"},i={solid:!1};function a(r,o,n,l){e(r,.38,o,.72,.17,.72,l,t),e(r,0,o,.17,.38,.17,"#4e5655"),e(r,.54,o+n*.32,.7,.61,.11,l,t)}let c=1;for(const r of[-1,1])for(const o of[-1,1]){for(const[l,h]of[[6,5],[17.5,11]])e(r*l,0,o*3.5,h,3.72,.25,"#c2c5af",{material:"drywall"}),e(r*3.5,0,o*l,.25,3.72,h,"#bec1b1",{material:"drywall"});e(r*13,0,o*14,8,2.9,.17,"#b1cfd0",{material:"glass",pane:c}),c*=2;for(const l of[9,17])e(r*l,0,o*14,.12,3,.26,"#525f61");e(r*13,2.92,o*14,8,.12,.26,"#596568"),e(r*15,0,o*8,4.5,.87,1.35,"#ab936e",{material:"plywood"}),e(r*19,0,o*18,2,1.6,1,"#87958a",{material:"plywood"}),e(r*7,0,o*18,.2,1.55,5,"#a88d65",{material:"plywood"});const n=r<0?o<0?"#668997":"#9d765b":o<0?"#9c9861":"#718674";e(r*15,1.01,o*8,1.06,.6,.1,"#38494b",i),e(r*15,.87,o*8,.15,.18,.12,"#454d4c",i),a(r*15,o*9.3,o,n);for(const l of[.12,.58,1.04])e(r*19,l,o*18.51,1.77,.39,.03,"#738078",i),e(r*19,l+.22,o*18.55,.36,.046,.06,"#404c48",i);if(e(r*16,1.4,o*3.36,4.2,.42,.045,n,i),e(r*13,.03,o*17,7.6,.025,4.5,n,i),r===o){e(r*13,0,o*18,.38,.75,1.3,"#59625e",t),e(r*13,.75,o*18,3.3,.16,1.7,"#ad9878",t);for(const l of[-1,1])a(r*13+l*.87,o*19.3,o,n)}else e(r*20,0,o*10,1.45,.48,4,n,t),e(r*20.62,.48,o*10,.21,.63,4,n,t),e(r*19,.32,o*13,1.1,.13,1.15,"#b39675",t);for(const l of[7,17])e(r*12,3.66,o*l,3.8,.08,.62,"#f4eaca",{solid:!1})}for(const r of[-18,-9,0,9,18])e(0,3.65,r,1.4,.09,2.8,"#f5ebcd",{solid:!1}),e(r,3.65,0,2.8,.09,1.4,"#f5ebcd",{solid:!1});return e(0,.003,0,6,.015,45,"#77858a",{solid:!1}),e(0,.004,0,45,.016,6,"#77858a",{solid:!1}),{name:"North Annex",sector:"NA–03",type:"Office floor",description:"Office suites, glazed conference rooms and intersecting carpeted corridors.",size:24,boxes:s,sky:"#b7c8ce",spawns:[[-20,-20,.78],[20,20,-2.36],[-20,20,2.36],[20,-20,-.78],[0,-19,0],[0,19,Math.PI],[-19,0,1.57],[19,0,-1.57]],practiceContact:[-13,-13,-2.35]}}function ri(){const e=ni(52),t=[],i=[[-41,-37,.73],[41,37,-2.4],[-36,41,2.45],[36,-41,-.7],[0,-44,0],[0,44,Math.PI],[-43,0,1.57],[43,0,-1.57]],a=[-33,-28,-2.4];ge(t,0,-.8,0,104,.8,104,"#71805a");for(const o of[-1,1])ge(t,0,0,o*52,104,10,.8,"#626d59",{boundary:!0}),ge(t,o*52,0,0,.8,10,104,"#626d59",{boundary:!0});for(const o of[-1,1])for(let n=-48;n<=48;n+=8)for(const l of[!0,!1]){const h=l?o*51.6:n,p=l?n:o*(52-.4),u=te(e,h,p);ge(t,h,u-.15,p,.27,1.55,.27,"#685b45",{solid:!1}),ge(t,h,u+.75,p,l?.14:8,.18,l?8:.14,"#817659",{solid:!1});const f=h+(l?o*6:0),b=p+(l?0:o*6);ge(t,f,u-.3,b,7,8+2*Math.cos(n),7,"#536c59",{solid:!1,shape:"pine"})}let c=143;const r=()=>(c=Math.imul(c,1664525)+1013904223>>>0)/4294967296;for(let o=-5;o<=5;o++)for(let n=-5;n<=5;n++){const l=n*9+(r()-.5)*5,h=o*9+(r()-.5)*5,p=te(e,l,h);if(!(Math.abs(l-9*Math.sin(h*.066))<4||Math.abs(h+7*Math.sin(l*.075))<4||[...i,a].some(([u,f])=>Math.hypot(u-l,f-h)<4)))if(r()<.27){const u=1.9+r()*2;ge(t,l,p-.45,h,u,u*.73,u*.86,"#8b9182",{shape:"stone"})}else{const u=5+r()*4;ge(t,l,p-.3,h,.72,u*.8,.72,"#66533e",{material:"plywood"});for(let f=0;f<2;f++)ge(t,l,p+u*(.22+f*.24),h,u*(.61-f*.17),u*(.64-f*.12),u*(.61-f*.17),f?"#49664d":"#374f41",{solid:!1,shape:"pine"})}}return{name:"Alder Ridge",sector:"AR–04",type:"Woodland highlands",description:"Rolling pine ridges, boulder fields and two winding trails.",size:52,boxes:t,spawns:i,practiceContact:a,terrain:e,sky:"#abc6c9"}}const E={grenade:{fuse:135,speed:20,lift:3.6,gravity:13,floorGrip:.76},rocket:{speed:34,lifetime:110},blast:{radius:8.2,damage:170,impulse:14,lift:5.5},feel:{duration:.29,coreDuration:.075,coreRadius:2.25,ringRadius:6.2,particles:76,particleSpeed:13,cameraKick:.46,shakeDecay:13,soundDuration:.34,soundGain:.35,pitchStart:180,pitchEnd:28},crouch:{spread:.68,recoil:.72},hit:{head:1.85,torso:1,legs:.72,speedScale:1.12,speedTicks:24},shot:{bodyCost:.35,crateCost:.42,splatterRange:6,markLimit:160}},G=(s,e,t)=>Math.min(t,Math.max(e,s));function ss(s){const e=[];function t(d,g,y,k,S,M,z,w=!0,R=!1,T,V){e.push({x:d,y:g,z:y,w:k,h:S,d:M,color:z,solid:w,roof:R,material:T,shotCost:V})}const i="#a7987c",a="#515b56",c="#424c49",r="#c8b99b",o="#aa5840",n="#b78d51";function l(d,g,y,k){const S=y?3:7,M=y?7:3;t(d,0,g,S,2.8,M,k);for(let z=-3.1;z<=3.1;z+=.64)if(y)for(const w of[-1,1])t(d+w*1.51,.15,g+z,.09,2.47,.13,k,!1);else for(const w of[-1,1])t(d+z,.15,g+w*1.51,.13,2.47,.09,k,!1);t(d,2.78,g,S+.12,.12,M+.12,k,!1),t(d+S/2+.03,.35,g,.06,.65,Math.min(1.5,M-.2),r,!1)}function h(d,g,y=1.65,k=0){t(d,k,g,y,y*.88,y,"#977d55",!0,!1,"plywood",E.shot.crateCost);for(const S of[-1,1])t(d+S*y*.31,k,g,.11,y*.89,y+.05,"#565c4d",!1);t(d,k+.15,g,y+.04,.15,y+.04,"#77664c",!1)}function p(d,g,y,k,S,M,z="all"){for(const w of[-1,1]){const R=(y-3.4)/2;for(const T of[-1,1])t(d+T*(y-R)/2,0,g+w*k/2,R,S,.45,M,!0,!1,"drywall");if(t(d,2.9,g+w*k/2,3.45,S-2.9,.45,M,!0,!1,"brick"),z==="ends")t(d+w*y/2,0,g,.45,S,k,M,!0,!1,"drywall");else{const T=(k-3.6)/2;for(const V of[-1,1])t(d+w*y/2,0,g+V*(k-T)/2,.45,S,T,M,!0,!1,"drywall");t(d+w*y/2,2.95,g,.45,S-2.95,3.65,M,!0,!1,"brick")}for(let T=-y/2+.7;T<y/2;T+=1.35)Math.abs(T)>1.85&&t(d+T,S-.95,g+w*(k/2+.24),.92,.53,.06,"#506260",!1);for(const T of[-1,1])t(d+T*y/2,0,g+w*k/2,.62,S+.18,.62,a)}t(d,S,g,y+.7,.24,k+.7,"#718078",!0,!0);for(let w=-y/2;w<y/2;w+=1.8)t(d+w,S+.24,g,.13,.08,k+.48,"#93a096",!1,!0);t(d,.005,g,y,.025,k,"#888779",!1),t(d,S-.24,g,2.8,.09,.32,"#ffeab1",!1)}function u(d,g,y){for(const k of[-1,1])t(d+k*y/2,0,g,.64,7.2,.64,n),t(d+k*y/2,0,g,1.05,.45,1.05,i);t(d,6.7,g,y+.8,.75,.65,n);for(let k=-y/2+.7;k<y/2;k+=1.2)t(d+k,6.84,g-.34,.55,.37,.07,c,!1);t(d+1.2,6.4,g,1.8,.38,.95,a,!1),t(d+1.2,4.7,g,.075,1.7,.075,c,!1)}function f(d,g,y,k,S,M){for(let z=0;z<k;z++)t(d,0,g+z*.54*y,M,(z+1)*S,.55,a)}const b=24;t(0,-.75,0,48,.75,48,"#989582");for(const d of[-1,1]){t(d*b,0,0,.55,3,48,i),t(0,0,d*b,48,3,.55,i);for(let g=-23;g<24;g+=4.5)t(g,0,d*b,.32,3.18,.72,a,!1),t(d*b,0,g,.72,3.18,.32,a,!1)}for(let d=-21;d<24;d+=4)t(0,.015,d,.16,.016,1.9,"#d3bf83",!1);for(const d of[-19.5,19.5])t(d,.012,0,.1,.014,45,"#cfc1a1",!1);if(s){p(0,1,21,19,5.3,i),p(-15,-13,9,8,3.7,"#8e9b89","ends"),l(14,-12,!0,o),l(-15,7,!0,a),l(14,13,!1,n),l(4,4,!0,o),h(-4,-4),h(-4,4),h(-3,13),u(1,-15,14),f(-7.1,-6.7,1,10,.22,2.1),t(-7.1,2.04,2.2,2.1,.16,7.6,a),t(-8.13,2.2,2.2,.1,.7,7.6,n);for(const d of[-.7,5.4])t(-7.1,0,d,.28,2.04,.28,c)}else p(-13,4,10,14,4.8,"#a0a28c"),p(13,-8,12,10,4.3,i),l(-6,-9,!1,o),l(7,5,!0,o),l(15,12,!1,"#677f76"),l(-10,15,!1,n),u(-3,1,10),h(2,-5),h(3.7,-5),h(2,-5,1.5,1.45),h(-4,8),h(13,-7),h(-14,3),f(7,14.65,-1,12,.235,2.25),t(11.9,2.65,5.6,7,.17,2.05,a),t(11.9,2.82,6.59,6.9,.6,.1,n),f(15,-1.55,1,12,.235,2.05);for(const d of[-21,21])for(const g of[-17,0,17])t(d,0,g,.17,5.5,.17,c,!1),t(d,5.4,g,1.7,.12,.16,c,!1),t(d-Math.sign(d)*.65,5.3,g,.55,.13,.3,"#e5d3a1",!1);for(let d=0;d<11;d++)t(-17+d*.7,.025,-17,.39,.02,1.1,"#b8aa7d",!1);return{name:s?"Relay Works":"Quarry Yard",sector:s?"RW–02":"QY–01",type:s?"Interior complex":"Industrial yard",description:s?"A roofed machine hall with four entrances and a fast perimeter loop.":"A sunlit freight yard with twin warehouses, cargo lanes and an overhead crane.",size:b,boxes:e,sky:s?"#b4bdba":"#c7c2ac",spawns:[[-18,-19,.55],[17,19,-2.5],[18,-19,-.65],[-18,19,2.35],[0,-21,0],[0,21,Math.PI],[-21,0,1.57],[21,0,-1.57]],practiceContact:s?[-11,-19,-1.6]:[-12.7,-10.4,-2.55]}}const U=[ss(!1),ss(!0),ai(),ri()];function ms(s){return{...s,intactBoxes:s.boxes,broken:0}}function gs(s,e){!s.intactBoxes||s.broken===e||(s.broken=e,s.boxes=s.intactBoxes.filter(t=>!(e&(t.pane??0))))}const is=new WeakMap,ys=(s,e)=>s+128*e;function Bt(s){let e=is.get(s.boxes);if(e)return e;e={cells:new Map,bounds:[]};for(const t of s.boxes){if(!t.solid)continue;const i=[t.x-t.w/2,t.y,t.z-t.d/2],a=[t.x+t.w/2,t.y+t.h,t.z+t.d/2];e.bounds.push({min:i,max:a,pane:t.pane,cost:t.shotCost??(t.material?oi[t.material]:1/0)});for(let c=Math.floor((i[0]-.65)/4);c<=Math.floor((a[0]+.65)/4);c++)for(let r=Math.floor((i[2]-.65)/4);r<=Math.floor((a[2]+.65)/4);r++){const o=ys(c,r);let n=e.cells.get(o);n||(n=[],e.cells.set(o,n)),n.push(t)}}return is.set(s.boxes,e),e}const ci=[];function Ze(s,e,t){return Bt(s).cells.get(ys(Math.floor(e/4),Math.floor(t/4)))??ci}function pt(s,e,t,i=0){return Math.abs(e-s.x)<s.w/2+i&&Math.abs(t-s.z)<s.d/2+i}function Qe(s,e,t,i,a){let c=0,r=a;for(let o=0;o<3;o++){if(Math.abs(e[o])<1e-7){if(s[o]<t[o]||s[o]>i[o])return 1/0;continue}const n=(t[o]-s[o])/e[o],l=(i[o]-s[o])/e[o];if(c=Math.max(c,Math.min(n,l)),r=Math.min(r,Math.max(n,l)),r<c)return 1/0}return c}function Ge(s,e,t,i=90){let a=Math.min(i,ps(s.terrain,e,t,i));for(const c of Bt(s).bounds)a=Math.min(a,Qe(e,t,c.min,c.max,a));return a}function li(s,e,t,i){const a=[],c=ps(s.terrain,e,t,i);if(Number.isFinite(c)){const r=e[0]+c*t[0],o=e[2]+c*t[2],n=te(s.terrain,r,o),l=(n-te(s.terrain,r+.01,o))*100,h=(n-te(s.terrain,r,o+.01))*100,p=Math.hypot(l,1,h);a.push({distance:c,entering:!0,cost:1/0,normal:[l/p,1/p,h/p]})}for(const r of Bt(s).bounds){const o=Qe(e,t,r.min,r.max,i);if(!Number.isFinite(o))continue;let n=1/0,l=0,h=0,p=-1/0;for(let b=0;b<3;b++){if(Math.abs(t[b])<1e-7)continue;const d=(r.min[b]-e[b])/t[b],g=(r.max[b]-e[b])/t[b];Math.min(d,g)>p&&(p=Math.min(d,g),l=b),Math.max(d,g)<n&&(n=Math.max(d,g),h=b)}if(n<=o+1e-6)continue;const u=[0,0,0],f=[0,0,0];u[l]=-Math.sign(t[l]),f[h]=Math.sign(t[h]),a.push({distance:o,normal:u,entering:!0,cost:r.cost,pane:r.pane}),n<=i&&a.push({distance:n,normal:f,entering:!1,cost:r.cost,pane:r.pane})}return a}const H=[{name:"Kestrel C4",type:"Carbine",mode:"AUTO",mag:30,delay:6,damage:27,reload:114,penetration:1.25,spread:.014,kick:.028,pellets:1,zoom:1.45,blurb:"Steady handling and a quick return to aim."},{name:"Viper 9",type:"Submachine gun",mode:"AUTO",mag:32,delay:4,damage:19,reload:86,penetration:.72,spread:.032,kick:.022,pellets:1,zoom:1.25,blurb:"Fast cycling and a short reload, with a wider grouping."},{name:"Breaker 12",type:"Pump shotgun",mode:"PUMP",mag:6,delay:47,damage:17,reload:148,penetration:.55,spread:.105,kick:.073,pellets:8,zoom:1.2,blurb:"Eight pellets per shell. Every follow-up needs a pump cycle."},{name:"Meridian D7",type:"Marksman rifle",mode:"SEMI",mag:10,delay:18,damage:68,reload:143,penetration:1.9,spread:.006,kick:.057,pellets:1,zoom:2,blurb:"Tight grouping and strong individual hits with a magnified sight."},{name:"Kestrel C4H",type:"Heavy carbine",mode:"AUTO",mag:24,delay:7,damage:34,reload:128,penetration:1.55,spread:.012,kick:.04,pellets:1,zoom:1.5,blurb:"A slower Kestrel variant with more kick and a tighter grouping."},{name:"Finch P9",type:"Pistol",mode:"SEMI",mag:14,delay:9,damage:25,reload:67,penetration:.65,spread:.019,kick:.032,pellets:1,zoom:1.25,blurb:"Fast draw and a short reset between taps."},{name:"Hammer H6",type:"Heavy pistol",mode:"SEMI",mag:6,delay:18,damage:48,reload:99,penetration:1.1,spread:.012,kick:.064,pellets:1,zoom:1.35,blurb:"Six rounds with a slower, heavier follow-up."},{name:"Comet R1",type:"RPG",mode:"ROCKET",mag:1,delay:35,damage:E.blast.damage,reload:156,penetration:0,spread:0,kick:.085,pellets:1,zoom:1.18,blurb:"A visible rocket bursts on contact. Reload between launches."}],Re=5,Ke=7,J=s=>typeof s=="number"&&Number.isInteger(s)&&s>=0&&s<Re,de=s=>typeof s=="number"&&Number.isInteger(s)&&s>=Re&&s<H.length,$e=60,ve=1/$e,Pt=$e*300,mt=12,ae=1,et=2,X=4,ke=8,st=16,be=32,gt=64,xt=128,Mt=256,it=512,nt=1024,tt=["Amber","Slate"],qe=s=>s.buttons&X?1.02:1.59,Pe=.46;function Tt(s){return[s.x+Math.cos(s.yaw)*s.lean*Pe/100,s.y+qe(s),s.z-Math.sin(s.yaw)*s.lean*Pe/100]}function hi(s){return H[s.gun].spread*(s.buttons&ke?.44:1)*(s.buttons&X?E.crouch.spread:1)*(1+Math.hypot(s.vx,s.vz)*.1)}function di(s,e){return H[s].kick*(e&X?E.crouch.recoil:1)}function ui(s,e,t){const i=100*(+!!(t&nt)-+!!(t&it));let a=e.lean+G(i-e.lean,-16,16);if(a){const c=Math.sign(a),r=[Math.cos(e.yaw)*c,0,-Math.sin(e.yaw)*c],o=[e.x,e.y+qe(e),e.z];let n=Math.abs(a)*Pe/100;for(const l of Ze(s,e.x,e.z)){const h=Qe(o,r,[l.x-l.w/2-.17,l.y-.17,l.z-l.d/2-.17],[l.x+l.w/2+.17,l.y+l.h+.17,l.z+l.d/2+.17],n);n=Math.min(n,Math.max(0,h-.005))}a=c*Math.round(n*100/Pe)}e.lean=a}const Ve=(s,e)=>[Math.sin(s)*Math.cos(e),Math.sin(e),Math.cos(s)*Math.cos(e)],bs=s=>[s.ack,0,0,s.yaw,s.pitch,0,s.life,-1];function Nt(s,e,t,i=1,a=Re,c=!1){const r=s.spawns[(e+(i-1)*(c?2:3))%s.spawns.length],o=J(t)?a:0;return{id:e,x:r[0],y:te(s.terrain,r[0],r[1]),z:r[1],vx:0,vy:0,vz:0,yaw:r[2],pitch:0,hp:100,gun:t,ammo:H[t].mag,holster:o,spareAmmo:H[o].mag,cook:0,boost:0,lean:0,cool:0,reload:0,frags:2,life:i,kills:0,deaths:0,respawn:0,ack:0,buttons:0,ground:1,protect:80}}function fi(s,e,t){if(!J(e)||!de(t))return;const i=J(s.gun)?e:t,a=J(s.gun)?t:e;s.gun!==i&&(s.gun=i,s.ammo=0,s.reload=H[i].reload,s.cool=12),s.holster!==a&&(s.holster=a,s.spareAmmo=0)}function Xe(s,e,t,i,a,c=.32){return Ze(s,e,i).some(r=>r.y+r.h>t+.035&&r.y<t+a-.015&&pt(r,e,i,c))}function Ft(s,e,t){if(e.hp<=0||e.life!==t[6])return 0;const i=e.buttons,a=t[5]&127;!e.cook&&(t[5]&Mt&&J(e.gun)||t[5]&xt&&de(e.gun))&&([e.gun,e.holster]=[e.holster,e.gun],[e.ammo,e.spareAmmo]=[e.spareAmmo,e.ammo],e.reload=e.ammo?0:H[e.gun].reload,e.cool=Math.max(e.cool,10));const c=H[e.gun];e.yaw=t[3],e.pitch=t[4],e.buttons=a,!(a&X)&&Xe(s,e.x,e.y,e.z,1.76)&&(e.buttons|=X);const r=qe(e)+.17,o=(e.buttons&X?2.2:a&ke?2.85:a&gt?7:4.9)*(e.boost?E.hit.speedScale:1);e.boost=Math.max(0,e.boost-1);const n=Math.max(1,Math.hypot(t[1],t[2])),l=t[1]/n,h=t[2]/n,p=(Math.sin(e.yaw)*l+Math.cos(e.yaw)*h)*o,u=(Math.cos(e.yaw)*l-Math.sin(e.yaw)*h)*o,f=e.ground?.35:.14;e.vx+=(p-e.vx)*f,e.vz+=(u-e.vz)*f;for(const[k,S]of[["x","vx"],["z","vz"]]){const M=e.x+(k==="x"?e.vx*ve:0),z=e.z+(k==="z"?e.vz*ve:0);if(Xe(s,M,e.y,z,r)){if(!e.ground||Xe(s,M,e.y+.25,z,r)){e[S]=0;continue}let w=e.y;for(const R of Ze(s,M,z))pt(R,M,z,.32)&&R.y+R.h<=e.y+.26&&(w=Math.max(w,R.y+R.h));e.y=w}e[k]=k==="x"?M:z}a&et&&!(i&et)&&e.ground&&(e.vy=6.4,e.ground=0),e.vy-=17*ve;const b=e.y+e.vy*ve;let d=te(s.terrain,e.x,e.z),g=100;for(const k of Ze(s,e.x,e.z))pt(k,e.x,e.z,.31)&&(k.y+k.h<=e.y+.035&&(d=Math.max(d,k.y+k.h)),k.y>=e.y+r-.02&&(g=Math.min(g,k.y-r)));e.y=s.terrain&&e.ground&&d>=e.y-.15?d:G(b,d,g),e.ground=+(e.y<=d+.001),(e.ground||b>=g)&&(e.vy=0),ui(s,e,t[5]),e.protect=Math.max(0,e.protect-1),e.cool=Math.max(0,e.cool-1),e.reload>0&&--e.reload===0&&(e.ammo=c.mag),(a&st||a&ae&&!e.ammo)&&!e.reload&&e.ammo<c.mag&&(e.reload=c.reload);let y=0;return!e.cook&&a&be&&!(i&be)&&e.frags>0&&(e.frags--,e.cook=E.grenade.fuse,e.protect=0),e.cook?(e.cook--,(!(a&be)||!e.cook)&&(y|=be),y&be&&(e.cook=0),y):(a&ae&&!e.reload&&!e.cool&&e.ammo>0&&(c.mode==="AUTO"||!(i&ae))&&(e.ammo--,e.cool=c.delay,e.protect=0,y|=ae),y)}function pi(s){return Array.isArray(s)&&s.length===8&&s.every(Number.isFinite)&&Number.isSafeInteger(s[0])&&s[0]>0&&s[0]<1e9&&Math.abs(s[1])<=1&&Math.abs(s[2])<=1&&Math.abs(s[3])<=Math.PI+.001&&Math.abs(s[4])<=1.39&&Number.isInteger(s[5])&&s[5]>=0&&s[5]<2048&&Number.isSafeInteger(s[6])&&Number.isSafeInteger(s[7])}function ns(s){return{id:s.id,life:s.life,x:s.x,y:s.y,z:s.z,crouched:!!(s.buttons&X),dx:Math.cos(s.yaw)*s.lean*Pe/100,dz:-Math.sin(s.yaw)*s.lean*Pe/100}}function os(s){const e=s.crouched?.38:0,t=(i,a,c,r,o)=>({min:[s.x+s.dx*o-c,s.y+i,s.z+s.dz*o-c],max:[s.x+s.dx*o+c,s.y+a,s.z+s.dz*o+c],weight:r});return[t(1.49-e,1.84-e,.16,E.hit.head,1),t(.79-e,1.49-e,.265,E.hit.torso,.55),t(0,.79-e,.18,E.hit.legs,0)]}class mi{constructor(e,t=!1){m(this,"tick",0);m(this,"done",!1);m(this,"players",new Map);m(this,"grenades",[]);m(this,"effects",[]);m(this,"sequence",0);m(this,"history",[]);m(this,"map");m(this,"scores",[0,0]);this.teamMode=t,this.map=ms(e)}shatter(e,t,i){(this.map.broken??0)&e||(gs(this.map,(this.map.broken??0)|e),this.emit("glass",t,-1,i,[0,0,0],0))}add(e,t,i=Re){const a=Nt(this.map,e,t,1,i,this.teamMode);return this.players.set(e,a),a}remove(e){this.players.delete(e),this.grenades=this.grenades.filter(t=>t.owner!==e);for(const t of this.history)t.poses=t.poses.filter(i=>i.id!==e)}emit(e,t,i,a,c,r){this.effects.push({kind:e,id:++this.sequence,who:t,other:i,o:a,v:c,gun:r})}harm(e,t,i,a,c=a){if(!(e.hp<=0||e.protect||this.teamMode&&t!==e.id&&t%2===e.id%2)&&(e.hp=Math.max(0,e.hp-i),e.boost=E.hit.speedTicks,this.emit("hit",t,e.id,[e.x,e.y+.9,e.z],c,e.gun),!e.hp)){e.cook&&(this.grenades.push({x:e.x,y:e.y+.7,z:e.z,vx:e.vx,vy:0,vz:e.vz,owner:e.id,fuse:e.cook}),e.cook=0),e.deaths++,e.respawn=150;const r=this.players.get(t);r&&r!==e&&(r.kills++,this.teamMode&&this.scores[r.id%2]++),this.emit("death",t,e.id,[e.x,e.y,e.z],a,e.gun)}}fire(e,t){var p;const i=H[e.gun],a=Tt(e),c=hi(e),r=Math.ceil(this.map.size*2*Math.SQRT2),o=Ve(e.yaw,e.pitch);if(this.emit("shot",e.id,-1,a,o,e.gun),e.gun===Ke){this.grenades.push({x:a[0],y:a[1],z:a[2],vx:o[0]*E.rocket.speed,vy:o[1]*E.rocket.speed,vz:o[2]*E.rocket.speed,fuse:E.rocket.lifetime,owner:e.id,rocket:!0});return}const n=G(t,this.tick-15,this.tick),h=(t>=0&&((p=this.history.find(u=>u.tick===n))==null?void 0:p.poses)||this.poses()).flatMap(u=>{const f=this.players.get(u.id);return f&&f!==e&&f.hp>0&&f.life===u.life?[{target:f,zones:os(u)}]:[]});for(let u=0;u<i.pellets;u++){const f=Ve(e.yaw+(Math.random()-.5)*c*2,e.pitch+(Math.random()-.5)*c*2),b=li(this.map,a,f,r),d=[];for(const{target:w,zones:R}of h){if(w.hp<=0)continue;let T=1/0,V=0;for(const se of R){const ce=Qe(a,f,se.min,se.max,Math.min(r,T));ce<T&&(T=ce,V=se.weight)}Number.isFinite(T)&&d.push({distance:T,target:w,weight:V})}const g=[...b,...d].sort((w,R)=>w.distance-R.distance),y=i.penetration;let k=y,S=0,M=0,z=-1/0;for(const w of g){if(k-=(w.distance-M)*S,M=w.distance,k<=0&&M-z>=E.shot.splatterRange)break;const R=[a[0]+f[0]*M,a[1]+f[1]*M,a[2]+f[2]*M];if("target"in w){if(k<=0)continue;!w.target.protect&&!(this.teamMode&&w.target.id%2===e.id%2)&&(this.harm(w.target,e.id,Math.max(1,Math.round(i.damage*w.weight*k/y)),[f[0]*4,1.5+f[1]*3,f[2]*4],f),z=M),k-=E.shot.bodyCost}else{if(w.pane&&k>0?(w.entering&&this.shatter(w.pane,e.id,R),z=-1/0):k>0&&this.emit("impact",e.id,-1,R,w.normal,e.gun),w.entering&&M-z<E.shot.splatterRange&&(this.emit("blood",e.id,-1,R,w.normal,e.gun),z=-1/0),k<=0||!Number.isFinite(w.cost))break;S=Math.max(0,S+(w.entering?w.cost:-w.cost))}}}}poses(){return[...this.players.values()].filter(e=>e.hp>0).map(ns)}advance(e){if(!this.done){this.tick++;for(const t of this.players.values()){const i=e.get(t.id);if(t.hp<=0){if(--t.respawn<=0){const n=Nt(this.map,t.id,J(t.gun)?t.gun:t.holster,t.life+1,de(t.gun)?t.gun:t.holster,this.teamMode);this.players.set(t.id,{...n,kills:t.kills,deaths:t.deaths,ack:t.ack})}i&&(t.ack=i[0]);continue}const a=t.cook,c=t.buttons,r=i??bs(t);i||(r[5]=t.buttons&(be|X|ke)|(t.lean<0?it:t.lean>0?nt:0));const o=Ft(this.map,t,r);if(i?t.ack=i[0]:t.buttons|=c&ae,o&ae&&this.fire(t,r[7]),o&be){const n=Ve(t.yaw,Math.min(Math.PI/2,t.pitch+.17)),l=Tt(t);l[1]-=.19;const h=a<=1?0:Math.max(0,Ge(this.map,l,n,.67)-.12);this.grenades.push({x:l[0]+n[0]*h,y:l[1]+n[1]*h,z:l[2]+n[2]*h,vx:n[0]*E.grenade.speed,vy:n[1]*E.grenade.speed+E.grenade.lift,vz:n[2]*E.grenade.speed,fuse:Math.max(1,a),owner:t.id})}}for(let t=this.grenades.length-1;t>=0;t--){const i=this.grenades[t];if(i.rocket){const c=[i.x,i.y,i.z],r=[i.vx/E.rocket.speed,i.vy/E.rocket.speed,i.vz/E.rocket.speed],o=E.rocket.speed*ve;let n=Ge(this.map,c,r,o+1e-4);for(const h of this.players.values())if(!(h.id===i.owner||h.hp<=0))for(const p of os(ns(h)))n=Math.min(n,Qe(c,r,p.min,p.max,o));const l=n<=o?Math.max(0,n-.025):o;i.x+=r[0]*l,i.y+=r[1]*l,i.z+=r[2]*l,n<=o&&(i.fuse=1)}else if(i.fuse>1){i.vy-=E.grenade.gravity*ve;for(const[c,r]of[["x","vx"],["z","vz"],["y","vy"]]){const o=i[r]*ve,n=Math.max(1,Math.ceil(Math.abs(o)/.15));for(let l=0;l<n;l++){const h=i[c]+o/n,p=c==="x"?h:i.x,u=c==="y"?h:i.y,f=c==="z"?h:i.z;if(u<te(this.map.terrain,p,f)+.13||Xe(this.map,p,u-.1,f,.2,.1)){i[r]*=-.43,c==="y"&&(i.vx*=E.grenade.floorGrip,i.vz*=E.grenade.floorGrip);break}i[c]=h}}}if(Math.max(Math.abs(i.x),Math.abs(i.z),Math.abs(i.y))>this.map.size+31&&(i.fuse=1),--i.fuse>0)continue;this.grenades.splice(t,1);const a=[i.x,i.y,i.z];for(const c of this.map.boxes)if(c.pane){const r=[G(i.x,c.x-c.w/2,c.x+c.w/2),G(i.y,c.y,c.y+c.h),G(i.z,c.z-c.d/2,c.z+c.d/2)],o=Math.hypot(r[0]-i.x,r[1]-i.y,r[2]-i.z);o<E.blast.radius&&(!o||Ge(this.map,a,r.map((n,l)=>(n-a[l])/o),o)>=o-.03)&&this.shatter(c.pane,i.owner,r)}this.emit("blast",i.owner,-1,a,[0,0,0],0);for(const c of this.players.values()){const r=c.x-i.x,o=c.y+.85-i.y,n=c.z-i.z,l=Math.max(.01,Math.hypot(r,o,n)),h=[r/l,o/l,n/l];l<E.blast.radius&&Ge(this.map,a,h,l)>=l-.01&&this.harm(c,i.owner,Math.max(1,Math.round(E.blast.damage*(1-l/E.blast.radius))),[h[0]*E.blast.impulse,E.blast.lift+h[1]*5,h[2]*E.blast.impulse],h)}}this.history.push({tick:this.tick,poses:this.poses()}),this.history.length>16&&this.history.shift(),this.done=this.tick>=Pt||(this.teamMode?this.scores.some(t=>t>=mt):[...this.players.values()].some(t=>t.kills>=mt))}}}class gi{constructor(e){m(this,"cells");m(this,"half");m(this,"walk");m(this,"layout");m(this,"way",new Map);this.half=Math.floor((e.size-1)/1.5),this.cells=this.half*2+1,this.walk=new Uint8Array(this.cells**2),this.refresh(e)}refresh(e){this.layout=e.boxes,this.way.clear();for(let t=0;t<this.walk.length;t++){const[i,a]=this.point(t);this.walk[t]=+!Xe(e,i,te(e.terrain,i,a),a,1.8,.5)}}point(e){return[(e%this.cells-this.half)*1.5,(Math.floor(e/this.cells)-this.half)*1.5]}cell(e,t){return G(Math.round(t/1.5)+this.half,0,this.cells-1)*this.cells+G(Math.round(e/1.5)+this.half,0,this.cells-1)}route(e,t){const i=new Int16Array(this.walk.length).fill(-1),a=[e];i[e]=e;for(let r=0;r<a.length;r++){const o=a[r];if(o===t)break;for(const n of[1,-1,this.cells,-this.cells]){const l=o+n;!this.walk[l]||i[l]!==-1||Math.abs(o%this.cells-l%this.cells)>1||(i[l]=o,a.push(l))}}let c=t;for(i[c]===-1&&(c=e);i[c]!==e&&c!==e;)c=i[c];return this.point(c)}input(e,t){this.layout!==e.map.boxes&&this.refresh(e.map);const i=[...e.players.values()].filter(b=>b!==t&&b.hp>0&&(!e.teamMode||b.id%2!==t.id%2)).sort((b,d)=>Math.hypot(b.x-t.x,b.z-t.z)-Math.hypot(d.x-t.x,d.z-t.z))[0];if(!i)return bs(t);const a=i.x-t.x,c=i.z-t.z,r=Math.hypot(a,c),o=i.y+1.1-t.y-qe(t);let n=Math.atan2(a,c),l=Math.atan2(o,r),h=0,p=0,u=0;if(Ge(e.map,[t.x,t.y+qe(t),t.z],Ve(n,l),r)>=r-.1&&r<26)n+=Math.sin(e.tick*.07+t.id)*.06,l+=Math.cos(e.tick*.05+t.id)*.027,h=r>12?.55:0,p=Math.sin(e.tick*.027+t.id)*.4,e.tick>64&&(e.tick+t.id*17)%85<43&&(H[t.gun].mode==="AUTO"||e.tick%4===0)&&(u|=ae);else{(!this.way.has(t.id)||(e.tick+t.id)%10===0)&&this.way.set(t.id,this.route(this.cell(t.x,t.z),this.cell(i.x,i.z)));const[b,d]=this.way.get(t.id);n=Math.atan2(b-t.x,d-t.z),l=0,h=1}return t.ammo||(u|=st),[e.tick+1,h,p,n,l,u,t.life,-1]}}var yi="intent",vs={shell:{proposal:{url:"https://github.com/napplet/naps/pull/101",status:"merged",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Optional readiness and environment binding has focused shim and reference-runtime coverage.",evidence:["packages/nap/src/shell/shim.test.ts"]},relay:{proposal:{url:"https://github.com/napplet/naps/pull/2",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Relay reads, publishing, and subscription lifecycle have maintained shim and integration tests; upstream naming remains under review.",evidence:["packages/nap/src/relay/shim.test.ts"],implementationReference:{revision:"cb8f8eabb2d09439e9d174cb9eb6ef2caad0eca1",evidence:".planning/quick/260703-ghg-align-napplet-packages-with-nap-relayeve/260703-ghg-SUMMARY.md",scope:"RelayEventResult sidecar migration; subsequent changes are not covered."}},identity:{proposal:{url:"https://github.com/napplet/naps/pull/102",status:"merged",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Read-only identity queries and updates have focused binding and reference-runtime coverage.",evidence:["packages/nap/src/identity/shim.test.ts"]},storage:{proposal:{url:"https://github.com/napplet/naps/pull/3",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Key-value binding has focused request/result tests and tutorial usage; host storage isolation remains the host responsibility.",evidence:["packages/nap/src/storage/shim.test.ts"]},inc:{proposal:{url:"https://github.com/napplet/naps/pull/104",status:"merged",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Topic and channel bindings have compatibility tests and authenticated-endpoint reference-runtime coverage.",evidence:["packages/nap/src/inc/shim.ts","packages/conformance-cli/src/browser.test.ts"]},theme:{proposal:{url:"https://github.com/napplet/naps/pull/103",status:"merged",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Theme queries and pushed updates have focused binding and opaque-iframe integration coverage.",evidence:["packages/nap/src/theme/shim.test.ts","packages/conformance-cli/src/browser.test.ts"]},keys:{proposal:{url:"https://github.com/napplet/naps/pull/9",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Keyboard binding ships, but dedicated domain regression coverage is limited; retain explicit evaluation opt-in.",evidence:["packages/nap/src/keys/shim.ts"]},media:{proposal:{url:"https://github.com/napplet/naps/pull/10",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Session creation and playback binding have focused regression coverage; proposed torrent playback amendments are not implied.",evidence:["packages/nap/src/media/shim.test.ts"]},notify:{proposal:{url:"https://github.com/napplet/naps/pull/11",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Notification binding ships with limited dedicated domain regression evidence; broader host integration confidence is unverified.",evidence:["packages/nap/src/notify/shim.ts"]},config:{proposal:{url:"https://github.com/napplet/naps/pull/14",status:"draft",checkedAt:"2026-10-31"},maturity:"exploratory",rationale:"Configuration binding is tested, but the upstream draft is marked MAY DEFER; use for design exploration.",evidence:["packages/nap/src/config/shim.test.ts"]},resource:{proposal:{url:"https://github.com/napplet/naps/pull/80",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Resource fetching has focused shim and type tests; the reverted merge and reopened proposal do not change that implementation assessment.",evidence:["packages/nap/src/resource/shim.test.ts"],implementationReference:{revision:"8e75eadf317d7fe809415e4755cd48f63cfb63f3",evidence:".planning/quick/260703-ghg-align-napplet-packages-with-nap-relayeve/260703-ghg-SUMMARY.md",scope:"Shared ResourceSidecarEntry types during the sidecar migration; subsequent resource changes are not covered."}},cvm:{proposal:{url:"https://github.com/napplet/naps/pull/31",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Session and registry bindings are tested; upstream explicitly marks the contract NEEDS WORK.",evidence:["packages/nap/src/cvm/shim.test.ts"]},outbox:{proposal:{url:"https://github.com/napplet/naps/pull/32",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Routing and subscription bindings have focused tests and an integration regression for structured-clone boundaries.",evidence:["packages/nap/src/outbox/shim.test.ts","packages/nap/src/boundary-integration.test.ts"],implementationReference:{revision:"57db924bac022cc14c67d9fca1a4d92cf1bd4725",evidence:".planning/quick/260703-ghg-align-napplet-packages-with-nap-relayeve/260703-ghg-SUMMARY.md",scope:"RelayEventResult and stream lifecycle migration; subsequent changes are not covered."}},upload:{proposal:{url:"https://github.com/napplet/naps/pull/33",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Upload binding has focused tests for request/result behavior; host rail support remains runtime-specific.",evidence:["packages/nap/src/upload/shim.test.ts"]},intent:{proposal:{url:"https://github.com/napplet/naps/pull/91",status:"merged",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Convention normalization and dispatch have focused binding and reference-runtime integration tests.",evidence:["packages/nap/src/intent/shim.test.ts"]},navigation:{proposal:{url:"https://github.com/napplet/naps/pull/126",status:"in-review",checkedAt:"2026-11-04"},maturity:"exploratory",rationale:"Binding and reference-runtime tests cover an earlier published draft revision; later upstream changes are not yet reconciled, so the API remains exploratory.",evidence:["packages/nap/src/navigation/shim.test.ts","packages/conformance/src/shell/reference-navigation.test.ts"]},ble:{proposal:{url:"https://github.com/napplet/naps/pull/62",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"GATT binding has unit coverage; real-device behavior across host backends is not established by these tests.",evidence:["packages/nap/src/ble/shim.test.ts"]},webrtc:{proposal:{url:"https://github.com/napplet/naps/pull/59",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Signaling and session binding have unit coverage; interoperable live peer sessions remain unverified here.",evidence:["packages/nap/src/webrtc/shim.test.ts"]},link:{proposal:{url:"https://github.com/napplet/naps/pull/53",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"The small link-opening binding has focused regression coverage; navigation authorization stays with the host.",evidence:["packages/nap/src/link/shim.test.ts"]},count:{proposal:{url:"https://github.com/napplet/naps/pull/69",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Count binding is tested, but accuracy and aggregation across real relay backends remain outside that evidence.",evidence:["packages/nap/src/count/shim.test.ts"]},lists:{proposal:{url:"https://github.com/napplet/naps/pull/68",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"List mutation binding is tested; concurrent real-host mutation behavior is not established by binding tests.",evidence:["packages/nap/src/lists/shim.test.ts"]},serial:{proposal:{url:"https://github.com/napplet/naps/pull/61",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Serial binding has unit coverage; device and native-host integration evidence is limited.",evidence:["packages/nap/src/serial/shim.test.ts"]},fs:{proposal:{url:"https://github.com/napplet/naps/pull/88",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Filesystem binding has MVP coverage; portability and authorization across storage backends remain under evaluation.",evidence:["packages/nap/src/fs/shim.test.ts"]},common:{proposal:{url:"https://github.com/napplet/naps/pull/67",status:"in-review",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Social action binding is tested; broader host integration and evolving action semantics warrant explicit opt-in.",evidence:["packages/nap/src/common/shim.test.ts"]},dm:{proposal:{url:"https://github.com/napplet/naps/pull/74",status:"draft",checkedAt:"2026-10-31"},maturity:"experimental",rationale:"Direct-message binding has shim and type coverage; transport interoperability is not established by those tests.",evidence:["packages/nap/src/dm/shim.test.ts"]},gamepad:{proposal:{url:"https://github.com/napplet/naps/pull/130",status:"in-review",checkedAt:"2026-10-31"},maturity:"supported",rationale:"Cross-repository delivery includes binding, security, runtime, and conformance verification; the reopened proposal is still subject to change.",evidence:["packages/nap/src/gamepad/shim.test.ts",".planning/phases/163-nap-gamepad-across-repositories/163-VERIFICATION.md"],implementationReference:{revision:"0b28f77e3dfa0f07dd7c0f9d61a7090ee99f3a5e",evidence:".planning/phases/163-nap-gamepad-across-repositories/163-SECURITY.md",scope:"Phase 163 binding, runtime isolation, and conformance verification."}},llm:{proposal:{url:"https://github.com/napplet/naps/pull/134",status:"draft",checkedAt:"2026-10-31"},maturity:"exploratory",rationale:"Early published draft has binding and mock-runtime tests; provider behavior and API design remain exploratory.",evidence:["packages/nap/src/llm/shim.test.ts","packages/conformance-cli/src/browser.test.ts"]},blossom:{proposal:{url:"https://github.com/napplet/naps/pull/71",status:"in-review",checkedAt:"2026-11-05"},maturity:"exploratory",rationale:"Binding and validator tests cover the wire contract, but the reference host only returns typed unavailable results; live endpoint, authentication, and integrity behavior are unproven.",evidence:["packages/nap/src/blossom/shim.test.ts","packages/conformance/src/validators/blossom.test.ts","packages/conformance-cli/src/browser.test.ts"]},catalog:{proposal:{url:"https://github.com/napplet/naps/pull/95",status:"in-review",checkedAt:"2026-11-09"},maturity:"experimental",rationale:"Binding, reference-shell snapshot, and envelope-validator tests cover read-only discovery; snapshot contents depend on each host's verified manifests and are not established by those tests.",evidence:["packages/nap/src/catalog/shim.test.ts","packages/conformance/src/shell/reference-catalog.test.ts","packages/conformance/src/validators/catalog.test.ts"]},torrent:{proposal:{url:"https://github.com/napplet/naps/pull/72",status:"in-review",checkedAt:"2026-11-09"},maturity:"exploratory",rationale:"Binding, validator, and real-iframe tests run against a reference shell without a torrent engine; live transfer, seeding, and content verification behavior are unproven.",evidence:["packages/nap/src/torrent/shim.test.ts","packages/conformance/src/validators/torrent.test.ts","packages/conformance-cli/src/browser.test.ts"]},soulseek:{proposal:{url:"https://github.com/napplet/naps/pull/135",status:"in-review",checkedAt:"2026-11-09"},maturity:"exploratory",rationale:"Binding, validator, and real-iframe tests run against a reference shell without a Soulseek client; live search, peer transfer, and saving behavior are unproven.",evidence:["packages/nap/src/soulseek/shim.test.ts","packages/conformance/src/validators/soulseek.test.ts","packages/conformance-cli/src/browser.test.ts"]}};for(const s of Object.values(vs))Object.freeze(s.proposal),Object.freeze(s.evidence),s.implementationReference&&Object.freeze(s.implementationReference),Object.freeze(s);Object.freeze(vs);function bi(){const s=new Map;function e(a,c){if(s.has(a))throw new Error(`NAP domain "${a}" is already registered`);s.set(a,c)}function t(a){const c=a.type.indexOf(".");if(c<=0)return!1;const r=a.type.slice(0,c),o=s.get(r);return o?(o(a),!0):!1}function i(){return Array.from(s.keys())}return{registerNap:e,dispatch:t,getRegisteredDomains:i}}var vi=bi(),wi=vi.registerNap;function ki(){var e;const s=window;if(!((e=s.napplet)!=null&&e.intent))throw new Error("window.napplet.intent is unavailable -- runtime did not inject this domain");return s.napplet.intent}function xi(s){return ki().onDelivery(s)}wi(yi,s=>{});class Mi{constructor(e,t,i={}){m(this,"context");m(this,"output");m(this,"session","");m(this,"pending",!1);m(this,"blocked",!1);m(this,"disposed",!1);m(this,"muted",!1);m(this,"volume",1);m(this,"stopped",!1);m(this,"listener");this.media=e,this.title=t,this.options=i}activate(){var e,t;if(!this.media||this.disposed||this.blocked)return!1;try{return this.context||(this.context=((t=(e=this.options).createContext)==null?void 0:t.call(e))??new AudioContext,this.output=this.context.createGain(),this.output.gain.value=0,this.output.connect(this.context.destination),this.context.onstatechange=()=>this.report()),!this.session&&!this.pending&&(this.pending=!0,this.register()),this.context.state==="suspended"&&this.resume(),this.audible}catch{return this.dispose(),!1}}get audible(){var e;return!!this.session&&!this.disposed&&!this.blocked&&!this.muted&&((e=this.context)==null?void 0:e.state)==="running"}setMuted(e){this.muted=e,this.applyGain(),this.report()}applyGain(){this.output&&(this.output.gain.value=this.audible?this.volume:0)}report(){var e,t;if(this.applyGain(),(t=(e=this.options).onChange)==null||t.call(e),!(!this.session||this.disposed))try{this.media.reportState(this.session,{status:this.audible?"playing":this.stopped?"stopped":"paused",volume:this.muted?0:this.volume})}catch{this.dispose()}}async resume(){var e;try{await((e=this.context)==null?void 0:e.resume()),this.report()}catch{this.applyGain()}}async register(){try{const e=await this.media.createSession({owner:"napplet",metadata:{title:this.title,mediaType:"audio"},capabilities:["play","pause","stop","volume"]});if(this.disposed){e.sessionId&&this.media.destroySession(e.sessionId);return}if(e.error||!e.sessionId||e.owner!=="napplet"){e.sessionId&&this.media.destroySession(e.sessionId),this.dispose();return}this.session=e.sessionId,this.listener=this.media.onCommand(this.session,(t,i)=>{var a;this.disposed||(t==="pause"||t==="stop"?(this.blocked=!0,this.stopped=t==="stop",this.applyGain(),(a=this.context)==null||a.suspend().then(()=>this.report()).catch(()=>{})):t==="play"?(this.blocked=!1,this.stopped=!1,this.resume()):t==="volume"&&typeof i=="number"&&Number.isFinite(i)&&(this.volume=Math.max(0,Math.min(1,i))),this.report())}),this.report()}catch{this.dispose()}finally{this.pending=!1}}dispose(){var e;if(!this.disposed){this.disposed=!0,this.applyGain();try{(e=this.listener)==null||e.close()}catch{}if(this.context&&(this.context.onstatechange=null,this.context.close().catch(()=>{})),this.session)try{this.media.destroySession(this.session)}catch{}this.session=""}}}const as=new Map;function je(s,e){const t=s+e;let i=as.get(t);if(!i){const a=parseInt(s.slice(1),16);i="rgb("+[a>>16,a>>8&255,a&255].map(c=>Math.round(c*e)).join(",")+")",as.set(t,i)}return i}function ws(s,e){const t=s.getContext("2d");if(!t)return;const i=s.clientWidth,a=s.clientHeight;if(!i||!a)return;const c=Math.min(2,devicePixelRatio);s.width=i*c,s.height=a*c,t.scale(c,c);const r=Math.min(i/75,a/43)*24/e.size,o=i*.51,n=a*.53,l=(d,g,y)=>[o+(d*.83-y*.55)*r,n+(d*.28+y*.42-g*.86)*r];function h(d,g,y){t.beginPath();for(let k=0;k<d.length;k++)k?t.lineTo(d[k][0],d[k][1]):t.moveTo(d[k][0],d[k][1]);t.closePath(),t.fillStyle=g,t.fill(),y&&(t.strokeStyle=y,t.lineWidth=.45,t.stroke())}function p(d){if(d.boundary||Math.max(Math.abs(d.x),Math.abs(d.z))>e.size+1)return;if(d.shape==="pine"){h([[d.x-d.w/2,d.y,d.z],[d.x,d.y+d.h,d.z],[d.x+d.w/2,d.y,d.z]].map(w=>l(...w)),d.color);return}const g=d.x-d.w/2,y=g+d.w,k=d.z-d.d/2,S=k+d.d,M=d.y,z=M+d.h;h([[g,M,S],[y,M,S],[y,z,S],[g,z,S]].map(w=>l(...w)),je(d.color,.7)),h([[y,M,k],[y,M,S],[y,z,S],[y,z,k]].map(w=>l(...w)),je(d.color,.53)),h([[g,z,k],[y,z,k],[y,z,S],[g,z,S]].map(w=>l(...w)),je(d.color,1.08),d.h>.2?"#c5ba9960":void 0)}const u=e.boxes[0];p({...u,y:-1.2,h:1.17,color:"#666e62"}),p(u);const f=e.terrain;if(f){const d=(g,y)=>l(g*f.spacing-f.extent,f.heights[y*f.side+g],y*f.spacing-f.extent);for(let g=0;g<f.side-1;g++)for(let y=0;y<f.side-1;y++){const k=g*f.side+y,S=f.heights[k],M=.87+.025*S+.06*(f.heights[k+1]-S);h([d(y,g),d(y,g+1),d(y+1,g)],je("#84916e",M)),h([d(y+1,g),d(y,g+1),d(y+1,g+1)],je("#84916e",M+.015))}}for(let d=-e.size+4;!f&&d<e.size;d+=4)for(const g of[[[-e.size,d],[e.size,d]],[[d,-e.size],[d,e.size]]]){const[y,k]=g.map(([S,M])=>l(S,.001,M));t.beginPath(),t.moveTo(y[0],y[1]),t.lineTo(k[0],k[1]),t.lineWidth=.5,t.strokeStyle="#686d5b66",t.stroke()}for(const d of e.boxes.slice(1).filter(g=>g.solid&&!g.roof&&g.h>.9&&g.w<30&&g.d<30)){const g=d.x-d.w/2,y=d.z-d.d/2;h([[g,y],[g+d.w,y],[g+d.w+d.h*.58,y+d.d+d.h*.39],[g+d.h*.58,y+d.d+d.h*.39]].map(([k,S])=>l(k,0,S)),"#48483d44")}const b=e.boxes.slice(1).sort((d,g)=>d.x*.55+d.z*.83+d.y*.65-(g.x*.55+g.z*.83+g.y*.65));for(const d of b)(d.w>40||d.d>40)&&d.y>=0&&d.x+d.z>=20||e.sector==="NA–03"&&d.roof||p(d);return l}function ks(s,e){const t=s.getContext("2d");if(!t)return;s.width=660,s.height=196,t.scale(2,2),t.strokeStyle="#bdc3ae",t.lineWidth=1.05,t.lineJoin="round";function i(h,p="#55605b"){t.beginPath(),h.forEach(([u,f],b)=>b?t.lineTo(u,f):t.moveTo(u,f)),t.closePath(),t.fillStyle=p,t.fill(),t.stroke()}function a(h,p,u,f,b){i([[h,p],[h+u,p],[h+u,p+f],[h,p+f]],b)}if(e>=5){if(e===7)a(35,36,233,17,"#646e55"),a(254,32,18,25,"#414b40"),a(74,52,12,17,"#53604e"),a(130,27,22,8,"#6a715a");else{const h=e===6?25:0;a(102,31,91+h,15,"#7a8074"),a(108,46,69,6,"#4b564d"),i([[111,49],[129,49],[122,73],[101,73]],"#49534b"),a(179+h,28,4,3,"#333e35")}return}const c=e===1,r=e===2,o=e===3,n=c?235:o?299:276,l=c?23:o?-4:8;t.translate(l,0),i([[24,40],[64,40],[77,36],[86,39],[86,53],[69,54],[49,64],[29,73],[22,72]],"#61665a"),i([[30,46],[61,45],[65,48],[34,62]],"#303a36"),a(19,40,5,33,"#343f39"),a(74,41,22,9,"#47514a"),i([[98,48],[116,50],[112,60],[105,77],[96,75],[101,57]],"#414b43"),r||i([[132,49],[149,51],[147,66],[153,76],[141,80],[133,69],[132,61]],"#606759"),i([[110,50],[134,50],[130,62],[113,63],[108,59],[111,57],[115,60],[127,59],[129,54],[111,54]],"#363e39"),a(86,35,72,16,"#626b5e"),a(91,49,59,5,"#475047"),a(97,39,23,4,"#353f39"),a(155,35,c?40:62,14,"#5b6458");for(let h=158;h<(c?192:212);h+=6)a(h,38,2.2,6,"#313d36");a(c?195:217,38,n-(c?195:217),5,"#555f54"),a(n,36,15,9,"#3d4840");for(let h=0;h<3;h++)a(n+3+h*3,37,1,5,"#72786b");r&&a(163,49,45,7,"#826f55"),o?(a(104,23,51,7,"#4d5950"),a(99,21,10,11,"#60695e"),a(149,20,13,12,"#566258"),a(116,30,4,5,"#4c564b"),a(140,30,4,5,"#4c564b")):(i([[105,35],[108,25],[118,25],[122,35]],"#414d44"),a(110,27,6,5,"#a1ad8a")),a(88,32,c?103:123,3,"#424b43");for(let h=91;h<(c?188:208);h+=5)a(h,31,2,2,"#7d8474");for(const[h,p]of[[92,46],[125,39],[150,46]])t.fillStyle="#c0bca2",t.fillRect(h,p,2,2)}const xs=[[0,1],[1,2],[1,3],[3,4],[4,5],[1,6],[6,7],[7,8],[0,9],[9,10],[10,11],[0,12],[12,13],[13,14]],Si=[[3,6],[9,12],[3,0],[6,0],[1,9],[1,12],[3,2],[6,2]];function Ms(s,e,t,i,a=0,c=!1,r=0){const o=Math.sin(a)*.24,n=c?.38:0,l=[[0,.93-n,0],[0,1.44-n,0],[0,1.67-n,0],[-.22,1.43-n,0],[-.28,1.2-n,.13],[-.14,1.29-n,.44],[.22,1.43-n,0],[.29,1.17-n,-.01],[.1,1.29-n,.25],[-.125,.86-n,0],[-.14,.47-n*.5,.08+(c?.23:0)+o],[-.15,.11,o],[.125,.86-n,0],[.14,.47-n*.5,.08+(c?.23:0)-o],[.15,.11,-o]];for(const u of[2,4,5,7,8]){const f=l[u],b=l[u===2?1:u<6?3:6],d=u===2?r*.65:r,g=f[1]-b[1],y=f[2]-b[2];f[1]=b[1]+g*Math.cos(d)+y*Math.sin(d),f[2]=b[2]-g*Math.sin(d)+y*Math.cos(d)}const h=Math.cos(i),p=Math.sin(i);return l.map(([u,f,b])=>[s+u*h+b*p,e+f,t+b*h-u*p])}class Ci{constructor(){m(this,"bodies",[]);m(this,"sparks",[]);m(this,"marks",[]);m(this,"muzzles",new Map);m(this,"damageBearing",0);m(this,"blasts",[]);m(this,"flash",0);m(this,"kick",0);m(this,"hit",0);m(this,"hurt",0);m(this,"shake",0);m(this,"shotCount",0)}reset(){this.blasts=[],this.bodies=[],this.sparks=[],this.marks=[],this.muzzles.clear(),this.flash=this.kick=this.hit=this.hurt=this.shake=this.shotCount=0}localShot(e){this.flash=.075,this.kick=Math.min(.15,this.kick+e),this.shotCount++}receive(e,t,i){if(e.kind==="shot")this.muzzles.set(e.who,.075);else if(e.kind==="impact"||e.kind==="blood"){const a=e.kind==="blood";this.marks.push({o:e.o,n:e.v,size:a?.16:.034,color:a?"#742a25":"#383a35",seed:e.id}),this.marks.length>E.shot.markLimit&&this.marks.shift(),a||this.burst(e.o,3,1.4,!1)}else if(e.kind==="glass"){const a=this.sparks.length;this.burst(e.o,14,2.8,!1);for(const c of this.sparks.slice(Math.min(a,this.sparks.length-14)))c.color="#abd2d5"}else if(e.kind==="death"){const a=i.find(n=>n.id===e.other),c=Ms(...e.o,(a==null?void 0:a.yaw)??0,Math.random()*5,!!(a&&a.buttons&4),(a==null?void 0:a.pitch)??0).map((n,l)=>({p:n,old:n.map((h,p)=>h-(e.v[p]*(l<3?1:.64)+(Math.random()-.5)*1.7)/60),r:l===2?.16:.095})),r=[...xs,...Si].map(([n,l])=>({a:n,b:l,length:Math.hypot(...c[n].p.map((h,p)=>h-c[l].p[p]))})),o=[[3,4,5],[6,7,8],[9,10,11],[12,13,14]].map(([n,l,h])=>{const p=(f,b)=>Math.hypot(...c[f].p.map((d,g)=>d-c[b].p[g])),u=p(n,l)+p(l,h);return{a:n,b:h,min:u*(n<9?.31:.39),max:u*.996}});this.bodies.push({j:c,links:r,bends:o,age:0,team:e.other,sleep:0}),this.bodies.length>10&&this.bodies.shift()}else if(e.kind==="hit")e.who===t&&(this.hit=.18),e.other===t&&(this.hurt=.48,this.damageBearing=Math.atan2(-e.v[0],-e.v[2]));else{this.blasts.push({o:e.o,age:0}),this.burst(e.o,E.feel.particles,E.feel.particleSpeed,!0);const a=i.find(c=>c.id===t);a&&(this.shake=Math.max(this.shake,E.feel.cameraKick*Math.max(0,1-Math.hypot(a.x-e.o[0],a.z-e.o[2])/18)));for(const c of this.bodies)for(const r of c.j){const o=Math.hypot(...r.p.map((n,l)=>n-e.o[l]));if(o<E.blast.radius){c.sleep=0;for(let n=0;n<3;n++)r.old[n]-=(r.p[n]-e.o[n])/(o+.3)*(1-o/E.blast.radius)*E.blast.impulse/60}}}}burst(e,t,i,a){for(let c=0;c<t;c++){const r=a&&c%3===0,o=r?.65+Math.random()*.55:.1+Math.random()*(a?.65:.14);this.sparks.push({p:[...e],v:[(Math.random()-.5)*i*2,Math.random()*i+1,(Math.random()-.5)*i*2],t:o,total:o,size:r?.23+Math.random()*.3:.04+Math.random()*.075,color:r?"#716d5e":c%2?"#fec15e":"#e58337"})}this.sparks.length>240&&this.sparks.splice(0,this.sparks.length-240)}step(e,t){this.blasts=this.blasts.filter(i=>(i.age+=t)<E.feel.duration),this.flash=Math.max(0,this.flash-t),this.kick*=Math.exp(-t*12),this.hit=Math.max(0,this.hit-t),this.hurt=Math.max(0,this.hurt-t),this.shake*=Math.exp(-t*E.feel.shakeDecay);for(const[i,a]of this.muzzles)a<=t?this.muzzles.delete(i):this.muzzles.set(i,a-t);this.sparks=this.sparks.filter(i=>{i.t-=t,i.v[1]-=t*(i.color==="#716d5e"?3:12);for(let c=0;c<3;c++)i.p[c]+=i.v[c]*t;const a=te(e.terrain,i.p[0],i.p[2])+.03;return i.p[1]<a&&(i.p[1]=a,i.v[1]*=-.3),i.t>0}),this.bodies=this.bodies.filter(i=>(i.age+=t)<9);for(const i of this.bodies){if(i.sleep>.6)continue;let a=0;for(const c of i.j){const r=c.p.map((o,n)=>o+(o-c.old[n])*.991-(n===1?14*t*t:0));c.old=c.p,c.p=r}for(let c=0;c<5;c++){for(const{a:r,b:o,length:n}of i.links){const l=i.j[r].p,h=i.j[o].p,p=h[0]-l[0],u=h[1]-l[1],f=h[2]-l[2],b=(1-n/Math.max(1e-4,Math.hypot(p,u,f)))*.5;l[0]+=p*b,l[1]+=u*b,l[2]+=f*b,h[0]-=p*b,h[1]-=u*b,h[2]-=f*b}for(const r of i.bends){const o=i.j[r.a].p,n=i.j[r.b].p,l=n[0]-o[0],h=n[1]-o[1],p=n[2]-o[2],u=Math.hypot(l,h,p);if(u>=r.min&&u<=r.max)continue;const f=.5*(1-(u<r.min?r.min:r.max)/Math.max(1e-4,u));o[0]+=l*f,o[1]+=h*f,o[2]+=p*f,n[0]-=l*f,n[1]-=h*f,n[2]-=p*f}for(const r of i.j){r.p[1]=Math.max(r.p[1],te(e.terrain,r.p[0],r.p[2])+r.r);for(const o of Ze(e,r.p[0],r.p[2])){if(!pt(o,r.p[0],r.p[2],r.r)||r.p[1]+r.r<=o.y||r.p[1]-r.r>=o.y+o.h)continue;const n=[o.w/2+r.r-Math.abs(r.p[0]-o.x),o.h/2+r.r-Math.abs(r.p[1]-o.y-o.h/2),o.d/2+r.r-Math.abs(r.p[2]-o.z)],l=n.indexOf(Math.min(...n)),h=[o.x,o.y+o.h/2,o.z][l];r.p[l]+=(r.p[l]>=h?1:-1)*n[l],l===1&&c===4&&(r.old[0]+=(r.p[0]-r.old[0])*.42,r.old[2]+=(r.p[2]-r.old[2])*.42)}}}for(const c of i.j)a+=Math.hypot(...c.p.map((r,o)=>r-c.old[o]));i.sleep=a<.023?i.sleep+t:0}}}const zi="object",Ei={lookSensitivity:{type:"number",title:"Look sensitivity",minimum:.3,maximum:2.5,default:1},renderScale:{type:"number",title:"Render resolution scale",minimum:.5,maximum:1,default:1}},Ai={type:zi,properties:Ei},Ce={sensitivity:1,scale:1};ze("config")&&(async()=>{Rt.schema||await Rt.registerSchema(Ai);const s=Rt.subscribe(e=>{Ce.sensitivity=typeof e.lookSensitivity=="number"?G(e.lookSensitivity,.3,2.5):1,Ce.scale=typeof e.renderScale=="number"?G(e.renderScale,.5,1):1,window.dispatchEvent(new Event("gameconfig"))});window.addEventListener("pagehide",()=>s.close(),{once:!0})})().catch(()=>{});const rs={Digit1:xt,Digit2:Mt,KeyF:ae,KeyV:ke,Space:et,KeyC:X,KeyQ:it,KeyE:nt,KeyR:st,KeyG:be,ShiftLeft:gt,ShiftRight:gt},Ri=[et,0,st,0,be,0,ke,ae,0,0,gt,0,xt,Mt,it,nt],Ii={fire:ae,aim:ke,jump:et,duck:X,left:it,right:nt,reload:st,throw:be},cs=()=>{var s;return(s=window.napplet)==null?void 0:s.soyMouse};class Li{constructor(e,t,i){m(this,"yaw",0);m(this,"pitch",0);m(this,"active",!1);m(this,"keys",new Set);m(this,"presses",0);m(this,"mouse",0);m(this,"touches",new Map);m(this,"stick",[0,0]);m(this,"toggles",0);m(this,"padMove",[0,0]);m(this,"padHeld",0);m(this,"padPressed",0);m(this,"padCrouch",!1);m(this,"padSwap",!1);m(this,"shellCapture");m(this,"shellLocked",!1);m(this,"lockPending",!1);m(this,"denied",!1);m(this,"locked",!1);m(this,"swap",!1);m(this,"drag",-1);m(this,"steerOrigin",null);m(this,"steerRate",0);m(this,"lastX",0);m(this,"lastY",0);this.canvas=e,this.pause=t,this.toggleCrouch=i,window.addEventListener("keydown",n=>{if(this.active){if(n.code==="Escape"||n.code==="KeyP"){n.preventDefault(),n.repeat||t();return}if(/^(Key[WASDFVCRGQE]|Digit[12]|Arrow(Up|Down|Left|Right)|Shift(Left|Right)|Space)$/.test(n.code)){if(n.preventDefault(),n.code==="KeyC"&&this.toggleCrouch()){n.repeat||this.toggle(X);return}n.repeat||(this.presses|=rs[n.code]??0),this.keys.add(n.code)}}}),window.addEventListener("keyup",n=>this.keys.delete(n.code)),window.addEventListener("blur",()=>this.clear()),document.addEventListener("pointerlockchange",()=>{const n=this.locked;if(this.locked=document.pointerLockElement===e,this.lockPending=!1,this.stopSteering(),this.locked&&!this.active){document.exitPointerLock();return}this.updateCursor(),n&&!this.locked&&this.active&&t()}),document.addEventListener("pointerlockerror",()=>{this.lockPending=!1,this.updateCursor()}),document.addEventListener("visibilitychange",()=>{document.hidden&&this.clear()}),this.canvas.addEventListener("contextmenu",n=>n.preventDefault()),e.addEventListener("mousedown",n=>{this.active&&!this.shellLocked&&this.mouseButtons(n.buttons),!(n.button!==1||!this.active||this.locked||this.shellLocked)&&(n.preventDefault(),this.steerOrigin=n.clientX,this.steerRate=0)}),window.addEventListener("mouseup",n=>{this.active&&!this.shellLocked&&this.mouseButtons(n.buttons),n.button===1&&this.stopSteering()}),e.addEventListener("auxclick",n=>{n.button===1&&this.active&&n.preventDefault()}),this.canvas.addEventListener("pointerdown",n=>{this.active&&(n.pointerType!=="mouse"&&n.preventDefault(),e.focus({preventScroll:!0}),n.pointerType==="mouse"&&(this.mouseButtons(n.buttons),n.buttons&4&&(this.steerOrigin=n.clientX,this.steerRate=0),this.lock()),this.drag=n.pointerId,this.lastX=n.clientX,this.lastY=n.clientY,!this.locked&&!e.hasPointerCapture(n.pointerId)&&e.setPointerCapture(n.pointerId))}),this.canvas.addEventListener("pointermove",n=>{if(this.active&&(n.pointerType==="mouse"&&this.mouseButtons(n.buttons),document.pointerLockElement!==e)){if(n.pointerType==="mouse"&&this.steerOrigin!==null&&n.buttons&4){const l=n.clientX-this.steerOrigin;this.steerRate=Math.sign(l)*G((Math.abs(l)-4)/56,0,1),this.turn(0,n.movementY),this.lastX=n.clientX,this.lastY=n.clientY;return}if(n.pointerType==="mouse"){this.stopSteering(),this.turn(n.movementX,n.movementY);return}n.pointerId===this.drag&&(this.turn(n.clientX-this.lastX,n.clientY-this.lastY),this.lastX=n.clientX,this.lastY=n.clientY)}}),document.addEventListener("mousemove",n=>{this.active&&document.pointerLockElement===e&&this.turn(n.movementX,n.movementY)});const a=n=>{this.active&&n.pointerType==="mouse"&&this.mouseButtons(n.buttons),n.pointerType==="mouse"&&!(n.buttons&4)&&this.stopSteering(),!n.buttons&&this.drag===n.pointerId&&(this.drag=-1)};window.addEventListener("pointerup",a),e.addEventListener("lostpointercapture",n=>{this.drag===n.pointerId&&(this.drag=-1,this.stopSteering(),this.mouse=0)}),window.addEventListener("pointercancel",()=>this.clear());const c=document.querySelector("#stick");let r=-1;const o=n=>{const l=c.getBoundingClientRect(),h=(n.clientX-l.left-l.width/2)/30,p=(n.clientY-l.top-l.height/2)/30,u=Math.max(1,Math.hypot(h,p));this.stick=[h/u,-p/u],c.firstElementChild.setAttribute("style","transform:translate("+h/u*23+"px,"+p/u*23+"px)")};c.onpointerdown=n=>{this.active&&(r=n.pointerId,c.setPointerCapture(r),o(n))},c.onpointermove=n=>{n.pointerId===r&&o(n)},c.onlostpointercapture=()=>{r=-1,this.stick=[0,0],c.firstElementChild.removeAttribute("style")};for(const n of document.querySelectorAll("[data-action]")){const l=Ii[n.dataset.action];n.onpointerdown=h=>{if(this.active){if(h.preventDefault(),n.setPointerCapture(h.pointerId),n.dataset.action==="swap"){this.swap=!0;return}l===ke||l===X&&this.toggleCrouch()?this.toggle(l):(this.touches.set(h.pointerId,l),this.presses|=l)}},n.onlostpointercapture=h=>this.touches.delete(h.pointerId)}}toggle(e){var t;this.toggles^=e,(t=document.querySelector('[data-action="'+(e===X?"duck":"aim")+'"]'))==null||t.setAttribute("aria-pressed",String(!!(this.toggles&e)))}mouseButtons(e){const t=(e&1?ae:0)|(e&2?ke:0);this.presses|=t&~this.mouse,this.mouse=t}offerShellMouse(e){this.shellCapture||(this.shellCapture=e.offer(t=>{if(this.active)if(t.type==="mouse.state"){const i=this.shellLocked&&!t.captured;this.shellLocked=t.captured,this.stopSteering(),this.updateCursor(),i&&this.pause()}else this.shellLocked&&(this.turn(t.dx,t.dy),this.mouseButtons(t.buttons))}))}stopSteering(){this.steerOrigin=null,this.steerRate=0}turn(e,t){this.yaw+=e*.004*Ce.sensitivity,this.pitch=G(this.pitch-t*.0035*Ce.sensitivity,-1.36,1.36)}clearPad(){this.padMove=[0,0],this.padHeld=this.padPressed=0,this.padCrouch=this.padSwap=!1}gamepad(e,t,i,a,c,r,o){this.active&&(this.padMove=[e,t],this.yaw+=i*c*3.2*Ce.sensitivity,this.pitch=G(this.pitch-a*c*2.4*Ce.sensitivity,-1.36,1.36),this.toggleCrouch()?o&2&&(this.padCrouch=!this.padCrouch):this.padCrouch=!!(r&2),this.padHeld=this.padCrouch?X:0,o&8&&(this.padSwap=!0),Ri.forEach((n,l)=>{r&1<<l&&(this.padHeld|=n),o&1<<l&&(this.padPressed|=n)}))}clear(){var e;this.stopSteering(),this.clearPad(),this.swap=!1,this.mouse=this.presses=this.toggles=0,this.keys.clear(),this.touches.clear(),this.stick=[0,0],this.drag=-1,(e=document.querySelector("#stick i"))==null||e.removeAttribute("style"),document.querySelectorAll('[aria-pressed="true"][data-action]').forEach(t=>t.setAttribute("aria-pressed","false"))}sync(e){this.yaw=e.yaw,this.pitch=e.pitch,this.clear()}input(e,t,i){const a=r=>Number(this.active&&this.keys.has(r));this.yaw+=((a("ArrowRight")-a("ArrowLeft"))*.038+this.steerRate*.07)*Ce.sensitivity,this.yaw=Math.atan2(Math.sin(this.yaw),Math.cos(this.yaw)),this.pitch=G(this.pitch+(a("ArrowUp")-a("ArrowDown"))*.029,-1.36,1.36);let c=this.presses|this.mouse|this.toggles|this.padHeld|this.padPressed;this.padPressed=0,(this.swap||this.padSwap)&&(this.padSwap=!1,c|=t.gun<t.holster?Mt:xt,this.swap=!1),this.presses=0;for(const r of this.keys)c|=rs[r]??0;for(const r of this.touches.values())c|=r;return[e,G(a("KeyW")-a("KeyS")+this.stick[1]+this.padMove[1],-1,1),G(a("KeyD")-a("KeyA")+this.stick[0]+this.padMove[0],-1,1),this.yaw,this.pitch,this.active?c:0,t.life,i]}updateCursor(){this.canvas.dataset.mouseLook=this.active?this.locked||this.shellLocked?"locked":"free":"off"}start(){var e;this.active=!0,this.canvas.focus({preventScroll:!0}),this.updateCursor(),!document.body.classList.contains("pad-mode")&&(cs()||((e=navigator.userActivation)==null?void 0:e.isActive)!==!1)&&this.lock()}stop(){var e;this.active=!1,(e=this.shellCapture)==null||e.close(),this.shellCapture=void 0,this.shellLocked=!1,this.clear(),this.updateCursor(),document.pointerLockElement===this.canvas&&(this.locked=!1,document.exitPointerLock())}lock(){const e=cs();if(this.active&&e&&matchMedia("(any-pointer:fine)").matches){this.offerShellMouse(e);return}if(!(!this.active||this.locked||this.lockPending||this.denied||!matchMedia("(any-pointer:fine)").matches||!this.canvas.requestPointerLock)){this.lockPending=!0;try{const t=this.canvas.requestPointerLock();t&&t.catch(i=>{this.lockPending=!1,i instanceof DOMException&&i.name==="SecurityError"&&/sandbox/i.test(i.message)&&(this.denied=!0),this.updateCursor()})}catch{this.lockPending=!1,this.updateCursor()}}}}const Pi="naddr1qvzqqqyf8ypzqw49s9e88sajl985jxzquprj7pyapugqp83rme3sqctxhj5mxm4rqqxkutfk8yenyc33xf3nwwrr9sgj7x",Ti={pubkey:"60517f64548279854ee9a122531e4d1a413e3dc956e2d0a450217420623ca688",relays:["wss://relay.napplet.soy/"]},We={napplet:Pi,provider:Ti},Fe="faultline-arena-v4";function Ss(s,e,t){if(!s||typeof s!="object")return null;const i=s;return i.version===1&&i.provider===e&&i.napplet===t&&i.protocol===Fe&&typeof i.room=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(i.room)?{version:1,provider:e,napplet:t,protocol:Fe,room:i.room}:null}function Ni(s){return!_e(s)||typeof s.provider!="string"||!/^[a-f0-9]{64}$/.test(s.provider)?null:Ss(s,s.provider,We.napplet)}const Ot=s=>s.name.slice(65),Ie=s=>s.name[64]===":",Cs=s=>s.peers.length-Number(Ie(s)),zs=s=>s.capacity-Number(Ie(s)),He=s=>s.name.slice(0,64);function _e(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}function It(s){return _e(s)&&typeof s.room=="string"&&s.protocol===Fe&&typeof s.name=="string"&&/^[a-f0-9]{64}[|:].{1,15}$/u.test(s.name)&&Array.isArray(s.peers)&&s.peers.length<=8&&new Set(s.peers).size===s.peers.length&&s.peers.every(e=>typeof e=="string"&&/^[a-f0-9]{64}$/.test(e))&&typeof s.capacity=="number"&&Number.isInteger(s.capacity)&&s.capacity>=2&&s.capacity<=8&&s.peers.length<=s.capacity}async function Se(s,e={}){var i,a;const t=await ti.callTool(We.provider,s,e);if(t.isError)throw new Error(((a=(i=t.content)==null?void 0:i.find(c=>c.type==="text"))==null?void 0:a.text)??"Room service declined the request");if(!_e(t.structuredContent))throw new Error("Room service returned an incomplete response");return t.structuredContent}class Fi{constructor(e,t,i){m(this,"actor","");m(this,"room",null);m(this,"connected",new Set);m(this,"fast",new Set);m(this,"notice","");m(this,"rtt",0);m(this,"ctl","");m(this,"state","");m(this,"allow","");m(this,"generation",0);m(this,"timer",0);m(this,"polling",!1);m(this,"opening",!1);m(this,"needsRetry",!1);m(this,"subscription");m(this,"transientInputs",!1);m(this,"pendingState");m(this,"sendingState",!1);m(this,"connectSince",0);m(this,"pingTime",0);m(this,"probe",0);m(this,"replies",new Set);m(this,"measured",new Map);m(this,"dead",!1);m(this,"lastSeen",0);this.changed=e,this.receive=t,this.ended=i}pingFor(e){const t=this.measured.get(e);if(t&&this.connected.has(e)&&performance.now()-t.at<1e4)return t.ms}get host(){return!!this.room&&this.actor===He(this.room)}get owner(){return this.room?He(this.room):""}get fastReady(){return this.connected.size>0&&[...this.connected].every(e=>this.fast.has(e))}async list(){const e=await Se("soy_room_list",{napplet:We.napplet,protocol:Fe});return(Array.isArray(e.rooms)?e.rooms:[]).filter(It).filter(t=>t.peers.includes(He(t)))}async advertise(e){if(!this.host||!this.room)throw new Error("Only the host can list a room");await Se("soy_room_advertise",{room:this.room.room,listing:e})}async enter(e,t,i,a=!1,c=!0){const r=await Se("soy_session");if(typeof r.actor!="string"||!/^[a-f0-9]{64}$/.test(r.actor))throw new Error("No transport identity available");if(i&&(r.provider!==i.provider||!Ss(i,i.provider,We.napplet)))throw new Error("This link belongs to another room service or game.");this.actor=r.actor,this.dead=!1,this.needsRetry=!1;const o=i?await Se("soy_room_enter",i):e?await Se("soy_room_join",{room:e}):await Se("soy_room_create",{napplet:We.napplet,protocol:Fe,name:this.actor+(a?":":"|")+t.trim().slice(0,15),capacity:8,listed:c});if(!It(o)||!o.peers.includes(this.actor)||!o.peers.includes(He(o)))throw(e||i)&&await Se("soy_room_leave",{room:e??i.room}),new Error("This is not an active Faultline room.");this.room=o,this.notice="",this.lastSeen=performance.now(),this.changed(),this.subscription||(this.subscription=Ne.onEvent(n=>{var h,p;if(n.sessionId!==this.ctl&&n.sessionId!==this.state)return;const l=n.sessionId===this.state;if(n.type==="peer"){if(!((h=this.room)!=null&&h.peers.includes(n.pubkey)))return;const u=l?this.fast:this.connected;n.state==="joined"?u.add(n.pubkey):(u.delete(n.pubkey),l||(this.measured.delete(n.pubkey),this.replies.delete(n.pubkey),n.pubkey===this.owner&&(this.rtt=0))),!l&&n.state==="joined"&&(this.notice="",this.lastSeen=performance.now()),this.changed()}else if(n.type==="message"&&_e(n.payload)&&((p=this.room)!=null&&p.peers.includes(n.from))&&(this.host||n.from===this.owner)){if(l&&n.payload.t!==(this.host?"input":"state"))return;if(n.payload.t==="probe"&&!this.host&&typeof n.payload.n=="number"&&Number.isFinite(n.payload.n)){this.send({t:"echo",n:n.payload.n});return}if(n.payload.t==="echo"&&this.host){if(this.probe&&n.payload.n===this.probe&&this.replies.delete(n.from)){const u=performance.now();u-this.probe<=1e4&&this.measured.set(n.from,{ms:Math.round(u-this.probe),at:u})}return}if(n.payload.t==="ping"&&this.host&&typeof n.payload.n=="number"&&Number.isFinite(n.payload.n)){this.send({t:"pong",to:n.from,n:n.payload.n});return}if(n.payload.t==="pong"&&n.payload.to===this.actor&&n.payload.n===this.pingTime){this.rtt=Math.round(performance.now()-this.pingTime);return}this.receive(n.from,n.payload)}else n.type==="closed"&&(l?(this.state="",this.fast.clear()):(this.ctl="",this.connected.clear(),this.allow="",this.notice=n.reason||"Peer connection closed"),this.changed())}));try{await this.transport()}catch(n){this.notice=String(n),this.changed()}this.timer=window.setInterval(()=>void this.poll(),2600)}async transport(){const e=this.room;if(!e||this.opening||this.needsRetry)return;const t=this.host?e.peers.filter(c=>c!==this.actor):[this.owner],i=t.join(",");if(this.allow===i&&(!i||this.ctl))return;this.opening=!0;const a=this.generation;try{if(await this.closeChannels(),!t.length||a!==this.generation){this.allow="";return}const c={type:"room",room:e.room,peers:t},r=async o=>{const n={scope:c,protocol:Fe,channel:o?"frames":"match",...o?{ordered:!1,maxRetransmits:0}:{}},{session:l}=await Ne.open(n),h=l;if(a!==this.generation||o&&(h.ordered!==!1||h.maxRetransmits!==0)){await Ne.close(l.id,"Unused channel");return}o?this.state=l.id:this.ctl=l.id};try{await r(!1)}catch(o){throw a===this.generation&&(this.needsRetry=!0),o}if(a!==this.generation)return;this.allow=i,this.connectSince=performance.now(),this.notice="";try{await r(!0)}catch{}}finally{this.opening=!1,this.changed()}}async poll(){const e=this.room,t=this.generation;if(!(!e||this.polling)){this.polling=!0;try{const i=await Se("soy_room_status",{room:e.room});if(t!==this.generation)return;if(!It(i)||!i.peers.includes(He(i)))throw new Error("The host left this room");this.room=i,this.lastSeen=performance.now(),await this.transport(),this.ctl&&i.peers.length>1&&this.connected.size===0&&performance.now()-this.connectSince>12e3&&(this.notice="Peer connection timed out. Retry or check the host network settings."),this.host&&this.connected.size?(this.probe=performance.now(),this.replies=new Set(this.connected),this.send({t:"probe",n:this.probe})):this.connected.size&&(this.pingTime=performance.now(),this.send({t:"ping",n:this.pingTime})),this.changed()}catch(i){if(t!==this.generation)return;const a=i instanceof Error?i.message:String(i);/expired|host left|join this room/i.test(a)||performance.now()-this.lastSeen>59e3?(this.leave(),this.ended(a)):(this.notice=a,this.changed())}finally{this.polling=!1}}}retry(){return this.needsRetry=!1,this.allow="",this.transport()}send(e){!this.ctl||!this.connected.size||Ne.send(this.ctl,e).catch(t=>{this.room&&(this.notice=String(t),this.changed())})}async snapshot(e){if(this.connected.size&&(this.pendingState=e,!this.sendingState)){this.sendingState=!0;try{for(;this.pendingState&&this.ctl;){const t=this.pendingState;this.pendingState=void 0,await Ne.send(this.fastReady?this.state:this.ctl,t)}}catch{}finally{this.sendingState=!1}}}async closeChannels(){const e=[this.ctl,this.state].filter(Boolean);this.transientInputs=!1,this.ctl=this.state="",this.connected.clear(),this.fast.clear(),this.replies.clear(),this.measured.clear(),this.probe=this.rtt=0,this.pendingState=void 0,await Promise.allSettled(e.map(t=>Ne.close(t,"Room membership changed")))}async leave(){var t;const e=this.room;this.generation++,this.room=null,this.dead=!0,clearInterval(this.timer),this.allow="",this.rtt=0,this.notice="",(t=this.subscription)==null||t.close(),this.subscription=void 0,await Promise.allSettled([this.closeChannels(),...e?[Se("soy_room_leave",{room:e.room})]:[]]),this.dead&&this.changed()}}function Di(s,e,t,i){const a=Math.max(0,Math.min(e,e-5+t*.06));if(s===0||a-s>18)return Math.max(s,a);const c=Math.min(1.15,Math.max(.85,1+(a-s)/24));return Math.min(e,s+Math.max(0,i)*.06*c)}function qi(s,e,t,i){var c;if(e[0]<=(((c=s.at(-1))==null?void 0:c[0])??t)||(s.push(e),s.length<=9))return;const a=s.findIndex((r,o)=>o<s.length-1&&r[5]===(o?s[o-1][5]:i)&&r[5]===s[o+1][5]);s.splice(a<0?0:a,1)}const Q=(s,e)=>[s[0]+e[0],s[1]+e[1],s[2]+e[2]],ct=(s,e)=>[s[0]-e[0],s[1]-e[1],s[2]-e[2]],K=(s,e)=>[s[0]*e,s[1]*e,s[2]*e],ye=(s,e)=>[s[1]*e[2]-s[2]*e[1],s[2]*e[0]-s[0]*e[2],s[0]*e[1]-s[1]*e[0]],le=s=>K(s,1/(Math.hypot(...s)||1)),Ye=[1,0,0],yt=[0,1,0],Dt=[0,0,1],Bi=[[0,4,6,2,.72],[1,3,7,5,.86],[0,1,5,4,.48],[2,6,7,3,1.08],[0,2,3,1,.9],[4,5,7,6,.68]];class lt{constructor(){m(this,"storage",new Float32Array(8192));m(this,"count",0);m(this,"corners",new Float32Array(24))}get data(){return this.storage.subarray(0,this.count)}clear(){this.count=0}reserve(e){if(this.count+e<=this.storage.length)return;const t=new Float32Array(Math.max(this.count+e,this.storage.length*2));t.set(this.storage),this.storage=t}triangle(e,t,i,a,c=1){const r=parseInt(a.slice(1),16),o=[r>>16,r>>8&255,r&255].map(n=>n*c/255);this.reserve(18);for(const n of[e,t,i])this.storage.set(n,this.count),this.storage.set(o,this.count+3),this.count+=6}flare(e,t,i,a){const c=[e[0],e[1],e[2]+i],r=o=>{const n=o*Math.PI/6+a,l=t*(o%2?.34:1);return[e[0]+Math.cos(n)*l,e[1]+Math.sin(n)*l,e[2]+i*.18]};this.reserve(432);for(let o=0;o<12;o++){const n=r(o),l=r(o+1);for(const[h,p]of[[e,[1,.98,.78]],[l,[1,.67,.22]],[n,[1,.76,.37]],[n,[1,.76,.37]],[l,[1,.67,.22]],[c,[1,.94,.6]]])this.storage.set(h,this.count),this.storage.set(p,this.count+3),this.count+=6}}box(e,t,i,a,c,r=[Ye,yt,Dt]){const o=parseInt(c.slice(1),16),n=(o>>16)/255,l=(o>>8&255)/255,h=(o&255)/255;this.reserve(216);const p=this.corners,u=this.storage;for(let f=0;f<8;f++){const b=t*(f&1?.5:-.5),d=i*(f&2?.5:-.5),g=a*(f&4?.5:-.5);for(let y=0;y<3;y++)p[f*3+y]=e[y]+r[0][y]*b+r[1][y]*d+r[2][y]*g}for(const[f,b,d,g,y]of Bi){const k=n*y,S=l*y,M=h*y;for(const z of[f,b,d,f,d,g]){const w=z*3;u[this.count++]=p[w],u[this.count++]=p[w+1],u[this.count++]=p[w+2],u[this.count++]=k,u[this.count++]=S,u[this.count++]=M}}}beam(e,t,i,a,c){const r=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],o=le(r),n=le(ye(Math.abs(o[1])>.94?Dt:yt,o));this.box(K(Q(e,t),.5),i,a,Math.hypot(...r),c,[n,ye(o,n),o])}body(e,t,i=!1){const a=i?t%2?"#587eaa":"#cb924c":t%2?"#626f60":"#6a7176",c="#424d47",r="#383d38";for(const[b,[d,g]]of xs.entries()){if(b<2)continue;const y=b>=8?.14:.115;this.beam(e[d],e[g],y,y,b>=8?c:a)}const o=le(ct(e[6],e[3])),n=le(ct(e[1],e[0])),l=le(ye(o,n)),h=[o,le(ye(l,o)),l],p=K(Q(e[0],e[1]),.5);this.box(p,.4,.48,.25,a,h),this.box(Q(p,K(l,.095)),.34,.31,.13,c,h),this.box(Q(e[0],K(n,-.045)),.33,.18,.23,c,h),this.beam(e[1],e[2],.13,.13,"#968974");const u=le(ct(e[2],e[1])),f=[o,u,le(ye(o,u))];this.box(e[2],.26,.26,.25,"#aa9982",f),this.box(Q(e[2],K(u,.075)),.3,.16,.29,c,f),this.box(Q(e[2],K(f[2],.13)),.23,.057,.035,"#414b48",f);for(const b of[11,14]){const d=le(ct(e[b-1],e[b])),g=le(ye(o,d));this.box(Q(e[b],K(g,.04)),.16,.14,.28,r,[o,d,g])}this.beam(e[3],e[6],.17,.17,a)}}function Oi(s){const e=s.createProgram();for(const[t,i]of[[s.VERTEX_SHADER,`
  attribute vec3 p;attribute vec3 c;uniform vec3 o,r,u,f;uniform vec2 lens;
  varying vec3 col;varying vec3 pos;varying float depth;
  void main(){vec3 d=p-o;float z=dot(d,f);gl_Position=vec4(dot(d,r)*lens.x,dot(d,u)*lens.y,z*1.00045-.065,z);col=c;pos=p;depth=z;}`],[s.FRAGMENT_SHADER,`precision mediump float;uniform float opacity;varying vec3 col;varying vec3 pos;varying float depth;
    void main(){vec3 cell=floor(pos*5.);float n=fract(dot(mod(cell,32.),vec3(.381,.517,.723)));
    float grit=(n-.5)*.028;gl_FragColor=vec4(mix(col+grit,vec3(.70,.72,.66),clamp((depth-14.)*.008,0.,.55)),opacity);}`]]){const a=s.createShader(t);if(s.shaderSource(a,i),s.compileShader(a),!s.getShaderParameter(a,s.COMPILE_STATUS))throw new Error(s.getShaderInfoLog(a)??"Shader unavailable");s.attachShader(e,a),s.deleteShader(a)}if(s.linkProgram(e),!s.getProgramParameter(e,s.LINK_STATUS))throw new Error("Unable to link arena shader");return e}class _i{constructor(e){m(this,"actors",new lt);m(this,"viewModel",new lt);m(this,"autoScale",1);m(this,"requestedScale",1);m(this,"sampleTime",0);m(this,"sampleCount",0);m(this,"gl");m(this,"flat",null);m(this,"program");m(this,"fixed");m(this,"dynamic");m(this,"glazing",new Float32Array);m(this,"staticData",new Float32Array);m(this,"level");m(this,"uniforms",{});m(this,"p",0);m(this,"c",0);m(this,"width",0);m(this,"height",0);m(this,"geometry");m(this,"overhead",!1);this.canvas=e,this.gl=e.getContext("webgl",{alpha:!0,antialias:!1,depth:!0,powerPreference:"high-performance"}),this.gl?this.setup():this.flat=e.getContext("2d",{alpha:!0}),e.addEventListener("webglcontextlost",t=>t.preventDefault()),e.addEventListener("webglcontextrestored",()=>{this.level=void 0,this.setup()})}setup(){const e=this.gl;this.program=Oi(e),e.useProgram(this.program),this.fixed=e.createBuffer(),this.dynamic=e.createBuffer(),this.p=e.getAttribLocation(this.program,"p"),this.c=e.getAttribLocation(this.program,"c");for(const t of["o","r","u","f","lens","opacity"])this.uniforms[t]=e.getUniformLocation(this.program,t);e.enable(e.DEPTH_TEST),e.enable(e.CULL_FACE),e.frontFace(e.CW),e.enableVertexAttribArray(this.p),e.enableVertexAttribArray(this.c),e.clearColor(0,0,0,0)}resize(e,t,i){var o;this.width=e,this.height=t,this.requestedScale=i;const a=Math.min(1.5,devicePixelRatio)*i*this.autoScale,c=Math.max(1,Math.round(e*a)),r=Math.max(1,Math.round(t*a));(this.canvas.width!==c||this.canvas.height!==r)&&(this.canvas.width=c,this.canvas.height=r,(o=this.gl)==null||o.viewport(0,0,c,r))}build(e,t){this.overhead=t;const i=new lt,a=new lt;this.geometry=e.boxes;const c=e.terrain;if(c){const o=(n,l)=>[n*c.spacing-c.extent,c.heights[l*c.side+n],l*c.spacing-c.extent];for(let n=0;n<c.side-1;n++)for(let l=0;l<c.side-1;l++){const h=o(l,n),p=o(l+1,n),u=o(l,n+1),f=o(l+1,n+1),d=Math.abs(h[0]-9*Math.sin(h[2]*.066))<3||Math.abs(h[2]+7*Math.sin(h[0]*.075))<3?"#a49a74":h[1]>5?"#919872":"#77835f";i.triangle(h,u,p,d,.98+(p[1]-h[1])*.048),i.triangle(p,u,f,d,.97+(f[1]-u[1])*.048)}}for(const o of e.boxes)if(!(o.boundary||t&&o.roof))if(o.pane){a.box([o.x,o.y+o.h/2,o.z],o.w,o.h,o.d,o.color);for(const n of[-1,1])i.box([o.x,o.y+(n>0?o.h-.1:.12),o.z],o.w,.09,o.d,"#a9cbca");for(const n of[-.27,0,.27])i.beam([o.x+o.w*n-.24,o.y+.45,o.z],[o.x+o.w*n+.38,o.y+o.h-.35,o.z],.045,.04,"#b9d2cf")}else if(o.shape){const n=(l,h,p)=>[o.x+Math.cos(l*Math.PI/3)*o.w*.5*p,h,o.z+Math.sin(l*Math.PI/3)*o.d*.5*p];for(let l=0;l<6;l++){const h=n(l,o.y,1),p=n(l+1,o.y,1),u=.76+.22*Math.cos(l);if(o.shape==="pine")i.triangle(h,[o.x,o.y+o.h,o.z],p,o.color,u);else{const f=n(l,o.y+o.h*.73,.82),b=n(l+1,o.y+o.h*.73,.82);i.triangle(h,f,p,o.color,u),i.triangle(p,f,b,o.color,u),i.triangle(f,[o.x+o.w*.08,o.y+o.h,o.z],b,o.color,1.1)}}}else i.box([o.x,o.y+o.h/2,o.z],o.w,o.h,o.d,o.color);for(let o=0;!c&&o<26;o++){const n=o*2.399,l=40+o%4*3,h=3+o*11%9;i.box([Math.sin(n)*l,h/2-.8,Math.cos(n)*l],4+o%8,h,5+o%5,"#858f84"),o%5===0&&i.box([Math.sin(n)*l,h+2,Math.cos(n)*l],.85,6,.85,"#7c8178")}for(const o of e.boxes)if(!(c||o.pane||!o.solid||o.y!==0||o.h<1||o.w>35||o.d>35)&&(i.box([o.x+.26,.014,o.z+.39],o.w+.25,.012,o.d+.4,"#767867"),o.w>4&&o.h>2.5))for(const n of[-1,1])i.box([o.x-o.w*.28,o.h*.57,o.z+n*(o.d*.5+.025)],.9,.14,.044,"#d2c7a6");this.glazing=new Float32Array(a.data),this.staticData=new Float32Array(i.data),this.level=e;const r=this.gl;r&&(r.bindBuffer(r.ARRAY_BUFFER,this.fixed),r.bufferData(r.ARRAY_BUFFER,this.staticData,r.STATIC_DRAW))}draw(e,t,i=!1,a=1){const c=this.gl;c&&(c.uniform1f(this.uniforms.opacity,a),c.uniform3fv(this.uniforms.o,e.o),c.uniform3fv(this.uniforms.r,e.r),c.uniform3fv(this.uniforms.u,e.u),c.uniform3fv(this.uniforms.f,e.f),c.uniform2f(this.uniforms.lens,e.scale/e.aspect,e.scale),c.bindBuffer(c.ARRAY_BUFFER,i?this.fixed:this.dynamic),i||c.bufferData(c.ARRAY_BUFFER,t,c.STREAM_DRAW),c.vertexAttribPointer(this.p,3,c.FLOAT,!1,24,0),c.vertexAttribPointer(this.c,3,c.FLOAT,!1,24,12),c.drawArrays(c.TRIANGLES,0,t.length/6))}software(e,t){const i=this.flat;if(!i)return;const a=this.canvas.width,c=this.canvas.height,r=c*e.scale*.5,o=[];for(const n of t)for(let l=0;l<n.length;l+=18){let h=[];for(let u=l;u<l+18;u+=6){const f=n[u]-e.o[0],b=n[u+1]-e.o[1],d=n[u+2]-e.o[2];h.push([f*e.r[0]+b*e.r[1]+d*e.r[2],f*e.u[0]+b*e.u[1]+d*e.u[2],f*e.f[0]+b*e.f[1]+d*e.f[2]])}if(h.every(u=>u[2]<.06))continue;if(h.some(u=>u[2]<.06)){const u=[];for(let f=0;f<3;f++){const b=h[f],d=h[(f+1)%3];if(b[2]>=.06&&u.push(b),b[2]>=.06!=d[2]>=.06){const g=(.06-b[2])/(d[2]-b[2]);u.push([b[0]+(d[0]-b[0])*g,b[1]+(d[1]-b[1])*g,.06])}}h=u}const p=h.map(u=>[a/2+u[0]*r/u[2],c/2-u[1]*r/u[2]]);p.every(u=>u[0]<0)||p.every(u=>u[0]>a)||p.every(u=>u[1]<0)||p.every(u=>u[1]>c)||o.push({pts:p,depth:h.reduce((u,f)=>u+f[2],0)/h.length,color:"rgba("+[3,4,5].map(u=>Math.round(n[l+u]*255)).join(",")+(n===this.glazing?",.12)":",1)")})}o.sort((n,l)=>l.depth-n.depth);for(const n of o)i.beginPath(),n.pts.forEach(([l,h],p)=>p?i.lineTo(l,h):i.moveTo(l,h)),i.closePath(),i.fillStyle=n.color,i.fill()}render(e,t,i,a,c,r,o,n=!1){var ce;if((this.level!==e||this.geometry!==e.boxes||this.overhead!==!t)&&this.build(e,!t),this.sampleTime||(this.sampleTime=r),++this.sampleCount>=24){const v=(r-this.sampleTime)/this.sampleCount,L=v>21?Math.max(.5,this.autoScale-.12):v<17.2?Math.min(1,this.autoScale+.035):this.autoScale;L!==this.autoScale&&(this.autoScale=L,this.resize(this.width,this.height,this.requestedScale)),this.sampleTime=r,this.sampleCount=0}const l=this.actors;l.clear();const h=this.canvas.width/this.canvas.height,p=!!t&&!!(t.buttons&ke)&&t.hp>0;let u=0,f;if(t){const v=Math.hypot(t.vx,t.vz);u=o?0:Math.sin(r*.012)*Math.min(.027,v*.006);const L=t.pitch+(o?0:c.kick*.65+c.shake*Math.sin(r*.12)*.12),F=[Math.cos(t.yaw),0,-Math.sin(t.yaw)],B=[Math.sin(t.yaw)*Math.cos(L),Math.sin(L),Math.cos(t.yaw)*Math.cos(L)],N=Tt(t),P=ye(B,F),O=o?0:t.lean*.0013;N[1]=t.y+(t.hp>0?qe(t)+u:.48),f={o:N,r:Q(K(F,Math.cos(O)),K(P,-Math.sin(O))),u:Q(K(P,Math.cos(O)),K(F,Math.sin(O))),f:B,aspect:h,scale:(p?H[t.gun].zoom:1)*1.32}}else{const v=[0,-.96,.28],L=Math.min(1.32,1.32*h),F=e.size*(.31+1.06*Math.max(L/h,L));f={o:K(v,-F),r:Ye,u:ye(v,Ye),f:v,aspect:h,scale:L}}const b=(v,L)=>{if(!t)return!0;const F=v-t.x,B=L-t.z,N=F*f.f[0]+B*f.f[2];return N>=-1.4&&Math.abs(F*f.r[0]+B*f.r[2])<3+Math.max(0,N)*f.aspect/f.scale*1.45};for(const v of i){if(v.id===(t==null?void 0:t.id)||!v.hp||!b(v.x,v.z))continue;const L=Math.hypot(v.vx,v.vz)>.3,F=Ms(v.x,v.y,v.z,v.yaw,L?r*.012+v.id:0,!!(v.buttons&X),v.pitch);for(let O=0;O<9;O++){const ie=(O===0?.12:O===2?1:.55)*v.lean*Pe/100;F[O][0]+=Math.cos(v.yaw)*ie,F[O][2]-=Math.sin(v.yaw)*ie}l.body(F,v.id,n);const B=Ve(v.yaw,v.pitch),N=v.gun===Ke?.78:de(v.gun)?.3:.66,P=Q(F[8],K(B,N));l.beam(F[8],P,v.gun===Ke?.18:.09,.11,"#393e3b"),c.muzzles.has(v.id)&&l.beam(P,Q(P,K(B,.21)),.12,.1,"#ffce6d"),l.box([v.x,v.y+.016,v.z],.68,.02,.5,"#747662")}for(const v of c.bodies)b(v.j[0].p[0],v.j[0].p[2])&&l.body(v.j.map(L=>L.p),v.team,n);for(const v of c.blasts){const L=v.age/E.feel.duration,F=.18+E.feel.ringRadius*Math.sqrt(L),B=v.o[1]+.06;if(v.age<E.feel.coreDuration){const N=E.feel.coreRadius*(1-v.age/E.feel.coreDuration);l.box(v.o,N*.76,N,N*.72,"#fff0ba");for(let P=0;P<5;P++){const O=P*Math.PI*2/5+v.o[0],ie=N*.8,Z=[v.o[0]+Math.cos(O)*ie,v.o[1]+N*(.12+P%2*.22),v.o[2]+Math.sin(O)*ie];l.beam(v.o,Z,N*.37,N*.26,"#ffc16a")}}for(let N=0;N<16;N++){const P=N*Math.PI/8,O=P+.3;l.beam([v.o[0]+Math.cos(P)*F,B,v.o[2]+Math.sin(P)*F],[v.o[0]+Math.cos(O)*F,B,v.o[2]+Math.sin(O)*F],.065*(1-L)+.015,.045,L<.4?"#fbc784":"#c5b69a")}}for(const v of a)l.box([v.x,v.y,v.z],v.rocket?.28:.22,v.rocket?.18:.27,.22,v.rocket?"#edab54":"#57613c");for(const v of c.sparks){const L=v.size*(.5+v.t/v.total);l.box(v.p,L,L,L,v.color)}for(const v of c.marks){if(!b(v.o[0],v.o[2]))continue;const L=v.n,F=le(ye(Math.abs(L[1])>.9?Ye:yt,L)),B=ye(L,F),N=[F,B,L],P=Q(v.o,K(L,.035)),ie=v.size>.1?8:1;for(let Z=0;Z<ie;Z++){const Me=v.seed+Z*2.4,Wt=Z?v.size*(.38+Z*.15):0,Jt=v.size*(Z?.27:1),Bs=Q(Q(P,K(F,Math.cos(Me)*Wt)),K(B,Math.sin(Me)*Wt));l.box(Bs,Jt*1.3,Jt,.008,v.color,N)}}(ce=this.gl)==null||ce.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT),this.flat&&this.flat.clearRect(0,0,this.canvas.width,this.canvas.height);const d=l.data;if(this.gl){if(this.draw(f,this.staticData,!0),this.draw(f,d),this.glazing.length){const v=this.gl;v.enable(v.BLEND),v.blendFunc(v.SRC_ALPHA,v.ONE_MINUS_SRC_ALPHA),v.depthMask(!1),this.draw(f,this.glazing,!1,.23),v.depthMask(!0),v.disable(v.BLEND)}}else this.software(f,[this.staticData,d,this.glazing]);if(!t)return f;if(!t.hp)return;const g=this.viewModel;g.clear();const y=H[t.gun],k=t.reload>0?Math.sin(Math.PI*t.reload/y.reload):0,S=p?0:Math.min(.22,f.aspect*.17),M=(p?-.104:-.205)-k*.17+u*.4,z=.56-c.kick*.7,w=(v,L,F,B,N,P,O)=>g.box([S+v,M+L,z+F],B,N,P,O),R=t.gun===2?"#947254":t.gun===4?"#6f715a":"#55605b",T=t.gun===1?.22:t.gun===3?.5:.34;if(t.gun===Ke)w(0,0,.12,.17,.16,.78,"#586447"),w(0,.014,.51,.2,.19,.06,"#323e35"),w(0,.102,.02,.055,.055,.05,"#4b5041"),w(.06,-.09,-.05,.12,.12,.22,"#71735d");else if(de(t.gun))w(0,.02,.02,.075,.08,.26,t.gun===5?"#57625b":"#838578"),w(0,-.072,-.058,.075,.15,.1,"#424b43"),w(.047,-.083,-.11,.094,.105,.17,"#6d735e"),w(0,.075,.125,.016,.025,.02,"#414941");else{w(0,0,0,.103,.109,.36,"#363e3c"),w(0,.044,.04,.112,.04,.31,R),w(0,.005,.21,.096,.088,.23,R),w(0,.021,.38,.034,.034,T,"#424a48"),w(0,.022,.36+T/2,.05,.049,.1,"#363b39"),w(0,-.09,.03,.057,.17,.09,"#535b52");for(let v=0;v<7;v++)w(0,.065,.08+v*.034,.106,.014,.014,"#343c38");w(0,.082,-.025,.074,.018,.054,"#404944");for(const v of[-1,1])w(v*.029,.105,-.025,.014,.046,.038,"#373d39");w(0,.127,-.025,.07,.013,.04,"#4e5a50"),w(0,.077,.32,.012,.063,.018,"#414941"),w(.068,-.074,-.08,.105,.104,.19,"#6e7360"),w(-.053,-.067,.17,.093,.1,.13,"#777a62")}if(c.flash>0){const v=c.flash/.075;g.flare([S,M+.022,z+(t.gun===Ke?.54:de(t.gun)?.16:.42+T/2)],(.032+.049*v)*(t.gun===2?1.4:1),.12+.19*v,c.shotCount*1.7)}const V={o:[0,0,0],r:Ye,u:yt,f:Dt,aspect:f.aspect,scale:1.42},se=g.data;this.gl?(this.gl.clear(this.gl.DEPTH_BUFFER_BIT),this.draw(V,se)):this.software(V,[se])}}class Ui{constructor(){m(this,"markers",document.getElementById("server-markers"))}draw(e,t,i,a){const c=t.filter(r=>r.hp>0);for(const r of Array.from(this.markers.children))c.some(o=>r.id==="server-seat-"+o.id)||r.remove();for(const r of c){const o="server-seat-"+r.id;let n=document.getElementById(o);n||(n=document.createElement("span"),n.id=o,this.markers.append(n)),n.className=a&&r.id%2?"server-marker slate":"server-marker";const l=i(r.id);n.textContent!==l&&(n.textContent=l);const h=r.x-e.o[0],p=r.y+2-e.o[1],u=r.z-e.o[2],f=d=>h*d[0]+p*d[1]+u*d[2],b=f(e.f);n.hidden=b<=0,b>0&&(n.style.left=50+50*e.scale*f(e.r)/(b*e.aspect)+"%",n.style.top=50-50*e.scale*f(e.u)/b+"%")}}}const _t=["x","y","z","vx","vy","vz","yaw","pitch"],Ut=["id","hp","gun","ammo","cool","reload","frags","kills","deaths","respawn","buttons","ground","protect","holster","spareAmmo","cook","boost","lean"],dt=_t.length*2+Ut.length+6;function ji(s){const e=[...s],t=new Uint8Array(e.length*dt),i=new DataView(t.buffer);let a=0;for(const c of e){for(const r of _t)i.setInt16(a,Math.round(c[r]*(r==="yaw"||r==="pitch"?1e4:100)),!0),a+=2;for(const r of Ut)t[a++]=c[r];i.setUint16(a,c.life,!0),a+=2,i.setUint32(a,c.ack,!0),a+=4}return btoa(String.fromCharCode(...t))}function Hi(s,e=24){if(typeof s!="string"||!s.length||s.length>Math.ceil(8*dt/3)*4)return null;let t;try{t=atob(s)}catch{return null}if(!t.length||t.length%dt||t.length>dt*8)return null;const i=Uint8Array.from(t,n=>n.charCodeAt(0)),a=new DataView(i.buffer),c=[],r=new Set;let o=0;for(;o<i.length;){const n={};for(const l of _t)n[l]=a.getInt16(o,!0)/(l==="yaw"||l==="pitch"?1e4:100),o+=2;for(const l of Ut)n[l]=i[o++];if(n.lean>127&&(n.lean-=256),n.life=a.getUint16(o,!0),o+=2,n.ack=a.getUint32(o,!0),o+=4,n.id>7||r.has(n.id)||!H[n.gun]||!H[n.holster]||J(n.gun)===J(n.holster)||n.spareAmmo>H[n.holster].mag||Math.abs(n.lean)>100||n.hp>100||n.cook>E.grenade.fuse||n.boost>E.hit.speedTicks||!n.life||n.ammo>H[n.gun].mag||n.buttons>=128||Math.abs(n.x)>e+2||Math.abs(n.z)>e+2||n.y<-.02||n.y>26||Math.abs(n.pitch)>1.39||Math.abs(n.yaw)>Math.PI+.001)return null;r.add(n.id),c.push(n)}return c}const ot=["Rook","Flint","Mica","Sable","Wren","Slate","Pike","Ash"],ls=s=>Array.isArray(s)&&s.length===3&&s.every(e=>Number.isFinite(e)&&Math.abs(e)<140);function Gi(s){return _e(s)&&["shot","death","hit","blast","impact","blood","glass"].includes(String(s.kind))&&ls(s.o)&&ls(s.v)&&typeof s.who=="number"&&typeof s.other=="number"&&(J(s.gun)||de(s.gun))&&Number.isInteger(s.id)}function Ki(s,e){return!Array.isArray(s)||s.length!==4||s[3]!==0&&s[3]!==1||!s.every(t=>Number.isFinite(t)&&Math.abs(t)<e)?null:{x:s[0],y:s[1],z:s[2],vx:0,vy:0,vz:0,owner:-1,fuse:0,rocket:s[3]===1}}class Yi{constructor(e,t,i,a,c){m(this,"world",null);m(this,"mine",0);m(this,"arena",0);m(this,"round",0);m(this,"level",U[0]);m(this,"paneMask",0);m(this,"teamMode",!1);m(this,"scores",[0,0]);m(this,"solo",!1);m(this,"paused",!1);m(this,"ended",!1);m(this,"seats",[]);m(this,"tick",0);m(this,"bot");m(this,"predicted");m(this,"seq",0);m(this,"pending",[]);m(this,"sendTicks",0);m(this,"queues",new Map);m(this,"frames",[]);m(this,"anchor",0);m(this,"lastFx",0);m(this,"renderTick",0);m(this,"lastDraw",0);m(this,"correction",[0,0,0]);m(this,"fx",new Ci);m(this,"interval",0);m(this,"raf",0);m(this,"last",0);m(this,"accumulator",0);m(this,"lastHud","");m(this,"lastFeed",0);m(this,"reduced",matchMedia("(prefers-reduced-motion: reduce)"));m(this,"hud",Object.fromEntries(["hud-map","round-clock","network-label","health","ammo","frags","gun-label","game-message","killfeed","hitmark","damage","cross"].map(e=>[e,document.getElementById(e)])));m(this,"renderer");m(this,"overview",new Ui);this.canvas=e,this.controls=t,this.rooms=i,this.finished=a,this.audio=c;const r=()=>{var n;const o=e.getBoundingClientRect();o.width&&((n=this.renderer)==null||n.resize(o.width,o.height,Ce.scale))};new ResizeObserver(r).observe(e),window.addEventListener("gameconfig",r)}name(e){var t;return((t=this.seats.find(i=>i.id===e))==null?void 0:t.name)||ot[e]||"Player"}start(e,t,i,a,c=!1){var h;this.stop(),this.round=e,this.arena=t,this.solo=a,this.teamMode=c,this.scores=[0,0],this.level=ms(U[t]),this.seats=i,this.mine=a?0:((h=i.find(p=>p.key===this.rooms.actor))==null?void 0:h.id)??-1,this.paneMask=this.level.boxes.reduce((p,u)=>p|(u.pane??0),0),this.tick=this.seq=this.renderTick=this.lastFx=0,this.frames=[],this.lastDraw=0,this.correction=[0,0,0],this.pending=[],this.sendTicks=0,this.queues.clear(),this.ended=this.paused=!1,this.fx.reset();for(const p of["remote","position","aim","shots","ack","blasts"])delete this.canvas.dataset[p];if(this.hud.killfeed.textContent="",this.lastHud="",a||this.rooms.host){this.world=new mi(U[t],c),this.level=this.world.map,this.scores=this.world.scores;for(const p of i)this.world.add(p.id,p.gun,p.secondary);if(a){this.bot=new gi(this.level);const[p,u,f]=U[t].practiceContact;Object.assign(this.world.players.get(1),{x:p,y:te(this.level.terrain,p,u),z:u,yaw:f,protect:0})}}const r=i.find(p=>p.id===this.mine),o=document.querySelector("#game");o.classList.toggle("spectating",!r),this.canvas.setAttribute("aria-label",r?"First-person arena. Use WASD to move and F to fire.":"Live 3D bird’s-eye view of the match"),document.querySelector("#shell").hidden=!0,o.hidden=!1,this.hud["hud-map"].textContent=U[t].name,this.hud["game-message"].textContent="",this.hud.hitmark.hidden=!0,r&&(this.predicted=Nt(U[t],this.mine,r.gun,1,r.secondary),this.controls.sync(this.predicted),this.controls.start()),this.renderer??(this.renderer=new _i(this.canvas));const n=this.canvas.getBoundingClientRect();this.renderer.resize(n.width,n.height,Ce.scale),this.last=performance.now(),this.accumulator=0,this.interval=window.setInterval(()=>this.pump(),1e3/$e);const l=p=>{document.hidden||this.draw(p),this.raf=requestAnimationFrame(l)};this.raf=requestAnimationFrame(l)}stop(){clearInterval(this.interval),cancelAnimationFrame(this.raf),this.controls.stop(),this.round=0,this.world=null,this.bot=void 0,this.predicted=void 0,document.querySelector("#game").hidden=!0,document.querySelector("#shell").hidden=!1}menu(e){this.paused=e,e?this.controls.stop():this.controls.start()}pump(){const e=performance.now();for(this.accumulator=Math.min(.14,this.accumulator+(e-this.last)/1e3),this.last=e;this.accumulator>=ve;)this.accumulator-=ve,!this.ended&&!(this.solo&&(this.paused||document.hidden))&&this.step(),this.fx.step(this.level,ve)}step(){var t,i,a;const e=((t=this.world)==null?void 0:t.players.get(this.mine))??this.predicted;if(this.world){const c=new Map;e&&c.set(this.mine,this.controls.input(++this.seq,e,this.world.tick));for(const l of this.world.players.values())if(l.id!==this.mine){const h=((i=this.bot)==null?void 0:i.input(this.world,l))??((a=this.queues.get(l.id))==null?void 0:a.shift());h&&c.set(l.id,h)}const r=e==null?void 0:e.life;this.world.advance(c),this.tick=this.world.tick;const o=this.world.players.get(this.mine);o&&o.life!==r&&this.controls.sync(o);const n=this.world.effects.splice(0);for(const l of n)this.effect(l);if(!this.solo){for(let l=0;l<n.length;l+=36)this.rooms.send({t:"fx",r:this.round,e:n.slice(l,l+36)});this.rooms.connected.size&&(this.tick%3===0||this.world.done)&&this.broadcast()}this.world.done&&this.finish()}else{if(!e||!this.frames.length||performance.now()-this.anchor>1600)return;const c=G(Math.ceil(this.rooms.rtt*$e/1e3)+9,12,36);if(this.pending.length<c){const r=this.controls.input(++this.seq,e,Math.floor(this.renderTick));Ft(this.level,this.predicted,r)&ae&&this.fireLocal(this.predicted.gun,this.predicted.buttons),this.pending.push(r)}if(++this.sendTicks>=2&&this.pending.length){const r={t:"input",r:this.round,b:this.pending.slice(-9)};this.rooms.transientInputs&&this.rooms.fastReady?this.rooms.snapshot(r):this.rooms.send(r),this.sendTicks=0}}}fireLocal(e,t){const i=di(e,t);this.fx.localShot(i),this.audio("shot",e),this.controls.pitch=G(this.controls.pitch+i*.32,-1.36,1.36)}effect(e){var n;if(e.id<=this.lastFx)return;this.lastFx=e.id,this.fx.receive(e,this.mine,this.players());const t=((n=this.world)==null?void 0:n.players.get(this.mine))??this.predicted;if(!t)return;const i=e.o[0]-((t==null?void 0:t.x)??0),a=e.o[2]-((t==null?void 0:t.z)??0),c=Math.hypot(i,a),r=1/(1+c*.13),o=G((i*Math.cos(this.controls.yaw)-a*Math.sin(this.controls.yaw))/Math.max(2,c),-.85,.85);e.kind==="shot"&&e.who===this.mine&&this.world?this.fireLocal(e.gun,(t==null?void 0:t.buttons)??0):e.kind==="shot"&&e.who!==this.mine&&this.audio("shot",e.gun,r,o),e.kind==="blast"&&this.audio("blast",0,r,o),e.kind==="hit"&&e.who===this.mine&&this.audio("hit",0),e.kind==="death"&&(this.hud.killfeed.textContent=this.name(e.who)+"  ›  "+this.name(e.other),this.lastFeed=performance.now())}broadcast(){const e=this.world,t={t:"state",r:this.round,k:e.tick,glass:e.map.broken??0,scores:e.scores,p:ji(e.players.values()),g:e.grenades.map(i=>[Math.round(i.x*100)/100,Math.round(i.y*100)/100,Math.round(i.z*100)/100,+!!i.rocket]),end:e.done};e.done?this.rooms.send(t):this.rooms.snapshot(t)}packet(e,t){var p;if(!this.round||t.r!==this.round)return;if(this.world){const u=this.seats.find(d=>d.key===e),f=u&&this.world.players.get(u.id);if(u&&f&&t.t==="equip"&&J(t.primary)&&de(t.secondary)){this.setSeatLoadout(u,t.primary,t.secondary);return}if(!f||t.t!=="input"||!Array.isArray(t.b)||t.b.length>9)return;let b=this.queues.get(f.id);b||(b=[],this.queues.set(f.id,b));for(const d of t.b)pi(d)&&d[6]===f.life&&qi(b,d,f.ack,f.buttons);return}if(e!==this.rooms.owner)return;if(t.t==="fx"&&Array.isArray(t.e)&&t.e.length<=80){for(const u of t.e)Gi(u)&&this.effect(u);return}if(t.t!=="state"||typeof t.k!="number"||!Number.isInteger(t.k)||t.k<=this.tick||t.k>Pt||!Array.isArray(t.g)||t.g.length>32)return;const i=t.glass,a=t.scores,c=this.paneMask;if(typeof i!="number"||!Number.isSafeInteger(i)||i<0||i>c||(i&~c)!==0||!Array.isArray(a)||a.length!==2||!a.every(u=>Number.isInteger(u)&&u>=0&&u<=mt+8))return;const r=Hi(t.p,this.level.size),o=t.g.map(u=>Ki(u,this.level.size+32));if(!r||o.some(u=>!u))return;const n=r.find(u=>(u==null?void 0:u.id)===this.mine);if(!n)return;const l=n.life!==((p=this.predicted)==null?void 0:p.life);gs(this.level,i),this.scores=[a[0],a[1]],this.tick=t.k,this.seq=Math.max(this.seq,n.ack),this.anchor=performance.now(),this.frames.push({tick:this.tick,players:r,grenades:o}),this.frames.length>18&&this.frames.shift(),this.pending=this.pending.filter(u=>u[0]>n.ack&&u[6]===n.life);const h=this.predicted;this.predicted={...n};for(const u of this.pending)Ft(this.level,this.predicted,u);if(h&&!l&&h.hp&&n.hp){const u=[h.x-this.predicted.x+this.correction[0],h.y-this.predicted.y+this.correction[1],h.z-this.predicted.z+this.correction[2]];this.correction=Math.hypot(...u)<1?u:[0,0,0]}else this.correction=[0,0,0];l&&this.controls.sync(n),t.end===!0&&this.finish()}setSeatLoadout(e,t,i){var c;e.gun=t,e.secondary=i;const a=(c=this.world)==null?void 0:c.players.get(e.id);a&&fi(a,t,i)}changeLoadout(e,t){const i=this.seats.find(a=>a.id===this.mine);return!i||!this.round||this.ended||!this.world&&!this.rooms.connected.has(this.rooms.owner)?!1:(this.setSeatLoadout(i,e,t),this.world||this.rooms.send({t:"equip",r:this.round,primary:e,secondary:t}),!0)}sendFinalState(){var e;(e=this.world)!=null&&e.done&&this.broadcast()}updateSeats(e){const t=this.seats;if(this.seats=e,!!this.world){for(const i of this.world.players.values())e.some(a=>{var c;return a.id===i.id&&a.key===((c=t.find(r=>r.id===i.id))==null?void 0:c.key)})||(this.world.remove(i.id),this.queues.delete(i.id));for(const i of e)this.world.players.has(i.id)||this.world.add(i.id,i.gun,i.secondary)}}players(){var e;return this.world?[...this.world.players.values()]:((e=this.frames.at(-1))==null?void 0:e.players)??[]}finish(){this.ended||(this.ended=!0,this.controls.stop(),this.finished())}draw(e){var f,b,d,g;const t=((f=this.world)==null?void 0:f.players.get(this.mine))??this.predicted,i=Math.max(0,Math.ceil((Pt-this.tick)/$e)),a=Math.floor(i/60)+":"+String(i%60).padStart(2,"0");if(this.world&&this.mine===-1){const y=this.players(),k=(b=this.renderer)==null?void 0:b.render(this.level,void 0,y,this.world.grenades,this.fx,e,this.reduced.matches,this.teamMode);k&&this.overview.draw(k,y,M=>this.name(M),this.teamMode),this.canvas.dataset.seat=String(this.mine),this.canvas.dataset.blasts=String(this.fx.blasts.length);const S="Dedicated host · "+y.length+(y.length===1?" player":" players");this.hud["network-label"].textContent!==S&&(this.hud["network-label"].textContent=S),this.hud["round-clock"].textContent!==a&&(this.hud["round-clock"].textContent=a);return}if(!t||!this.renderer)return;let c=this.players(),r=((d=this.world)==null?void 0:d.grenades)??((g=this.frames.at(-1))==null?void 0:g.grenades)??[];const o=this.lastDraw?Math.max(0,e-this.lastDraw):0;if(this.lastDraw=e,!this.world&&this.frames.length){const y=Di(this.renderTick,this.tick,Math.max(0,e-this.anchor),o);this.renderTick=y;const k=this.frames.findIndex(w=>w.tick>=y),S=this.frames[Math.max(0,k)],M=this.frames[Math.max(0,k-1)],z=G((y-M.tick)/Math.max(1,S.tick-M.tick),0,1);c=S.players.map(w=>{const R=M.players.find(V=>V.id===w.id);if(!R||R.life!==w.life||R.hp===0||!w.hp)return w;const T=Math.atan2(Math.sin(w.yaw-R.yaw),Math.cos(w.yaw-R.yaw));return{...w,x:R.x+(w.x-R.x)*z,y:R.y+(w.y-R.y)*z,z:R.z+(w.z-R.z)*z,yaw:R.yaw+T*z,pitch:R.pitch+(w.pitch-R.pitch)*z}}),r=S.grenades}const n={...t,yaw:this.controls.yaw,pitch:this.controls.pitch},l=Math.exp(-o/65);for(const[y,k]of["x","y","z"].entries())this.correction[y]*=l,n[k]+=this.correction[y];this.canvas.dataset.viewTick=this.renderTick.toFixed(2),this.renderer.render(this.level,n,c,r,this.fx,e,this.reduced.matches,this.teamMode),this.canvas.dataset.position=[n.x,n.z].map(y=>y.toFixed(3)).join(","),this.canvas.dataset.aim=n.yaw.toFixed(3),this.canvas.dataset.lean=String(n.lean),this.canvas.dataset.crouch=String(!!(n.buttons&4)),this.canvas.dataset.glass=String(this.level.broken??0),this.canvas.dataset.shots=String(this.fx.shotCount),this.canvas.dataset.blasts=String(this.fx.blasts.length),this.canvas.dataset.seat=String(this.mine),this.canvas.dataset.ack=String(t.ack),this.canvas.dataset.remote=c.filter(y=>y.id!==this.mine).map(y=>[y.id,y.x.toFixed(2),y.z.toFixed(2),y.pitch.toFixed(2),+!!(y.buttons&X)].join(",")).join("|");const h=H[t.gun],p=this.solo?"Practice · 3 bots":this.rooms.host?"Room host · "+(this.rooms.fastReady?"Realtime":"Reliable"):this.rooms.connected.size&&this.frames.length&&performance.now()-this.anchor<1600?this.rooms.rtt?this.rooms.rtt+" ms":"Connected":"Reconnecting",u=[i,this.scores.join("-"),t.gun,Math.ceil(t.cook/6),t.hp,t.ammo,t.frags,t.kills,Math.ceil(t.respawn/60),!!t.reload,p].join("|");if(u!==this.lastHud&&(this.lastHud=u,this.hud["round-clock"].textContent=a,this.hud["network-label"].textContent=p+" · "+(this.teamMode?tt[t.id%2]+" · Amber "+this.scores[0]+" / Slate "+this.scores[1]:t.kills+"/"+mt),this.hud.health.textContent=String(t.hp),this.hud.ammo.textContent=t.ammo+" / "+h.mag,this.hud.frags.textContent=t.frags+" FRAG",this.hud["gun-label"].textContent=(J(t.gun)?"1 · ":"2 · ")+h.name,this.hud["game-message"].textContent=t.hp?t.cook?"Frag · "+(Math.ceil(t.cook/6)/10).toFixed(1)+" s":t.reload?"Reloading…":"":"Respawn in "+Math.ceil(t.respawn/60)),this.hud.cross.hidden=!!(n.buttons&ke)||!n.hp,this.hud.hitmark.hidden=this.fx.hit<=0,this.hud.damage.style.opacity=String(Math.min(.9,this.fx.hurt*2)),this.fx.hurt>0){const y=this.fx.damageBearing-n.yaw;this.hud.damage.style.setProperty("--hit-x",50+50*Math.sin(y)+"%"),this.hud.damage.style.setProperty("--hit-y",50-50*Math.cos(y)+"%")}this.lastFeed&&e-this.lastFeed>3800&&(this.hud.killfeed.textContent="",this.lastFeed=0)}}const I=s=>document.getElementById(s),Be=I("dialog"),$=I("dialog-body"),we=I("dialog-note"),Es=()=>new Mi(ze("media")?ei:void 0,"Faultline match audio");let Ee=Es(),ht;function $i(s,e,t=1,i=0){const a=Ee.context,c=Ee.output;if(!a||!c||!Ee.audible)return;const r=a.currentTime,o=a.createOscillator(),n=a.createGain(),l=a.createStereoPanner();l.pan.value=i,l.connect(c);const h=s==="blast"?E.feel.soundDuration:s==="hit"?.06:.1+(e===2?.07:0);if(o.type=s==="hit"?"sine":s==="blast"?"sawtooth":"triangle",o.frequency.setValueAtTime(s==="hit"?760:s==="blast"?E.feel.pitchStart:210+e*22,r),o.frequency.exponentialRampToValueAtTime(s==="hit"?510:s==="blast"?E.feel.pitchEnd:42,r+h),n.gain.setValueAtTime((s==="blast"?E.feel.soundGain:s==="hit"?.09:.14)*t,r),n.gain.exponentialRampToValueAtTime(.001,r+h),o.connect(n),n.connect(l),s!=="hit"){if(!ht){ht=a.createBuffer(1,Math.ceil(a.sampleRate*.55),a.sampleRate);const f=ht.getChannelData(0);for(let b=0;b<f.length;b++)f[b]=Math.random()*2-1}const p=a.createBufferSource(),u=a.createBiquadFilter();p.buffer=ht,u.type="lowpass",u.frequency.setValueAtTime(s==="blast"?3100:4700+e*230,r),u.frequency.exponentialRampToValueAtTime(s==="blast"?150:680,r+h),p.connect(u),u.connect(n),p.onended=()=>{p.disconnect(),u.disconnect()},p.start(),p.stop(r+h)}o.onended=()=>{o.disconnect(),n.disconnect(),l.disconnect()},o.start(),o.stop(r+h)}let ne=0,oe=0,pe=Re,he=0,bt="play",D="",Ae=!1,Y=0,me=0,jt=0,qt="",vt="",_=[],ut=0,Je=[],wt=0;const As=ze("webrtc")&&ze("cvm");let ue=!0,Rs=!1,De="";async function St(){var e,t;const s=x.room;if(!(!s||!x.host||!Rs))try{await x.advertise({title:Ot(s),phase:Y?"playing":"lobby",accepting:!0,badges:[U[me].name,ue?"Team deathmatch":"Free-for-all",...Ie(s)?["Count includes server"]:[]]}),((e=x.room)==null?void 0:e.room)===s.room&&(De="")}catch{if(((t=x.room)==null?void 0:t.room)!==s.room)return;De="Public listing unavailable. Friends can still find this room in Browse rooms."}}let Is="";const Ht=new Li(I("scene"),()=>Oe(),()=>j.toggleCrouch),x=new Fi(Zi,Qi,s=>{Ct(),re("message","Room closed"),we.textContent=s,q("Return to operations",ee)}),C=new Yi(I("scene"),Ht,x,Xi,$i),j=new ii(Ls,()=>{Ee.dispose(),Ee=Es(),x.room&&zt()});function q(s,e,t=!1,i=$){const a=document.createElement("button");return a.className=t?"primary":"secondary",a.textContent=s,a.onclick=e,i.append(a),a}function W(s,e="muted"){const t=document.createElement("p");return t.className=e,t.textContent=s,$.append(t),t}function ee(){clearInterval(wt),ut++,Be.open&&Be.close(),D=""}function re(s,e){s!=="browse"&&clearInterval(wt),D=s,I("dialog-title").textContent=e,$.replaceChildren(),we.textContent="",Be.open||Be.showModal(),I("dismiss").hidden=s==="lobby"||s==="results"||Ae}function kt(s){var e;return((e=j.profile)==null?void 0:e.name)||j.alias||ot[s]}function Ls(){var e,t;const s=_.find(i=>i.key===x.actor);if(s&&x.host&&(s.name=kt(s.id),s.profile=(e=j.profile)==null?void 0:e.key),C.solo){const i=C.seats.find(a=>a.id===C.mine);i&&(i.name=kt(i.id))}if(x.room&&(Te(),D==="lobby"&&fe()),D==="settings"){const i=document.querySelector("#crouch-mode");i&&!i.dataset.edited&&(i.value=j.toggleCrouch?"toggle":"hold");const a=document.getElementById("profile-status");a&&(a.textContent=j.message);const c=document.getElementById("name-source");c&&(c.value=j.profileSelected?"nostr":"alias");const r=document.getElementById("alias-field");if(r&&(r.hidden=!!j.profile||j.loading),!j.profile&&!j.loading&&((t=document.activeElement)==null?void 0:t.id)!=="alias-name"){const o=document.getElementById("alias-name");o&&!o.dataset.edited&&(o.value=j.alias)}}}function Gt(){Is=D,re("settings","Player settings");const s=(c,r)=>{const o=document.createElement("label");return o.className="field",o.textContent=c,o.append(r),$.append(o),o},e=document.createElement("select");e.id="name-source",e.add(new Option("Anonymous alias","alias")),e.add(new Option("Nostr profile","nostr")),e.options[1].disabled=!j.canProfile,s("Play as",e);const t=document.createElement("input");t.id="alias-name",t.maxLength=24,t.autocomplete="off",t.placeholder="Use assigned callsign",t.value=j.alias,t.oninput=()=>{t.dataset.edited="true"},s("Custom name",t).id="alias-field";const i=W("","profile-status muted");i.id="profile-status",i.setAttribute("role","status"),W("Profile mode shares your display name and public key with the room.","profile-status muted"),e.onchange=()=>{e.value==="alias"?j.useAlias():j.useProfile()};const a=document.createElement("select");a.id="crouch-mode",a.onchange=()=>{a.dataset.edited="true"},a.add(new Option("Toggle","toggle")),a.add(new Option("Hold","hold")),a.value=j.toggleCrouch?"toggle":"hold",s("Crouch behavior",a),q("Done",()=>{j.save(t.value,a.value==="toggle"),at()},!0),Ls()}I("settings").onclick=Gt;function at(){if(!(Ae||D==="lobby")){if(D==="settings"){const s=Is;ee(),s==="pause"?Oe():s==="lobby"&&fe();return}if(D==="loadout"){ee(),Oe();return}if(D==="pause"){ee(),C.menu(!1);return}if(D==="results"){Ts();return}ee()}}I("dismiss").onclick=at;Be.addEventListener("cancel",s=>{s.preventDefault(),at()});function Ue(s){bt=s;for(const e of["play","armory","controls"])I(e+"-page").hidden=e!==s;for(const e of document.querySelectorAll("[data-page]")){const t=e.dataset.page===s;e.classList.toggle("selected",t),t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}s==="play"&&Kt(),s==="armory"&&(he=oe,Ps())}for(const s of document.querySelectorAll("[data-page]"))s.onclick=()=>Ue(s.dataset.page);function Kt(){const s=U[ne];I("sector").textContent=s.sector,I("map-name").textContent=s.name,I("map-type").textContent=s.type,I("map-index").textContent=String(ne+1).padStart(2,"0")+" / "+String(U.length).padStart(2,"0"),I("equipped-name").textContent=H[oe].name,I("equipped-type").textContent="+ "+H[pe].name,ws(I("plate"),s),ks(I("equipped-art"),oe)}new ResizeObserver(()=>{bt==="play"&&ws(I("plate"),U[ne])}).observe(I("plate"));I("next-map").onclick=()=>{ne=(ne+1)%U.length,Kt()};I("prev-map").onclick=()=>{ne=(ne+U.length-1)%U.length,Kt()};I("open-loadout").onclick=()=>Ue("armory");function Ps(){const s=I("weapon-list");s.replaceChildren(),H.forEach((i,a)=>{const c=document.createElement("button");c.className="weapon-option"+(a===he?" active":""),c.setAttribute("aria-pressed",String(a===he));const r=document.createElement("strong"),o=document.createElement("small");r.textContent=i.name,o.textContent=i.type+(a===oe||a===pe?" · Equipped":""),c.append(r,o),c.onclick=()=>{he=a,Ps(),s.children[a].focus()},s.append(c)});const e=H[he];ks(I("weapon-art"),he),I("weapon-class").textContent=e.type+" / "+e.mode,I("weapon-name").textContent=e.name,I("weapon-desc").textContent=e.blurb;const t=I("stats");t.replaceChildren();for(const[i,a]of[["Magazine",e.mag],["Damage per trigger",e.pellets>1?e.damage+" × "+e.pellets:e.damage],["Cycle time",Math.round(e.delay/60*1e3)+" ms"],["Reload",(e.reload/60).toFixed(2)+" s"],["Sight magnification",e.zoom+"×"]]){const c=document.createElement("dt"),r=document.createElement("dd");c.textContent=String(i),r.textContent=String(a),t.append(c,r)}I("equip").textContent=he===oe||he===pe?"Return to operations":"Equip "+e.name}I("equip").onclick=()=>{J(he)?oe=he:pe=he,Ue("play")};function Yt(){ee(),Ee.activate();const s=[0,1,2,3].map(e=>({id:e,key:"bot-"+e,name:e===0?kt(e):ot[e],gun:e===0?oe:(e+ne)%Re,secondary:e===0?pe:Re,ready:!0}));C.start(1,ne,s,!0)}I("practice").onclick=Yt;function Oe(){!C.round||C.ended||D||(xe(!1),C.menu(!0),re("pause",C.solo?"Practice paused":"Match menu"),W(C.solo?U[C.arena].name:"The multiplayer round continues.","dialog-info muted"),q("Resume",at,!0),q("Change loadout",Vi),q("Player settings",Gt),C.solo?q("Restart practice",Yt):(!x.connected.size||x.notice)&&q("Retry connection",()=>void x.retry().catch(s=>{we.textContent=String(s)})),q(C.solo?"Leave practice":"Leave room",()=>void zt()))}function Vi(){re("loadout","Change loadout");const s=(i,a,c)=>{const r=document.createElement("label"),o=document.createElement("select");return r.textContent=i,H.forEach((n,l)=>{c(l)&&o.add(new Option(n.name,String(l),!1,l===a))}),r.append(o),$.append(r),o},e=s("Primary",oe,J),t=s("Secondary",pe,de);q("Equip and resume",()=>{const i=Number(e.value),a=Number(t.value);if(!C.changeLoadout(i,a)){we.textContent="Reconnect to the host to change loadout.";return}oe=i,pe=a,ee(),C.menu(!1)},!0),q("Back",()=>{ee(),Oe()})}I("pause").onclick=Oe;function Ct(){qt=vt="",clearTimeout(jt),xe(!1),C.stop(),Y=0,_=[],ee(),Ue("play"),I("link-status").textContent="Standby"}async function zt(){x.host&&x.send({t:"closed"}),Ct(),await x.leave()}function Xi(){xe(!1);const s=(me+1)%U.length;if(!C.solo&&x.host&&x.room){const i=Y,a=x.room.room;if(jt=window.setTimeout(()=>{var c;!x.host||((c=x.room)==null?void 0:c.room)!==a||Y!==i||(me=s,Xt(),St())},5e3),Ie(x.room)){I("game-message").textContent="Next arena · "+U[s].name,D==="lobby"&&fe();return}}re("results","Round complete");const e=C.players().sort((i,a)=>a.kills-i.kills||i.deaths-a.deaths),t=e.filter(i=>{var a;return i.kills===((a=e[0])==null?void 0:a.kills)}).map(i=>C.name(i.id));W(C.teamMode?(C.scores[0]===C.scores[1]?"Teams tied.":tt[+(C.scores[1]>C.scores[0])]+" wins.")+" Amber "+C.scores[0]+" / Slate "+C.scores[1]:t.join(" + ")+(t.length>1?" tied for first.":" wins."),"muted dialog-info");for(const i of e){const a=document.createElement("div");a.className="roster-row",a.textContent=(C.teamMode?tt[i.id%2]+" · ":"")+C.name(i.id)+(i.id===C.mine?" (you)":"");const c=document.createElement("small");c.textContent=i.kills+" K / "+i.deaths+" D",a.append(c),$.append(a)}C.solo?q("Play again",Yt,!0):x.host&&W("Up next · "+U[s].name+" in five seconds."),C.solo||x.host?q(C.solo?"Operations":"Return to lobby",Ts,!C.solo):(W("Waiting for the next round."),q("Leave room",()=>void zt()))}function Ts(){if(C.solo){Ct();return}x.host&&(clearTimeout(jt),me=(me+1)%U.length,C.stop(),Y=0,St(),Te(),fe())}function Ns(){re("create","Create room");const s=document.createElement("label");s.htmlFor="room-name",s.textContent="Room name";const e=document.createElement("input");e.id="room-name",e.maxLength=15,e.value=U[ne].name,e.autocomplete="off",$.append(s,e);const t=document.createElement("select"),i=document.createElement("label");i.className="field",i.textContent="Game mode",t.add(new Option("Team deathmatch","team")),t.add(new Option("Free-for-all","ffa")),t.value=ue?"team":"ffa",t.onchange=()=>{ue=t.value==="team"},i.append(t),$.append(i);const a=document.createElement("select");a.add(new Option("Free to join","open")),a.add(new Option("Room code only","code"));const c=document.createElement("label");c.className="field",c.textContent="Room access",c.append(a),$.append(c);const r=document.createElement("select");r.add(new Option("Host and play","player")),r.add(new Option("Dedicated host","server"));const o=document.createElement("label");o.className="field",o.textContent="This browser",o.append(r),$.append(o);const n=document.createElement("label"),l=document.createElement("input");l.type="checkbox",l.checked=!1,n.append(l," Show this lobby in Playing now across shells"),$.append(n);const h=W("","dialog-info muted"),p=()=>{const f=r.value==="server";h.textContent=f?"Up to 7 players. Keep this window open and awake to run the server.":U[ne].name+" · Up to 8 players · Players can join during a match.",l.disabled=a.value==="code",l.disabled&&(l.checked=!1),u.textContent=f?"Start server":"Open lobby"};a.onchange=r.onchange=p;const u=q("Open lobby",()=>{e.reportValidity()&&Et(null,e.value.trim()||U[ne].name,void 0,{share:l.checked,dedicated:r.value==="server",listed:a.value==="open"})},!0);e.onkeydown=f=>{f.key==="Enter"&&u.click()},p(),e.select()}function Wi(){re("code","Enter room code");const s=document.createElement("input");s.setAttribute("aria-label","Room code"),s.maxLength=36,$.append(s),s.required=!0,s.pattern="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",q("Join room",()=>{s.reportValidity()&&Et(s.value.trim().toLowerCase(),"")},!0),s.focus()}I("host").onclick=Ns;async function Et(s,e,t,i){if(!Ae){i!=null&&i.dedicated||Ee.activate(),Ae=!0,I("dismiss").hidden=!0;for(const a of $.querySelectorAll("button"))a.disabled=!0;we.textContent="Contacting room service…";try{me=ne,Y=0,_=[],Rs=!!(i!=null&&i.share),De="",await x.enter(s,e,t,i==null?void 0:i.dedicated,i==null?void 0:i.listed),x.host&&$t(),i!=null&&i.dedicated&&Xt(),await St(),(!Y||D==="lobby")&&fe(),Te()}catch(a){we.textContent=(a instanceof Error?a.message:String(a))+(s?"":" · Check Browse rooms before creating another lobby.");for(const c of $.querySelectorAll("button"))c.disabled=!1}finally{Ae=!1,I("dismiss").hidden=D==="lobby"}}}async function ft(){const s=++ut;try{const e=await x.list();if(D!=="browse"||Ae||ut!==s)return;Je=e,Ji()}catch(e){D==="browse"&&ut===s&&(we.textContent=String(e))}}function Ji(){re("browse","Room browser"),Je.length||W("No open rooms. Create one to invite other players.","muted dialog-info");for(const s of Je){const e=q(Ot(s),()=>void Et(s.room,""));e.className="room-item",e.dataset.room=s.room;const t=document.createElement("small");t.textContent=Cs(s)+" / "+zs(s)+(Ie(s)?" · Dedicated":"")+"   →",e.append(t),e.disabled=s.peers.length>=s.capacity}q("Refresh rooms",()=>void ft()),q("Create room",Ns,!Je.length),q("Enter room code",Wi)}I("browse").onclick=()=>{Je=[],re("browse","Room browser"),W("Finding rooms…"),q("Refresh rooms",()=>void ft()),ft(),clearInterval(wt),wt=window.setInterval(()=>{Ae||ft()},4200)};if(!As){for(const s of["host","browse"])I(s).disabled=!0;document.querySelector(".action-panel p").textContent="This host lacks room or peer support. Solo practice is available."}function $t(){var e;const s=x.room;if(!(!s||!x.host)){_=_.filter(t=>s.peers.includes(t.key));for(const t of s.peers){if((t===x.actor?Ie(s):!x.connected.has(t))||_.some(o=>o.key===t))continue;const i=Array.from({length:8},(o,n)=>n).filter(o=>!_.some(n=>n.id===o)),a=_.filter(o=>o.id%2===0).length,c=+(a>_.length-a),r=(ue?i.find(o=>o%2===c):void 0)??i[0];if(r===void 0)break;_.push({key:t,id:r,name:t===x.actor?kt(r):ot[r],profile:t===x.actor?(e=j.profile)==null?void 0:e.key:void 0,gun:t===x.actor?oe:0,secondary:t===x.actor?pe:Re,ready:!0})}if(ue&&!Y){const t=_.filter(r=>r.id%2===0),i=_.filter(r=>r.id%2===1),a=t.length>i.length?t:i,c=a===t?i:t;for(;a.length>c.length+1;){const r=a.pop(),o=Array.from({length:8},(n,l)=>l).find(n=>n%2!==r.id%2&&!_.some(l=>l.id===n));if(o===void 0)break;r.id=o,c.push(r)}}Y&&C.round&&C.updateSeats(_)}}function Te(s=!1){var i,a;if(!x.room||!x.connected.size)return;const e=x.host?{t:"lobby",transientInputs:!0,r:Y,map:me,teamMode:ue,s:_.map(c=>({...c,ping:x.pingFor(c.key)}))}:{t:"hello",gun:oe,secondary:pe,ready:!0,name:((i=j.profile)==null?void 0:i.name)||j.alias,profile:(a=j.profile)==null?void 0:a.key},t=JSON.stringify([x.room.room,[...x.connected].sort(),e]);(s||t!==vt)&&(x.send(e),vt=t)}function Zi(){x.room&&(x.connected.size||(vt=""),x.host&&$t(),Te(!x.host&&!_.length),D==="lobby"&&fe())}function Fs(s){var t;if(C.solo)return s==="bot-0"?"Local":"Bot";if(s===x.owner)return"Host";if(!x.host&&!x.connected.has(x.owner))return"—";const e=x.host?x.pingFor(s):((t=_.find(i=>i.key===s))==null?void 0:t.ping)??(s===x.actor&&x.rtt>0?x.rtt:void 0);return e===void 0?"—":e+" ms"}function hs(s){for(const e of s.querySelectorAll("[data-peer-ping]")){const t=e.dataset.peerPing;e.textContent=x.host&&t!==x.actor&&!x.connected.has(t)?"Connecting…":Fs(t)}}let ds=0;const Vt=I("scoreboard");function us(){const s=I("score-rows"),e=new Map(C.players().map(i=>[i.id,i])),t=[...C.seats].sort((i,a)=>{var c,r;return(((c=e.get(a.id))==null?void 0:c.kills)??0)-(((r=e.get(i.id))==null?void 0:r.kills)??0)||i.id-a.id});s.replaceChildren(...t.map(i=>{const a=e.get(i.id),c=document.createElement("tr");for(const r of[i.name+(i.id===C.mine?" (you)":""),C.teamMode?tt[i.id%2]:"—",(a==null?void 0:a.kills)??0,(a==null?void 0:a.deaths)??0,Fs(i.key)]){const o=document.createElement("td");o.textContent=String(r),c.append(o)}return c}))}function xe(s){clearInterval(ds),Vt.hidden=!s,I("scores").setAttribute("aria-expanded",String(s)),s&&(us(),ds=window.setInterval(us,500))}I("scores").onclick=()=>xe(Vt.hidden);window.addEventListener("keydown",s=>{s.code!=="Tab"||s.ctrlKey||s.altKey||s.metaKey||s.shiftKey||!Ht.active||D||(s.preventDefault(),s.repeat||xe(!0))});window.addEventListener("keyup",s=>{s.code==="Tab"&&!Vt.hidden&&xe(!1)});window.addEventListener("blur",()=>xe(!1));document.addEventListener("visibilitychange",()=>{document.hidden&&xe(!1)});function fe(){const s=x.room;if(!s)return;const e=JSON.stringify([s.room,s.peers,me,ue,_.map(({ping:c,...r})=>r),C.ended,De,[...x.connected].sort(),x.notice]);if(D==="lobby"&&qt===e){hs($);return}qt=e,re("lobby",Ot(s));const t=x.host&&Ie(s);I("link-status").textContent=t?"Hosting server":"In lobby",W((x.host||_.length?U[me].name:"Receiving battlefield…")+" · "+Cs(s)+" / "+zs(s)+" players · "+(ue?"Team deathmatch":"Free-for-all"),"muted dialog-info"),t&&W(C.ended?"Round complete. The next round starts shortly.":_.length?"Dedicated server running.":"Dedicated server running with zero players.","dialog-info"),De&&W(De,"dialog-info"),x.host&&W("Room code: "+s.room,"muted dialog-info");const i=document.createElement("div");i.className="roster",$.append(i);for(const c of[x.owner,...s.peers.filter(r=>r!==x.owner)]){if(Ie(s)&&c===x.owner)continue;const r=document.createElement("div");r.className="roster-row";const o=_.find(h=>h.key===c),n=document.createElement("span");n.textContent=(o?o.name:"Joining…")+(c===x.actor?" (you)":"")+(o&&ue?" · "+tt[o.id%2]:""),o!=null&&o.profile&&(n.textContent+=" · Nostr",n.title=o.profile),r.append(n);const l=document.createElement("small");l.dataset.peerPing=c,r.append(l),i.append(r)}hs(i);const a=document.createElement("div");a.className="room-actions",$.append(a),x.host&&!t?q("Start match",()=>{Ee.activate(),Xt(),St()},!0,a):x.host||(we.textContent=x.connected.has(x.owner)?"Waiting for the host to start.":"Connecting to the room host…"),x.notice&&(we.textContent=x.notice,q("Retry connection",()=>void x.retry().catch(c=>{we.textContent=String(c)}),!1,a)),t?q("Back to overview",ee,!0,a):q("Player settings",Gt,!1,a),q(t?"Stop server":"Leave room",()=>void zt(),!1,a)}function Xt(){!x.host||!x.room||(Y=Math.floor(performance.now()*100)+1,Ds(),Te(!0))}function Ds(){xe(!1),ee(),C.start(Y,me,_,!1,ue)}I("server-menu").onclick=fe;function Qi(s,e){if(x.host)if(e.t==="hello"){$t();const t=_.find(i=>i.key===s);t&&typeof e.gun=="number"&&Number.isInteger(e.gun)&&J(e.gun)&&de(e.secondary)&&typeof e.name=="string"&&e.name===Le(e.name)&&(e.profile===void 0||Lt(e.profile))&&typeof e.ready=="boolean"&&(t.name=e.name||ot[t.id],t.profile=e.profile,Y||(t.gun=e.gun,t.secondary=e.secondary),Te(!0),C.ended&&C.sendFinalState(),D==="lobby"&&fe())}else C.packet(s,e);else if(s===x.owner){if(e.t==="closed"){x.leave(),Ct(),re("message","Room closed"),W("The host left the room."),q("Operations",ee,!0);return}if(e.t==="lobby"){if(!Number.isSafeInteger(e.r)||typeof e.r!="number"||e.r<0||typeof e.map!="number"||!Number.isInteger(e.map)||!U[e.map]||typeof e.teamMode!="boolean"||!Array.isArray(e.s)||e.s.length>8||!e.s.every(i=>_e(i)&&typeof i.key=="string"&&/^[a-f0-9]{64}$/.test(i.key)&&typeof i.id=="number"&&Number.isInteger(i.id)&&i.id>=0&&i.id<8&&typeof i.gun=="number"&&Number.isInteger(i.gun)&&J(i.gun)&&de(i.secondary)&&typeof i.name=="string"&&i.name.length>0&&i.name===Le(i.name)&&(i.profile===void 0||Lt(i.profile))&&(i.ping===void 0||Number.isInteger(i.ping)&&Number(i.ping)>=0&&Number(i.ping)<=6e4)&&typeof i.ready=="boolean")||!e.s.some(i=>i.key===x.actor)||new Set(e.s.map(i=>i.key)).size!==e.s.length||new Set(e.s.map(i=>i.id)).size!==e.s.length)return;if(x.transientInputs=e.transientInputs===!0,_=e.s,me=e.map,ue=e.teamMode,e.r!==Y){const i=Y;if(Y=e.r,Y){Ds();const a=_.find(c=>c.key===x.actor);(a.gun!==oe||a.secondary!==pe)&&C.changeLoadout(oe,pe)}else i&&(C.stop(),Te(),fe())}else!Y&&D!=="settings"?fe():C.updateSeats(_)}else C.packet(s,e)}}window.addEventListener("pagehide",()=>{C.stop(),Ee.dispose(),x.leave()},{once:!0});Ys(Ht,Be,{screen:()=>D?"dialog/"+D:C.round?C.mine<0?"observing":"playing":"page/"+bt,menu:()=>C.mine<0?fe():Oe(),scores:xe,back:()=>{var s;Ae||(D==="code"?I("browse").click():D==="lobby"&&C.mine<0&&C.round?ee():D==="lobby"||D==="results"&&!x.host&&!C.solo?(s=[...$.querySelectorAll("button")].find(e=>e.textContent==="Leave room"))==null||s.focus():D?at():bt!=="play"&&Ue("play"))}});Ue("play");function qs(s){const e=Ni(s);!e||!As||x.room||Ae||C.world||(re("invite","Join a public room?"),W("Join this Faultline lobby using its configured room service.","dialog-info"),q("Join room",()=>void Et(e.room,"",e),!0),q("Not now",ee))}if(ze("intent"))try{xi(s=>{s.convention==="napplet:game/join"&&qs(s.payload)})}catch{}ze("storage")&&Promise.resolve().then(()=>Js("soy.room-entry.v1")).then(async s=>{s&&(await Zs("soy.room-entry.v1"),qs(JSON.parse(s)))}).catch(()=>{});
</script>
    <style>:root{color-scheme:dark;--bg: #141918;--surface: #202624;--border: #39403b;--muted: #a2aaa0;--ink: #eef0e6;--accent: #eab775;--mono: ui-monospace, SFMono-Regular, Consolas, monospace;--type: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;font:15px var(--type);color:var(--ink);background:var(--bg)}*{box-sizing:border-box}html,body,#app{height:100%;margin:0}body{overflow:hidden}button,input{font:inherit}button{cursor:pointer;color:inherit}button:disabled{opacity:.48;cursor:default}button:focus-visible,input:focus-visible,canvas:focus-visible{outline:2px solid var(--accent);outline-offset:-3px}button{border:0;background:none}button:hover:enabled{filter:brightness(1.16)}button:active:enabled{transform:translateY(1px)}[hidden]{display:none!important}#shell{height:100%;overflow:auto;background:radial-gradient(ellipse at 35% 5%,#21272390,transparent 57%),var(--bg)}header{height:64px;display:flex;align-items:center;gap:clamp(20px,5vw,82px);padding:0 clamp(16px,4vw,66px);background:#171c1a;border-bottom:1px solid var(--border)}.brand{font:italic 900 clamp(20px,2vw,30px)/1 var(--type);letter-spacing:-1.5px;display:flex;align-items:center;gap:10px}.mark{width:30px;height:24px;display:block;background:var(--accent);clip-path:polygon(25% 0,100% 0,85% 28%,44% 28%,37% 43%,74% 43%,60% 70%,24% 70%,9% 100%,0 100%,0 52%)}nav{align-self:stretch;display:flex;gap:clamp(9px,2.5vw,40px)}nav button{padding:0 2px;position:relative;font-size:13px;font-weight:650;color:var(--muted)}nav .selected{color:var(--ink)}nav .selected:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background:var(--accent)}.link-status{margin-left:auto;display:flex;gap:8px;align-items:center;color:#c3c8bc;font:11px var(--mono)}.link-status i,.plate-tag i{display:inline-block}.link-status i{width:6px;height:6px;border-radius:50%;background:#a6bc91;box-shadow:0 0 8px #a6bc9144}main{max-width:1450px;margin:auto;padding:clamp(18px,3.5vh,44px) clamp(16px,4vw,66px) 24px}.page-heading{display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin:0 0 clamp(14px,2.5vh,32px)}h1,h2,p{margin:0}h1{font-size:clamp(31px,3.6vw,55px);line-height:1;font-weight:720;letter-spacing:-.055em}.metadata,.card-label,.plate-tag,.code,.game-top small,.game-bottom small{font:10px/1.35 var(--mono);letter-spacing:.09em;text-transform:uppercase}.metadata{color:var(--muted);line-height:1.6}.metadata span{color:#6c756c;margin:0 .55em}.dashboard{display:grid;grid-template-columns:minmax(0,1.95fr) minmax(238px,.85fr);gap:15px;align-items:stretch}.panel,.map-card,.weapon-sheet,#weapon-list{background:var(--surface);border:1px solid var(--border)}.map-card{display:flex;flex-direction:column}.plate{position:relative;isolation:isolate;flex:1;min-height:285px;overflow:hidden;background-color:#2b342f;background-image:linear-gradient(90deg,#cfd6b309 1px,transparent 1px),linear-gradient(#cfd6b309 1px,transparent 1px),radial-gradient(ellipse at 55% 42%,#566054 0,#333d35 57%,#28312b);background-size:26px 26px,26px 26px,auto}.plate:after{content:"";position:absolute;top:0;right:0;bottom:0;left:0;pointer-events:none;background:linear-gradient(0deg,#131a16ee,transparent 32%)}#plate{position:absolute;top:3%;right:0;bottom:9%;left:0;width:100%;height:88%}.plate-tag,.north{position:absolute;color:#d2d6c4;z-index:1}.plate-tag{top:19px;left:20px;display:flex;gap:8px;align-items:center}.corner-symbol{width:10px;height:10px;border:1px solid var(--accent);transform:rotate(45deg)}.north{top:16px;right:20px;font:9px var(--mono);text-align:center}.north b{display:block;font-size:19px}.map-caption{position:absolute;z-index:1;bottom:22px;left:24px}.code{color:var(--accent);display:block;margin-bottom:5px;font-weight:700}.map-caption h2{font-size:clamp(30px,3.5vw,53px);letter-spacing:-.06em;line-height:.99}.map-caption>span:last-child{display:block;margin-top:7px;color:#c4ccbd;font-size:12px}.map-switch,.map-switch>div,.map-switch>span{display:flex;align-items:center}.map-switch{justify-content:space-between;min-height:51px;padding:4px 13px 4px 20px;border-top:1px solid var(--border);font-size:13px}.map-switch>span{gap:10px}.layer-icon{font:24px var(--type);color:var(--accent)}.map-switch b{font:11px var(--mono);color:#c6cbbd;margin:0 6px}.square{width:36px;height:36px;border:1px solid var(--border);font:22px/1 var(--type);background:#272e29}.side{display:grid;grid-template-rows:auto 1fr;gap:14px}.action-panel,.weapon-sheet,.controls{padding:clamp(16px,2vw,27px)}.panel h2{font-size:clamp(20px,1.9vw,28px);letter-spacing:-.045em}.panel p{color:#b1b7ac;font-size:13px;line-height:1.5;margin:6px 0 19px}.primary,.secondary{display:flex;align-items:center;justify-content:center;gap:8px;min-height:44px;width:100%;padding:10px 14px;font-weight:700;font-size:14px}.primary{background:var(--accent);color:#21241d}.secondary{background:#303731;border:1px solid #51594e;color:var(--ink)}.action-panel .primary,.action-panel .secondary{justify-content:flex-start}.secondary{margin-top:8px}.arrow{margin-left:auto;font-size:18px}.button-icon{font:20px/1 var(--mono);width:20px}.practice-row{border-top:1px solid var(--border);margin-top:15px;padding-top:5px;display:flex;align-items:center;justify-content:space-between}.practice-row button{text-align:left;padding:9px 0;font-weight:600;font-size:13px;min-height:36px}.practice-row button span{margin-left:4px;color:var(--accent)}small,.loadout>span:last-child{color:var(--muted)}.practice-row small{font:10px var(--mono)}.loadout{text-align:left;padding:14px 19px 16px;display:grid;grid-template-columns:1fr auto;align-content:space-between}.card-label{color:#b8bfb0}.loadout .card-label{display:flex;justify-content:space-between;grid-column:1/-1}.card-label b{color:var(--accent)}#equipped-art{width:100%;height:clamp(57px,8vh,110px);object-fit:contain;grid-column:1/-1}.loadout strong{font-size:16px;letter-spacing:-.02em}.loadout>span:last-child{align-self:end;font:9px var(--mono);text-transform:uppercase}.armory-layout{display:grid;grid-template-columns:minmax(170px,.72fr) 1.5fr;gap:14px}.weapon-option{display:block;text-align:left;padding:15px;width:100%;border-bottom:1px solid var(--border)}.weapon-option strong,.weapon-option small{display:block}.weapon-option small{font:10px var(--mono);margin-top:4px}.weapon-option.active{background:#303930;box-shadow:inset 3px 0 var(--accent)}#weapon-art{width:100%;height:clamp(70px,16vh,160px);object-fit:contain;background:radial-gradient(ellipse,#363f35,transparent 70%)}.weapon-sheet h2{margin-top:5px}.weapon-sheet dl,.controls dl{font-size:13px;margin:12px 0 17px;display:grid;grid-template-columns:1fr auto;gap:0}.weapon-sheet dt,.weapon-sheet dd,.controls dt,.controls dd{margin:0;padding:7px 0;border-top:1px solid var(--border)}dt{color:var(--muted)}dd{font-family:var(--mono)}.controls{max-width:680px}.controls p{margin-bottom:0}dialog{background:#202622;color:var(--ink);border:1px solid #535d50;padding:20px;width:min(420px,94vw);max-height:92dvh;overflow:auto}dialog::backdrop{background:#070c0bd6}.dialog-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}.dialog-head h2{font-size:25px;letter-spacing:-.045em}.dialog-head button{flex:none}dialog label,.field-label{display:block;color:#bdc4b8;font-size:12px;margin:10px 0 7px}input{width:100%;padding:12px;background:#131815;color:var(--ink);border:1px solid #545e51;border-radius:0;margin:0 0 12px}.room-item,.roster-row{width:100%;padding:11px 0;border-top:1px solid var(--border);display:flex;align-items:center;text-align:left;justify-content:space-between;gap:10px;font-size:13px}.room-item small,.roster-row small{font:10px var(--mono)}.muted,#dialog-note{font-size:13px;line-height:1.45;color:var(--muted)}#dialog-note:not(:empty){margin-top:12px;color:#e1bd90}.room-actions{margin-top:12px}.room-actions .secondary{min-height:38px}.dialog-info{padding-bottom:12px}.result-list{padding:0;list-style:none}#game,#scene,.hud,#touch,#damage{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}#game{overflow:hidden;background:linear-gradient(#929f9e,#d4cdb5 58%,#a9a58a)}#scene{touch-action:none;outline:0}.hud,#touch{pointer-events:none;color:#f3f3e9;text-shadow:0 1px 3px #17201a}.game-top,.game-bottom{position:absolute;display:flex;align-items:flex-start;justify-content:space-between;left:16px;right:16px}.game-top{top:12px}.game-top>div:first-child,.game-bottom>div{background:#15201bd9;padding:6px 9px;border-left:2px solid var(--accent)}.game-top b{font:700 14px var(--type)}.game-top small,.game-bottom small{display:block;color:#e0e1d1;font-size:9px}.game-top button{pointer-events:auto;background:#18211ddc;border:1px solid #d8d5b761;height:38px;width:38px}.game-bottom{bottom:14px;align-items:end}.game-bottom strong{font:700 25px var(--type)}.hud-right{text-align:right}#round-clock{position:absolute;left:50%;transform:translate(-50%);font:600 15px var(--mono);background:#1c2521cf;padding:6px 10px}#cross,#hitmark{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font:22px monospace;color:#fff;text-shadow:0 0 2px #29332b}#hitmark{font-size:33px;color:#ffe8b2}#damage{background:radial-gradient(ellipse at var(--hit-x, 50%) var(--hit-y, 0%),#c82e1e 0%,#ab2115a8 9%,transparent 43%);opacity:0}#game-message{position:absolute;top:58%;width:100%;text-align:center;font:bold 16px var(--type)}#killfeed{position:absolute;top:65px;right:16px;font:11px var(--mono);background:#19251fc9;padding:4px 7px}#killfeed:empty{display:none}#touch{display:none}#stick,.touch-actions button{pointer-events:auto;touch-action:none;user-select:none;-webkit-user-select:none}#stick{position:absolute;left:17px;bottom:75px;border:1px solid #e9edcd99;background:#18241b77;border-radius:50%;width:84px;height:84px}#stick i{position:absolute;left:24px;top:24px;width:34px;height:34px;border-radius:50%;background:#cdd4b999}.touch-actions{position:absolute;right:12px;bottom:84px;display:grid;grid-template-columns:repeat(3,44px);gap:3px}.touch-actions button{min-height:44px;background:#18241ba3;border:1px solid #d4dbc27a;font:10px var(--mono)}.touch-actions button:last-child{color:#f5cb89;border-color:#e8bb70}#min-size{display:none}@media(pointer:coarse){#touch{display:block}.square,.game-top button,.practice-row button{min-width:44px;min-height:44px}}@media(min-width:1050px)and (min-height:630px){.plate{min-height:min(53vh,630px)}.side{grid-template-rows:1.25fr 1fr}.action-panel{display:flex;flex-direction:column;justify-content:center}.loadout{padding:22px}.loadout canvas#equipped-art{height:clamp(78px,13vh,170px)}}@media(max-width:680px){header{height:53px;gap:16px;padding:0 14px}.brand{font-size:18px;gap:5px}.mark{width:21px;height:18px}nav{margin-left:auto;gap:12px}nav button{font-size:12px}.link-status{display:none}.dashboard{grid-template-columns:1fr}.side{grid-template-columns:1.2fr 1fr;grid-template-rows:1fr}.plate{min-height:clamp(210px,35vh,350px)}main{padding:19px 14px}.page-heading{display:block}.metadata{font-size:9px;margin-top:7px}.map-caption{left:16px;bottom:13px}.map-caption h2{font-size:30px}.map-switch{min-height:45px}.action-panel,.loadout{padding:13px}.loadout{grid-template-columns:1fr}.loadout>span:last-child{margin-top:4px}.action-panel p{margin-bottom:12px}.armory-layout{grid-template-columns:1fr}#weapon-list{display:flex;overflow-x:auto}.weapon-option{min-width:109px;width:auto}.weapon-option.active{box-shadow:inset 0 -2px var(--accent)}}@media(max-width:440px){.side{grid-template-columns:1fr}.loadout{display:grid;grid-template-columns:1fr 100px;align-items:center;position:relative;min-height:82px}.loadout .card-label{grid-column:1;grid-row:1}.loadout .card-label b{display:none}#equipped-art{grid-column:2;grid-row:1/4;width:100px;height:65px}.loadout strong,.loadout>span:last-child{grid-column:1}.game-top,.game-bottom{left:8px;right:8px}.touch-actions{right:6px}.plate-tag{top:12px;left:13px}.north{top:9px;right:11px}}@media(max-height:410px)and (min-width:600px){header{height:43px}main{padding-top:12px}.page-heading{margin-bottom:10px}h1{font-size:28px}.plate{min-height:205px}.action-panel{padding:12px}.panel p{margin:3px 0 8px}.loadout canvas#equipped-art{height:38px}.practice-row{margin-top:6px}}@media(pointer:coarse)and (min-width:600px)and (max-height:410px){.touch-actions,#stick{bottom:18px}.game-bottom{left:116px;right:166px}}@media(max-width:500px){#round-clock{position:static;transform:none;margin-left:auto;margin-right:8px}}@media(max-width:279px),(max-height:209px){#min-size{display:grid;align-content:center;justify-items:center;gap:9px;position:fixed;top:0;right:0;bottom:0;left:0;background:var(--surface);font:600 14px var(--type);z-index:1000}#shell,#game,dialog[open]{visibility:hidden}}.roster{max-height:min(32dvh,250px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}.roster-row{min-height:33px;padding:8px 0}#scene[data-mouse-look=free],#scene[data-mouse-look=locked]{cursor:none}#dialog-body select{display:block;width:100%;padding:9px;margin:5px 0 10px;background:#29312c;color:#f3f3e9;border:1px solid #758174;font:inherit}.touch-actions button[data-action=swap]{min-height:44px}#dialog-body .field{display:grid;gap:4px;margin:8px 0;font:600 13px var(--type)}#dialog-body .field input,#dialog-body .field select{box-sizing:border-box;width:100%;min-height:40px}#dialog-body .field select{margin:0}#dialog-body .profile-status{font-size:12px;overflow-wrap:anywhere}.roster-row>span{overflow-wrap:anywhere;min-width:0}@media(max-width:520px){header nav{gap:0}header nav button{padding-inline:6px}}.match-actions{display:flex;gap:4px}.game-top #scores{width:auto;padding-inline:8px}#server-view,#server-menu,#game.spectating .game-bottom,#game.spectating #cross,#game.spectating #touch,#game.spectating #pause,#game.spectating #damage{display:none}#game.spectating #server-menu{display:inline-block;width:auto;padding-inline:8px}#game.spectating #server-view{display:block;position:absolute;top:0;right:0;bottom:0;left:0;pointer-events:none}#server-markers{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}.server-marker{position:absolute;transform:translate(-50%,-100%);padding:2px 5px;background:#17221eee;border-bottom:3px solid var(--accent);color:#fff;font:600 11px var(--type)}.server-marker.slate{border-color:#8dbcdc}#scoreboard{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:min(440px,95%);max-height:68%;overflow:auto;background:#19231ff2;color:#f3f3e9;border-top:2px solid var(--accent);padding:12px;pointer-events:auto;z-index:2}#scoreboard h2{margin:0 0 8px;font:bold 16px var(--type)}#scoreboard table{width:100%;border-collapse:collapse;font:12px var(--type)}#scoreboard :is(th,td){padding:5px 3px;text-align:right}#scoreboard :is(th,td):first-child{text-align:left;overflow-wrap:anywhere}#scoreboard th{border-bottom:1px solid #829080}.pad-mode :is(button,select,input):focus{outline:3px solid #ffcb66;outline-offset:2px}.pad-hint{display:none}.pad-mode .pad-hint{display:block;margin-top:.7rem}.pad-editor{max-width:min(28rem,90vw);max-height:90vh;overflow:auto}.pad-editor output{display:block;padding:.5rem 0;overflow-wrap:anywhere}.pad-keys{display:grid;gap:.3rem;margin:.5rem 0}.pad-keys button{padding:.45rem .25rem;min-width:0}
</style>
    <meta name="napplet-type" content="multiplayer-shooter">
    <meta name="napplet-requires" content="cvm,webrtc">
    <meta name="napplet-config-schema" content="{&quot;type&quot;:&quot;object&quot;,&quot;properties&quot;:{&quot;lookSensitivity&quot;:{&quot;type&quot;:&quot;number&quot;,&quot;title&quot;:&quot;Look sensitivity&quot;,&quot;minimum&quot;:0.3,&quot;maximum&quot;:2.5,&quot;default&quot;:1},&quot;renderScale&quot;:{&quot;type&quot;:&quot;number&quot;,&quot;title&quot;:&quot;Render resolution scale&quot;,&quot;minimum&quot;:0.5,&quot;maximum&quot;:1,&quot;default&quot;:1}}}">
  </head>
  <body>
    <div id="app">
      <div id="shell">
        <header>
          <div class="brand"><i class="mark" aria-hidden="true"></i>FAULTLINE</div>
          <nav aria-label="Game menu">
            <button data-page="play" class="selected">Operations</button
            ><button data-page="armory">Armory</button><button data-page="controls">Controls</button
            ><button id="settings">Settings</button>
          </nav>
          <div class="link-status"><i></i><span id="link-status">Standby</span></div>
        </header>
        <main id="play-page">
          <div class="page-heading">
            <h1>Deployment</h1>
            <div class="metadata">Room matches <span>/</span> 12 eliminations <span>/</span> 05:00</div>
          </div>
          <div class="dashboard">
            <section class="map-card">
              <div class="plate">
                <canvas id="plate" aria-label="Isometric preview of the selected arena"></canvas>
                <div class="plate-tag"><i class="corner-symbol"></i> Arena survey</div>
                <div class="north" aria-hidden="true">N<b>↑</b></div>
                <div class="map-caption">
                  <span id="sector" class="code"></span>
                  <h2 id="map-name"></h2>
                  <span id="map-type"></span>
                </div>
              </div>
              <div class="map-switch">
                <span><i class="layer-icon">▱</i> Battlefield</span>
                <div>
                  <button id="prev-map" class="square" aria-label="Previous battlefield">‹</button
                  ><b id="map-index"></b
                  ><button id="next-map" class="square" aria-label="Next battlefield">›</button>
                </div>
              </div>
            </section>
            <div class="side">
              <section class="panel action-panel">
                <h2>Multiplayer</h2>
                <p>Join a room for team deathmatch or free-for-all.</p>
                <button id="host" class="primary">
                  <span class="button-icon" aria-hidden="true">+</span>Create room<span
                    class="arrow"
                    aria-hidden="true"
                    >↗</span
                  >
                </button>
                <button id="browse" class="secondary">
                  <span class="button-icon" aria-hidden="true">≡</span>Browse rooms<span
                    class="arrow"
                    aria-hidden="true"
                    >›</span
                  >
                </button>
                <div class="practice-row">
                  <button id="practice">Solo practice <span aria-hidden="true">→</span></button
                  ><small>3 bots</small>
                </div>
              </section>
              <button class="loadout panel" id="open-loadout">
                <span class="card-label">Loadout <b>↗</b></span
                ><canvas id="equipped-art" aria-hidden="true"></canvas
                ><strong id="equipped-name"></strong><span id="equipped-type"></span>
              </button>
            </div>
          </div>
        </main>
        <main id="armory-page" hidden>
          <div class="page-heading">
            <h1>Armory</h1>
            <div class="metadata">Primary &amp; secondary weapons</div>
          </div>
          <div class="armory-layout">
            <div id="weapon-list"></div>
            <section class="weapon-sheet panel">
              <canvas id="weapon-art" aria-label="Selected weapon profile"></canvas>
              <div class="card-label" id="weapon-class"></div>
              <h2 id="weapon-name"></h2>
              <p id="weapon-desc"></p>
              <dl id="stats"></dl>
              <button class="primary" id="equip">Equip weapon</button>
            </section>
          </div>
        </main>
        <main id="controls-page" hidden>
          <div class="page-heading"><h1>Controls</h1></div>
          <section class="panel controls">
            <h2>Controller</h2>
            <dl>
              <dt>Menus / settings</dt><dd>D-pad or left stick · A select · B back · left/right change</dd>
              <dt>Move / look</dt><dd>Left / right stick · click left stick to sprint</dd>
              <dt>Fire / aim</dt><dd>Right / left trigger</dd>
              <dt>Jump / crouch</dt><dd>A / B</dd>
              <dt>Reload / swap weapon</dt><dd>X / Y · D-pad up/down selects a slot</dd>
              <dt>Grenade / lean</dt><dd>Hold LB and release to throw · D-pad left/right to lean</dd>
              <dt>Players / match menu</dt><dd>Hold View / press Menu</dd>
            </dl>
            <h2>Movement &amp; combat</h2>
            <dl>
              <dt>Move / sprint</dt>
              <dd>W A S D / Shift</dd>
              <dt>Look</dt>
              <dd>Capture mouse in the player · Esc releases · hold and drag middle mouse for continuous turns without capture · arrow keys</dd>
              <dt>Fire / aim down sights</dt>
              <dd>Left / right mouse or F / V</dd>
              <dt>Lean left / right</dt>
              <dd>Hold Q / E</dd>
              <dt>Jump / crouch</dt>
              <dd>Space / C · toggle by default</dd>
              <dt>Reload / cook grenade</dt>
              <dd>R / hold G, release to throw</dd>
              <dt>Primary / secondary</dt>
              <dd>1 / 2</dd>
              <dt>Player list and ping</dt>
              <dd>Hold Tab</dd>
              <dt>Match menu</dt>
              <dd>Esc / P</dd>
            </dl>
            <p>
              On touchscreens, move with the left pad and drag the scene to look. Tap ADS to toggle
              aiming. Hold FRAG to cook, release to throw, and tap SWAP to switch weapons.
            </p>
          </section>
        </main>
      </div>
      <div id="game" hidden>
        <canvas
          id="scene"
          tabindex="0"
          aria-label="First-person arena. Use WASD to move and F to fire."
        ></canvas>
        <div id="server-view" role="img" aria-label="Live bird’s-eye view of the arena">
          <div id="server-markers" aria-hidden="true"></div>
        </div>
        <div class="hud">
          <div class="game-top">
            <div><b id="hud-map"></b><small id="network-label"></small></div>
            <div id="round-clock"></div>
            <div class="match-actions">
              <button id="scores" aria-controls="scoreboard" aria-expanded="false">Players</button>
              <button id="pause" aria-label="Open match menu">Ⅱ</button>
              <button id="server-menu">Server</button>
            </div>
          </div>
          <section id="scoreboard" aria-labelledby="scores-title" hidden>
            <h2 id="scores-title">Players</h2>
            <table><thead><tr><th>Player</th><th>Team</th><th>K</th><th>D</th><th>Host ping</th></tr></thead>
              <tbody id="score-rows"></tbody>
            </table>
          </section>
          <div id="cross" aria-hidden="true">+</div>
          <div id="hitmark" hidden>×</div>
          <div id="damage"></div>
          <div id="killfeed" aria-live="polite"></div>
          <div id="game-message" role="status"></div>
          <div class="game-bottom">
            <div><small>Health</small><strong id="health"></strong></div>
            <div class="hud-right">
              <small id="gun-label"></small><strong id="ammo"></strong><small id="frags"></small>
            </div>
          </div>
        </div>
        <div id="touch">
          <div id="stick" aria-label="Move"><i></i></div>
          <div class="touch-actions">
            <button data-action="left" aria-label="Lean left">◀</button
            ><button data-action="swap">SWAP</button
            ><button data-action="right" aria-label="Lean right">▶</button
            ><button data-action="aim">ADS</button><button data-action="reload">RLD</button
            ><button data-action="throw">FRAG</button><button data-action="jump">JUMP</button
            ><button data-action="duck">LOW</button><button data-action="fire">FIRE</button>
          </div>
        </div>
      </div>
      <dialog id="dialog">
        <div class="dialog-head">
          <h2 id="dialog-title"></h2>
          <button id="dismiss" class="square" aria-label="Close">×</button>
        </div>
        <div id="dialog-body"></div>
        <small class="pad-hint">D-pad to move · A to select · B to go back</small>
        <p id="dialog-note" role="status"></p>
      </dialog>
      <div id="min-size">Enlarge the frame to play.<small>280 × 210 minimum</small></div>
    </div>
  </body>
</html>