<!-- RUBY-BACKUP · part 455 -->
  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:12px 35px;background:transparent;border:2px solid #ff6666;color:#ff6666;font-size:16px;border-radius:6px;cursor:pointer;">Mourn</button>';
        }
      }, 1500);
    }
  }, 1800);
  unlockAchievement('Lost Their Prized Possession');
  codeStatus('lost: '+prized.name);
  /* the aftermath begins */
  setTimeout(function(){ startAftermath(); }, 5000);
}
function presentCrystal(){
  /* the twin crystal floats out, toward the player */
  var div = document.createElement('div');
  div.id = 'capsule-present';
  div.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:20000;background:rgba(5,5,20,0.92);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;margin-bottom:15px;">You never crossed the boundary.</div>'
    + '<div style="font-size:16px;color:#ffd700;margin-bottom:15px;">But the capsule flipped it to you.</div>'
    + '<div id="capsule-words" style="font-style:italic;font-size:18px;line-height:2;max-width:600px;min-height:180px;"></div>';
  document.body.appendChild(div);
  var words = [
    '"I do not know what it is yet."',
    '"But it is futuristic. It seems like it should be mine."',
    '"It makes so much sense to own this."',
    '"It looks like it has a reasonable chance of being good for me."',
    '<span style="color:#00ffff;">The twin crystal floats toward you.</span>',
    '<span style="color:#ff6666;">You did not cross the boundary. It crossed to you.</span>'
  ];
  var w = document.getElementById('capsule-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('capsule-present');
        if(d) d.remove();
        FORBIDDEN_TOUCHED = true;
        try{ localStorage.setItem('ruby-forbidden-touched', '1'); }catch(e){}
        /* it gets added to their inventory — and they lose their prized possession */
        receiveTwinCrystal();
        /* the aftermath comes first. The valley. Then the court. */
      }, 2000);
    }
  }, 1800);
}
if(typeof PHONE_CALLERS==='undefined') var PHONE_CALLERS = [];
try{ placePhoneCallers(); }catch(e){}
/* 