:root {
  --bg: #0B0811;
  --map-bg: #120B1C;
  --panel: #16101F;
  --panel-2: #1C1428;
  --panel-3: #23182F;
  --card: rgba(255,255,255,.035);
  --border: rgba(255,255,255,.085);
  --border-strong: rgba(255,255,255,.14);
  --text: #FFFFFF;
  --text-soft: #EEE6F7;
  --muted: #BCAFCB;
  --muted-2: #8D8199;
  --purple: #833AB4;
  --pink: #E1306C;
  --orange: #FF5F1F;
  --selection: #FFD166;
  --good: #72D995;
  --warn: #F0C76A;
  --danger: #FF7D7D;
  --ocean: #1B4057;
  --plains: #3E714C;
  --forest: #234E31;
  --hills: #765837;
  --mountains: #17101F;
  --sidebar-width: 390px;
  --shadow: 0 22px 55px rgba(0,0,0,.34);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, summary { font: inherit; }
button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--selection);
  outline-offset: 2px;
}

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  width: 100vw;
  height: 100vh;
  background: var(--bg);
}

#mapShell {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 42%, rgba(131,58,180,.10), transparent 42%),
    radial-gradient(circle at 78% 68%, rgba(225,48,108,.045), transparent 26%),
    var(--map-bg);
}

#mapShell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset -18px 0 40px rgba(0,0,0,.22);
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
#map:active { cursor: grabbing; }

/* ===== Floating map HUD ===== */
.map-topbar {
  position: absolute;
  z-index: 20;
  top: 16px;
  left: 16px;
  right: 16px;
  min-height: 72px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(22,16,31,.93), rgba(16,11,24,.88));
  box-shadow: 0 14px 36px rgba(0,0,0,.30);
  backdrop-filter: blur(14px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 165px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  background: transparent;
}
.brand-mark img { display: block; width: 100%; height: 100%; }
.topbar-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.topbar-version {
  margin-top: 3px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.topbar-metrics {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(90px, 1fr));
  gap: 7px;
}
.metric-chip {
  min-width: 0;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 11px;
  background: rgba(255,255,255,.035);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.metric-chip.metric-emphasis {
  background: linear-gradient(135deg, rgba(131,58,180,.16), rgba(225,48,108,.08));
  border-color: rgba(225,48,108,.20);
}
.metric-label {
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-chip strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-chip strong.positive { color: var(--good); }
.metric-chip strong.negative { color: var(--danger); }

.sim-cluster {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 3px;
}
.sim-state {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}
.sim-state span {
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.sim-state strong { margin-top: 4px; font-size: 12px; }

.speed-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.compact-speed-row { width: 210px; }
.speed-row button {
  min-height: 34px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  background: rgba(255,255,255,.045);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition: transform .14s ease, border-color .14s ease, background .14s ease, filter .14s ease;
}
.speed-row button:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.18); }
.speed-row button.active {
  border-color: transparent;
  background: linear-gradient(90deg, var(--purple), var(--pink), var(--orange));
  color: #fff;
  box-shadow: 0 5px 12px rgba(225,48,108,.18);
}
.square-btn.paused {
  color: var(--selection);
  border-color: rgba(255,209,102,.45);
  background: rgba(255,209,102,.08);
}

/* ===== Sidebar ===== */
#sidebar {
  position: relative;
  z-index: 30;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 16px 22px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.018), transparent 180px),
    var(--panel);
  border-left: 1px solid rgba(255,255,255,.07);
  box-shadow: -18px 0 42px rgba(0,0,0,.22);
  scrollbar-width: thin;
  scrollbar-color: #4A3A59 transparent;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: #4A3A59; border-radius: 999px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar-head {
  min-height: 52px;
  padding: 2px 3px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sidebar-eyebrow {
  margin-bottom: 3px;
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.sidebar-head h2 {
  font-size: 22px;
  line-height: 1;
  letter-spacing: -.03em;
}
.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 5px rgba(114,217,149,.09), 0 0 16px rgba(114,217,149,.30);
}

.panel {
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.018));
  box-shadow: 0 10px 24px rgba(0,0,0,.12);
}
.selection-panel {
  min-height: 210px;
  border-color: rgba(255,255,255,.10);
  background:
    linear-gradient(180deg, rgba(131,58,180,.035), transparent 120px),
    var(--panel-2);
}

