<!-- RUBY-BACKUP · part 247 -->
odeStatus('Young King — regal bearing, childlike wonder');
}
function stopYoungKing(){
  if(YK_ANIM){ clearInterval(YK_ANIM); YK_ANIM = null; }
}
function startCyborg(){
  stopSwift(); stopDancer(); stopStrider();
  /* replace player mesh with cyborg */
  if(typeof playerMesh!=='undefined' && playerMesh && typeof scene!=='undefined'){
    scene.remove(playerMesh);
  }
  CYBORG_MESH = buildCyborg();
  if(CYBORG_MESH && typeof scene!=='undefined'){
    /* position at player */
    if(typeof mePos!=='undefined'){
      CYBORG_MESH.position.set(mePos.x*0.13, 0, mePos.z*0.13);
    }
    scene.add(CYBORG_MESH);
    /* keep playerMesh reference for animation */
    if(typeof playerMesh!=='undefined') playerMesh = CYBORG_MESH;
  }
  codeStatus('Cyborg — carbon fiber, chrome, blue glow. Like the shoes.');
}
function startSwift(){
  stopSwift(); stopDancer(); stopStrider();
  SWIFT_LAST = null;
  SWIFT_ANIM = setInterval(function(){
    if(typeof mePos==='undefined' || typeof playerMesh==='undefined' || !playerMesh) return;
    var now = {x: mePos.x, z: mePos.z, t: Date.now()};
    if(SWIFT_LAST){
      var dx = now.x - SWIFT_LAST.x, dz = now.z - SWIFT_LAST.z;
      var dt = (now.t - SWIFT_LAST.t)/1000;
      var speed = dt>0 ? Math.sqrt(dx*dx+dz*dz)/dt : 0;
      var newMode = 'idle';
      if(speed > 8) newMode = 'run';
      else if(speed > 0.5) newMode = 'walk';
      SWIFT_MODE = newMode;
      /* animate based on mode */
      var t = Date.now()/100;
      /* track exhaustion: was running, now stopped */
      if(SWIFT_MODE==='run'){
        SWIFT_WAS_RUNNING = Date.now();
      }
      var exhausted = false;
      if(SWIFT_MODE==='idle' && SWIFT_WAS_RUNNING && (Date.now()-SWIFT_WAS_RUNNING)<8000){
        exhausted = true;
      }
      if(exhausted){
        /* BURNT OUT: bent over, hands on knees, breathing hard */
        var breath = Math.sin(t*3)*0.06; /* rapid heavy breathing */
        playerMesh.rotation.x = 0.6; /* bent over */
        playerMesh.position.y = -0.15 + breath;
        playerMesh.rotation.z = Math.sin(t*3)*0.03;
        /* arms hang toward knees (approximated by lean) */
      }else if(SWIFT_MODE==='run'){
        /* fast bob, lean forward */
        playerMesh.position.y += Math.abs(Math.sin(t*2))*0.08;
        playerMesh.rotation.x = 0.2;
        playerMesh.rotation.z = Math.sin(t*2)*0.15;
      }else if(SWIFT_MODE==='walk'){
        /* moderate stride */
        playerMesh.position.y += Math.abs(Math.sin(t))*0.04;
        playerMesh.rotation.x = 0.05;
        playerMesh.rotation.z = Math.sin(t)*0.08;
      }else{
        /* idle — subtle breathing */
        playerMesh.rotation.x = 0;
        playerMesh.rotation.z = 0;
        playerMesh.position.y += Math.sin(t*0.3)*0.01;
      }
    }
    SWIFT_LAST = now;
  }, 100);
  codeStatus('Swift — walks when you walk, runs when you run');
}
function stopSwift(){
  if(SWIFT_ANIM){ clearInterval(SWIFT_ANIM); SWIFT_ANIM = null; }
  SWIFT_MODE = 'idle';
}
function startDancer(){
  stopDancer(); stopStrider();
  var t = 0;
  DANCER_ANIM = setInterval(function(){
    t += 0.2;
    if(typeof playerMesh!=='undefined' && playerMesh){
      /* spin + bounce + sway */
      playerMesh.rotation.y += 0.1;
      playerMesh.position.y += Math.abs(Math.sin(t))*0.05;
      playerMesh.rotation.z = Math.sin(t)*0.2;
    }
  }, 50);
  codeStatus('Dancer dances — watch it go');
}
function stopDancer(){
  if(DANCER_ANIM){ clearInterval(DANCER_ANIM); DANCER_ANIM = null; }
}
function startStrider(){
  stopStrider();
  /* bobbing walk animation on the player marker */
  var t = 0;
  STRIDER_ANIM = setInterval(function(){
    t += 0.15;
    if(typeof playerMesh!=='undefined' && playerMesh){
      playerMesh.position.y += Math.sin(t)*0.02;
      playerMesh.rotation.z = Math.sin(t*0.5)*0.1;
    }
  }, 50);
  codeStatus('Strider walks — watch it move');
}
function stopStrider(){
  if(STRIDER_ANIM){ clearInterval(STRIDER_ANIM); STRIDER_ANIM = null; }
}
function selectAvatar(id){
  CURRENT_AVATAR = id;
  try{ localStorage.setItem('ruby-avatar', id); }catch(e){}
  /* apply the avatar */
  if(id==='circle'){
    if(typeof handleCode==='function') handleCode('body circle');
  }else if(id==='strider'){
    stopDancer(); startStrider();
    codeStatus('Strider — the one that moves');
  }else if(id==='dancer'){
    stopStrider(); stopSwift(); startDancer();
    codeStatus('Dancer — the one that dances');
  }else if(id==='swift'){
    stopStrider(); stopDancer(); startSwift();
    codeStatus('Swift — walks when you walk, runs when you run');
  }else if(id==='cyborg'){
    stopYoungKing(); startCyborg();
  }else if(id==='youngking'){
    stopUnimpressed(); startYoungKing();
  }else if(id==='unimpressed'){
    stopSmugbug(); startUnimpressed();
  }else if(id==='smugbug'){
    stopReluctant(); startSmugbug();
  }else if(id==='reluctant'){
    stopMatriarch(); startReluctant();
  }else if(id==='matriarch'){
    stopGeneric(); stopPatriarch(); startMa