<!-- SOLID-PLAYTIME · part 188 -->
 }
    }
  }catch(e){}
}
if(window.MutationObserver){
  var mo2=new MutationObserver(function(){ markTreasureSlots(); });
  var p0=document.getElementById('invPanel');
  if(p0) mo2.observe(p0,{childList:true,subtree:true});
  else{
    var w8=setInterval(function(){
      var p1=document.getElementById('invPanel');
      if(p1){ mo2.observe(p1,{childList:true,subtree:true}); clearInterval(w8); }
    },1500);
  }
}
/* treasure taps: show, don't run material logic */
document.addEventListener('click',function(e){
  var b=e.target&&e.target.closest?e.target.closest('button'):null;
  if(b&&b.dataset&&b.dataset.treasure==='1'){
    e.stopPropagation();
    var page=(window.invState&&window.invState.page)||0, cat=window.invCatalog||[];
    var gridEl=null, divs=document.getElementById('invPanel').querySelectorAll('div');
    for(var i=0;i<divs.length;i++){ if(divs[i].style.gridTemplateColumns){ gridEl=divs[i]; break; } }
    var idx=Array.prototype.indexOf.call(gridEl.querySelectorAll('button'),b);
    var item=cat[page*25+idx];
    if(item) toast('TREASURE — '+item.name+' ('+item.n+' BLOCKS)','#ffd700');
  }
},true);

/* ============ demo castle (my lead) ============ */
var demoDone=false;
try{ demoDone=!!localStorage.getItem('solid-demo-castle'); }catch(e){}
function demoCastle(){
  toast('ROYAL DEMO — WATCH IT RISE','#ffd700');
  var hx=snap(Kt.hero.position.x)+24, hz=snap(Kt.hero.position.z);
  hx=snap(hx); hz=snap(hz);
  var plan=[];
  var S='stone', G='gold';
  for(var fx=-2;fx<=2;fx++) for(var fz=-2;fz<=2;fz++) plan.push(['slab',S,fx*CELL,0,fz*CELL]);
  [[-2,-2],[2,-2],[-2,2],[2,2]].forEach(function(c){ plan.push(['pillar',S,c[0]*CELL,0.25,c[1]*CELL]); });
  for(var wx=-2;wx<=2;wx++){
    if(wx!==0) plan.push(['wall',S,wx*CELL,0.25,-2*CELL]);
    if(wx!==0) plan.push(['wall',S,wx*CELL,0.25,2*CELL]);
  }
  for(var wz2=-1;wz2<=1;wz2++){ plan.push(['wall',S,-2*CELL,0.25,wz2*CELL]); plan.push(['wall',S,2*CELL,0.25,wz2*CELL]); }
  plan.push(['arch',G,0,0.25,2*CELL]);
  for(var rx=-1;rx<=1;rx++) for(var rz=-1;rz<=1;rz++) plan.push(['roof',G,rx*CELL,3.25,rz*CELL]);
  var i=0;
  sessionPlaced=[];
  function step(){
    if(i>=plan.length){
      sealBuild('CASTLE');
      try{ localStorage.setItem('solid-demo-castle','1'); }catch(e){}
      demoDone=true;
      toast('THE CASTLE STANDS — SEALED TO YOUR CHEST','#ffd700');
      return;
    }
    var p=plan[i++];
    var wx2=hx+p[2], wz2=hz+p[4];
    var y=groundY(wx2,wz2)+p[3];
    if(!cellTaken(wx2,wz2,y)){
      spawnBlock(p[0],p[1],wx2,y,wz2,0);
      sessionPlaced.push({shape:p[0],variant:p[1]});
      try{ Kt.burst(wx2,y+1.5,wz2,VCOLOR[p[1]]); }catch(e){}
    }
    saveBuilds();
    setTimeout(step,70);
  }
  step();
}
window.demoCastle=demoCastle;

}catch(e){ if(window.console&&console.warn) console.warn('build-pack:',e); }
})(),(function(){
try{
var T=window.THREE; if(!T) return;
if(window.kingdomPackLoaded) return; window.kingdomPackLoaded=true;

/* ============ defs (independent copies — packs stay decoupled) ============ */
var VCOLOR={wood:0x8B5A2B, stone:0x8a8f98, gold:0xffd700, marble:0xe8e4da};
var VCSS={wood:'#8B5A2B', stone:'#8a8f98', gold:'#ffd700', marble:'#e8e4da'};
var CELL=2;
var VMAT={};
Object.keys(VCOLOR).forEach(function(v){
  VMAT[v]=new T.MeshStandardMaterial({color:VCOLOR[v],roughness:v==='gold'?0.35:0.85,metalness:v==='gold'?0.7:0.05});
});
function groundY(x,z){ try{ return Kt.ground(x,z); }catch(e){ return 0; } }
function toast(m,c){ try{ window.invToast(m,c); }catch(e){} }
function box(grp,w,h,d,x,y,z){
  var m=new T.Mesh(new T.BoxGeometry(w,h,d),null);
  m.position.set(x,y,z); grp.add(m); return m;
}
function buildPiece(shape){
  var g=new T.Group();
  if(shape==='pillar'){ box(g,1,3.6,1,0,1.8,0); box(g,1.4,0.3,1.4,0,3.75,0); box(g,1.3,0.3,1.3,0,0.15,0); }
  else if(shape==='wall'){ box(g,2,3,0.5,0,1.5,0); }
  else if(shape==='roof'){ var m=new T.Mesh(new T.ConeGeometry(1.65,1.3,4),null); m.position.y=0.65; m.rotation.y=Math.PI/4; g.add(m); }
  else if(shape==='arch'){ box(g,0.5,3,1,-0.75,1.5,0); box(g,0.5,3,1,0.75,1.5,0); box(g,2,0.7,1,0,3.35,0); }
  else if(shape==='slab'){ box(g,2,0.25,2,0,0.125,0); }
  return g;
}
function paintPiece(g,variant){
  g.traverse(function(o){ if(o.isMesh) o.material=VMAT[variant]; });
  return g;
}

/* ============ structure templates (relative plans) ============ */
function castlePlan(){
  var plan=[], S='stone', G='gold';
  for(var fx=-2;fx<=2;fx++) for(var fz=-2;fz<=2;fz++) plan.push(['slab',S,fx*CELL,0,fz*CELL]);
  [[-2,-2],[2,-2],[-2,2],[2,2]].forEach(function(c){ plan.push(['pillar',S,c[0]*CELL,0.25,c[1]*CELL]); });
  for(var wx=-2;wx<=2;wx++){
    if(wx!==0) plan.push(['wall',S,wx*CELL,0.25,-2*CELL]);
    if(wx!==0) plan.push(['wall',S,wx*CELL,0.25,2*CELL]);
  }
  for(var wz=-1;wz<=1;wz++){ plan.push(['wall',S,-2*CELL,0.25,wz*CELL]); plan.push(['wall',S,2*CELL,0.25,wz*CELL]); }
  plan.push(['arch',G,0,0.25,2*CELL]);
  for(var rx=-1;rx<=1;rx++) for(var rz=-