.civ-atlas {
  --atlas-panel: #132529;
  --atlas-accent: #c7f2ce;
  --atlas-stroke: #7ba8a5;
  margin-block: clamp(1.2rem, 5vw, 4rem);
  border: 1px solid var(--line, #3b5358);
  border-radius: var(--radius, 1.25rem);
  background: linear-gradient(145deg, #193035, var(--atlas-panel) 43%, #122227);
  overflow: hidden;
}

.civ-atlas [hidden] { display: none !important; }

.civ-atlas-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: .9rem 1.5rem;
  padding: clamp(1rem, 2.7vw, 2rem);
  padding-block-end: 1.1rem;
}

.civ-atlas-header h2 { margin: .25rem 0 0; font-size: clamp(1.9rem, 3.2vw, 3.05rem); }

.civ-atlas-choice {
  display: grid;
  width: min(100%, 26rem);
  gap: .28rem;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted, #b4c6c4);
}

.civ-atlas-choice select { width: 100%; min-height: 44px; }
.civ-atlas-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(18rem, .46fr); }
.civ-atlas-visual { min-width: 0; }

.civ-atlas-stage {
  aspect-ratio: 760 / 450;
  min-height: 18.8rem;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse at 40% 53%, #426b5d45 0, transparent 58%),
    radial-gradient(ellipse at 92% 10%, #3ba9a222 0, transparent 38%),
    linear-gradient(164deg,#122c2d,#0e1c21 67%);
  border-block: 1px solid #3b5358;
}

.civ-atlas-stage::before {
  position: absolute;
  inset: 0;
  content: '';
  pointer-events: none;
  background-image:
    linear-gradient(to bottom, #799f9714 1px, transparent 1px),
    linear-gradient(to right, #799f9714 1px, transparent 1px);
  background-size: 1.8rem 1.8rem;
  mask-image: radial-gradient(ellipse at 46% 49%, #000 10%, transparent 79%);
}

.civ-atlas-world, .civ-atlas-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.civ-atlas-world { transition: transform 180ms ease-out; }
.civ-atlas-world:has([data-dragging="true"]) { transition: none; }
.civ-atlas-svg { pointer-events: none; overflow: visible; }
.civ-atlas-edge { opacity: .31; transition: opacity 160ms ease; }
.civ-atlas-edge[data-visible="true"] { opacity: .92; }
.civ-atlas-line, .civ-atlas-light { fill: none; stroke-linecap: round; }
.civ-atlas-line { stroke: var(--atlas-stroke); }

.civ-atlas-edge[data-visible="true"] .civ-atlas-line {
  stroke: var(--atlas-accent);
  filter: drop-shadow(0 0 4px #9fe6cc63);
}

.civ-atlas-edge[data-bridge="true"] .civ-atlas-line { stroke-dasharray: 5 5; }
.civ-atlas-light { visibility: hidden; opacity: 0; stroke: #e4f8dc; stroke-width: 2.5px; stroke-dasharray: 9 91; }
.civ-atlas[data-motion="on"] .civ-atlas-edge[data-visible="true"][data-bridge="false"] .civ-atlas-light {
  visibility: visible;
  animation: civ-atlas-current 8s linear infinite;
}
.civ-atlas-edge:nth-child(2n) .civ-atlas-light { animation-delay: -3s !important; }
.civ-atlas-edge:nth-child(3n) .civ-atlas-light { animation-delay: -5s !important; }

@keyframes civ-atlas-current {
  from { stroke-dashoffset: 100; opacity: .08; }
  22%, 80% { opacity: .7; }
  to { stroke-dashoffset: 0; opacity: .08; }
}

.civ-atlas-dot { fill: #203735; fill: color-mix(in srgb, var(--dot) 21%, #13272c); stroke: var(--dot); stroke-width: .65px; vector-effect: non-scaling-stroke; }
.civ-atlas-ring { fill: none; stroke: var(--dot); stroke-width: 1.45; opacity: .33; vector-effect: non-scaling-stroke; }
.civ-atlas-glyph { color: var(--dot); fill: none; stroke: currentColor; stroke-width: 1.62; stroke-linecap: round; stroke-linejoin: round; }
.civ-atlas-svg [data-current="true"] .civ-atlas-dot { filter: drop-shadow(0 0 7px #c9f4d869); }
.civ-atlas-svg [data-current="true"] .civ-atlas-ring { opacity: .88; stroke-width: 2; }

.civ-atlas-node {
  position: absolute;
  z-index: 1;
  width: 44px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: grab;
  touch-action: pan-y;
  transform: translate(-50%, -50%);
}

.civ-atlas-node:hover { outline: 2px solid var(--dot); outline-offset: 1px; }
.civ-atlas-node:focus-visible { z-index: 2; outline: 3px solid var(--focus, #fff1a5); outline-offset: 2px; }
.civ-atlas-node[data-dragging="true"] { cursor: grabbing; }

.civ-atlas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .42rem;
  padding: .72rem clamp(.75rem, 2vw, 1.35rem) .25rem;
}

.civ-atlas-toolbar button, .civ-atlas-adjust button {
  min-width: 44px;
  min-height: 44px;
  padding: .4rem .72rem;
  border: 1px solid var(--line, #3b5358);
  border-radius: .55rem;
  color: var(--ink, #f8f4e8);
  background: #1c3235;
  cursor: pointer;
  font-weight: 700;
}

.civ-atlas-toolbar button:disabled { opacity: .58; cursor: default; }
.civ-atlas-toolbar button:enabled:hover, .civ-atlas-adjust button:hover { border-color: var(--atlas-accent); }
.civ-atlas-guide, .civ-atlas-legend {
  margin: .55rem 0 0;
  padding-inline: clamp(.75rem, 2vw, 1.35rem);
  color: var(--muted, #b4c6c4);
  font-size: .79rem;
}
.civ-atlas-legend { display: flex; flex-wrap: wrap; gap: .45rem 1.15rem; padding-block-end: 1.15rem; }
.civ-atlas-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.civ-atlas-legend i { display: inline-block; flex: none; color: var(--atlas-accent); }
.civ-atlas-key-dot { width: .7rem; height: .7rem; border: 1px solid currentColor; border-radius: 50%; }
.civ-atlas-key-line { width: 1.15rem; border-top: 2px solid currentColor; }
.civ-atlas-key-bridge { width: 1.15rem; border-top: 2px dashed currentColor; }

.civ-atlas-panel {
  min-width: 0;
  padding: 0 clamp(1rem, 2.6vw, 1.55rem) 1rem;
}

.civ-atlas-kpi h3 {
  margin: 0 0 .3rem;
  font-family: var(--serif, Georgia, serif);
  font-size: clamp(1.36rem, 2vw, 1.95rem);
  line-height: 1.15;
}

.civ-atlas-kpi p, .civ-atlas-connections p, .civ-atlas-method p, .civ-atlas-directory p {
  color: var(--muted, #b4c6c4);
  font-size: .84rem;
  margin: .35rem 0 .7rem;
}

.civ-atlas-kpi strong { color: var(--atlas-accent); font-variant-numeric: tabular-nums; }
.civ-atlas-link { margin-block: .35rem .72rem; }
.civ-atlas-connections h4 { font-size: .95rem; margin: .75rem 0 .25rem; }

.civ-atlas-neighbors, .civ-atlas-directory ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.civ-atlas-neighbors a, .civ-atlas-directory li a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 44px;
  padding: .4rem .18rem;
  color: var(--ink, #f8f4e8);
  text-decoration: none;
  border-bottom: 1px solid var(--line, #3b5358);
  font-size: .84rem;
}

.civ-atlas-neighbors a:hover span, .civ-atlas-directory li a:hover span {
  color: var(--atlas-accent);
  text-decoration: underline;
}

.civ-atlas-neighbors strong, .civ-atlas-directory li strong {
  color: var(--atlas-accent);
  font-variant-numeric: tabular-nums;
}

.civ-atlas summary {
  display: list-item;
  min-height: 44px;
  padding-block: .7rem;
  cursor: pointer;
  font-weight: 700;
  font-size: .86rem;
}

.civ-atlas-method, .civ-atlas-adjust { margin: .2rem 0 0; }
.civ-atlas-adjust > div { display: flex; flex-wrap: wrap; gap: .4rem; }
.civ-atlas-comparison table { table-layout: fixed; width: 100%; max-width: 100%; font-size: .76rem; }
.civ-atlas-comparison caption { margin-bottom: .4rem; text-align: left; color: var(--muted, #b4c6c4); }
.civ-atlas-comparison th, .civ-atlas-comparison td { padding: .4rem .18rem; overflow-wrap: anywhere; font-size: .76rem; }
.civ-atlas-comparison th:first-child { width: 35%; }

.civ-atlas-directory {
  padding: .15rem clamp(1rem, 2.7vw, 2rem) .4rem;
  border-top: 1px solid var(--line, #3b5358);
}
.civ-atlas-directory ul { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 2rem; padding-bottom: .9rem; }

@media (max-width: 790px) {
  .civ-atlas-grid { grid-template-columns: minmax(0,1fr); }
  .civ-atlas-panel { border-top: 1px solid var(--line, #3b5358); padding-block-start: 1.25rem; }
}

@media (max-width: 520px) {
  .civ-atlas-stage { aspect-ratio: 1.12; min-height: 18rem; }
  .civ-atlas-directory ul { grid-template-columns: minmax(0,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .civ-atlas-world, .civ-atlas-edge { transition: none; }
  .civ-atlas-light { animation: none !important; }
}

@media (forced-colors: active) {
  .civ-atlas-node[aria-pressed="true"] { outline: 2px solid Highlight; }
  .civ-atlas-edge .civ-atlas-line, .civ-atlas-ring { stroke: CanvasText; filter: none; }
  .civ-atlas-dot, .civ-atlas-svg [data-current="true"] .civ-atlas-dot { fill: Canvas; stroke: Highlight; filter: none; }
  .civ-atlas-glyph { color: CanvasText; }
  .civ-atlas-light { animation: none !important; visibility: hidden !important; }
}
