<!-- SAGA-STAGING · part 68 -->
rData.armR.rotation.x = -Math.sin(animPhase.swim) * animAmp.swim;
      playerBody.rotation.x = -Math.PI/2 + 0.3;
    } else if(moveMode==='fly'){
      /* Fly: tilt only, limbs ease to neutral */
      if(playerBody.userData.legL) playerBody.userData.legL.rotation.x *= 0.9;
      if(playerBody.userData.legR) playerBody.userData.legR.rotation.x *= 0.9;
    }
  }
  /* 1. AUTO-SWIM check */
  if(typeof waterAt !== 'undefined'){
    var wtr = waterAt(kingPos.x, kingPos.z);
    if(wtr && kingPos.y <= wtr.surfaceY + 0.3 && moveMode !== 'swim' && moveMode !== 'fly'){
      moveMode = 'swim';
    } else if(!wtr && moveMode === 'swim'){
      moveMode = 'walk';
    }
  }
  updateCamera();
  renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', function(){
  camera.aspect=window.innerWidth/window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
});
document.getElementById('boot').style.display='none';
say('Coders100 — all codes organized. Type or tap \u2630.');


/* ===== v190 CORE SCOPE BRIDGE =====
 * Legacy systems below this IIFE depend on CODERS100 internals.
 * Export references only; do not alter world state.
 */
window.SAGA_CORE = window.SAGA_CORE || {};

window.SAGA_CORE.CODES = CODES;
window.SAGA_CORE.runCode = runCode;
window.SAGA_CORE.kingPos = kingPos;
window.SAGA_CORE.scene = scene;
window.SAGA_CORE.camera = camera;
window.SAGA_CORE.renderer = renderer;
window.SAGA_CORE.sfx = sfx;
window.SAGA_CORE.say = say;
window.SAGA_CORE.spawnNewBody = spawnNewBody;

window.SAGA_CORE.getGroundY = function(){ return groundY; };
window.SAGA_CORE.getMoveMode = function(){ return moveMode; };
window.SAGA_CORE.getCamYaw = function(){ return camYaw; };
window.SAGA_CORE.getCamPitch = function(){ return camPitch; };
window.SAGA_CORE.getCamDist = function(){ return camDist; };
window.SAGA_CORE.getPlayerBody = function(){ return playerBody; };

/* Legacy aliases used by existing post-IIFE code. */
window.CODES = CODES;
window.runCode = runCode;
window.kingPos = kingPos;
window.scene = scene;
window.camera = camera;
window.renderer = renderer;
window.sfx = sfx;
window.say = say;
window.spawnNewBody = spawnNewBody;

})();


/* Wire click sound to all UI buttons */
document.addEventListener('touchstart', function(e){
  var t = e.target;
  if(t && (t.tagName === 'BUTTON' || t.closest('button'))){
    sfx('click');
  }
}, {passive:true});


/* PLAYA 2.0 TOGGLE — top-right, menu with Chat, Mic, Playa 2.0 */
(function(){
  if(document.getElementById('playa2-btn')) return;
  var b = document.createElement('button');
  b.id = 'playa2-btn';
  b.innerHTML = '◆';
  b.title = 'Menu';
  b.style.cssText = 'position:fixed;top:12px;right:12px;z-index:9999;' +
    'width:44px;height:44px;border-radius:50%;' +
    'background:#1a1a2e;color:#ffd700;font-size:20px;' +
    'border:2px solid #ffd700;cursor:pointer;' +
    'display:flex;align-items:center;justify-content:center;';
  // Toggle menu
  var menu = document.createElement('div');
  menu.id = 'playa2-menu';
  menu.style.cssText = 'position:fixed;top:64px;right:12px;z-index:9998;' +
    'background:rgba(10,10,26,0.95);border:2px solid #ffd700;border-radius:12px;' +
    'padding:8px;display:none;flex-direction:column;gap:8px;';
  menu.innerHTML =
    '<button id="m-chat" style="background:#1a1a2e;color:#ffd700;border:1px solid #ffd700;border-radius:8px;padding:10px 16px;font-size:16px;cursor:pointer;min-height:48px;">💬 Chat</button>' +
    '<button id="m-mic" style="background:#1a1a2e;color:#ffd700;border:1px solid #ffd700;border-radius:8px;padding:10px 16px;font-size:16px;cursor:pointer;min-height:48px;">🎙️ Mic</button>' +
    '<button id="m-worldintel" style="background:#1a1a2e;color:#ffd700;border:1px solid #ffd700;border-radius:8px;padding:10px 16px;font-size:16px;cursor:pointer;min-height:48px;">◎ World Intelligence</button>' +
    '<button id="m-playa" style="background:#1a1a2e;color:#ffd700;border:1px solid #ffd700;border-radius:8px;padding:10px 16px;font-size:16px;cursor:pointer;min-height:48px;">◆ Playa 2.0</button>';
  document.body.appendChild(menu);
  var open = false;
  function toggleMenu(){ open = !open; menu.style.display = open ? 'flex' : 'none'; }
  b.addEventListener('click', function(e){ e.stopPropagation(); toggleMenu(); });
  b.addEventListener('touchstart', function(e){ e.stopPropagation(); toggleMenu(); }, {passive:true});
  // Wire menu buttons to original actions
  menu.querySelector('#m-chat').addEventListener('click', function(){
    var cb = document.getElementById('game-chat-btn'); if(cb) cb.click();
    toggleMenu();
  });
  menu.querySelector('#m-mic').addEventListener('click', function(){
    var mb = document.getElementById('transceiver-btn'); if(mb) mb.click();
    toggleMenu();
  });
  menu.querySelector("#m-worldintel").addEventListener("click",function(){
    toggleMenu();
    var old=document.getElementById("world-intelligence-panel")