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

body {
  background: #111;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #eee;
  user-select: none;
}

#canvas {
  position: fixed;
  top: 0; left: 0;
  display: block;
}

/* ─── HUD ─────────────────────────────────────────────────────────────────── */

#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 14px;
  pointer-events: none;
  z-index: 10;
}

#hud-left {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 260px;
}

#hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  pointer-events: auto;
}

#hud-right span {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 600;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.bar-label {
  width: 22px;
  text-align: center;
  font-size: 14px;
}

.bar-track {
  flex: 1;
  height: 12px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 100%;
  border-radius: 6px;
  transition: width 0.1s ease;
}

.hp-bar    { background: linear-gradient(90deg, #c0392b, #e74c3c); }
.xp-bar    { background: linear-gradient(90deg, #1e8449, #27ae60); }
.base-bar  { background: linear-gradient(90deg, #1a5276, #2980b9); }

.bar-num {
  width: 80px;
  text-align: right;
  font-size: 11px;
  color: #aaa;
  white-space: nowrap;
}

#shop-btn {
  pointer-events: auto;
  background: rgba(40, 80, 40, 0.85);
  border: 1px solid #4caf50;
  border-radius: 6px;
  color: #aaffaa;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
#shop-btn:hover { background: rgba(60,120,60,0.9); }

/* ─── Overlay ─────────────────────────────────────────────────────────────── */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#overlay.hidden { display: none; }

#overlay-content {
  background: #1a1e2a;
  border: 1px solid #334;
  border-radius: 12px;
  padding: 28px 36px;
  max-width: 700px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#overlay-content h2 {
  font-size: 26px;
  margin-bottom: 8px;
  color: #ffe066;
}

#overlay-content p {
  color: #aaa;
  margin-bottom: 18px;
}

/* ─── Level-up ────────────────────────────────────────────────────────────── */

.upgrade-choices {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.upgrade-card {
  background: #232838;
  border: 2px solid #334;
  border-radius: 10px;
  padding: 18px 16px;
  width: 170px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.upgrade-card:hover {
  border-color: #ffe066;
  background: #2c3248;
  transform: translateY(-2px);
}

.upgrade-icon { font-size: 34px; margin-bottom: 8px; }
.upgrade-name { font-weight: 700; font-size: 14px; margin-bottom: 5px; color: #eee; }
.upgrade-desc { font-size: 12px; color: #888; line-height: 1.4; }

/* ─── Shop ────────────────────────────────────────────────────────────────── */

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  text-align: left;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #232838;
  border: 1px solid #334;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.shop-item:hover:not(.disabled) {
  border-color: #4caf50;
  background: #2a3328;
}

.shop-item.disabled { opacity: 0.45; cursor: not-allowed; }

.shop-icon { font-size: 26px; width: 36px; text-align: center; flex-shrink: 0; }

.shop-info { flex: 1; }
.shop-name { font-weight: 700; font-size: 14px; }
.shop-name kbd { font-size: 10px; font-family: inherit; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: middle; }
.shop-desc { font-size: 12px; color: #888; }

.shop-cost {
  font-weight: 700;
  font-size: 14px;
  color: #ffd700;
  white-space: nowrap;
}
.shop-cost.too-expensive { color: #c0392b; }

#close-shop-btn, #restart-btn {
  background: #2c3e50;
  border: 1px solid #4a6278;
  border-radius: 8px;
  color: #ccc;
  font-size: 14px;
  padding: 8px 24px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.15s;
}
#close-shop-btn:hover, #restart-btn:hover { background: #3d5166; }

/* ─── Game Over / Stats ───────────────────────────────────────────────────── */

.stats {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0 20px;
  font-size: 15px;
  color: #aaa;
}

.stats div {
  background: #232838;
  border: 1px solid #334;
  border-radius: 6px;
  padding: 6px 14px;
}

/* ─── Seed display ───────────────────────────────────────────────────────── */

#seed-display {
  font-size: 10px;
  color: rgba(255,255,255,0.22);
  letter-spacing: 0.3px;
  min-height: 14px;
}

/* ─── Title screen ───────────────────────────────────────────────────────── */

#title-screen {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

#title-screen.hidden { display: none; }

#title-content {
  text-align: center;
  max-width: 500px;
  padding: 0 20px;
}

#title-content h1 {
  font-size: 54px;
  font-weight: 800;
  color: #ffe066;
  letter-spacing: 3px;
  margin-bottom: 10px;
  text-shadow: 0 0 40px rgba(255,224,102,0.35);
}

.title-tagline {
  color: #778;
  font-size: 14px;
  margin-bottom: 30px;
}

.title-instructions {
  background: rgba(0,0,0,0.4);
  border: 1px solid #2a2d3a;
  border-radius: 8px;
  padding: 14px 22px;
  margin-bottom: 26px;
  font-size: 13px;
  color: #99a;
  line-height: 2.2;
}

.title-seed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 26px;
  font-size: 13px;
  color: #778;
}

#seed-input {
  background: #141820;
  border: 1px solid #334;
  border-radius: 6px;
  color: #dde;
  font-size: 13px;
  font-family: monospace;
  padding: 5px 10px;
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}

#seed-input:focus { border-color: #ffe066; }

#start-btn {
  background: rgba(35, 90, 35, 0.9);
  border: 2px solid #4caf50;
  border-radius: 8px;
  color: #aaffaa;
  font-size: 18px;
  font-weight: 700;
  padding: 11px 48px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, transform 0.1s;
}

#start-btn:hover {
  background: rgba(55, 130, 55, 0.95);
  transform: translateY(-2px);
}

/* ─── Upgrades panel ─────────────────────────────────────────────────────── */

#upgrades-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 0;
  margin-top: 2px;
}

