<!-- SOLID CITY · part 3697 -->
se()+' HULL IMPACT · SHIELD EMPTY');
  for(let i=0;i<18;i++)particle(ship.x,ship.y,'hit');if(ship.hull<=0)finish(false);
}
function pointDefense(owner){if(ship.defCooldown>0)return;ship.defCooldown=.8;const before=enemyShots.length;enemyShots=enemyShots.filter(p=>{const d=Math.hypot(p.x-ship.x,p.y-ship.y);if(d<.18){emit('point_defense',{owner,projectile:p.id});for(let i=0;i<6;i++)particle(p.x,p.y,'muzzle');return false;}return true;});if(before!==enemyShots.length)emit('defense_intercept',{owner,count:before-enemyShots.length});}
function ai(dt){aiTick-=dt;if(aiTick>0)return;aiTick=.18;const nav=coordination.tasks.nav;if(nav.owner==='ai'){const ex=enemies.reduce((best,e)=>{const d=Math.hypot(e.x-ship.x,e.y-ship.y);return d<(best.d||9)?{d,e}:best;},{});const danger=enemyShots.find(p=>Math.hypot(p.x-ship.x,p.y-ship.y)<.24);let desired=.5;if(warden&&!danger)desired=.5;if(danger)desired=ship.x+(ship.x-danger.x>0?.2:-.2);else if(ex.e&&ex.d<.22)desired=ship.x+(ship.x-ex.e.x>0?.17:-.17);const epoch=nav.epoch;coordination.command('nav','ai',epoch,()=>{ship.navInput=Math.max(-1,Math.min(1,(desired-ship.x)*5));ship.boost=true;},'AI-nav-'+Math.floor(performance.now()/180));}
  ['batteryA','batteryB'].forEach((name,idx)=>{const t=coordination.tasks[name];if(t.owner==='ai'&&(enemies.length||warden?.stage==='synchronize')){const live=enemies.filter(e=>!e.dead);if(live.length||warden?.stage==='synchronize'){if(name==='batteryA')ship.targetA=idx%live.length;else ship.targetB=(live.length-1);if(rand()<.72)fireBattery(name,'ai');}}});
  const def=coordination.tasks.defense;if(def.owner==='ai'){const nearest=enemyShots.reduce((a,p)=>Math.hypot(p.x-ship.x,p.y-ship.y)<Math.hypot((a||{x:9}).x-ship.x,(a||{y:9}).y-ship.y)?p:a,null);if(nearest){ship.shieldFace=projectileImpactFace(nearest);pointDefense('ai');}else ship.shieldFace='front';}
}
function beginWarden(){
   warden={stage:'approach',time:0,align:0,shield:0,volleys:new Set(),cycles:0,emStep:0,window:0};
   emit('warden_arrival',{range:480});showWarning('MERIDIAN GATE · THE WARDEN AWAKENS');
   $('advisoryText').textContent='Armor rejects gunfire. Helm, defense and batteries must act together.';
 }
 function wardenSalvo(name,owner){
   if(!warden||warden.stage!=='synchronize')return;
   if(warden.window<=0){emit('warden_armor_deflection',{battery:name,owner});return;}
   warden.volleys.add(name);emit('warden_battery_timed',{battery:name,owner});
   if(warden.volleys.size===2){warden.cycles++;warden.volleys.clear();warden.window=0;emit('warden_lock_broken',{cycle:warden.cycles});
     if(warden.cycles>=2){warden.stage='blackout';warden.time=0;warden.emStep=0;$('blackout').hidden=false;emit('bridge_blackout',{});}
     else {warden.stage='approach';warden.align=0;warden.shield=0;}
   }
 }
 function emergencyAction(step){
   if(!warden||warden.stage!=='blackout'||paused||ended)return;
   if(step!==warden.emStep){emit('emergency_rejected',{expected:warden.emStep,received:step});$('emProgress').textContent='WRONG CIRCUIT · FOLLOW 01 → 02 → 03';return;}
   warden.emStep++;emit('emergency_control',{control:['helm','shield','guns'][step],step:warden.emStep});
   $('emProgress').textContent='EMERGENCY SEQUENCE · '+warden.emStep+' / 3';
   if(warden.emStep===3){$('blackout').hidden=true;warden.stage='passage';warden.time=0;emit('bridge_restored',{});showWarning('GATE OPEN · MAKE THE FINAL PASSAGE');}
 }
 function updateWarden(dt){
   if(!warden)return;warden.time+=dt;bossClock+=dt;
   if(warden.stage==='approach'){
     // Coordinated helm alignment, shield facing, and independent battery readiness.
     if(Math.abs(ship.x-.5)<.085)warden.align=Math.min(1,warden.align+dt*.75);else warden.align=Math.max(0,warden.align-dt*.5);
     if(ship.shieldFace==='front'&&ship.shield>12)warden.shield=Math.min(1,warden.shield+dt*.7);else warden.shield=Math.max(0,warden.shield-dt*.5);
     if(warden.align>=1&&warden.shield>=1){warden.stage='synchronize';warden.window=6;warden.time=0;warden.volleys.clear();emit('warden_window_open',{seconds:6});}
   }else if(warden.stage==='synchronize'){
     warden.window-=dt;if(warden.window<=0){warden.stage='approach';warden.align=0;warden.shield=0;warden.volleys.clear();emit('warden_window_lost',{});}
   }else if(warden.stage==='blackout'){
     if(warden.time>24){warden.stage='approach';warden.cycles=1;warden.align=0;warden.shield=0;$('blackout').hidden=true;emit('blackout_failed',{});damageShip(14,'warden blackout','front');}
   }else if(warden.stage==='passage'){
     ship.progress=Math.min(1,ship.progress+dt*.055);
   }
   const msg=warden.stage==='approach'?'WARDEN · ALIGN HELM '+Math.round(warden.align*100)+'% · FACE SHIELD FRONT '+Math.round(warden.shield*100)+'%':warden.stage==='synchronize'?'WARDEN EXPOSED · FIRE BOTH BATTERIES · '+warden.window.toFixed(1)+'s':warden.stage==='blackout'?'BRIDGE BLACKOUT · EMERGENCY CIRCUITS 01 → 02 → 03':'WARDEN DISARMED · CROSS THE GATE';
   $('wardenBanner').textContent=msg;$('wardenBa