<!-- RUBY-BACKUP · part 135 -->
);
    /* Restore saved pose — if they left on their belly, they're still on it */
    try{
      var savedPose = localStorage.getItem('ruby-pose');
      if(savedPose === 'lay'){
        window._laying = true;
        if(myAvatar) myAvatar.rotation.x = -Math.PI/2;
        codeStatus('still on your belly — hit Stand');
      }else if(savedPose === 'crouch'){
        window._crouching = true;
        if(myAvatar) myAvatar.scale.y = 0.6;
      }
    }catch(e){}
  }else{
    if(myAvatar) myAvatar.visible = false;
    setFly(false);
    camera.near = 0.1; camera.updateProjectionMatrix();
    codeStatus('back to the high view');
  }
  if(typeof ghost!=='undefined' && ghost) ghost.visible = false;
}
function setFly(on){
  var wasFlying = FLYM;
  FLYM = !!on;
  var fb = document.getElementById('flybtn');
  if(fb) fb.classList.toggle('on', FLYM);
  /* sword retired */
  if(FLYM){
    aimYaw = faceYaw; aimPitch = 0; aimedAnchor = null;
    /* Fly clears ALL pose traps — one flight state, King's order */
    try{
      window._laying = false; window._crawling = false; window._crouching = false;
      onGround = false;
      window._takeoffUntil = performance.now() + 2000; /* 2 seconds of lift */
    }catch(e){}
    codeStatus('fly — PROVOLTA takes you up');
  }
  /* Flight end calibration — camera snaps behind the body, facing forward */
  if(wasFlying && !FLYM){
    try{
      if(typeof WALK !== 'undefined' && WALK){
        if(typeof camYaw !== 'undefined'){
          camYaw = faceYaw; camPitch = 0.55;
        }
      }else if(typeof camGoal !== 'undefined'){
        camGoal.th = faceYaw; camGoal.ph = 0.55;
      }
    }catch(e){}
  }
}
function setWear(name){
  myWearName = name || null;
  if(myWearGrp){ scene.remove(myWearGrp); myWearGrp = null; }
  if(name){
    myWearGrp = buildWearable(name);
    if(myWearGrp){ scene.add(myWearGrp); codeStatus('wearing '+name+' — send it to a friend so they see it too'); }
    else { myWearName = null; codeStatus('no save named '+name); }
  } else codeStatus('unworn');
}
loadUndo(); loadSaves(); loadDid(); loadAnchors(); drawAnchorRings(); loadPortals(); drawPortals(); loadKings(); loadShoes();
/* eyes first — on every load, Solid sees (if chosen) */
setTimeout(function(){
  try{
    var ea = true;
    try{ ea = localStorage.getItem('ruby-eyes-auto')!=='0'; }catch(e){}
    if(ea && typeof Mainframe!=='undefined' && WATCH_ID) Mainframe.run('eyes');
  }catch(e){}
}, 4000);
try{
  /* v116 -> v117 migration: the 169 separate stones become the one whole */
  var hadOld = false;
  for(var fi=stones.children.length-1; fi>=0; fi--){ if(stones.children[fi].userData.y===-59){ stones.remove(stones.children[fi]); hadOld = true; } }
  if(hadOld){ save(); try{ localStorage.setItem(FLOOR_KEY, '1'); }catch(e){} }
  /* THE GROUND IS NEVER MISSING — build floor unconditionally */
  try{ if(typeof buildFloorMesh==='function') buildFloorMesh(); }catch(e){}
  try{ localStorage.setItem(FLOOR_KEY,'1'); }catch(e){}
  try{
    loadDigs();
    if(localStorage.getItem(LAND_KEY)==='1'){
      if(!floorMesh){ buildFloorMesh(); try{ localStorage.setItem(FLOOR_KEY,'1'); }catch(e){} }
      buildLandMesh();
      buildLandGrid();
    }
    else { /* every new world is born with land */
      if(!floorMesh){ buildFloorMesh(); try{ localStorage.setItem(FLOOR_KEY,'1'); }catch(e){} }
      buildLandMesh();
      buildLandGrid();
      try{ localStorage.setItem(LAND_KEY,'1'); }catch(e){}
    }
  }catch(e){}
}catch(e){}
/* ?body=king&crown=1 — load in the crown on the body, no punching in */
/* ?walk=1 — load walking in your body, avatars on, no punching in */
if(START_CROWN){ if(!WALK) setWalk(true); CROWN = true; glide = null; crownIntro = true; }
else if(START_WALK){ if(!WALK) setWalk(true); }
if(/[?&]far=1/.test(location.search)){ camDist = 40; camPitch = 0.35; }
if(WATCH_ID) startWatch();

/* ---- ghost: a 1-ruby whisper of the chosen shape where it will land (not a menu) ---- */
var ghostPlainMat = new T.MeshBasicMaterial({color:0xffd700, transparent:true, opacity:0.35, depthWrite:false});
var ghost = new T.Mesh(shapeGeo('cube', window.MINIMUM), ghostPlainMat);
ghost.userData.k = 1;
ghost.visible = false; scene.add(ghost);
function refreshGhost(){
  var base = shapeBase(curShapeKey), ghostly = shapeIsGhost(curShapeKey);
  var k = legalK1(base);
  ghost.geometry.dispose();
  ghost.geometry = shapeGeo(base, window.MINIMUM);
  ghost.material = ghostly ? intaglioMat : ghostPlainMat;
  ghost.scale.set(k, k, k);
  ghost.userData.k = k;
}

/* ---- the code popup: the shape's own code is the only thing that pops up on each block ---- */
var rubiEl = document.getElementById('rubicount'), rubiT = null;
function shapeCodeOf(shapeKey){
  var base = shapeBase(shapeKey), ghostly = shapeIsGhost(shapeKey);
  var c = SHAPE_CODES[base]||'?';
  return ghostly ? c.toUpperCase() : c;
}
function showShapeCode(g){
  var u = g.userData, r = u.rubies||1;
  var top = r*(u.k1||1)*window.MINIMUM;
  var