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

body {
  background: #1a1a2e;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  background: #2d5a1e;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  font-size: 16px;
  font-weight: bold;
  z-index: 10;
}

#hud span {
  padding: 4px 12px;
  border-radius: 12px;
}

#hud-wood { background: rgba(139, 90, 43, 0.6); }
#hud-coins { background: rgba(218, 165, 32, 0.6); }
#hud-spears { background: rgba(100, 149, 237, 0.6); }
#hud-base { background: rgba(106, 168, 79, 0.6); }

#hud-pause {
  padding: 4px 12px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s;
}

#hud-pause:hover {
  background: rgba(255, 255, 255, 0.3);
}

.btn-danger {
  background: #e57373 !important;
  border-color: #c62828 !important;
}

.btn-danger:hover {
  background: #ef9a9a !important;
}

/* Overlays & Modals */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.modal {
  background: #f0e6d3;
  border: 4px solid #8b5a2b;
  border-radius: 16px;
  padding: 24px 32px;
  min-width: 280px;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal h2 {
  color: #4a2c0a;
  margin-bottom: 12px;
  font-size: 24px;
}

.modal p {
  color: #5a3d1a;
  margin-bottom: 16px;
  font-size: 15px;
  line-height: 1.4;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-buttons button {
  padding: 10px 20px;
  border: 3px solid #6b4226;
  border-radius: 12px;
  background: #8bc34a;
  color: #2e1a00;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.modal-buttons button:hover {
  background: #9ccc65;
  transform: scale(1.05);
}

.modal-buttons button:active {
  transform: scale(0.95);
}

/* Tutorial */
.tutorial-modal h2 {
  color: #1565c0;
}

/* Win */
.win-modal {
  border-color: #ffd700;
  background: linear-gradient(135deg, #fff8e1, #ffe082);
}

.win-modal h2 {
  color: #e65100;
  font-size: 28px;
}

/* Crafting / Build list items */
.recipe-item, .build-item {
  background: #e8d5b7;
  border: 2px solid #a0764a;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.recipe-item .recipe-name, .build-item .build-name {
  font-weight: bold;
  color: #4a2c0a;
}

.recipe-item .recipe-cost, .build-item .build-cost {
  font-size: 13px;
  color: #6b4226;
}

.recipe-item button, .build-item button {
  padding: 6px 14px;
  border: 2px solid #6b4226;
  border-radius: 8px;
  background: #8bc34a;
  color: #2e1a00;
  font-weight: bold;
  cursor: pointer;
  font-size: 14px;
}

.recipe-item button:disabled, .build-item button:disabled {
  background: #bbb;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Mobile Controls */
#mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  pointer-events: none;
  z-index: 20;
}

#mobile-controls.hidden {
  display: none;
}

#dpad {
  position: relative;
  width: 130px;
  height: 130px;
  pointer-events: auto;
}

.dpad-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#btn-up { top: 0; left: 43px; }
#btn-down { bottom: 0; left: 43px; }
#btn-left { top: 43px; left: 0; }
#btn-right { top: 43px; right: 0; }

.dpad-btn:active {
  background: rgba(255, 255, 255, 0.5);
}

#action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 220px;
  pointer-events: auto;
}

.action-btn {
  padding: 10px 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
}

.action-btn:active {
  background: rgba(255, 255, 255, 0.5);
}

/* Screen shake */
#game-canvas.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-2px, 4px); }
  80% { transform: translate(2px, -4px); }
}
