* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: #0a0d12;
  color: #e8ecf2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ---- app frame: 16:9, scaled to fit the window ---- */
#app {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

/* ---- top HUD bar ---- */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7.8%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(#141926f5, #141926d9);
  border-bottom: 1px solid #2a3348;
  font-size: clamp(11px, 1.5vh, 16px);
  z-index: 5;
}

.stat {
  background: #1c2333;
  border: 1px solid #2e3a52;
  border-radius: 6px;
  padding: 3px 10px;
  white-space: nowrap;
}

.stat.flash {
  animation: goldflash 0.3s;
}

@keyframes goldflash {
  0%, 100% { background: #1c2333; border-color: #2e3a52; }
  50%      { background: #5a3a2a; border-color: #e05555; }
}

#startWaveBtn {
  margin-left: auto;
  font: inherit;
  font-weight: 600;
  background: #2f6b3a;
  color: #eaf5ec;
  border: 1px solid #4a9b58;
  border-radius: 8px;
  padding: 4px 14px;
  cursor: pointer;
}

#startWaveBtn:hover {
  background: #3a8047;
}

/* ---- bottom tower bar ---- */
#towerbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 12.2%;
  display: flex;
  gap: 8px;
  align-items: stretch;
  padding: 6px 10px;
  background: linear-gradient(#141926d9, #141926f5);
  border-top: 1px solid #2a3348;
  z-index: 5;
}

.card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 8px;
  background: #1c2333;
  border: 2px solid #2e3a52;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  font-size: clamp(9px, 1.35vh, 14px);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.1s ease, background 0.1s ease;
}

.card:hover {
  transform: translateY(-2px);
}

.card.selected {
  border-color: #f5c542;
  background: #2a3348;
}

.card.unaffordable {
  opacity: 0.45;
  cursor: not-allowed;
}

.card.unaffordable:hover {
  transform: none;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.1em;
  width: 100%;
}

.card-key {
  background: #2e3a52;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.85em;
}

.card-name {
  font-weight: 700;
}

.card-cost {
  margin-left: auto;
  color: #f5c542;
}

.card-stats {
  opacity: 0.85;
  font-size: 0.95em;
}

.card-desc {
  opacity: 0.6;
  font-size: 0.9em;
}

/* ---- sell panel ---- */
#sellPanel {
  position: absolute;
  top: calc(7.8% + 8px);
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1c2333f0;
  border: 1px solid #2e3a52;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: clamp(11px, 1.4vh, 14px);
  z-index: 6;
}

#sellLabel {
  font-weight: 600;
}

#sellPanel button {
  font: inherit;
  border: 1px solid #2e3a52;
  border-radius: 6px;
  background: #2a3348;
  color: inherit;
  padding: 3px 8px;
  cursor: pointer;
}

#sellBtn {
  background: #4a2a2a;
  border-color: #7a4444;
}

#sellBtn:hover {
  background: #5d3333;
}

/* ---- overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.78);
  backdrop-filter: blur(2px);
  z-index: 10;
}

.overlay-card {
  background: #141926;
  border: 1px solid #2a3348;
  border-radius: 14px;
  padding: 28px 36px;
  max-width: 540px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.overlay-card h1 {
  font-size: clamp(22px, 4.5vh, 42px);
  margin-bottom: 10px;
}

.overlay-card p {
  opacity: 0.85;
  margin-bottom: 8px;
  line-height: 1.45;
}

.overlay-card ul {
  text-align: left;
  opacity: 0.75;
  margin: 12px 0 18px;
  padding-left: 18px;
  line-height: 1.6;
  font-size: 0.92em;
}

.overlay-card button {
  margin-top: 10px;
  font: inherit;
  font-size: clamp(14px, 2vh, 18px);
  font-weight: 600;
  background: #f5c542;
  color: #241c07;
  border: none;
  border-radius: 8px;
  padding: 10px 26px;
  cursor: pointer;
}

.overlay-card button:hover {
  background: #ffd75e;
}

button:focus-visible {
  outline: 2px solid #6fb7e0;
  outline-offset: 2px;
}
