<!-- SOLID CITY · part 1971 -->
dy.appendChild(b);
  M.outBtn = b;
  return b;
}
function nearCar(wx, wz) {
  if (!M.group) return null;
  var cars = (M.group.userData || {}).cars || [], best = null, bd = 5.2;
  cars.forEach(function (car) {
    if (car.state !== 'parked') return;
    var d = Math.hypot(wx - (POS.x + car.x), wz - (POS.z + car.z));
    if (d < bd) { bd = d; best = car; }
  });
  return best;
}
function actHere(wx, wz) {
  if (window.CityDrive && CityDrive.active()) return { kind: 'firstparking', label: 'STEP OUT OF THE RIDE' };
  var car = nearCar(wx, wz);
  if (car) return { kind: 'firstparking', label: '\uD83D\uDE97 ROLL \u2014 ' + car.name };
  return null;
}
function act() {
  if (window.CityDrive && CityDrive.active()) {
    var st = CityDrive.state();
    if (CityDrive.end() !== true) return; // RUNG 2: NO_SAFE_EXIT — the driver stays seated, the car stays driven, nothing is re-parked
    if (st && st.carId && M.group) {
      (M.group.userData.cars || []).forEach(function (car) {
        if (car.id === st.carId) {
          car.state = 'parked';
          car.x = car.mesh.position.x; car.z = car.mesh.position.z; car.yaw = car.mesh.rotation.y;
          car.solids = addBox(car.x, car.z, 2.6, 5.6, car.yaw, car.y, car.y + 2.1);
        }
      });
    }
    return;
  }
  var car = nearCar(S.p.x, S.p.z);
  if (!car || !window.CityDrive) return;
  if (!CityDrive.begin(car.mesh, car.yaw, POS.x, POS.z, car.id)) return; // RUNG 2: admission first — a refused entry moves nothing (no solid lifted, no state flipped)
  removeSolids(car.solids); car.solids = null;
  car.state = 'driven';
}
function load() {
  M.state = 'loading';
  var p; try { p = import('/city/first-city-parking.js?v=20261013a'); } catch (e) { p = Promise.reject(e); }
  p.then(function (mod) {
    var make = mod.createFirstParking || mod.default;
    var g = make({ THREE: A.T, groundAt: (typeof groundAt === 'function') ? groundAt : function () { return 20; }, deckY: firstCityDeckY() });
    g.position.set(POS.x, 0, POS.z);
    A.world.add(g); M.group = g; M.state = 'ready';
    collide(g.userData || {}); hyperStop(); outButton();
    if (window.logBuild) logBuild('first-parking', 'The South Lot: apron + ramp + 14 rides + the Long Road, below the First City');
  }).catch(function (e) { M.state = 'failed'; try { console.warn('[city] South Lot skipped:', e && e.message); } catch (x) {} });
}
function standY(wx, wz, wy) {
  var deckY = firstCityDeckY(), best = -1;
  // the First City's own podium (lent by this placer until its own grows one)
  if (wx > FC.x - 212 && wx < FC.x + 212 && wz > FC.z - 380 && wz < FC.z + 380) {
    if (wy > deckY - 2.4 && deckY > best) best = deckY;
  }
  if (M.state !== 'ready' || !M.group) return best;
  var lx = wx - POS.x, lz = wz - POS.z, zones = M.group.userData.zones || [];
  for (var i = 0; i < zones.length; i++) {
    var zn = zones[i];
    if (zn.kind === 'flat') {
      if (lx >= zn.x0 && lx <= zn.x1 && lz >= zn.z0 && lz <= zn.z1 && wy > zn.y - 2.4 && zn.y > best) best = zn.y;
    } else if (zn.kind === 'ramp') {
      if (lx >= zn.x0 && lx <= zn.x1 && lz >= zn.z0 && lz <= zn.z1) {
        var t = (lz - zn.z0) / (zn.z1 - zn.z0), sy = zn.y0 + (zn.y1 - zn.y0) * t;
        if (wy > sy - 2.4 && sy > best) best = sy;
      }
    } else if (zn.kind === 'road') {
      for (var j = 0; j < zn.segs.length; j++) {
        var sg = zn.segs[j], dx = sg.x2 - sg.x1, dz = sg.z2 - sg.z1, L2 = dx * dx + dz * dz;
        var tt = L2 > 0 ? ((lx - sg.x1) * dx + (lz - sg.z1) * dz) / L2 : 0;
        if (tt < -0.05 || tt > 1.05) continue;
        var px = sg.x1 + dx * tt, pz = sg.z1 + dz * tt;
        if (Math.hypot(lx - px, lz - pz) > 7.2) continue;
        var ry = sg.y1 + (sg.y2 - sg.y1) * tt + 0.02;
        if (wy > ry - 2.4 && ry > best) best = ry;
      }
    }
  }
  return best;
}
function update(dt) {
  if (M.state === 'idle') { if (A.isBuilt && !A.isBuilt()) return; M.wait -= dt; if (M.wait <= 0) load(); return; }
  if (M.state !== 'ready' || document.hidden) return;
  var c = A.camera.position, d = Math.hypot(c.x + A.origin.x - POS.x, c.z + A.origin.z - (POS.z + 122));
  M.group.visible = d < 9000;
  if (d < 3200 && M.group.userData.update) try { M.group.userData.update(S.t); } catch (e) {}
  if (M.outBtn) M.outBtn.style.display = (window.CityDrive && CityDrive.active()) ? 'block' : 'none';
  if (S.mode === 'walk' && !S.drive) {
    var pd = Math.hypot(S.p.x - POS.x, S.p.z - (POS.z + 122));
    if (pd < 300 && !M.said) { M.said = true; if (window.CityHyper && CityHyper.narrate) CityHyper.narrate('<b>The South Lot</b>: fourteen rides under the First City. Walk to one and roll \u2014 the Long Road runs east to the capital.', 10); }
    else if (pd > 600) M.said = false;
  }
}
function radar(g, blip, fl) { if (M.state === 'ready') blip(POS.x, POS.z + 122, '#ffd27a', fl ? 3 : 6, fl ? '' : 'SOUTH LOT'); }
window.CityFirstParking = { update: update, radar: radar, standY: standY, actHere: actHere, act: act, pos: 