/* Gearspire — steampunk brass/copper aesthetic */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0; padding: 0;
  background: radial-gradient(ellipse at center, #1c1004 0%, #110a02 55%, #090501 100%);
  background-attachment: fixed;
  font-family: 'Courier New', 'Segoe UI', monospace;
  overflow: hidden;
  width: 100vw; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

/* ── HUD ──────────────────────────────────────────────────────────────────── */
#hud-container {
  flex-shrink: 0; display: flex; justify-content: center;
  background: linear-gradient(135deg, rgba(28,16,4,0.97) 0%, rgba(40,22,6,0.97) 100%);
  border-bottom: 2px solid rgba(180,110,30,0.5);
  backdrop-filter: blur(8px); min-height: 62px;
  box-shadow: 0 0 12px rgba(180,110,30,0.25), inset 0 1px 0 rgba(220,160,60,0.12);
  position: relative; z-index: 101;
}

#hud {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 14px; width: 100%; flex-wrap: wrap;
}

@media (max-width: 768px) {
  #hud-container { min-height: 76px; }
  #hud { flex-direction: column; gap: 8px; padding: 6px 10px; justify-content: center; }
  #score-block { order: 1; width: 100%; justify-content: center; flex-wrap: wrap; }
  #hud-buttons { order: 2; justify-content: center; }
}

#score-block { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

#wave-hud, #lives-hud, #gears-hud, #score-hud, #best-hud {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 1.1em; color: #fff;
  background: linear-gradient(135deg, rgba(160,90,20,0.14) 0%, rgba(120,65,10,0.09) 100%);
  padding: 4px 9px; border-radius: 8px;
  border: 1px solid rgba(180,110,30,0.3);
  box-shadow: 0 2px 6px rgba(160,90,20,0.18), inset 0 1px 0 rgba(255,200,80,0.08);
}

@media (max-width: 768px) {
  #wave-hud, #lives-hud, #gears-hud, #score-hud, #best-hud {
    font-size: 0.82em; padding: 3px 7px;
  }
}

.score-label {
  font-size: 0.6em; color: #c8882a; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
}

.score-value {
  font-weight: 800; color: #ffe75a;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 6px rgba(255,231,90,0.4);
}

#hud-buttons { display: flex; gap: 8px; align-items: center; }

#hud button {
  background: linear-gradient(135deg, rgba(40,22,5,0.88) 0%, rgba(28,14,2,0.92) 100%);
  border: 1px solid rgba(180,110,30,0.4);
  color: #e8c878; font-size: 1em; padding: 7px 11px;
  border-radius: 7px; cursor: pointer;
  transition: all 0.22s ease; font-family: 'Courier New', monospace;
  box-shadow: 0 2px 5px rgba(0,0,0,0.35), 0 0 6px rgba(180,110,30,0.15);
  display: flex; align-items: center;
}

#launch-btn {
  background: linear-gradient(135deg, rgba(60,35,5,0.95) 0%, rgba(80,45,5,0.95) 100%);
  border-color: rgba(220,160,40,0.7);
  color: #ffe75a; font-weight: 800; letter-spacing: 0.5px;
  box-shadow: 0 0 12px rgba(220,160,40,0.4);
  padding: 7px 16px;
}

#launch-btn:hover {
  background: linear-gradient(135deg, rgba(180,110,20,0.6) 0%, rgba(220,150,30,0.4) 100%);
  box-shadow: 0 4px 16px rgba(220,160,40,0.6), 0 0 16px rgba(220,160,40,0.5);
  transform: translateY(-2px); color: #fff;
  border-color: rgba(255,200,80,0.9);
}

#hud button:hover:not(#launch-btn) {
  background: linear-gradient(135deg, rgba(180,110,30,0.38) 0%, rgba(130,75,15,0.28) 100%);
  box-shadow: 0 4px 14px rgba(180,110,30,0.45);
  transform: translateY(-2px); color: #fff;
}

/* ── Canvas ───────────────────────────────────────────────────────────────── */
#canvas-container {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  width: 100%; padding: 0 0 env(safe-area-inset-bottom, 0px) 0;
  overflow: hidden; position: relative; z-index: 2;
}