.hidden { display: none !important; }

.selection-empty {
  min-height: 176px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 22px 20px;
  border: 1px dashed rgba(255,255,255,.10);
  border-radius: 13px;
  background: rgba(255,255,255,.018);
}
.selection-empty-icon {
  width: 46px;
  height: 46px;
  margin-bottom: 12px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(131,58,180,.22), rgba(225,48,108,.12));
  color: #FFD6EA;
  font-size: 25px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.selection-empty strong {
  margin-bottom: 6px;
  font-size: 14px;
}
.selection-empty span {
  max-width: 260px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.detail-stack { display: grid; gap: 12px; }
.selection-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.selection-kind {
  margin-bottom: 5px;
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .11em;
}
.city-name {
  color: var(--text);
  font-size: 20px;
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -.025em;
}

.section-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.section-block.first-section { margin-top: 4px; }
.panel-subtitle {
  margin: 0 0 8px;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .01em;
}
.detail-card {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  background: rgba(0,0,0,.10);
}
.detail-card .stat-row {
  min-height: 31px;
  padding: 0 10px;
  border-bottom: 1px solid rgba(255,255,255,.045);
}
.detail-card .stat-row:last-child { border-bottom: 0; }
.compact-card .stat-row { min-height: 29px; }

.stat-row {
  min-height: 29px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 11px;
}
.stat-row span { color: var(--muted); }
.stat-row strong {
  color: var(--text);
  text-align: right;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.stat-row strong.positive { color: var(--good); }
.stat-row strong.negative { color: var(--danger); }

.resource-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.resource-card {
  min-height: 58px;
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 11px;
  background: rgba(255,255,255,.025);
}
.resource-card span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.resource-card strong {
  margin-top: 8px;
  font-size: 17px;
  line-height: 1;
}
.resource-card-wood { border-left: 3px solid #69B773; }
.resource-card-ore { border-left: 3px solid #AEB5C5; }
.resource-card-fish { border-left: 3px solid #64D2E8; }
.resource-card-grain { border-left: 3px solid #E7C86C; }
.resource-card-lumber { border-left: 3px solid #D79A54; }
.resource-card-metal { border-left: 3px solid #D7DDEA; }

.action-hint {
  margin-top: 8px;
  padding: 8px 9px;
  border: 1px solid rgba(255,209,102,.12);
  border-radius: 9px;
  background: rgba(255,209,102,.055);
  color: #F2D992;
  font-size: 10px;
  line-height: 1.45;
}

.divider { display: none; }

.primary-btn,
.secondary-btn,
.danger-btn {
  width: 100%;
  min-height: 38px;
  padding: 9px 11px;
  margin-top: 8px;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  transition: transform .14s ease, border-color .14s ease, filter .14s ease, background .14s ease;
}
.primary-btn {
  border: 0;
  background: linear-gradient(95deg, var(--purple), var(--pink), var(--orange));
  box-shadow: 0 7px 16px rgba(225,48,108,.14);
}
.secondary-btn {
  border: 1px solid rgba(255,255,255,.11);
  background: rgba(255,255,255,.045);
}
.danger-btn {
  border: 1px solid rgba(255,95,31,.26);
  background: rgba(255,95,31,.07);
  color: #FFD4C7;
}
.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:disabled {
  cursor: not-allowed;
  opacity: .42;
  filter: none !important;
  transform: none !important;
}
.primary-btn.unaffordable,
.secondary-btn.unaffordable {
  opacity: .60;
  box-shadow: none;
  outline: 1px solid rgba(255,125,125,.22);
}

.two-col-actions,
.save-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.two-col-actions .primary-btn,
.two-col-actions .secondary-btn,
.two-col-actions .danger-btn,
.save-row .secondary-btn { margin-top: 8px; }

.road-destination-list {
  display: grid;
  gap: 7px;
  margin-top: 7px;
}
.road-destination-list.hidden { display: none; }
.road-destination-btn { margin-top: 0; }
.active-target-btn {
  border-color: rgba(255,209,102,.72) !important;
  color: var(--selection) !important;
  background: rgba(255,209,102,.07) !important;
}

.build-feedback {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 0 11px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 10px;
  line-height: 1.4;
  border: 1px solid rgba(255,255,255,.10);
  background: #21182C;
  box-shadow: 0 10px 25px rgba(0,0,0,.18);
}
.build-feedback.success {
  color: #A8F2BE;
  border-color: rgba(85,194,113,.28);
  background: #15261B;
}
.build-feedback.error {
  color: #FFB0B0;
  border-color: rgba(255,95,95,.28);
  background: #2A171B;
}

/* ===== Utility drawers ===== */
.sidebar-utilities {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.utility-drawer {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 13px;
  background: rgba(255,255,255,.025);
}
.utility-drawer summary {
  list-style: none;
  cursor: pointer;
  min-height: 49px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--text-soft);
  user-select: none;
}
.utility-drawer summary::-webkit-details-marker { display: none; }
.utility-drawer summary::after {
  content: "+";
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255,255,255,.045);
  color: var(--muted);
  font-size: 14px;
  transition: transform .18s ease;
}
.utility-drawer[open] summary::after { content: "−"; }
.utility-drawer summary span {
  display: block;
  font-size: 11px;
  font-weight: 800;
}
.utility-drawer summary small {
  grid-column: 1;
  color: var(--muted-2);
  font-size: 9px;
  line-height: 1.2;
}
.drawer-content {
  padding: 3px 12px 12px;
  border-top: 1px solid rgba(255,255,255,.055);
}
.drawer-content > .stat-row { min-height: 27px; }

/* ===== Map helper UI ===== */
.map-hint {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 13px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  background: rgba(12,8,18,.80);
  color: rgba(255,255,255,.60);
  font-size: 9px;
  pointer-events: none;
  backdrop-filter: blur(10px);
}
.keycap {
  padding: 3px 5px;
  border: 1px solid rgba(255,255,255,.11);
  border-bottom-color: rgba(255,255,255,.20);
  border-radius: 5px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.84);
  font-size: 8px;
  font-weight: 800;
}

.map-legend {
  position: absolute;
  z-index: 12;
  left: 16px;
  bottom: 16px;
  width: 150px;
  padding: 9px 10px 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 11px;
  background: rgba(12,8,18,.78);
  backdrop-filter: blur(10px);
  pointer-events: none;
}
.legend-title {
  margin-bottom: 7px;
  color: rgba(255,255,255,.80);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .09em;
}
.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 7px;
}
.legend-grid span {
  display: flex;
  align-items: center;
  gap: 5px;
  color: rgba(255,255,255,.63);
  font-size: 8px;
}
.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.legend-swatch.ocean { background: var(--ocean); }
.legend-swatch.plains { background: var(--plains); }
.legend-swatch.forest { background: var(--forest); }
.legend-swatch.hills { background: var(--hills); }
.legend-swatch.mountains { background: var(--mountains); }
.legend-swatch.river { background: #4BBEFF; }

.debug-panel {
  position: absolute;
  z-index: 25;
  left: 16px;
  top: 102px;
  max-width: 320px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  background: rgba(15,10,23,.92);
  color: #fff;
  font: 10px/1.55 Consolas, monospace;
  pointer-events: none;
  white-space: pre-line;
}

/* ===== Map rendering ===== */
.hex {
  stroke: rgba(255,255,255,.14);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.hex-ocean { fill: var(--ocean); }
.hex-plains { fill: var(--plains); }
.hex-forest { fill: var(--forest); }
.hex-hills { fill: var(--hills); }
.hex-mountains { fill: var(--mountains); }

.hex-hover,
.hex-selected {
  pointer-events: none;
  fill: none;
  vector-effect: non-scaling-stroke;
}
.hex-hover { stroke: rgba(255,255,255,.74); stroke-width: 1.5; }
.hex-selected {
  stroke: var(--selection);
  stroke-width: 3;
  filter: drop-shadow(0 0 5px rgba(255,209,102,.38));
}

.city-marker,
.production-marker,
.resource-marker { pointer-events: none; }
.city-dot {
  fill: #FF8A3D;
  stroke: #FFFFFF;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.50));
}
.city-capital .city-dot {
  fill: var(--orange);
  stroke-width: 2.6;
  filter: drop-shadow(0 0 5px rgba(255,95,31,.35)) drop-shadow(0 2px 4px rgba(0,0,0,.5));
}
.city-label {
  fill: #FFFFFF;
  stroke: rgba(0,0,0,.90);
  stroke-width: 3.5px;
  paint-order: stroke fill;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .01em;
  vector-effect: non-scaling-stroke;
  user-select: none;
}
.entity-selection-ring {
  fill: none;
  stroke: var(--selection);
  stroke-width: 2.6;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 6px rgba(255,209,102,.58));
}

/* Resource fields */
.resource-marker-bg {
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.46));
}
.resource-wood-bg { fill: #1F4A2E; stroke: #75D38A; }
.resource-log-line {
  stroke: #D6A15A;
  stroke-width: 2.3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.resource-ore-bg { fill: #282D38; stroke: #BCC5D7; }
.resource-ore-crystal {
  fill: #AEB8CB;
  stroke: #F5F7FB;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}
.resource-fish-bg { fill: #153F52; stroke: #6BD5F0; }
.resource-fish-body,
.resource-fish-tail {
  fill: #8BE7F8;
  stroke: #E9FBFF;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

/* Production buildings */
.logging-camp-base {
  fill: #173A24;
  stroke: #64D07C;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.48));
}
.logging-camp-hut { fill: #B9783D; stroke: #F0C07B; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.logging-camp-roof { fill: #6C4328; stroke: #F0C07B; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.mine-base {
  fill: #262A35;
  stroke: #A8B1C5;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.48));
}
.mine-shaft { fill: #4A5060; stroke: #D7DCE7; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.mine-beam { stroke: #E4B45C; stroke-width: 2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.fishery-base {
  fill: #15394A;
  stroke: #64D2E8;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.48));
}
.fishery-hull { fill: #D8A64B; stroke: #FFF0BA; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.fishery-mast { stroke: #FFFFFF; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.fishery-flag { fill: var(--orange); stroke: #FFD9CA; stroke-width: .8; vector-effect: non-scaling-stroke; }

.city-industry-badge {
  stroke: rgba(7,12,28,.95);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.city-industry-sawmill { fill: #D79A54; }
.city-industry-smelter { fill: #C4CDDE; }

/* Infrastructure */
.road-connection,
.rail-connection { pointer-events: none; }
.road-line-shadow,
.road-line,
.rail-line-shadow,
.rail-line,
.rail-sleepers {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.road-line-shadow { stroke: rgba(0,0,0,.65); stroke-width: 7.4; }
.road-line {
  stroke: #FFD166;
  stroke-width: 3.5;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}
.rail-line-shadow { stroke: rgba(0,0,0,.73); stroke-width: 8.4; }
.rail-line {
  stroke: #BAC4D3;
  stroke-width: 4.8;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.55));
}
.rail-sleepers { stroke: #46505F; stroke-width: 2.5; stroke-dasharray: 2 5; }
.road-connection.selected .road-line-shadow { stroke: rgba(255,255,255,.72); stroke-width: 9; }
.road-connection.selected .road-line { stroke-width: 4.5; filter: drop-shadow(0 0 5px rgba(255,209,102,.72)); }
.rail-connection.selected .rail-line-shadow { stroke: rgba(255,255,255,.72); stroke-width: 10; }
.rail-connection.selected .rail-line { stroke: #EEF2F8; stroke-width: 5.6; filter: drop-shadow(0 0 6px rgba(215,225,240,.72)); }
.infrastructure-connection.load-active .road-line,
.infrastructure-connection.load-active .rail-line { filter: drop-shadow(0 0 3px rgba(255,255,255,.18)); }
.infrastructure-connection.load-heavy .road-line { stroke: #FF9F43; filter: drop-shadow(0 0 5px rgba(255,159,67,.42)); }
.infrastructure-connection.load-heavy .rail-line { stroke: #D7A6E8; filter: drop-shadow(0 0 5px rgba(215,166,232,.42)); }
.infrastructure-connection.load-full .road-line,
.infrastructure-connection.load-full .rail-line { stroke: var(--orange); filter: drop-shadow(0 0 7px rgba(255,95,31,.62)); }
.infrastructure-connection.selected .road-line,
.infrastructure-connection.selected .rail-line { filter: drop-shadow(0 0 6px rgba(255,209,102,.72)); }

/* ===== Responsive ===== */
@media (max-width: 1380px) {
  :root { --sidebar-width: 360px; }
  .map-topbar { grid-template-columns: auto minmax(0, 1fr); }
  .sim-cluster { grid-column: 1 / -1; justify-content: flex-end; margin-top: -2px; }
  .topbar-metrics { grid-template-columns: repeat(5, minmax(78px, 1fr)); }
}

@media (max-width: 1080px) {
  :root { --sidebar-width: 330px; }
  .map-topbar { right: 12px; left: 12px; top: 12px; }
  .topbar-brand { min-width: 145px; }
  .topbar-metrics { grid-template-columns: repeat(3, minmax(75px, 1fr)); }
  .metric-chip:nth-child(4),
  .metric-chip:nth-child(5) { display: none; }
  .compact-speed-row { width: 190px; }
}

@media (max-width: 820px) {
  :root { --sidebar-width: 300px; }
  #sidebar { padding: 12px; }
  .map-topbar { display: none; }
  .map-hint, .map-legend { display: none; }
}

/* Core 5.1 UI: clearer wood resource icon */
.resource-tree {
  vector-effect: non-scaling-stroke;
  stroke: #E8F7EC;
  stroke-width: .75;
}
.resource-tree-back { fill: #63B576; opacity: .92; }
.resource-tree-front { fill: #8AD49A; }
.resource-tree-trunk {
  stroke: #E0A45E;
  stroke-width: 1.35;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* ===== Core 6.0 resource geography ===== */
.map-legend {
  pointer-events: auto;
}

.layer-toggle {
  width: 100%;
  margin-top: 9px;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
  color: rgba(255,255,255,.72);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .035em;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}
.layer-toggle:hover {
  background: rgba(255,255,255,.075);
  color: #fff;
}
.layer-toggle.active,
.layer-toggle[aria-pressed="true"] {
  color: #fff;
  border-color: rgba(225,48,108,.42);
  background: linear-gradient(135deg, rgba(131,58,180,.24), rgba(225,48,108,.16));
}
.layer-toggle-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #75D38A, #6BD5F0);
  box-shadow: 0 0 0 2px rgba(255,255,255,.06);
}

.resource-field-card {
  border-color: rgba(117,211,138,.13);
}

.resource-potential-halo {
  fill: none;
  stroke: rgba(255,255,255,.34);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transition: opacity .18s ease;
}
.resource-wood .resource-potential-halo { stroke: rgba(117,211,138,.76); }
.resource-ore .resource-potential-halo { stroke: rgba(210,219,237,.74); }
.resource-fish .resource-potential-halo { stroke: rgba(107,213,240,.78); }

.resource-condition-low .resource-marker-bg { opacity: .78; }
.resource-condition-critical .resource-marker-bg { opacity: .58; }
.resource-condition-depleted .resource-marker-bg { opacity: .34; }
.resource-condition-critical,
.resource-condition-depleted { opacity: .72; }

#map.resource-overlay-active #world .hex {
  opacity: .42;
}
#map.resource-overlay-active #entities,
#map.resource-overlay-active #infrastructure {
  opacity: .64;
}
#map.resource-overlay-active #resources .resource-potential-halo {
  opacity: .78;
}
#map.resource-overlay-active #resources .resource-marker-bg {
  stroke-width: 2.5;
  filter: drop-shadow(0 0 5px rgba(255,255,255,.16)) drop-shadow(0 2px 3px rgba(0,0,0,.55));
}
#map.resource-overlay-active #resources .resource-condition-rich {
  opacity: 1;
}
#map.resource-overlay-active #resources .resource-condition-stable {
  opacity: .88;
}
#map.resource-overlay-active #resources .resource-condition-low {
  opacity: .70;
}
#map.resource-overlay-active #resources .resource-condition-critical {
  opacity: .52;
}
#map.resource-overlay-active #resources .resource-condition-depleted {
  opacity: .30;
}

/* Core 7.0 map views */
.map-view-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.map-view-controls .layer-toggle:first-child {
  grid-column: 1 / -1;
}

.map-view-legend {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 9px;
  background: rgba(255,255,255,.035);
  color: rgba(255,255,255,.68);
  font-size: 10px;
  line-height: 1.35;
}

#map.map-analysis-active #world .hex {
  opacity: .62;
  transition: opacity 160ms ease;
}

#map.map-analysis-active #resources:not(.resource-layer-active) {
  opacity: .34;
}

.map-view-city-halo {
  fill: rgba(255,255,255,.08);
  stroke-width: 5;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 5px rgba(0,0,0,.35));
}

.map-view-city-halo.overlay-good { stroke: #57D993; fill: rgba(87,217,147,.16); }
.map-view-city-halo.overlay-medium { stroke: #FFB454; fill: rgba(255,180,84,.16); }
.map-view-city-halo.overlay-bad { stroke: #FF5F5F; fill: rgba(255,95,95,.18); }

.map-view-city-halo.overlay-development-declining { stroke: #FF5F5F; fill: rgba(255,95,95,.18); }
.map-view-city-halo.overlay-development-struggling { stroke: #FF9F43; fill: rgba(255,159,67,.17); }
.map-view-city-halo.overlay-development-stable { stroke: #D6D9E5; fill: rgba(214,217,229,.11); }
.map-view-city-halo.overlay-development-growing { stroke: #57D993; fill: rgba(87,217,147,.16); }
.map-view-city-halo.overlay-development-thriving { stroke: #55D9FF; fill: rgba(85,217,255,.18); }

.map-view-traffic {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 10;
  opacity: .64;
  vector-effect: non-scaling-stroke;
}
.map-view-traffic.traffic-free { stroke: rgba(87,217,147,.78); }
.map-view-traffic.traffic-busy { stroke: rgba(255,180,84,.88); }
.map-view-traffic.traffic-full { stroke: rgba(255,95,95,.96); filter: drop-shadow(0 0 5px rgba(255,95,95,.35)); }

@media (max-width: 1180px) {
  .map-view-controls { grid-template-columns: 1fr; }
  .map-view-controls .layer-toggle:first-child { grid-column: auto; }
}

/* ===== Core 8.0 settlement suitability ===== */
.settlement-suitability {
  stroke-width: 1.35;
  vector-effect: non-scaling-stroke;
  opacity: .82;
}
.settlement-poor {
  fill: rgba(255,95,95,.14);
  stroke: rgba(255,95,95,.52);
}
.settlement-fair {
  fill: rgba(240,199,106,.14);
  stroke: rgba(240,199,106,.56);
}
.settlement-good {
  fill: rgba(114,217,149,.15);
  stroke: rgba(114,217,149,.62);
}
.settlement-excellent {
  fill: rgba(85,217,255,.18);
  stroke: rgba(85,217,255,.72);
}

/* Core 9.0 maritime infrastructure */
.sea-line-shadow,
.sea-line {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sea-line-shadow { stroke: rgba(3, 13, 28, .82); stroke-width: 6px; }
.sea-line { stroke: #66d9ff; stroke-width: 2.3px; stroke-dasharray: 7 5; opacity: .86; }
.sea-connection.selected .sea-line { stroke: #fff1a8; stroke-width: 3.4px; opacity: 1; }
.sea-connection.load-heavy .sea-line { stroke: #ffb347; }
.sea-connection.load-full .sea-line { stroke: #ff5f57; }
.city-industry-port { fill: none; stroke: #66d9ff; stroke-width: 1.7px; stroke-linecap: round; vector-effect: non-scaling-stroke; }

/* Core 10.0: natural freshwater geography */
#natural-features {
  pointer-events: none;
}

.river-line {
  fill: none;
  stroke: rgba(75, 188, 255, 0.95);
  stroke-width: 3.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 2px rgba(52, 161, 235, 0.45));
}

.river-line-underlay {
  stroke: rgba(5, 32, 60, 0.72);
  stroke-width: 5.6;
  filter: none;
}

.freshwater-zone {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.freshwater-distance-0 {
  fill: rgba(72, 190, 255, 0.18);
  stroke: rgba(92, 206, 255, 0.82);
  stroke-width: 1.15;
}

.freshwater-distance-1 {
  fill: rgba(72, 190, 255, 0.10);
  stroke: rgba(92, 206, 255, 0.45);
  stroke-width: 0.9;
}

.freshwater-distance-2 {
  fill: rgba(72, 190, 255, 0.045);
  stroke: rgba(92, 206, 255, 0.18);
  stroke-width: 0.6;
}

/* Core 11.0: agricultural land-use analysis */
.fertility-zone {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
  stroke-width: 0.8;
}

.fertility-poor {
  fill: rgba(163, 122, 86, 0.10);
  stroke: rgba(171, 133, 96, 0.28);
}

.fertility-fair {
  fill: rgba(223, 190, 92, 0.12);
  stroke: rgba(232, 199, 102, 0.42);
}

.fertility-good {
  fill: rgba(114, 201, 104, 0.14);
  stroke: rgba(126, 220, 115, 0.52);
}

.fertility-excellent {
  fill: rgba(74, 210, 135, 0.19);
  stroke: rgba(92, 232, 151, 0.72);
}

.farm-base {
  fill: rgba(231, 200, 108, 0.18);
  stroke: #E7C86C;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.farm-stalk,
.farm-grain {
  fill: none;
  stroke: #F0D57D;
  stroke-width: 1.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Core 12.0: energy geography */
.energy-zone {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
  stroke-width: 0.85;
}
.energy-low {
  fill: rgba(135, 120, 220, 0.08);
  stroke: rgba(150, 135, 230, 0.26);
}
.energy-medium {
  fill: rgba(112, 174, 235, 0.13);
  stroke: rgba(120, 190, 245, 0.46);
}
.energy-high {
  fill: rgba(82, 218, 207, 0.18);
  stroke: rgba(94, 232, 217, 0.72);
}
.city-energy-hydro {
  fill: rgba(84, 205, 255, .28);
  stroke: #6EDCFF;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}
.city-energy-wind line,
.city-energy-wind path {
  fill: none;
  stroke: #D7F3FF;
  stroke-width: 1.25;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Core 13: persistent city construction overview, independent of selection. */
.construction-panel { margin-top: 14px; }
.construction-panel summary { cursor: pointer; font-weight: 700; font-size: 14px; }
.construction-panel summary span { float: right; color: #ffd07c; font-variant-numeric: tabular-nums; }
.construction-help, .construction-empty { color: #c0c9d7; font-size: 12px; line-height: 1.5; margin: 12px 0 0; }
.construction-list { display: grid; gap: 10px; max-height: 220px; overflow-y: auto; margin-top: 10px; }
.construction-list:empty { display: none; }
.construction-card { padding: 10px; border: 1px solid #68543b; border-radius: 9px; background: #29271f; display: grid; gap: 7px; }
.construction-city-link { background: none; border: 0; padding: 0; color: #ffe0a0; text-align: left; font: inherit; font-size: 12px; cursor: pointer; }
.construction-city-link:hover { text-decoration: underline; }
.construction-city-link:focus-visible { outline: 2px solid #ffd07c; outline-offset: 3px; }
.construction-card progress { appearance: none; display: block; width: 100%; height: 6px; border: 0; border-radius: 9px; overflow: hidden; background: #494334; }
.construction-card progress::-webkit-progress-bar { background: #494334; }
.construction-card progress::-webkit-progress-value { background: #ffc666; }
.construction-card progress::-moz-progress-bar { background: #ffc666; }
.construction-detail { font-size: 11px; line-height: 1.4; color: #f2dcb5; }
.city-construction-track { fill: none; stroke: #574629; stroke-width: 2.5; }
.city-construction-progress { fill: none; stroke: #ffc666; stroke-width: 2.5; stroke-linecap: round; }
.city-construction-crane { fill: none; stroke: #ffc666; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Core 14: freight reports and map vehicles. */
.freight-report { margin: 12px 0; padding: 12px; border: 1px solid rgba(130,168,199,.3); border-radius: 10px; background: rgba(7,18,29,.65); }
.freight-report p { margin: 6px 0; line-height: 1.5; overflow-wrap: anywhere; }
.freight-heading { font-weight: 700; color: #eef5ff; }
.freight-warning { color: #ffc17a; }
.freight-caption { font-size: 12px; line-height: 1.5; color: #b9c8d9; }
.freight-vehicle { filter: drop-shadow(0 1px 1px rgba(0,0,0,.65)); }
.freight-load-marker { stroke: #172536; stroke-width: 1; }
.freight-load-marker text { font: bold 9px sans-serif; stroke: none; fill: #172536; }