.upgrade-badge {
  position: relative;
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  cursor: default;
}

.upgrade-badge sup {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 8px;
  color: #ffe066;
  font-weight: 700;
  line-height: 1;
}

/* ─── Placement hint ─────────────────────────────────────────────────────── */

#placement-hint {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,14,20,0.88);
  border: 1px solid #ffe066;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 13px;
  color: #ffe066;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
}

#placement-hint.hidden { display: none; }

/* ─── Skill tree ─────────────────────────────────────────────────────────── */

#skill-tree-btn {
  pointer-events: auto;
  background: rgba(40, 55, 80, 0.85);
  border: 1px solid #5588cc;
  border-radius: 6px;
  color: #aabbff;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
#skill-tree-btn:hover { background: rgba(55, 75, 115, 0.9); }

#ep-display {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #aabbff;
}

#mute-btn {
  pointer-events: auto;
  background: rgba(30,30,30,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  font-size: 15px;
  padding: 4px 9px;
  cursor: pointer;
}

.st-tree {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 18px;
  flex-wrap: wrap;
}

.st-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-width: 130px;
}

.st-branch-label {
  font-size: 11px;
  font-weight: 700;
  color: #778;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.st-connector {
  color: #334;
  font-size: 14px;
  line-height: 1.2;
  user-select: none;
}

.st-node {
  width: 120px;
  background: #1a1e2a;
  border: 1px solid #334;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}

.st-node.st-available {
  border-color: #5588cc;
  background: #1e2535;
  cursor: pointer;
}
.st-node.st-available:hover {
  border-color: #88bbff;
  background: #252d42;
  transform: translateY(-1px);
}
.st-node.st-unlocked {
  border-color: #44cc66;
  background: #182518;
}
.st-node.st-locked { opacity: 0.4; }

.st-icon { font-size: 22px; display: block; margin-bottom: 4px; }
.st-name { font-size: 11px; font-weight: 700; color: #ccd; display: block; margin-bottom: 5px; }
.st-cost { font-size: 14px; color: #aabbff; font-weight: 700; }
.st-node.st-unlocked .st-cost { color: #44cc66; }
.st-node.st-locked .st-cost { color: #556; }

/* ─── Leaderboard ────────────────────────────────────────────────────────── */

#leaderboard {
  margin-top: 24px;
  width: 100%;
}

.lb-title {
  font-size: 10px;
  font-weight: 700;
  color: #556;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.lb-empty {
  font-size: 12px;
  color: #445;
  text-align: center;
  padding: 12px 0;
}

.lb-scroll {
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #334 transparent;
}
.lb-scroll::-webkit-scrollbar { width: 4px; }
.lb-scroll::-webkit-scrollbar-thumb { background: #334; border-radius: 2px; }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.lb-table thead tr {
  position: sticky;
  top: 0;
  background: rgba(10,14,20,0.97);
}

.lb-table th {
  color: #556;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 4px 6px;
  text-align: right;
  border-bottom: 1px solid #1e2230;
}
.lb-table th:first-child { text-align: center; }

.lb-table td {
  padding: 5px 6px;
  text-align: right;
  color: #778;
  border-bottom: 1px solid #141620;
}

/* Medal colours for top 3 */
.lb-table tbody tr:nth-child(1) td { color: #ffe066; }
.lb-table tbody tr:nth-child(2) td { color: #c0c0c0; }
.lb-table tbody tr:nth-child(3) td { color: #cd7f32; }

.lb-rank  { text-align: center !important; color: #445 !important; width: 24px; }
.lb-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-time  { font-variant-numeric: tabular-nums; }
.lb-date  { font-size: 11px; color: #445 !important; }

/* ─── Controls hint ──────────────────────────────────────────────────────── */

#controls-hint {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  pointer-events: none;
  z-index: 5;
}
