/* ---------- 2.0 backpack: one screen, the hotbar on top, the figure, your items and the picture recipe book ----------
   Loaded before style.css, so rules that change shared classes (.inventory-panel, .hot-slot, .chip) use two classes. */
.backpack-panel, .trade-panel, .quest-projects { -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
.backpack-panel img, .trade-panel img, .quest-projects img { -webkit-user-drag:none; }
.inventory-panel.backpack-panel { --fw:112px; width:min(1120px, calc(100vw - 32px)); max-width:none; height:min(860px, calc(100dvh - 32px)); max-height:none; display:flex; flex-direction:column; gap:8px; overflow:hidden; padding:12px 14px; }
.inventory-panel .bag-head { position:static; top:auto; margin:0; padding:0; background:none; display:flex; align-items:center; gap:10px; }
.bag-wallet { display:flex; gap:14px; flex:1 1 auto; min-width:0; overflow:hidden; font:900 18px var(--body); color:#ffecb2; }
.bag-head > :not(.bag-wallet) { flex-shrink:0; }
.bag-wallet span { display:inline-flex; align-items:center; gap:5px; }
.bag-wallet .ico, .money .ico { width:18px; height:18px; }
.bag-table { font-size:18px; padding:4px 9px; border-radius:10px; background:#31643680; color:#d6ffcb; }
.trade-sign { font-size:22px; }
.inventory-panel .bag-head .bag-close, .inventory-panel .bag-head .bag-open { min-width:52px; min-height:44px; font-size:20px; }

/* The hotbar, large: one column per slot (lane hand makes it 9). */
.backpack-panel .bag-hotbar .inventory-hotbar { grid-template-columns:repeat(var(--slots,9),minmax(0,1fr)); gap:6px; margin:0; }
.backpack-panel .bag-hotbar .hot-slot { height:62px; padding:4px; display:grid; place-items:center; }
.backpack-panel .bag-hotbar .hot-slot.targeted { border-color:#7fe0ff; box-shadow:0 0 0 3px #7fe0ff70, inset 0 0 12px #7fe0ff55; animation:bagTarget 1s ease-in-out infinite; }
.touch-mode .backpack-panel .hot-slot>small { display:none; }
@keyframes bagTarget { 50% { box-shadow:0 0 0 5px #7fe0ff40, inset 0 0 16px #7fe0ff80; } }

.backpack-panel .bag-main { flex:1; min-height:0; display:grid; grid-template-columns:150px minmax(0,1fr) minmax(0,1.45fr); gap:12px; }
.backpack-panel .bag-items, .backpack-panel .book-cards { min-height:0; overflow:auto; overscroll-behavior:contain; }

/* The figure: the player's own skin with three wear places. */
.bag-figure { display:flex; flex-direction:column; align-items:center; gap:6px; padding-top:6px; }
.figure-wrap { position:relative; width:var(--fw); height:calc(var(--fw) * 2); }
.figure-img { width:100%; height:100%; image-rendering:pixelated; filter:drop-shadow(0 4px 0 #0005); }
.wear-place { position:absolute; width:calc(var(--fw) * .42); height:calc(var(--fw) * .42); margin:0; padding:0; display:grid; place-items:center; border-radius:50%; border:3px dashed #ffffff70; background:#0b1a2a99; color:#fff; cursor:pointer; }
.wear-place.worn { border:3px solid #ffd97a; background:transparent; box-shadow:0 0 0 3px #ffd97a40, inset 0 0 10px #ffd97a60; }
.wear-side.worn { background:#3e4a2ccc; }
.wear-place .item-emoji { width:80%; height:80%; font-size:calc(var(--fw) * .22); border-bottom-width:3px; }
.wear-ghost { font-size:calc(var(--fw) * .2); opacity:.38; filter:grayscale(.5); }
.wear-body { left:calc(50% - var(--fw) * .21); top:36%; }
.wear-feet { left:calc(50% - var(--fw) * .21); bottom:-4%; }
.wear-side { right:-24%; top:50%; }
.figure-name { max-width:100%; padding:2px 8px; border-radius:8px; background:#0b1a2acc; font:900 12px var(--body); letter-spacing:1px; color:#ffe9a6; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-transform:uppercase; }
.bag-hearts { color:#ff7b8d; font-size:16px; letter-spacing:1px; text-shadow:0 2px #451a28; }

/* Your items: picture tiles with counts; handy things first, materials after. */
.bag-items { display:grid; grid-template-columns:repeat(auto-fill,minmax(66px,1fr)); grid-auto-rows:max-content; gap:6px; align-content:start; padding:2px; }
.bag-tile { position:relative; height:74px; padding:6px 2px 14px; display:grid; place-items:center; border-radius:10px; border:2px solid #ffffff26; background:linear-gradient(#253a52,#182a3e); color:#fff; cursor:pointer; min-width:0; }
.bag-tile.material { background:linear-gradient(#2a2f3e,#1c202c); }
.bag-tile>b { position:absolute; right:5px; bottom:13px; font:900 13px var(--body); text-shadow:0 2px 2px #000; }
.bag-tile .tile-name { position:absolute; left:3px; right:3px; bottom:2px; font:800 9px var(--body); color:#cfe0ee; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-align:center; }
.bag-tile .item-emoji { width:36px; height:36px; font-size:24px; }
.bag-tile .item-tile { width:32px; height:32px; }
.saying { box-shadow:0 0 0 3px #ffe27a !important; }

/* The recipe book: picture chips, then cards. */
.bag-book { display:flex; flex-direction:column; gap:8px; min-height:0; }
.book-chips { display:flex; gap:5px; flex-wrap:wrap; }
.book-chips .chip { font-size:20px; padding:4px 10px 5px; min-width:44px; min-height:40px; border-width:2px; }
.book-cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(136px,1fr)); grid-auto-rows:max-content; gap:8px; align-content:start; padding:2px 2px 8px; }
.book-empty { font-size:28px; opacity:.5; margin:12px; }
.book-cards .recipe-card { position:relative; padding:8px 8px 10px; gap:5px; align-items:center; text-align:center; cursor:pointer; background:#14283b; border:2px solid #ffffff22; border-radius:12px; transition:opacity .2s; }
.book-cards .recipe-card.ready { border-color:#8cff6e; background:linear-gradient(#1f4a2c,#14283b); box-shadow:0 0 0 2px #8cff6e40, 0 0 14px #8cff6e40; }
.book-cards .recipe-card.faded { opacity:.62; }
.book-cards .recipe-card.brain-locked { opacity:.5; filter:grayscale(.45); }
.book-cards .recipe-card.owned { opacity:.7; }
.book-cards .recipe-card.holding { box-shadow:0 0 0 4px #ffe27a, 0 0 22px #ffe27a80; }
.book-cards .recipe-card.nope { animation:cardNope .35s; }
@keyframes cardNope { 20% { transform:translateX(-6px); } 45% { transform:translateX(5px); } 70% { transform:translateX(-3px); } }
.card-result { position:relative; display:grid; place-items:center; min-height:52px; margin-top:4px; }
.card-result .item-emoji { width:48px; height:48px; font-size:32px; }
.card-result .item-tile { width:44px; height:44px; }
.card-result>b { position:absolute; right:-18px; bottom:-2px; font:900 15px var(--body); color:#fff3c2; text-shadow:0 2px 2px #000; }
.card-name { font:800 11px var(--body); color:#d9e8f2; line-height:1.2; }
.recipe-parts { display:flex; flex-wrap:wrap; justify-content:center; gap:4px 8px; }
.part { position:relative; display:inline-flex; flex-direction:column; align-items:center; gap:2px; }
.part .item-emoji { width:26px; height:26px; font-size:17px; border-bottom-width:3px; }
.part .item-tile { width:24px; height:24px; }
.part.short .item-emoji, .part.short .item-tile { opacity:.85; filter:grayscale(.5) brightness(1.3); background:#ffffff2e; border-radius:4px; outline:2px dashed #ffd27acc; outline-offset:2px; }
.pips { display:flex; flex-wrap:wrap; justify-content:center; max-width:52px; gap:2px; }
.dot-pip { width:9px; height:9px; border-radius:2px; display:block; }
.dot-pip.got { background:#8cff6e; box-shadow:0 1px 0 #2c6b1f; }
.dot-pip.ghost { border:1.5px dashed #ffffff80; }
.pip-num { font:900 11px var(--body); font-style:normal; color:#ffb4a8; }
.pip-num.got { color:#a8ff8e; }
.recipe-money { display:flex; gap:8px; justify-content:center; min-height:4px; }
.money { display:inline-flex; align-items:center; gap:3px; font:900 12px var(--body); color:#ffecb2; }
.money.short { color:#ff9a9a; }
.card-badges { position:absolute; left:5px; top:5px; display:flex; flex-direction:column; gap:4px; }
.card-badge { width:32px; height:32px; padding:0; border-radius:50%; border:2px solid #f7c56a; background:#4d3b22; font-size:16px; cursor:pointer; display:grid; place-items:center; }
.card-badge.here { border-color:#8cff6e; background:#24452a; }
.card-badge.pulse { animation:badgePulse 1s ease-in-out infinite; }
@keyframes badgePulse { 50% { box-shadow:0 0 0 6px #f7c56a55; background:#7a5a2c; } }
.brain-ring { position:relative; width:34px; height:34px; border-radius:50%; display:grid; place-items:center; cursor:pointer; background:conic-gradient(#ffd23f calc(var(--fill) * 1%), #ffffff26 0); }
.brain-ring::before { content:""; position:absolute; inset:4px; border-radius:50%; background:#1b2b40; }
.brain-ring>b { position:relative; font-size:15px; }
.brain-ring>i { position:absolute; right:-5px; bottom:-5px; font-size:12px; font-style:normal; }
.card-owned { width:30px; height:30px; display:grid; place-items:center; border-radius:50%; background:#2f7a3a; font:900 17px var(--body); }
.card-read { position:absolute; right:4px; top:4px; width:34px; height:34px; padding:0; border-radius:50%; border:2px solid #ffffff40; background:#22364d; font-size:15px; cursor:pointer; }

/* The Craft & Trade stall. */
.inventory-panel.trade-panel { width:min(760px, calc(100vw - 32px)); max-width:none; max-height:calc(100dvh - 32px); display:flex; flex-direction:column; gap:10px; overflow:hidden; padding:12px 14px; }
.trade-panel .book-cards { min-height:0; overflow:auto; }

/* The Quest book's building projects. */
.quest-projects { margin-top:14px; }
.quest-projects-head { font-size:30px; margin:6px 0; }
.project-cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:8px; }
.project-cards .project-card { position:relative; padding:10px; gap:6px; align-items:center; text-align:center; }
.project-cards .project-card.ready { border-color:#8cff6e; box-shadow:0 0 14px #8cff6e40; }
.project-cards .project-card.done { opacity:.65; }
.project-name { font:16px var(--display); color:#ffe49c; line-height:1.15; padding:0 26px; }
.project-reward { display:flex; gap:8px; align-items:center; justify-content:center; }
.project-actions { display:flex; gap:6px; align-items:center; justify-content:center; margin-top:auto; }
.project-actions .card-read { position:static; }
.expansion-panel .project-actions .btn { margin:0; white-space:nowrap; padding:8px 12px; font-size:15px; }
.project-done { font:900 22px var(--body); color:#8cff6e; }

/* Flying pictures and the hold-to-craft array (outside the modal, above it). */
.bag-fly { position:fixed; z-index:60; pointer-events:none; }
.bag-fly .item-emoji { width:44px; height:44px; font-size:30px; }
.bag-fly .item-tile { width:40px; height:40px; }
.craft-array { position:fixed; left:0; right:0; top:max(12px, 14dvh); margin:0 auto; width:fit-content; max-width:calc(100vw - 32px); z-index:45; pointer-events:none; display:flex; flex-direction:column; gap:3px; padding:10px 14px; border-radius:14px; background:#0f1f2df0; border:2px solid #ffe27a; box-shadow:0 10px 30px #0008; }
.array-row { display:flex; align-items:center; gap:6px; }
.row-cost { display:inline-flex; align-items:center; gap:2px; font:900 11px var(--body); }
.row-cost .item-emoji { width:22px; height:22px; font-size:15px; border-bottom-width:2px; }
.row-cost .item-tile { width:20px; height:20px; }
.array-row .arrow { color:#ffe27a; }
.row-made { display:flex; gap:3px; }
.row-made .dot { width:10px; height:10px; border-radius:2px; background:var(--c,#fff); box-shadow:inset 0 0 0 1px #0006; }
.array-more { text-align:center; color:#ffe27a; line-height:1; }
.array-sum { text-align:center; font:900 20px var(--body); color:#fff3c2; margin-top:4px; }

/* Portrait phones and tablets: the figure beside your items, the book below. */
@media (orientation:portrait) and (max-width:900px) {
  .inventory-panel.backpack-panel { --fw:80px; padding:10px; gap:6px; }
  .backpack-panel .bag-main { grid-template-columns:96px minmax(0,1fr); grid-template-rows:auto minmax(0,1fr); grid-template-areas:"fig items" "book book"; gap:8px; }
  .backpack-panel .bag-figure { grid-area:fig; }
  .backpack-panel .bag-items { grid-area:items; max-height:min(34dvh, 260px); }
  .backpack-panel .bag-book { grid-area:book; }
}
@media (max-width:700px) {
  .backpack-panel .bag-hotbar .inventory-hotbar { gap:3px; }
  .backpack-panel .bag-hotbar .hot-slot { height:44px; padding:2px; }
  .backpack-panel .bag-hotbar .hot-slot .item-emoji { width:28px; height:28px; font-size:20px; }
  .backpack-panel .bag-hotbar .hot-slot .item-tile { width:24px; height:24px; }
  .backpack-panel .bag-hotbar .hot-slot>b { font-size:10px; right:2px; bottom:1px; }
  .bag-items { grid-template-columns:repeat(auto-fill,minmax(56px,1fr)); gap:4px; }
  .bag-tile { height:62px; }
  .bag-tile .item-emoji { width:30px; height:30px; font-size:20px; }
  .bag-tile .item-tile { width:26px; height:26px; }
  .book-cards { grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; }
  .book-chips .chip { font-size:17px; padding:3px 6px; min-width:40px; min-height:36px; }
  .bag-wallet { font-size:15px; gap:10px; }
  .project-cards { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:360px) {
  /* Nine slots across a 320-wide phone: a thinner frame so each slot stays at least 30 px. */
  #modal.modal-inventory { padding:6px; }
  .inventory-panel.backpack-panel, .inventory-panel.trade-panel { width:calc(100vw - 12px); padding:8px 6px; }
  .backpack-panel .bag-hotbar .inventory-hotbar { gap:2px; }
  .backpack-panel .bag-hotbar .hot-slot .item-emoji { width:22px; height:22px; font-size:16px; }
  .backpack-panel .bag-hotbar .hot-slot .item-tile { width:20px; height:20px; }
  .trade-sign { display:none; }
  .inventory-panel .bag-head .bag-close, .inventory-panel .bag-head .bag-open { min-width:44px; padding:6px 8px; }
}
/* Short landscape phones: three columns, each scrolling on its own. */
@media (max-height:600px) and (orientation:landscape) {
  .inventory-panel.backpack-panel { --fw:56px; padding:8px 10px; gap:5px; height:calc(100dvh - 24px); }
  .backpack-panel .bag-main { grid-template-columns:84px minmax(0,1fr) minmax(0,1.5fr); gap:8px; }
  .backpack-panel .bag-hotbar .hot-slot { height:40px; padding:2px; }
  .backpack-panel .bag-hotbar .hot-slot .item-emoji { width:26px; height:26px; font-size:18px; }
  .backpack-panel .bag-hotbar .hot-slot .item-tile { width:22px; height:22px; }
  .bag-figure { padding-top:0; gap:2px; }
  .wear-place { border-width:2px; }
  .wear-side { right:-34%; }
  .bag-hearts { font-size:12px; }
  .inventory-panel .bag-head .bag-close, .inventory-panel .bag-head .bag-open { min-height:38px; padding:4px 10px; }
  .bag-items { grid-template-columns:repeat(auto-fill,minmax(54px,1fr)); }
  .bag-tile { height:58px; }
  .book-cards { grid-template-columns:repeat(auto-fill,minmax(118px,1fr)); }
  .book-chips .chip { font-size:15px; min-height:32px; min-width:36px; padding:2px 6px; }
  .card-result { min-height:40px; }
  .card-result .item-emoji { width:38px; height:38px; font-size:25px; }
  .card-result .item-tile { width:34px; height:34px; }
  .inventory-panel.trade-panel { max-height:calc(100dvh - 24px); padding:8px 10px; }
}
