:root {
  --bg: #04070d;
  --glass: rgba(14, 20, 32, 0.78);
  --glass-strong: rgba(14, 20, 32, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e9edf3;
  --muted: #98a3b3;
  --faint: #6b7686;
  --accent: #ffd166;
  --accent-2: #63e6be;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); overflow: hidden; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent-2); }

#stage { position: fixed; inset: 0; touch-action: none; cursor: grab; }
#stage.dragging { cursor: grabbing; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
#globe-hit { position: absolute; border-radius: 50%; cursor: pointer; }

.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- top bar ---------- */
#topbar { position: fixed; top: 12px; left: 12px; right: 12px; height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 10px 0 12px; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: 0.2px; padding: 8px 14px 8px 10px; }
.brand, #world-switch, #search, #panel-toggle { background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); }
.segmented { display: inline-flex; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; color: var(--muted); cursor: pointer; font-weight: 600; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] { background: rgba(255, 255, 255, 0.12); color: var(--text); }
#topbar .segmented button { padding: 7px 16px; }
#search { margin-left: auto; position: relative; display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 40px; width: min(340px, 40vw); color: var(--muted); }
#search input { flex: 1; border: 0; outline: none; background: none; color: var(--text); min-width: 0; }
#search input::placeholder { color: var(--faint); }
#search:focus-within { border-color: rgba(255, 209, 102, 0.5); }
#search-results { position: absolute; top: 46px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; max-height: 360px; overflow: auto; background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
#search-results li { padding: 7px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; color: var(--text); }
#search-results li small { color: var(--faint); white-space: nowrap; }
#search-results li[aria-selected="true"], #search-results li:hover { background: rgba(255, 255, 255, 0.09); }
.icon-btn { width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass); color: var(--text); display: grid; place-items: center; cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { border-color: var(--line-strong); background: var(--glass-strong); }
#panel-toggle { display: none; }

/* ---------- panel ---------- */
#panel { position: fixed; top: 72px; left: 12px; bottom: 12px; width: 296px; overflow-y: auto; padding: 6px 0 10px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }
#panel { background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.sec { padding: 10px 14px 8px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h3 { margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.9px; color: var(--faint); }
.sec h4 { margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row + .row, .chips + .row { margin-top: 10px; }
.row label { color: var(--muted); min-width: 92px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: rgba(255,255,255,0.03); color: var(--muted); padding: 5px 10px; border-radius: 999px; cursor: pointer; font-weight: 500; }
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip[aria-pressed="true"] { color: #10151f; background: var(--accent); border-color: var(--accent); }
.layer-list { list-style: none; margin: 0; padding: 0; }
.layer-list li button { width: 100%; text-align: left; display: flex; align-items: center; gap: 9px; padding: 6px 8px; border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--text); }
.layer-list li button:hover { background: rgba(255,255,255,0.06); }
.layer-list li button .dot { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--faint); flex: none; display: grid; place-items: center; }
.layer-list li button[aria-pressed="true"] { background: rgba(255, 209, 102, 0.1); }
.layer-list li button[aria-pressed="true"] .dot { border-color: var(--accent); }
.layer-list li button[aria-pressed="true"] .dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.layer-list li button .tag { margin-left: auto; font-size: 10px; color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; text-transform: uppercase; letter-spacing: 0.4px; }
.toggle { display: flex; align-items: center; gap: 9px; padding: 5px 2px; cursor: pointer; color: var(--text); }
.toggle input { appearance: none; width: 30px; height: 17px; border-radius: 999px; background: rgba(255,255,255,0.15); position: relative; cursor: pointer; margin: 0; flex: none; transition: background 0.15s; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked { background: var(--accent-2); }
.toggle input:checked::after { transform: translateX(13px); }
input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
.val { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }
.panel-foot { padding: 10px 14px 4px; color: var(--faint); font-size: 12px; }
.panel-foot button { background: none; border: 0; padding: 0; color: var(--accent-2); cursor: pointer; text-decoration: underline; }
.hint { color: var(--faint); font-size: 12px; margin: 6px 0 0; }

/* ---------- legend ---------- */
#legend { position: fixed; left: 324px; bottom: 12px; width: 330px; max-height: calc(100vh - 110px); overflow: auto; padding: 12px 14px; display: none; }
#legend.show { display: block; }
#legend { background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
#legend h2 { margin: 0; font-size: 14px; font-weight: 600; }
#legend .sub { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
#legend .blurb { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
#legend .credit { color: var(--faint); font-size: 11px; margin-top: 6px; }
#legend canvas.bar { width: 100%; height: 12px; border-radius: 3px; display: block; }
.ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap; }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }
.units { font-size: 11px; color: var(--faint); }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; margin-top: 2px; }
.swatches div { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text); min-width: 0; }
.swatches div span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatches i { width: 11px; height: 11px; border-radius: 3px; flex: none; border: 1px solid rgba(255,255,255,0.15); }
.swatches i.round { border-radius: 50%; }
.legend-block + .legend-block { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.legend-block h5 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.series { display: flex; align-items: center; gap: 10px; margin: 10px 0 2px; }
.series .icon-btn { width: 32px; height: 32px; font-size: 13px; flex: none; }
.series .month { min-width: 74px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- tooltip, info ---------- */
#tooltip { position: fixed; z-index: 20; pointer-events: none; max-width: 280px; padding: 8px 11px; background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; }
#tooltip .t { font-weight: 600; font-size: 13px; }
#tooltip .k { color: var(--muted); }
#tooltip .v { font-weight: 600; }
#tooltip .c { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
#tooltip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: baseline; }
#info { position: fixed; top: 72px; right: 12px; width: 330px; max-height: calc(100vh - 330px); overflow: auto; padding: 14px 16px; }
#info { background: var(--glass-strong); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
#info h2 { margin: 0 26px 2px 0; font-size: 16px; }
#info .sub { color: var(--muted); margin-bottom: 8px; }
#info p { margin: 8px 0; }
#info .close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; font-size: 16px; }
#info table { width: 100%; border-collapse: collapse; font-size: 12px; }
#info td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
#info td:first-child { color: var(--muted); padding-right: 10px; }
#info td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#info td small { color: var(--faint); }
#info .src { font-size: 11px; color: var(--faint); margin-top: 8px; word-break: break-all; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(255,255,255,0.1); margin-right: 4px; }

/* ---------- HUD / zoom / credit ---------- */
#hud { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 7px 14px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; pointer-events: none; }
#hud { background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); }
.hud-sep { width: 1px; height: 14px; background: var(--line-strong); }
#hud-scale { display: inline-flex; align-items: center; gap: 6px; }
#hud-scale i { display: inline-block; height: 6px; border: 1.5px solid var(--text); border-top: 0; }
#zoom-ctl { position: fixed; display: flex; flex-direction: column; gap: 6px; }
#credit { position: fixed; right: 14px; bottom: 6px; font-size: 10.5px; color: rgba(255,255,255,0.45); max-width: 46vw; text-align: right; pointer-events: none; text-shadow: 0 1px 2px #000; }

#loading { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); transition: opacity 0.25s; }
#loading.hide { opacity: 0; pointer-events: none; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog#about { max-width: 640px; width: calc(100% - 32px); max-height: calc(100vh - 64px); color: var(--text); background: #0e1420; border: 1px solid var(--line-strong); border-radius: 14px; padding: 22px 24px; box-shadow: var(--shadow); }
dialog#about::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog#about h2 { margin: 0 0 8px; }
dialog#about h3 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
dialog#about ul { padding-left: 18px; margin: 6px 0; }
dialog#about li { margin: 3px 0; color: var(--muted); }
dialog#about li b { color: var(--text); font-weight: 600; }
dialog#about .close { float: right; }

.error-box { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--text); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  #topbar { gap: 8px; top: 8px; left: 8px; right: 8px; }
  .brand span { display: none; }
  .brand { padding: 7px; }
  #panel-toggle { display: grid; }
  #search { width: auto; flex: 1; min-width: 0; }
  #topbar .segmented button { padding: 7px 11px; }
  #panel { top: 64px; left: 8px; right: 8px; bottom: auto; width: auto; max-height: 62vh; display: none; z-index: 10; }
  body.panel-open #panel { display: block; }
  #legend { left: 8px; right: 8px; width: auto; bottom: 52px; max-height: 34vh; padding: 10px 12px; }
  #legend .blurb, #legend .credit { display: none; }
  #info { top: auto; bottom: 52px; left: 8px; right: 8px; width: auto; max-height: 45vh; z-index: 11; }
  #hud { bottom: 8px; font-size: 11px; padding: 6px 12px; }
  #credit { display: none; }
}
