:root {
  --bg: #101217;
  --panel: #171a21;
  --panel-2: #20252e;
  --line: #303744;
  --text: #eef2f6;
  --muted: #99a4b3;
  --accent: #63d4b1;
  --warn: #e7bb62;
  --bad: #ee7b73;
  --unknown: #9ba6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  height: 100vh;
}

.map-region {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #131720;
}

.brand h1 {
  margin: 0 0 2px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 420px;
}

.controls input,
.controls select,
.controls button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}

.controls input {
  flex: 1;
  min-width: 160px;
  padding: 0 10px;
}

.controls select {
  padding: 0 8px;
}

.controls button {
  padding: 0 12px;
  cursor: pointer;
}

.link-button {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.link-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#detailsTitle a,
.polity-name a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--muted);
}

#detailsTitle a:hover,
.polity-name a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#cy {
  min-width: 0;
  min-height: 0;
}

.details-panel {
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.empty-state,
#details {
  padding: 22px;
}

.empty-state h2,
#details h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.5;
}

.details-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.status-pill {
  display: inline-flex;
  margin: 0 0 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.distance {
  margin: 4px 0 0;
  color: var(--accent);
  white-space: nowrap;
}

section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

section h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
}

dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  font-size: 14px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.polity-section {
  padding-top: 12px;
  padding-bottom: 12px;
}

.polity-name {
  margin: 0 0 2px;
  font-size: 14px;
  font-weight: 600;
}

.polity-facts {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.bodies-bar {
  position: relative;
  height: 96px;
  margin: 8px 4px 0;
}

.bodies-bar .bar-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 44px;
  height: 1px;
  background: var(--line);
}

.bodies-bar button {
  position: absolute;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}

.bodies-bar .body-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 10px;
  white-space: nowrap;
  cursor: pointer;
}

.bodies-bar .body-au {
  position: absolute;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--muted);
}

.bodies-bar .body-offset-tick {
  position: absolute;
  width: 1px;
  height: 6px;
  background: var(--muted);
}

.bodies-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  margin: 10px 0 14px;
}

.bodies-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.bodies-legend-dash::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 0;
  border-top: 2px dashed var(--muted);
  margin-right: 4px;
}

.bodies-detail {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  min-height: 60px;
  font-size: 13px;
}

.bodies-detail .bd-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 4px;
}

.bodies-detail .bd-meta {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 8px;
}

.bodies-detail dl {
  margin: 0 0 8px;
  font-size: 12px;
}

.bodies-detail .bd-notes {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.bodies-detail .bd-back {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-bottom: 8px;
}

.bodies-detail .bd-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 12px;
}

.bodies-detail .bd-list-row:last-child {
  border-bottom: none;
}

.lore-source {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.lore-body {
  font-size: 13px;
  line-height: 1.5;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.lore-body h4,
.lore-body h5,
.lore-body h6 {
  margin: 16px 0 6px;
  color: var(--text);
}

.lore-body h4:first-child,
.lore-body h5:first-child,
.lore-body h6:first-child {
  margin-top: 0;
}

.lore-body p {
  margin: 0 0 8px;
}

.lore-body ul {
  margin: 0 0 8px;
  padding-left: 18px;
  color: var(--text);
}

.lore-body strong {
  color: var(--text);
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 70vh auto;
    height: auto;
    min-height: 100vh;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .details-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
