/* Grid inventories: tiles, grids, equipment slots, the drag ghost, and the in-raid inventory panel (ui/raidinv.js).
   Widgets: ui/invgrid.js. A grid is var(--w) x var(--h) cells of var(--cell); a tile sits at --x --y and spans
   --tw x --th cells; --bg / --fg are the item's icon colours. */

:root {
  --cell: clamp(30px, min(3.1vw, 4.6vh), 46px);
  --tile-gap: 2px;
}
@media (max-width: 759px) {
  :root { --cell: clamp(26px, calc((100vw - 50px - var(--sl, 0px) - var(--sr, 0px)) / 10), 46px); }
}

/* ---------- a grid */
.inv-grid-wrap { position: relative; display: inline-block; max-width: 100%; }
.inv-grid {
  position: relative;
  width: calc(var(--w) * var(--cell));
  height: calc(var(--h) * var(--cell));
  background-color: rgba(6, 8, 10, 0.55);
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.075) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.075) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  border: 1px solid var(--line-2);
  border-radius: 3px;
  box-sizing: content-box;
  touch-action: pan-y;
}
.inv-none {
  padding: 10px 12px;
  border: 2px dashed var(--line-2);
  border-radius: var(--r);
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: calc(6 * var(--cell));
}
.cellnum {
  position: absolute;
  left: calc(var(--x) * var(--cell) + 3px);
  top: 1px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  z-index: 0;
}
.inv-hl {
  position: absolute;
  display: none;
  left: calc(var(--x) * var(--cell));
  top: calc(var(--y) * var(--cell));
  width: calc(var(--tw) * var(--cell));
  height: calc(var(--th) * var(--cell));
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
}
.inv-hl.on { display: block; }
.inv-hl.ok { background: rgba(113, 211, 107, 0.22); box-shadow: inset 0 0 0 2px var(--good); }
.inv-hl.bad { background: rgba(255, 91, 77, 0.2); box-shadow: inset 0 0 0 2px var(--bad); }
.inv-hl.merge { background: rgba(255, 210, 0, 0.22); box-shadow: inset 0 0 0 2px var(--bkv); }
.inv-hl.same { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.3); }

/* ---------- a tile */
.tile {
  position: absolute;
  left: calc(var(--x) * var(--cell));
  top: calc(var(--y) * var(--cell));
  width: calc(var(--tw) * var(--cell));
  height: calc(var(--th) * var(--cell));
  z-index: 1;
  border: var(--tile-gap) solid transparent;
  border-radius: 6px;
  background-clip: padding-box;
  background-color: var(--bg);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.28));
  color: var(--fg);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  outline: none;
  transition: transform 0.1s, opacity 0.12s, box-shadow 0.12s;
}
.tile:hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55); }
.tile:focus-visible { box-shadow: inset 0 0 0 2px var(--bkv); }
.tile .g {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(min(var(--tw), var(--th)) * var(--cell) * 0.5);
  line-height: 1;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', var(--font-body);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}
.tile.r1 .g { transform: rotate(90deg); }
.tile .nm {
  position: absolute;
  left: 3px;
  top: 1px;
  right: 3px;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: clamp(9px, calc(var(--cell) * 0.27), 12px);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.tile.s1 .nm { font-size: clamp(8px, calc(var(--cell) * 0.22), 10px); left: 2px; right: 1px; opacity: 0.9; }
.tile.s1 .g { top: 18%; font-size: calc(var(--cell) * 0.42); }
.tile .n {
  position: absolute;
  right: 2px;
  bottom: 1px;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(8px, calc(var(--cell) * 0.24), 11px);
  line-height: 1.25;
  pointer-events: none;
}
.tile .cond {
  position: absolute;
  left: 2px;
  bottom: 1px;
  padding: 0 3px;
  border-radius: 3px;
  background: var(--warn);
  color: #221400;
  font-weight: 800;
  font-size: 9px;
  line-height: 1.3;
  text-transform: uppercase;
  pointer-events: none;
}
.tile.d2 .cond { background: var(--bad); color: #fff; }
.tile.f1 .cond { background: #d7c7ff; color: #2a1a5a; }
.tile.s1 .cond { font-size: 7.5px; padding: 0 2px; }
.tile.d1 { filter: saturate(0.8); }
.tile.d2 { filter: saturate(0.6) brightness(0.85); }
.tile.d2 .g { transform: scaleY(0.55); }
.tile.r1.d2 .g { transform: rotate(90deg) scaleY(0.55); }
.tile.f1 { border-style: dashed; border-color: rgba(215, 199, 255, 0.8); background-clip: border-box; }

/* kinds */
.tile.k-voucher {
  background-color: var(--paper);
  background-image: repeating-linear-gradient(0deg, transparent 0 5px, rgba(0, 0, 0, 0.05) 5px 6px);
  color: var(--paper-ink);
  border-radius: 2px;
}
.tile.k-voucher .n { background: transparent; color: var(--paper-ink); font-size: clamp(9px, calc(var(--cell) * 0.28), 12px); }
.tile.k-money .n { background: rgba(0, 40, 0, 0.6); }
.tile.k-bag .n { background: rgba(0, 0, 0, 0.45); }

/* states */
.tile.dragging { opacity: 0.28; box-shadow: none; }
.tile.armed {
  transform: scale(1.06);
  z-index: 4;
  box-shadow: 0 0 0 3px var(--bkv), 0 6px 16px rgba(0, 0, 0, 0.5);
}

/* the drag ghost (fixed, follows the pointer; ui/invgrid.js sets left/top/width/height and --cellpx) */
.tile.ghost {
  --cell: var(--cellpx, 40px);
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  opacity: 0.92;
  transform: none;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55);
  transition: none;
  cursor: grabbing;
}
.tile.ghost.ok { box-shadow: 0 0 0 3px var(--good), 0 10px 22px rgba(0, 0, 0, 0.55); }
.tile.ghost.merge { box-shadow: 0 0 0 3px var(--bkv), 0 10px 22px rgba(0, 0, 0, 0.55); }
.tile.ghost.bad { box-shadow: 0 0 0 3px var(--bad), 0 10px 22px rgba(0, 0, 0, 0.55); opacity: 0.75; }

body.inv-dragging, body.inv-dragging * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }

.drag-hint {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--sb));
  transform: translateX(-50%);
  z-index: 2001;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(10, 12, 14, 0.9);
  border: 1px solid var(--line-2);
  color: var(--text-dim);
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
}
.drag-hint .btn { pointer-events: auto; min-height: var(--tap); }
.drag-hint:has(.btn) { padding: 4px; background: transparent; border: 0; }

