<!-- RUBY-BACKUP · part 209 -->
5px 40px;color:#fff;font-family:Arial;text-align:center;max-width:85%;';
  div.innerHTML = '<div style="color:#ff0000;font-weight:bold;font-size:20px;margin-bottom:15px;">THE SEARCH</div>'
    + '<div id="search-words" style="font-size:16px;line-height:1.8;min-height:120px;"></div>';
  document.body.appendChild(div);
  var words = [
    'The officers search you.',
    'Pockets. Pack. Everywhere.',
    '<span style="color:#ff6666;font-weight:bold;">They cannot find it.</span>',
    'The twin lightning is NOT on him.',
    '"WHERE IS IT?!"',
    'They really get on the case now.'
  ];
  var w = document.getElementById('search-words');
  var i = 0;
  var wt = setInterval(function(){
    if(i < words.length){
      w.innerHTML += '<div style="margin:10px 0;opacity:0;animation:fadein 1s forwards;">'+words[i]+'</div>';
      i++;
    }else{
      clearInterval(wt);
      setTimeout(function(){
        var d = document.getElementById('court-search');
        if(d) d.remove();
        /* the case intensifies */
        if(typeof courtIsReady==='function' && courtIsReady()){
          startTwinCase();
        }
      }, 2000);
    }
  }, 1500);
  codeStatus('the court cannot find it on him — they get on the case');
  }, 18000); /* after grid desperation */
}
loadPadCharge();
function walkValley(){
  var div = document.getElementById('scary-valley');
  if(div) div.remove();
  /* the valley walk — creatures */
  codeStatus('you walk down the scary valley. Creatures watch from the dark.');
  /* spawn creature encounters */
  var encounters = 0;
  var et = setInterval(function(){
    encounters++;
    var creatures = ['eyes in the dark', 'something breathing', 'claws on stone', 'a shape that was not there before'];
    var cr = creatures[Math.floor(Math.random()*creatures.length)];
    codeStatus('valley: '+cr+'... ('+encounters+'/5)');
    /* the long walk drains the pad */
    drainPad(25);
    if(encounters >= 5){
      clearInterval(et);
      /* pad shuts down after the long walk */
      drainPad(100);
      codeStatus('you made it through the valley. Your pad is dead.');
    }
  }, 4000);
}
/* gun stores check if closed */
function weaponsStoreOpen(){
  try{
    return localStorage.getItem('ruby-aftermath')!=='1';
  }catch(e){ return true; }
}
try{
  if(localStorage.getItem('ruby-aftermath')==='1') AFTERMATH_ACTIVE = true;
}catch(e){}
function receiveTwinCrystal(){
  addToInventory(TWIN_CRYSTAL);
  var prized = getPrizedPossession();
  /* the crystal is value 0, so prized is something else */
  var inv = getInventory().filter(function(i){ return i.id !== 'twin-crystal'; });
  if(inv.length > 0){
    var p = inv[0];
    inv.forEach(function(item){ if((item.value||0) > (p.value||0)) p = item; });
    prized = p;
  }else{
    prized = null;
  }
  if(prized){
    /* they lose it */
    removeFromInventory(prized.id);
    losePrizedSequence(prized);
  }else{
    /* they had nothing to lose — the crystal takes their credits instead */
    loadCredits();
    var lost = Math.floor(CREDITS * 0.5);
    CREDITS = Math.max(0, CREDITS - lost);
    try{ localStorage.setItem('ruby-credits', CREDITS.toString()); }catch(e){}
    codeStatus('the crystal takes '+lost+' credits. You had no prized possession to lose.');
  }
}
function losePrizedSequence(prized){
  var div = document.createElement('div');
  div.id = 'lose-prized';
  div.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:22000;background:rgba(20,5,5,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:16px;color:#888;margin-bottom:15px;">The twin crystal is yours now.</div>'
    + '<div style="font-size:20px;color:#ff6666;font-weight:bold;margin-bottom:20px;">But everything has a price.</div>'
    + '<div id="lose-words" style="font-style:italic;font-size:18px;line-height:2;max-width:600px;min-height:150px;"></div>';
  document.body.appendChild(div);
  var isWeapon = prized.id==='laser-cannon'||prized.id==='pistol'||prized.id==='shotgun'||prized.id==='rifle';
  var words = [
    'You feel it leave you.',
    'Your <span style="color:#ffd700;font-weight:bold;">'+prized.name+'</span>...',
    '...is gone.',
    'The forbidden thing took your prized possession.',
    isWeapon
      ? 'But guns are bad anyway. You are lighter without it.'
      : 'You did not choose this. It chose you.'
  ];
  var w = document.getElementById('lose-words');
  var i = 0;
  var wt = setInterval(function(){
    if(i < words.length){
      w.innerHTML += '<div style="margin:12px 0;opacity:0;animation:fadein 1s forwards;">'+words[i]+'</div>';
      i++;
    }else{
      clearInterval(wt);
      setTimeout(function(){
        var d = document.getElementById('lose-prized');
        if(d){
          d.innerHTML += '<button onclick="document.getElementById(\'lose-prized\').remove()" style="margin-top:20px;padding:1