<!-- RUBY-BACKUP · part 319 -->
0*Math.cos(camYaw));
          camera.position.copy(crownIntroFrom);
        }
        crownIntroT += dt;
        var cik = Math.min(1, crownIntroT/2.5), cie = cik*cik*(3-2*cik);
        _a1.set(mePos.x, mePos.y + hh, mePos.z);
        camera.position.lerpVectors(crownIntroFrom, _a1, cie);
        var igy = groundY(camera.position.x, camera.position.z);
        if(camera.position.y < igy + 0.6) camera.position.y = igy + 0.6;
        _a2.set(Math.sin(camYaw)*Math.cos(camPitch), Math.sin(camPitch), Math.cos(camYaw)*Math.cos(camPitch));
        _a3.set(mePos.x, mePos.y + 0.6, mePos.z);
        _a2.add(_a1);
        _a3.lerp(_a2, cie);
        camera.lookAt(_a3);
        if(myAvatar) myAvatar.visible = true;
        if(myWearGrp) myWearGrp.visible = true;
        if(cik >= 1){ crownIntro = false; crownIntroT = 0; crownIntroFrom = null; }
      }else{
        var cgy = groundY(mePos.x, mePos.z);
        camera.position.set(mePos.x, Math.max(mePos.y + hh, cgy + 0.6), mePos.z);
        _a1.set(Math.sin(camYaw)*Math.cos(camPitch), Math.sin(camPitch), Math.cos(camYaw)*Math.cos(camPitch));
        _a2.copy(camera.position).add(_a1);
        camera.lookAt(_a2);
        if(myAvatar) myAvatar.visible = false;
        if(myWearGrp) myWearGrp.visible = false;
      }
    }else{
      /* Fly cam — your 360, eyes on her body (King's order) */
      var _chaseDist = camDist, _chaseH = 0.16;
      if(typeof FLYM !== 'undefined' && FLYM){
        _chaseDist = Math.max(_chaseDist, 6); /* pull back to see her */
        _chaseH = 0.5; /* eyes on her body */
      }
      var wgy = groundY(mePos.x + _chaseDist*Math.sin(camYaw)*cpw, mePos.z + _chaseDist*Math.cos(camYaw)*cpw);
      camera.position.set(
        mePos.x + _chaseDist*Math.sin(camYaw)*cpw,
        Math.max(mePos.y + 0.22 + _chaseDist*Math.sin(camPitch), wgy + 0.6),
        mePos.z + _chaseDist*Math.cos(camYaw)*cpw
      );
      camera.lookAt(mePos.x, mePos.y+_chaseH, mePos.z);
      if(myAvatar) myAvatar.visible = true;
      if(myWearGrp) myWearGrp.visible = true;
    }
    /* sword retired — block removed */
    if(myAvatar){
      myAvatar.position.copy(mePos);
      if(AVATAR==='king') myAvatar.rotation.y = faceYaw;
      if(myWearGrp) myWearGrp.position.set(mePos.x, mePos.y + (AVATAR==='king'?1.35:0.4) + Math.sin(t*2)*0.03, mePos.z);
    }
    for(var rcid in remoteAvatars){
      var rao = remoteAvatars[rcid];
      rao.grp.position.y = Math.sin(t*2 + rao.phase)*0.03;
      if(rao.wearGrp) rao.wearGrp.position.y = (rao.kind==='king'?1.35:0.4) + Math.sin(t*2+rao.phase)*0.03;
    }
  }
  /* floating words ride over their speakers, then fade */
  if(floatWords.length){
    var nowMs = performance.now();
    for(var fi=floatWords.length-1; fi>=0; fi--){
      var fw = floatWords[fi], left = fw.until - nowMs;
      if(left<=0){ fw.el.remove(); floatWords.splice(fi,1); continue; }
      var pp = null;
      if(fw.client===CLIENT_ID){
        if(WALK && myAvatar) pp = _a1.set(myAvatar.position.x, myAvatar.position.y + (AVATAR==='king'?1.7:0.55), myAvatar.position.z);
        else if(typeof cursor!=='undefined' && cursor) pp = _a1.set(cursor.x, 2.2, cursor.z);
      }else if(fw.client && remoteAvatars[fw.client]){
        var rra = remoteAvatars[fw.client];
        pp = _a1.set(rra.grp.position.x, rra.grp.position.y + (rra.kind==='king'?1.7:0.55), rra.grp.position.z);
      }
      if(!pp){ fw.el.style.display='none'; continue; }
      _a2.copy(pp).project(camera);
      if(_a2.z>1){ fw.el.style.display='none'; continue; }
      fw.el.style.display='block';
      fw.el.style.left = ((_a2.x*0.5+0.5)*window.innerWidth)+'px';
      fw.el.style.top = ((-_a2.y*0.5+0.5)*window.innerHeight)+'px';
      fw.el.style.opacity = left<1500 ? (left/1500).toFixed(2) : '1';
    }
  }else if(!WALK){
    /* the high view — never while walking; the body owns the camera there */
    camT.th += (camGoal.th-camT.th)*0.12;
    camT.ph += (camGoal.ph-camT.ph)*0.12;
    camT.r  += (camGoal.r -camT.r )*0.12;
    camera.position.set(
      lookTarget.x + camT.r*Math.sin(camT.ph)*Math.sin(camT.th),
      camT.r*Math.cos(camT.ph),
      lookTarget.z + camT.r*Math.sin(camT.ph)*Math.cos(camT.th)
    );
    camera.lookAt(lookTarget);
  }
  try{ if(typeof updatePadFollow==='function') updatePadFollow(); }catch(e){}
  try{ if(typeof updateCrownLock==='function') updateCrownLock(); }catch(e){}
  renderer.render(scene, camera);
})();

/* CODE PALETTE - scroll through, tap to send (King's idea 2026-10-01) */
(function(){
  var codes = [
    'b 1 1 1', 'b 1 1 2', 'b 1 1 3', 'b 1 1 4', 'b 1 1 5', 'b 1 1 6', 'b 1 1 7', 'b 1 1 8', 'b 1 1 9', 'b 1 1 10', 'b 1 2 1', 'b 1 2 2', 'b 1 2 3', 'b 1 2 4', 'b 1 2 5', 'b 1 2 6', 'b 1 2 7', 'b 1 2 8', 'b 1 2 9', 'b 1 2 10', 'b 1 3 1', 'b 1 3 2', 'b 1 3 3', 'b 1 3 4', 'b 1 3 5', 'b 1 3 6', 'b 1 3 7', 'b 1 3 8', 'b 1 3 9', 'b 1 3 10', 'b 1 4 1', 'b 1 4 2', 'b 1 4 3', 'b 1 4 4', 'b 1 4 5', 'b 1 4 6', 'b 1 4 7', 'b 1 4 8', 'b 1 4 9', 'b 1 4 