<!-- SOLID CITY · part 406 -->
ctTarget.kind === 'board') board();
  else if (actTarget.kind === 'exit') disembark();
  else if (actTarget.kind === 'train') { if (window.CityHyperTrain) CityHyperTrain.board(); }
  else if (actTarget.kind === 'elevator') { if (window.CityHyperCity) CityHyperCity.boardElevator(); if (window.CityAnnex) CityAnnex.boardElevator(P.x, P.z); if (window.CityQuadrantCrown) CityQuadrantCrown.boardElevator(P.x, P.z); }
}
function openPortal(d) {
  $('p-title').textContent = d.title || d.label; $('p-go').href = d.url; $('p-go').textContent = d.go || 'ENTER';
  var np = window.CityPlayer && d === D.studio ? CityPlayer.state() : null;
  $('p-text').textContent = (np && np.title ? 'Now playing on Studio Radio: \u201c' + np.title + '\u201d. ' : '') + d.text;
  $('sc-portal').hidden = false;
}
var ray = new T.Raycaster(), ndc = new T.Vector2();
function onTap(x, y) {
  if (S.mode !== 'walk') return;
  ndc.set(x / innerWidth * 2 - 1, -(y / innerHeight) * 2 + 1); ray.setFromCamera(ndc, camera);
  if (window.CityForge && CityForge.tap(x, y)) return;
  if (ray.intersectObject(sable, true).length) openTalk();
  else if (window.CityCitizens && CityCitizens.tap(ray)) { /* 👥 citizen talk panel opened */ }
  else if (SOUL.group && Math.hypot(S.p.x - D.soul.x, S.p.z - D.soul.z) < 140 && ray.intersectObject(SOUL.group, true).length) openSoul();
}
function board() { S.mode = 'boarded'; avatar.visible = false; S.ship.x = PAD.x; S.ship.y = PAD.y + 2.4; S.ship.z = PAD.z; S.ship.speed = 0; levelShip(Math.PI); help('Ship boarded. Hit the big red LAUNCH button. Warp Speed mini-game: walk through the spaceport gate.'); }
function disembark() { S.mode = 'walk'; avatar.visible = true; S.p.x = PAD.x; S.p.z = PAD.z - 52; S.p.y = groundAt(S.p.x, S.p.z); S.p.face = Math.PI; setFlightUI(false); help('Clear of the pad — the hangar is behind you, the city ahead.'); }
function levelShip(heading) { S.ship.q.setFromAxisAngle(UP, heading); }
var countT = 0, countEnd = 0, countShown = '';
function startCountdown() {
  if (S.mode !== 'boarded') return; S.mode = 'countdown'; countT = 3.0; countEnd = performance.now() + 3000; countShown = ''; $('sc-launch').hidden = true; $('sc-act').hidden = true; $('sc-count').hidden = false;
}
function setFlightUI(on) { $('sc-thr').hidden = !on; $('sc-fbtns').hidden = !on; }
/* ROYAL FLIGHT (2026-10-12) — the King's sole power. Hyper calls this ONLY
   after the server-side Royal Rights unlock; nothing here self-grants. */
window.CityRoyal = {
  setFly: function (on) {
    if (S.mode !== 'walk') return false;
    if (on && !S.rfly) { S.rfly = true; S.rflyLand = false; S.rflyT = 0; S.rflyV = 0; help('You rise. Climb and sink with the gold arrows (or R / F). Tap WALK to land.', 6); }
    else if (!on && S.rfly) { S.rflyLand = true; }
    return true;
  },
  flying: function () { return !!S.rfly; },
  setRise: function (v) { S.rflyRise = v; },
  onLand: null
};
function returnToCity() { if (S.mode === 'fly' || S.mode === 'auto') startAuto(false); }
function startAuto(landNow) { S.mode = 'auto'; S.auto = { phase: 'cruise', land: true }; help('Autopilot: returning to the Orbital Spaceport. Move the stick to take back control.'); }
var helpTimer = 0;
function help(t, sec) { var h = $('sc-help'); h.textContent = t; h.style.opacity = 1; helpTimer = sec || 6; }

/* ---------------- walking ---------------- */
function updateWalk(dt) {
  var k = input.keys, mx = input.sx, my = input.sy;
  if (k.KeyW || k.ArrowUp) my -= 1; if (k.KeyS || k.ArrowDown) my += 1; if (k.KeyA || k.ArrowLeft) mx -= 1; if (k.KeyD || k.ArrowRight) mx += 1;
  var mag = Math.min(1, Math.hypot(mx, my)), P = S.p;
  if (mag > 0.08) {
    var sp = (k.ShiftLeft || k.ShiftRight || mag > 0.95 && IS_TOUCH ? 15 : 8) * mag;
    if (S.rfly) sp *= 2.2; // royal flight: the superhero covers ground
    var fx = -Math.sin(S.camYaw), fz = -Math.cos(S.camYaw), rx = Math.cos(S.camYaw), rz = -Math.sin(S.camYaw);
    var vx = (fx * -my + rx * mx) / (Math.hypot(mx, my) || 1), vz = (fz * -my + rz * mx) / (Math.hypot(mx, my) || 1);
    P.x += vx * sp * dt; P.z += vz * sp * dt;
    var want = Math.atan2(vx, vz), dA = ((want - P.face + Math.PI * 3) % (Math.PI * 2)) - Math.PI; P.face += dA * Math.min(1, dt * 10);
    P.walk = (P.walk || 0) + dt * sp * 1.4;
  }
  if (S.ai) { // Hyper Controller AI walk: user input always wins
    if (mag > 0.08) S.ai(null);
    else { var st = S.ai(dt); if (st) { P.x += st.vx * dt; P.z += st.vz * dt; var wa = Math.atan2(st.vx, st.vz), da = ((wa - P.face + Math.PI * 3) % (Math.PI * 2)) - Math.PI; P.face += da * Math.min(1, dt * 8); P.walk = (P.walk || 0) + dt * st.sp * 1.1; mag = 1; } }
  }
  // everything visible is solid
  collideXZ(P, 0.45, P.y + 1);
  var sx = SABLE_POS.x - P.x, sz = SABLE_POS.z - P.z, sd = Math.hypot(sx, sz); if (sd < 1.3 && sd > 0) { P.x = SABLE_POS.x - sx / sd * 1.3; P.z = SABLE_POS.z - sz / sd * 1.3; }
  var RF = !!S.rfly;
  if (RF) {
    var rise = S.rflyRise || 0;
    if (k.KeyR || k.Space) ris