:root {
  color-scheme: light;
  --ink: #001e42;
  --muted: #657183;
  --line: #d9ded8;
  --paper: #f7f5ed;
  --paper-strong: #fffdf6;
  --deep: #001e42;
  --teal: #005826;
  --gold: #b78b3e;
  --red: #a34e45;
  --shadow: 0 16px 50px rgba(0, 30, 66, 0.12);
  --terrain-land: linear-gradient(145deg, rgba(220, 211, 153, 0.78), rgba(181, 186, 132, 0.58));
  --terrain-sea: linear-gradient(30deg,
    rgba(73, 139, 151, 0.78) 0 25%,
    rgba(126, 178, 181, 0.58) 25% 33.3333%,
    rgba(73, 139, 151, 0.78) 33.3333% 41.6667%,
    rgba(126, 178, 181, 0.58) 41.6667% 50%,
    rgba(73, 139, 151, 0.78) 50% 58.3333%,
    rgba(126, 178, 181, 0.58) 58.3333% 66.6667%,
    rgba(73, 139, 151, 0.78) 66.6667% 75%,
    rgba(126, 178, 181, 0.58) 75% 100%);
  --terrain-mountain: linear-gradient(120deg, #565a59 49.5%, #c5c8c3 50.5%);
  --terrain-valley: linear-gradient(120deg, #9c967f 49.5%, #c3bda6 50.5%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #dfe4df;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

.game-shell {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.9), transparent 34rem),
    linear-gradient(145deg, #e9ece7, #d7deda);
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  color: #f6f3e8;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035), transparent 28%),
    var(--deep);
  border-bottom: 3px solid #b08c4b;
  box-shadow: 0 5px 20px rgba(0, 30, 66, 0.24);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.brand-mark {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border: 1px solid #d8cda6;
  color: #e2cf98;
  font-family: Georgia, serif;
  letter-spacing: -2px;
  transform: rotate(45deg);
}

.brand-mark::first-letter {
  transform: rotate(-45deg);
}

.brand p,
.brand span {
  margin: 0;
}

.brand p {
  font-family: "Songti SC", "SimSun", serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.16em;
}

.brand div > span {
  color: #b7c3bf;
  font-size: 9px;
  letter-spacing: 0.14em;
}

.world-stats {
  display: flex;
  align-items: stretch;
  margin-left: auto;
}

.world-stats div {
  min-width: 112px;
  padding: 3px 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.13);
}

.world-stats span,
.world-stats strong {
  display: block;
}

.world-stats span {
  color: #aebbb6;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.world-stats strong {
  margin-top: 4px;
  color: #f7f0d8;
  font-size: 14px;
}

.icon-button {
  width: 35px;
  height: 35px;
  border: 1px solid #60706b;
  border-radius: 50%;
  background: transparent;
  color: #d8e0dc;
  cursor: pointer;
}

.controlbar {
  min-height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 28px;
  background: rgba(255, 253, 246, 0.94);
  border-bottom: 1px solid #cbd2cc;
}

.scenario-tabs,
.time-controls,
.chart-tabs,
.inspector-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.controlbar button,
.controlbar select,
.chart-tabs button,
.inspector-tabs button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #596661;
  cursor: pointer;
}

.scenario-tabs button.active,
.chart-tabs button.active,
.inspector-tabs button.active {
  border-color: #b9c4bd;
  background: #eef1eb;
  color: #244943;
  font-weight: 700;
}

.controlbar button.primary {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

.controlbar button.primary.running {
  background: #925346;
  border-color: #925346;
}

.time-controls label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.time-controls select {
  height: 32px;
  border: 1px solid var(--line);
  background: white;
}

.toggle input,
.route-switch input {
  accent-color: var(--teal);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: minmax(590px, calc(100vh - 127px)) auto;
}

.map-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #bfc8c1;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 22px 13px;
  background: rgba(249, 248, 241, 0.9);
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact {
  align-items: center;
  padding-block: 14px;
}

.eyebrow {
  color: #8d6e35;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.panel-heading h1,
.panel-heading h2 {
  margin: 3px 0;
  font-family: "Songti SC", "SimSun", serif;
}

.panel-heading h1 {
  font-size: 23px;
}

.panel-heading h2 {
  font-size: 18px;
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  gap: 14px;
  padding-top: 13px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #65716d;
  font-size: 10px;
}

.legend i {
  width: 9px;
  height: 9px;
  background: var(--legend);
  border: 1px solid rgba(35, 48, 45, 0.25);
  transform: rotate(45deg);
}

.map-stage {
  position: relative;
  flex: 1;
  min-height: 500px;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 70%, rgba(185, 169, 109, 0.22), transparent 25%),
    radial-gradient(circle at 76% 25%, rgba(92, 132, 117, 0.18), transparent 28%),
    linear-gradient(145deg, #cfd8ca, #afc4ba);
  isolation: isolate;
}

.map-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.2;
  background-image: repeating-linear-gradient(105deg, transparent 0 18px, rgba(255, 255, 255, 0.25) 19px);
}

.map-transform {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 50% 50%;
  will-change: transform;
  touch-action: none;
}

.map-world {
  position: absolute;
  inset: 0;
}

.periodic-map-copy {
  transform: translateX(var(--periodic-shift));
}

.map-stage.pan-mode,
.map-stage.pan-mode .terrain-hex,
.map-stage.pan-mode .route-path,
.map-stage.pan-mode .connection-guide,
.map-stage.pan-mode .infrastructure-edge-editor {
  cursor: grab;
}

.map-stage.dragging,
.map-stage.dragging .terrain-hex,
.map-stage.dragging .route-path,
.map-stage.dragging .connection-guide,
.map-stage.dragging .infrastructure-edge-editor {
  cursor: grabbing;
}

.map-viewport-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 11;
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid rgba(81, 101, 94, 0.55);
  border-radius: 3px;
  background: rgba(250, 248, 237, 0.9);
  box-shadow: 0 4px 12px rgba(35, 48, 44, 0.14);
}

.map-viewport-controls button {
  min-width: 29px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #bcc7c0;
  background: #fffdf6;
  color: #41514c;
  cursor: pointer;
}

.map-viewport-controls button.active {
  border-color: #526c63;
  background: #526c63;
  color: #fffdf6;
}

.editor-toolbar {
  position: absolute;
  left: 14px;
  right: auto;
  top: 12px;
  z-index: 12;
  display: grid;
  grid-template-columns: 106px 106px minmax(360px, 1fr);
  width: min(650px, calc(100% - 92px));
  max-height: calc(100% - 24px);
  align-items: stretch;
  gap: 7px;
  padding: 8px;
  overflow: auto;
  border: 1px solid #7f918a;
  background: rgba(250, 248, 237, 0.96);
  box-shadow: 0 8px 22px rgba(35, 48, 44, 0.2);
}

.editor-toolbar[hidden] {
  display: none;
}

.editor-toolbar b,
.editor-toolbar span,
.editor-toolbar strong {
  font-size: 14px;
}

.editor-toolbar small,
.editor-toolbar > #editor-status {
  font-size: 12px;
  line-height: 1.45;
}