#game {
  flex: 1; min-height: 0; width: 100%; display: block;
  outline: none; touch-action: none; cursor: pointer;
}

/* ── Overlay ──────────────────────────────────────────────────────────────── */
#overlay {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  z-index: 100; pointer-events: none;
}

#overlay:not(.hidden) {
  background: radial-gradient(ellipse at center, rgba(20,11,2,0.88) 0%, rgba(8,4,1,0.95) 100%);
  backdrop-filter: blur(8px); pointer-events: auto;
}

.overlay-content {
  background: linear-gradient(135deg, rgba(20,11,2,0.97) 0%, rgba(12,6,1,0.97) 100%);
  border: 2px solid rgba(180,110,30,0.55);
  border-radius: 16px; padding: 28px 32px; color: #fff;
  text-align: center; max-width: 520px; width: 94%;
  box-shadow: 0 0 28px rgba(180,110,30,0.22), 0 14px 44px rgba(0,0,0,0.55);
  pointer-events: auto;
}

.overlay-content h1 {
  font-size: 2.4em; margin: 0 0 8px;
  color: #c8882a; text-shadow: 0 0 14px rgba(200,140,50,0.6);
  font-weight: 800; letter-spacing: 2px; font-family: 'Courier New', monospace;
}

.overlay-content h2 {
  font-size: 1.8em; margin: 0 0 14px;
  color: #c8882a; text-shadow: 0 0 10px rgba(200,140,50,0.5);
  font-family: 'Courier New', monospace;
}

.overlay-content p {
  color: #c0a068; font-size: 1em; margin: 0 0 16px; line-height: 1.55;
}

.start-buttons {
  display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 8px;
}

.overlay-content button {
  background: linear-gradient(135deg, rgba(40,22,5,0.9) 0%, rgba(28,14,2,0.94) 100%);
  border: 1px solid rgba(180,110,30,0.45);
  color: #e8c878; font-size: 1.05em; font-weight: bold;
  padding: 10px 22px; border-radius: 8px; min-width: 180px;
  cursor: pointer; transition: all 0.22s ease; font-family: 'Courier New', monospace;
  box-shadow: 0 2px 7px rgba(0,0,0,0.3), 0 0 7px rgba(180,110,30,0.15);
  display: inline-flex; align-items: center; justify-content: center;
}

.overlay-content button:hover {
  background: linear-gradient(135deg, rgba(180,110,30,0.4) 0%, rgba(130,75,15,0.3) 100%);
  box-shadow: 0 5px 18px rgba(180,110,30,0.48), 0 0 12px rgba(180,110,30,0.5);
  transform: translateY(-2px); color: #fff;
  border-color: rgba(220,160,60,0.75);
}

.overlay-content button:active { transform: none; }

/* ── Info screen ──────────────────────────────────────────────────────────── */
#info-screen {
  max-width: 860px; width: 96%; padding: 18px 22px;
  max-height: min(90vh, 90dvh);
  display: flex; flex-direction: column; text-align: left; overflow: hidden;
}

#info-screen h2 { text-align: center; font-size: 1.5em; margin: 0 0 10px; flex: 0 0 auto; }

#info-screen .info-content {
  display: grid; gap: 8px; margin-bottom: 10px;
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
}

@media (min-width: 700px) { #info-screen .info-content { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { #info-screen .info-content { grid-template-columns: 1fr 1fr 1fr; } }

#info-screen .info-section {
  background: rgba(180,110,30,0.07); border: 1px solid rgba(180,110,30,0.2);
  border-radius: 9px; padding: 9px 12px;
}

#info-screen .info-section h3 { color: #c8882a; margin: 0 0 5px; font-size: 0.95em; }
#info-screen .info-section p  { margin: 0 0 3px; font-size: 0.86em; line-height: 1.42; color: #b09060; }
#info-screen .info-section p strong { color: #ffe75a; }
#info-screen #close-info-btn { flex: 0 0 auto; align-self: center; margin-top: 6px; }