/* ---------- an equipment slot (weapon 4x2, melee 4x1, bag 2x2) */
.inv-slot { position: relative; display: inline-flex; flex-direction: column; gap: 2px; }
.slot-label { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); line-height: 1.1; }
.slot-hint { font-size: 0.75rem; color: var(--text-faint); line-height: 1.1; }
.slot-hint:empty { display: none; }
.slot-box {
  position: relative;
  border: 2px dashed var(--line-2);
  border-radius: 6px;
  background: rgba(6, 8, 10, 0.5);
  transition: border-color 0.1s, background 0.1s;
}
.shape-wide .slot-box { width: calc(4 * var(--cell)); height: calc(2 * var(--cell)); }
.shape-bar .slot-box { width: calc(4 * var(--cell)); height: calc(1 * var(--cell)); }
.shape-sq .slot-box { width: calc(2 * var(--cell)); height: calc(2 * var(--cell)); }
.shape-tall .slot-box { width: calc(1 * var(--cell)); height: calc(3 * var(--cell)); }
.inv-slot.filled .slot-box { border-style: solid; border-color: transparent; background: transparent; }
.inv-slot.hover.ok .slot-box { border: 2px solid var(--good); background: rgba(113, 211, 107, 0.18); }
.inv-slot.hover.bad .slot-box { border: 2px solid var(--bad); background: rgba(255, 91, 77, 0.15); }
.tile.in-slot { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.tile.in-slot .g { font-size: calc(min(var(--tw), var(--th), 2) * var(--cell) * 0.5); }
.cell-probe { position: absolute; width: var(--cell); height: 0; visibility: hidden; pointer-events: none; }

/* ---------- a drop zone (sell, drop on the ground) */
.inv-zone { transition: background 0.1s, border-color 0.1s, color 0.1s; }
.inv-zone.hover.ok { border-color: var(--good) !important; background: rgba(113, 211, 107, 0.18) !important; color: var(--text) !important; }
.inv-zone.hover.bad { border-color: var(--bad) !important; background: rgba(255, 91, 77, 0.14) !important; }

/* ======================================================================================================
   The in-raid inventory (ui/raidinv.js). Desktop: a see-through panel on the right, the game runs beside it.
   Phones: full screen. Stacks above the touch controls (z 20 in #ui).
   ====================================================================================================== */
.raidinv {
  position: fixed;
  top: calc(12px + var(--st));
  right: calc(12px + var(--sr));
  z-index: 40;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 24px - var(--st) - var(--sb));
  max-height: calc(100dvh - 24px - var(--st) - var(--sb));
  max-width: calc(100vw - 24px);
  background: rgba(15, 17, 20, 0.86);
  background-image: var(--grain);
  border: 1px solid var(--line-2);
  border-top: 4px solid var(--bkv);
  border-radius: var(--r-l);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--text);
  pointer-events: auto;
  overflow: hidden;
  font-size: 15px;
}
.ri-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.ri-title { font-size: 1.45rem; color: var(--bkv); }
.ri-kg { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-dim); }
.ri-kg-bar { position: relative; flex: 1; max-width: 140px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.ri-kg-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--good); border-radius: 4px; transition: width 0.2s; }
.ri-kg-bar.over .ri-kg-fill { background: var(--warn); }
.ri-kg-t { white-space: nowrap; }
.ri-close { flex: none; }
.ri-mach {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 14px;
  background: rgba(255, 210, 0, 0.12);
  border-bottom: 1px solid rgba(255, 210, 0, 0.35);
  font-size: 0.9rem;
  flex: none;
}
.ri-mach > span { flex: 1; min-width: 12em; }
.ri-cols {
  display: flex;
  gap: 16px;
  padding: 10px 14px 8px;
  overflow: auto;
  overscroll-behavior: contain;
  min-height: 0;
  flex: 1;
}
.ri-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ri-kit { flex: none; }
.ri-slots {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  justify-content: start;
}
.ri-slots > .inv-slot:nth-child(1) { grid-column: 1; grid-row: 1; }
.ri-slots > .inv-slot:nth-child(2) { grid-column: 1; grid-row: 2; }
.ri-slots > .inv-slot:nth-child(3) { grid-column: 2; grid-row: 1 / span 2; }
.ri-block { position: relative; display: flex; flex-direction: column; gap: 3px; }
.ri-sub { display: flex; align-items: baseline; gap: 8px; }
.ri-sub-t { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.ri-sub small { color: var(--text-faint); font-size: 0.72rem; }
.ri-small { display: flex; gap: 12px; flex-wrap: wrap; }
.ri-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 4px 10px;
  border: 2px dashed var(--line-2);
  border-radius: var(--r);
  color: var(--text-faint);
  font-size: 0.85rem;
  text-align: center;
}
.ri-drop > span { font-size: 1.2rem; }
.ri-loot { flex: none; padding-right: 16px; border-right: 1px solid var(--line); }
.ri-loot-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ri-loot-t { font-size: 1.25rem; flex: 1; color: var(--sodium); }
.ri-loot-btns { display: flex; gap: 6px; }
.ri-lootgrid { min-height: calc(2 * var(--cell)); }
.ri-search {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(10, 12, 14, 0.78);
  border-radius: 4px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.ri-search-bar { width: 70%; max-width: 160px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.ri-search-bar > span { display: block; height: 100%; width: 0; background: var(--bkv); transition: width 0.1s linear; }
.ri-empty { color: var(--text-faint); margin: 0; font-size: 0.9rem; }
.ri-foot {
  flex: none;
  padding: 5px 14px 7px;
  border-top: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 0.78rem;
  line-height: 1.25;
}

/* phones in portrait and small windows: full screen, the container above the kit */
@media (max-width: 759px) {
  .raidinv {
    --cell: clamp(30px, calc((100vw - 40px) / 8), 46px);
    inset: 0;
    top: 0;
    right: 0;
    max-height: none;
    max-width: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding-top: var(--st);
    padding-bottom: var(--sb);
    background-color: rgba(13, 15, 17, 0.97);
  }
  .ri-cols { flex-direction: column; gap: 12px; padding: 10px 12px; }
  .ri-loot { padding-right: 0; border-right: 0; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .ri-kg-bar { max-width: 90px; }
  .ri-title { font-size: 1.3rem; }
}
/* phones in landscape: full screen, side by side, smaller cells */
@media (max-height: 520px) and (min-width: 560px) {
  .raidinv {
    --cell: clamp(24px, calc((100vh - 150px) / 7), 38px);
    inset: 0;
    top: 0;
    right: 0;
    max-height: none;
    max-width: none;
    border-radius: 0;
    padding-left: var(--sl);
    padding-right: var(--sr);
    background-color: rgba(13, 15, 17, 0.97);
  }
  .ri-cols { flex-direction: row; padding: 6px 12px; }
  .ri-head { padding-top: 2px; padding-bottom: 2px; }
  .ri-foot { display: none; }
}

/* the pushed cart: a second container column (ui/raidinv.js setCart) */
.ri-cart .ri-loot-t { color: var(--bkv); }
.ri-cart-n { color: var(--text-faint); font-family: var(--font-mono); font-size: 0.8rem; }
@media (max-width: 759px) {
  .raidinv.has-loot .ri-cart { padding-top: 0; }
}
