<!-- SOLID CITY · part 2068 -->
ySelector('option[value="' + cv + '"]')) c.value = cv;
}
function command(k) {
  pause('command');
  if (k === 'resume') { st.paused = false; st.status = 'resumed'; st.goal = busy() ? 'finishing the current trip' : ''; st.next = Date.now() + 500; paint(); return; }
  if (k === 'go') { var p = HY.pois.filter(function (o) { return o.id === $('ai-district').value; })[0]; if (p) HY.driveTo(p, 'AI DRIVE'); }
  else if (k === 'follow') { var c = window.CityCitizens && CityCitizens.get($('ai-citizen').value); if (c) { if (S.mode === 'walk') CityCitizens.watch(c); else CityCitizens.find(c); } }
  else if (k === 'fly') { if (window.CityWatch) { addHop(); CityWatch.start('hop', 'City hop'); } }
  else if (k === 'land') { HY.cmd('land'); }
  else if (k === 'tour') { HY.cmd('tour'); }
  paint();
}
function where() {
  var p = S.mode === 'walk' ? S.p : S.ship, best = '', bd = 1e9;
  HY.pois.forEach(function (o) { var d = Math.hypot(o.x - p.x, o.z - p.z); if (d < bd) { bd = d; best = o.name; } });
  var nm = (A.whereName && A.whereName(p.x, p.z)) || 'Solid City';
  return bd < 160 ? 'near ' + best + ' (' + Math.round(bd) + ' m) \u00b7 ' + nm : nm;
}
function modeText() {
  var W = window.CityWatch && CityWatch.state;
  if (W && W.state && W.state !== 'idle') return 'flying (Watch: ' + ((W.route && W.route.name) || 'route') + ')';
  return { walk: 'on foot', boarded: 'in a ship on the pad', countdown: 'launch countdown', launch: 'launching', fly: 'flying', auto: 'autopilot flight', watch: 'flying (Watch)' }[S.mode] || S.mode;
}
function nearby() {
  if (!window.CityCitizens || !CityCitizens.state) return 'none';
  var p = S.mode === 'walk' ? S.p : S.ship;
  var l = CityCitizens.state().map(function (c) { return { n: c.name, d: Math.hypot(c.x - p.x, c.z - p.z) }; }).filter(function (c) { return c.d < 120; }).sort(function (a, b) { return a.d - b.d; }).slice(0, 4);
  return l.length ? l.map(function (c) { return c.n + ' (' + Math.round(c.d) + ' m)'; }).join(', ') : 'none within 120 m';
}
/* real state (2026-10-10): what the avatar is actually doing, whoever started it. PAUSED only when the
   autopilot is paused AND nothing is moving the avatar. */
function realState() {
  var h = HY.state || {}, W = window.CityWatch && CityWatch.state, rf = window.CityRadarFind && CityRadarFind.followState && CityRadarFind.followState();
  var cf = window.CityCitizens && CityCitizens.following && CityCitizens.following();
  if (h.nav && h.nav.p) return (h.tour ? 'TOUR \u00b7 ' : '') + 'WALKING TO ' + h.nav.p.name;
  if (h.flyDrive && h.flyDrive.t) return 'FLYING TO ' + h.flyDrive.t.name;
  if (W && W.state && W.state !== 'idle' && W.state !== 'paused') return 'FLYING \u00b7 WATCH ' + ((W.route && W.route.name) || '');
  if (h.tour) return 'TOUR';
  if (rf) return 'FOLLOWING ' + rf.name;
  if (cf) return 'WATCHING ' + cf.name;
  if (/^(countdown|launch)$/.test(S.mode)) return 'LAUNCHING';
  if (S.mode === 'fly' || S.mode === 'auto') return 'FLYING';
  return '';
}
function paint() {
  if (!badge) return;
  var rs = realState(), idlePaused = st.paused && !rs;
  badge.classList.toggle('paused', idlePaused);
  badge.innerHTML = (idlePaused ? 'HYPER CONTROLLER PAUSED' : rs ? 'HYPER CONTROLLER \u00b7 DRIVING' : 'HYPER CONTROLLER ACTIVE') + '<small>' +
    esc(idlePaused ? 'manual control \u00b7 tap Resume' : rs ? rs + (st.paused ? ' (your command)' : '') : st.status) + '</small>';
  resume.hidden = !st.paused;
  if (statusEl) statusEl.textContent = 'AI PILOT (' + (st.kind === 'guest' ? 'guest, scripted' : esc(st.name)) + ') \u00b7 ' + (idlePaused ? 'PAUSED' : st.paused ? 'MANUAL' : 'AUTO') + (rs ? ' \u00b7 State: ' + rs : '') +
    ' \u00b7 Location: ' + where() + ' \u00b7 Mode: ' + modeText() + ' \u00b7 Goal: ' + (idlePaused ? 'none (manual control)' : st.paused ? (rs || 'manual') : (st.goal || st.status)) + ' \u00b7 Nearby citizens: ' + nearby() + (st.arr ? ' \u00b7 Last arrival: ' + st.arr.name + ' (' + Math.max(0, Math.round((Date.now() - st.arr.t) / 1000)) + ' s ago)' : '') + '.';
}
function pause(why) {
  if (!st.on || st.paused) return; st.paused = true; st.status = 'paused';
  try { HY.stopAI(true); } catch (e) {}
  paint();
}

/* ---------- activities ---------- */
function busy() {
  var h = HY.state || {}, W = window.CityWatch && CityWatch.state;
  return !!(h.nav || h.tour || h.flyDrive) || (W && W.state && W.state !== 'idle') || /^(auto|watch|countdown|launch|fly)$/.test(S.mode) ||
    !!(window.CityCitizens && CityCitizens.following && CityCitizens.following());
}
function poi(id) { return HY.pois.filter(function (o) { return o.id === id; })[0] || null; }
function walkTo(p, label, dwell, say) {
  if (!p) return false;
  st.goal = label || ('heading to ' + p.name); st.status = st.goal;
  var ok = HY.driveTo(p, 'AI DRIVE', function () { st.status = (say || 'arrived at ') + p.name; st.goal = st.status; st.next = Date.now() + dwell * 1000; paint(); });
  return ok !== false;
}
var ACTS = {
  district: f