<!-- RUBY-BACKUP · part 206 -->
ip = setInterval(function(){
    t += 0.05;
    g.rotation.x = -t * 0.5;
    g.position.y = Math.sin(t * 2) * 0.2;
    if(t >= Math.PI){
      clearInterval(flip);
      g.rotation.x = -Math.PI * 0.5;
      /* the crystal rises, presented to them */
      presentCrystal();
    }
  }, 50);
  codeStatus('the capsule flips open...');
}

/* INVENTORY — and the price of the forbidden */

/* WEAPONS — the laser cannon is the prize */
var WEAPONS = [
  {id: 'pistol', name: 'Pistol', value: 100, description: 'Standard sidearm'},
  {id: 'shotgun', name: 'Shotgun', value: 300, description: 'Pump-action, 5-pellet spread'},
  {id: 'rifle', name: 'Rifle', value: 500, description: 'Long range, precise'},
  {id: 'laser-cannon', name: 'Laser Cannon', value: 2000, description: 'Cyan beam. One-shots targets. The prize.'}
];
function giveWeapon(weaponId){
  var w = WEAPONS.find(function(x){ return x.id === weaponId; });
  if(!w) return;
  var inv = getInventory();
  if(inv.find(function(i){ return i.id === w.id; })){
    codeStatus('you already own the '+w.name);
    return;
  }
  addToInventory({id: w.id, name: w.name, value: w.value, description: w.description});
  unlockAchievement('Owns '+w.name);
}
function showWeapons(){
  if(!weaponsStoreOpen()){
    codeStatus('the gun stores are closed. Finding a new one is impossible.');
    return;
  }
  var html = WEAPONS.map(function(w, i){
    return '<div style="margin:8px 0;padding:10px;border:1px solid #ff6600;border-radius:5px;">'
      + '<b>'+w.name+'</b> — '+w.value+' credits<br><small>'+w.description+'</small><br>'
      + '<button onclick="buyWeapon('+i+')" style="margin-top:5px;">BUY</button></div>';
  }).join('');
  var d = document.createElement('div');
  d.id = 'weapon-panel';
  d.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:10000;background:rgba(30,15,5,0.95);border:3px solid #ff6600;border-radius:12px;padding:20px;color:#fff;max-width:400px;max-height:70%;overflow:auto;';
  loadCredits();
  d.innerHTML = '<b style="color:#ff6600">WEAPONS</b> (you have '+CREDITS+' credits)<br><br>'+html
    + '<br><button onclick="document.getElementById(\'weapon-panel\').remove()">CLOSE</button>';
  document.body.appendChild(d);
}
function buyWeapon(idx){
  loadCredits();
  var w = WEAPONS[idx];
  if(!w) return;
  if(CREDITS < w.value){
    codeStatus('not enough credits — need '+w.value);
    return;
  }
  CREDITS -= w.value;
  try{ localStorage.setItem('ruby-credits', CREDITS.toString()); }catch(e){}
  var d = document.getElementById('weapon-panel');
  if(d) d.remove();
  giveWeapon(w.id);
  codeStatus('you bought the '+w.name+'!');
}
function getInventory(){
  try{
    return JSON.parse(localStorage.getItem('ruby-inventory')||'[]');
  }catch(e){ return []; }
}
function saveInventory(inv){
  try{ localStorage.setItem('ruby-inventory', JSON.stringify(inv)); }catch(e){}
}
function addToInventory(item){
  var inv = getInventory();
  inv.push(item);
  saveInventory(inv);
  codeStatus('added to inventory: '+item.name);
  return inv;
}
function removeFromInventory(itemId){
  var inv = getInventory();
  inv = inv.filter(function(i){ return i.id !== itemId; });
  saveInventory(inv);
  return inv;
}
function getPrizedPossession(){
  var inv = getInventory();
  if(inv.length === 0) return null;
  /* prized = highest value */
  var prized = inv[0];
  inv.forEach(function(item){
    if((item.value||0) > (prized.value||0)) prized = item;
  });
  return prized;
}
function showInventory(){
  var inv = getInventory();
  if(inv.length === 0){
    codeStatus('inventory is empty');
    return;
  }
  var html = inv.map(function(i){ return i.name+' ('+(i.value||0)+'cr)'; }).join(' | ');
  codeStatus('inventory: '+html);
}
/* the twin crystal */
var TWIN_CRYSTAL = {
  id: 'twin-crystal',
  name: 'Twin Lightning Crystal',
  value: 0,
  description: 'Forbidden. It came to you. You did not seek it.'
};
/* they receive it — and lose their prized possession */

/* THE AFTERMATH — between the crystal and the court */
var AFTERMATH_ACTIVE = false;
function startAftermath(){
  if(AFTERMATH_ACTIVE) return;
  AFTERMATH_ACTIVE = true;
  try{ localStorage.setItem('ruby-aftermath', '1'); }catch(e){}
  /* gun stores closed */
  codeStatus('the gun stores are closed. Finding a new one is impossible.');
  /* the world turns cold */
  setTimeout(function(){ badGuysWin(); }, 3000);
  setTimeout(function(){ homelessAngry(); }, 6000);
  setTimeout(function(){ friendsAvoid(); }, 9000);
  setTimeout(function(){ scaryValley(); }, 12000);
}
function badGuysWin(){
  var div = document.createElement('div');
  div.id = 'bad-guys';
  div.style.cssText = 'position:fixed;bottom:100px;left:20px;z-index:9998;background:rgba(30,5,5,0.9);border:2px solid #ff0000;border-radius:8px;padding:10px 15px;color:#ff6666;font-family:Arial;font-size:13px;max-width:280px;';
  div.innerHTML = '<b>BAD GUYS</b><br><i>"No cannon? No problem... for us."</i><br><small>They fe