* { box-sizing: border-box; }

:root {
  --bg: #14171c;
  --panel: #1d2128;
  --panel-2: #262b34;
  --border: #323844;
  --text: #e8e6e3;
  --muted: #9aa3ae;
  --gold: #ffd54f;
  --red: #ef5350;
  --accent: #4caf7a;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}

[hidden] { display: none !important; }

#app { max-width: 1500px; margin: 0 auto; padding: 12px 16px; }

/* ---------- Main menu ---------- */
#menu {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(76, 175, 122, 0.18), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(255, 120, 40, 0.10), transparent 60%),
    var(--bg);
  padding: 32px 16px;
}
.menu-inner { width: 100%; max-width: 1180px; text-align: center; }
.logo {
  font-size: clamp(36px, 6vw, 64px); margin: 0; letter-spacing: 1px;
  background: linear-gradient(180deg, #fff3c4, #ffd54f 55%, #d9822b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}
.tagline { color: var(--muted); margin: 8px 0 28px; font-size: 16px; }

#mapGrid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  text-align: left;
}
.map-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 0; overflow: hidden; border-radius: 12px; text-align: left;
  background: var(--panel); border: 1px solid var(--border);
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.map-card:hover:not(:disabled) {
  transform: translateY(-3px); border-color: #5aa9d6; background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.map-card canvas {
  width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover;
  display: block; border-bottom: 1px solid var(--border);
}
.map-card .body { padding: 6px 14px 14px; }
.map-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.map-card .title { font-size: 18px; font-weight: 700; }
.map-card .num { color: var(--muted); font-weight: 600; margin-right: 6px; }
.map-card .diff { color: #ef7350; letter-spacing: 2px; font-size: 13px; white-space: nowrap; }
.map-card .diff .off { color: #4a505c; }
.map-card .desc { color: var(--muted); font-size: 13px; margin: 4px 0 8px; font-weight: 400; }
.map-card .meta { color: var(--muted); font-size: 12px; font-weight: 500; }
.map-card .best { font-size: 13px; }
.map-card .stars { color: var(--gold); letter-spacing: 2px; font-size: 16px; }
.map-card .stars .off { color: #4a505c; }
.map-card:disabled { opacity: 1; }
.map-card .lock {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  background: rgba(14, 16, 20, 0.72); backdrop-filter: grayscale(1) blur(1px);
  color: var(--muted); font-size: 14px;
}
.map-card .lock b { font-size: 30px; color: var(--text); }
.menu-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 22px; color: var(--muted); font-size: 13px;
}
.menu-foot button { font-size: 12px; padding: 5px 10px; }

.stat.mapname { color: #9fd3ff; font-size: 14px; }

#topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 10px;
}
#topbar h1 { font-size: 20px; margin: 0 8px 0 0; letter-spacing: 0.5px; }
.stat {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 8px; font-weight: 700; font-size: 16px;
  font-variant-numeric: tabular-nums; min-width: 70px;
}
.stat.gold .ico { color: var(--gold); }
.stat.lives .ico { color: var(--red); }
.stat .lbl { color: var(--muted); font-weight: 500; font-size: 13px; }
.spacer { flex: 1; }

button {
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  transition: background 0.12s, transform 0.05s;
}
button:hover:not(:disabled) { background: #313744; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: #2e7d50; border-color: #3c9a64; }
button.primary:hover:not(:disabled) { background: #36915d; }
button.danger { background: #7a2e2e; border-color: #9a3c3c; }
button.danger:hover:not(:disabled) { background: #8f3636; }
button.on { background: #2e5d7d; border-color: #3c7a9a; }

main { display: flex; gap: 14px; align-items: flex-start; }

#stage { position: relative; flex: 1; min-width: 0; }
#game {
  display: block; width: 100%; height: auto;
  border-radius: 10px; border: 1px solid var(--border);
  background: #2d4a26; cursor: crosshair;
}

#overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 16, 0.6); backdrop-filter: blur(3px);
  border-radius: 10px;
}
#overlay.hidden { display: none; }
#overlay .panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 26px 32px; max-width: 440px; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
#overlay h2 { margin: 0 0 10px; font-size: 30px; }
#overlayText { color: var(--muted); margin-bottom: 18px; }
#overlayText p { margin: 6px 0; }
#overlayButtons { display: flex; gap: 10px; justify-content: center; }
#overlayButtons button { padding: 10px 22px; font-size: 16px; }

#side {
  width: 290px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
#side h3 { margin: 0 0 8px; font-size: 15px; }

#shop { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 12px; }
.shop-btn {
  display: flex; align-items: center; gap: 6px; text-align: left;
  padding: 3px 6px; min-width: 0;
}
.shop-btn canvas { width: 36px; height: 36px; flex-shrink: 0; }
.shop-btn .txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.shop-btn .name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-btn .key { color: var(--muted); font-size: 10px; font-weight: 500; }
.shop-btn .cost { color: var(--gold); font-variant-numeric: tabular-nums; font-size: 12px; }
.shop-btn.active { background: #2e5d7d; border-color: #5aa9d6; }
.shop-btn.cant .cost { color: var(--red); }
.shop-btn.cant { opacity: 0.6; }
.shop-btn.locked { opacity: 0.45; cursor: not-allowed; }
.shop-btn.locked canvas { filter: grayscale(1) brightness(0.6); }
.shop-btn.locked .cost { color: var(--muted); }

#info {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; margin-bottom: 12px; min-height: 120px;
}
#infoSub { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
#infoStats { list-style: none; padding: 0; margin: 0 0 8px; }
#infoStats li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; font-size: 13px; }
#infoStats li span { color: var(--muted); }
#infoStats li.sep { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
#infoStats li.headline { font-size: 15px; padding: 3px 0; }
#infoStats li.headline span { color: var(--text); }
#infoStats li.headline b { color: var(--gold); }
#infoStats li.headline small { color: var(--muted); font-weight: 500; font-size: 11px; }
#infoStats li.headline.sub { font-size: 13px; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 4px; }
#infoStats li.headline.sub b { color: var(--text); }
#infoStats em { color: #7fd99a; font-style: normal; }
#infoStats .boost { color: #7fd99a; }
#infoActions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#infoActions #btnTarget { grid-column: 1 / -1; }
#infoActions.hidden, #specChoice.hidden { display: none; }
#infoActions.no-target #btnTarget { display: none; }
#infoActions #btnSell { font-size: 12px; }

#specChoice { display: grid; gap: 6px; margin-top: 8px; }
.spec-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
button.spec { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 7px 10px; }
button.spec span { font-weight: 400; font-size: 12px; color: var(--muted); }
button.spec-a { border-color: #3c8fb3; background: #1f3a4a; }
button.spec-a:hover:not(:disabled) { background: #26485c; }
button.spec-b { border-color: #b3603c; background: #4a2a1f; }
button.spec-b:hover:not(:disabled) { background: #5c3326; }
button.spec-c { border-color: #9a5cb3; background: #3a2445; }
button.spec-c:hover:not(:disabled) { background: #4a2e58; }

#dmgPanel { margin-bottom: 12px; }
#dmgPanel h3 { display: flex; justify-content: space-between; align-items: baseline; }
.dm-total { font-size: 12px; color: var(--muted); font-weight: 500; }
#dmgMeter { max-height: 260px; overflow-y: auto; }
.dm-row { display: grid; grid-template-columns: 96px 1fr 46px; align-items: center; gap: 6px; font-size: 12px; padding: 2px 4px; border-radius: 4px; }
#dmgMeter .dm-row { cursor: pointer; }
#dmgMeter .dm-row:hover { background: #262b34; }
#dmgMeter .dm-row.sel { background: #2e5d7d; }
#dmgMeter .dm-row.sel .dm-name { color: var(--text); }
.dm-name small { color: #6d7581; }
.dm-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-bar { height: 8px; background: #1a1d23; border-radius: 4px; overflow: hidden; }
.dm-bar i { display: block; height: 100%; border-radius: 4px; }
.dm-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dm-gold { grid-column: 2 / -1; color: var(--gold); font-weight: 600; }
.dm-empty { color: var(--muted); font-size: 12px; }
.summary { text-align: left; margin: 12px 0 4px; }
.summary h4 { margin: 0 0 6px; font-size: 13px; color: var(--text); }
.summary .mvp { font-size: 13px; margin-top: 8px; color: var(--text); }
#overlay .panel { max-width: 480px; }

#nextWave { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
#nextWave b { color: var(--text); }

#help { font-size: 13px; color: var(--muted); }
#help summary { cursor: pointer; color: var(--text); font-weight: 600; }
#help ul { padding-left: 18px; margin: 6px 0 0; }
#help b { color: var(--text); }

/* Menu: tower roster + rewards */
#towerRoster { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: -10px 0 22px; }
.roster-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 64px;
  font-size: 11px; color: var(--muted);
}
.roster-item canvas { width: 40px; height: 40px; }
.roster-item.locked canvas { filter: grayscale(1) brightness(0.45); }
.roster-item.locked { opacity: 0.6; }
.map-card .reward { font-size: 12px; margin-top: 6px; color: #9fd3ff; }
.map-card .reward.done { color: #7fd99a; }

@media (max-width: 920px) {
  main { flex-direction: column; }
  #side { width: 100%; }
  #shop { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}