<!-- RUBY-BACKUP · part 288 -->
vx*vx+vz*vz);
    var flat = Math.min(1, dc/100); // flat within 100 units of center
    h *= flat;
    // keep highways corridors flatter (they're elevated anyway)
    _pos.setY(vi, h);
  }
  geo.computeVertexNormals();
  // subtle natural variation via vertex colors (not a grid)
  var colors = [];
  var posAttr = geo.attributes.position;
  var baseColor = new T.Color(0x3a5a2a); /* grass green */
  var varColor = new T.Color(0x2a4a1a); /* darker grass */
  for(var i=0; i<posAttr.count; i++){
    var x = posAttr.getX(i), z = posAttr.getZ(i);
    // organic noise, not grid-aligned
    var n = Math.sin(x*0.05)*Math.cos(z*0.05)*0.5 + 0.5;
    var c = baseColor.clone().lerp(varColor, n*0.4);
    // sacred ruby cell stays clear
    if(Math.abs(x)<10 && Math.abs(z)<10){
      c = new T.Color(0x1a1a1a);
    }
    colors.push(c.r, c.g, c.b);
  }
  geo.setAttribute('color', new T.Float32BufferAttribute(colors, 3));
  floorMesh = new T.Mesh(geo, new T.MeshStandardMaterial({
    vertexColors: true,
    roughness: 0.95,
    metalness: 0.0,
    side: T.DoubleSide
  }));
  floorMesh.position.y = 0.13;
  scene.add(floorMesh);
  FLOOR_Y = 0.13;
}
var landMesh = null;
var LAND_KEY = 'ruby-land-v1';
var digs = [];
var DIG_KEY = 'ruby-digs-v1';
var eyesLive = null;
var bodyTool = false;
var solidStopped = false;
try{ solidStopped = localStorage.getItem('ruby-solid-stopped')==='1'; }catch(e){}
var ourGrid = null;
function trackPlateau(){
  /* the grid moves for us — the build does not */
  if(typeof PLATEAU==='undefined' || !PLATEAU) return;
  if(typeof mePos!=='undefined' && mePos){
    var gx = Math.round(mePos.x/2)*2, gz = Math.round(mePos.z/2)*2;
    if(gx!==PLATEAU.x || gz!==PLATEAU.z){
      PLATEAU.x = gx; PLATEAU.z = gz;
      /* the flat sits on the hill beneath — never floating, never buried */
      var d = Math.sqrt(gx*gx+gz*gz);
      var hb = applyDigs(landBaseRaw(gx, gz), gx, gz);
      PLATEAU.h = (d<2) ? hb : Math.max(0.02, hb);
    }
    /* render our reality — only 20 steps from the edge, fading smooth, snapped to the intaglio linework */
    if(!ourGrid){
      var og = new T.CircleGeometry(PLATEAU.r, 24);
      ourGrid = new T.Mesh(og, new T.MeshBasicMaterial({color:0xffd700, transparent:true, opacity:0, side:T.DoubleSide, depthWrite:false}));
      ourGrid.rotation.x = -Math.PI/2;
      scene.add(ourGrid);
    }
    var edgeD = 49 - Math.max(Math.abs(PLATEAU.x), Math.abs(PLATEAU.z));
    var want = edgeD >= 20 ? 0.12 : 0;
    var cur = ourGrid.material.opacity;
    ourGrid.material.opacity = cur + (want-cur)*0.15; /* the map flows smooth, never pops */
    ourGrid.visible = ourGrid.material.opacity > 0.01;
    /* locked — our grid steps on reality 2's land */
    ourGrid.position.set(PLATEAU.x, groundY(PLATEAU.x, PLATEAU.z)+0.03, PLATEAU.z);
  }
}
/* RESPECT ZONES — roads, buildings, flat areas, city: the land bows to them */
var _respectZones = [];
window.addRespectZone = function(x, z, r){
  _respectZones.push({x: x, z: z, r: r});
};
function inRespectZone(x, z){
  for(var i = 0; i < _respectZones.length; i++){
    var rz = _respectZones[i];
    var dx = x - rz.x, dz = z - rz.z;
    if(dx*dx + dz*dz < rz.r * rz.r) return true;
  }
  try{
    var cc = (typeof getCityCenter === 'function' ? getCityCenter() : {x: 25, z: -10});
    var cdx = x - cc.x, cdz = z - cc.z;
    if(cdx*cdx + cdz*cdz < 30*30) return true;
  }catch(e){}
  var qdx = x - 8, qdz = z - 9;
  if(qdx*qdx + qdz*qdz < 20*20) return true;
  return false;
}
var WATER_LEVEL = 0.25;
window.getWaterLevel = function(){ return WATER_LEVEL; };
function landBaseRaw(x, z){
  var h = 0.6*Math.sin(x*0.09)*Math.cos(z*0.07)
        + 0.35*Math.sin(x*0.16+1.7)*Math.sin(z*0.13+0.6)
        + 0.22*Math.cos(x*0.05-0.8)*Math.sin(z*0.06+2.1);
  h = Math.max(0.05, h+0.45);
  if(inRespectZone(x, z)){
    var d0 = Math.sqrt(x*x+z*z);
    if(d0 < 2){ var sh0 = 1-d0/2; h = h*(1-sh0) + (-0.24)*sh0; }
    return h;
  }
  var distC = Math.sqrt(x*x + z*z);
  if(distC > 200){
    var mtn = 2.5 * Math.abs(Math.sin(x*0.02) * Math.cos(z*0.025));
    mtn += 1.2 * Math.abs(Math.sin(x*0.04+1) * Math.sin(z*0.035+2));
    var valley = 1.0 * Math.abs(Math.cos(x*0.015+0.5) * Math.sin(z*0.02+1.5));
    h += mtn - valley * 0.5;
  }
  if(distC > 100 && distC < 400){
    var canyonPath = Math.sin(x*0.03) * 50 + Math.cos(z*0.02) * 30;
    var canyonDist = Math.abs(z - canyonPath - 150);
    if(canyonDist < 15){
      var depth = (1 - canyonDist/15);
      depth = depth * depth * (3 - 2*depth);
      h -= depth * 2.0;
    }
  }
  if(distC > 300){
    var cliffZone = Math.sin(x*0.05) * Math.cos(z*0.04);
    if(cliffZone > 0.7){ h += 1.5; }
  }
  var riverPath = Math.sin(x*0.025+2) * 80;
  var riverDist = Math.abs(z - riverPath + 100);
  if(riverDist < 8 && distC > 80){
    var rd = (1 - riverDist/8);
    rd = rd * rd * (3 - 2*rd);
    h -= rd * 1.2;
    if(h < WATER_LEVEL + 0.3) h = WATER_LEVEL - 0.1;
  }
  var d = Math.sqrt(x*x+z*z);
  if(d < 2){ var sh 