<!-- RUBY-BACKUP · part 197 -->
his list.', loc: '???', secret: 'You will know it when you find it.'}
];
var ACTIVE_HIDDEN = null;
function hiddenQuest(){
  /* rarer — 20% chance of hidden, 80% regular */
  if(Math.random() < 0.2){
    var q = HIDDEN_QUESTS[Math.floor(Math.random()*HIDDEN_QUESTS.length)];
    ACTIVE_HIDDEN = q;
    ACTIVE_QUEST = q;
    var div = document.createElement('div');
    div.id = 'quest-hud';
    var existing = document.getElementById('quest-hud');
    if(existing) existing.remove();
    div.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);z-index:9999;background:rgba(10,5,20,0.95);border:3px solid #aa00ff;border-radius:10px;padding:15px 25px;color:#fff;font-family:Arial;text-align:center;max-width:85%;';
    div.innerHTML = '<div style="color:#aa00ff;font-weight:bold;font-size:18px;">HIDDEN QUEST #'+q.id+' 🔮</div><div style="margin-top:8px;"><b>'+q.giver+':</b></div><div style="margin-top:6px;font-style:italic;">'+q.text+'</div><div style="margin-top:8px;font-size:11px;color:#888;">secret: '+q.secret+'</div><div style="margin-top:6px;font-size:12px;color:#aaa;">type "questdone" when complete</div>';
    document.body.appendChild(div);
    codeStatus('HIDDEN quest #'+q.id+' — '+q.giver);
    return q;
  }else{
    return randomQuest();
  }
}
function randomQuest(){
  var q = SIDE_QUESTS[Math.floor(Math.random()*SIDE_QUESTS.length)];
  ACTIVE_QUEST = q;
  /* show quest */
  var cv = document.createElement('canvas');
  cv.width = 512; cv.height = 128;
  var ctx = cv.getContext('2d');
  ctx.fillStyle = 'rgba(20,20,40,0.95)';
  ctx.fillRect(0, 0, 512, 128);
  ctx.strokeStyle = '#ffcc00'; ctx.lineWidth = 4;
  ctx.strokeRect(6, 6, 500, 116);
  ctx.fillStyle = '#ffcc00'; ctx.font = 'bold 22px Arial'; ctx.textAlign = 'center';
  ctx.fillText('SIDE QUEST #'+q.id, 256, 32);
  ctx.fillStyle = '#ffffff'; ctx.font = '20px Arial';
  ctx.fillText(q.giver+':', 256, 58);
  ctx.font = 'italic 18px Arial';
  /* wrap */
  var words = q.text.split(' '), line='', lines=[];
  words.forEach(function(w){
    if((line+' '+w).length > 35){ lines.push(line); line = w; }
    else line += (line?' ':'')+w;
  });
  lines.push(line);
  lines.slice(0,2).forEach(function(l,i){ ctx.fillText(l, 256, 82+i*22); });
  var tex = new THREE.CanvasTexture(cv);
  /* display as HUD */
  var existing = document.getElementById('quest-hud');
  if(existing) existing.remove();
  var div = document.createElement('div');
  div.id = 'quest-hud';
  div.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);z-index:9999;background:rgba(20,20,40,0.9);border:3px solid #ffcc00;border-radius:10px;padding:15px 25px;color:#fff;font-family:Arial;text-align:center;max-width:80%;';
  div.innerHTML = '<div style="color:#ffcc00;font-weight:bold;font-size:18px;">SIDE QUEST #'+q.id+'</div><div style="margin-top:8px;"><b>'+q.giver+':</b> <i>'+q.text+'</i></div><div style="margin-top:8px;font-size:12px;color:#aaa;">'+q.loc+' — type "questdone" when complete</div>';
  document.body.appendChild(div);
  /* auto-hide after 10s */
  setTimeout(function(){ var d=document.getElementById('quest-hud'); if(d) d.style.opacity='0.7'; }, 10000);
  codeStatus('quest #'+q.id+' — '+q.giver+': '+q.text);
  /* fill Continuum */
  try{ questToContinuum(q); }catch(e){}
  return q;
}
function completeQuest(){
  if(ACTIVE_QUEST){
    var q = ACTIVE_QUEST;
    ACTIVE_QUEST = null;
    var d = document.getElementById('quest-hud');
    if(d) d.remove();
    codeStatus('quest #'+q.id+' complete! Mahalo.');
  }else{
    codeStatus('no active quest — type "quest" for one');
  }
}
/* quests fill the Continuum to max 25 */
function questToContinuum(quest){
  if(typeof DESK_PAD==='undefined') return;
  /* map quest location to useful codes */
  var locCodes = {
    'city': ['city', 'ancestors', 'officer', 'purposes'],
    'dark': ['dark', 'quest'],
    'plaza': ['plaza', 'play'],
    'rural': ['rural'],
    'tribal': ['tribal'],
    'valley': ['valleys'],
    'terrain': ['wildterrain'],
    'wildlife': ['wildlife'],
    'spaceport': ['spaceport', 'hokulea', 'spacemission'],
    'cosmic': ['cosmic'],
    'all': ['ancestralcity'],
    'sky': ['cosmicsky']
  };
  var codes = locCodes[quest.loc] || ['quest'];
  codes.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){}
}
function fillContinuumMax(){
  if(typeof DESK_PAD==='undefined') return;
  /* essential codes for the full experience */
  var essentials = [
    'quest', 'ancestralcity', 'plaza', 'play', 'dark',
    'city', 'rural', 'tribal', 'valleys', 'wildterrain',
    'wildlife', 'spaceport', 'hokulea', 'cosmic',
    'ancestors', 'officer', 'spacemission', 'stranger',
    'continuum', 'dome', 'capsule', 'decree',
    'kidmode', 'tutorial', 'avat