.editor-title {
  display: flex;
  min-width: 92px;
  flex-direction: column;
  justify-content: center;
  padding: 4px 8px 4px 2px;
  border-right: 1px solid #d7ddd8;
}

.editor-title b {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
}

.editor-title small,
.editor-palette strong {
  color: var(--muted);
  font-weight: 500;
}

.editor-palette,
.editor-actions {
  display: grid;
  gap: 5px;
}

.editor-palette {
  grid-template-rows: 22px repeat(5, 32px);
  align-content: start;
}

.editor-palette strong {
  display: flex;
  align-items: center;
  padding-left: 4px;
}

.editor-palette button,
.editor-palette strong,
.editor-actions button,
.editor-actions span {
  font-size: 14px;
}

.editor-toolbar button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-height: 32px;
  padding: 3px 7px;
  border: 1px solid #bcc7c0;
  background: #f8f7ef;
  color: #41514c;
  cursor: pointer;
  white-space: nowrap;
}

.editor-palette button {
  min-width: 0;
}

.editor-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.editor-footer {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 32px;
}

.editor-footer > #editor-status {
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.editor-wrap-switch {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #41514c;
  font-size: 13px;
  white-space: nowrap;
}

.editor-wrap-switch button {
  min-width: 36px;
  justify-content: center;
  padding-inline: 7px;
}

