Files
2026-10-19 14:26:34 +03:30

206 lines
29 KiB
JavaScript

(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))t(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&t(a)}).observe(document,{childList:!0,subtree:!0});function r(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function t(s){if(s.ep)return;s.ep=!0;const o=r(s);fetch(s.href,o)}})();function ot(e){const c=new URLSearchParams(location.search).get("host")??"*",r=s=>window.parent.postMessage({m3:1,...s},c);let t=0;return window.addEventListener("message",s=>{var a,d,u;if(s.source!==window.parent||c!=="*"&&s.origin!==c)return;const o=s.data;if(!(!o||o.m3!==1))switch(o.type){case"init":e.onInit(o),r({type:"ready"});break;case"state":e.onState(o.env);break;case"ack":(a=e.onAck)==null||a.call(e,o);break;case"view_changed":(d=e.onViewChanged)==null||d.call(e,o.view);break;case"cmd_failed":(u=e.onCmdFailed)==null||u.call(e,o.req_id,o.code);break}}),r({type:"loaded"}),{cmd(s,o={}){const a=++t;return r({type:"cmd",cmd_type:s,payload:o,req_id:a}),a},toast(s,o,a="info"){r({type:"toast",text_fa:s,text_en:o,kind:a})}}}const E=`
<defs>
<linearGradient id="cp-w-body" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#ffffff"/>
<stop offset="35%" stop-color="#f8fafc"/>
<stop offset="70%" stop-color="#e2e8f0"/>
<stop offset="100%" stop-color="#94a3b8"/>
</linearGradient>
<linearGradient id="cp-w-spec" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="#ffffff" stop-opacity="0.95"/>
<stop offset="60%" stop-color="#ffffff" stop-opacity="0.3"/>
<stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
</linearGradient>
<linearGradient id="cp-w-gold" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#fef08a"/>
<stop offset="30%" stop-color="#f59e0b"/>
<stop offset="70%" stop-color="#d97706"/>
<stop offset="100%" stop-color="#78350f"/>
</linearGradient>
<radialGradient id="cp-ruby" cx="35%" cy="30%" r="70%">
<stop offset="0%" stop-color="#fda4af"/>
<stop offset="35%" stop-color="#f43f5e"/>
<stop offset="75%" stop-color="#be123c"/>
<stop offset="100%" stop-color="#4c0519"/>
</radialGradient>
<radialGradient id="cp-pearl" cx="30%" cy="30%" r="70%">
<stop offset="0%" stop-color="#ffffff"/>
<stop offset="45%" stop-color="#fef08a"/>
<stop offset="85%" stop-color="#f59e0b"/>
<stop offset="100%" stop-color="#b45309"/>
</radialGradient>
</defs>
`,P=`
<defs>
<linearGradient id="cp-b-body" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#334155"/>
<stop offset="25%" stop-color="#1e293b"/>
<stop offset="65%" stop-color="#0f172a"/>
<stop offset="100%" stop-color="#020617"/>
</linearGradient>
<linearGradient id="cp-b-spec" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#94a3b8" stop-opacity="0.9"/>
<stop offset="45%" stop-color="#64748b" stop-opacity="0.35"/>
<stop offset="100%" stop-color="#0f172a" stop-opacity="0"/>
</linearGradient>
<linearGradient id="cp-b-gold" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#fde047"/>
<stop offset="30%" stop-color="#eab308"/>
<stop offset="70%" stop-color="#ca8a04"/>
<stop offset="100%" stop-color="#581c87"/>
</linearGradient>
<radialGradient id="cp-sapphire" cx="35%" cy="30%" r="70%">
<stop offset="0%" stop-color="#93c5fd"/>
<stop offset="35%" stop-color="#38bdf8"/>
<stop offset="75%" stop-color="#1d4ed8"/>
<stop offset="100%" stop-color="#091e60"/>
</radialGradient>
<radialGradient id="cp-amethyst" cx="30%" cy="30%" r="70%">
<stop offset="0%" stop-color="#e9d5ff"/>
<stop offset="45%" stop-color="#a855f7"/>
<stop offset="85%" stop-color="#6b21a8"/>
<stop offset="100%" stop-color="#2e1065"/>
</radialGradient>
</defs>
`;function rt(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 18 90 C 20 84, 30 82, 50 82 C 70 82, 80 84, 82 90 L 82 93 C 82 95, 78 96, 50 96 C 22 96, 18 95, 18 93 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="28" ry="3.5" fill="${o}"/>
<path d="M 27 82 C 29 74, 34 68, 38 52 C 40 44, 42 42, 42 42 L 58 42 C 58 42, 60 44, 62 52 C 66 68, 71 74, 73 82 Z" fill="${t}"/>
<path d="M 33 80 C 35 73, 40 60, 42 50 C 45 49, 48 50, 48 51 C 45 61, 41 72, 38 80 Z" fill="${s}" stroke="none"/>
<ellipse cx="50" cy="42" rx="14" ry="4" fill="${o}"/>
<ellipse cx="50" cy="39" rx="11" ry="3" fill="${t}"/>
<circle cx="50" cy="24" r="14" fill="${t}"/>
<ellipse cx="44" cy="18" rx="6" ry="3.5" transform="rotate(-30 44 18)" fill="#ffffff" opacity="${e?"0.85":"0.5"}" stroke="none"/>
<circle cx="50" cy="9.5" r="2.5" fill="${o}"/>
<path d="M 21 89 C 30 85, 70 85, 79 89" fill="none" stroke="${e?"#e2e8f0":"#64748b"}" stroke-width="1.2" opacity="0.6"/>
</g>
</svg>`}function st(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)",a=e?"url(#cp-ruby)":"url(#cp-sapphire)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 18 90 C 20 84, 30 82, 50 82 C 70 82, 80 84, 82 90 L 82 93 C 82 95, 78 96, 50 96 C 22 96, 18 95, 18 93 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="29" ry="3.5" fill="${o}"/>
<path d="M 25 82 C 32 72, 38 60, 34 50 C 31 46, 24 47, 18 43 C 14 40, 15 35, 19 32 C 24 29, 32 30, 36 24 C 40 18, 44 14, 52 11 L 55 18 C 58 14, 62 12, 65 14 C 67 15, 66 18, 64 22 C 74 26, 78 40, 77 56 C 76 68, 73 76, 75 82 Z" fill="${t}"/>
<path d="M 64 22 C 70 24, 76 29, 78 36 C 73 34, 68 33, 65 34 C 72 38, 77 44, 78 52 C 73 50, 68 49, 65 51 C 72 55, 75 62, 76 70 C 72 68, 68 67, 66 69" fill="none" stroke="${o}" stroke-width="2.6"/>
<path d="M 36 24 C 44 32, 48 44, 45 52 C 40 56, 34 52, 34 50" fill="none" stroke="${r}" stroke-width="1.8"/>
<path d="M 52 24 C 58 34, 60 52, 58 72 C 54 74, 48 74, 46 72 C 50 56, 48 38, 44 26 Z" fill="${s}" stroke="none"/>
<ellipse cx="20" cy="38" rx="2.5" ry="1.5" transform="rotate(-20 20 38)" fill="${r}"/>
<path d="M 17 41 C 21 44, 25 43, 27 41" fill="none" stroke="${r}" stroke-width="1.5"/>
<ellipse cx="36" cy="27" rx="3.5" ry="2.2" transform="rotate(-15 36 27)" fill="${a}"/>
<circle cx="35" cy="26" r="1" fill="#ffffff" stroke="none"/>
<path d="M 33 66 C 42 70, 58 70, 67 66 L 68 71 C 58 75, 42 75, 32 71 Z" fill="${o}"/>
<circle cx="50" cy="71" r="4.5" fill="${o}"/>
<circle cx="50" cy="71" r="2.5" fill="${a}"/>
</g>
</svg>`}function ct(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 20 90 C 22 84, 30 82, 50 82 C 70 82, 78 84, 80 90 L 80 93 C 80 95, 76 96, 50 96 C 24 96, 20 95, 20 93 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="27" ry="3.5" fill="${o}"/>
<path d="M 29 82 C 31 72, 38 64, 40 52 L 60 52 C 62 64, 69 72, 71 82 Z" fill="${t}"/>
<path d="M 35 80 C 37 72, 42 62, 44 54 C 47 54, 49 55, 49 56 C 45 66, 42 74, 39 80 Z" fill="${s}" stroke="none"/>
<path d="M 38 52 C 44 55, 56 55, 62 52 L 63 56 C 56 59, 44 59, 37 56 Z" fill="${o}"/>
<path d="M 36 50 C 33 42, 32 30, 42 19 C 46 15, 49 13, 50 13 C 51 13, 54 15, 58 19 C 68 30, 67 42, 64 50 Z" fill="${t}"/>
<path d="M 58 22 L 40 40 L 44 43 L 61 24 Z" fill="${o}"/>
<path d="M 50 28 L 50 42 M 45 33 L 55 33" stroke="${o}" stroke-width="2.6"/>
<circle cx="50" cy="11" r="3.5" fill="${o}"/>
<circle cx="50" cy="11" r="1.8" fill="${e?"url(#cp-ruby)":"url(#cp-sapphire)"}" stroke="none"/>
<path d="M 40 24 C 36 30, 36 40, 39 46 C 40 46, 42 45, 42 44 C 40 38, 41 30, 43 25 Z" fill="${s}" stroke="none"/>
</g>
</svg>`}function at(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 18 90 C 20 84, 30 82, 50 82 C 70 82, 80 84, 82 90 L 82 93 C 82 95, 78 96, 50 96 C 22 96, 18 95, 18 93 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="29" ry="3.5" fill="${o}"/>
<path d="M 26 82 L 31 34 L 69 34 L 74 82 Z" fill="${t}"/>
<path d="M 31 80 L 35 36 L 43 36 L 39 80 Z" fill="${s}" stroke="none"/>
<path d="M 23 34 L 77 34 L 75 27 L 25 27 Z" fill="${o}"/>
<rect x="28" y="29" width="6" height="4" fill="${t}"/>
<rect x="40" y="29" width="6" height="4" fill="${t}"/>
<rect x="54" y="29" width="6" height="4" fill="${t}"/>
<rect x="66" y="29" width="6" height="4" fill="${t}"/>
<path d="M 24 27 L 24 14 L 33 14 L 33 20 L 44 20 L 44 14 L 56 14 L 56 20 L 67 20 L 67 14 L 76 14 L 76 27 Z" fill="${t}"/>
<path d="M 23 14 L 34 14 M 43 14 L 57 14 M 66 14 L 77 14" stroke="${o}" stroke-width="2"/>
<path d="M 48 46 C 48 43, 52 43, 52 46 L 52 64 L 48 64 Z" fill="${r}"/>
<circle cx="50" cy="46" r="1.5" fill="${o}"/>
<path d="M 33 55 L 67 55" stroke="${r}" stroke-width="1.2" opacity="0.4"/>
</g>
</svg>`}function nt(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)",a=e?"url(#cp-ruby)":"url(#cp-sapphire)",d=e?"url(#cp-pearl)":"url(#cp-amethyst)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 18 90 C 20 84, 30 82, 50 82 C 70 82, 80 84, 82 90 L 82 93 C 82 95, 78 96, 50 96 C 22 96, 18 95, 18 93 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="29" ry="3.5" fill="${o}"/>
<path d="M 27 82 C 29 68, 38 60, 41 48 L 59 48 C 62 60, 71 68, 73 82 Z" fill="${t}"/>
<path d="M 32 80 C 35 68, 41 58, 44 50 C 47 49, 49 50, 49 52 C 45 64, 40 74, 37 80 Z" fill="${s}" stroke="none"/>
<path d="M 38 48 C 44 51, 56 51, 62 48 L 63 53 C 56 56, 44 56, 37 53 Z" fill="${o}"/>
<path d="M 40 48 C 37 40, 31 34, 28 32 L 72 32 C 69 34, 63 40, 60 48 Z" fill="${t}"/>
<path d="M 28 32 L 20 18 L 34 26 L 50 12 L 66 26 L 80 18 L 72 32 Z" fill="${t}"/>
<path d="M 27 32 C 40 35, 60 35, 73 32 L 73 35 C 60 38, 40 38, 27 35 Z" fill="${o}"/>
<circle cx="20" cy="17" r="3.2" fill="${d}"/>
<circle cx="34" cy="25" r="3.2" fill="${d}"/>
<circle cx="50" cy="11" r="4.2" fill="${d}"/>
<circle cx="66" cy="25" r="3.2" fill="${d}"/>
<circle cx="80" cy="17" r="3.2" fill="${d}"/>
<ellipse cx="50" cy="40" rx="3.5" ry="4.5" fill="${a}"/>
<circle cx="49" cy="38" r="1.2" fill="#ffffff" stroke="none"/>
</g>
</svg>`}function lt(e){const c=e?E:P,r=e?"#0f172a":"#020617",t=e?"url(#cp-w-body)":"url(#cp-b-body)",s=e?"url(#cp-w-spec)":"url(#cp-b-spec)",o=e?"url(#cp-w-gold)":"url(#cp-b-gold)";return`<svg viewBox="0 0 100 100" class="piece-svg piece-${e?"w":"b"}" xmlns="http://www.w3.org/2000/svg">
${c}
<g stroke="${r}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M 16 90 C 18 84, 28 82, 50 82 C 72 82, 82 84, 84 90 L 84 94 C 84 96, 78 97, 50 97 C 22 97, 16 96, 16 94 Z" fill="${t}"/>
<ellipse cx="50" cy="83" rx="31" ry="3.8" fill="${o}"/>
<path d="M 25 82 C 27 68, 36 58, 38 46 L 62 46 C 64 58, 73 68, 75 82 Z" fill="${t}"/>
<path d="M 30 80 C 33 68, 40 56, 42 48 C 45 47, 48 48, 48 50 C 44 62, 38 74, 35 80 Z" fill="${s}" stroke="none"/>
<path d="M 34 46 C 42 49, 58 49, 66 46 L 67 51 C 58 54, 42 54, 33 51 Z" fill="${o}"/>
<path d="M 33 46 C 28 38, 28 28, 50 24 C 72 28, 72 38, 67 46 Z" fill="${t}"/>
<path d="M 50 24 L 50 46 M 34 36 C 42 34, 58 34, 66 36" stroke="${o}" stroke-width="2.6"/>
<ellipse cx="50" cy="46" rx="16" ry="3.5" fill="${o}"/>
<path d="M 46 24 L 54 24 L 52 19 L 48 19 Z" fill="${o}"/>
<path d="M 48 19 L 42 16 L 44 11 L 47 13 L 47 6 L 53 6 L 53 13 L 56 11 L 58 16 L 52 19 Z" fill="${o}"/>
<circle cx="50" cy="13" r="2.8" fill="${e?"url(#cp-ruby)":"url(#cp-sapphire)"}"/>
<circle cx="49" cy="12" r="0.9" fill="#ffffff" stroke="none"/>
</g>
</svg>`}const it={p:rt,n:st,b:ct,r:at,q:nt,k:lt},T={};function _(e,c){if(!e||!c)return"";const r=`${e}-${c}`;if(!T[r]){const t=it[e];t&&(T[r]=t(c==="w"))}return T[r]??""}class dt{constructor(c){this.particles=[],this.shockwaves=[],this.animId=null,this.lastTime=0,this.canvas=c,this.ctx=c.getContext("2d"),this.resize(),window.addEventListener("resize",()=>this.resize()),this.startLoop()}resize(){var t,s,o;const c=(t=this.canvas.parentElement)==null?void 0:t.getBoundingClientRect();if(!c)return;const r=window.devicePixelRatio||1;this.canvas.width=Math.round(c.width*r),this.canvas.height=Math.round(c.height*r),this.canvas.style.width=`${c.width}px`,this.canvas.style.height=`${c.height}px`,(o=(s=this.ctx).resetTransform)==null||o.call(s),this.ctx.scale(r,r)}startLoop(){if(this.animId)return;const c=r=>{const t=this.lastTime?Math.min((r-this.lastTime)/1e3,.1):.016;this.lastTime=r,this.update(t),this.render(),this.animId=requestAnimationFrame(c)};this.animId=requestAnimationFrame(c)}update(c){for(let r=this.shockwaves.length-1;r>=0;r--){const t=this.shockwaves[r];t.radius+=(t.maxRadius-t.radius)*12*c,t.alpha-=t.decay*c,(t.alpha<=0||t.radius>=t.maxRadius*.98)&&this.shockwaves.splice(r,1)}for(let r=this.particles.length-1;r>=0;r--){const t=this.particles[r];t.x+=t.vx*c,t.y+=t.vy*c,t.vx*=Math.pow(t.drag,c*60),t.vy*=Math.pow(t.drag,c*60),t.vy+=t.gravity*c,t.vRot&&t.rotation!==void 0&&(t.rotation+=t.vRot*c),t.alpha-=t.decay*c,t.alpha<=0&&this.particles.splice(r,1)}}render(){const c=this.canvas.width/(window.devicePixelRatio||1),r=this.canvas.height/(window.devicePixelRatio||1);this.ctx.clearRect(0,0,c,r);for(const t of this.shockwaves)this.ctx.save(),this.ctx.beginPath(),this.ctx.arc(t.x,t.y,Math.max(1,t.radius),0,Math.PI*2),this.ctx.strokeStyle=t.color,this.ctx.globalAlpha=Math.max(0,t.alpha),this.ctx.lineWidth=t.lineWidth,this.ctx.stroke(),this.ctx.restore();for(const t of this.particles){if(this.ctx.save(),this.ctx.globalAlpha=Math.max(0,t.alpha),this.ctx.fillStyle=t.color,t.shape==="rect"||t.shape==="spark"){this.ctx.translate(t.x,t.y),t.rotation!==void 0&&this.ctx.rotate(t.rotation);const s=t.size||t.radius*2;t.shape==="spark"?this.ctx.fillRect(-s,-s*.25,s*2,s*.5):this.ctx.fillRect(-s*.5,-s*.5,s,s)}else this.ctx.beginPath(),this.ctx.arc(t.x,t.y,Math.max(.5,t.radius),0,Math.PI*2),this.ctx.fill();this.ctx.restore()}}captureImpact(c,r,t="w"){this.shockwaves.push({x:c,y:r,radius:4,maxRadius:48,color:t==="w"?"rgba(255, 235, 180, 0.9)":"rgba(120, 140, 180, 0.9)",alpha:.9,decay:2.8,lineWidth:3});const s=t==="w"?["#ffffff","#fef08a","#f59e0b","#fbbf24"]:["#94a3b8","#cbd5e1","#64748b","#38bdf8"],o=18;for(let a=0;a<o;a++){const d=Math.PI*2*a/o+(Math.random()-.5)*.5,u=120+Math.random()*220;this.particles.push({x:c,y:r,vx:Math.cos(d)*u,vy:Math.sin(d)*u,radius:2+Math.random()*2.5,color:s[Math.floor(Math.random()*s.length)],alpha:1,decay:1.8+Math.random()*1.4,gravity:80,drag:.92,shape:"spark",size:3+Math.random()*3,rotation:d})}for(let a=0;a<6;a++){const d=Math.random()*Math.PI*2,u=25+Math.random()*45;this.particles.push({x:c+(Math.random()-.5)*12,y:r+(Math.random()-.5)*12,vx:Math.cos(d)*u,vy:Math.sin(d)*u,radius:4+Math.random()*6,color:"rgba(200, 200, 210, 0.4)",alpha:.6,decay:1.2,gravity:-10,drag:.88,shape:"circle"})}}landingPuff(c,r){for(let t=0;t<8;t++){const s=20+Math.random()*40;this.particles.push({x:c+(Math.random()-.5)*10,y:r+10,vx:(Math.random()-.5)*s,vy:-Math.random()*20,radius:2.5+Math.random()*3,color:"rgba(220, 220, 230, 0.35)",alpha:.5,decay:2,gravity:15,drag:.85,shape:"circle"})}}promotionBurst(c,r){this.shockwaves.push({x:c,y:r,radius:6,maxRadius:60,color:"rgba(251, 191, 36, 0.95)",alpha:1,decay:2,lineWidth:4});const t=["#fbbf24","#fef08a","#60a5fa","#a78bfa","#ffffff"];for(let s=0;s<28;s++){const o=Math.random()*Math.PI*2,a=60+Math.random()*180;this.particles.push({x:c,y:r,vx:Math.cos(o)*a,vy:Math.sin(o)*a-50,radius:2+Math.random()*3,color:t[Math.floor(Math.random()*t.length)],alpha:1,decay:1.2+Math.random()*1,gravity:-30,drag:.94,shape:"rect",size:3+Math.random()*4,rotation:Math.random()*Math.PI*2,vRot:(Math.random()-.5)*10})}}victoryConfetti(){const c=this.canvas.width/(window.devicePixelRatio||1),r=this.canvas.height/(window.devicePixelRatio||1),t=["#ef4444","#3b82f6","#10b981","#f59e0b","#8b5cf6","#ec4899","#ffffff","#fbbf24"];for(let s=0;s<90;s++){const o=c*.5+(Math.random()-.5)*100,a=r*.45+(Math.random()-.5)*50,d=-Math.PI*.5+(Math.random()-.5)*Math.PI*.85,u=180+Math.random()*360;this.particles.push({x:o,y:a,vx:Math.cos(d)*u,vy:Math.sin(d)*u,radius:3+Math.random()*3,color:t[Math.floor(Math.random()*t.length)],alpha:1,decay:.4+Math.random()*.3,gravity:160,drag:.97,shape:"rect",size:5+Math.random()*5,rotation:Math.random()*Math.PI*2,vRot:(Math.random()-.5)*12})}}}function H(e){return{f:e.charCodeAt(0)-97,r:parseInt(e[1],10)-1}}function v(e,c){return String.fromCharCode(97+e)+(c+1)}function D(e,c,r){const t=new Map;for(const l of c)t.set(l.square,l);const s=t.get(e);if(!s||!s.type||s.color!==r)return[];const{f:o,r:a}=H(e),d=[],u=(l,p)=>{if(l<0||l>7||p<0||p>7)return!1;const g=v(l,p),i=t.get(g);return!i||!i.color?(d.push({target:g,isCapture:!1}),!0):(i.color!==r&&d.push({target:g,isCapture:!0}),!1)};switch(s.type){case"p":{const l=r==="w"?1:-1,p=r==="w"?1:6,g=v(o,a+l),i=t.get(g);if(i&&!i.color&&(d.push({target:g,isCapture:!1}),a===p)){const f=v(o,a+l*2),h=t.get(f);h&&!h.color&&d.push({target:f,isCapture:!1})}for(const f of[-1,1])if(o+f>=0&&o+f<=7){const h=v(o+f,a+l),y=t.get(h);y&&y.color&&y.color!==r&&d.push({target:h,isCapture:!0})}break}case"n":{const l=[[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]];for(const[p,g]of l){const i=o+p,f=a+g;if(i>=0&&i<=7&&f>=0&&f<=7){const h=v(i,f),y=t.get(h);!y||!y.color?d.push({target:h,isCapture:!1}):y.color!==r&&d.push({target:h,isCapture:!0})}}break}case"b":{const l=[[-1,-1],[-1,1],[1,-1],[1,1]];for(const[p,g]of l){let i=o+p,f=a+g;for(;u(i,f);)i+=p,f+=g}break}case"r":{const l=[[-1,0],[1,0],[0,-1],[0,1]];for(const[p,g]of l){let i=o+p,f=a+g;for(;u(i,f);)i+=p,f+=g}break}case"q":{const l=[[-1,-1],[-1,1],[1,-1],[1,1],[-1,0],[1,0],[0,-1],[0,1]];for(const[p,g]of l){let i=o+p,f=a+g;for(;u(i,f);)i+=p,f+=g}break}case"k":{for(let p=-1;p<=1;p++)for(let g=-1;g<=1;g++){if(p===0&&g===0)continue;const i=o+p,f=a+g;if(i>=0&&i<=7&&f>=0&&f<=7){const h=v(i,f),y=t.get(h);!y||!y.color?d.push({target:h,isCapture:!1}):y.color!==r&&d.push({target:h,isCapture:!0})}}const l=r==="w"?0:7;if(a===l&&o===4){const p=t.get(v(5,l)),g=t.get(v(6,l)),i=t.get(v(7,l));p&&!p.color&&g&&!g.color&&(i==null?void 0:i.type)==="r"&&i.color===r&&d.push({target:v(6,l),isCapture:!1});const f=t.get(v(3,l)),h=t.get(v(2,l)),y=t.get(v(1,l)),m=t.get(v(0,l));f&&!f.color&&h&&!h.color&&y&&!y.color&&(m==null?void 0:m.type)==="r"&&m.color===r&&d.push({target:v(2,l),isCapture:!1})}break}}return d.filter(l=>!ft(e,l.target,c,r))}function ft(e,c,r,t){const s=r.map(i=>{if(i.square===e)return{square:e,type:null,color:null};if(i.square===c){const f=r.find(h=>h.square===e);return{square:c,type:(f==null?void 0:f.type)??null,color:t}}return{...i}}),o=s.find(i=>i.type==="k"&&i.color===t);if(!o)return!1;const{f:a,r:d}=H(o.square),u=t==="w"?"b":"w",l=new Map;for(const i of s)l.set(i.square,i);const p=[[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]];for(const[i,f]of p){const h=a+i,y=d+f;if(h>=0&&h<=7&&y>=0&&y<=7){const m=l.get(v(h,y));if(m&&m.color===u&&m.type==="n")return!0}}const g=u==="w"?1:-1;for(const i of[-1,1]){const f=a-i,h=d-g;if(f>=0&&f<=7&&h>=0&&h<=7){const y=l.get(v(f,h));if(y&&y.color===u&&y.type==="p")return!0}}for(const[i,f]of[[-1,0],[1,0],[0,-1],[0,1]]){let h=a+i,y=d+f;for(;h>=0&&h<=7&&y>=0&&y<=7;){const m=l.get(v(h,y));if(m&&m.color){if(m.color===u&&(m.type==="r"||m.type==="q"))return!0;break}h+=i,y+=f}}for(const[i,f]of[[-1,-1],[-1,1],[1,-1],[1,1]]){let h=a+i,y=d+f;for(;h>=0&&h<=7&&y>=0&&y<=7;){const m=l.get(v(h,y));if(m&&m.color){if(m.color===u&&(m.type==="b"||m.type==="q"))return!0;break}h+=i,y+=f}}for(let i=-1;i<=1;i++)for(let f=-1;f<=1;f++){if(i===0&&f===0)continue;const h=a+i,y=d+f;if(h>=0&&h<=7&&y>=0&&y<=7){const m=l.get(v(h,y));if(m&&m.color===u&&m.type==="k")return!0}}return!1}let n=null,F=null,Z=null,$=null,C="",M=[],x=null,R=null,N=!1;const w=(e,c)=>(Z==null?void 0:Z.locale)==="en"?c:e,O=ot({onInit(e){Z=e,document.documentElement.lang=e.locale,document.documentElement.dir=e.dir,document.getElementById("board-grid")||j(),k()},onState(e){e.t==="snap"&&(document.getElementById("board-grid")||j(),F=n,n=e.body,pt(F,n),n.turn!==n.me&&(C="",M=[],x=null),k())},onAck(e){e.status==="rejected"&&O.toast("حرکت پذیرفته نشد","Move not accepted","warn")}});function pt(e,c){var d;if(!e||!c||!$)return;const r=new Map(e.board.map(u=>[u.square,u])),t=new Map(c.board.map(u=>[u.square,u]));let s="",o="",a=null;for(const[u,l]of t.entries()){const p=r.get(u);p&&(p.color&&!l.color?s=u:l.color&&(!p.color||p.color!==l.color||p.type!==l.type)&&(o=u,p.color&&p.color!==l.color&&(a=p)))}if(s&&o){R={from:s,to:o};const u=document.querySelector(`[data-square="${o}"]`);if(u){const l=u.getBoundingClientRect(),p=(d=document.getElementById("vfx-canvas"))==null?void 0:d.getBoundingClientRect();if(p){const i=l.left-p.left+l.width/2,f=l.top-p.top+l.height/2;a?$.captureImpact(i,f,a.color):$.landingPuff(i,f)}const g=u.querySelector(".piece-wrapper");g&&(g.classList.remove("anim-land"),g.offsetWidth,g.classList.add("anim-land"))}}c.phase==="over"&&c.winner!==null&&!N&&(N=!0,setTimeout(()=>$==null?void 0:$.victoryConfetti(),350))}function j(){const e=document.getElementById("app");e.innerHTML=`
<div id="top-bar" class="player-bar"></div>
<div class="board-container">
<canvas id="vfx-canvas"></canvas>
<div id="board-grid" class="board-grid"></div>
</div>
<div id="bottom-bar" class="player-bar"></div>
<div id="modal-container"></div>
`;const c=document.getElementById("vfx-canvas");$=new dt(c);const r=document.getElementById("board-grid");r.addEventListener("click",t=>{const s=t.target.closest(".cell");s&&s.dataset.square&&!s.disabled&&yt(s.dataset.square)});for(let t=0;t<64;t++){const s=document.createElement("button");s.className="cell",s.dataset.index=String(t),r.appendChild(s)}}function k(){var m;if(!n)return;const e=n.me,c=e!=null&&n.players[e]!==void 0;let r,t;c?(r=n.players[e],t=n.players.find(b=>b.seat!==e)||n.players[1-e]):(r=n.players.find(b=>b.color==="w")||n.players[0],t=n.players.find(b=>b.color==="b")||n.players[1]);const s=(r==null?void 0:r.color)||"w",o=s==="b",a=r?n.turn===r.seat&&n.phase==="play":!1,d=t?n.turn===t.seat&&n.phase==="play":!1;z("top-bar",t,d,!1),z("bottom-bar",r,a,c);const u=new Map;for(const b of n.board)u.set(b.square,b);const l=o?[7,6,5,4,3,2,1,0]:[0,1,2,3,4,5,6,7],p=o?[0,1,2,3,4,5,6,7]:[7,6,5,4,3,2,1,0],g=document.getElementById("board-grid");if(!g)return;const i=g.children;let f=0;const h=n.phase==="play"&&n.turn===e,y=n.check&&n.phase==="play"?(m=n.board.find(b=>{var L;return b.type==="k"&&b.color===((L=n.players[n.turn])==null?void 0:L.color)}))==null?void 0:m.square:null;for(const b of p)for(const L of l){const I=String.fromCharCode(97+L)+(b+1),q=u.get(I)||{type:null,color:null},S=i[f++];S.dataset.square=I,S.dataset.color=q.color||"";const K=(L+b)%2===0?"dark":"light",A=C===I,U=R&&(R.from===I||R.to===I),V=y===I;S.className=`cell ${K}`+(A?" selected":"")+(U?" last-move":"")+(V?" in-check":"");const Y=M.some(B=>B.target===I),Q=M.some(B=>B.target===I&&B.isCapture);let G="";const J=o?L===7:L===0,X=o?b===7:b===0;if(J&&(G+=`<span class="coord-rank">${b+1}</span>`),X&&(G+=`<span class="coord-file">${String.fromCharCode(97+L)}</span>`),q.type&&q.color){const B=_(q.type,q.color),et=q.type==="n"&&A?" anim-knight":"";G+=`<div class="piece-wrapper${et}">${B}</div>`}Q?G+='<div class="capture-ring"></div>':Y&&(G+='<div class="move-dot"></div>'),S.innerHTML=G;const W=h&&!0&&q.color===s,tt=C?h:W;S.disabled=!tt}gt()}function z(e,c,r,t){const s=document.getElementById(e);if(!s||!c||!n)return;s.className="player-bar"+(r?" active":"");const o=ut(c.color),a=ht(c.color),d=a>0?`<span class="advantage-score">+${a}</span>`:"",u=c.bot?'<span class="bot-tag">BOT</span>':"",l=t?`<span class="bot-tag you-tag">${w("شما","YOU")}</span>`:"",p=n.phase==="over"?n.winner===c.seat?w("برنده 🏆","Winner 🏆"):n.winner===null?w("تساوی 🤝","Draw 🤝"):"":r?t?w("نوبت شماست","Your turn"):w("در حال تفکر…","Thinking…"):"";s.innerHTML=`
<div class="player-profile">
<div class="player-badge ${c.color}">
${c.color==="w"?"♔":"♚"}
</div>
<div class="player-meta">
<div class="player-name">${c.name} ${u} ${l}</div>
<div class="player-status">${p}</div>
</div>
</div>
<div class="captured-tray">
${o.map(g=>`<div class="mini-piece">${_(g.type,g.color)}</div>`).join("")}
${d}
</div>
`}function ut(e){if(!n)return[];const c=e==="w"?"b":"w",r={p:8,n:2,b:2,r:2,q:1},t={p:0,n:0,b:0,r:0,q:0};for(const o of n.board)o.color===c&&o.type&&t[o.type]!==void 0&&t[o.type]++;const s=[];for(const o of["q","r","b","n","p"]){const a=r[o]-(t[o]||0);for(let d=0;d<a;d++)s.push({square:"",type:o,color:c})}return s}function ht(e){if(!n)return 0;const c={p:1,n:3,b:3,r:5,q:9};let r=0,t=0;for(const s of n.board){if(!s.type||!s.color)continue;const o=c[s.type]||0;s.color===e?r+=o:t+=o}return r-t}function gt(){var c,r,t;const e=document.getElementById("modal-container");if(!(!e||!n)){if(x){const s=n.me!==null&&n.me!==void 0?(c=n.players[n.me])==null?void 0:c.color:"w";e.innerHTML=`
<div class="modal-backdrop">
<div class="promo-card">
<div class="promo-title">${w("ارتقای پیاده به:","Promote pawn to:")}</div>
<div class="promo-options">
${["q","r","b","n"].map(o=>`
<button class="promo-piece-btn" data-promo="${o}" title="${o}">
${_(o,s)}
</button>
`).join("")}
</div>
<button class="promo-cancel-btn" data-cancel-promo="1">${w("لغو","Cancel")}</button>
</div>
</div>
`,e.querySelectorAll("[data-promo]").forEach(o=>{o.addEventListener("click",()=>{var d;const a=o.dataset.promo;if(x&&a){O.cmd("move",{from:x.from,to:x.to,promotion:a});const u=document.querySelector(`[data-square="${x.to}"]`);if(u){const l=u.getBoundingClientRect(),p=(d=document.getElementById("vfx-canvas"))==null?void 0:d.getBoundingClientRect();p&&($==null||$.promotionBurst(l.left-p.left+l.width/2,l.top-p.top+l.height/2))}x=null,C="",M=[],k()}})}),(r=e.querySelector("[data-cancel-promo]"))==null||r.addEventListener("click",()=>{x=null,k()});return}if(n.phase==="over"){n.winner!==null&&(n.winner,n.me);const s=n.winner===null;let o="",a="";s?n.result_reason==="stalemate"?(o=w("پات — مساوی!","Stalemate — Draw!"),a=w("شاه راه حرکتی ندارد","King has no legal moves")):n.result_reason==="insufficient_material"?(o=w("تساوی — عدم کفایت مهره‌ها","Draw — Insufficient Material"),a=w("مهره کافی برای مات کردن در صفحه وجود ندارد","Neither side has sufficient pieces to force checkmate")):(o=w("بازی مساوی شد","Draw!"),a=w("هیچ‌کدام از طرفین برنده نشد","No side achieved victory")):(o=`${(t=n.players[n.winner])==null?void 0:t.name} ${w("برنده شد! 🏆","Wins! 🏆")}`,a=n.result_reason==="checkmate"?w("با کیش و مات حریف","By checkmate"):n.result_reason==="abandoned"?w("به دلیل ترک حریف","By abandonment"):""),e.innerHTML=`
<div class="game-over-banner">
<div class="game-over-title">${o}</div>
<div class="game-over-subtitle">${a}</div>
</div>
`;return}e.innerHTML=""}}function yt(e){var s;if(!n||n.phase!=="play"||x)return;const c=n.me;if(c==null||n.turn!==c)return;const r=(s=n.players[c])==null?void 0:s.color;if(!r)return;const t=n.board.find(o=>o.square===e);if(C){if(C===e){C="",M=[],k();return}if(t!=null&&t.color&&t.color===r){C=e;try{M=D(e,n.board,r)}catch{M=[]}k();return}const o=n.board.find(d=>d.square===C),a=r==="b"?"1":"8";if((o==null?void 0:o.type)==="p"&&e[1]===a){x={from:C,to:e},C="",M=[],k();return}O.cmd("move",{from:C,to:e}),C="",M=[],k()}else if(t&&t.color===r){C=e;try{M=D(e,n.board,r)}catch{M=[]}k()}}