/* =========================================================
   RPG 2D PRO - Inventário / Equipado / Craft
   Versão limpa V18.1
   Objetivo:
   - manter 20 slots fixos no inventário (5 x 4)
   - manter Equipado na largura de 5 slots
   - remover blocos antigos acumulados e bordas grossas
   - manter compatível com botões de skill/item e UI ajustável
   ========================================================= */

:root{
  --inv-slot:44px;
  --inv-gap:5px;
  --inv-panel-w:292px;
  --inv-bg-top:rgba(30,24,13,.96);
  --inv-bg-bottom:rgba(8,7,6,.96);
  --inv-gold:#ffd36a;
  --inv-gold-border:rgba(214,177,82,.48);
  --inv-soft-border:rgba(255,255,255,.16);
}

/* ===== INVENTÁRIO: OVERLAY ===== */
#inventoryUI{
  display:none;
  position:fixed;
  inset:0;
  z-index:30010;
  background:transparent;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
  pointer-events:none;
  align-items:flex-start;
  justify-content:flex-start;
  padding:0;
}

body.inventory-open #inventoryUI,
#inventoryUI[style*="flex"]{
  display:block;
  pointer-events:none;
}

/* ===== INVENTÁRIO: JANELA ===== */
#inventoryPanel{
  position:fixed;
  left:max(8px, env(safe-area-inset-left));
  top:max(62px, calc(env(safe-area-inset-top) + 58px));
  box-sizing:border-box;
  width:var(--inv-panel-w);
  min-width:var(--inv-panel-w);
  max-width:calc(100vw - 16px);
  max-height:calc(100vh - 82px);
  padding:8px;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  pointer-events:auto;
  color:#fff;
  background:linear-gradient(180deg, var(--inv-bg-top), var(--inv-bg-bottom));
  border:1px solid var(--inv-gold-border);
  border-radius:12px;
  box-shadow:0 8px 24px rgba(0,0,0,.58), inset 0 0 0 1px rgba(255,255,255,.04);
}

#inventoryHeader{
  position:relative;
  display:block;
  width:100%;
  height:30px;
  min-height:30px;
  margin:0 0 6px 0;
  padding:0;
  flex:0 0 auto;
}

#inventoryPanel h2,
#inventoryHeader h2{
  display:block;
  box-sizing:border-box;
  width:100%;
  margin:0;
  padding:7px 34px 0 34px;
  text-align:center;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  color:var(--inv-gold);
  font-size:15px;
  line-height:16px;
  text-shadow:0 1px 2px #000;
}

#inventoryClose{
  position:absolute;
  right:0;
  top:0;
  box-sizing:border-box;
  width:28px;
  height:28px;
  min-width:28px;
  max-width:28px;
  padding:0;
  margin:0;
  z-index:2;
  border:1px solid rgba(255,255,255,.16);
  border-radius:8px;
  background:rgba(255,255,255,.08);
  color:#fff;
  font-size:16px;
  line-height:26px;
  cursor:pointer;
  touch-action:manipulation;
  -webkit-tap-highlight-color:rgba(255,215,0,.25);
}

/* ===== EQUIPADO ===== */
#equipmentBox{
  box-sizing:border-box;
  width:100%;
  max-width:100%;
  margin:0 0 6px 0;
  padding:6px;
  flex:0 0 auto;
  background:rgba(255,255,255,.045);
  border:1px solid rgba(214,177,82,.28);
  border-radius:10px;
}

#equipmentBox h3{
  height:14px;
  line-height:14px;
  margin:0 0 5px 0;
  color:var(--inv-gold);
  font-size:12px;
}

#equipmentBox > small{
  display:none;
}

#equipmentGrid{
  display:grid;
  grid-template-columns:repeat(5, var(--inv-slot));
  grid-auto-rows:var(--inv-slot);
  gap:var(--inv-gap);
  justify-content:center;
  align-items:center;
  width:100%;
}

.equipmentSlot{
  box-sizing:border-box;
  width:var(--inv-slot);
  height:var(--inv-slot);
  min-width:var(--inv-slot);
  min-height:var(--inv-slot);
  max-width:var(--inv-slot);
  max-height:var(--inv-slot);
  padding:3px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  text-align:center;
  overflow:hidden;
  color:#fff;
  background:rgba(32,32,32,.95);
  border:1px solid var(--inv-soft-border);
  border-radius:8px;
  cursor:pointer;
  user-select:none;
  touch-action:manipulation;
}