.editor-actions #editor-finish {
  min-width: 126px;
  justify-content: center;
  border-color: #738b82;
  background: #edf1ec;
}

.tool-swatch {
  position: relative;
  display: inline-block;
  width: 19px;
  height: 15px;
  flex: 0 0 auto;
}

.tool-swatch.terrain {
  width: 18px;
  height: 20.78px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--terrain-land);
}

.tool-swatch.terrain.land { background: var(--terrain-land); }
.tool-swatch.terrain.sea { background: var(--terrain-sea); }
.tool-swatch.terrain.mountain { background: var(--terrain-mountain); }
.tool-swatch.terrain.valley { background: var(--terrain-valley); }
.tool-swatch.terrain.city {
  background: var(--terrain-land);
}

.tool-swatch.terrain.city::before,
.tool-swatch.terrain.city::after {
  position: absolute;
  left: 50%;
  top: 50%;
  content: "";
  border: 1.5px solid white;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
}

.tool-swatch.terrain.city::before {
  width: 11px;
  height: 11px;
}

.tool-swatch.terrain.city::after {
  width: 5px;
  height: 5px;
}

.tool-swatch.edge::before,
.tool-swatch.auto-connect::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  border-top: 3px solid #f3f0df;
  box-shadow: 0 0 0 1px #7d8c86;
}

