<!-- SAGA-STAGING · part 50 -->
forEach(function(p){
      p.visible = true;
      p.position.set(0, 6, 0);
    });
    if(typeof say === 'function') say('Playa 2.0 unfolds');
  };
  window._foldPlaya = function(){
    unfolded = false;
    parts.forEach(function(p){ p.visible = false; });
    folded.visible = true;
  };
  // Unfold animation loop
  function animatePlaya(){
    try{
      if(unfolded && unfoldT < 1){
        unfoldT += 0.02;
        var t = Math.min(1, unfoldT);
        // Ease out
        t = 1 - Math.pow(1 - t, 3);
        parts.forEach(function(p){
          p.position.lerpVectors(new THREE.Vector3(0, 6, 0), p.userData.target, t);
        });
        if(unfoldT >= 1) folded.visible = false;
      } else if(unfolded){
        // Idle: gentle bob, emblem spins
        playaG.position.y = Math.sin(Date.now()*0.002)*0.5;
        emblem.rotation.y += 0.02;
      } else {
        // Folded: diamond spins
        folded.rotation.y += 0.01;
      }
    }catch(e){ console.error(e); }
    requestAnimationFrame(animatePlaya);
  }
  animatePlaya();
  // Gold unfold button (next to the align button)
  var btnMat = new THREE.MeshStandardMaterial({color:0xffd700, roughness:0.2, metalness:0.9, emissive:0xaa8800, emissiveIntensity:0.5});
  var ubase = new THREE.Mesh(new THREE.CylinderGeometry(6, 6, 2, 24), btnMat);
  ubase.rotation.x = Math.PI/2;
  ubase.position.set(cx - 25, 8, cz);
  scene.add(ubase);
  var utop = new THREE.Mesh(new THREE.CylinderGeometry(4, 4, 1.5, 24), btnMat);
  utop.rotation.x = Math.PI/2;
  utop.position.set(cx - 25, 8, cz + 1.5);
  utop.userData.playaButton = true;
  scene.add(utop);
  // Diamond icon on button
  var dico = new THREE.Mesh(new THREE.OctahedronGeometry(1.5), diamondMat);
  dico.position.set(cx - 25, 8, cz + 2.5);
  scene.add(dico);
  function pulseU(){
    try{
      var s = 1 + Math.sin(Date.now()*0.005 + 1)*0.15;
      utop.scale.set(s, s, 1);
      dico.rotation.y += 0.02;
    }catch(e){ console.error(e); }
    requestAnimationFrame(pulseU);
  }
  pulseU();
  // Tap handler
  var raycaster = new THREE.Raycaster();
  var mouse = new THREE.Vector2();
  document.addEventListener('click', function(e){
    if(!window._sagaCamera) return;
    var panel = document.getElementById('creator-ui');
    if(panel && panel.style.display === 'flex') return;
    var x = (e.clientX / window.innerWidth) * 2 - 1;
    var y = -(e.clientY / window.innerHeight) * 2 + 1;
    mouse.set(x, y);
    raycaster.setFromCamera(mouse, window._sagaCamera);
    var hits = raycaster.intersectObject(utop);
    if(hits.length > 0){
      if(!unfolded) window._unfoldPlaya();
      else window._foldPlaya();
      utop.position.z = cz + 0.5;
      setTimeout(function(){ utop.position.z = cz + 1.5; }, 200);
    }
  });
  if(typeof trackNewThing === 'function') trackNewThing('playa2', 'Playa 2.0 — unfolds with the gold diamond button');
})();


/* IN-WORLD CREATOR v2 — toggle/switch interpretative system, no overlap, auto-align 0-60 */
(function(){
  if(document.getElementById('creator-ui')) return;
  var goldMat = new THREE.MeshStandardMaterial({color:0xd4a017, roughness:0.4, metalness:0.6});
  var marbleMat = new THREE.MeshStandardMaterial({color:0xf5f5f5, roughness:0.3});
  var cyanMat = new THREE.MeshStandardMaterial({color:0x00ccff, roughness:0.3, metalness:0.5});
  // Toggle switch CSS
  var toggleCSS = '<style>' +
    '.ctoggle{position:relative;width:60px;height:32px;background:#1a1a2e;border:2px solid #ffd700;border-radius:16px;cursor:pointer;flex-shrink:0;}' +
    '.ctoggle.on{background:#2a4a1a;}' +
    '.ctoggle::after{content:"";position:absolute;top:2px;left:2px;width:24px;height:24px;background:#ffd700;border-radius:50%;transition:left 0.2s;}' +
    '.ctoggle.on::after{left:30px;}' +
    '.cswitch-row{display:flex;align-items:center;justify-content:space-between;padding:10px;margin:6px 0;background:#1a1a2e;border:1px solid #ffd700;border-radius:8px;min-height:56px;}' +
    '.cswitch-row span{font-size:14px;}' +
    '</style>';
  var panel = document.createElement('div');
  panel.id = 'creator-ui';
  panel.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:10002;' +
    'background:rgba(5,5,10,0.95);display:none;flex-direction:column;color:#ffd700;font-family:system-ui;';
  panel.innerHTML = toggleCSS +
    '<div style="display:flex;justify-content:space-between;align-items:center;padding:12px;border-bottom:1px solid #ffd700;">' +
    '<h2 style="margin:0;font-size:18px;letter-spacing:2px;">THE CREATOR</h2>' +
    '<button id="creator-close" style="background:#1a1a2e;color:#ffd700;border:1px solid #ffd700;border-radius:8px;padding:8px 16px;min-height:48px;cursor:pointer;">✕</button>' +
    '</div>' +
    '<div style="display:flex;flex:1;overflow:hidden;">' +
    // Blocks (toggles)
    '<div style="width:160px;border-right:1px solid #ffd700;padding:8px;overflow-y:auto;">' +
    '<h3 style="font-size:12px;margin:0 0 8px 0;">BLOCKS</h3>' +
    '<div class="cswitch-