:root {
  color-scheme: dark;
  --background: #0c2025;
  --panel: #10272bdc;
  --panel-solid: #112a2f;
  --ink: #f2eddb;
  --muted: #b4c8c6;
  --gold: #efca83;
  --gold-dim: #a98750;
  --stroke: #b9c5a22a;
  --serif: "Songti SC", "Noto Serif CJK SC", SimSun, serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  background: var(--background);
  color: var(--ink);
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  font: 1rem/1.5 var(--sans);
}

button, select, input { font: inherit; }
button {
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:hover { color: #fff5d8; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid #f5cb75;
  outline-offset: 3px;
}

a { color: var(--gold); text-underline-offset: .24em; }
[hidden] { display: none !important; }

.topbar {
  position: relative;
  z-index: 2;
  flex: none;
  min-height: 68px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 26px;
  padding: 0 26px;
  background: linear-gradient(100deg, #132e32 0%, #0c2026 58%, #122a2e);
  border-bottom: 1px solid #d5ad6770;
  box-shadow: 0 5px 25px #0615185e;
}

.identity, .top-actions { display: flex; align-items: center; gap: 13px; }
.identity h1 {
  margin: 0;
  font: 700 1.55rem/1 var(--serif);
  letter-spacing: .1em;
  white-space: nowrap;
}

.seal {
  width: 37px;
  height: 37px;
  display: grid;
  place-items: center;
  position: relative;
  border: 1px solid #d6ae70;
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px #0c2227, inset 0 0 0 4px #d6ae7055;
}
.seal span {
  width: 24px;
  height: 24px;
  background: linear-gradient(120deg, #fff2c4 49%, #b89558 50%);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
}

.scenes {
  display: flex;
  height: 42px;
  align-items: stretch;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  background: #081b20;
}
.scenes button {
  font-size: .9rem;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 0 14px;
  color: var(--muted);
}
.scenes button:hover { background: #ffffff10; }
.scenes button[aria-pressed="true"] {
  color: #fff3cf;
  border-color: #c5a76b89;
  background: linear-gradient(180deg, #d3a46538, #af80401a);
}

.top-actions { justify-content: flex-end; gap: 8px; }
.top-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 11px;
  white-space: nowrap;
  font-size: .88rem;
  border: 1px solid var(--stroke);
  border-radius: 4px;
  color: var(--muted);
}
.top-action:hover { border-color: var(--gold-dim); }
.search-mark {
  width: 12px;
  height: 12px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  position: relative;
}
.search-mark::after {
  position: absolute;
  content: "";
  height: 1.5px;
  width: 5px;
  background: currentColor;
  transform: rotate(48deg);
  left: 8px;
  top: 9px;
}

.atlas { flex: 1; min-height: 0; position: relative; overflow: hidden; isolation: isolate; }
#map, .map-shadow { position: absolute; inset: 0; }
#map { background: #143f4b; }
#map > .atlas-renderer { position: absolute; inset: 0; visibility: hidden; pointer-events: none; }
#map > .atlas-renderer--active { visibility: visible; pointer-events: auto; }
.atlas-renderer.leaflet-container { background: #143f4b; font-family: var(--sans); }
.flat-map-label {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #fff5d9;
  white-space: nowrap;
  font: 600 .76rem/1.3 var(--sans);
  text-shadow: 0 1px 2px #12282a, 0 0 4px #152c2d, 0 0 4px #152c2d;
}
.flat-map-label--country { font-size: .92rem; letter-spacing: .04em; }
.flat-map-label--land { color: #f2dfad; font-family: var(--serif); }
.flat-map-label--water { color: #a6d3d5; letter-spacing: .095em; font: italic 600 .9rem var(--serif); }
.flat-map-label--facility { color: #fff0c7; font-size: .82rem; }
.flat-map-label--facility::before {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto 2px;
  background: #f2ce88;
  border: 1px solid #173439;
  border-radius: 50%;
}
.flat-map-label--port { transform: translate(-8px, -50%); display: flex; align-items: center; gap: 6px; padding: 4px 5px 4px 3px; }
.flat-map-label--port::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: none;
  transform: rotate(45deg);
  background: #edc380;
  border: 1px solid #ffecae;
  box-shadow: 0 0 0 2px #173137;
}
.flat-map-label--port.selected-port { color: #ffe5a5; }
.flat-map-label--port.selected-port::before { background: #fff2b1; box-shadow: 0 0 0 2px #5e441f, 0 0 10px #ffce69; }
.flat-map-label--port:hover { z-index: 1; color: #ffedb7; background: #0f292bd9; border-radius: 3px; }
.map-shadow {
  pointer-events: none;
  box-shadow: inset 0 0 100px #07232632, inset 0 -36px 62px #0a252b61;
}
.map-status {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(90%, 420px);
  border: 1px solid var(--stroke);
  background: var(--panel-solid);
  border-radius: 5px;
  padding: 12px 22px;
  text-align: center;
}
.control-surface {
  border: 1px solid #b2c2a55c;
  background: linear-gradient(153deg, #133137f5, #0a1f24f0);
  color: var(--ink);
  border-radius: 6px;
  box-shadow: 0 5px 22px #06181c49, inset 0 1px #d8e4c013;
}
.map-left { position: absolute; left: 20px; top: 21px; display: grid; justify-items: start; gap: 13px; }
.layers { padding: 9px 7px 7px; }
.layers h2 { margin: 0 0 7px 9px; font-weight: 550; font-size: .83rem; color: var(--muted); }
.layer-buttons { display: grid; gap: 3px; }
.layer-buttons button {
  display: flex;
  min-height: 39px;
  width: 107px;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: .93rem;
}
.layer-buttons button:hover { background: #bedbd51b; }
.layer-buttons button[data-layer="regional"] { line-height: 1.14; }
.layer-buttons button[aria-pressed="true"] {
  border-color: #d5b27580;
  color: #ffe7ae;
  background: linear-gradient(105deg, #c7964d36, #9885501e);
}
.layer-emblem { width: 18px; height: 18px; flex: none; }

.camera { padding: 2px; display: grid; }
.camera button {
  width: 39px;
  height: 38px;
  border-radius: 3px;
  font: 600 .86rem/1 var(--mono);
}
.camera button + button { border-top: 1px solid #bacda71f; }
.camera button:hover { background: #cedeb21f; }
.camera button:disabled { opacity: .48; cursor: default; background: none; }
.camera button[aria-pressed="true"] { background: #97805045; color: var(--gold); }
.camera #zoom-in, .camera #zoom-out, .grid-mark { font: 1.35rem/1 var(--sans); }
.compass-needle {
  display: inline-block;
  width: 17px;
  height: 25px;
  transform: rotate(var(--needle-angle, 0deg));
  background: linear-gradient(#f3c980 0 50%, #91b3ae 50% 100%);
  clip-path: polygon(50% 0%, 82% 54%, 50% 100%, 18% 54%);
}

.scale-and-legend { position: absolute; bottom: 31px; left: 20px; display: grid; justify-items: start; gap: 8px; pointer-events: none; }
.legend { min-width: 152px; max-width: 260px; padding: 10px 12px; font-size: .83rem; pointer-events: auto; }
.legend-title { color: var(--ink); font-weight: 650; }
.legend-detail { color: var(--muted); font-size: .77rem; }
.legend-list { display: grid; margin-top: 9px; gap: 5px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.swatch { display: inline-block; width: 12px; height: 8px; border-radius: 2px; border: 1px solid #ffffff33; }
.swatch.line { width: 16px; height: 0; border: 0; border-top: 2px dashed var(--gold); }
.swatch.port { height: 10px; width: 10px; margin-inline: 2px; background: var(--gold); transform: rotate(45deg); border: 0; }
.swatch.boundary { height: 0; width: 16px; border: 0; border-top: 1px dashed #dcd2bc; }
.legend-ramp { margin-top: 8px; border-radius: 2px; height: 7px; border: 1px solid #ffffff26; }
.legend-range { display: flex; justify-content: space-between; gap: 22px; margin-top: 3px; color: var(--muted); }
.view-status { max-width: 180px; padding: 7px 9px; font-size: .78rem; }
#scale {
  background: #0e282cbb;
  border: 1px solid #e9e3cb;
  border-top: 0;
  text-align: center;
  color: #fff9e8;
  font: 12px/19px var(--mono);
  white-space: nowrap;
  box-shadow: 0 2px 8px #06181c80;
}

.inspector {
  position: absolute;
  right: 22px;
  top: 21px;
  width: 345px;
  max-height: calc(100% - 60px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #5a756c #172c2e;
}
.inspector-head {
  display: flex;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 6px 12px 6px 17px;
  background: linear-gradient(90deg, #a68c4f2b, transparent 80%);
  border-bottom: 1px solid #a9b69c3d;
}
.inspector-head span { color: #f0d4a0; font-size: .83rem; letter-spacing: .08em; }
.inspector-head button, .dialog-head button { font: 1.45rem/1 var(--sans); min-width: 30px; min-height: 30px; color: var(--muted); }
.inspector-body { padding: 18px; }
.inspector-body h2, .dialog-head h2 {
  margin: 0;
  font: 700 1.78rem/1.22 var(--serif);
  letter-spacing: .035em;
  overflow-wrap: anywhere;
}
.inspector-body .subhead { color: var(--muted); font-size: .84rem; margin: 5px 0 0; }
.inspector-body p { font-size: .91rem; color: #d5e2db; margin: 13px 0; line-height: 1.65; }
.inspector-body .fine { font-size: .81rem; color: var(--muted); }
.inspector-body .source-link { display: inline-block; font-size: .81rem; margin-top: 8px; }
.surface-directory { margin-block: 10px; }
.surface-directory summary { color: var(--gold); cursor: pointer; padding-block: 5px; font-size: .86rem; }
.surface-directory .port-list button { text-align: start; }
.surface-play { display: inline-flex; align-items: center; text-decoration: none; }
.inspector-body h3 { font-size: .94rem; margin: 18px 0 9px; font-weight: 650; }

.focus-stat {
  margin: 16px 0 12px;
  padding: 12px 0;
  border-block: 1px solid var(--stroke);
}
.metric-number {
  font: 600 clamp(1.6rem, 3vw, 2.13rem)/1.06 var(--mono);
  color: #ffe3a7;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
}
.metric-unit { color: var(--muted); font-size: .82rem; margin: 3px 0; }
.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 11px;
  margin: 14px 0;
  font-size: .87rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.kv dd.positive { color: #a5dfbf; }
.kv dd.negative { color: #f1b69a; }

.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.primary, .secondary {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid #bdab7866;
  border-radius: 4px;
  font-size: .86rem;
  font-weight: 600;
}
.primary {
  border-color: #f1d49d;
  background: linear-gradient(#f3d59c, #d7ae6b);
  color: #1a2a27;
  box-shadow: inset 0 1px #fff2c9;
}
.primary:hover { color: #162420; background: #ffe4b0; }
.secondary { color: #edd4a1; background: #e0c38610; }
.secondary:hover { background: #e0c3862a; }
.port-list { display: grid; gap: 4px; }
.port-list button, .search-results button {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 7px 9px;
  border: 1px solid var(--stroke);
  border-radius: 4px;
  background-color: #e1ebd009;
  min-height: 35px;
  font-size: .85rem;
}
.port-list button:hover, .search-results button:hover { background: #ddc39023; border-color: #c0a76c72; }
.port-list button span:last-child { color: #e6c791; font-family: var(--mono); white-space: nowrap; }
.year-control { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
select {
  color: var(--ink);
  border: 1px solid #abc3ba61;
  border-radius: 4px;
  background: #1b363a;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #c6cbb1 50%), linear-gradient(135deg, #c6cbb1 50%, transparent 50%);
  background-size: 5px 5px;
  background-position: right 12px center, right 7px center;
  background-repeat: no-repeat;
  min-height: 34px;
  font-size: .86rem;
  padding: 4px 23px 4px 8px;
}
.section-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-bar h3 { margin: 12px 0; }
.comparison-selects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 15px 0 12px; }
.comparison-selects label { font-size: .78rem; color: var(--muted); }
.comparison-selects select { display: block; width: 100%; margin-top: 4px; }
.compare-bars { margin: 12px 0; display: grid; gap: 10px; }
.compare-bar-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: .85rem; }
.compare-bar-label strong { font: 600 .85rem var(--mono); white-space: nowrap; }
.compare-bar-track { margin-top: 5px; height: 7px; border-radius: 2px; background: #bfd5d221; overflow: hidden; }
.compare-bar-track i { display: block; height: 100%; border-radius: 2px; background: #e6bc78; }
.compare-bar:nth-child(2) .compare-bar-track i { background: #8cc9c2; }
.compare-table { width: 100%; border-collapse: collapse; font-size: .81rem; margin: 12px 0 5px; }
.compare-table th, .compare-table td { padding: 8px 3px; border-bottom: 1px solid var(--stroke); text-align: right; }
.compare-table th:first-child { text-align: left; font-weight: 500; color: var(--muted); }
.compare-table td { font-variant-numeric: tabular-nums; }
.source-list { margin: 13px 0 0; padding: 0; display: grid; gap: 6px; list-style: none; font-size: .81rem; }
.insight { background: #c7ad6816; border-left: 2px solid #b79b61; padding: 8px 10px; }

.map-footer {
  position: absolute;
  left: 20px;
  right: 22px;
  bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #d4ded7;
  font-size: .75rem;
  text-shadow: 0 1px 2px #051419;
  pointer-events: none;
}
.map-footer button { pointer-events: auto; font-size: inherit; }
.map-footer button:hover { text-decoration: underline; }
#map .maplibregl-popup-content {
  color: var(--ink);
  background: #0c262bec;
  border: 1px solid #c5ac7188;
  border-radius: 4px;
  padding: 7px 10px;
  font: 600 .82rem/1.4 var(--sans);
  box-shadow: 0 4px 16px #07191e88;
}
#map .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #0c262bec; }
#map .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #0c262bec; }
#map .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #0c262bec; }
#map .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #0c262bec; }

.atlas-dialog {
  width: min(94vw, 510px);
  max-height: min(83dvh, 720px);
  padding: 0 20px 21px;
  color: var(--ink);
  background: #132d32;
  border: 1px solid #b99d65a1;
  border-radius: 7px;
  box-shadow: 0 18px 70px #001014b8;
}
.atlas-dialog::backdrop { background: #081c22b9; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 0 14px; }
.dialog-head h2 { font-size: 1.38rem; }
.atlas-dialog input {
  width: 100%;
  border: 1px solid #b7d1c775;
  padding: 10px 12px;
  border-radius: 4px;
  background: #0b2328;
  color: var(--ink);
}
.search-results { display: grid; margin-top: 12px; gap: 5px; }
.search-results button { min-height: 41px; }
.search-results button small { color: var(--muted); }
.sources-dialog { width: min(94vw, 680px); }
.sources-dialog h3 { margin: 1rem 0 .3rem; font-size: 1rem; color: #efcf98; }
.sources-dialog p { font-size: .92rem; margin: .4rem 0; color: #cfddd7; }
.sources-dialog ul { list-style: none; padding: 0; margin: .35rem 0; display: grid; gap: 5px; font-size: .87rem; }

@media (max-width: 880px) {
  .topbar { column-gap: 13px; padding-inline: 16px; }
  .identity h1 { font-size: 1.27rem; }
  .seal { width: 30px; height: 30px; }
  .seal span { width: 20px; height: 20px; }
  .scenes button { padding-inline: 9px; }
  .inspector { width: 296px; right: 13px; }
}

@media (min-width: 651px) and (max-height: 720px) {
  .scale-and-legend { left: 74px; }
}

@media (max-width: 650px) {
  .topbar { grid-template-columns: 1fr auto; padding: 8px 11px; row-gap: 8px; }
  .identity { gap: 7px; }
  .identity h1 { font-size: 1.12rem; }
  .scenes { grid-row: 2; grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); height: 37px; }
  .top-actions { grid-column: 2; grid-row: 1; gap: 5px; }
  .top-action { min-height: 33px; font-size: .79rem; padding-inline: 7px; }
  .map-left { left: 9px; right: 9px; top: 9px; gap: 8px; }
  .map-left { pointer-events: none; }
  .map-left > :not(.view-status) { pointer-events: auto; }
  .layers { width: 100%; padding: 3px; }
  .layers h2 { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); }
  .layer-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; }
  .layer-buttons button { width: auto; min-height: 35px; gap: 4px; justify-content: center; padding: 0 3px; font-size: .78rem; }
  .layer-emblem { width: 13px; height: 13px; }
  .camera button { width: 31px; height: 32px; }
  .inspector { top: auto; bottom: 28px; left: 9px; right: 9px; width: auto; max-height: 39%; }
  .inspector-head { min-height: 36px; padding-block: 2px; }
  .inspector-body { padding: 12px; }
  .inspector-body h2 { font-size: 1.42rem; }
  .scale-and-legend { top: 61px; bottom: auto; left: auto; right: 9px; justify-items: end; }
  body:not(.development-mode) .scale-and-legend { top: 99px; }
  .legend { max-width: 143px; min-width: auto; padding: 5px 8px; font-size: .73rem; }
  .legend-list { margin-top: 5px; }
  .legend-detail { font-size: .68rem; }
  .legend-range { gap: 8px; }
  .map-footer { left: 9px; right: 9px; justify-content: end; font-size: .69rem; }
  .mouse-help { display: none; }
}

.stat-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.stat-controls label { display: grid; gap: 4px; min-width: 0; font-size: .74rem; color: var(--muted); }
.stat-controls select {
  box-sizing: border-box;
  width: 100%;
  min-height: 32px;
  min-width: 0;
  padding: 3px 21px 3px 6px;
  border: 1px solid #abc3ba61;
  border-radius: 4px;
  background-color: #0e272b;
  color: var(--ink);
  font: 500 .82rem/1.2 var(--sans);
  text-overflow: ellipsis;
}
.stat-controls select:disabled { opacity: .64; }
.regional-map-controls { grid-template-columns: minmax(0, 1fr); margin-top: 6px; }
.regional-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
.regional-table thead th:not(:first-child) { color: var(--region-color); overflow-wrap: anywhere; }
.regional-table td { white-space: nowrap; }
.regional-table tr[aria-current="true"] { background: #d9ba6a1f; }
.regional-table button {
  display: block;
  margin-inline-start: auto;
  min-height: 27px;
  padding: 1px 0;
  font-size: .75rem;
  text-decoration: underline;
}
.regional-study .regional-scope { margin-block: 0 8px; }
.legend[data-statistics] { width: 249px; }
.stat-ramp { display: flex; border-radius: 2px; overflow: hidden; margin-top: 7px; }
.stat-swatch { flex: 1; height: 7px; }
.stat-coverage { margin-top: 6px; color: var(--muted); font-size: .72rem; line-height: 1.25; }
.stat-coverage .swatch { flex: 0 0 12px; }
.stat-loading { margin-top: 6px; color: var(--muted); font-size: .76rem; }
.stat-loading button { padding: 2px 6px; min-height: 28px; }
.stat-study { margin-top: 12px; }
.stat-readings { display: grid; gap: 5px; margin-top: 10px; }
.stat-reading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-inline-start: 2px solid var(--stat-line);
  background: #b7d7d30c;
  color: var(--muted);
  font-size: .78rem;
}
.stat-reading strong { color: var(--stat-line); font: 600 .94rem/1.25 var(--mono); text-align: end; }
.stat-trend { margin: 12px 0 6px; }
.stat-trend figcaption { color: var(--muted); font-size: .75rem; }
.stat-trend canvas { display: block; width: 100%; height: 138px; cursor: crosshair; touch-action: pan-y; }
.stat-table summary { color: var(--gold); font-size: .81rem; cursor: pointer; padding: 7px 0; }
.stat-table table { margin-top: 4px; }
.stat-table tr[aria-current="true"] { background: #d9ba6a1f; }
.stat-table th button { min-height: 27px; color: var(--gold); text-align: start; padding: 0; }
.stat-table th button:hover { text-decoration: underline; }
.inspector-body .stat-notes { margin-bottom: 4px; }
.stat-sources { display: grid; justify-items: start; gap: 4px; }
.inspector-body .stat-sources .source-link { margin-top: 2px; }

@media (max-width: 650px) {
  .legend[data-statistics] { width: min(205px, 63vw); max-width: none; }
  .stat-controls select { min-height: 36px; }
  .stat-reading { padding: 5px 7px; }
  .atlas:has(.legend[data-statistics]) .stat-study .stat-controls { display: none; }
  .atlas:has(.stat-study) #inspector .comparison-selects { margin-block: 9px 6px; }
}