/* ── Game-over ────────────────────────────────────────────────────────────── */
#sales-pitch { margin: 8px 0; padding: 10px; background: rgba(255,215,0,0.07); border: 1px solid rgba(255,215,0,0.2); border-radius: 9px; }
#sales-pitch .cta-text { color: #a08848 !important; font-size: 0.92em !important; font-weight: normal !important; margin: 0 !important; line-height: 1.5; }

@media (max-width: 768px) {
  #gameover-screen {
    max-height: calc(100dvh - 76px - env(safe-area-inset-bottom,0px) - 14px);
    overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px 14px !important;
  }
}

/* ── Leaderboard panel ────────────────────────────────────────────────────── */
#leaderboard-panel {
  background: rgba(10,6,1,0.75); border: 1px solid rgba(180,110,30,0.3);
  border-radius: 10px; margin: 10px 0 7px; padding: 9px 12px;
  text-align: left; max-height: 180px; overflow-y: auto;
}

#leaderboard-panel h3 { margin: 0 0 7px; color: #ffe75a; font-size: 0.9em; text-align: center; text-transform: uppercase; letter-spacing: 1px; }

#leaderboard-list { list-style: none; margin: 0; padding: 0; }
#leaderboard-list li { display: flex; align-items: center; gap: 7px; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 0.82em; color: #c8a060; }
#leaderboard-list li:last-child { border-bottom: none; }

.lb-loading, .lb-empty { justify-content: center; color: rgba(255,255,255,0.4); font-style: italic; }
.lb-rank  { width: 20px; text-align: right; color: rgba(255,231,90,0.8); font-weight: bold; flex-shrink: 0; }
.lb-name  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: bold; color: #ffe75a; font-family: 'Courier New', monospace; flex-shrink: 0; }
.lb-status { font-size: 0.76em; color: rgba(255,255,255,0.38); text-align: center; margin: 4px 0 0; }

/* ── Leaderboard overlay ─────────────────────────────────────────────────── */
#leaderboard-overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, rgba(20,11,2,0.92) 0%, rgba(8,4,1,0.97) 100%);
  backdrop-filter: blur(8px); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}

#leaderboard-overlay.hidden { display: none !important; }

#leaderboard-modal {
  background: rgba(14,8,2,0.95); border: 1px solid rgba(180,110,30,0.45);
  border-radius: 14px; padding: 26px 30px;
  min-width: 300px; max-width: 440px; width: 90%;
  box-shadow: 0 8px 38px rgba(180,110,30,0.28); text-align: center;
}

#leaderboard-modal h2 { margin: 0 0 14px; color: #ffe75a; font-size: 1.2em; letter-spacing: 2px; text-transform: uppercase; font-family: 'Courier New', monospace; }

#leaderboard-overlay-list { list-style: none; margin: 0 0 16px; padding: 0; max-height: 260px; overflow-y: auto; text-align: left; }
#leaderboard-overlay-list li { display: flex; align-items: center; gap: 9px; padding: 5px 2px; border-bottom: 1px solid rgba(255,255,255,0.07); color: #c8a060; font-size: 0.9em; }
#leaderboard-overlay-list li:last-child { border-bottom: none; }

#close-leaderboard-overlay-btn {
  background: linear-gradient(135deg, rgba(40,22,5,0.9) 0%, rgba(28,14,2,0.94) 100%);
  border: 1px solid rgba(180,110,30,0.38); color: #e8c878;
  font-size: 0.92em; font-weight: 600; padding: 8px 24px; border-radius: 9px;
  cursor: pointer; transition: all 0.22s ease; box-shadow: 0 4px 10px rgba(180,110,30,0.24);
  font-family: 'Courier New', monospace;
}

#close-leaderboard-overlay-btn:hover {
  background: linear-gradient(135deg, rgba(180,110,30,0.38) 0%, rgba(130,75,15,0.28) 100%);
  transform: translateY(-2px); color: #fff;
}

/* ── Tech Tree overlay ───────────────────────────────────────────────────── */
#tech-tree-overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, rgba(20,11,2,0.92) 0%, rgba(8,4,1,0.97) 100%);
  backdrop-filter: blur(8px); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
#tech-tree-overlay.hidden { display: none !important; }

