<!-- SOLID CITY · part 1149 -->
ding); }
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
};
/* FIRST DRIVES (2026-10-13) — the South Lot rides. The avatar is the real
   human of this world; the rides were built for him to roll in. CityDrive
   owns the drive state and updateWalk integrates it (driveStep), exactly
   the way royal flight is integrated: one sanctioned hook in the physics.
   Any visitor may roll a lot ride, as any visitor may ride the train. */
/* RUNG 2 — THE DOORS ARE SEARCHED (the Apply-Everything Commission, 2026-10-13).
 * VECTOR's exit contract, entered after the Rung 1 survey found the old
 * step-out blind: it placed the avatar 2.6 m to the car's left with no
 * clearance and no standing test. Now both doors are searched — left
 * first, as the city has always stepped out — and each candidate must
 * pass two tests in the city's own terms: no blocker (a solid whose body
 * occupies the landing, judged at the walker's own radius) and stand
 * permission (a surface the walker himself could stand on: terrain,
 * classified support, or the parking system's own surfaces, inside the
 * walker's 1.6 eligibility gate and with no drop greater than 1.2). If
 * neither door is lawful, the exit is REFUSED — NO_SAFE_EXIT — and the
 * driver stays seated. A refusal is a door that would have hurt him,
 * named instead of opened. */
function driveDoorClear(x, z, floorY) {
  for (var k = 0; k < solids.length; k++) {
    var s = solids[k];
    if (s.y1 <= floorY + 0.55) continue; // a floor at the feet, not a blocker
    if (s.y0 >= floorY + 1.7) continue; // above the head — the walker passes under
    if (x > s.x0 - 0.45 && x < s.x1 + 0.45 && z > s.z0 - 0.45 && z < s.z1 + 0.45) return false;
  }
  return true;
}
function driveDoorStand(x, z, floorY) {
  var gy = groundAt(x, z); if (gy < 0.5) gy = 0.5;
  var sty = solidsTopSupport(x, z, 0); if (sty > gy) gy = sty;
  if (window.CityFirstParking && CityFirstParking.standY) { var py = CityFirstParking.standY(x, z, floorY); if (py > gy) gy = py; }
  return gy >= floorY - 1.2 && gy <= floorY + STEP_UP;
}
function driveDoorOpen(x, z, cx, cz, floorY) {
  if (!driveDoorClear(x, z, floorY)) return false;
  if (!driveDoorClear((x + cx) / 2, (z + cz) / 2, floorY)) return false; // the swept step between
  return driveDoorStand(x, z, floorY);
}
window.CityDrive = {
  active: function () { return !!S.drive; },
  state: function () { return S.drive || null; },
  begin: function (mesh, yaw, ox, oz, carId) {
    /* A DOOR THAT SPEAKS (the King's report, 2026-10-13 ~23:20):
     * he flew to the South Lot, came down on the Tug's own roof,
     * and the ROLL button "won't let me in" — the old law refused
     * in silence whenever the flight flag still stood, and a
     * silent refusal reads as a broken button. Now: a flight ends
     * by the choosing (no one boards from the air; stepping in IS
     * the landing), and every other refusal names itself aloud. */
    if (S.drive) { help('Already rolling — step out first.', 4); return false; }
    if (S.mode !== 'walk') { help('Roll from on foot — not while ' + S.mode + '.', 4); return false; }
    if (S.rfly) { S.rfly = false; S.rflyLand = false; S.rflyV = 0; if (window.CityRoyal && CityRoyal.onLand) CityRoyal.onLand(); }
    S.drive = { mesh: mesh, yaw: yaw || 0, speed: 0, _thr: 0, _str: 0, ox: ox || 0, oz: oz || 0, carId: carId || null };
    if (avatar) avatar.visible = false;
    help('You roll. Push the stick up to drive, sideways to steer. The action button steps you out.', 7);
    return true;
  },
  end: function () {
    var D = S.drive; if (!D) return false;
    var P = S.p;
    var rx = Math.cos(D.yaw), rz = -Math.sin(D.yaw);
    var lx = P.x - rx * 2.6, lz = P.z - rz * 2.6, gx = P.x + rx * 2.6, gz = P.z + rz * 2.6;
    var door = null;
    if (driveDoorOpen(lx, lz, P.x, P.z, P.y)) door = [lx, lz];
    else if (driveDoorOpen(gx, gz, P.x, P.z, P.y)) door = [gx, gz];
    if (!door) { help('No safe exit here — roll somewhere clearer and step out.', 5); return 'NO_SAFE_EXIT'; }
    if (D.mesh) { D.mesh.positio