#itemGrid {
  display: none;
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 24px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  padding: 12px;
  border-radius: 0 0 12px 12px;
  animation: slideDown 0.4s ease forwards;
  max-width: calc(100vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0) - 24px);
  box-sizing: border-box;
  z-index: 10;
  width: 80%;
  aspect-ratio: 763 / 405;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
}

.item-slot {
  background: #bcbcbc00;
  border-radius: 12px;
  display: flex;
  aspect-ratio: 1 / 1;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  border: none;
}

.item-slot.empty {
  background: rgba(255,255,255,0.04);
  border: 2px dotted #bcbcbc;
  border-radius: 12px;
  position: relative;
}

.item-slot.empty span {
  font-size: 32px;
  color: #bcbcbc;
  font-weight: bold;
  outline: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.item-slot {
  animation: fadeInScale 0.4s ease forwards;
  opacity: 0; /* initial state for animation */
}


.item-slot:hover {
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.25);
}

.item-slot.selected {
  outline: 2px solid #fffffffa;
  box-shadow: 0 0 8px rgba(106, 195, 255, 0.6);
  transform: scale(1.1);
}




.item-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
 }


.click-area {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 20%;
  transform: translateX(-50%);
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
}

.suitcase-ping {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(106,195,255,0.18);
  border: 4px solid #8dd2ff;
  animation: pingAnim 1.5s ease-out infinite;
  z-index: 1;
}

.suitcase-label {
  position: absolute;
  bottom: 50%;
  left: 66%;
  font-family: 'Ubuntu', sans-serif;
  font-size: 7px;
  font-weight: bold;
  color: #fff;
  background: rgba(0, 0, 0, 0);
  padding: 3px 8px;
  border-radius: 6px;
  box-shadow: 0 0 6px #6ac3ff44;
  letter-spacing: 0.5px;
  z-index: 2;
  pointer-events: none;
  animation: labelPulse 1.5s ease-out infinite;
}


@keyframes pingAnim {
  0% { transform: scale(1); opacity: 1; }
  80% { transform: scale(1.4); opacity: 0.66; }
  100% { transform: scale(1.7); opacity: 0; }
}


@keyframes labelPulse {
  0%   { opacity: 1; }
  80%  { opacity: 0.66; }
  100% { opacity: 0; }
}


.click-area.fade-out {
  animation: fadeAway 0.5s forwards;
}

@keyframes fadeAway {
  to {
    opacity: 0;
    transform: scale(1.3) translateX(-50%);
  }
}

@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}



@keyframes slideInOverlay {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Overlay content is a full clickable link; layout is sized for portrait. Positioning is set by JS so the overlay sits under the grid. */
#itemOverlay .overlay-content.full-link {
  position: relative;
  right: 25%;
  top: auto;
  transform: none;
  width: min(92vw, 340px);
  max-width: 340px;
  min-width: 180px;
  box-sizing: border-box;
  
  display: flex;
  flex-direction: column;
  align-items: center;
  
  overflow: hidden;
  background: none;
  border-radius: 16px;
  box-shadow: none;
  text-decoration: none;
  z-index: 30;
  border: none;
  transition: box-shadow 0.2s;
}

#itemOverlay img {
  position: relative;
  width: min(70vw, 180px);
  max-width: 180px;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 2;
}

#itemOverlay .item-info {
  position: relative;
  width: 100%;
  color: #fff;
  font-size: clamp(15px, 3vw, 22px);
  line-height: 1.15;
  z-index: 2;
  text-align: center;
  margin-top: 0;
  padding: 0 2px;
  box-sizing: border-box;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  font-weight: 700;
}

#itemOverlay .item-name {
  display: block;
  width: 100%;
  color: #fff;
  cursor: pointer;
  padding: 4px 0 0 0;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

#itemOverlay .overlay-content.full-link:active .item-name,
#itemOverlay .overlay-content.full-link:hover .item-name {
  background: rgba(255,255,255,0.08);
  color: #cfeeff;
}

/* Keep overlay background removed but ensure the box contains its children cleanly.
   Add a subtle outline so the box reads as a contained element without a solid fill. */
#itemOverlay {
  display: none;
  position: absolute;
  top: auto; /* positioned by JS when shown so it sits under the grid */
  left: auto;
  transform: none;
  box-sizing: border-box;
  z-index: 20;
  padding: 0;
  background: transparent;
  border-radius: 10px;
  max-width: 92vw;
  max-height: 72vh;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
  border: none;
}

/* Vertical layout: image on top, text below. Remove rotations. */
#itemOverlay img {
  position: relative;
  width: min(72vw, 220px);
  max-width: 220px;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.28);
  z-index: 3;
}

#itemOverlay .item-info {
  position: relative;
  width: 100%;
  color: #fff;
  font-size: 16px;
  line-height: 1.1;
  z-index: 2;
  text-align: center;
  margin-top: -8px; /* slight overlap so image and text feel connected */
  padding: 6px 4px 0 4px;
  box-sizing: border-box;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* Make the name clearly clickable and add subtle pulse animation */
#itemOverlay .item-link {
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  display: inline-block;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  transition: transform 160ms ease, box-shadow 160ms ease, color 160ms ease;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  animation: pulseName 2.8s ease-in-out infinite;
}

#itemOverlay .item-link:hover,
#itemOverlay .item-link:focus {
  transform: translateY(-2px) scale(1.02);
  text-decoration: underline;
  color: #cfeeff;
}

@keyframes pulseName {
  0% { transform: scale(1); }
  50% { transform: scale(1.01); }
  100% { transform: scale(1); }
}

#itemGrid { z-index: 2; }
#itemOverlay { z-index: 2; }

#closeSuitcaseBtn {
  position: absolute;
  left: 25%;
  bottom: 30%;
  width: 22px;
  height: 22px;
  background: #222;
  color: #fff;
  border: none;
  border-radius: 50%;
  box-shadow: 0 2px 8px #0005;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#closeSuitcaseBtn.show {
  opacity: 1;
  pointer-events: auto;
}

#closeSuitcaseBtn:hover {
  background: #333;
  color: #ff6a6a;
}
