/* ── 인벤토리(격자 가방) ── */
/* 칸 크기는 화면 높이에 맞춘다: 장비 2줄(1.6칸씩) + 가방 9줄 + 머리·도구·일괄 분해 줄이 남는 높이에 꼭 맞도록(모자라면 스크롤) */
.panel-box.panel-inv {
  --cell: clamp(26px, min(4.2vw, calc((100vh - 440px) / 12.2)), 56px);
  position: relative; overflow: visible;
  /* 가로: 격자 10칸 + 안쪽 여백 + 세로 스크롤 막대 자리(항상 비워 둠) — 내용이 창보다 넓으면 눌렀을 때 옆으로 밀린다 */
  width: calc(var(--cell) * 10 + 56px); max-width: 100%; height: auto; max-height: 100%;
}
.inv-layout {
  flex: 1; overflow-x: hidden; overflow-y: auto; scrollbar-gutter: stable;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-height: 0;
}
.inv-bag { display: flex; flex-direction: column; gap: 8px; }
.inv-grid {
  --gw: 10; --gh: 9;
  position: relative; width: calc(var(--cell) * var(--gw)); height: calc(var(--cell) * var(--gh));
  border: 1px solid var(--line); border-radius: 6px; background: rgba(8, 8, 10, 0.6);
  touch-action: none;
}
.inv-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--gw), 1fr); grid-template-rows: repeat(var(--gh), 1fr); }
.inv-cell { border-right: 1px solid rgba(255, 255, 255, 0.05); border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.inv-items { position: absolute; inset: 0; }
.inv-item {
  position: absolute;
  left: calc(var(--x) * var(--cell)); top: calc(var(--y) * var(--cell));
  width: calc(var(--w) * var(--cell)); height: calc(var(--h) * var(--cell));
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #3a3a40; border-radius: 4px;
  background: linear-gradient(180deg, rgba(60, 60, 68, 0.55), rgba(30, 30, 36, 0.55));
  cursor: var(--cur-point); touch-action: none; overflow: hidden;
}
.inv-item.r1 { border-color: var(--r1); background: linear-gradient(180deg, rgba(74, 160, 255, 0.22), rgba(20, 30, 46, 0.6)); }
.inv-item.r2 { border-color: var(--r2); background: linear-gradient(180deg, rgba(255, 210, 58, 0.2), rgba(46, 40, 16, 0.6)); }
.inv-item.r3 { border-color: var(--r3); background: linear-gradient(180deg, rgba(180, 92, 255, 0.22), rgba(36, 20, 50, 0.6)); }
.inv-item.r4 { border-color: var(--r4); background: linear-gradient(180deg, rgba(255, 138, 30, 0.26), rgba(50, 28, 12, 0.6)); box-shadow: inset 0 0 12px rgba(255, 138, 30, 0.35); }
.inv-item.r5 { border-color: var(--r5); background: linear-gradient(180deg, rgba(217, 178, 106, 0.28), rgba(46, 36, 18, 0.65)); box-shadow: inset 0 0 12px rgba(217, 178, 106, 0.4); }
.inv-item.is-mat { border-color: #8a7a5a; background: linear-gradient(180deg, rgba(120, 100, 60, 0.3), rgba(30, 26, 20, 0.6)); }
.inv-item.is-sel { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.inv-item.is-dragging { opacity: 0.3; }
.inv-item-img {
  width: calc(var(--iw, 1) * var(--cell) - 6px); height: calc(var(--ih, 1) * var(--cell) - 6px);
  object-fit: contain; pointer-events: none; flex: none;
}
.inv-item.is-rot .inv-item-img { transform: rotate(90deg); }
.inv-item-eq .inv-item-img { width: 86%; height: 86%; }
.inv-count {
  position: absolute; right: 3px; bottom: 1px; font-size: 12px; font-weight: 800;
  color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000; pointer-events: none;
}
.inv-drop {
  position: absolute; pointer-events: none;
  left: calc(var(--x) * var(--cell)); top: calc(var(--y) * var(--cell));
  width: calc(var(--w) * var(--cell)); height: calc(var(--h) * var(--cell));
  border-radius: 4px;
}
.inv-drop.is-ok { background: rgba(111, 220, 132, 0.25); border: 2px solid var(--good); }
.inv-drop.is-bad { background: rgba(226, 81, 62, 0.25); border: 2px solid var(--danger); }
.inv-ghost {
  position: fixed; z-index: 80; pointer-events: none;
  left: var(--gx); top: var(--gy); width: var(--gw); height: var(--gh);
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 4px; background: rgba(30, 30, 36, 0.7);
  opacity: 0.9;
}
.inv-ghost.r1 { border-color: var(--r1); }
.inv-ghost.r2 { border-color: var(--r2); }
.inv-ghost.r3 { border-color: var(--r3); }
.inv-ghost.r4 { border-color: var(--r4); }
.inv-ghost.r5 { border-color: var(--r5); }
.inv-ghost-img { width: var(--iw); height: var(--ih); object-fit: contain; flex: none; }
.inv-ghost.is-rot .inv-ghost-img { transform: rotate(90deg); }
.inv-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; }
.inv-auto, .inv-bulk { display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.inv-auto .btn, .inv-bulk .btn { white-space: nowrap; flex: none; min-width: 84px; }
.inv-auto .inv-bulk-filter, .inv-bulk .inv-bulk-filter { min-width: 0; flex-wrap: wrap; gap: 3px; }
.inv-auto .inv-chip, .inv-bulk .inv-chip { font-size: 11px; padding: 2px 6px; min-height: 26px; }
.inv-bulk-filter { display: flex; gap: 4px; }
.inv-chip {
  font: inherit; font-size: 12px; padding: 4px 7px; min-height: 30px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  background: rgba(20, 20, 26, 0.7); border: 1px solid currentColor; opacity: 0.5;
}
.inv-chip.is-on { opacity: 1; background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 0 0 1px currentColor; }
.inv-chip:hover { opacity: 0.8; }
.inv-chip.is-on:hover { opacity: 1; }

/* 창고 모드: 장비 칸 대신 창고 탭과 격자(10 × 8)가 가방 위에 나온다. 칸은 창이 길어진 만큼 작게 */
.inv-stash { display: none; flex: none; flex-direction: column; gap: 8px; }
.panel-box.panel-inv.is-stash { --cell: clamp(22px, min(4.2vw, calc((100vh - 440px) / 17)), 52px); }
.panel-inv.is-stash .inv-layout { overflow-y: auto; }
.panel-inv.is-stash .inv-stash { display: flex; }
.panel-inv.is-stash .inv-equip, .panel-inv.is-stash .inv-bulk, .panel-inv.is-stash .inv-auto { display: none; }
.stash-grid { --gw: 10; --gh: 8; }
.stash-head { display: flex; gap: 6px; align-items: stretch; }
.stash-head .stash-tabs { flex: 1; min-width: 0; }
.stash-sort { flex: none; padding-inline: 10px; }
.stash-tabs { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.stash-tab {
  position: relative; min-height: 32px; padding: 0; border-radius: 6px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 700; color: var(--muted);
  background: rgba(20, 20, 26, 0.7); border: 1px solid var(--line);
}
.stash-tab:hover { color: var(--text); border-color: #6a6a74; }
.stash-tab.has-items::after {
  content: ''; position: absolute; right: 4px; top: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2);
}
.stash-tab.is-on { color: #1a1206; background: var(--accent-2); border-color: var(--accent-2); }
.stash-tab.is-on::after { background: #1a1206; }
.stash-tab.is-hover { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }

/* 장비 칸: 몸 모양 배치 */
.inv-equip {
  display: grid; gap: 8px;
  grid-template-columns: repeat(4, calc(var(--cell) * 1.6));
  grid-template-rows: repeat(2, calc(var(--cell) * 1.6));
  grid-template-areas: "weapon head chest arm" "ring belt leg feet";
}
.inv-slot {
  position: relative; border: 1px dashed #4a4a52; border-radius: 8px; background: rgba(8, 8, 10, 0.5);
  display: flex; align-items: center; justify-content: center;
}
.inv-slot-weapon { grid-area: weapon; } .inv-slot-head { grid-area: head; } .inv-slot-chest { grid-area: chest; }
.inv-slot-arm { grid-area: arm; } .inv-slot-leg { grid-area: leg; } .inv-slot-feet { grid-area: feet; }
.inv-slot-ring { grid-area: ring; } .inv-slot-belt { grid-area: belt; }
.inv-slot-name { font-size: 12px; color: var(--muted); pointer-events: none; }
.inv-slot.is-filled { border-style: solid; }
.inv-slot.is-filled .inv-slot-name { display: none; }
.inv-slot .inv-item { position: absolute; inset: 0; left: 0; top: 0; width: 100%; height: 100%; }
.inv-slot.is-hover { border-color: var(--good); background: rgba(111, 220, 132, 0.15); }
.inv-slot.is-hover.is-bad { border-color: var(--danger); background: rgba(226, 81, 62, 0.15); }

/* 상세 정보: 인벤토리 왼쪽에 붙는 별도 창. 내용만 스크롤되고 버튼 줄은 늘 아래에 보인다 */
.inv-detail {
  position: absolute; top: 0; right: calc(100% + 12px);
  width: 340px; max-height: 100%;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  animation: toast-in 0.15s ease;
}
.inv-detail-head { flex: none; display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 700; color: var(--muted); }
.close-btn-small { width: 30px; height: 30px; }
.inv-info { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.inv-actions:empty { display: none; }
.inv-equip, .inv-bag { flex: none; }
.it-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(14px, 1.3vw, 17px); }
.it-affix-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-guide { margin: 0; font-size: 13px; line-height: 1.6; color: var(--muted); }
.inv-arrow { font-size: 12px; color: var(--accent-2); font-weight: 700; }
.inv-actions { flex: none; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 10px; border-top: 1px solid #2c2a26; }
.inv-actions .btn { flex: 1 1 0; min-width: 0; }
.inv-err { margin: 0; font-size: 13px; color: var(--danger); }
.it-detail { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid #2c2a26; border-radius: 10px; background: var(--panel-2); }
.it-name { font-size: 17px; font-weight: 800; }
.it-name.it-mat { color: #f0deb0; }
.it-sub { font-size: 12px; color: var(--muted); }
.it-lv.is-locked, .it-req.is-locked { color: var(--danger); font-weight: 700; }
.it-req { font-size: 12px; color: var(--sky); }
.it-desc { margin: 0; font-size: 13px; line-height: 1.6; }
.it-imp { display: flex; flex-direction: column; gap: 2px; padding-bottom: 6px; border-bottom: 1px solid #2c2a26; }
.it-line { font-size: 14px; }
.it-quality { font-size: 12px; color: var(--muted); }
.it-affixes { display: flex; flex-direction: column; gap: 3px; }
.it-none { font-size: 13px; color: var(--muted); }
.it-affix {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  font-size: 14px; color: #a8c8ff; background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 4px;
  text-align: left; font-family: inherit;
}
button.it-affix:hover { border-color: var(--line); }
.it-affix.is-picked { border-color: var(--accent-2); background: rgba(232, 163, 58, 0.12); }
.it-range { font-size: 12px; color: var(--muted); white-space: nowrap; }
.it-powers { display: flex; flex-direction: column; gap: 4px; padding-top: 6px; border-top: 1px solid #2c2a26; }
.it-power { font-size: 14px; line-height: 1.5; color: var(--r5); }
.it-lore { margin: 0; font-size: 13px; font-style: italic; color: #b8a888; }

@media (max-width: 900px) {
  .panel-box.panel-inv { --cell: clamp(24px, min(8.2vw, calc((100vw - 80px) / 10), calc((100vh - 220px) / 12.2)), 48px); }
  .panel-box.panel-inv.is-stash { --cell: clamp(24px, min(8.2vw, calc((100vw - 80px) / 10)), 44px); }
  /* 낮은 화면에서는 도구 줄까지 닿도록 창 안을 굴린다 */
  .inv-layout { overflow-y: auto; }
  /* 좁은 화면: 인벤토리 아래쪽을 덮는 판으로 띄운다 */
  .inv-detail { top: auto; right: 0; left: 0; bottom: 0; width: auto; max-height: 62%; border-radius: 14px 14px 16px 16px; }
}

/* 강화 준비(재료 우클릭): 준비한 재료는 빛나고, 장비 위에서는 누름 커서 */
.inv-item.is-armed { outline: 2px solid var(--good); outline-offset: -2px; animation: inv-armed 0.9s ease-in-out infinite alternate; }
@keyframes inv-armed { from { box-shadow: 0 0 0 rgba(111, 220, 132, 0); } to { box-shadow: 0 0 12px rgba(111, 220, 132, 0.75); } }
.panel-inv.is-arming .inv-item:not(.is-mat) { cursor: var(--cur-point); }
.inv-armed {
  margin: 6px 0 0; padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 700;
  color: var(--good); background: rgba(111, 220, 132, 0.1); border: 1px solid rgba(111, 220, 132, 0.4);
}

/* 장착 비교: 좋아짐 초록 · 나빠짐 빨강 */
.it-compare { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.it-compare-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.it-compare-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 1px 0; }
.it-compare-row.is-up { color: var(--good); }
.it-compare-row.is-down { color: var(--danger); }
.it-compare-v { font-weight: 700; }
.it-compare-row.is-up .it-compare-v::before { content: '▲ '; font-size: 10px; }
.it-compare-row.is-down .it-compare-v::before { content: '▼ '; font-size: 10px; }
.it-compare-none { font-size: 12px; color: var(--muted); }

/* 마우스를 올려 두면 뜨는 아이템 정보 상자 */
.item-tip {
  position: fixed; left: var(--tx, 0); top: var(--ty, 0); z-index: 900; pointer-events: none;
  width: 300px; max-width: calc(100vw - 16px); padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}
