#tower-container {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: clamp(2px, 0.8vh, 8px);
  /* vertical padding keeps the card shape; horizontal is tight to avoid
     overflowing the tower-inner-container when the sidebar is present */
  padding: clamp(3px, 1.5vh, 14px) clamp(2px, 0.6vw, 6px);
  background-color: #1a1a1b;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  width: fit-content;
  max-height: 90%;
  justify-content: center;
  align-items: center;
  transition: opacity 0.35s ease;
}

/* During a difficulty switch the old tower is cleared before the new one
   is built. Do not render its empty dark card during that handoff. */
#tower-container:empty {
  display: none;
}

.tower-box {
  /* account for 200px sidebar — use content area (100vw - 200px) as reference */
  flex: 0 0 auto;
  width: clamp(22px, min(4.6vh, calc((100vw - 200px) * 0.042)), 56px);
  height: clamp(22px, min(4.6vh, calc((100vw - 200px) * 0.042)), 56px);
  border: 2px solid #88888b;
  background-color: transparent;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(0.7rem, min(2.7vh, 2vw), 1.8rem);
  font-weight: bold;
  border-radius: 4px;
  pointer-events: none;
  transition: border-color 0.2s ease;
}

.tower-pop-in {
  animation: towerPopIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes towerPopIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  60% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.tower-shake {
  animation: towerShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes towerShake {

  0%,
  100% {
    transform: translateX(0);
  }

  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-4px);
  }

  20%,
  40%,
  60%,
  80% {
    transform: translateX(4px);
  }
}

@media (max-width: 768px) {
  #tower-container {
    gap: 2px;
    padding: 6px 5px;
    width: 100%;
    max-width: none;
    max-height: none;
  }

  .tower-box {
    width: 26px;
    height: 26px;
    border-width: 1.5px;
    font-size: 0.9rem;
  }

}

/* Ultra-narrow screens: shrink tower content to fit the narrower column. */
@media (max-width: 430px) {
  #tower-container {
    padding: 6px 2px;
  }

  .tower-box {
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
  }

}