.tool-swatch.edge.river::before { border-color: #83cbd4; }
.tool-swatch.edge.channel::before { border-color: #287a91; }
.tool-swatch.edge.empty::before {
  border-top: 2px dashed #aeb8b2;
  box-shadow: none;
}
.tool-swatch.auto-connect::before { border-top-style: dashed; border-color: #b48a44; box-shadow: none; }
.tool-swatch.territory {
  border: 2px solid #66897e;
  border-radius: 2px;
  background: rgba(102, 137, 126, 0.18);
}

.polity-editor label {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 14px;
}

.polity-editor,
.polity-editor button,
.polity-editor input,
.polity-editor select,
.polity-editor span,
.polity-editor strong {
  font-size: 14px;
}

.polity-editor select,
.polity-editor input {
  width: 100%;
  min-width: 0;
  height: 32px;
  box-sizing: border-box;
  border: 1px solid #bcc7c0;
  background: #fffdf6;
  color: var(--ink);
}

.polity-editor input[type="color"] {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 1px;
  overflow: hidden;
  border: 1px solid #8da099;
  border-radius: 50%;
  background: transparent;
}

.entity-settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.entity-settings-row > label,
.entity-name-and-color > label:not(.compact-color) {
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px;
}

.entity-name-and-color {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  min-width: 0;
  align-items: center;
  gap: 5px;
}

.entity-name-and-color .compact-color {
  display: flex;
  justify-content: center;
  align-items: center;
}

.polity-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.polity-buttons button {
  min-width: 0;
  justify-content: center;
  padding-inline: 5px;
}

.polity-buttons .tool-swatch {
  width: 14px;
}

.territory-settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.territory-settings-row button {
  min-width: 0;
  justify-content: center;
}

.territory-settings-row label {
  grid-template-columns: auto minmax(0, 1fr);
}

.map-settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
  align-items: center;
  gap: 6px;
}

.map-settings-row > label:not(.editor-wrap-switch) {
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 3px;
}

.map-settings-row .editor-wrap-switch {
  display: inline-flex;
  min-width: 0;
  justify-content: center;
  padding-inline: 0;
}

@media (max-width: 980px) {
  .editor-toolbar {
    grid-template-columns: 1fr 1fr;
    max-height: 76%;
    overflow-y: auto;
  }
  .editor-title,
  .editor-actions,
  .editor-toolbar > #editor-status { grid-column: 1 / -1; }
}

.editor-toolbar button.active,
#editor-toggle.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.map-stage.editing .terrain-layer {
  z-index: 4;
  opacity: 0.9;
}

.map-stage.editing .route-layer {
  z-index: 5;
}

.map-stage.editing .city-layer {
  z-index: 6;
}

.map-stage.editing .terrain-hex {
  cursor: crosshair;
  outline: 1px solid rgba(255, 255, 255, 0.18);
}

.map-stage.editing .terrain-hex:hover,
.terrain-hex.path-selected {
  background: rgba(245, 205, 102, 0.52);
}

.terrain-layer,
.route-layer,
.city-layer {
  position: absolute;
  inset: 0;
}

.terrain-layer {
  z-index: 1;
  opacity: 0.94;
}

.terrain-hex {
  position: absolute;
  width: 9.64%;
  height: 20.58%;
  padding: 0;
  border: 0;
  transform: translate(-50%, -50%);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  outline: 1px solid rgba(255, 255, 255, 0.22);
  cursor: default;
}

.terrain-hex[data-kind="land"] {
  background: var(--terrain-land);
}

.terrain-hex[data-kind="mountain"] {
  background: var(--terrain-mountain);
}

.terrain-hex[data-kind="valley"] {
  background: var(--terrain-valley);
}

.terrain-hex[data-kind="sea"] {
  background: var(--terrain-sea);
}

.terrain-hex[data-kind="city"] {
  display: grid;
  place-items: center;
  background: var(--terrain-land);
  cursor: pointer;
}

.territory-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 10px;
  height: 10px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: var(--territory);
  box-shadow: 0 1px 4px rgba(30, 36, 34, 0.48);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.territory-dot::after {
  position: absolute;
  inset: 25%;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background: var(--city-marker);
}

.city-tile-symbol {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  background: var(--territory);
}

.city-tile-symbol::after {
  inset: 24%;
  border: 2px solid rgba(255, 255, 255, 0.88);
  background: var(--city-marker);
}

.terrain-hex.selected-owner {
  filter: brightness(1.08) saturate(1.2);
  outline: 2px solid rgba(255, 235, 164, 0.72);
}

.terrain-hex.selected-city {
  filter: brightness(1.12) saturate(1.24);
  outline: 3px solid #fff0b6;
}

.route-layer {
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.route-path {
  cursor: pointer;
}

.connection-guide {
  cursor: pointer;
}

.route-path:focus,
.connection-guide:focus,
.infrastructure-edge-editor:focus {
  outline: none;
}

.connection-guide polyline {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
}

.connection-guide-hit {
  stroke: transparent;
  stroke-width: 10px;
  pointer-events: stroke;
}

.connection-guide-main {
  stroke: rgba(74, 71, 62, 0.42);
  stroke-width: 1px;
  stroke-dasharray: 2.2 2.2;
  pointer-events: none;
}

.connection-guide:hover .connection-guide-main,
.connection-guide:focus-visible .connection-guide-main,
.connection-guide.selected .connection-guide-main {
  stroke: #b47e30;
  stroke-width: 1.8px;
  opacity: 0.95;
}

.route-path polyline {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-path-hit {
  stroke: transparent;
  stroke-width: 16px;
  pointer-events: stroke;
}

.route-path-main {
  stroke: #635d4f;
  stroke-width: 3px;
  opacity: var(--route-opacity);
  pointer-events: none;
}

.route-path-main.river {
  stroke: #8fd3df;
  stroke-width: 4px;
}

.route-path-main.river.natural-river {
  stroke: #175b7a;
}

.route-path-main.road {
  stroke: #fffdf4;
  filter: drop-shadow(0 0 1px rgba(47, 43, 35, 0.88));
}

.route-path.selected .route-path-main {
  stroke-width: 6px;
  opacity: 1;
}

.route-path:focus-visible .route-path-main {
  stroke-width: 6px;
  opacity: 1;
}

.route-path.embargoed .route-path-main {
  stroke-dasharray: 5 4;
  opacity: 0.48;
}

.infrastructure-edge-editor polyline {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
}

.infrastructure-edge-hit {
  stroke: transparent;
  stroke-width: 12px;
  pointer-events: none;
}

.route-layer.edge-editing .infrastructure-edge-hit {
  pointer-events: stroke;
}

.route-layer.edge-editing .infrastructure-edge-editor {
  cursor: crosshair;
}

.infrastructure-edge-main {
  pointer-events: none;
  stroke-width: 3px;
}

.infrastructure-edge-main.empty {
  stroke: transparent;
}

.infrastructure-edge-main.road {
  stroke: #fffdf4;
  filter: drop-shadow(0 0 1px rgba(47, 43, 35, 0.88));
}

.infrastructure-edge-main.river {
  stroke: #8fd3df;
  stroke-width: 4px;
}

.infrastructure-edge-main.channel {
  stroke: #175b7a;
  stroke-width: 4px;
}

.route-layer.edge-editing .infrastructure-edge-editor:hover .infrastructure-edge-main.empty,
.route-layer.edge-editing .infrastructure-edge-editor:focus-visible .infrastructure-edge-main.empty {
  stroke: rgba(245, 205, 102, 0.78);
  stroke-width: 2px;
  stroke-dasharray: 2 2;
}

.route-layer.edge-editing .infrastructure-edge-editor:hover .infrastructure-edge-main:not(.empty),
.route-layer.edge-editing .infrastructure-edge-editor:focus-visible .infrastructure-edge-main:not(.empty) {
  stroke-width: 6px;
}

.city-layer {
  z-index: 3;
  pointer-events: none;
}

.city-caption {
  position: absolute;
  width: 112px;
  height: 58px;
  transform: translate(18px, -26px);
  text-align: left;
}

.city-label {
  position: absolute;
  left: 0;
  top: 8px;
  min-width: 76px;
  padding: 5px 8px;
  background: rgba(249, 248, 236, 0.9);
  border: 1px solid rgba(61, 74, 68, 0.35);
  box-shadow: 0 3px 8px rgba(42, 52, 47, 0.15);
}

.city-label b,
.city-label small {
  display: block;
  white-space: nowrap;
}

.city-label b {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 12px;
}

.city-label small {
  color: #68736e;
  font-size: 9px;
}

.city-caption.selected .city-label {
  border-color: #b47e30;
  background: #fff9e7;
}

.city-stability {
  position: absolute;
  left: -8px;
  top: 0;
  min-width: 22px;
  padding: 1px 4px;
  border-radius: 8px;
  background: #3e6a5a;
  color: white;
  font-size: 8px;
  text-align: center;
}

.city-history-bars {
  position: absolute;
  left: 0;
  top: 43px;
  width: 57px;
  height: 18px;
  display: flex;
  align-items: end;
  gap: 3px;
  padding: 2px 5px;
  border: 1px solid rgba(61, 74, 68, 0.25);
  background: rgba(249, 248, 236, 0.86);
}

.city-history-bars i {
  width: 8px;
  height: calc(var(--bar) * 13px);
  background: #587f75;
  transition: height 120ms ease-out;
}

.city-history-bars i:nth-child(2) {
  background: #c28d3e;
}

.city-history-bars i:nth-child(3) {
  background: #99734e;
}

.city-history-bars i:nth-child(4) {
  background: #6d8190;
}

.city-stability.warn {
  background: var(--red);
}

.map-note {
  position: absolute;
  left: 18px;
  bottom: 16px;
  z-index: 4;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  background: rgba(38, 52, 49, 0.82);
  color: #e7ede9;
  font-size: 10px;
  box-shadow: var(--shadow);
}

.pulse-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: #d8ad5d;
  box-shadow: 0 0 0 4px rgba(216, 173, 93, 0.18);
}

.inspector {
  min-width: 0;
  overflow-y: auto;
  background: var(--paper);
  border-left: 1px solid rgba(255, 255, 255, 0.8);
}

.inspector-tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px 12px;
  background: rgba(247, 245, 237, 0.96);
  border-bottom: 1px solid var(--line);
}

.inspector-tabs button {
  flex: 1;
}

.inspector-hero,
.route-hero {
  padding: 18px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--polity, #005826) 34%, white), transparent 80%),
    var(--paper-strong);
  border-bottom: 1px solid var(--line);
}

.inspector-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
}

