@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=Rye&display=swap');

/* user-select alone isn't enough on iOS Safari — without the -webkit-
   prefixed versions too, tapping directly on a glyph can still get grabbed
   by the text-selection/callout gesture recognizer and never reach the
   click handler, even though tapping the same element's non-text pixels
   works fine. touch-callout:none additionally kills the copy/lookup popup
   a press-and-hold on text can trigger. */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #0b0e17;
  font-family: 'Rajdhani', sans-serif;
  color: #f2ead9;
  touch-action: manipulation;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    /* distant gas giant, upper-right */
    radial-gradient(circle at 82% 6%,
      #ffdca0 0%, #f0b268 14%, #d98f4e 30%, #b8703c 46%, transparent 62%),
    radial-gradient(circle at 82% 6%, rgba(255,196,120,0.35), transparent 70%),
    radial-gradient(ellipse at 80% 0%, rgba(255,196,120,0.12), transparent 55%),
    /* starfield */
    radial-gradient(1.5px 1.5px at 10% 15%, #fff, transparent),
    radial-gradient(1px 1px at 25% 8%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60% 20%, #fff, transparent),
    radial-gradient(1px 1px at 38% 5%, #fff, transparent),
    radial-gradient(1px 1px at 45% 12%, #fff, transparent),
    radial-gradient(1px 1px at 5% 30%, #fff, transparent),
    radial-gradient(1px 1px at 92% 25%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 15% 22%, #fff, transparent),
    radial-gradient(1px 1px at 70% 10%, #fff, transparent),
    radial-gradient(1px 1px at 30% 18%, #fff, transparent),
    linear-gradient(180deg, #0b0e17 0%, #131a2b 40%, #1a1f2b 100%);
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(20,16,12,0.92), rgba(20,16,12,0.75));
  border-bottom: 2px solid #4a3826;
  z-index: 10;
  flex-wrap: wrap;
}

.hud-title {
  font-family: 'Rye', serif;
  font-size: 14px;
  color: #ffcf7a;
  text-shadow: 0 0 8px rgba(255,180,60,0.5);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

#resource-bar { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }

.resource-chip {
  display: flex; align-items: center; gap: 5px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 3px 9px;
  font-weight: 700;
  font-size: 14px;
}
.resource-chip .icon { font-size: 15px; }
.resource-chip.pulse { animation: pulse 0.35s ease; }
@keyframes pulse { 0%{ transform: scale(1);} 40%{ transform: scale(1.15);} 100%{ transform: scale(1);} }

#wave-indicator {
  font-size: 12px;
  background: rgba(255,80,80,0.15);
  border: 1px solid rgba(255,120,120,0.4);
  border-radius: 8px;
  padding: 3px 8px;
  white-space: nowrap;
  color: #ffb0b0;
  font-weight: 700;
}

/* ---------- Stage / canvas ---------- */
#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px;
}

#game-canvas {
  background: #5b6472;
  border: 3px solid #2c333c90;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

#toast-anchor { position: absolute; inset: 0; pointer-events: none; }

/* ---------- Building panel ---------- */
/* Fixed to the stage's top-right corner, out of the way of both the map
   and the build bar, so it never overlaps anything else that's clickable. */
#building-panel, #placement-bar {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(15,12,10,0.94);
  border: 2px solid #6b4e2e;
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 20;
  min-width: 220px;
  max-width: min(260px, calc(100% - 20px));
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
#placement-bar { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; font-size: 13px; }

.panel-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 700; }
.panel-header span:nth-child(1) { font-size: 20px; }
#bp-name { flex: 1; color: #ffd98a; }

.icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #f2ead9;
  border-radius: 6px;
  width: 26px; height: 26px;
  font-size: 13px;
  cursor: pointer;
}

/* Caption text lives OUTSIDE the button (see .btn-caption below) so the
   button itself is a big, blank tap target — text baked into a clickable
   element is what made this one unreliable to tap in the first place. */
.action-btn {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(180deg, #4fe0c0, #2bb89a);
  color: #06231c;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.action-btn.secondary {
  width: auto;
  min-height: 0;
  background: linear-gradient(180deg, #6b5a4a, #4a3c2f);
  color: #f2ead9;
  padding: 7px 12px;
}

.btn-caption {
  font-size: 12px;
  font-weight: 700;
  color: #d8cfc0;
  text-align: center;
  line-height: 1.35;
  margin-bottom: 6px;
}
.btn-icon { font-size: 24px; line-height: 1; }

/* ---------- Build bar ---------- */
#build-bar {
  display: flex;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(15,12,10,0.96), rgba(20,16,12,0.85));
  border-top: 2px solid #4a3826;
  overflow-x: auto;
  z-index: 15;
}

/* Each build option is a label above a big blank icon button above its
   cost — the button itself carries no text, only the icon, so a tap never
   has to land on a glyph to register. */
.build-item {
  flex: 0 0 auto;
  width: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.build-item .bb-label { font-size: 9.5px; font-weight: 700; text-align: center; letter-spacing: 0.2px; color: #f2ead9; }
.build-item .bb-cost { font-size: 9px; color: #bcd8ff; opacity: 0.85; text-align: center; }

.build-btn {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.16);
  border-radius: 10px;
  cursor: pointer;
}
.build-btn .bb-icon { font-size: 22px; line-height: 1; }
.build-btn:disabled { opacity: 0.4; }
.build-btn.active { border-color: #5fe0c0; box-shadow: 0 0 0 2px rgba(95,224,192,0.35); }

/* ---------- Game over ---------- */
#game-over {
  position: absolute; inset: 0;
  background: rgba(5,4,3,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
#game-over .panel {
  background: rgba(20,16,12,0.96);
  border: 2px solid #6b4e2e;
  border-radius: 12px;
  padding: 26px 30px;
  text-align: center;
  max-width: 320px;
}
#game-over h2 { font-family: 'Rye', serif; color: #ff8a6b; margin: 0 0 8px; font-size: 20px; }
#game-over p { margin: 0 0 16px; color: #d8cfc0; }

.hidden { display: none !important; }

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .hud-title { font-size: 11px; }
  .resource-chip { font-size: 12px; padding: 3px 7px; }
  .build-item { width: 58px; }
  .build-btn .bb-icon { font-size: 19px; }
  #building-panel, #placement-bar { min-width: 150px; top: 6px; right: 6px; }
}
