<!-- SOLID CITY · part 2034 -->
ar d=Math.round(elapsedMs()/1000),resc=events.filter(function(e){return e.type==='rescue'}).length,hand=events.filter(function(e){return e.type==='handoff'}).length;document.getElementById('winner').textContent=(team==='gold'?'Gold':'Teal')+' secures the Meridian Beacon.';document.getElementById('summary').textContent='Mission time '+Math.floor(d/60)+'m '+d%60+'s · '+hand+' control handoffs · '+resc+' rescues · '+eventCounts.hit+' confirmed hits. Every figure is drawn from this battle ledger.';document.getElementById('debrief').classList.add('open')}
  function shipColor(team){return team==='gold'?'#ffc952':'#38e3d1'}
  function draw(ctx,focusTeam,w,h){ctx.clearRect(0,0,w,h);ctx.save();ctx.scale(w/W,h/H);var g=ctx.createRadialGradient(600,360,10,600,360,650);g.addColorStop(0,'#0c2420');g.addColorStop(1,'#010504');ctx.fillStyle=g;ctx.fillRect(0,0,W,H);
    ctx.fillStyle='#b9ffef';for(var k=0;k<70;k++){var sx=(k*193%W),sy=(k*97%H),sz=(k%3)+1;ctx.globalAlpha=.22+(k%5)*.08;ctx.fillRect(sx,sy,sz,sz)}ctx.globalAlpha=1;
    ctx.strokeStyle='#28443e';ctx.lineWidth=2;ctx.setLineDash([7,10]);ctx.beginPath();ctx.arc(BEACON.x,BEACON.y,BEACON.r,0,Math.PI*2);ctx.stroke();ctx.setLineDash([]);ctx.fillStyle='#9bcac0';ctx.font='700 13px sans-serif';ctx.textAlign='center';ctx.fillText('MERIDIAN',600,356);ctx.font='10px sans-serif';ctx.fillText('CONTROL BEACON',600,372);
    for(var r of rocks){ctx.save();ctx.translate(r.x,r.y);ctx.rotate(r.spin);ctx.fillStyle='#26302e';ctx.strokeStyle='#52605d';ctx.lineWidth=2;ctx.beginPath();for(var v=0;v<8;v++){var a=v/8*Math.PI*2,rr=r.r*(.75+(v%3)*.12);ctx.lineTo(Math.cos(a)*rr,Math.sin(a)*rr)}ctx.closePath();ctx.fill();ctx.stroke();ctx.restore()}
    for(var p of shots){ctx.strokeStyle=shipColor(p.team);ctx.lineWidth=3;ctx.beginPath();ctx.moveTo(p.x,p.y);ctx.lineTo(p.x-p.vx*.035,p.y-p.vy*.035);ctx.stroke()}
    for(var sp of sparks){ctx.globalAlpha=sp.life*4;ctx.fillStyle=shipColor(sp.color);ctx.fillRect(sp.x,sp.y,3,3)}ctx.globalAlpha=1;
    for(var s of ships){drawShip(ctx,s,focusTeam)}ctx.restore()}
  function drawShip(ctx,s,focusTeam){var c=shipColor(s.team),isSel=selected[s.team]===s.id;ctx.save();ctx.translate(s.x,s.y);ctx.rotate(s.a);if(s.disabled>0){ctx.globalAlpha=.35;ctx.rotate(s.disabled*2)}if(isSel){ctx.strokeStyle='#fff';ctx.lineWidth=2;ctx.beginPath();ctx.arc(0,0,25,0,Math.PI*2);ctx.stroke()}ctx.fillStyle=c;ctx.shadowColor=c;ctx.shadowBlur=s.team===focusTeam?12:3;ctx.beginPath();ctx.moveTo(20,0);ctx.lineTo(-12,-10);ctx.lineTo(-6,0);ctx.lineTo(-12,10);ctx.closePath();ctx.fill();ctx.shadowBlur=0;ctx.fillStyle='#e9ffff';ctx.fillRect(3,-2,8,4);ctx.restore();ctx.fillStyle='rgba(0,0,0,.75)';ctx.fillRect(s.x-23,s.y+18,46,5);ctx.fillStyle=s.hull<30?'#ff6969':'#71f0ac';ctx.fillRect(s.x-23,s.y+18,46*(s.hull/100),5);ctx.fillStyle=s.team===focusTeam?'#e8f7f4':'#718a86';ctx.font='700 10px sans-serif';ctx.textAlign='center';ctx.fillText(s.name,s.x,s.y+36);if(s.owners.movement==='HUMAN'){ctx.fillStyle='#fff';ctx.font='8px sans-serif';ctx.fillText('HUMAN HELM',s.x,s.y-23)}}
  var canvases={gold:document.getElementById('goldCanvas'),teal:document.getElementById('tealCanvas')},contexts={gold:canvases.gold.getContext('2d'),teal:canvases.teal.getContext('2d')};
  function resizeCanvas(c){var r=c.getBoundingClientRect(),d=Math.min(2,window.devicePixelRatio||1);c.width=Math.max(1,Math.round(r.width*d));c.height=Math.max(1,Math.round(r.height*d));c._w=r.width;c._h=r.height;c.getContext('2d').setTransform(d,0,0,d,0,0)}function resizeAll(){resizeCanvas(canvases.gold);resizeCanvas(canvases.teal)}
  function pointFrom(e,c){var r=c.getBoundingClientRect();return{x:(e.clientX-r.left)/r.width*W,y:(e.clientY-r.top)/r.height*H}}
  function bindCanvas(team){var c=canvases[team],down=false;c.addEventListener('pointerdown',function(e){e.preventDefault();down=true;c.setPointerCapture(e.pointerId);var p=pointFrom(e,c),a=teamShips(team).filter(function(s){return s.disabled<=0}).sort(function(x,y){return dist(p,x)-dist(p,y)}),s=a[0];if(s&&dist(p,s)<55){claim(s,['movement','navigation']);s.humanAim={x:p.x+(s.team==='gold'?100:-100),y:p.y}}else{var cur=ships.find(function(x){return x.id===selected[team]});if(cur){cur.humanAim=p;cur.task='Human vector'}}});c.addEventListener('pointermove',function(e){if(!down)return;var s=ships.find(function(x){return x.id===selected[team]});if(s){s.humanAim=pointFrom(e,c);s.task='Human vector'}});function up(){down=false}c.addEventListener('pointerup',up);c.addEventListener('pointercancel',up)}
  bindCanvas('gold');bindCanvas('teal');
  document.addEventListener('pointerdown',function(e){var b=e.target.closest('button');if(!b)return;var team=b.dataset.team;if(b.dataset.order)issueOrder(team,b.dataset.order);if(b.dataset.action){var s=ships.find(function(x){return x.id===selected[team]});if(!s){toast('Tap a '+team+' fighter first');return}if(b.dataset.action==='fire'){claim(s,['weapons']);fire(s,true)}if(b.dataset.action==='shield'){if(s.shieldWindow>