<!-- RUBY-BACKUP · part 202 -->
g = document.getElementById('solid-speech');
  if(existing) existing.remove();
  div.id = 'solid-speech';
  div.style.cssText = 'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);z-index:9999;background:rgba(20,10,40,0.95);border:2px solid #ffd700;border-radius:12px;padding:15px 25px;color:#ffeebb;font-family:Georgia,serif;font-style:italic;max-width:80%;text-align:center;';
  div.innerHTML = '<div style="color:#ffd700;font-style:normal;font-weight:bold;margin-bottom:8px;">— Solid</div>"'+answer+'"';
  document.body.appendChild(div);
  setTimeout(function(){ var d=document.getElementById('solid-speech'); if(d) d.remove(); }, 12000);
  codeStatus('Solid answers');
}
function solidGuide(place){
  var guides = {
    'city': 'Go to the towers. The streets will tell you their names.',
    'plaza': 'The heart. Follow any path inward.',
    'dark': 'The corners of the map. Small now. Be kind to the souls there.',
    'spaceport': 'Look for the landing pads. Hokulea is above.',
    'valleys': 'South and west. Follow the sound of water.'
  };
  var g = guides[place.toLowerCase()];
  if(g) codeStatus('Solid guides you: '+g);
  else codeStatus('Solid guides you: explore. The map will teach you.');
}
function dismissSolid(){
  if(SOLID_NPC){
    try{ scene.remove(SOLID_NPC); }catch(e){}
    if(SOLID_NPC.userData.anim) clearInterval(SOLID_NPC.userData.anim);
    if(SOLID_NPC.userData.speakTimer) clearInterval(SOLID_NPC.userData.speakTimer);
    SOLID_NPC = null;
    var d = document.getElementById('solid-speech');
    if(d) d.remove();
    codeStatus('Solid leaves. You have what you need. You do not need her anymore.');
  }else{
    codeStatus('Solid is not here');
  }
}
function meetSolid(){
  if(typeof scene==='undefined' || typeof mePos==='undefined') return;
  if(SOLID_NPC){
    dismissSolid();
  }
  /* she appears at the plaza — the heart */
  var x = mePos.x*0.13, z = mePos.z*0.13;
  SOLID_NPC = buildSolidNPC(x+3, 0, z+3);
  scene.add(SOLID_NPC);
  codeStatus('Solid — she has come to meet you.');
}

/* THE ENDING — when you did all you could do */
var GAME_PROGRESS = {};
function trackProgress(key){
  try{
    GAME_PROGRESS = JSON.parse(localStorage.getItem('ruby-progress')||'{}');
  }catch(e){ GAME_PROGRESS = {}; }
  GAME_PROGRESS[key] = true;
  try{ localStorage.setItem('ruby-progress', JSON.stringify(GAME_PROGRESS)); }catch(e){}
  checkEnding();
}
function getProgress(){
  try{
    return JSON.parse(localStorage.getItem('ruby-progress')||'{}');
  }catch(e){ return {}; }
}
/* what "all you could do" means */
var COMPLETION_KEYS = [
  'met_solid',      /* met Solid */
  'did_quest',      /* completed a quest */
  'filled_max',     /* Continuum to 25 */
  'saw_hokulea',    /* saw the mother ship */
  'visited_city',   /* built the city */
  'visited_dark',   /* saw the dark places */
  'helped_soul',    /* helped a funny soul */
  'asked_solid'     /* asked Solid a question */
];
function checkEnding(){
  var prog = getProgress();
  var done = COMPLETION_KEYS.filter(function(k){ return prog[k]; });
  if(done.length >= COMPLETION_KEYS.length){
    /* the game ends */
    showEnding();
  }
  return done.length;
}
function showEnding(){
  try{
    if(localStorage.getItem('ruby-ended')==='1') return; /* only once */
    localStorage.setItem('ruby-ended', '1');
  }catch(e){}
  var div = document.createElement('div');
  div.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:20000;background:radial-gradient(ellipse at center, rgba(20,10,40,0.95) 0%, rgba(5,2,15,0.98) 100%);display:flex;flex-direction:column;justify-content:center;align-items:center;color:#ffeebb;font-family:Georgia,serif;text-align:center;padding:40px;';
  div.innerHTML = '<div style="font-size:42px;color:#ffd700;margin-bottom:30px;">✦</div>'
    + '<div style="font-size:28px;font-style:italic;margin-bottom:20px;line-height:1.6;">'
    + 'You did all you could do.'
    + '</div>'
    + '<div style="font-size:18px;opacity:0.85;line-height:1.8;max-width:600px;">'
    + 'You met Solid. You helped the souls.<br>'
    + 'You walked the ancestral streets.<br>'
    + 'You saw Hokulea in orbit.<br>'
    + 'The ancestors were gracious.<br><br>'
    + 'The last King built this for you.<br>'
    + 'And you — you did all you could do.<br><br>'
    + '<span style="color:#ffd700;">This is felt by all.</span>'
    + '</div>'
    + '<div style="margin-top:40px;font-size:14px;opacity:0.6;">The game ends. But the map remains.<br>You can always return.</div>'
    + '<button onclick="this.parentElement.remove()" style="margin-top:30px;padding:12px 30px;background:transparent;border:2px solid #ffd700;color:#ffd700;border-radius:8px;font-size:16px;cursor:pointer;">Return to the Map</button>';
  document.body.appendChild(div);
  codeStatus('the ending — you did all you could do');
}
/* hook progress tracking into existing actions */
var _origMeetSolid = meetSolid;
meetSolid = function(){ trackProgress('met