<!-- SOLID-PLAYTIME · part 181 -->
.forEach(function(wd){ catalog.push({id:'w-'+wd[0],kind:'weapon',w:wd[0],name:wd[1],css:wd[2]}); });
SHAPES.forEach(function(s){ VARIANTS.forEach(function(v){
  catalog.push({id:'m-'+v+'-'+s,kind:'material',shape:s,variant:v,name:(v+' '+s).toUpperCase(),css:VCSS[v]});
});});
var PER_PAGE=25, TOTAL_PAGES=8, TOTAL_SLOTS=200, STACK_MAX=2000;

/* ============ state (persisted) ============ */
var inv={counts:{},equipped:'pistol',held:null,page:0};
try{
  var sv=JSON.parse(localStorage.getItem('solid-inv-v1')||'{}');
  if(sv.counts) inv.counts=sv.counts;
  if(sv.equipped) inv.equipped=sv.equipped;
  if(sv.held) inv.held=sv.held;
}catch(e){}
function save(){ try{ localStorage.setItem('solid-inv-v1',JSON.stringify({counts:inv.counts,equipped:inv.equipped,held:inv.held})); }catch(e){} }

/* ============ canvas icons ============ */
var iconCache={};
function shade(hex,f){
  var n=parseInt(hex.slice(1),16), r=(n>>16)&255, g=(n>>8)&255, b=n&255;
  r=Math.max(0,Math.min(255,Math.round(r*f))); g=Math.max(0,Math.min(255,Math.round(g*f))); b=Math.max(0,Math.min(255,Math.round(b*f)));
  return 'rgb('+r+','+g+','+b+')';
}
function drawShape(g,shape,css){
  var dark=shade(css,0.55), lite=shade(css,1.25);
  g.fillStyle=css; g.strokeStyle=dark; g.lineWidth=2;
  function R(x,y,w,h){ g.fillStyle=css; g.fillRect(x,y,w,h); g.strokeRect(x,y,w,h); }
  if(shape==='pillar'){ R(22,8,12,34); R(16,4,24,6); R(16,42,24,6); }
  else if(shape==='column'){ R(22,8,12,34); g.fillStyle=dark; for(var i=0;i<3;i++) g.fillRect(24+i*4,10,1.5,30); R(16,4,24,6); R(16,42,24,6); }
  else if(shape==='wall'){ R(8,14,40,28); g.strokeStyle=dark; g.lineWidth=1.5;
    g.beginPath(); g.moveTo(8,23); g.lineTo(48,23); g.moveTo(8,32); g.lineTo(48,32);
    g.moveTo(21,14); g.lineTo(21,23); g.moveTo(35,23); g.lineTo(35,32); g.moveTo(21,32); g.lineTo(21,42); g.stroke(); }
  else if(shape==='step'){ R(8,34,40,8); R(18,24,30,10); R(28,14,20,10); }
  else if(shape==='stairs'){ for(var s2=0;s2<5;s2++) R(8+s2*8,34-s2*7,8,7+(s2*0)); R(8,34,40,8); }
  else if(shape==='roof'){ g.fillStyle=css; g.beginPath(); g.moveTo(6,36); g.lineTo(28,8); g.lineTo(50,36); g.closePath(); g.fill(); g.stroke();
    g.fillStyle=dark; g.fillRect(24,22,8,14); }
  else if(shape==='foundation'){ R(6,30,44,12); R(10,24,36,6); }
  else if(shape==='beam'){ R(6,22,44,12); g.fillStyle=dark; g.fillRect(6,22,44,3); }
  else if(shape==='arch'){ g.fillStyle=css; g.beginPath(); g.moveTo(10,44); g.lineTo(10,24); g.arc(28,24,18,Math.PI,0); g.lineTo(46,44); g.closePath(); g.fill(); g.stroke();
    g.fillStyle='#0a0a0a'; g.beginPath(); g.arc(28,30,10,Math.PI,0); g.lineTo(38,44); g.lineTo(18,44); g.closePath(); g.fill(); }
  else if(shape==='platform'){ R(6,28,44,8); R(10,36,6,8); R(40,36,6,8); }
  else if(shape==='fence'){ for(var f=0;f<4;f++){ R(10+f*12,12,6,28); } R(8,20,40,5); R(8,30,40,5); }
  else if(shape==='slab'){ R(8,24,40,10); g.fillStyle=lite; g.fillRect(8,24,40,3); }
  g.fillStyle=lite; g.fillRect(4,4,3,48);
}
function drawWeaponIcon(g,w,css){
  g.fillStyle=css; g.strokeStyle=shade(css,0.5); g.lineWidth=2;
  if(w==='pistol'){ g.fillRect(10,22,28,9); g.strokeRect(10,22,28,9); g.fillRect(14,31,8,14); g.strokeRect(14,31,8,14); g.fillRect(38,24,8,5); }
  else if(w==='rifle'){ g.fillRect(6,24,40,7); g.strokeRect(6,24,40,7); g.fillRect(20,31,7,12); g.strokeRect(20,31,7,12); g.fillRect(38,20,10,6); }
  else if(w==='shotgun'){ g.fillRect(8,22,34,10); g.strokeRect(8,22,34,10); g.fillRect(16,32,8,13); g.strokeRect(16,32,8,13); g.fillRect(30,32,14,7); }
  else if(w==='laser'){ g.fillRect(8,23,34,10); g.strokeRect(8,23,34,10); g.fillStyle='#ffffff'; g.fillRect(40,25,8,6); g.fillStyle=css; g.fillRect(12,25,14,6); }
}
function iconFor(item){
  if(iconCache[item.id]) return iconCache[item.id];
  var c=document.createElement('canvas'); c.width=c.height=56;
  var g=c.getContext('2d');
  if(item.kind==='weapon') drawWeaponIcon(g,item.w,item.css);
  else drawShape(g,item.shape,item.css);
  var url=c.toDataURL();
  iconCache[item.id]=url;
  return url;
}

/* ============ toast ============ */
var toastBox=document.createElement('div');
toastBox.style.cssText='position:fixed;bottom:130px;left:50%;transform:translateX(-50%);z-index:10002;display:flex;flex-direction:column;gap:6px;align-items:center;pointer-events:none;';
document.body.appendChild(toastBox);
function toast(msg,color){
  color=color||'#ffd700';
  var d=document.createElement('div');
  d.textContent=msg;
  d.style.cssText='padding:8px 14px;background:rgba(0,0,0,0.72);border:1px solid '+color+';color:'+color+';border-radius:8px;font-size:13px;font-weight:bold;white-space:nowrap;';
  toastBox.appendChild(d);
  while(toastBox.children.length>4) toastBox.removeChild(toastBox.firstChild);
  setTimeout(function(){ d.style.transition='opacity 0.5s'; d.style.opacity='0'; setTimeout(function(){ if(d.parentNode) d.parentNode.removeChild(d); },500); },1700);
}
window.invToast=toast;

/* ============ inventory panel ============ */
