<!-- RUBY-BACKUP · part 198 -->
ars'
  ];
  essentials.forEach(function(code){
    if(DESK_PAD.indexOf(code) < 0 && DESK_PAD.length < 25){
      DESK_PAD.push(code);
  try{ if(typeof continuumGathered==='function') continuumGathered(); }catch(e){}
    }
  });
  try{ localStorage.setItem('ruby-chartpad', JSON.stringify(DESK_PAD)); }catch(e){}
  codeStatus('Continuum filled to max — '+DESK_PAD.length+'/25');
  /* bonus unlocked! */
  if(DESK_PAD.length >= 25) unlockBonus();
}
function listQuests(){
  codeStatus(SIDE_QUESTS.length+' side quests available. Type "quest" for a random one.');
}

/* SPACE TRAVEL MISSIONS + THE RICH STRANGER */
var SPACE_MISSIONS = [
  {id: 'S1', text: 'Board Hokulea. She will take you to the stars.', detail: 'Stand beneath her orbit. Look up. She will lower a beam.'},
  {id: 'S2', text: 'Chart the three wormholes. Map where they lead.', detail: 'Enter each paradox wormhole. Remember what you see.'},
  {id: 'S3', text: 'Count Hokulea orbits. She circles every 4 minutes.', detail: 'Time her. The pattern reveals a message.'},
  {id: 'S4', text: 'Land on the blue planet in the cosmic sky.', detail: 'The planet is far. The ship knows the way.'},
  {id: 'S5', text: 'Collect stardust from the nebula.', detail: 'Fly through the magenta cloud. Your hull will glow.'},
  {id: 'S6', text: 'Race a spaceship around the city.', detail: 'Launch from the spaceport. Three laps. Do not hit the towers.'},
  {id: 'S7', text: 'Deliver a message to the orbit.', detail: 'Hokulea carries letters between worlds. Write one.'},
  {id: 'S8', text: 'Repair the landing pad lights.', detail: 'One beacon is dim. Find which. Fix it.'},
  {id: 'S9', text: 'Escort the mother ship through the storm.', detail: 'The storm beach reaches orbit. Guide her through.'},
  {id: 'S10', text: 'Find the star that fell.', detail: 'It is in the rough terrain, pretending to be a rock.'}
];
function spaceMission(){
  var m = SPACE_MISSIONS[Math.floor(Math.random()*SPACE_MISSIONS.length)];
  var div = document.createElement('div');
  var existing = document.getElementById('quest-hud');
  if(existing) existing.remove();
  div.id = 'quest-hud';
  div.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);z-index:9999;background:rgba(5,10,30,0.95);border:3px solid #00ffff;border-radius:10px;padding:15px 25px;color:#fff;font-family:Arial;text-align:center;max-width:85%;';
  div.innerHTML = '<div style="color:#00ffff;font-weight:bold;font-size:18px;">SPACE MISSION '+m.id+' 🚀</div><div style="margin-top:8px;font-style:italic;">'+m.text+'</div><div style="margin-top:6px;font-size:13px;color:#aaa;">'+m.detail+'</div>';
  document.body.appendChild(div);
  codeStatus('space mission '+m.id+' — '+m.text);
}
/* THE RICH STRANGER — once in a lifetime, after months */
function checkStrangerEligibility(){
  try{
    var firstPlay = localStorage.getItem('ruby-first-play');
    var strangerSeen = localStorage.getItem('ruby-stranger-seen');
    if(!firstPlay){
      localStorage.setItem('ruby-first-play', Date.now().toString());
      return false;
    }
    if(strangerSeen) return false; /* once in a lifetime */
    var monthsPlayed = (Date.now() - parseInt(firstPlay)) / (30*24*60*60*1000);
    /* appears after 2+ months, or very rarely before */
    if(monthsPlayed >= 2) return true;
    if(Math.random() < 0.001) return true; /* 0.1% chance — a miracle */
    return false;
  }catch(e){ return false; }
}
var STRANGER = null;
function buildRichStranger(x, y, z){
  var g = new THREE.Group();
  /* wealthy — gold, elegant */
  var skin = new THREE.MeshStandardMaterial({color: 0xd4a574, roughness: 0.4});
  var gold = new THREE.MeshStandardMaterial({color: 0xffd700, metalness: 0.9, roughness: 0.2});
  var suit = new THREE.MeshStandardMaterial({color: 0x1a1a2a, roughness: 0.3});
  var head = new THREE.Mesh(new THREE.SphereGeometry(0.15, 20, 20), skin);
  head.position.y = 1.6; g.add(head);
  /* kind, tired eyes — has seen much */
  [-1,1].forEach(function(s){
    var eye = new THREE.Mesh(new THREE.SphereGeometry(0.022, 10, 10),
      new THREE.MeshStandardMaterial({color: 0x3a2a1a}));
    eye.position.set(0.08, 1.62, s*0.06); g.add(eye);
  });
  /* gray hair — distinguished */
  var hair = new THREE.Mesh(new THREE.SphereGeometry(0.155, 16, 16, 0, Math.PI*2, 0, Math.PI*0.5),
    new THREE.MeshStandardMaterial({color: 0xaaaaaa, roughness: 0.8}));
  hair.position.y = 1.62; g.add(hair);
  /* elegant suit */
  var body = new THREE.Mesh(new THREE.CylinderGeometry(0.18, 0.22, 1.0, 14), suit);
  body.position.y = 1.0; g.add(body);
  /* gold watch — glints */
  var watch = new THREE.Mesh(new THREE.CylinderGeometry(0.04, 0.04, 0.02, 10), gold);
  watch.position.set(0, 0.9, 0.22); watch.rotation.x = Math.PI/2;
  g.add(watch);
  /* gold cane */
  var cane = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, 1.1, 8), gold);
  cane.position.set(0, 0.55, 0.28); g.add(cane);
  var caneTop = new THREE.Mesh(new THREE.SphereGeometry(0.04, 10, 10), go