<!-- SOLID CITY · part 2196 -->
n pick('LOOK');
  if (/^walk$/.test(c)) return pick('WALK');
  if (/^(glossary|help)$/.test(c)) return c === 'help' ? narrate('I understand: "drive me to studio", "fly me to Mauna Kea", "tour", "scan", "focus", "return", "talk to sable", "stop".', 9) : glossary();
  if (/^(home|go home|take me home|fly home|land|return to city)$/.test(c)) { return driveTo(flying() ? FLY[0] : P('plaza'), 'AI DRIVE'); }
  var m = c.match(/(?:drive me to|take me to|walk me to|walk to|fly me to|fly to|go to|navigate to|show me|find|head to)\s+(.+)/);
  if (m) {
    var p = matchTarget(m[1]);
    if (p) { driveTo(p, 'AI DRIVE'); return; }
    narrate('I couldn\u2019t find anything matching \u201c' + esc(m[1]) + '\u201d. Try "studio", "spaceport", "warp", "SABLE", or in flight "Mauna Kea".', 7); return;
  }
  var p2 = matchTarget(c); if (p2) { driveTo(p2, 'AI DRIVE'); return; }
  narrate('I understand: "drive me to studio", "fly me to Mauna Kea", "tour", "scan", "return", "stop".', 7);
}

/* ---------------- wiring ---------------- */
function pick(m) { stopAI(true); clearNarration(); setMode(m); if (m === 'LOOK') { S.camDist = 14; S.camPitch = 0.5; H.lastDrag = 0; narrate('LOOK: drag to orbit the camera; it slowly circles when you let go. Tap 🚶 to walk again.', 5); } }
hc.querySelectorAll('.hc-mode-btn').forEach(function (b) { b.addEventListener('click', function () { pick(b.getAttribute('data-mode')); }); });

/* ================= ROYAL RIGHTS (2026-10-12) =================
   One gate: the server decides from the King's account; his typed password
   unlocks; then FLY pops up and BUILD arms. Nobody else ever sees the key. */
(function () {
  var me = null, flyBtn = null, riseEl = null, sending = false;
  var buildBtn = $('hc-build'); if (buildBtn) buildBtn.style.display = 'none'; // fail closed until royal is proven
  function post(path, body) {
    return fetch(path, { method: 'POST', credentials: 'same-origin', cache: 'no-store', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': (me && me.csrf) || '' }, body: JSON.stringify(body || {}) })
      .then(function (r) { return r.json().catch(function () { return {}; }).then(function (j) { return { status: r.status, j: j }; }); });
  }
  function showRise(on) {
    if (!riseEl) {
      riseEl = document.createElement('div'); riseEl.id = 'hc-rise';
      riseEl.innerHTML = '<button type="button" id="hc-rise-up" aria-label="Climb">⬆</button><button type="button" id="hc-rise-dn" aria-label="Sink">⬇</button>';
      document.body.appendChild(riseEl);
      bindHold(riseEl.querySelector('#hc-rise-up'), 1); bindHold(riseEl.querySelector('#hc-rise-dn'), -1);
    }
    riseEl.style.display = on ? 'flex' : 'none';
    if (!on && window.CityRoyal) CityRoyal.setRise(0);
  }
  function bindHold(el, v) {
    el.addEventListener('pointerdown', function (e) { e.preventDefault(); if (window.CityRoyal) CityRoyal.setRise(v); });
    ['pointerup', 'pointerleave', 'pointercancel'].forEach(function (t) { el.addEventListener(t, function () { if (window.CityRoyal) CityRoyal.setRise(0); }); });
    el.addEventListener('contextmenu', function (e) { e.preventDefault(); });
  }
  function applyRoyal() {
    if (buildBtn) buildBtn.style.display = '';
    var key = $('hc-royal-key'); if (key) key.style.display = 'none';
    if (!flyBtn) {
      flyBtn = document.createElement('button');
      flyBtn.type = 'button'; flyBtn.id = 'hc-royal-fly'; flyBtn.className = 'hc-mode-btn'; flyBtn.setAttribute('data-mode', 'FLY');
      flyBtn.title = 'Fly — the King\'s own power'; flyBtn.setAttribute('aria-label', 'Fly'); flyBtn.textContent = '🪽';
      var look = hc.querySelector('.hc-mode-btn[data-mode="LOOK"]');
      if (look && look.nextSibling) look.parentNode.insertBefore(flyBtn, look.nextSibling); else $('hc-buttons').appendChild(flyBtn);
      flyBtn.addEventListener('click', function () {
        if (!window.CityRoyal) return;
        if (CityRoyal.flying()) { CityRoyal.setFly(false); return; }
        stopAI(true); CityRoyal.setFly(true); setMode('FLY'); showRise(true);
        narrate('🪽 <b>Flight is yours, my King.</b> Steer with the stick, hold ⬆ / ⬇ to climb and sink, tap 🚶 WALK to land.', 6);
      });
      if (window.CityRoyal) CityRoyal.onLand = function () { setMode('WALK'); showRise(false); narrate('Landed. The ground remembers its King.', 3); };
      $('hc-buttons').addEventListener('click', function (e) {
        var t = e.target && e.target.closest ? e.target.closest('.hc-mode-btn') : null;
        if (t && t.getAttribute('data-mode') === 'WALK' && window.CityRoyal && CityRoyal.flying()) { e.stopPropagation(); e.preventDefault(); CityRoyal.setFly(false); }
      }, true);
    }
    flyBtn.style.display = '';
  }
  function unlock() {
    if (sending) return; sending = true;
    var inp = document.getElementById('hc-royal-pw'); var pw = inp ? inp.value : '';
    post('/api/city/royal/unlock', { password: pw }).then(function (r) {
      sending = fal