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

:root {
  --bg: #1a472a;
  --panel: #2d5a3d;
  --panel-border: #4a8f5c;
  --accent: #ff6b35;
  --accent-hover: #ff8c5a;
  --text: #f5f0e6;
  --text-dim: #b8d4be;
  --path: #c4a574;
  --grass: #3d8b4f;
  --grass-dark: #2d6b3d;
  --gold: #ffd54f;
}

body {
  min-height: 100vh;
  font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
  background: linear-gradient(160deg, #0f2818 0%, #1a472a 50%, #0d1f12 100%);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
}

#app {
  width: 100%;
  max-width: 1200px;
}

/* ========== MENU OVERLAY ========== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a1f10 0%, #1a472a 50%, #0d2815 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.menu-overlay.hidden {
  display: none;
}

.menu-container {
  display: flex;
  gap: 32px;
  max-width: 900px;
  width: 100%;
  background: linear-gradient(180deg, #2d5a3d 0%, #1e3d28 100%);
  border: 4px solid #4a8f5c;
  border-radius: 20px;
  padding: 28px 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}

.menu-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.menu-right {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.game-title {
  font-size: 2.4rem;
  text-align: center;
  color: var(--gold);
  text-shadow: 0 3px 8px rgba(0,0,0,0.5), 0 0 30px rgba(255, 213, 79, 0.3);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

/* ========== SECTIONS ========== */
.menu-section {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 16px;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(255,255,255,0.1);
}

/* ========== MAP SELECTION ========== */
.map-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: linear-gradient(180deg, #3d6b4a 0%, #2d5a3a 100%);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.map-btn:hover {
  background: linear-gradient(180deg, #4a7a58 0%, #3a6a48 100%);
  transform: translateX(4px);
}

.map-btn.selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, #4a7a58 0%, #3a6a48 100%);
  box-shadow: 0 0 15px rgba(255, 213, 79, 0.3);
}

.map-preview {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.map-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.map-name {
  font-weight: 700;
  font-size: 1rem;
}

/* Map Preview */
.map-preview-container {
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

#mapPreviewCanvas {
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background: #3d8b4f;
}

.map-desc {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
}

/* ========== DIFFICULTY SELECTION ========== */
.diff-grid {
  display: flex;
  gap: 10px;
}

.diff-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  background: linear-gradient(180deg, #3d6b4a 0%, #2d5a3a 100%);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn:hover {
  background: linear-gradient(180deg, #4a7a58 0%, #3a6a48 100%);
}

.diff-btn.selected {
  border-color: var(--accent);
  background: linear-gradient(180deg, #5a4a7a 0%, #4a3a6a 100%);
  box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
}

.diff-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.diff-desc {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
}

/* ========== QUEST SELECTION ========== */
.quest-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.quest-list::-webkit-scrollbar {
  width: 6px;
}

.quest-list::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
}

.quest-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
}

.quest-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  background: linear-gradient(180deg, #3d6b4a 0%, #2d5a3a 100%);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.quest-btn:hover {
  background: linear-gradient(180deg, #4a7a58 0%, #3a6a48 100%);
  transform: translateX(4px);
}

.quest-btn.selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, #4a7a58 0%, #3a6a48 100%);
  box-shadow: 0 0 15px rgba(255, 213, 79, 0.3);
}

.quest-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quest-icon {
  font-size: 1.2rem;
}

.quest-name {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
}

.quest-reward {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.85rem;
}

.quest-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.35;
  padding-left: 28px;
}

/* ========== START BUTTON ========== */
.btn-start {
  width: 100%;
  margin-top: auto;
  padding: 16px 24px;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, #d55a28 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 0 #b84320, 0 8px 20px rgba(0,0,0,0.3);
  transition: all 0.15s;
  text-transform: uppercase;
}

.btn-start:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #b84320, 0 12px 25px rgba(0,0,0,0.35);
}

.btn-start:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b84320, 0 4px 10px rgba(0,0,0,0.3);
}

/* ========== QUEST PROGRESS IN HUD ========== */
.quest-progress {
  flex: 1;
  min-width: 160px;
  padding: 6px 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  font-size: 0.8rem;
}

.quest-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin-top: 5px;
  overflow: hidden;
}

.quest-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 0.4s ease;
}

.quest-progress.hidden {
  display: none;
}

/* ========== HUD ========== */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  padding: 12px 16px;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 4px 0 #1e3d28;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
}

.hud-icon {
  font-size: 1.25rem;
}

.round-info {
  flex: 1;
  min-width: 140px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.95rem;
}

.btn-wave {
  margin-left: auto;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, #e55a28 100%);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b84320;
  transition: transform 0.1s, filter 0.15s;
}

.btn-wave:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-wave:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b84320;
}

.btn-wave:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-control {
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #5a4a7a 0%, #4a3a6a 100%);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 0 #3a2a5a;
  transition: transform 0.1s, filter 0.15s;
}

.btn-control:hover {
  filter: brightness(1.1);
}

.btn-control:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #3a2a5a;
}