.inspector-hero h2,
.route-hero h2 {
  margin: 3px 0 6px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 25px;
}

.inspector-hero p,
.route-hero p {
  margin: 0;
  color: #68736f;
  font-size: 11px;
  line-height: 1.7;
}

.score-ring {
  width: 67px;
  height: 67px;
  display: grid;
  place-content: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, #f8f5e9 59%, transparent 61%),
    conic-gradient(#397160 var(--score), #d9ded6 0);
  text-align: center;
}

.score-ring strong,
.score-ring span {
  display: block;
}

.score-ring strong {
  font-size: 17px;
}

.score-ring span {
  color: var(--muted);
  font-size: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-grid > div {
  min-height: 73px;
  padding: 12px 15px;
  background: #fbfaf3;
}

.metric-grid span,
.metric-grid strong,
.metric-grid small {
  display: block;
}

.metric-grid span {
  color: var(--muted);
  font-size: 9px;
}

.metric-grid strong {
  margin: 2px 0;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 17px;
}

.metric-grid small {
  color: #8a938f;
  font-size: 9px;
}

.positive {
  color: #39735b !important;
}

.negative {
  color: #a44e46 !important;
}

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

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title h3 {
  margin: 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 13px;
}

.section-title > span {
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.good-row {
  display: grid;
  grid-template-columns: 29px 72px 1fr 38px 36px;
  align-items: center;
  gap: 7px;
  min-height: 47px;
  border-top: 1px solid #e5e7e0;
}

.good-row:first-child,
.class-row:first-child {
  border-top: 0;
}

.good-icon {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--good) 60%, #4d5a55);
  background: color-mix(in srgb, var(--good) 25%, white);
  color: #394641;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 11px;
  transform: rotate(45deg);
}

.good-icon::first-line {
  transform: rotate(-45deg);
}

.good-row b,
.good-row small {
  display: block;
}

.good-row b {
  font-size: 11px;
}

.good-row small {
  color: var(--muted);
  font-size: 8px;
}

.good-row > strong {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  text-align: right;
}

.good-row em {
  font-style: normal;
  font-size: 8px;
  text-align: right;
}

.good-stock {
  min-width: 0;
}

.meter {
  display: block;
  height: 6px;
  overflow: hidden;
  background: #dfe4de;
  border-radius: 5px;
}

.meter i {
  display: block;
  height: 100%;
  background: #507e70;
  border-radius: inherit;
}

.meter.tight i {
  background: #ad554a;
}

.meter.surplus i {
  background: #b8984f;
}

.class-row {
  display: grid;
  grid-template-columns: 27px 105px 1fr 63px;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  border-top: 1px solid #e5e7e0;
}

.class-icon {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e1e6df;
  color: #53625c;
  font-size: 9px;
}

.class-row b,
.class-row small {
  display: block;
}

.class-row b {
  font-size: 10px;
}

.class-row small,
.class-money small {
  color: var(--muted);
  font-size: 8px;
}

.class-money {
  text-align: right;
}

.class-money strong {
  display: block;
  color: #3a765c;
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

.ledger,
.route-result {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
}

.ledger span,
.route-result span {
  padding: 11px;
  background: #efeee7;
  text-align: center;
}

.ledger small,
.ledger b,
.route-result small,
.route-result b {
  display: block;
}

.ledger small,
.route-result small {
  color: var(--muted);
  font-size: 8px;
}

.ledger b,
.route-result b {
  margin-top: 2px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}

.route-hero p {
  display: flex;
  align-items: center;
  gap: 10px;
}

.route-hero p i {
  color: var(--gold);
  font-style: normal;
}

.route-pressure {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 14px;
}

.route-pressure > span {
  display: grid;
  grid-template-columns: 22px 1fr auto 1fr;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid #d7ddd5;
  background: rgba(255, 255, 255, 0.53);
  font-family: ui-monospace, monospace;
  font-size: 9px;
}

.route-pressure i {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--good) 30%, white);
  font-style: normal;
}

.route-pressure em {
  color: var(--gold);
  font-style: normal;
}

.route-goods-head,
.route-goods-row {
  display: grid;
  grid-template-columns: minmax(72px, 0.72fr) repeat(2, minmax(105px, 1fr));
  align-items: center;
  gap: 8px;
}

.route-goods-head {
  padding: 0 0 7px;
  color: var(--muted);
  font-size: 8px;
  text-align: right;
}

.route-goods-head span {
  text-align: left;
}

.route-goods-row {
  min-height: 45px;
  border-top: 1px solid #e1e5de;
}

.route-good-name,
.route-flow-cell {
  min-width: 0;
}

.route-good-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}

