<!-- SOLID CITY · part 3459 -->
if(d.recover>=7){d.status='ACTIVE';d.hp=55;d.owner='AI';d.epoch++;d.task='REGROUP';d.x=convoyX+.14+Math.random()*.05;d.y=.42+Math.random()*.16;addEvent('RECOVERED',d.name,'Recovered by AI sub-commanders; resumed at epoch '+d.epoch)}})}
  function update(dt){
    elapsed=(performance.now()-missionStart)/1000;processQueue();
    drones.forEach(function(d,i){if(d.status!=='ACTIVE')return;if(d.owner==='HUMAN')humanControl(d,dt);else aiControl(d,dt,i);d.vx*=Math.pow(.16,dt);d.vy*=Math.pow(.16,dt);d.x+=d.vx*dt;d.y+=d.vy*dt;d.x=Math.max(.05,Math.min(.96,d.x));d.y=Math.max(.12,Math.min(.91,d.y));d.pulse=Math.max(0,d.pulse-dt);d.hit=Math.max(0,d.hit-dt)});
    debris.slice().forEach(function(o){o.x+=o.vx*dt;o.y+=o.vy*dt;o.angle+=o.spin*dt;if(o.y<.12||o.y>.91)o.vy*=-1;if(o.x<.06){debris.splice(debris.indexOf(o),1);progress=Math.max(0,progress-1.8);addEvent('BREACH','CONVOY','Uncleared debris crossed the protection line');}
      drones.forEach(function(d){if(d.status!=='ACTIVE'||d.hit>0)return;var dist=Math.hypot(o.x-d.x,o.y-d.y);if(dist<o.r+.015){d.hp-=16+wave*3;d.hit=.7;o.vx*=-.55;o.vy+=(Math.random()-.5)*.05;addEvent('IMPACT',d.name,'Hull impact; integrity now '+Math.max(0,Math.round(d.hp))+'%');if(d.hp<=0)disableDrone(d,'debris impact')}})
    });
    particles.forEach(function(p){p.x+=p.vx*dt;p.y+=p.vy*dt;p.life-=dt});particles=particles.filter(function(p){return p.life>0});recoverLogic(dt);
    var active=drones.filter(function(d){return d.status==='ACTIVE'}).length;var pressure=Math.max(0,1-debris.length/(7+wave*2));progress+=dt*(.22+.24*pressure)*(active/12);convoyX=.12+progress/100*.65;
    if(progress>=wave*25&&wave<4){wave++;spawnWave(wave);announce('Wave '+wave+' incoming. '+debris.length+' hazards tracked.')}
    if(elapsed>=nextHazardAt){nextHazardAt=elapsed+Math.max(4.5,8-wave);if(wave>=2)debris.push({id:++uid,x:.98,y:.14+Math.random()*.75,r:.012+Math.random()*.012,hp:40+wave*13,max:40+wave*13,vx:-.006-wave*.001,vy:(Math.random()-.5)*.008,spin:(Math.random()-.5)*2,angle:Math.random()*6.28})}
    if(elapsed>=nextAdvisoryAt){nextAdvisoryAt=elapsed+6;autoAdvisory()}
    if(active===0)finish(false);else if(progress>=100)finish(true);
    updateHUD();
  }
  function announce(t){document.getElementById('advisory').textContent=t}
  function autoAdvisory(){var active=drones.filter(function(d){return d.status==='ACTIVE'}).length,human=drones.filter(function(d){return d.owner==='HUMAN'&&d.status==='ACTIVE'}).length;if(active<9)announce('Integrity falling. REGROUP can recover disabled drones.');else if(debris.length>12)announce('Hazard density high. Recommend SCATTER or SWEEP. Advisory only.');else if(human)announce(human+' human-held drone'+(human===1?' remains':'s remain')+' outside AI group orders.');else announce('AI sub-commanders executing '+activeOrder+'. All control channels stable.')}
  function finish(success){if(!running)return;running=false;document.getElementById('debriefTitle').textContent=success?'Lane secured.':'Swarm lost.';document.getElementById('debriefCopy').textContent=success?'The convoy reached the exit vector under coordinated protection.':'No active drones remain to protect the convoy.';document.getElementById('finalTime').textContent=nowStamp();document.getElementById('finalClear').textContent=count('CLEARED');document.getElementById('finalLost').textContent=count('LOST');debrief.hidden=false;addEvent(success?'COMPLETE':'FAILED','MISSION',success?'Convoy reached exit vector':'All drones disabled')}
  function update(dtForDraw){draw();if(running)requestAnimationFrame(loop)}
  function loop(t){var dt=Math.min(.035,(t-last)/1000||.016);last=t;update(dt);draw();requestAnimationFrame(loop)}

  function draw(){
    var w=canvasW,h=canvasH;if(!w||!h)return;ctx.clearRect(0,0,w,h);ctx.fillStyle='#03090b';ctx.fillRect(0,0,w,h);
    ctx.strokeStyle='rgba(82,224,208,.055)';ctx.lineWidth=1;for(var x=0;x<w;x+=44){ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,h);ctx.stroke()}for(var y=0;y<h;y+=44){ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(w,y);ctx.stroke()}
    for(var s=0;s<38;s++){var sx=(s*97%997)/997*w,sy=(s*61%557)/557*h;ctx.fillStyle='rgba(220,246,242,'+(s%5===0?.55:.22)+')';ctx.fillRect(sx,sy,s%5===0?1.6:1,s%5===0?1.6:1)}
    var top=.18*h,bottom=.86*h;ctx.fillStyle='rgba(82,224,208,.035)';ctx.fillRect(0,top,w,bottom-top);ctx.strokeStyle='rgba(82,224,208,.18)';ctx.setLineDash([8,10]);ctx.beginPath();ctx.moveTo(0,top);ctx.lineTo(w,top);ctx.moveTo(0,bottom);ctx.lineTo(w,bottom);ctx.stroke();ctx.setLineDash([]);
    ctx.fillStyle='rgba(82,224,208,.65)';ctx.font='10px ui-monospace,monospace';ctx.fillText('CONVOY LANE K-9',12,top-10);
    var cx=convoyX*w,cy=.5*h;ctx.save();ctx.translate(cx,cy);ctx.fillStyle='#8fb9ba';ctx.beginPath();ctx.moveTo(18,0);ctx.lineTo(-10,-10);ctx.lineTo(-18,0);ctx.lineTo(-10,10);ctx.closePath();ctx.fill();ctx.fillStyle='#52e0d0';ctx.fillRect(-8,-2,20,4);ctx.restore();
    debris.forEach(function(o){var ox=o.x*w,oy=o.y*h,r=o.r*Math.min(w,h)