<!-- NEWWORLD · part 2 -->
ipt>
</body>
</html>


===== FILE: public/newworld/index.html.bak-20261009-phase0 =====
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>New World</title>
<style>
  body { margin: 0; overflow: hidden; background: #000; }
  canvas { display: block; }
  #hud { position: fixed; top: 10px; left: 10px; color: #0ff; font-family: monospace; font-size: 14px; z-index: 100; }
</style>
</head>
<body>
<div id="hud">NEW WORLD</div>
<button id="radio-btn" style="position:fixed;bottom:20px;right:10px;padding:12px 16px;background:#00aaaa;border:none;border-radius:8px;color:#fff;font-size:16px;z-index:9998;">&#10022; Radio</button>
<script src="/newworld/three.min.js"></script>
<script src="/newworld/engine.js"></script>
<script src="/newworld/player.js"></script>
<script src="/newworld/input.js"></script>
<script src="/newworld/world.js"></script>
<script src="/newworld/radio.js"></script>
<script src="/newworld/main.js"></script>
<script>
// Wire the HUD radio button to the Radio panel
document.getElementById('radio-btn').onclick = function(){ Radio.show(); };
</script>
</body>
</html>


===== FILE: public/newworld/input.js =====
/* ============================================================
   INPUT.js
   Category: CONTROLS / INPUT
   Purpose: Keyboard input state — joystick comes later
   Dependencies: None (standalone)
   Provides: Input.keys
   ============================================================ */

var Input = (function(){
  'use strict';
  
  /* ----- KEY STATE ----- */
  // Tracks which keys are currently held down
  // Keys are lowercase: 'w', 'a', 's', 'd', 'arrowup', etc.
  var keys = {};
  
  /* ----- EVENT LISTENERS ----- */
  window.addEventListener('keydown', function(e){
    keys[e.key.toLowerCase()] = true;
  });
  
  window.addEventListener('keyup', function(e){
    keys[e.key.toLowerCase()] = false;
  });
  
  /* ----- PUBLIC API ----- */
  return {
    keys: keys  // Check Input.keys['w'] to see if W is held
  };
  
  /* ----- FUTURE: TOUCH JOYSTICK ----- */
  // Will add: left stick (movement), right stick (camera)
  // Will follow: GTA-style pipeline (deadzone 0.18, gamma 1.5)
  // See: CONTROLS APPROVED 2026-10-06 in MEMORY.md
})();


===== FILE: public/newworld/main.js =====
/* ============================================================
   MAIN.js
   Category: CORE / GAME LOOP
   Purpose: Ties compartments together — the heartbeat
   Dependencies: Engine, Player, Input, World
   Provides: (runs automatically, no exports)
   ============================================================ */

(function(){
  'use strict';
  
  /* ----- HUD REFERENCE ----- */
  var hud = document.getElementById('hud');
  
  /* ----- MOVEMENT ----- */
  // Reads input, updates player position
  // Speed: 0.2 units/frame (~12 u/s at 60fps)
  function handleMovement(){
    var k = Input.keys;
    var speed = 0.2;
    
    if(k['w'] || k['arrowup'])    Player.pos.z -= speed;  // North
    if(k['s'] || k['arrowdown'])  Player.pos.z += speed;  // South
    if(k['a'] || k['arrowleft'])  Player.pos.x -= speed;  // West
    if(k['d'] || k['arrowright']) Player.pos.x += speed;  // East
    
    Player.update();  // Sync mesh to position
  }
  
  /* ----- CAMERA ----- */
  // Third-person follow: above and behind player
  function updateCamera(){
    Engine.camera.position.set(
      Player.pos.x,      // Follow X
      10,                // Height: 10 units up
      Player.pos.z + 20  // Behind: 20 units south
    );
    Engine.camera.lookAt(Player.pos.x, 0, Player.pos.z);
  }
  
  /* ----- HUD ----- */
  // Shows position — debug info, will become proper UI later
  function updateHUD(){
    hud.textContent = 'NEW WORLD | ' + 
      Player.pos.x.toFixed(1) + ', ' + 
      Player.pos.z.toFixed(1);
  }
  
  /* ----- MAIN LOOP ----- */
  function animate(){
    requestAnimationFrame(animate);  // 60fps
    
    handleMovement();
    updateCamera();
    updateHUD();
    
    Engine.renderer.render(Engine.scene, Engine.camera);
  }
  
  /* ----- START ----- */
  animate();
  console.log('New World initialized — modular, clean, admin only');
})();


===== FILE: public/newworld/player.js =====
/* ============================================================
   PLAYER.js
   Category: ACTOR / AVATAR
   Purpose: The King's avatar — gold sphere, position tracking
   Dependencies: Engine (scene)
   Provides: Player.pos, Player.mesh, Player.update()
   ============================================================ */

var Player = (function(){
  'use strict';
  
  /* ----- POSITION STATE ----- */
  // Separated from mesh — logic works on pos, render syncs mesh
  var pos = {
    x: 0,  // East-West
    y: 0,  // Up-Down (height)
    z: 0   // North-South
  };
  
  /* ----- VISUAL MESH ----- */
  var mesh = new THREE.Mesh(
    new THREE.SphereGeometry(1, 16, 16),  // Radius 1, smooth
    new THRE