/* ═══════════════════════════════════════════════════════════
   WORLD MAP GENERATOR — styles
   ═══════════════════════════════════════════════════════════ */

.worldmap-root {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 600px;
  background: var(--bg-1, #0d0f14);
  color: var(--text-1, #e8e8f0);
}

/* ── Toolbar ────────────────────────────────────────────── */
.worldmap-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-2, #15171f);
  border-bottom: 1px solid var(--border-1, #2a2d38);
  flex-wrap: wrap;
}

.worldmap-toolbar .wm-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-3, #1e2129);
  color: var(--text-1, #e8e8f0);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.worldmap-toolbar .wm-btn:hover {
  background: var(--bg-4, #262932);
  border-color: var(--accent, #7c5cfc);
}
.worldmap-toolbar .wm-btn.primary {
  background: var(--accent, #7c5cfc);
  color: #fff;
  border-color: var(--accent, #7c5cfc);
}
.worldmap-toolbar .wm-btn.primary:hover {
  filter: brightness(1.1);
}
.worldmap-toolbar .wm-btn i {
  width: 14px;
  height: 14px;
}

.wm-toolbar-spacer {
  flex: 1;
}

/* ── Tiles toggle ──────────────────────────────────────────── */
.wm-tiles-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  margin-right: 4px;
}
.wm-tiles-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.wm-toggle-track {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--bg-3, #1e2129);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 9px;
  transition: background 0.2s, border-color 0.2s;
}
.wm-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-2, #a0a3ad);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.wm-tiles-toggle input:checked ~ .wm-toggle-track {
  background: var(--accent, #7c6af7);
  border-color: var(--accent, #7c6af7);
}
.wm-tiles-toggle input:checked ~ .wm-toggle-track .wm-toggle-thumb {
  transform: translateX(14px);
  background: #fff;
}
.wm-toggle-label {
  font-size: 12px;
  color: var(--text-2, #a0a3ad);
}
.wm-tiles-toggle:hover .wm-toggle-label {
  color: var(--text-1, #e8e8f0);
}

/* ── Tileset selector ─────────────────────────────────────── */
.wm-tileset-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-3, #1e2129) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a0a3ad'/%3E%3C/svg%3E") no-repeat right 8px center;
  background-size: 8px 5px;
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 6px;
  color: var(--text-2, #a0a3ad);
  font-size: 12px;
  padding: 4px 24px 4px 8px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  height: 30px;
  min-width: 100px;
}
.wm-tileset-select:hover,
.wm-tileset-select:focus {
  border-color: var(--accent, #7c5cfc);
  color: var(--text-1, #e8e8f0);
  outline: none;
}
.wm-tileset-select option {
  background: var(--bg-2, #15171f);
  color: var(--text-1, #e8e8f0);
}

.wm-zoom-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  background: var(--bg-3, #1e2129);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 6px;
}
.wm-zoom-group button {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-2, #a0a3ad);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.wm-zoom-group button:hover {
  background: var(--bg-4, #262932);
  color: var(--text-1, #e8e8f0);
}
.wm-zoom-label {
  min-width: 44px;
  text-align: center;
  font-size: 12px;
  color: var(--text-2, #a0a3ad);
  user-select: none;
}

/* ── Viewport (canvas container) ─────────────────────────── */
.worldmap-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a1620;
  cursor: grab;
}

/* In cover/hero mode the tile grid always fills the viewport — no dark background needed */
.hero-map-canvas .worldmap-viewport {
  background: transparent;
}
.worldmap-viewport.dragging {
  cursor: grabbing;
}
.worldmap-viewport.placing-entity {
  cursor: crosshair;
}

.wm-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.wm-stage canvas,
.wm-stage svg,
.wm-tile-grid canvas,
.wm-tile-grid svg {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  /* Smooth scaling for the baked map. Crisp tile detail when zoomed in is
     provided by the screen-space #wm-detail overlay (renders real tiles at the
     live zoom); nearest-neighbour here just made the low-res bake look blocky. */
  image-rendering: auto;
}

#wm-terrain {
  z-index: 1;
}
#wm-tiles {
  z-index: 2;
}
#wm-entities {
  z-index: 3;
  pointer-events: none;
}
#wm-labels {
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}
#wm-interactive {
  z-index: 5;
}

/* ── Entity markers (interactive layer) ──────────────────── */
.wm-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: grab;
  user-select: none;
  z-index: 5;
}
.wm-marker.dragging {
  cursor: grabbing;
  z-index: 100;
}
.wm-marker:hover .wm-marker-icon {
  filter: brightness(1.3) drop-shadow(0 0 4px rgba(255, 220, 100, 0.8));
}
.wm-marker-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #2a2418;
  background: #f0e6c8;
  border: 2px solid #2a2418;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  transition: filter 0.15s;
}
.wm-marker.city .wm-marker-icon {
  background: #e8d088;
  border-color: #4a3818;
}
.wm-marker.capital .wm-marker-icon {
  background: #ffd700;
  border-color: #4a3818;
  width: 28px;
  height: 28px;
  font-size: 18px;
}
.wm-marker.village .wm-marker-icon {
  background: #d8c898;
  border-color: #5a4828;
  width: 16px;
  height: 16px;
  font-size: 12px;
}
.wm-marker.landmark .wm-marker-icon {
  background: #c8a878;
  border-color: #4a2818;
  border-radius: 4px;
  transform: rotate(45deg);
}
.wm-marker.landmark .wm-marker-icon > * {
  transform: rotate(-45deg);
}
.wm-marker.fortress .wm-marker-icon {
  background: #a89878;
  border-color: #2a1818;
  border-radius: 2px;
}
.wm-marker.port .wm-marker-icon {
  background: #88b8d8;
  border-color: #18384a;
}
.wm-marker-label {
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  font-weight: 600;
  color: #2a2418;
  text-shadow:
    -1px -1px 0 #f0e6c8,
    1px -1px 0 #f0e6c8,
    -1px 1px 0 #f0e6c8,
    1px 1px 0 #f0e6c8,
    0 0 3px rgba(240, 230, 200, 0.8);
  pointer-events: none;
}
.wm-marker.capital .wm-marker-label {
  font-size: 13px;
  font-weight: 700;
}

/* ── Country & continent labels (SVG) ───────────────────── */
.wm-country-label {
  font-family: 'Cinzel', Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 600;
  fill: #4a3818;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(240, 230, 200, 0.7);
  stroke-width: 3px;
  pointer-events: none;
}
.wm-continent-label {
  font-family: 'Cinzel', Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 4px;
  text-transform: uppercase;
  fill: #2a1810;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(240, 230, 200, 0.6);
  stroke-width: 4px;
  opacity: 0.5;
  pointer-events: none;
}

/* ── Minimap ─────────────────────────────────────────────── */
.wm-minimap {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 160px;
  height: 110px;
  background: rgba(20, 30, 40, 0.85);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 4px;
  overflow: hidden;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.wm-minimap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}
.wm-minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--accent, #7c5cfc);
  background: rgba(124, 92, 252, 0.15);
  pointer-events: none;
}

/* ── HUD — Elevation / Climate Info Strip ──────────────────── */
.wm-hud {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: rgba(10, 14, 22, 0.80);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 20px;
  font-size: 12px;
  font-family: Georgia, serif;
  color: #c8c8d8;
  pointer-events: none;
  z-index: 60;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.wm-hud-biome {
  color: #e0d8b0;
  font-weight: bold;
  letter-spacing: 0.02em;
}
.wm-hud-stat {
  color: #a8b8c8;
}
.wm-hud-sep {
  color: rgba(255,255,255,0.20);
  font-size: 10px;
}

/* ── Info / loading overlay ──────────────────────────────── */
.wm-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(10, 14, 22, 0.85);
  z-index: 200;
  color: var(--text-1, #e8e8f0);
  font-size: 14px;
}
.wm-loader-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-4, #262932);
  border-top-color: var(--accent, #7c5cfc);
  border-radius: 50%;
  animation: wm-spin 0.8s linear infinite;
}
@keyframes wm-spin {
  to {
    transform: rotate(360deg);
  }
}

.wm-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(10, 14, 22, 0.6);
  z-index: 10;
  pointer-events: none;
  color: var(--text-2, #a0a3ad);
}
.wm-empty-hint i {
  width: 48px;
  height: 48px;
  opacity: 0.4;
}

/* ── Settings modal extras ───────────────────────────────── */
.wm-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.wm-settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-2, #a0a3ad);
}
.wm-settings-grid input[type="number"],
.wm-settings-grid select {
  padding: 6px 8px;
  background: var(--bg-3, #1e2129);
  color: var(--text-1, #e8e8f0);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 4px;
  font-size: 13px;
}
.wm-settings-grid input[type="range"] {
  width: 100%;
}
.wm-settings-grid .wm-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

/* ── Map Generation Settings Panel (collapsible, top-left) ─── */
.worldmap-root {
  position: relative; /* ensure absolute children are positioned inside it */
}
.wm-genset-panel {
  position: fixed;
  z-index: 200;
  width: 264px;
  transition: left 0.22s ease;
  background: rgba(15, 17, 25, 0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(124, 92, 252, 0.45);
  border-top: 2px solid var(--accent, #7c5cfc);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255,255,255,0.05);
  color: var(--text-1, #e8e8f0);
  overflow: hidden;
  pointer-events: all;
}
.wm-genset-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.wm-genset-header:hover {
  background: rgba(255, 255, 255, 0.04);
}
.wm-genset-panel:not(.collapsed) .wm-genset-header {
  border-bottom-color: var(--border-1, #2a2d38);
}
.wm-genset-header > i:first-child {
  width: 15px;
  height: 15px;
  color: var(--accent, #7c5cfc);
  flex-shrink: 0;
}
.wm-genset-header-title {
  flex: 1;
}
.wm-genset-chevron {
  width: 13px !important;
  height: 13px !important;
  color: var(--text-2, #a0a3ad) !important;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.wm-genset-panel:not(.collapsed) .wm-genset-chevron {
  transform: rotate(180deg);
}
.wm-genset-body {
  max-height: 62vh;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wm-genset-panel.collapsed .wm-genset-body {
  display: none;
}
.wm-genset-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3, #606270);
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px solid var(--border-1, #2a2d38);
}
.wm-genset-section:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}
.wm-genset-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-2, #a0a3ad);
}
.wm-genset-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wm-genset-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent, #7c5cfc);
}
.wm-genset-row .wm-gs-val {
  font-size: 11px;
  color: var(--text-2, #a0a3ad);
  min-width: 30px;
  text-align: right;
}
.wm-genset-label input[type="number"],
.wm-genset-label select {
  padding: 5px 8px;
  background: var(--bg-3, #1e2129);
  color: var(--text-1, #e8e8f0);
  border: 1px solid var(--border-1, #2a2d38);
  border-radius: 5px;
  font-size: 12px;
  width: 100%;
}
.wm-genset-label input[type="number"]:focus,
.wm-genset-label select:focus {
  outline: none;
  border-color: var(--accent, #7c5cfc);
}
.wm-genset-checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-2, #a0a3ad);
  cursor: pointer;
  user-select: none;
}
.wm-genset-checkbox input[type="checkbox"] {
  accent-color: var(--accent, #7c5cfc);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.wm-genset-apply {
  width: 100%;
  padding: 8px 12px;
  background: var(--accent, #7c5cfc);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
  margin-top: 2px;
}
.wm-genset-apply:hover {
  filter: brightness(1.12);
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  .worldmap-toolbar .wm-btn span {
    display: none;
  }
  .worldmap-toolbar .wm-btn {
    padding: 6px 8px;
  }
  .wm-minimap {
    width: 100px;
    height: 70px;
  }
}
