<!-- SAGA-SOLID · part 81 -->
seSpeed * 3 : _baseSpeed;
}

/* ===== THE TOUCH — v96, engage with blocks only when logged in ===== */
var _canTouchBlocks = false;
function grantTouch(){
  _canTouchBlocks = true;
  if(typeof say === "function") say("You have the touch. Blocks answer to you now.");
}
function canTouch(){
  return _canTouchBlocks;
}
/* Gate block taps */
(function(){
  var _origHandler = null;
  document.addEventListener("click", function(e){
    var t = e.target;
    /* If tapping a 3D block (not UI), check touch permission */
    if(t && t.tagName === "CANVAS"){
      if(!_canTouchBlocks){
        /* Let the raycast happen, but the block won't respond without touch */
      }
    }
  }, true);
})();

window.__sagaExecMark('6830');

/* ===== COIN FLIP — v97, over the flat volcano ===== */
var _flipCoin = null;
var _flipAnim = null;
function buildFlipCoin(){
  if(_flipCoin) return;
  /* Gold coin */
  var geo = new THREE.CylinderGeometry(2, 2, 0.3, 32);
  var mat = new THREE.MeshStandardMaterial({
    color: 0xd8a920, roughness: 0.2, metalness: 0.9,
    emissive: 0x554400, emissiveIntensity: 0.3
  });
  _flipCoin = new THREE.Mesh(geo, mat);
  /* Start position: west of the flat volcano at (2000, 1920) */
  _flipCoin.position.set(1800, 100, 1920);
  scene.add(_flipCoin);
  if(typeof say === "function") say("The coin rises to flip the flat volcano.");
}
function flipCoinOverVolcano(){
  buildFlipCoin();
  if(_flipAnim) clearInterval(_flipAnim);
  var t = 0;
  var startX = 1800, endX = 2200;
  var volcanoX = 2000, volcanoZ = 1920, volcanoH = 80;
  _flipAnim = setInterval(function(){
    t += 0.02;
    if(t >= 1){
      clearInterval(_flipAnim);
      _flipAnim = null;
      if(typeof say === "function") say("The coin lands. Heads.");
      return;
    }
    /* Arc over the volcano */
    var x = startX + (endX - startX) * t;
    var y = 100 + Math.sin(t * Math.PI) * (volcanoH + 60);
    _flipCoin.position.set(x, y, volcanoZ);
    /* Flip (spin) */
    _flipCoin.rotation.x += 0.3;
    _flipCoin.rotation.z += 0.1;
  }, 30);
}
/* Auto-start one flip for the King */
setTimeout(function(){
  if(typeof scene !== "undefined") flipCoinOverVolcano();
}, 5000);

/* ===== REAL ATMOSPHERE — v100 ===== */
var _atmosFx = null;
function clearAtmos(){
  if(_atmosFx){
    scene.remove(_atmosFx);
    _atmosFx = null;
  }
}
function setAurora(){
  clearAtmos();
  var g = new THREE.Group();
  for(var i=0; i<5; i++){
    var geo = new THREE.PlaneGeometry(100, 20, 20, 1);
    var mat = new THREE.MeshBasicMaterial({color: 0x00ff88, transparent: true, opacity: 0.3, side: THREE.DoubleSide});
    var m = new THREE.Mesh(geo, mat);
    m.position.set((i-2)*40, 80, -100);
    m.rotation.x = -0.3;
    g.add(m);
  }
  scene.add(g);
  _atmosFx = g;
  if(typeof say === "function") say("Aurora dances.");
}
function setEmber(){
  clearAtmos();
  var g = new THREE.Group();
  var geo = new THREE.SphereGeometry(0.3, 8, 8);
  var mat = new THREE.MeshBasicMaterial({color: 0xff6600});
  for(var i=0; i<50; i++){
    var p = new THREE.Mesh(geo, mat);
    p.position.set((Math.random()-0.5)*100, Math.random()*50, (Math.random()-0.5)*100);
    p.userData.vy = 0.5 + Math.random();
    g.add(p);
  }
  g.userData.update = function(){
    g.children.forEach(function(p){
      p.position.y += p.userData.vy;
      if(p.position.y > 60) p.position.y = 0;
    });
  };
  scene.add(g);
  _atmosFx = g;
  if(typeof say === "function") say("Embers rise.");
}
function setStorm(){
  clearAtmos();
  var g = new THREE.Group();
  var light = new THREE.PointLight(0x8888ff, 5, 200);
  light.position.set(0, 50, 0);
  g.add(light);
  g.userData.flash = 0;
  g.userData.update = function(){
    g.userData.flash--;
    if(g.userData.flash <= 0){
      light.intensity = Math.random() > 0.7 ? 10 : 2;
      g.userData.flash = 10 + Math.random()*30;
    }
  };
  scene.add(g);
  _atmosFx = g;
  if(typeof say === "function") say("Storm gathers.");
}
function setDawn(){
  clearAtmos();
  if(typeof scene !== "undefined"){
    scene.background = new THREE.Color(0xffb366);
    scene.fog = null; /* HAZE REMOVED */
  }
  _atmosFx = {dummy: true};
  if(typeof say === "function") say("Dawn breaks.");
}
function setWhiteout(){
  clearAtmos();
  if(typeof scene !== "undefined"){
    scene.background = new THREE.Color(0xffffff);
    scene.fog = null; /* HAZE REMOVED */
  }
  _atmosFx = {dummy: true};
  if(typeof say === "function") say("Whiteout.");
}
function setRain(){
  clearAtmos();
  var g = new THREE.Group();
  var geo = new THREE.CylinderGeometry(0.05, 0.05, 3);
  var mat = new THREE.MeshBasicMaterial({color: 0x8888ff, transparent: true, opacity: 0.6});
  for(var i=0; i<100; i++){
    var p = new THREE.Mesh(geo, mat);
    p.position.set((Math.random()-0.5)*100, Math.random()*60, (Math.random()-0.5)*100);
    p.userData.vy = 2 + Math.random()*2;
    g.add(p);
  }
  g.userData.update = function(){
    g.children.forEach(function(p){
      p.position.y -= p.userData.vy;
      