.map-panel {
  grid-column: 1 / -1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.map-scroll {
  width: 100%;
  max-width: 100%;
  margin-top: 18px;
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.56);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.world-map {
  display: grid;
  grid-template-columns: repeat(var(--map-width), 30px);
  width: max-content;
  max-width: none;
  gap: 2px;
}

.map-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  isolation: isolate;
}

.map-tile::before,
.map-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.map-tile::before {
  z-index: -1;
  opacity: 0;
}

.map-tile::after {
  z-index: 3;
  opacity: 0;
}

.map-tile--ocean { background: rgba(14, 116, 144, 0.55); }
.map-tile--plains { background: rgba(101, 163, 13, 0.42); }
.map-tile--forest { background: rgba(21, 128, 61, 0.55); }
.map-tile--mountain { background: rgba(100, 116, 139, 0.55); }

.map-tile--territory-human::before { background: rgba(56, 189, 248, 0.34); opacity: 1; }
.map-tile--territory-forestfolk::before { background: rgba(74, 222, 128, 0.34); opacity: 1; }
.map-tile--territory-stonefolk::before { background: rgba(226, 232, 240, 0.28); opacity: 1; }
.map-tile--territory-wanderers::before { background: rgba(251, 191, 36, 0.34); opacity: 1; }

.map-tile--road {
  color: #f8fafc;
  font-weight: 900;
  text-shadow: 0 0 3px #0f172a;
}

.map-tile--road::after {
  opacity: 1;
  inset: 44% -1px auto;
  height: 4px;
  border-radius: 999px;
  background: #f8fafc;
  box-shadow: 0 0 5px rgba(248, 250, 252, 0.9);
}

.map-tile--effect-rain::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(125, 211, 252, 0.95), 0 0 8px rgba(56, 189, 248, 0.7);
  animation: rain-pulse 1.8s ease-in-out infinite;
}

.map-tile--effect-sun::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(253, 224, 71, 0.9);
  background: radial-gradient(circle, rgba(253, 224, 71, 0.42), transparent 70%);
}

.map-tile--effect-wind::after {
  opacity: 1;
  border-top: 2px solid rgba(186, 230, 253, 0.95);
  border-bottom: 2px solid rgba(186, 230, 253, 0.55);
  transform: skewX(-18deg) scale(0.86);
}

.map-tile--effect-abundance::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(190, 242, 100, 0.95), 0 0 8px rgba(132, 204, 22, 0.58);
}

.map-tile--effect-earth::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(251, 146, 60, 0.92);
  background: repeating-linear-gradient(45deg, transparent 0 5px, rgba(251, 146, 60, 0.28) 5px 7px);
}

.map-tile--settled {
  z-index: 4;
  border-width: 2px;
  font-size: 1.12rem;
}

.map-tile--stage-camp { box-shadow: 0 0 5px rgba(250, 204, 21, 0.5); }
.map-tile--stage-village { box-shadow: 0 0 9px rgba(250, 204, 21, 0.78); transform: scale(1.04); }
.map-tile--stage-town { box-shadow: 0 0 13px rgba(250, 204, 21, 0.95); transform: scale(1.1); }
.map-tile--stage-city { box-shadow: 0 0 17px rgba(244, 114, 182, 0.98); transform: scale(1.16); }

.settlement-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.settlement-stage-icon {
  position: relative;
  z-index: 1;
  font-size: 0.9em;
}

.settlement-marker--village .settlement-stage-icon { font-size: 1em; }
.settlement-marker--town .settlement-stage-icon { font-size: 1.08em; }
.settlement-marker--city .settlement-stage-icon { font-size: 1.14em; }

.settlement-race-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: #0f172a;
  font-size: 8px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.7);
}

.map-tile--race-human { border-color: #38bdf8; }
.map-tile--race-forestfolk { border-color: #4ade80; }
.map-tile--race-stonefolk { border-color: #e2e8f0; }
.map-tile--race-wanderers { border-color: #fbbf24; }

.map-tile:focus-visible {
  outline: 2px solid #f8fafc;
  outline-offset: 1px;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 12px 0 0;
  color: #94a3b8;
  font-size: 0.86rem;
}

.settlement-details {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(125, 211, 252, 0.22);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.5);
  color: #cbd5e1;
}

.settlement-details strong { color: #f8fafc; }

@keyframes rain-pulse {
  50% { filter: brightness(1.35); }
}

@media (max-width: 720px) {
  .map-scroll {
    overflow: hidden;
    padding: 5px;
  }

  .world-map {
    grid-template-columns: repeat(var(--map-width), minmax(0, 1fr));
    width: 100%;
    gap: 1px;
  }

  .map-tile {
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    aspect-ratio: 1;
    border-radius: 3px;
    font-size: clamp(0.42rem, 2.25vw, 0.68rem);
    overflow: visible;
  }

  .map-tile--settled { font-size: clamp(0.58rem, 2.8vw, 0.82rem); }
  .map-tile--stage-village { transform: scale(1.06); }
  .map-tile--stage-town { transform: scale(1.14); }
  .map-tile--stage-city { transform: scale(1.2); }

  .map-tile--road::after {
    height: 3px;
  }

  .settlement-race-badge {
    top: -2px;
    right: -2px;
    width: clamp(8px, 2.2vw, 12px);
    height: clamp(8px, 2.2vw, 12px);
    font-size: clamp(5px, 1.25vw, 7px);
  }

  .map-legend {
    gap: 6px 12px;
    font-size: 0.78rem;
  }
}