* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: #0d0b08;
  color: #e8ddc7;
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  overflow: hidden;
  height: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 16px;
  background: linear-gradient(#2a2016, #1a140d);
  border-bottom: 2px solid #6b5530;
}

.brand {
  font-weight: bold;
  font-size: 1.2em;
  color: #e8c94a;
  letter-spacing: 0.5px;
}

.stat {
  font-size: 1.05em;
  background: rgba(0,0,0,0.35);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #4a3b22;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), inset 0 -1px 2px rgba(0,0,0,0.4);
}

@keyframes stat-pulse {
  0% { border-color: #ffe066; box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), inset 0 -1px 2px rgba(0,0,0,0.4), 0 0 0 2px rgba(255,224,102,0.35); }
  100% { border-color: #4a3b22; box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), inset 0 -1px 2px rgba(0,0,0,0.4); }
}
.stat-pulse { animation: stat-pulse 500ms ease-out; }

.spacer { flex: 1; }

.ctrlbtn {
  background: #3a2c18;
  color: #e8ddc7;
  border: 1px solid #6b5530;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.95em;
  transition: background-color 150ms ease-out, border-color 150ms ease-out, transform 100ms ease-out;
}
.ctrlbtn:hover { background: #4a3a22; border-color: #ffe066; }
.ctrlbtn:active { transform: scale(0.96); }

#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#stage {
  position: relative;
  background: #050505;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

#messages {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

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

.toast {
  background: rgba(20,15,8,0.85);
  border: 1px solid #6b5530;
  color: #ffe066;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.9em;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  animation: toast-in 200ms ease-out;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay.hidden { display: none; }

@keyframes overlay-box-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

.overlay-box {
  background: #1a140d;
  border: 2px solid #6b5530;
  border-radius: 10px;
  padding: 32px 48px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: overlay-box-in 220ms ease-out;
}

#gameOverTitle.victory { color: #5ec95e; }
#gameOverTitle.defeat { color: #d4453c; }

.overlay-box .primary {
  margin-top: 16px;
  background: #4d7bd6;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  font-size: 1em;
  cursor: pointer;
  transition: background-color 150ms ease-out, transform 100ms ease-out;
}
.overlay-box .primary:hover { background: #6a94e0; }
.overlay-box .primary:active { transform: scale(0.96); }

#sidebar {
  width: 300px;
  flex-shrink: 0;
  background: #17120b;
  border-left: 2px solid #6b5530;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: rgba(0,0,0,0.3);
  border: 1px solid #4a3b22;
  border-radius: 8px;
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.panel h3 {
  margin: 0 0 8px;
  color: #ffe066;
  font-size: 1em;
}

.hint {
  color: #a89a7a;
  font-size: 0.88em;
  margin: 0;
}

#minimapCanvas {
  width: 100%;
  aspect-ratio: auto;
  border: 1px solid #4a3b22;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 150ms ease-out, filter 150ms ease-out;
}
#minimapCanvas:hover { border-color: #ffe066; filter: brightness(1.12); }

.btn-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 6px 0;
}

.action-btn {
  background: #2a2016;
  color: #e8ddc7;
  border: 1px solid #6b5530;
  border-radius: 6px;
  padding: 6px 4px;
  cursor: pointer;
  font-size: 0.82em;
  line-height: 1.3;
  transition: background-color 150ms ease-out, border-color 150ms ease-out, transform 100ms ease-out;
}
.action-btn:hover:not(:disabled) { background: #3a2c18; border-color: #ffe066; }
.action-btn:active:not(:disabled) { transform: scale(0.96); }
.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.action-btn small { color: #a89a7a; }

.ctrlbtn:focus-visible,
.action-btn:focus-visible,
.overlay-box .primary:focus-visible,
#minimapCanvas:focus-visible {
  outline: 2px solid #ffe066;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .toast, .overlay-box, .stat-pulse {
    animation: none;
  }
  .ctrlbtn, .action-btn, .overlay-box .primary, #minimapCanvas {
    transition: none;
  }
}

.queue-row {
  font-size: 0.82em;
  color: #a89a7a;
  margin-top: 4px;
}

.help ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82em;
  color: #c9bb9a;
  line-height: 1.5;
}
