<!-- SOLID-PLAYTIME · part 193 -->
T=window.THREE; if(!T) return;
if(window.consolePackLoaded) return; window.consolePackLoaded=true;
/* MINIMUM = 0.13 world units — the King's eyes, the smallest thing rendered.
   The base unit the world is designed from, by the King's word. */
window.MINIMUM=0.13;
window.applyMinimum=function(obj){
  try{
    if(window.MINIMUM_OFF) return obj;
    var bb=new T.Box3().setFromObject(obj);
    var sz=new T.Vector3(); bb.getSize(sz);
    var m=Math.min(sz.x,sz.y,sz.z), MIN=(window.MINIMUM||0.13);
    if(m>0&&m<MIN){
      obj.scale.multiplyScalar(MIN/m);
      try{ if(window.minimumReached) window.minimumReached(); }catch(e){}
    }
  }catch(e){}
  return obj;
};
/* DEFAULT MINIMUM REACHED — the black type, like the wormhole's word */
window.minimumReached=function(){
  try{
    var d=document.getElementById('minimum-reached');
    if(!d){
      d=document.createElement('div');
      d.id='minimum-reached';
      d.className='world-message';
      d.setAttribute('role','status');
      d.style.cssText='position:fixed;left:0;right:0;top:16%;text-align:center;color:#000;'
        +'font-family:Georgia,serif;font-size:17px;letter-spacing:3px;z-index:10001;'
        +'pointer-events:none;transition:opacity .4s;';
      document.body.appendChild(d);
    }
    d.textContent='DEFAULT MINIMUM REACHED';
    d.style.opacity='1';
    if(d._t) clearTimeout(d._t);
    d._t=setTimeout(function(){ try{ d.style.opacity='0'; }catch(e){} },2700);
  }catch(e){}
};

/* ============ CONSOLE PACK v2 — the gold box you hold and set down ==========
   TAP BOX: a glowing gold box appears in his hand.
   BUILD mode: the map wears its grid; a gold footprint marks the box's bed;
   an invisible crosshair at frame-center illuminates when locked on a square.
   PLACE: the box is set down and unfolds into the full console.
   Footprint 16x14 = 8x7 cells of the 2-unit world grid. Light by design.    */
function toast(m,c){ try{ window.invToast(m,c); }catch(e){} }
function groundY(x,z){ try{ return Kt.ground(x,z); }catch(e){ return 0; } }
function callAction(action,args){
  return fetch('/solid/playtime/actions',{method:'POST',headers:{'Content-Type':'application/json'},
    body:JSON.stringify({action:action,args:args||{}}),credentials:'same-origin'})
    .then(function(r){ return r.json(); })
    .then(function(j){ if(j.error) throw new Error(j.error); return j.data; });
}

var VARIANTS=['wood','stone','gold','marble'];
var VCSS={wood:'#8B5A2B',stone:'#8a8f98',gold:'#ffd700',marble:'#e8e4da'};
var SHAPES=['pillar','wall','step','roof','foundation','beam','arch','stairs','platform','fence','column','slab'];
var CELL=2, FOOT_W=16, FOOT_D=14;

var api=null, curVariant='wood', curShape=null;
var buildersCache=[], visitIdx=0;
var buttons=[], hitMeshes=[];
var deployed=[];
var handBox=null, handPulse=null;
var foot=null, footFill=null;
var cross=null;
var DEFS=null;

/* wait until the builder AND the hero are truly standing in the world */
var tries=0;
var wt=setInterval(function(){
  tries++;
  var ok=false;
  try{ ok=!!(window.syncBuildAPI&&window.syncBuildAPI.piece&&Kt.hero&&Kt.hero.position&&isFinite(Kt.hero.position.x)); }catch(e){ ok=false; }
  if(ok){ api=window.syncBuildAPI; clearInterval(wt); boot(); }
  else if(tries>120) clearInterval(wt);
},500);

/* ---------- the glowing gold box ---------- */
function goldBoxMesh(s){
  return new T.Mesh(new T.BoxGeometry(s,s,s),
    new T.MeshStandardMaterial({color:0xffd700,roughness:0.25,metalness:0.8,emissive:0x553a00}));
}
window.consoleGhostMesh=function(){ return goldBoxMesh(1.4); };
window.pickupConsole=function(){
  if(handBox){ dropHold(); toast('THE GOLD BOX RESTS','#ffd700'); return; }
  try{
    window.invState.held='console';
    localStorage.setItem('solid-inv-v1',JSON.stringify({counts:window.invState.counts,equipped:window.invState.equipped,held:window.invState.held}));
  }catch(e){}
  try{
    handBox=goldBoxMesh(0.9);
    var anchor=null;
    try{ Kt.hero.traverse(function(o){ if(o&&o.name==='KING-HAND-R-01') anchor=o; }); }catch(e){}
    if(anchor){ anchor.add(handBox); handBox.position.set(0,0.35,0); }
    else { handBox.position.set(0.8,-0.45,-1.45); Kt.hero.add(handBox); }
    var p=0;
    handPulse=setInterval(function(){
      p+=0.12;
      try{ handBox.material.emissiveIntensity=0.7+0.5*Math.sin(p); }catch(e){}
    },90);
  }catch(e){ handBox=null; }
  toast('HOLDING THE GOLD BOX — TAP BUILD, AIM, PLACE','#ffd700');
};
function dropHold(){
  try{ if(handBox&&handBox.parent) handBox.parent.remove(handBox); }catch(e){}
  handBox=null;
  if(handPulse){ clearInterval(handPulse); handPulse=null; }
  try{ if(window.invState&&window.invState.held==='console') window.invState.held=null; }catch(e){}
}

/* ---------- footprint: the bed where the box will land ---------- */
function ensureFoot(){
  if(foot) return foot;
  foot=new T.Group();
  var hw=FOOT_W/2, hd=FOOT_D/2;
  var pts=[new T.Vector3(-hw,0,-hd),new T.Vector3(hw,0,-hd),new T.Vector3(h