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

/* ── Loading screen ──────────────────────────────────────────────────────── */
#map-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  transition: opacity 0.8s ease;
}
#map-loader.fade-out { opacity: 0; pointer-events: none; }

#map-loader #ml-bg, #map-loader .ml-bg2 {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  aspect-ratio: 1672 / 941;
  transform: translateX(-50%);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  /* Imagen a TODO el alto, centrada; los costados se funden en el negro del fondo
     (sin corte seco cuando la pantalla es más ancha que la imagen). */
  -webkit-mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,.2) 4%, rgba(0,0,0,.55) 8%, rgba(0,0,0,.85) 12%, #000 16%, #000 84%, rgba(0,0,0,.85) 88%, rgba(0,0,0,.55) 92%, rgba(0,0,0,.2) 96%, transparent 100%);
          mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,.2) 4%, rgba(0,0,0,.55) 8%, rgba(0,0,0,.85) 12%, #000 16%, #000 84%, rgba(0,0,0,.85) 88%, rgba(0,0,0,.55) 92%, rgba(0,0,0,.2) 96%, transparent 100%);
  opacity: 0;
  transition: opacity 0.8s ease;
}

#ml-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom,
      rgba(4,2,12,0.55) 0%,
      rgba(4,2,12,0.05) 35%,
      rgba(4,2,12,0.05) 60%,
      rgba(4,2,12,0.80) 85%,
      rgba(4,2,12,0.97) 100%),
    linear-gradient(to right,
      rgba(4,2,12,0.40) 0%,
      transparent 20%,
      transparent 80%,
      rgba(4,2,12,0.40) 100%);
}

/* Logo top-left */
#ml-logo-img {
  position: absolute;
  top: 28px;
  left: 32px;
  height: 108px;
  width: auto;
  filter: drop-shadow(0 2px 16px rgba(0,0,0,0.85));
  z-index: 1;
}

/* ── Fantasy progress bar ── */
#ml-bar-wrap {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 82vw);
  text-align: center;
  z-index: 1;
}

#ml-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.ml-rune {
  font-size: 1rem;
  color: #8a6830;
  flex-shrink: 0;
  text-shadow: 0 0 8px rgba(200,160,60,.5);
  animation: runeGlow 2s ease-in-out infinite alternate;
}
@keyframes runeGlow {
  from { color: #6a4820; text-shadow: 0 0 4px rgba(200,160,60,.2); }
  to   { color: #d4a840; text-shadow: 0 0 14px rgba(220,180,80,.7); }
}

#ml-bar-track {
  flex: 1;
  height: 22px;
  position: relative;
  background: linear-gradient(180deg, #0c0818 0%, #14102a 50%, #0c0818 100%);
  border: 1px solid #3a2850;
  border-radius: 3px;
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,0.8),
    inset 0 -1px 3px rgba(0,0,0,0.5),
    0 0 12px rgba(80,40,120,0.3);
  overflow: hidden;
}

/* Decorative notch lines on the track */
#ml-bar-notches {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-evenly;
  pointer-events: none;
  z-index: 3;
}
#ml-bar-notches span {
  width: 1px;
  background: linear-gradient(180deg, transparent 20%, rgba(80,50,120,0.4) 50%, transparent 80%);
}

#ml-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(180deg,
    #d4a030 0%,
    #a87020 20%,
    #e8c060 45%,
    #a06018 70%,
    #c8902a 100%
  );
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 18px rgba(220,160,40,0.5), inset 0 1px 2px rgba(255,220,120,0.4);
  z-index: 1;
}

/* Animated shimmer sweep */
#ml-bar-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255,240,180,0.55) 48%,
    rgba(255,255,220,0.70) 50%,
    rgba(255,240,180,0.55) 52%,
    transparent 70%
  );
  animation: barShimmer 1.8s linear infinite;
}
@keyframes barShimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(400%);  }
}

/* Leading-edge spark glow */
#ml-bar-sparks {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 18px;
  background: linear-gradient(90deg, transparent, rgba(255,230,130,0.9));
  filter: blur(3px);
  border-radius: 0 2px 2px 0;
}

#ml-bar-label {
  font-family: 'Georgia', serif;
  font-size: 0.68rem;
  letter-spacing: 2.5px;
  color: #6a5480;
  text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

