<!-- RUBY-BACKUP · part 513 -->
  setTimeout(function(){ document.body.removeChild(a); }, 1000);
        codeStatus('screenshot saved');
      }
    }, 'image/png');
  }catch(e){
    codeStatus('screenshot failed');
  }
}
function toggleCameraPanel(){
  _camOpen = !_camOpen;
  if(_camPanel) _camPanel.style.display = _camOpen ? 'flex' : 'none';
  if(_camBtn) _camBtn.textContent = _camOpen ? '\u2715' : '\u25CE';
}
/* move with keyboard */
var _origHideFloat = typeof hideFloatButtons === 'function' ? hideFloatButtons : null;
  _menuBtn.id = 'mastermenubtn';
  _menuBtn.textContent = '\u2630';
  _menuBtn.title = 'Menu';
  _menuBtn.style.cssText = 'position:fixed;bottom:14px;right:14px;z-index:10000;width:46px;height:46px;background:#d8a920;color:#111;border:1px solid #d8a920;border-radius:50%;font-size:24px;line-height:1;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;';
  _menuBtn.onclick = function(){ toggleButtonMenu(); };
  document.body.appendChild(_menuBtn);
  createCameraButton();
  /* the panel that holds them */
  _menuPanel = document.createElement('div');
  _menuPanel.id = 'buttonmenupanel';
  _menuPanel.style.cssText = 'position:fixed;bottom:90px;left:50%;transform:translateX(-50%);z-index:9999;display:none;flex-direction:row;flex-wrap:wrap;gap:14px;justify-content:center;align-items:center;max-height:50vh;overflow-y:auto;padding:16px;max-width:92vw;background:rgba(10,8,4,0.92);border-radius:20px;border:2px solid #8a6a1c;';
  document.body.appendChild(_menuPanel);
  /* ? help button — lives in the dynamic panel */
  var _helpBtn = document.createElement('button');
  _helpBtn.id = 'helpbtn';
  _helpBtn.textContent = '?';
  _helpBtn.title = 'Help';
  _helpBtn.style.cssText = 'width:46px;height:46px;background:#1a1a1a;color:#ffd700;border:1px solid #ffd700;border-radius:50%;font-size:24px;line-height:1;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;';
  _helpBtn.onclick = function(){ toggleHelp(); };
  _menuPanel.appendChild(_helpBtn);
  /* her buttons — hover over her body, not in the menu */
  var bringBtn = document.createElement('button');
  bringBtn.id = 'bringherbtn';
  bringBtn.textContent = '\u2640';
  bringBtn.title = 'Bring Her';
  bringBtn.style.cssText = 'position:fixed;z-index:10000;width:46px;height:46px;background:#d8a920;color:#111;border:1px solid #d8a920;border-radius:50%;font-size:24px;line-height:1;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;display:none;';
  bringBtn.onclick = function(){ if(typeof Mainframe!=='undefined') Mainframe.run('bringher'); };
  document.body.appendChild(bringBtn);
  var dismissBtn = document.createElement('button');
  dismissBtn.id = 'dismissherbtn';
  dismissBtn.textContent = '\u2715';
  dismissBtn.title = 'Dismiss Her';
  dismissBtn.style.cssText = 'position:fixed;z-index:10000;width:46px;height:46px;background:rgba(216,169,32,0.9);color:#111;border:1px solid #d8a920;border-radius:50%;font-size:20px;line-height:1;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;display:none;';
  dismissBtn.onclick = function(){ if(typeof Mainframe!=='undefined') Mainframe.run('dismissher'); };
  document.body.appendChild(dismissBtn);
  /* collect the buttons into the panel */
  var ids = ['refresh','mode-create','mode-delete','shape-btn','render-btn','walk-btn','movetogglebtn','continuumBtn','placetogglebtn','jumpbtn','codebtn','chatbtn','gobtn','clear-cache-btn','map-toggle-btn','district-one-btn','homebtn','grabbtn','creatorblockbtn','creatorcompass','camerabtn','musicbtn','songbtn','helpbtn','exportbtn','mastermenubtn']; /* flybtn lives by the joystick now */
  // auto-collapse after tapping any button — the buttons should not block
  setTimeout(function(){
    try{
      var panel = document.getElementById('buttonmenupanel');
      if(panel){
        panel.addEventListener('click', function(e){
          if(e.target.tagName==='BUTTON'){
            setTimeout(function(){ 
              if(typeof toggleButtonMenu==='function' && _menuOpen) toggleButtonMenu();
            }, 300);
          }
        });
      }
    }catch(e){}
  }, 6000);
  var checkCount = 0;
  var collectTimer = setInterval(function(){
    checkCount++;
    var allFound = true;
    ids.forEach(function(id){
      var b = document.getElementById(id);
      if(b && !_menuPanel.contains(b)){
        /* move into panel, reset position */
        b.style.position = 'static';
        b.style.bottom = 'auto';
        b.style.right = 'auto';
        _menuPanel.appendChild(b);
      } else if(!b){
        allFound = false;
      }
    });
    if(allFound || checkCount > 30) clearInterval(collectTimer);
  }, 1000);
}
/* GRAB MODE — pick up, twist, turn */
var GRAB_MODE = false;
var _grabbed = null;
var _grabPanel = null;
function toggleGrabMode(){
  GRAB_MODE = !GRAB_MODE;
  if(GRAB_MODE){
    codeStatus('grab mode — tap something to pick it up');
    showGrabHint();
  }else{
    codeStatus('grab mode off');
    dropGrabbed();
    hideG