/* ── Inventory Hotbar ── */
#inventory-hotbar {
  position: fixed;
  bottom: 80px; /* Distinct row above emotes */
  left: 50%;
  transform: translateX(-50%);
  z-index: 305;
  display: none; /* Only show when body.playing */
  flex-direction: column-reverse; /* Keep toggle below the item panel */
  align-items: center;
  gap: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
  width: 100%;
  max-width: 380px;
  padding: 0 10px;
  box-sizing: border-box;
}

body.playing #inventory-hotbar {
  display: flex;
}

body.playing.chatting #inventory-hotbar {
  display: none;
}

/* On touch devices, move it to top to avoid joystick and right action controls completely */
body.touch-device #inventory-hotbar {
  bottom: auto;
  top: 175px;
}

#inventory-toggle-btn {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 8px 16px;
  color: white;
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

#inventory-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: scale(1.05);
}

.hotbar-label {
  font-size: 14px;
  font-weight: 500;
}

#inventory-content {
  pointer-events: auto;
  display: none;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  width: 100%;
  box-sizing: border-box;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

#inventory-hotbar.open #inventory-content {
  display: flex;
}

.hotbar-categories {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.hotbar-categories::-webkit-scrollbar { display: none; }

.hotbar-cat-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.1s;
}

.hotbar-cat-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.hotbar-cat-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.hotbar-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}

.hotbar-items::-webkit-scrollbar { width: 4px; }
.hotbar-items::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 2px; }

.hotbar-item {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  position: relative;
  transition: all 0.1s;
}

.hotbar-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.hotbar-item.selected {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.hotbar-item.equipped {
  border-color: #2ecc71;
}

.hotbar-item-count {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  font-weight: bold;
  color: white;
  text-shadow: 0 1px 2px black, 0 -1px 2px black;
  pointer-events: none;
}

.hotbar-item-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #2ecc71;
  color: white;
  font-size: 10px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.hotbar-msg {
  width: 100%;
  text-align: center;
  padding: 20px 0;
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
}
.hotbar-msg.error {
  color: #e74c3c;
}

.hotbar-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #182331;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 12px;
  width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 250;
  animation: hotbarPop 0.15s ease-out;
}

/* Touch inventory opens near the top; its actions must open downwards. */
body.touch-device .hotbar-popover {
  top: calc(100% + 52px);
  bottom: auto;
  max-width: calc(100vw - 48px);
}

@keyframes hotbarPop {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

.hotbar-popover::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: #182331;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.hotbar-popover-title {
  color: white;
  font-weight: bold;
  font-size: 14px;
  margin-right: 16px;
}

.hotbar-popover-desc {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  line-height: 1.3;
}

.hotbar-popover-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.hotbar-action-btn {
  flex: 1;
  background: #3498db;
  color: white;
  border: none;
  padding: 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
}

.hotbar-action-btn:hover {
  background: #2980b9;
}

.hotbar-popover-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.hotbar-popover-close:hover {
  color: white;
}