/* ultra_inventory.css — Ultrastation W2: visual inventory panel.
 *
 * Read-only icon grid with tabs (All / Weapons / Armor / Rings / Trinkets /
 * Belts / Other), weight/encumbrance bar, and equipped-item badge.
 * Self-wires via Viewport.onViewerData — no edits to viewport.js / app.js.
 *
 * Visible only when the per-turn payload carries an `ultra_panel` key
 * (i.e. GHELMYON_FEATURE_ULTRASTATION is set server-side). When the
 * key is absent the panel stays hidden; byte-identical to demo-safe.
 *
 * IT310: the panel can also be dragged into a floating position via the
 * header's move grip (`.floating` class, `position: fixed`) and re-docked
 * with a double-click; it stays minimizable via the existing collapse tab.
 *
 * Theme: inherits --bg / --bg2 / --fg / --border / --accent /
 *   --fg-dim / --green / --yellow from style.css :root.
 */

/* =========================================================================
   Panel container
   ========================================================================= */

#ultra-inventory-panel {
  display: none;           /* hidden by default; JS sets display:flex when data arrives */
  flex-direction: column;
  width: 100%;
  max-width: 320px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 12px;
  color: var(--fg);
  user-select: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

#ultra-inventory-panel.visible {
  display: flex;
}

/* IT310: dragged off its docked spot in #right-panel into a floating window.
 * Width/left/top are set inline by ultra_inventory.js at drag time (and
 * restored from localStorage on load) so the panel keeps its current size
 * instead of stretching to `max-width` against the viewport. z-index sits
 * above the game pane/FX layers (<=70) but well below tooltips/context
 * menus/modals (9000+) so hover info and dialogs still win. */
#ultra-inventory-panel.floating {
  position: fixed;
  z-index: 80;
  margin: 0;
  max-width: none;
}

/* =========================================================================
   Header + title
   ========================================================================= */

#ultra-inventory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 4px;
  background: var(--bg3, #0d1525);
  border-bottom: 1px solid var(--border);
}

/* IT310: move grip — drag anywhere on it to reposition the panel. */
#ultra-inventory-move-grip {
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: -2px;
  padding: 0 6px 0 0;
  cursor: move;
  touch-action: none;   /* let the pointer drag own the move gesture */
  user-select: none;
  transition: color 0.15s;
}

#ultra-inventory-move-grip:hover {
  color: var(--fg);
}

#ultra-inventory-title {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

#ultra-inventory-weight-label {
  font-size: 10px;
  color: var(--fg-dim);
}

/* Right-side header cluster: weight readout + open/close toggle. */
#ultra-inventory-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The open/close "tab" button. */
.ultra-inventory-collapse {
  background: rgba(0, 0, 0, 0.35);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 2px 7px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.ultra-inventory-collapse:hover {
  color: var(--fg);
  border-color: var(--fg-dim);
  background: rgba(40, 40, 60, 0.8);
}

/* Collapsed: hide the body, leaving just the header bar as the reopen tab. */
#ultra-inventory-panel.collapsed > #ultra-encumbrance-track,
#ultra-inventory-panel.collapsed > #ultra-inventory-tabs,
#ultra-inventory-panel.collapsed > #ultra-inventory-grid,
#ultra-inventory-panel.collapsed > #ultra-inventory-drag-handle {
  display: none;
}
#ultra-inventory-panel.collapsed > #ultra-inventory-header {
  border-bottom: none;
}

/* =========================================================================
   Encumbrance bar
   ========================================================================= */

#ultra-encumbrance-track {
  margin: 0 8px 0;
  height: 4px;
  background: var(--bg3, #0d1525);
  border-radius: 2px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  /* use padding-bottom as gap between bar and tabs */
  box-sizing: content-box;
}

#ultra-encumbrance-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

#ultra-encumbrance-fill.enc-heavy {
  background: var(--yellow);
}

#ultra-encumbrance-fill.enc-over {
  background: var(--accent);
}

/* =========================================================================
   Tab bar
   ========================================================================= */

#ultra-inventory-tabs {
  display: flex;
  flex-wrap: wrap;   /* IT310: 7 tabs (incl. Rings/Trinkets/Belts) wrap onto 2 rows */
  gap: 1px;
  padding: 4px 8px 0;
  background: var(--bg3, #0d1525);
  border-bottom: 1px solid var(--border);
}