body {
  background: #0a0a0f;
  color: #ccc;
  font-family: 'Georgia', serif;
  overflow: hidden;
  height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 48px;
  background: rgba(10,8,20,0.95);
  border-bottom: 1px solid #3a2050;
  flex-shrink: 0;
  z-index: 1000;
}

#topbar .logo { color: #c8a850; font-size: 1rem; letter-spacing: 2px; white-space: nowrap; }

#continent-select {
  background: #1a1030;
  border: 1px solid #4a3060;
  color: #ccc;
  padding: 4px 10px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.85rem;
}

.resource-bar {
  display: flex;
  gap: 14px;
  font-size: 0.8rem;
  color: #aaa;
  margin-left: auto;
}
.resource-bar span { display: flex; align-items: center; gap: 4px; }
.resource-bar .val { color: #e8c870; }

#player-info { font-size: 0.8rem; color: #9a89a0; white-space: nowrap; }

.btn-mode {
  padding: 5px 12px;
  background: #2a1840;
  border: 1px solid #5a3080;
  color: #c8a850;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  transition: all .2s;
  white-space: nowrap;
}
.btn-mode:hover { background: #3a2050; }
.btn-mode.active { background: #5a3090; border-color: #c8a850; }

/* ── Map container ───────────────────────────────────────────────────────── */
#map-container {
  flex: 1;
  position: relative;
  cursor: grab;
}
#map-container:active { cursor: grabbing; }
#map-container.build-mode { cursor: crosshair; }

/* Leaflet default overrides */
.leaflet-container { background: #0a0a2a; }
.leaflet-tile-pane { image-rendering: pixelated; }

/* ── Entity markers ──────────────────────────────────────────────────────── */
.entity-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  /* Small markers (dungeons, rebels, resources, armies) stay legible at every
     zoom: they barely shrink when zooming out. transform-origin matches
     iconAnchor [20, 40]. */
  transform-origin: 50% 40px;
  transform: scale(var(--icon-scale, 1));
}
.entity-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}
.entity-sprite {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}
/* Dungeons +40%: los que NO tienen imagen propia muestran el emoji placeholder
   (los que sí tienen sprite escalan vía ENTITY_WORLD_SIZE en map.js). */
.etype-dungeon .entity-icon   { font-size: 3.36rem; }
.etype-dungeon .entity-sprite { width: 84px; height: 84px; }
/* Entidades estáticas como imageOverlay: escalan con el zoom de forma nativa. */
.world-entity {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.55));
  cursor: pointer;
}
/* Marcha Libre: avatar controlable + cursor del modo */
.ml-avatar {
  filter: drop-shadow(0 4px 7px rgba(0,0,0,0.6));
  pointer-events: none;
  object-fit: contain;          /* preserva proporción (no estira) */
  transition: opacity 0.11s ease;  /* crossfade suave al cambiar de dirección */
}
.ml-avatar-fallback { font-size: 40px; line-height: 1; filter: drop-shadow(0 3px 5px rgba(0,0,0,0.85)); }
#map-container.ml-mode { cursor: crosshair; }

