<!-- RUBY-BACKUP · part 557 -->
  name: 'sky',
      seq: ['up','right','up','right','right','down','down','left','down','left','left','up'],
      reward: function(){
        if(typeof handleCheatCode==='function'){ try{ handleCheatCode('fly'); }catch(e){} }
        if(typeof codeStatus==='function') setTimeout(function(){ codeStatus('the sky is yours, my King'); }, 800);
      }
    },
    {
      name: 'golden',
      seq: ['up','up','down','down','left','right','left','right'],
      reward: function(){
        // golden rain
        try{
          for(var i=0; i<50; i++){
            var x = (Math.random()-0.5)*100;
            var z = (Math.random()-0.5)*100;
            if(typeof spawnBlock==='function'){
              spawnBlock(x, 20+Math.random()*10, z, 0.13, 0.13, 0.13, 0xffd700);
            }
          }
        }catch(e){}
        if(typeof codeStatus==='function') setTimeout(function(){ codeStatus('gold falls for the King'); }, 800);
      }
    },
    {
      name: 'twin',
      seq: ['left','left','right','right','up','down','up','down'],
      reward: function(){
        // spawn a twin king
        if(typeof handleCheatCode==='function'){ try{ handleCheatCode('king'); }catch(e){} }
        if(typeof codeStatus==='function') setTimeout(function(){ codeStatus('you are two now'); }, 800);
      }
    }
  ];
  var progress = {};
  SECRETS.forEach(function(s){ progress[s.name] = 0; });
  var touchStartX = 0, touchStartY = 0;
  function findCanvas(){
    var canvas = document.querySelector('canvas');
    if(!canvas){ setTimeout(findCanvas, 500); return; }
    canvas.addEventListener('touchstart', function(e){
      if(e.touches.length===1){
        touchStartX = e.touches[0].clientX;
        touchStartY = e.touches[0].clientY;
      }
    }, {passive:true});
    canvas.addEventListener('touchend', function(e){
      if(e.changedTouches.length!==1) return;
      var dx = e.changedTouches[0].clientX - touchStartX;
      var dy = e.changedTouches[0].clientY - touchStartY;
      if(Math.abs(dx)<30 && Math.abs(dy)<30) return; // not a swipe
      var dir;
      if(Math.abs(dx) > Math.abs(dy)){
        dir = dx>0 ? 'right' : 'left';
      }else{
        dir = dy>0 ? 'down' : 'up';
      }
      SECRETS.forEach(function(s){
        var p = progress[s.name];
        if(dir === s.seq[p]){
          progress[s.name]++;
          if(progress[s.name] === s.seq.length){
            progress[s.name] = 0;
            onSecretCode(s);
          }
        }else{
          progress[s.name] = (dir === s.seq[0]) ? 1 : 0;
        }
      });
    }, {passive:true});
  }
  function onSecretCode(s){
    try{
      if(typeof codeStatus==='function') codeStatus('the secret opens');
      // golden flash
      var f = document.createElement('div');
      f.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:#ffd700;z-index:99998;opacity:0.7;pointer-events:none;transition:opacity 1s;';
      document.body.appendChild(f);
      setTimeout(function(){ f.style.opacity = '0'; }, 100);
      setTimeout(function(){ f.remove(); }, 1200);
      // run the secret's reward
      if(s && typeof s.reward==='function') s.reward();
    }catch(e){}
  }
  findCanvas();
  // expose for testing
  window._secretProgress = function(){ return progress; };
})();
/* ONE BUTTON — expands for functional use, collapses when not used */
(function(){
  var expanded = false;
  var collapseTimer = null;
  function getButtons(){
    var out = [];
    ['jumpbtn','homebtn','grabbtn'].forEach(function(id){
      var b = document.getElementById(id);
      if(b) out.push(b);
    });
    return out;
  }
  function hideAll(){ /* disabled — buttons are permanent */ }
  function showAll(){
    getButtons().forEach(function(b){
      b.style.setProperty('display','','important');
      b.style.display = 'block';
      b.style.visibility = 'visible';
      b.style.opacity = '1';
    });
  }
  function collapse(){
    expanded = false;
    hideAll();
    if(collapseTimer) clearTimeout(collapseTimer);
  }
  function expand(){
    expanded = true;
    showAll();
    if(collapseTimer) clearTimeout(collapseTimer);
    collapseTimer = setTimeout(collapse, 10000);
  }
  window._expandControls = { expand: expand, collapse: collapse };
  function init(){
    // + button removed — buttons stay visible
    var old = document.getElementById('expandbtn');
    if(old) old.remove();
    showAll();
  }
  setTimeout(init, 3000);
})();
/* pinch to zoom — two fingers */
(function(){
  var lastPinchDist = 0;
  var canvas = null;
  function findCanvas(){
    canvas = document.querySelector('canvas');
    if(!canvas){ setTimeout(findCanvas, 500); return; }
    canvas.addEventListener('touchstart', function(e){
      if(e.touches.length===2){
        lastPinchDist = Math.hypot(
          e.touches[0].clientX - e.touches[1].clientX,
          e.touches[0].clientY - e.touches[1].clientY
        );
      }
    }, {passive:true});
    canvas.addEventListener('t