.route-good-name i {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--good) 30%, white);
  font-style: normal;
}

.route-flow-cell {
  text-align: right;
}

.route-flow-cell strong,
.route-flow-cell small {
  display: block;
}

.route-flow-cell strong {
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

.route-flow-cell small {
  overflow: hidden;
  color: var(--muted);
  font-size: 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-policy label {
  display: block;
  padding: 10px 0;
  border-top: 1px solid #e1e5de;
}

.route-policy label > span {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
}

.route-policy input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 10px 0 5px;
  accent-color: var(--teal);
}

.route-policy label > small,
.route-switch span small {
  display: block;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.5;
}

.route-policy .route-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.route-switch input {
  width: 34px;
  height: 18px;
}

.connectivity-card {
  background: #f1f3ec;
}

.connectivity-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}

.connectivity-summary b,
.connectivity-summary span {
  padding: 4px 7px;
  border: 1px solid #d4dbd4;
  background: white;
  font-size: 9px;
}

.connectivity-card p,
.load-note {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.65;
}

.route-policy .embargo-switch {
  color: #8d443d;
}

.sandbox-fields,
.route-editor-fields {
  background: #f5f0df;
}

.sandbox-fields > label,
.productivity-fields label,
.route-editor-fields label {
  display: grid;
  gap: 4px;
  color: #5f6b67;
  font-size: 9px;
}

