<!-- SOLID CITY · part 3763 -->
eserved.','king',null,from,'king');taskDrawer(t);toast('Ownership transferred; work preserved.')}
    if(action==='save'){var value=document.getElementById('workEditor').value;t.work=value;addEvent(t,'edit','The King','Saved a human edit. Simulated collaborators may resume only from this version.','king');taskDrawer(t);toast('Human edit recorded.')}
    if(action==='return'){var to=t.previousOwner;t.owner=to;t.previousOwner=null;t.state='in-progress';addEvent(t,'handoff','The King','Returned the edited task to '+ownerName(to)+' without resetting its work.','king',null,'king',to);taskDrawer(t);toast('Returned with your edits intact.')}
    if(action==='approve'){askConfirm('This records an explicit human approval event and marks this reviewed result complete. Continue?',function(){t.state='done';t.owner='king';addEvent(t,'approval','The King','Explicitly approved the reviewed result and marked it complete.','king');closeConfirm();taskDrawer(t);toast('Approval recorded.')})}
    if(action==='changes'){t.state='in-progress';var to=t.owner==='king'?(t.previousOwner||'surveyor'):t.owner;t.owner=to;addEvent(t,'review','The King','Requested changes; existing work and history remain attached.','king');taskDrawer(t);toast('Change request recorded.')}
    if(action==='publish'){askConfirm('Approve the board as a PLANNED inaugural service only? This does not claim operating transportation.',function(){t.state='done';t.owner='king';addEvent(t,'approval','The King','Explicitly approved the planned-service board for completion. No operational service was claimed.','king');closeConfirm();taskDrawer(t);toast('Planned board approval recorded.')})}
    if(action==='info'){var need=document.getElementById('infoNeed').value.trim(),source=document.getElementById('infoSource').value.trim();if(!need||!source){toast('Name both the need and its source.');return}addEvent(t,'info-request',ownerName(t.owner), 'Requested: '+need+'.',t.owner);addEvent(t,'info-answer','Surveyor','Answered the request using named source: '+source+'.','surveyor',source);taskDrawer(t);toast('Request and sourced answer recorded.')}
  }
  function runCollab(){var t;
    if(collabStep===0){t=taskById('t2');if(t.state!=='done'&&t.owner!=='king'){t.state='review';t.owner='surveyor';addEvent(t,'handoff','Route Planner','Transferred the completed route draft to Surveyor for review.','planner',null,'planner','surveyor');collabStep++;toast('AI-to-AI handoff recorded.');return}}
    if(collabStep<=1){t=taskById('t4');if(t.owner!=='king'&&t.state!=='done'){t.work+='\n\nResult: Wording meets the planned-service safety rule. Human confirmation still required.';t.state='review';addEvent(t,'result','Safety Checker','Verified the board uses planned-service language and makes no live transit claim.','safety','Rendered Harbor Shuttle Board copy');addEvent(t,'review','Safety Checker','Submitted the safety result for explicit human approval.','safety');collabStep=2;toast('Safety result recorded for human review.');return}}
    t=tasks.find(function(x){return x.owner!=='king'&&x.state==='in-progress'});if(t){addEvent(t,'result',ownerName(t.owner),'Recorded a collaborator checkpoint from the current work version.',t.owner,'Current task work version');toast('Collaborator checkpoint recorded.')}else toast('No autonomous step available. A human review gate is waiting.')
  }
  function switchView(name,push){document.querySelectorAll('.view').forEach(function(v){v.classList.remove('active')});document.querySelectorAll('.nav button').forEach(function(b){b.classList.toggle('active',b.dataset.view===name)});var el=document.getElementById(name+'View');if(el)el.classList.add('active');if(push!==false){var q=name==='workshop'?'':('?view='+encodeURIComponent(name));history.replaceState(null,'',q||location.pathname)}window.scrollTo({top:0,behavior:'smooth'})}
  function renderAll(){renderTasks();renderWorkers();renderFeed();renderStats()}
  document.addEventListener('click',function(e){var taskEl=e.target.closest('[data-task]');if(taskEl){taskDrawer(taskById(taskEl.dataset.task));return}var nav=e.target.closest('[data-view]');if(nav){switchView(nav.dataset.view);return}var nt=e.target.closest('[data-nav-task]');if(nt){switchView('workshop');taskDrawer(taskById(nt.dataset.navTask));return}var action=e.target.closest('[data-action]');if(action){handleAction(action.dataset.action);return}});
  document.addEventListener('keydown',function(e){if((e.key==='Enter'||e.key===' ')&&e.target.matches('[data-task]')){e.preventDefault();taskDrawer(taskById(e.target.dataset.task))}if(e.key==='Escape'){closeDrawer();closeConfirm()}});
  document.getElementById('closeDrawer').addEventListener('click',closeDrawer);document.getElementById('drawerBackdrop').addEventListener('click',function(e){if(e.target===this)closeDrawer()});
  document.getElementById('openStatsBtn').addEventListener('click',function(){switchView('stats')});document.getElementById('runStepBtn').addEventListen