<!-- RUBY-BACKUP · part 506 -->
)*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);
  }
}
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);
  var d = Math.sqrt(x*x+z*z);
  if(d < 2){ var sh = 1-d/2; h = h*(1-sh) + (-0.24)*sh; }
  return h;
}
function landBase(x, z){
  /* the plateau — 2 grids of sure flat ground, for us to stand */
  var P = (typeof PLATEAU!=='undefined' && PLATEAU) ? PLATEAU : {x:8, z:8, r:2.5, h:0.9};
  var pdx = x-P.x, pdz = z-P.z, pd = Math.sqrt(pdx*pdx+pdz*pdz);
  if(pd < P.r) return P.h;
  var h = landBaseRaw(x, z);
  /* blend the plateau's edge */
  if(pd < P.r+3){ var t = (pd-P.r)/3; h = P.h*(1-t*t*(3-2*t)) + h*(t*t*(3-2*t)); }
  /* the sacred hollow — the ruby's cell stays open */
  if(d < 2){ var sh = 1-d/2; h = h*(1-sh) + (-0.24)*sh; }
  return h;
}
function applyDigs(h, x, z){
  for(var i=0;i<digs.length;i++){
    var dg = digs[i], dx = x-dg.x, dz = z-dg.z, dist = Math.sqrt(dx*dx+dz*dz);
    if(dist < dg.r){ var t = 1-dist/dg.r; h -= dg.d * t*t*(3-2*t); }
  }
  return h;
}
function landH(x, z){
  if(!landMesh) return 0;
  var h = applyDigs(landBaseRaw(x, z), x, z);
  var d = Math.sqrt(x*x+z*z);
  if(d < 2) return h;  /* the sacred hollow keeps its depth */
  return Math.max(0.02, h);
}
function persistDigs(){
  try{ localStorage.setItem(DIG_KEY, JSON.stringify(digs)); }catch(e){}
}
function loadDigs(){
  try{ digs = JSON.parse(localStorage.getItem(DIG_KEY)||'[]'); }catch(e){ digs=[]; }
}
function refreshLandMesh(cx, cz, cr){
  if(!landMesh || !landMesh.geometry.userData.topCount) return;
  var pa = landMesh.geometry.attributes.position;
  var topN = landMesh.geometry.userData.topCount;
  for(var i=0; i<topN; i++){
    var x = pa.getX(i), z = pa.getZ(i);
    var dx = x-cx, dz = z-cz;
    if(dx*dx+dz*dz < (cr+3)*(cr+3)) pa.setY(i, FLOOR_Y + 0.02 + landH(x, z));
  }
  pa.needsUpdate = true;
  landMesh.geometry.computeVertexNormals();
}
function digAt(x, z){
  digs.push({x:x, z:z, r:4.5, d:1.6});
  persistDigs();
  refreshLandMesh(x, z, 4.5);
  /* topo stays true — re-chart the dug area */
  try{
    if(TOPO && typeof groundY!=='undefined'){
      for(var ix=Math.max(TOPO_MIN,Math.floor(x-6)); ix<=Math.min(TOPO_MAX,Math.ceil(x+6)); ix++){
        for(var iz=Math.max(TOPO_MIN,Math.floor(z-6)); iz<=Math.min(TOPO_MAX,Math.ceil(z+6)); iz++){
          TOPO[ix+','+iz]=groundY(ix,iz);
        }
      }
    }
  }catch(e){}
}
function groundY(x, z){
  var base = FLOOR_Y + 0.02 + landH(x, z);
  // Check solid node surfaces (standable, impenetrable)
  if(typeof SOLID_SURFACES==='undefined') return base;
  for(var i=0; i<SOLID_SURFACES.length; i++){
    var sf = SOLID_SURFACES[i];
    var dx = x - sf.x, dz = z - sf.z;
    if(dx*dx + dz*d