.city-affiliation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.city-affiliation-row label {
  display: grid;
  gap: 4px;
  color: #5f6b67;
  font-size: 9px;
}

.city-affiliation-row .compact-color {
  justify-items: center;
}

.sandbox-fields #edit-city-color {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 2px;
  overflow: hidden;
  border-radius: 50%;
}

.compact-color input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.compact-color input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.sandbox-fields input,
.sandbox-fields select,
.route-editor-fields input,
.route-editor-fields select {
  width: 100%;
  min-height: 29px;
  border: 1px solid #c8d0c9;
  background: white;
  color: var(--ink);
}

.productivity-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin: 8px 0;
}

.sandbox-fields .editor-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0;
}

.sandbox-fields .editor-check input {
  width: 18px;
}

.danger-button {
  width: 100%;
  min-height: 30px;
  border: 1px solid #bf837a;
  background: #fff5f2;
  color: #91483e;
}

.route-editor-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
}

.route-editor-fields small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 8px;
}

.empty-state {
  margin: 22px;
  padding: 34px 20px;
  border: 1px dashed #bec8c1;
  color: var(--muted);
  text-align: center;
}

.empty-state b {
  color: var(--ink);
}

.empty-state p {
  margin: 7px 0 0;
  font-size: 10px;
}

.analytics {
  grid-column: 1 / -1;
  min-width: 0;
  background: var(--paper-strong);
  border-top: 1px solid #bdc6bf;
}

