<!-- SOLID CITY · part 2900 -->
t=null;recordEvent('lost',{pod:p.id});setAdvice(p.id+' is gone. Choose the next signal — the clock is still moving.')}});
    if(s.cargo){s.cargo.x=s.x-22;s.cargo.y=s.y+21;if(s.cargo.hp<=0){s.cargo.status='lost';s.cargo.lostReason='pod failed while under our protection';state.lost++;recordEvent('lost',{pod:s.cargo.id});s.cargo=null;state.triageTarget=null}}
    if(s.cargo&&dist(s,state.gate)<state.gate.r){const p=s.cargo;p.status='rescued';state.rescued++;s.cargo=null;state.triageTarget=null;recordEvent('rescue',{pod:p.id});const unresolved=state.pods.some(x=>x.status==='adrift'),resolved=state.pods.filter(x=>x.status==='rescued'||x.status==='lost').length;let msg;if(!unresolved)msg=p.id+' reached staging. The ghost echo is sharpening into a heartbeat.';else if(resolved===1)msg=p.id+' reached staging. That ghost echo just answered our scanner again.';else if(resolved===2)msg=p.id+' reached staging. Lantern Anchor lost a radial beam — the station is visibly breaking.';else msg=p.id+' reached staging. Choose who we fly for next.';setAdvice(msg);}
  }
  function damageShip(amount){const s=state.ship;if(s.pulse>0)amount*=.25;if(s.shield>0){const take=Math.min(s.shield,amount);s.shield-=take;amount-=take}s.hp=Math.max(0,s.hp-amount)}
  function updateRisk(){state.risk=state.pods.filter(p=>(p.status==='adrift'||p.status==='cargo')&&p.hp<42).length}
  function checkEnd(){
    const corridorDone=state.pods.every(p=>p.status==='rescued'||p.status==='lost');
    if(state.ship.hp<=0){
      state.pods.forEach(p=>{if(p.status==='adrift'||p.status==='cargo'){p.status='lost';p.lostReason='lost when the rescue vessel was destroyed';state.lost++;recordEvent('lost',{pod:p.id})}});
      if(state.anchor.heartbeat.status!=='rescued'&&state.anchor.heartbeat.status!=='lost'){state.anchor.heartbeat.status='lost';state.anchor.heartbeat.lostReason='never reached after the rescue vessel was destroyed';state.lost++;recordEvent('lost',{pod:'Iona'})}
      endMission('vessel');
    }else if(corridorDone&&!state.ship.cargo&&state.anchor.phase==='hidden'){
      finishTimer+=.016;if(finishTimer>.3)beginAnchor();
    }
  }
  function finishMission(){if(state.missionEnd)return;state.anchor.phase='done';endMission('survived')}
  function debriefMarkup(){
    const all=state.pods.concat([{id:'Iona',status:state.anchor.heartbeat.status,lostReason:state.anchor.heartbeat.lostReason}]);
    const home=all.filter(p=>p.status==='rescued').map(p=>p.id),lost=all.filter(p=>p.status==='lost');
    const homeLine=home.length?home.join(', '):'No one';
    const lostLine=lost.length?lost.map(p=>p.id+' — '+(p.lostReason||'not recovered')).join('; '):'No one';
    const debt=lost.length?'Their names remain on tonight’s board. Fly again because a different order, a steadier hold, or one braver return could bring them home.':'No empty places tonight. Fly again because every life depends on making the same courage repeatable.';
    return '<b>Home:</b> '+homeLine+'.<br><b>Lost:</b> '+lostLine+'.<span class="debt">'+debt+'</span>';
  }
  function endMission(kind){
    if(state.missionEnd)return;state.missionEnd=true;running=false;paused=false;setMissionInterfaceInert(false);$('#pauseBtn').classList.add('hidden');$('#pauseScreen').classList.remove('show');$('#pauseScreen').setAttribute('aria-hidden','true');
    recordEvent('mission',{success:kind==='survived'&&state.rescued>0,rescued:state.rescued,lost:state.lost});
    let title;if(kind==='vessel')title='Rescue vessel lost';else if(state.rescued===0)title='No pilots recovered';else if(state.rescued===4)title='The constellation holds';else title='The debt remains';
    $('#resultTitle').textContent=title;$('#resultCopy').innerHTML=debriefMarkup();$('#result').classList.add('show');updateCommand();
  }

  function draw(){
    const g=ctx.createLinearGradient(0,0,W,H);g.addColorStop(0,'#06151e');g.addColorStop(1,'#02070c');ctx.fillStyle=g;ctx.fillRect(0,0,W,H);
    drawStars();drawGate();drawAnchor();state.hazards.forEach(drawHazard);state.debris.forEach(drawDebris);state.pods.forEach(drawPod);state.enemies.forEach(drawEnemy);state.shots.forEach(drawShot);drawShip();
  }
  function drawStars(){ctx.save();for(let i=0;i<90;i++){const x=(i*113)%W,y=(i*67)%H,a=.2+(i%5)*.12;ctx.fillStyle='rgba(177,230,239,'+a+')';ctx.fillRect(x,y,i%13===0?2:1,i%13===0?2:1)}ctx.restore()}
  function drawGate(){const g=state.gate;ctx.save();ctx.translate(g.x,g.y);ctx.strokeStyle='#57e7ff';ctx.lineWidth=6;ctx.shadowColor='#32d9ff';ctx.shadowBlur=22;ctx.beginPath();ctx.arc(0,0,g.r,-1.2,1.2);ctx.stroke();ctx.beginPath();ctx.arc(0,0,g.r,1.94,4.34);ctx.stroke();ctx.shadowBlur=0;ctx.fillStyle='#b8f7ff';ctx.font='700 13px "Arial Narrow"';ctx.textAlign='center';ctx.fillText('RESCUE GATE',0,-g.r-12);ctx.restore()}
  function drawAnchor(){
    const a=state.anchor,known=a.phase!=='hidden',progress=state.pods.filter(p=>p.status==='rescued'||p.status==='lost').length;
    ctx.save();ctx.translate(a.x,a.y);ctx.glob