.btn-control.active {
  background: linear-gradient(180deg, #7a6a9a 0%, #6a5a8a 100%);
  box-shadow: 0 4px 0 #5a4a7a, 0 0 12px rgba(130, 100, 200, 0.4);
}

.game-wrap {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.side-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 4px 0 #1e3d28;
}

.left-panel h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.right-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.right-panel .sel-kills {
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.right-panel .sel-kills strong {
  font-size: 1.1rem;
}

.right-panel .path-rules {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  line-height: 1.3;
}

.right-panel .sel-stats {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.5;
}

.right-panel.hidden {
  display: none;
}

.tower-shop {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tower-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  background: var(--grass-dark);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.tower-btn:hover {
  background: #357a48;
}

.tower-btn.selected {
  border-color: var(--accent);
  background: #3a6b4a;
}

.tower-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tower-btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.tower-btn-info {
  flex: 1;
  min-width: 0;
}

.tower-btn-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.tower-btn-cost {
  font-size: 0.8rem;
  color: var(--gold);
}

#game {
  display: block;
  border: 4px solid var(--panel-border);
  border-radius: 8px;
  background: var(--grass);
  cursor: crosshair;
  flex-shrink: 0;
  max-width: 100%;
  height: auto;
}

.upgrade-paths {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.path-row {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.path-upgrade-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: pre-line;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  background: var(--grass-dark);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
  min-height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.path-upgrade-btn span {
  display: block;
}

.path-upgrade-btn .upgrade-cost {
  font-size: 0.6rem;
  opacity: 0.8;
  margin-top: 2px;
}

.path-upgrade-btn:hover:not(:disabled) {
  background: #357a48;
  border-color: rgba(255, 255, 255, 0.35);
}

.path-upgrade-btn.owned {
  background: #2e5c3a;
  border-color: #81c784;
  color: #a5d6a7;
  cursor: default;
}

.path-upgrade-btn.locked {
  opacity: 0.45;
}

.path-upgrade-btn:disabled:not(.owned) {
  cursor: not-allowed;
  opacity: 0.5;
}

.path-upgrade-btn.targeting-btn {
  padding: 6px 4px;
  font-size: 0.65rem;
  min-height: 28px;
}

.path-upgrade-btn.targeting-btn.active {
  background: #4a8f5c;
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(255, 213, 79, 0.4);
}

.targeting-div {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
}

.btn-action {
  display: block;
  width: 100%;
  padding: 8px;
  margin-bottom: 6px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: #4a8f5c;
  color: #fff;
}

.btn-action:hover {
  filter: brightness(1.1);
}

.btn-sell {
  background: #8b4545;
}

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

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--panel);
  border: 4px solid var(--panel-border);
  border-radius: 16px;
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 {
  font-size: 2.2rem;
  margin-bottom: 14px;
  color: var(--gold);
}

.overlay-card p {
  margin-bottom: 24px;
  color: var(--text-dim);
  font-size: 1.05rem;
  line-height: 1.5;
  white-space: pre-line;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .menu-container {
    flex-direction: column;
  }
  
  .menu-right {
    width: 100%;
  }
  
  .diff-grid {
    flex-wrap: wrap;
  }
  
  .diff-btn {
    min-width: calc(50% - 5px);
  }
  
  .game-wrap {
    flex-direction: column;
    align-items: center;
  }

  .side-panel {
    width: 100%;
    max-width: 960px;
  }

  .tower-shop {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .tower-btn {
    flex: 1;
    min-width: 140px;
  }
}

/* ========== MAP EDITOR ========== */
.map-editor-overlay {
  z-index: 300;
  background: rgba(0, 0, 0, 0.9);
}

.map-editor-overlay.hidden {
  display: none;
}

.map-editor-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 1000px;
  width: 100%;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 12px;
}

.editor-toolbar h2 {
  font-size: 1.2rem;
  color: var(--gold);
  margin-right: auto;
}

.editor-tools {
  display: flex;
  gap: 8px;
}

.editor-tool {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--grass-dark);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.editor-tool:hover {
  background: #357a48;
}

.editor-tool.active {
  border-color: var(--gold);
  background: #3a6b4a;
  box-shadow: 0 0 10px rgba(255, 213, 79, 0.3);
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.btn-editor {
  width: 100%;
  margin-top: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(180deg, #5a4a7a 0%, #4a3a6a 100%);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 #3a2a5a;
  transition: all 0.15s;
}

.btn-editor:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #3a2a5a;
}

#mapEditorCanvas {
  border: 4px solid var(--panel-border);
  border-radius: 8px;
  cursor: crosshair;
  background: #3d8b4f;
}

.editor-help {
  padding: 10px 16px;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.editor-help p {
  margin: 4px 0;
}

.btn-save {
  background: #4a8f5c;
}

.btn-cancel {
  background: #8b4545;
}

/* ========== EDITOR TOOLS ENHANCEMENT ========== */
.editor-separator {
  width: 2px;
  height: 30px;
  background: rgba(255,255,255,0.2);
  margin: 0 8px;
}

.editor-toolbar .editor-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.btn-danger {
  background: #c62828;
}
.btn-danger:hover {
  background: #e53935;
}

/* ========== TEXTURE CONTROLS ========== */
.editor-texture-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}

.texture-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text);
}

.texture-label select {
  padding: 6px 10px;
  background: var(--grass-dark);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.texture-label select:hover {
  border-color: var(--accent);
}

.texture-label select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(255, 213, 79, 0.3);
}
