<!-- RUBY-BACKUP · part 348 -->
Math.PI/2); o.blade.translate(0,0,0.28);
  o.tip  = new T.ConeGeometry(0.055, 0.12, 4); o.tip.rotateY(Math.PI/4); o.tip.rotateX(Math.PI/2); o.tip.translate(0,0,0.51);
  o.guard= new T.BoxGeometry(0.20, 0.035, 0.07); o.guard.translate(0,0,0.08);
  o.grip = new T.CylinderGeometry(0.025, 0.025, 0.14, 8); o.grip.rotateX(Math.PI/2); o.grip.translate(0,0,-0.02);
  o.pommel=new T.SphereGeometry(0.035, 8, 6); o.pommel.translate(0,0,-0.11);
  o.tipglow=new T.SphereGeometry(0.028, 8, 6); o.tipglow.translate(0,0,0.58);
  return o;
})();
var avatarGlowMat = new T.MeshBasicMaterial({color:0xfff2b0});
var eyeGlowMat   = new T.MeshBasicMaterial({color:0xffb830});
var smileMat     = new T.MeshBasicMaterial({color:0x6b4d0c});
var jewelRedMat  = new T.MeshStandardMaterial({color:0xb3001b, emissive:0xff1a2e, emissiveIntensity:1.4, roughness:0.2, metalness:0.3});
var jewelBlueMat = new T.MeshStandardMaterial({color:0x1a3cff, emissive:0x2a4cff, emissiveIntensity:1.2, roughness:0.2, metalness:0.3});
var jewelGreenMat= new T.MeshStandardMaterial({color:0x0fbf5a, emissive:0x0fbf5a, emissiveIntensity:1.2, roughness:0.2, metalness:0.3});
var pearlMat     = new T.MeshStandardMaterial({color:0xfff6e8, roughness:0.35, metalness:0.1});
var WALK=false, FLYM=false, WALKLINE=false, walkLineLast=null;
var mePos=new T.Vector3(0,0,0), meVel=new T.Vector3();
var mirrorStones=[];
(function(){
  function makeMirrors(){
    try{
      for(var i=0; i<2; i++){
        var m=new T.Mesh(new T.BoxGeometry(0.3,0.1,0.3), new T.MeshBasicMaterial({visible:false}));
        m.visible=false;
        scene.add(m);
        mirrorStones.push(m);
      }
    }catch(e){}
  }
  if(typeof scene!=='undefined' && scene) makeMirrors();
  else setTimeout(makeMirrors, 2000);
})();
/* ORGANIZED MAP BUILD — on fresh load, build in order: floor, land, player, mirrors */
function buildMapOrganized(){
  try{
    /* 1. Floor first */
    if(typeof buildFloorMesh==='function' && (typeof floorMesh==='undefined' || !floorMesh)){
      buildFloorMesh();
      try{ localStorage.setItem(FLOOR_KEY,'1'); }catch(e){}
    }
    /* 2. Land/heightmap */
    if(typeof buildLandMesh==='function' && (typeof landMesh==='undefined' || !landMesh)){
      buildLandMesh();
      try{ localStorage.setItem(LAND_KEY,'1'); }catch(e){}
    }
    /* 3. Player on top of land */
    if(typeof groundY==='function' && typeof mePos!=='undefined'){
      var gy=groundY(8,8);
      mePos.set(8, gy+0.1, 8);
      if(typeof meVel!=='undefined') meVel.set(0,0,0);
    }
    /* 4. Mirror stones below */
    try{
      if(typeof mirrorStones!=='undefined' && mirrorStones.length===2 && typeof groundY==='function'){
        var gy2=groundY(mePos.x, mePos.z);
        mirrorStones[0].position.set(mePos.x-0.12, gy2-0.25, mePos.z);
        mirrorStones[1].position.set(mePos.x+0.12, gy2-0.25, mePos.z);
      }
    }catch(e){}
    /* 5. Verify shoes on land, else fly */
    setTimeout(function(){
      try{
        if(typeof groundY==='function' && typeof mePos!=='undefined'){
          var gy3=groundY(mePos.x, mePos.z);
          if(Math.abs(mePos.y - gy3) > 0.5 && typeof setFly==='function' && !FLYM){
            setFly(true);
          }
        }
      }catch(e){}
    }, 1000);
  }catch(e){}
}
/* auto-load 8ms after load */

/* TOPOGRAPHICAL MAP — on load, chart the land so nothing builds below it */
var TOPO = null, TOPO_MIN = -70, TOPO_MAX = 70;
function buildTopoMap(){
  try{
    if(typeof groundY==='undefined') return;
    TOPO = {};
    for(var x=TOPO_MIN; x<=TOPO_MAX; x++){
      for(var z=TOPO_MIN; z<=TOPO_MAX; z++){
        TOPO[x+','+z] = groundY(x, z);
      }
    }
  }catch(e){}
}
function topoY(x, z){
  try{
    if(!TOPO) return null;
    var ix = Math.round(x), iz = Math.round(z);
    if(ix<TOPO_MIN || ix>TOPO_MAX || iz<TOPO_MIN || iz>TOPO_MAX) return null;
    return TOPO[ix+','+iz];
  }catch(e){ return null; }
}

/* FORTIFIED FOUNDATION — the land is impenetrable from all error */
var LAND_FORTIFIED = true;
var _lastGoodGround = {};
function fortifiedGroundY(x, z){
  try{
    if(typeof x!=='number' || typeof z!=='number' || !isFinite(x) || !isFinite(z)){
      return 0.3; /* invalid input → safe default */
    }
    /* clamp to sane world bounds */
    x = Math.max(-1000, Math.min(1000, x));
    z = Math.max(-1000, Math.min(1000, z));
    var y;
    try{
      y = groundY(x, z);
    }catch(e){
      y = NaN;
    }
    /* validate the result */
    if(typeof y!=='number' || !isFinite(y)){
      var key = Math.round(x)+','+Math.round(z);
      y = _lastGoodGround[key];
      if(typeof y!=='number' || !isFinite(y)) y = 0.3;
    }else{
      /* remember the good value */
      var key2 = Math.round(x)+','+Math.round(z);
      _lastGoodGround[key2] = y;
      /* prune cache if too large */
      if(Object.keys(_lastGoodGround).length > 5000) _lastGoodGround = {};
    }
    /* never below the absolute floor */
    y = Math.max(0.02, y);
    /* never absurdly high (error spik