:root {
  --bg: #1c1712;
  --panel: #2d251c;
  --panel-accent: #9c7b3c;
  --text: #f2e8d4;
  --muted: #c7b08a;
  --danger: #e65c3c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #3a2f23, #140f0b 65%);
  color: var(--text);
}

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

#app.hidden {
  display: none;
}

#menu-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(180, 120, 40, 0.25), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(120, 70, 30, 0.35), transparent 60%),
    linear-gradient(120deg, #140f0b, #2b2117 55%, #140f0b);
  color: var(--text);
  z-index: 10;
  pointer-events: auto;
}

#menu-screen.visible {
  display: flex;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #111;
  z-index: 1;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  z-index: 2;
}

#top-bar {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 16px;
  background: rgba(28, 23, 18, 0.8);
  padding: 10px 14px;
  border: 1px solid var(--panel-accent);
  border-radius: 8px;
  pointer-events: auto;
}

.stat {
  font-size: 14px;
  color: var(--muted);
}

#side-panel {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

#minimap {
  width: 100%;
  border: 1px solid var(--panel-accent);
  background: #15110c;
}

#selection-panel,
#build-panel,
#production-panel {
  background: rgba(45, 37, 28, 0.9);
  border: 1px solid var(--panel-accent);
  padding: 10px;
  border-radius: 6px;
}

#build-panel {
  display: none;
}

.panel-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}

#build-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

#build-buttons button,
#production-queue button,
.hud-button,
.menu button {
  background: var(--panel-accent);
  border: none;
  color: #1a140e;
  padding: 8px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}

#build-buttons button:disabled,
#production-queue button:disabled {
  background: #4b3a22;
  color: #8c7b5f;
}

#selection-title {
  font-weight: 600;
  margin-bottom: 6px;
}

#selection-details {
  font-size: 12px;
  color: var(--muted);
  min-height: 44px;
}

.selection-building {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selection-building-tile {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d0c15;
  border: 1px solid var(--panel-accent);
  position: relative;
  image-rendering: pixelated;
}

.selection-building-tile::after {
  content: "";
  position: absolute;
  inset: 6px;
  background: var(--tile-image);
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
}

.selection-health {
  width: 100%;
}

.selection-health-bar {
  height: 8px;
  background: #1b1510;
  border: 1px solid #58422a;
  border-radius: 4px;
  overflow: hidden;
}

.selection-health-fill {
  height: 100%;
  width: 0;
  background: #3fa34d;
}

.selection-health-bar.good .selection-health-fill {
  background: #3fa34d;
}

.selection-health-bar.warn .selection-health-fill {
  background: #d6b139;
}

.selection-health-bar.danger .selection-health-fill {
  background: #dd7a33;
}

.selection-health-bar.critical .selection-health-fill {
  background: #d54b3e;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: #3a2f23;
  border: 1px solid var(--panel-accent);
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0;
}

.progress-fill {
  height: 100%;
  background: #d4a24c;
  width: 0;
}

#production-queue {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 7, 5, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 5;
}

.overlay.visible {
  display: flex;
}

.menu {
  background: rgba(45, 37, 28, 0.95);
  border: 1px solid var(--panel-accent);
  padding: 24px;
  border-radius: 8px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  pointer-events: auto;
}

.build-menu {
  width: 520px;
  background: #2a2834;
  border: 2px solid #585070;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: #e9e5ff;
}

.build-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #3b3850;
  padding: 10px 12px;
  border: 1px solid #585070;
}

.build-menu-title {
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 13px;
}

#close-build-menu {
  background: #71679a;
  border: none;
  color: #0f0c17;
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
}

.build-menu-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: #1d1b28;
  padding: 10px;
  border: 1px solid #585070;
  min-height: 180px;
}

.build-tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0d0c15;
  border: 2px solid #3d3850;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.build-tile.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.build-tile::after {
  content: "";
  position: absolute;
  inset: 6px;
  background: var(--tile-image);
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
}

.build-tile-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 10px;
  text-align: center;
  color: #bcb2db;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.build-menu-detail {
  background: #1d1b28;
  border: 1px solid #585070;
  padding: 10px;
  min-height: 70px;
  font-size: 12px;
  color: #c5bddf;
  display: flex;
  flex-direction: column;
  gap: 6px;
}


.menu h1,
.menu h2 {
  margin: 0 0 8px 0;
}

.menu label {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
}

.menu input {
  width: 180px;
  background: #1a140e;
  border: 1px solid #5f4a2d;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
}

.menu-divider {
  height: 1px;
  background: rgba(156, 123, 60, 0.6);
  margin: 4px 0;
}

.menu-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.menu-status {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  #side-panel {
    width: 200px;
  }

  #build-buttons {
    grid-template-columns: 1fr;
  }
}