/* Marca de destino: anillo de aterrizaje + marquita + temporizador */
.ml-target { position: relative; }
.ml-target-ring {
  position: absolute; left: 0; top: 0; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border: 3px solid #7cd4ff; border-radius: 50%;
  animation: mlPulse 1.1s ease-out infinite;
}
@keyframes mlPulse { 0% { transform: scale(.45); opacity: .95; } 100% { transform: scale(1.5); opacity: 0; } }
.ml-target-dot {
  position: absolute; left: 0; top: 0; width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; background: #7cd4ff; box-shadow: 0 0 9px #7cd4ff;
}
.ml-target-timer {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -30px);
  background: rgba(0,0,0,.74); color: #cfefff; font-size: .72rem; font-weight: 600;
  padding: 1px 7px; border-radius: 4px; white-space: nowrap;
}
/* al llegar: corta el pulso, deja la marquita y la desvanece */
.ml-target.landed .ml-target-ring,
.ml-target.landed .ml-target-timer { display: none; }
.ml-target.landed .ml-target-dot { animation: mlFade 4s ease-out forwards; }
@keyframes mlFade { 0% { opacity: .9; transform: scale(1.7); } 100% { opacity: 0; transform: scale(.5); } }
/* Etiqueta de nombre (tooltip permanente): tamaño FIJO, no escala con el zoom. */
.leaflet-tooltip.entity-tip {
  background: rgba(0,0,0,0.72);
  color: #eee;
  border: none;
  box-shadow: none;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.leaflet-tooltip.entity-tip::before { display: none; }  /* sin flechita */
.entity-label {
  background: rgba(0,0,0,0.75);
  color: #eee;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 2px;
  white-space: nowrap;
  margin-top: 2px;
  pointer-events: none;
}
.entity-label.faction-humans    { border-left: 2px solid #4a90d9; }
.entity-label.faction-darkones  { border-left: 2px solid #c03030; }
.entity-label.faction-celestials{ border-left: 2px solid #d4a820; }

/* ── City markers ─────────────────────────────────────────────────────────── */
.city-marker {
  position: relative;
  /* transform-origin must match iconAnchor [88, 176] — bottom-center of the 176px image */
  transform-origin: 50% 176px;
  /* Cities (big 176px sprite) keep the proportional zoom curve so they sit on
     the terrain naturally. */
  transform: scale(var(--entity-scale, 1));
}

.city-img-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.city-img {
  width: 176px;
  height: 176px;
  object-fit: contain;
  image-rendering: auto;
}
.city-emoji { font-size: 4.8rem; line-height: 1; }
.city-marker:hover .city-img { filter: brightness(1.15); }

/* Faction glow on hover */
.city-faction-celestials .city-img {
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.75)) drop-shadow(0 0 8px rgba(130,180,255,.4));
}
.city-faction-celestials:hover .city-img {
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.85)) drop-shadow(0 0 18px rgba(130,180,255,.75));
}
.city-faction-humans .city-img {
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.75)) drop-shadow(0 0 8px rgba(74,144,217,.4));
}
.city-faction-humans:hover .city-img {
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.85)) drop-shadow(0 0 18px rgba(74,144,217,.75));
}
.city-faction-darkones .city-img {
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.75)) drop-shadow(0 0 8px rgba(192,48,48,.4));
}
.city-faction-darkones:hover .city-img {
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.85)) drop-shadow(0 0 18px rgba(192,48,48,.75));
}

/* Army march line */
.march-line { stroke-dasharray: 8 4; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -24; } }

/* ── Info popup ──────────────────────────────────────────────────────────── */
#entity-popup {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,8,20,0.97);
  border: 1px solid #4a3060;
  border-radius: 4px;
  padding: 16px 20px;
  min-width: 240px;
  z-index: 900;
  display: none;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
}
#entity-popup.visible { display: block; }
#entity-popup h3 { color: #c8a850; margin-bottom: 8px; font-size: 1rem; }
#entity-popup .detail { font-size: 0.8rem; color: #aaa; margin-bottom: 4px; }
#entity-popup .actions { display: flex; gap: 8px; margin-top: 12px; }
#entity-popup .actions button {
  flex: 1; padding: 7px;
  background: #2a1840; border: 1px solid #5a3080;
  color: #ccc; border-radius: 3px; cursor: pointer;
  font-family: inherit; font-size: 0.8rem; transition: background .2s;
}
#entity-popup .actions button:hover { background: #3a2050; }
.popup-close {
  position: absolute; top: 8px; right: 10px;
  cursor: pointer; color: #7a6890; font-size: 1rem;
}

