<!-- LIVE · part 63 -->
/* redraw while open */
  if(mapOpen) requestAnimationFrame(drawMap);
}

/* ===== PRECISE COMPASS — true degrees ===== */
var compassEl = null;
function updateCompass(){
  if(!compassEl){
    compassEl = document.createElement('div');
    compassEl.style.cssText = 'position:fixed;top:70px;left:12px;z-index:90;width:60px;height:60px;border-radius:50%;background:#141006;border:2px solid #d8a920;display:flex;align-items:center;justify-content:center;color:#ffd700;font:11px monospace;';
    document.body.appendChild(compassEl);
  }
  var deg = Math.round(((camYaw*180/Math.PI)%360+360)%360);
  var dirs = ['E','SE','S','SW','W','NW','N','NE'];
  var dir = dirs[Math.round(deg/45)%8];
  compassEl.textContent = deg+'° '+dir;
}
/* update compass in animate loop */
var _origUpdateCam = updateCamera;
updateCamera = function(){
  _origUpdateCam();
  if(compassEl) updateCompass();
};

/* ===== 56 BUTTONS — uniform, intricate ===== */
var BTNS = [
  ['p1-temple','Build district',function(){ nextDistrict(); }],
  ['p1-map','Map',function(){ toggleMap(); }],
  ['p1-camera','Camera',function(){ toggleCamera(); }],
  ['p1-sun','Day',function(){ runCode('daycity'); }],
  ['p1-moon','Night',function(){ runCode('nightcity'); }],
  ['p1-pin','Where am I',function(){ runCode('whereami'); }],
  ['p1-hamburger','Menu',function(){ osOpen=false; osEl.classList.remove('open');; }],
  ['p1-plus','Create',function(){ setCreateMode(); }],
  ['p1-minus','Delete',function(){ setDeleteMode(); }],
  ['p1-cube','Shapes',function(){ showShapes(); }],
  ['p1-palette','Render',function(){ showRender(); }],
  ['p1-walker','Walk',function(){ moveMode='walk'; say('walk'); }],
  ['p1-bird','Fly',function(){ moveMode='fly'; say('fly'); }],
  ['p1-uparrow','Jump',function(){ doJump(); }],
  ['p1-hand','Grab',function(){ setGrabMode(); }],
  ['p1-speech','Chat',function(){ openChat(); }],
  ['p1-gt','Codes',function(){ codeInput.focus(); }],
  ['p1-link','Go',function(){ goToDialog(); }],
  ['p1-house','Home',function(){ kingPos.set(0,0,0); say('home'); }],
  ['p1-music','Music',function(){ toggleMusic(); }],
  ['p2-continuum','Continuum',function(){ openContinuum(); }],
  ['p2-place','Place',function(){ setPlaceMode(); }],
  ['p2-help','Help',function(){ showHelp(); }],
  ['p2-export','Export',function(){ runCode('exportfbx'); }],
  ['p2-fixstation','Fix station',function(){ openFixStation(); }],
  ['p2-sky','Sky',function(){ showSky(); }],
  ['p2-treasure','Treasure',function(){ startTreasure(); }],
  ['p2-clearcache','Clear cache',function(){ if(confirm('Clear?')) location.reload(); }],
  ['p2-waypoints','Waypoints',function(){ manageWaypoints(); }],
  ['p2-kidmode','Kid mode',function(){ toggleKidMode(); }],
  ['p2-crown','Crown',function(){ crownView(); }],
  ['p2-dimension','Dimension',function(){ switchDimension(); }],
  ['p3-soliditronium','Soliditronium',function(){ openSoliditronium(); }],
  ['p3-capsule','Capsule',function(){ openCapsule(); }],
  ['p3-fillgaps','Fill gaps',function(){ fillGaps(); }],
  ['p3-recolor','Recolor',function(){ recolorBlocks(); }],
  ['p3-saveview','Save view',function(){ saveView(); }],
  ['p3-gotoview','Go to view',function(){ goToView(); }],
  ['p3-presets','Presets',function(){ showPresets(); }],
  ['p3-aurora','Aurora',function(){ setAurora(); }],
  ['p3-ember','Ember',function(){ setEmber(); }],
  ['p3-storm','Storm',function(){ setStorm(); }],
  ['p3-dawn','Dawn',function(){ setDawn(); }],
  ['p3-invite','Invite',function(){ sendInvite(); }],
  ['p4-whiteout','Whiteout',function(){ setWhiteout(); }],
  ['p4-rain','Rain',function(){ setRain(); }],
  ['p4-wear','Wear',function(){ openWear(); }],
  ['p4-walkline','Walkline',function(){ toggleWalkline(); }],
  ['p4-redseams','Red seams',function(){ toggleRedSeams(); }],
  ['p4-glide','Glide',function(){ runCode('glide'); }],
  ['p4-taptocrown','Tap to crown',function(){ tapToCrown(); }],
  ['p4-tutorial','Tutorial',function(){ startTutorial(); }],
  ['p4-presence','Presence',function(){ showPresence(); }],
  ['p4-balance','Balance',function(){ checkBalance(); }],
  ['p4-ship','Ship',function(){ shipStatus(); }],
  ['p4-history','History',function(){ showHistory(); }],
];
/* Organize by function with section headers */
var GROUPS = [
  ['CORE', 0, 20],
  ['BUILD', 20, 32],
  ['WORLD', 32, 44],
  ['SYSTEM', 44, 56],
];
GROUPS.forEach(function(g){
  var header = document.createElement('div');
  header.textContent = g[0];
  header.style.cssText = 'width:100%;text-align:center;color:#ffd700;font:16px Georgia,\'Times New Roman\',serif;letter-spacing:6px;margin:10px 0 6px 0;border-bottom:1px solid #d8a920;padding-bottom:6px;';
  osEl.appendChild(header);
  for(var i=g[1]; i<g[2]; i++){
    (function(b){
      var cell = document.createElement('div');
      cell.style.cssText = 'display:flex;flex-direction:column;align-items:center;gap:2px;width:72px;flex-shrink:0;';
      var btn = document.createElement('button');
  btn.title = b[1];
  btn.in