.equipmentSlot.empty{
  opacity:.45;
}

.equipmentSlot.equipped{
  border-color:#d4af37;
  box-shadow:inset 0 0 8px rgba(212,175,55,.16);
}

.equipmentSlot b{
  max-width:100%;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  color:var(--inv-gold);
  font-size:8px;
  line-height:9px;
  text-transform:uppercase;
}

.equipmentSlot span{
  max-width:100%;
  display:block;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:9px;
  line-height:10px;
}

.equipmentSlot small{
  display:none;
}

/* ===== INVENTÁRIO: 20 SLOTS FIXOS ===== */
#inventoryGrid{
  display:grid;
  grid-template-columns:repeat(5, var(--inv-slot));
  grid-auto-rows:var(--inv-slot);
  gap:var(--inv-gap);
  justify-content:center;
  align-items:center;
  width:100%;
  max-width:100%;
  margin:0;
  padding:0 0 2px 0;
  flex:1 1 auto;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
}

.itemSlot{
  position:relative;
  box-sizing:border-box;
  width:var(--inv-slot);
  height:var(--inv-slot);
  min-width:var(--inv-slot);
  min-height:var(--inv-slot);
  max-width:var(--inv-slot);
  max-height:var(--inv-slot);
  padding:3px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  overflow:hidden;
  text-align:center;
  color:#fff;
  font-size:10px;
  line-height:1.05;
  background:rgba(18,18,18,.92);
  border:1px solid var(--inv-soft-border);
  border-radius:8px;
  box-shadow:inset 0 0 8px rgba(0,0,0,.45);
  cursor:pointer;
  user-select:none;
  touch-action:none;
  -webkit-tap-highlight-color:rgba(255,215,0,.25);
}

.itemSlot.empty{
  opacity:.34;
}

.itemSlot.fixedEmptySlot span{
  color:rgba(255,255,255,.42);
  font-size:9px;
}

.itemSlot.busy,
.equipmentSlot.busy{
  opacity:.55;
  pointer-events:none;
}

.itemSlot b{
  max-width:100%;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
  color:#fff;
  font-size:9px;
  line-height:10px;
}

.itemSlot em,
.itemSlot small,
.itemSlot .itemStats{
  display:none;
}

.itemQty{
  position:absolute;
  right:3px;
  bottom:2px;
  min-width:14px;
  padding:0 3px;
  border-radius:7px;
  background:rgba(0,0,0,.62);
  color:#fff;
  font-size:9px;
  line-height:12px;
}

.itemSlot.weapon{ border-color:rgba(231,76,60,.85); }
.itemSlot.armor{ border-color:rgba(52,152,219,.85); }
.itemSlot.potion,
.itemSlot.consumable{ border-color:rgba(46,204,113,.85); }

.itemSlot.skillBindableItem{
  outline:1px solid rgba(126,255,178,.12);
}

.itemSlot.skillItemPendingBind{
  border-color:#7cffb2;
  box-shadow:0 0 10px rgba(124,255,178,.35), inset 0 0 8px rgba(0,0,0,.45);
}

/* Quando inventário abre, evita clique em HUD atrás dele. */
body.inventory-open #chatBox,
body.inventory-open #chatInput,
body.inventory-open #chatSend,
body.inventory-open .chat-tabs,
body.inventory-open #joystick,
body.inventory-open #attackBtn,
body.inventory-open #spellBtn,
body.inventory-open #btnInventoryQuick,
body.inventory-open #btnCraftQuick,
body.inventory-open #openMenu{
  pointer-events:none;
}

body.inventory-open #btnInventoryQuick,
body.inventory-open #btnCraftQuick{
  opacity:.35;
}

/* ===== BOTÕES RÁPIDOS INVENTÁRIO / CRAFT ===== */
#btnInventoryQuick,
#btnCraftQuick{
  display:none;
  position:fixed;
  left:auto;
  right:max(10px, env(safe-area-inset-right));
  width:42px;
  height:42px;
  border-radius:10px;
  border:1px solid rgba(191,156,87,.6);
  background:linear-gradient(to bottom, rgba(80,60,25,.85), rgba(25,18,8,.85));
  color:#f6e6b2;
  z-index:10049;
  opacity:.92;
  box-shadow:0 0 6px rgba(0,0,0,.5), inset 0 0 4px rgba(255,215,0,.15);
  align-items:center;
  justify-content:center;
  touch-action:manipulation;
  cursor:pointer;
}

