<!-- SOLID CITY · part 462 -->
ock.on || (micLock.aborts || 0) >= 3) return;
    setTimeout(micRecStart, 400);
  };
  try { rec.start(); } catch (e) { micLock.rec = null; }
}

/* ---------------- main loop ---------------- */
var workTimes = [], last = performance.now(), fpsAcc = 0, fpsN = 0, fpsVal = 60, running = false, frameTimes = [];
function frame(now) {
  if (!running) return;
  requestAnimationFrame(frame);
  var now0 = performance.now();
  var dt = Math.min(0.1, (now - last) / 1000); last = now; S.t += dt;
  frameTimes.push(dt * 1000); if (frameTimes.length > 600) frameTimes.shift();
  fpsAcc += dt; fpsN++; if (fpsAcc > 0.5) { fpsVal = fpsN / fpsAcc; fpsAcc = 0; fpsN = 0; }
  if (S.mode === 'walk') updateWalk(dt);
  else if (S.mode === 'countdown') { countT = (countEnd - now) / 1000; var ct = countT > 0 ? String(Math.ceil(countT)) : 'GO'; if (ct !== countShown) { countShown = ct; $('sc-count').textContent = ct; } shipFlames.forEach(function (f) { f.scale.setScalar(0.4 + Math.random() * 0.3); }); if (countT < -0.5) { $('sc-count').hidden = true; S.mode = 'launch'; S.launchT = 0; } }
  else if (S.mode === 'launch') updateLaunch(dt);
  else if (S.mode === 'fly') updateFly(dt);
  else if (S.mode === 'auto') updateAuto(dt);
  else if (S.mode === 'watch') { if (window.CityWatch) CityWatch.fly(dt); else S.mode = 'fly'; }
  if (window.CityHyper) CityHyper.update(dt);
  if (window.CityWatch) CityWatch.update(dt);
  if (window.CityForge) CityForge.update(dt);
  if (window.CityCitizens) CityCitizens.update(dt);
  if (window.CityMonuments) CityMonuments.update(dt);
  if (window.CitySanctuary) try { CitySanctuary.update(dt); } catch (e) {}
  if (window.CityCampus) try { CityCampus.update(dt); } catch (e) {}
  if (window.CityBook) try { CityBook.update(dt); } catch (e) {}
  if (window.CityPodium) try { CityPodium.update(dt); } catch (e) {}
  // ship + avatar + sable placement (scene space = absolute - origin)
  ship.position.set(S.ship.x - origin.x, S.ship.y, S.ship.z - origin.z); ship.quaternion.copy(S.ship.q);
  var fl = S.mode === 'fly' || S.mode === 'auto' || S.mode === 'launch' || S.mode === 'watch' ? 0.6 + Math.min(S.ship.speed, 3000) / 1200 + (S.ship.boost ? 0.8 : 0) : S.mode === 'countdown' ? null : 0.01;
  if (fl !== null) shipFlames.forEach(function (f) { f.scale.set(1, Math.min(fl, 2.2) * (0.9 + Math.random() * 0.2), 1); });
  avatar.position.set(S.p.x - origin.x, S.p.y, S.p.z - origin.z);
  sable.position.set(SABLE_POS.x - origin.x, SABLE_POS.y + 0.1 + Math.sin(S.t * 1.3) * 0.06, SABLE_POS.z - origin.z);
  if (S.mode === 'walk') sable.rotation.y = Math.atan2(S.p.x - SABLE_POS.x, S.p.z - SABLE_POS.z);
  sable.userData.halo.rotation.z = S.t;
  for (var i = 0; i < animated.length; i++) animated[i](S.t);
  placeCamera(dt);
  updateTerrain({ x: camAbs.x, y: camAbs.y, z: camAbs.z }, MOBILE ? 4 : 6);
  updateHUD(dt);
  renderer.render(scene, camera);
  if (PERF) { renderer.getContext().finish(); workTimes.push(performance.now() - now0); if (workTimes.length > 600) workTimes.shift(); }
}

/* ---------------- boot ---------------- */
var cityBuilt = false;
function boot() {
  $('sc-load').textContent = 'Raising the capital…';
  setTimeout(function () {
    buildCity(); cityBuilt = true; try { dispatchEvent(new Event('sc-city-built')); } catch (e) {}
    $('sc-load').textContent = 'Generating the island chain…';
    setTimeout(function () {
      camAbs.set(0, 30, 60);
      for (var n = 0; n < 6; n++) updateTerrain({ x: 0, y: 30, z: 60 }, 120);
      buildMap();
      if (window.CityPlayer) { CityPlayer.mount($('sc-hud')); CityPlayer.onChange(function (s) { NP.playing = s.playing; if (NP.draw && (s.title !== NP.t || s.playing !== NP.p)) { NP.t = s.title; NP.p = s.playing; NP.draw(s.title, s.kind, s.playing); } }); setTimeout(function () { CityPlayer.preload(); }, 200); }
      $('sc-load').textContent = 'Ready.'; $('sc-enter').disabled = false;
      if (QS.has('auto')) enter();
    }, 30);
  }, 30);
}
function enter() {
  if (window.CityPlayer) CityPlayer.gesture();   // the ENTER tap unlocks audio on iOS
  if (QS.get('fs') === '1') { var fe = document.documentElement, rf = fe.requestFullscreen || fe.webkitRequestFullscreen; if (rf) try { var fp = rf.call(fe); if (fp && fp.catch) fp.catch(function () {}); } catch (e) {} }   // from /press-start
  $('sc-boot').hidden = true; $('sc-hud').hidden = false; if (window.AudioDrive) AudioDrive.attach(); running = true; last = performance.now(); requestAnimationFrame(frame);
  help(IS_TOUCH ? 'Left stick to walk, drag to look. Tap SABLE to talk. The spaceport is to the south-west.' : 'WASD to walk, drag to look, E to interact. Tap SABLE to talk. The spaceport is south-west — board a ship and fly.', 8);
}
$('sc-enter').disabled = true; $('sc-enter').addEventListener('click', enter);
S.camYaw = 0;
boot();

/* test / screenshot hooks (read-only debugging; no server effect) */
window.SC = {
  state: S, origin: origin,
  stats: function () { var ft = frameTimes.slice().s