<!-- RUBY-BACKUP · part 452 -->
   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 feel like they always win now.</small>';
  document.body.appendChild(div);
  setTimeout(function(){ var d=document.getElementById('bad-guys'); if(d) d.remove(); }, 8000);
  codeStatus('the bad guys feel like they always win');
}
function homelessAngry(){
  /* adult mode — the funny homeless become angry */
  var div = document.createElement('div');
  div.id = 'homeless-angry';
  div.style.cssText = 'position:fixed;bottom:100px;right:20px;z-index:9998;background:rgba(20,20,20,0.9);border:2px solid #888;border-radius:8px;padding:10px 15px;color:#aaa;font-family:Arial;font-size:13px;max-width:280px;';
  div.innerHTML = '<b>THE HOMELESS</b> (adult mode)<br><i>"You had everything. You lost it. Now you know."</i><br><small>They are angry. Not funny anymore.</small>';
  document.body.appendChild(div);
  setTimeout(function(){ var d=document.getElementById('homeless-angry'); if(d) d.remove(); }, 8000);
  codeStatus('the homeless are angry');
}
function friendsAvoid(){
  var div = document.createElement('div');
  div.id = 'friends-avoid';
  div.style.cssText = 'position:fixed;top:100px;left:50%;transform:translateX(-50%);z-index:9998;background:rgba(15,15,25,0.9);border:2px solid #5555ff;border-radius:8px;padding:10px 20px;color:#aaaaff;font-family:Arial;font-size:13px;text-align:center;';
  div.innerHTML = 'People you used to know cross the street when they see you.<br><small>They avoid you.</small>';
  document.body.appendChild(div);
  setTimeout(function(){ var d=document.getElementById('friends-avoid'); if(d) d.remove(); }, 8000);
  codeStatus('people you knew avoid you');
}
function scaryValley(){
  var div = document.createElement('div');
  div.id = 'scary-valley';
  div.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:20000;background:rgba(5,5,10,0.97);display:flex;flex-direction:column;justify-content:center;align-items:center;color:#fff;font-family:Georgia,serif;text-align:center;';
  div.innerHTML = '<div style="font-size:14px;color:#888;letter-spacing:3px;margin-bottom:15px;">THE ONLY WAY FORWARD</div>'
    + '<div style="font-size:28px;color:#ff6666;font-weight:bold;margin-bottom:20px;">THE SCARY VALLEY</div>'
    + '<div id="valley-words" style="font-style:italic;font-size:17px;line-height:2;max-width:600px;min-height:200px;"></div>'
    + '<div id="valley-btn" style="margin-top:20px;"></div>';
  document.body.appendChild(div);
  v