#btnInventoryQuick{
  top:max(60px, calc(env(safe-area-inset-top) + 60px));
  font-size:12px;
  font-weight:800;
}

#btnCraftQuick{
  top:max(110px, calc(env(safe-area-inset-top) + 110px));
  font-size:10px;
  font-weight:800;
  letter-spacing:.2px;
}

#btnInventoryQuick:active,
#btnCraftQuick:active{
  transform:scale(.92);
}

/* ===== CRAFT ===== */
#craftUI{
  position:fixed;
  inset:0;
  z-index:30020;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:12px;
  background:rgba(0,0,0,.72);
  pointer-events:auto;
}

#craftUI.hidden{
  display:none;
}

#craftPanel{
  box-sizing:border-box;
  width:min(560px, calc(100vw - 20px));
  max-height:82vh;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  color:#f6e6b2;
  background:linear-gradient(to bottom,#1c160c,#070605);
  border:1px solid rgba(191,156,87,.75);
  border-radius:16px;
  box-shadow:0 10px 34px rgba(0,0,0,.8);
}

.craftHeader{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:10px 12px;
  border-bottom:1px solid rgba(191,156,87,.35);
}

.craftHeader h2{
  margin:0;
  color:var(--inv-gold);
  font-size:18px;
}

#craftClose{
  width:36px;
  height:36px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.08);
  color:#fff;
  font-size:18px;
  cursor:pointer;
}

#craftGold,
#craftMessage{
  padding:6px 12px;
  color:var(--inv-gold);
  font-size:12px;
}

#craftList{
  overflow:auto;
  padding:8px;
  display:flex;
  flex-direction:column;
  gap:8px;
}

.craftCard{
  padding:9px;
  border:1px solid rgba(255,255,255,.12);
  border-radius:12px;
  background:rgba(255,255,255,.055);
}

.craftTop{
  display:flex;
  justify-content:space-between;
  gap:8px;
}

.craftTop b{
  color:#ffe9a8;
  font-size:13px;
}

.craftTop small,
.craftCard p{
  margin:4px 0;
  opacity:.8;
  font-size:11px;
}

.craftReqs,
.craftMaterials{
  display:flex;
  flex-wrap:wrap;
  gap:5px;
  margin:6px 0;
}

.craftReqs span,
.craftMaterials span{
  padding:4px 7px;
  border:1px solid rgba(255,255,255,.08);
  border-radius:999px;
  background:rgba(255,255,255,.08);
  font-size:10px;
}

.craftReqs .ok,
.craftMaterials .ok{ color:#7cffb2; }
.craftReqs .bad,
.craftMaterials .bad{ color:#ff8b8b; }

.craftCard button{
  width:100%;
  margin-top:6px;
  padding:9px;
  border:1px solid rgba(191,156,87,.6);
  border-radius:10px;
  background:linear-gradient(to bottom,#6e4b1f,#2b1a08);
  color:#f8e7a5;
  cursor:pointer;
}

.craftEmpty{
  padding:16px;
  text-align:center;
  opacity:.75;
}

/* ===== RESPONSIVO ===== */
@media (orientation:landscape) and (max-height:520px){
  :root{
    --inv-slot:42px;
    --inv-panel-w:292px;
  }

  #inventoryPanel{
    top:max(44px, calc(env(safe-area-inset-top) + 42px));
    max-width:min(var(--inv-panel-w), calc(100vw - 150px));
    max-height:calc(100vh - 52px);
    padding:8px;
  }

  #btnInventoryQuick{
    top:max(56px, calc(env(safe-area-inset-top) + 56px));
  }

  #btnCraftQuick{
    top:max(104px, calc(env(safe-area-inset-top) + 104px));
  }
}

@media (max-width:560px) and (orientation:portrait){
  #inventoryPanel{
    left:max(8px, env(safe-area-inset-left));
    top:max(74px, calc(env(safe-area-inset-top) + 70px));
    max-height:calc(100vh - 92px);
  }
}