#tech-tree-modal {
  background: rgba(14,8,2,0.96); border: 1px solid rgba(180,110,30,0.45);
  border-radius: 14px; padding: 22px 24px;
  max-width: 720px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 38px rgba(180,110,30,0.28); text-align: center;
}
#tech-tree-modal h2 {
  margin: 0 0 14px; color: #ffe75a; font-size: 1.2em;
  letter-spacing: 2px; text-transform: uppercase;
  font-family: 'Courier New', monospace;
}
.tech-section-title {
  color: #c8882a; font-size: 0.75em; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  margin: 14px 0 8px; font-family: 'Courier New', monospace;
}
.tech-tower-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px; margin-bottom: 4px;
}
.tech-card {
  background: rgba(22,12,2,0.9); border: 1px solid rgba(160,95,25,0.4);
  border-radius: 9px; padding: 10px 8px; text-align: center;
}
.tech-card-icon { font-size: 1.6em; line-height: 1.2; }
.tech-card-name {
  color: #ffe075; font-weight: 700; font-size: 0.82em;
  font-family: 'Courier New', monospace; margin: 4px 0;
}
.tech-stats {
  width: 100%; border-collapse: collapse;
  font-size: 0.72em; font-family: 'Courier New', monospace;
  color: #b08040; text-align: left;
}
.tech-stats td, .tech-stats th {
  padding: 2px 3px; border-bottom: 1px solid rgba(120,70,20,0.25);
}
.tech-stats td:last-child, .tech-stats th:last-child { text-align: right; color: #e0b060; }
.tech-stats th { color: #c8882a; font-size: 0.9em; }
.tech-tier-table { max-width: 300px; margin: 8px auto; }
.tech-card-ability {
  font-size: 0.72em; color: #a07040; margin-top: 6px;
  font-style: italic; font-family: 'Courier New', monospace;
}
.tech-divider {
  border: none; border-top: 1px solid rgba(160,95,25,0.3);
  margin: 14px 0;
}
.tech-merge-desc {
  color: #a07040; font-size: 0.82em; font-family: 'Courier New', monospace;
  margin-bottom: 10px; line-height: 1.5;
}
.tech-merge-desc strong { color: #ffe075; }
.tech-upgrade-badge { color: #ffcc44; font-style: normal; }
.tech-recipe-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.tech-recipe-card {
  background: rgba(22,12,2,0.9); border: 1px solid rgba(160,95,25,0.35);
  border-radius: 9px; padding: 10px 12px; text-align: left;
}
.tech-recipe-ingredients {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px; margin-bottom: 5px; font-family: 'Courier New', monospace;
  font-size: 0.82em;
}
.tech-recipe-part { color: #c8a060; }
.tech-recipe-op { color: rgba(180,130,50,0.5); font-weight: bold; }
.tech-recipe-result { color: #ffe075; font-weight: 700; }
.tech-recipe-desc {
  font-size: 0.76em; color: #907040; font-style: italic;
  font-family: 'Courier New', monospace;
}
#close-tech-overlay-btn {
  background: linear-gradient(135deg, rgba(40,22,5,0.9) 0%, rgba(28,14,2,0.94) 100%);
  border: 1px solid rgba(180,110,30,0.38); color: #e8c878;
  font-size: 0.92em; font-weight: 600; padding: 8px 24px; border-radius: 9px;
  cursor: pointer; transition: all 0.22s ease; box-shadow: 0 4px 10px rgba(180,110,30,0.24);
  font-family: 'Courier New', monospace; margin-top: 16px;
}
#close-tech-overlay-btn:hover {
  background: linear-gradient(135deg, rgba(180,110,30,0.38) 0%, rgba(130,75,15,0.28) 100%);
  transform: translateY(-2px); color: #fff;
}

.hidden { display: none !important; }
.icon { font-size: 1.05em; vertical-align: middle; }

#version-info { position: fixed; bottom: calc(6px + env(safe-area-inset-bottom, 0px)); right: 8px; z-index: 15; pointer-events: none; }
#version-info p { color: rgba(255,255,255,0.28); font-size: 0.72em; margin: 0; text-align: right; font-family: 'Courier New', monospace; }