/* ── Army detail panel (inside entity popup) ─────────────────────────────── */
.army-detail { margin: 8px 0 4px; }
.army-detail.hidden { display: none !important; }
.army-detail-loading { font-size: 0.78rem; color: #7a6890; }

.ad-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ad-mission { font-size: 0.85rem; font-weight: 700; color: #c8a850; }
.ad-status {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 3px;
}
.ad-status.traveling { background: rgba(74,124,247,.2); color: #7aaeff; }
.ad-status.returning { background: rgba(76,175,119,.2); color: #6ecf99; }

.ad-countdown {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.05);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 4px;
}
.ad-cd-label { font-size: 0.75rem; color: #9a89a0; }
.ad-cd-val   { font-size: 0.9rem; font-weight: 700; color: #e8c870; margin-left: auto; font-variant-numeric: tabular-nums; }

.ad-return-eta {
  font-size: 0.75rem;
  color: #7a8a70;
  margin-bottom: 8px;
  padding-left: 2px;
}

.ad-section {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #5a4870;
  margin: 8px 0 4px;
  border-top: 1px solid #2a1840;
  padding-top: 6px;
}

.ad-units, .ad-cargo { display: flex; flex-direction: column; gap: 3px; }
.ad-empty { font-size: 0.78rem; color: #5a4870; padding-left: 2px; }

.ad-unit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}
.ad-u-icon { font-size: 1rem; flex-shrink: 0; }
.ad-u-name { flex: 1; color: #c8c0d8; }
.ad-u-tier { font-size: 0.68rem; background: rgba(74,124,247,.2); color: #7aaeff; border-radius: 2px; padding: 0 3px; }
.ad-u-qty  { font-weight: 700; color: #e8c870; white-space: nowrap; }

.ad-cargo-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}
.ad-c-name { flex: 1; color: #c8c0d8; }
.ad-c-val  { font-weight: 600; color: #d4dae8; white-space: nowrap; }

/* ── Build hint ──────────────────────────────────────────────────────────── */
#build-hint {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(90,48,144,0.92);
  color: #fff;
  padding: 8px 20px;
  border-radius: 3px;
  font-size: 0.85rem;
  z-index: 900;
  display: none;
  pointer-events: none;
}
#build-hint.visible { display: block; }

/* ── Status bar ──────────────────────────────────────────────────────────── */
#statusbar {
  height: 26px;
  background: rgba(10,8,20,0.95);
  border-top: 1px solid #2a1840;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 0.72rem;
  color: #7a6890;
  flex-shrink: 0;
  gap: 16px;
}
#statusbar #coords { color: #9a89a0; }
#statusbar #status-msg { margin-left: auto; }

/* ── Route-line filter panel ─────────────────────────────────────────────── */
#route-filters {
  position: absolute;
  bottom: 34px;
  right: 12px;
  z-index: 900;
  background: rgba(10,8,20,0.9);
  border: 1px solid #2a1840;
  border-radius: 7px;
  padding: 8px 11px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  user-select: none;
  pointer-events: all;
}
.rf-title {
  font-size: 0.65rem;
  color: #5a4870;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding-bottom: 4px;
  border-bottom: 1px solid #1e1430;
}
.rf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.78rem;
  color: #c0b0d0;
  transition: color .15s;
}
.rf-item:hover { color: #e0d0f0; }
.rf-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity .2s;
}
.rf-label { flex: 1; }

/* Toggle switch */
.rf-toggle {
  flex-shrink: 0;
  width: 30px;
  height: 16px;
  border-radius: 8px;
  background: #3a8c5a;
  position: relative;
  transition: background .2s;
}
.rf-toggle::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 16px;
  transition: left .2s;
}

/* OFF state */
.rf-item.off .rf-dot       { opacity: 0.3; }
.rf-item.off .rf-label     { opacity: 0.45; }
.rf-item.off .rf-toggle    { background: #2a1e38; }
.rf-item.off .rf-toggle::after { left: 2px; }

/* Pulsing city-slot marker for MapMaker continents */
.city-slot-pulse {
  width: 40px !important;
  height: 40px !important;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.25);
  border: 2px solid #4ade80;
  animation: city-slot-pulse 2.4s ease-in-out infinite;
  cursor: pointer;
}
@keyframes city-slot-pulse {
  0%,100% { transform: scale(1);   opacity: 0.9; box-shadow: 0 0 0 0 rgba(74,222,128,0.6); }
  50%      { transform: scale(1.4); opacity: 0.4; box-shadow: 0 0 0 12px rgba(74,222,128,0); }
}

/* MM-zone markers (dungeon/boss/resource/rebel) */
.mm-zone-marker {
  font-size: 22px;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.8));
  cursor: pointer;
  transition: transform .15s;
}
.mm-zone-marker:hover { transform: scale(1.3); }
