:root {
  --bg: #10131a;
  --bg-panel: #191d27;
  --bg-panel-2: #1f2430;
  --border: #333a4a;
  --text: #e8e6df;
  --text-dim: #9aa0b0;
  --gold: #e0b23d;
  --danger: #d1483d;
  --good: #5fb64c;
  --accent: #4c86c9;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

#app { width: 100vw; height: 100vh; position: relative; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- Screens */

.screen {
  width: 100%; height: 100%;
  display: flex;
}

#screen-menu, #screen-round-clear, #screen-game-over, #screen-victory {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1b2130 0%, #0b0d12 100%);
}

.menu-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 44px;
  max-width: 520px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.menu-card h1 {
  font-size: 2.4em;
  margin: 0 0 4px;
  color: var(--gold);
  letter-spacing: 0.5px;
}

.menu-card h2 {
  margin: 0 0 6px;
  color: var(--gold);
}

.subtitle { color: var(--text-dim); margin: 0 0 18px; }
.best-round { color: var(--text-dim); font-size: 0.9em; margin-bottom: 22px; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95em;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover { background: #262c3a; border-color: #4a5468; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-panel-2); }

.btn-primary { background: linear-gradient(180deg, #6fae4a, #4c8a33); border-color: #7fc457; color: #fff; font-weight: 600; }
.btn-primary:hover { background: linear-gradient(180deg, #7fc457, #5a9a3d); }
.btn-danger { background: linear-gradient(180deg, #b8483d, #8f342b); border-color: #d1483d; color: #fff; }
.btn-danger:hover { background: linear-gradient(180deg, #cf5347, #a03c31); }
.btn-ghost { background: transparent; }
.btn-big { display: block; width: 100%; padding: 14px; font-size: 1.1em; margin: 6px 0; }
.btn-small { padding: 6px 10px; font-size: 0.85em; }
.btn-close { padding: 2px 9px; font-size: 1em; line-height: 1; }

.menu-help {
  margin-top: 18px;
  text-align: left;
  color: var(--text-dim);
  font-size: 0.88em;
}
.menu-help summary { cursor: pointer; color: var(--text); margin-bottom: 6px; }
.menu-help ul { margin: 6px 0 0; padding-left: 18px; }
.menu-help li { margin-bottom: 4px; }

.rc-summary {
  text-align: left;
  background: var(--bg-panel-2);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 14px 0;
  font-size: 0.92em;
  line-height: 1.7;
}
.rc-summary .row { display: flex; justify-content: space-between; gap: 12px; }
.rc-summary .row b { color: var(--gold); }

#rc-village { max-height: 40vh; overflow-y: auto; margin-bottom: 10px; }

/* ---------------------------------------------------------------- Game screen */

#screen-game { flex-direction: column; }

#hud-top {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 10px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hud-stat { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 1.05em; }
.hud-icon { color: var(--gold); }
.hud-icon-life { color: var(--danger); }
.hud-stat-wave { color: var(--text-dim); font-weight: 400; font-size: 0.95em; }
.hud-wave-label { color: #c9553d; font-weight: 600; font-size: 0.9em; min-width: 90px; }
.hud-spacer { flex: 1; }
.hud-controls { display: flex; gap: 8px; }

#game-area { position: relative; flex: 1; min-height: 0; background: #0c0e13; }
#game-canvas { display: block; width: 100%; height: 100%; }

.btn-floating {
  position: absolute;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 12px 26px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

#shop-bar {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.shop-tower {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 92px;
  padding: 8px 10px;
  background: var(--bg-panel-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.shop-tower:hover:not(:disabled) { border-color: var(--gold); }
.shop-tower.selected { border-color: var(--gold); background: #2a2410; }
.shop-tower .name { font-size: 0.82em; font-weight: 600; }
.shop-tower .cost { font-size: 0.78em; color: var(--gold); }
.shop-tower .swatch { width: 22px; height: 22px; border-radius: 50%; margin-bottom: 2px; }
.shop-tower:disabled { opacity: 0.45; }
.shop-tower .lock-hint { font-size: 0.68em; color: var(--text-dim); text-align: center; }

/* ---------------------------------------------------------------- Panels */

.panel {
  position: absolute;
  top: 66px; right: 14px;
  width: 300px;
  max-height: calc(100% - 150px);
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(0,0,0,0.45);
  z-index: 6;
}
.panel-wide { width: 380px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  position: sticky; top: 0;
  background: var(--bg-panel);
}

.tp-stats {
  padding: 10px 14px;
  font-size: 0.85em;
  color: var(--text-dim);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  border-bottom: 1px solid var(--border);
}
.tp-stats span.v { color: var(--text); font-weight: 600; }

.tp-path { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.tp-path .path-title { font-weight: 600; margin-bottom: 6px; display: flex; justify-content: space-between; }
.tp-path .path-title .lv { color: var(--gold); font-weight: 400; font-size: 0.85em; }
.tp-path .path-desc { font-size: 0.8em; color: var(--text-dim); margin-bottom: 8px; min-height: 2.4em; }
.tp-path .pips { display: flex; gap: 4px; margin-bottom: 8px; }
.tp-path .pip { flex: 1; height: 6px; border-radius: 3px; background: #333; }
.tp-path .pip.filled { background: var(--gold); }

#tp-sell { width: calc(100% - 28px); margin: 12px 14px; }

#vp-buildings, #ap-list { padding: 8px 14px 14px; }

.vp-building {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.vp-building:last-child { border-bottom: none; }
.vp-building .head { display: flex; justify-content: space-between; align-items: baseline; }
.vp-building .head .name { font-weight: 600; }
.vp-building .head .lv { color: var(--gold); font-size: 0.85em; }
.vp-building .desc { font-size: 0.8em; color: var(--text-dim); margin: 4px 0 8px; }
.vp-building .pips { display: flex; gap: 4px; margin-bottom: 8px; }
.vp-building .pip { flex: 1; height: 6px; border-radius: 3px; background: #333; }
.vp-building .pip.filled { background: var(--good); }
.vp-building .upgrade-btn { width: 100%; }

.ach-item {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  opacity: 0.45;
}
.ach-item.unlocked { opacity: 1; }
.ach-item:last-child { border-bottom: none; }
.ach-item .icon { font-size: 1.3em; line-height: 1; }
.ach-item .name { font-weight: 600; font-size: 0.9em; }
.ach-item .desc { font-size: 0.78em; color: var(--text-dim); }

/* ---------------------------------------------------------------- Toasts */

#toast-container {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: linear-gradient(180deg, #2a2410, #1c1808);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease-out, toast-out 0.4s ease-in 3.6s forwards;
}
.toast .icon { font-size: 1.4em; }
.toast .title { font-weight: 700; color: var(--gold); font-size: 0.85em; }
.toast .name { font-size: 0.92em; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* ---------------------------------------------------------------- Scrollbars */

.panel::-webkit-scrollbar, #rc-village::-webkit-scrollbar, #shop-bar::-webkit-scrollbar { width: 8px; height: 8px; }
.panel::-webkit-scrollbar-thumb, #rc-village::-webkit-scrollbar-thumb { background: #3a4256; border-radius: 4px; }