.chart-tabs button {
  min-height: 29px;
  padding-inline: 11px;
  font-size: 10px;
}

.chart-wrap {
  height: 240px;
  padding: 12px 18px 4px;
}

.timeline-controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 10px;
  border-top: 1px solid #e1e5df;
  color: var(--muted);
  font-size: 10px;
}

.timeline-range {
  position: relative;
  height: 28px;
  min-width: 180px;
}

.timeline-range-track {
  position: absolute;
  inset: 12px 0 auto;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #d7ddd8;
}

.timeline-range-track i {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: inherit;
  background: var(--teal);
}

.timeline-range input {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  pointer-events: none;
  appearance: none;
  background: transparent;
}

.timeline-range input::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}

.timeline-range input::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  background: var(--paper-strong);
  box-shadow: 0 1px 4px rgba(40, 59, 53, 0.24);
  pointer-events: auto;
  appearance: none;
  cursor: ew-resize;
}

.timeline-range input::-moz-range-track {
  height: 4px;
  background: transparent;
}

.timeline-range input::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  background: var(--paper-strong);
  box-shadow: 0 1px 4px rgba(40, 59, 53, 0.24);
  pointer-events: auto;
  cursor: ew-resize;
}

.timeline-controls strong {
  min-width: 145px;
  color: #485751;
}

.timeline-controls button {
  min-height: 28px;
  border: 1px solid #bdc7c0;
  background: #f7f7f1;
  color: #40544e;
  cursor: pointer;
}

.timeline-controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

#history-chart {
  width: 100%;
  height: 100%;
}

.event-strip {
  display: flex;
  gap: 7px;
  padding: 7px 18px 14px;
  overflow-x: auto;
}

.event {
  min-width: 270px;
  padding: 8px 11px;
  border-left: 3px solid #98a59f;
  background: #eeeee8;
  color: #66726e;
  font-size: 9px;
}

.event b {
  margin-right: 8px;
  color: #42504b;
}

.event.good {
  border-color: #4f826f;
}

.event.warn {
  border-color: #ad554a;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  padding: 30px;
  border: 1px solid #9daaa3;
  background: #fbf9ef;
  color: var(--ink);
  box-shadow: 0 30px 100px rgba(30, 43, 39, 0.38);
}

dialog::backdrop {
  background: rgba(26, 38, 35, 0.68);
  backdrop-filter: blur(3px);
}

dialog h2 {
  margin: 5px 0 12px;
  font-family: "Songti SC", "SimSun", serif;
}

dialog p {
  color: #5f6d68;
  font-size: 12px;
  line-height: 1.85;
}

.dialog-close {
  position: absolute;
  right: 14px;
  top: 12px;
  border: 0;
  background: transparent;
  color: #7e8a85;
  font-size: 24px;
  cursor: pointer;
}

.flow-explainer {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 23px 0;
}

.flow-explainer div {
  flex: 1;
  padding: 12px 8px;
  border: 1px solid #ccd3cc;
  background: white;
  text-align: center;
}

.flow-explainer b,
.flow-explainer span {
  display: block;
}

.flow-explainer b {
  font-family: "Songti SC", "SimSun", serif;
}

.flow-explainer span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 8px;
}

.flow-explainer i {
  color: var(--gold);
  font-style: normal;
}

.metric-definition {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

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

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .world-stats div {
    min-width: 90px;
    padding-inline: 11px;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    min-height: 68px;
    padding: 10px 15px;
  }

  .world-stats div:nth-child(2),
  .world-stats div:nth-child(3) {
    display: none;
  }

  .brand {
    min-width: 0;
  }

  .controlbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 8px 12px;
  }

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

  .workspace {
    display: block;
  }

  .map-stage {
    min-height: 520px;
  }

  .inspector {
    max-height: none;
    border-top: 1px solid var(--line);
  }

  .route-goods-head,
  .route-goods-row {
    grid-template-columns: minmax(68px, 0.62fr) repeat(2, minmax(96px, 1fr));
  }

  .legend {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