.ultra-tab {
  flex: 1 1 30%;
  min-width: 56px;
  padding: 4px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fg-dim);
  font-family: inherit;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: center;
  transition: color 0.15s, border-color 0.15s;
  outline: none;
  white-space: nowrap;
}

.ultra-tab:hover {
  color: var(--fg);
}

.ultra-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* =========================================================================
   Item grid
   ========================================================================= */

#ultra-inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 4px;
  padding: 8px;
  /* #42: drag the bottom-right corner to make the item area bigger/smaller.
     `resize` needs a non-visible overflow (auto, below). Height persists via
     ultra_inventory.js. */
  overflow: auto;
  resize: vertical;
  min-height: 96px;
  max-height: 70vh;
  height: 260px;
  background: var(--bg2);
  /* Custom scrollbar — thin, themed */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#ultra-inventory-grid::-webkit-scrollbar { width: 4px; }
#ultra-inventory-grid::-webkit-scrollbar-track { background: transparent; }
#ultra-inventory-grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* =========================================================================
   Drag handle (pull up or down to resize the item area)
   ========================================================================= */

#ultra-inventory-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 12px;
  background: var(--bg3, #0d1525);
  border-top: 1px solid var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
  touch-action: none;   /* let the pointer drag own the vertical gesture */
}

#ultra-inventory-drag-handle:hover {
  background: var(--accent2, #0f3460);
}

.ultra-inventory-grip {
  width: 28px;
  height: 3px;
  border-radius: 2px;
  background: var(--fg-dim);
  opacity: 0.6;
}

#ultra-inventory-drag-handle:hover .ultra-inventory-grip {
  opacity: 1;
}

/* While dragging the handle, stop text selection and keep the resize cursor. */
body.ultra-inv-dragging {
  cursor: ns-resize;
  user-select: none;
}

/* IT310: while dragging the panel by its move grip, stop text selection
 * and keep the move cursor everywhere (not just over the grip). */
body.ultra-inv-moving {
  cursor: move;
  user-select: none;
}

/* Empty state */
#ultra-inventory-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--fg-dim);
  font-size: 11px;
  padding: 20px 0;
}

/* =========================================================================
   Item cell
   ========================================================================= */

.ultra-item-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg3, #0d1525);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 3px 3px;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
}

.ultra-item-cell:hover {
  border-color: var(--fg-dim);
  background: var(--accent2, #0f3460);
}

/* Equipped cells have an accent border */
.ultra-item-cell.equipped {
  border-color: var(--accent);
}

.ultra-item-cell.equipped:hover {
  border-color: var(--yellow);
}

/* =========================================================================
   Item icon / glyph
   ========================================================================= */

.ultra-item-icon-wrap {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 3px;
  background: var(--bg2);
  flex-shrink: 0;
}

.ultra-item-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;   /* crisp pixel art icons */
  border-radius: 2px;
}

/* Fallback glyph — shown when icon == "" */
.ultra-item-glyph {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--fg-dim);
  background: var(--bg3, #0d1525);
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0;
}

/* =========================================================================
   Item name + weight hint
   ========================================================================= */

.ultra-item-name {
  width: 100%;
  margin-top: 3px;
  font-size: 9px;
  color: var(--fg);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.ultra-item-hint {
  font-size: 8px;
  color: var(--fg-dim);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

/* =========================================================================
   Equipped badge (small corner mark)
   ========================================================================= */

.ultra-equipped-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  display: none;   /* shown only on .equipped cells */
  box-shadow: 0 0 4px rgba(233, 69, 96, 0.6);
}

.ultra-item-cell.equipped .ultra-equipped-badge {
  display: block;
}

/* Stack-count badge: bottom-right "xN" when more than one is held. */
.ultra-item-count {
  position: absolute;
  bottom: 2px;
  right: 3px;
  min-width: 14px;
  padding: 0 3px;
  font-size: 11px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 7px;
  pointer-events: none;
}

/* =========================================================================
   Accessibility
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  .ultra-item-cell            { transition: none; }
  #ultra-encumbrance-fill     { transition: none; }
  .ultra-tab                  { transition: none; }
  .ultra-inventory-collapse   { transition: none; }
  #ultra-inventory-move-grip  { transition: none; }
}

/* =========================================================================
   Responsive: narrow sidebar → tighter grid
   ========================================================================= */

@media (max-width: 260px) {
  #ultra-inventory-grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  }
  .ultra-item-icon-wrap { width: 30px; height: 30px; }
  .ultra-item-glyph     { font-size: 15px; }
}
