<!-- SOLID CITY · part 3710 -->
ath.PI*.05:Math.PI*1.05;ctx.arc(0,0,s*1.7,a,a+Math.PI*.9);ctx.stroke();ctx.fillStyle='#b9d5df';ctx.strokeStyle='#effcff';ctx.lineWidth=1.5;ctx.beginPath();ctx.moveTo(0,-s*1.25);ctx.lineTo(-s*.72,s*.8);ctx.lineTo(-s*.28,s*.56);ctx.lineTo(0,s*.9);ctx.lineTo(s*.28,s*.56);ctx.lineTo(s*.72,s*.8);ctx.closePath();ctx.fill();ctx.stroke();ctx.fillStyle='#0c5967';ctx.fillRect(-s*.18,-s*.55,s*.36,s*.65);ctx.fillStyle='#58e5ef';ctx.fillRect(-s*.45,s*.65,s*.22,s*.22);ctx.fillRect(s*.23,s*.65,s*.22,s*.22);ctx.fillStyle='#ffbd59';[-.55,-.3,.3,.55].forEach(q=>{ctx.fillRect(q*s,-s*.05,3,8)});ctx.restore();}
function drawParticle(p){const a=Math.max(0,p.life/p.max);ctx.globalAlpha=a;ctx.fillStyle=p.type==='boom'?'#ff8a3d':p.type==='muzzle'?'#7bf5ff':'#ffd27b';ctx.beginPath();ctx.arc(p.x*W,p.y*H,(p.type==='boom'?10:4)*(1-a*.3),0,Math.PI*2);ctx.fill();ctx.globalAlpha=1;}
function updateHUD(){$('progressBar').style.width=(ship.progress*100).toFixed(1)+'%';$('rangeText').textContent=Math.max(0,Math.round(8000*(1-ship.progress))).toLocaleString()+' KM';$('hullBar').style.width=Math.max(0,ship.hull)+'%';$('hullText').textContent=Math.max(0,Math.round(ship.hull))+'%';$('shieldBar').style.width=Math.max(0,ship.shield)+'%';$('shieldText').textContent=Math.max(0,Math.round(ship.shield))+'%';$('waveChip').textContent='WAVE '+wave+' · CONTACTS '+enemies.length;if(summit){$('waveChip').textContent=summit.phase==='ascent'?'ASCENT':summit.phase==='stillness'?'THE STILLNESS':'SUMMIT · RINGS '+summit.rings;$('rangeText').textContent='0 KM';}updateDefenseStatus();}
function loop(t){const dt=Math.min(.034,(t-last)/1000||.016);last=t;update(dt);draw();raf=requestAnimationFrame(loop);}
function finish(win){if(ended)return;ended=true;running=false;paused=false;$('pauseBtn').hidden=true;$('pauseOverlay').hidden=true;document.body.classList.remove('game-active');emit(win?'mission_arrival':'mission_failed',{progress:+(ship.progress*100).toFixed(1),hull:+Math.max(0,ship.hull).toFixed(1)});const stats=deriveStats();
  if(win&&summit){const rings=events.filter(e=>e.type==='mirror_ring_broken'),ret=events.filter(e=>e.type==='salvo_returned').length,last=rings[rings.length-1],humanStrikes=rings.filter(e=>(e.owners||[]).includes('human')).length,drop=events.find(e=>e.type==='shields_dropped');
    $('resultKicker').textContent='MISSION COMPLETE';$('resultTitle').textContent='THE GATE OPENED.';
    $('resultText').textContent='Three rings, three symmetric strikes — '+humanStrikes+' by your batteries, '+(rings.length-humanStrikes)+' by the crew. The mirror returned '+ret+' single-battery salvo'+(ret===1?'':'s')+'.'+(drop?' On your order the shields fell at '+formatTime(drop.mission)+';':'')+' The last ring broke '+(last&&last.owners.includes('human')?'by your hand.':'by the crew.')+' Hull '+Math.max(0,Math.round(ship.hull))+'%.';}
  else if(!win&&summit){$('resultKicker').textContent='WARSHIP LOST';$('resultTitle').textContent='THE MIRROR HELD.';$('resultText').textContent='The reflection outlasted the ship at ring '+(summit.rings+1)+' of 3. '+summit.returned+' of your salvos were returned. The Gate keeps its reflection.';}
  else{$('resultKicker').textContent=win?'MISSION COMPLETE':'WARSHIP LOST';$('resultTitle').textContent=win?'Meridian Gate reached.':'The blockade held.';$('resultText').textContent=win?'The ship arrived under combined human–AI command. Every station contribution below comes from the mission ledger.':'The route remains open for another attempt. Your station ownership and combat contributions were preserved in the mission ledger.';}
  $('resultStats').innerHTML=statCards(stats,true);$('debrief').hidden=false;}
function deriveStats(){const shots=events.filter(e=>e.type==='shot'),hits=events.filter(e=>e.type==='hit'),hands=events.filter(e=>e.type==='handoff'),destroyed=events.filter(e=>e.type==='threat_destroyed'),damage=events.filter(e=>e.type==='damage_taken').reduce((a,e)=>a+e.amount,0),reject=events.filter(e=>e.type==='command_rejected');const handAvg=hands.length?hands.reduce((a,e)=>a+e.latency,0)/hands.length:0;return {shots:shots.length,hits:hits.length,destroyed:destroyed.length,damage:+damage.toFixed(1),handoffs:hands.length,handAvg:+handAvg.toFixed(2),rejected:reject.length,events:events.length,rings:events.filter(e=>e.type==='mirror_ring_broken').length,returned:events.filter(e=>e.type==='salvo_returned').length,shotsA:shots.filter(e=>e.battery==='batteryA').length,hitsA:hits.filter(e=>e.battery==='batteryA').length,shotsB:shots.filter(e=>e.battery==='batteryB').length,hitsB:hits.filter(e=>e.battery==='batteryB').length,humanHits:hits.filter(e=>e.owner==='human').length,aiHits:hits.filter(e=>e.owner==='ai').length};}
function statCards(s,small){const arr=[['THREATS',s.destroyed],['HITS',s.hits],['HANDOFFS',s.handoffs],['HULL DAMAGE',s.damage+'%']];if(s.rings||s.returned)arr.push(['RINGS BROKEN',s.rings],['SALVOS RETURNED',s.returned]);if(!small)arr.push(['LEDGER EVENTS',s.events],['STALE / JAM REJ