:root {
  --radius: 14px;
  --font: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  --bg-0: #060a13;
  --bg-1: #0a101f;
  --panel: rgba(15, 23, 42, 0.72);
  --panel-solid: #0f172a;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.30);
  --text-1: #e8eef9;
  --text-2: #94a3b8;
  --text-3: #5b6b84;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --up: #ff5d6c;
  --down: #2bd5a5;
  --flat: #94a3b8;
  --glow-up: rgba(255, 93, 108, 0.45);
  --glow-down: rgba(43, 213, 165, 0.45);
  --land: rgba(64, 130, 255, 0.10);
  --land-dim: rgba(64, 130, 255, 0.04);
  --land-stroke: rgba(125, 165, 255, 0.20);
  --sea-line: rgba(148, 163, 184, 0.06);
  --mask: rgba(2, 6, 14, 0.55);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
  --bg-0: #eef2f8;
  --bg-1: #f6f8fc;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.20);
  --text-1: #101828;
  --text-2: #55627a;
  --text-3: #98a2b3;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.10);
  --up: #e5484d;
  --down: #12a150;
  --flat: #64748b;
  --glow-up: rgba(229, 72, 77, 0.35);
  --glow-down: rgba(18, 161, 80, 0.35);
  --land: rgba(37, 99, 235, 0.12);
  --land-dim: rgba(37, 99, 235, 0.05);
  --land-stroke: rgba(37, 99, 235, 0.28);
  --sea-line: rgba(15, 23, 42, 0.05);
  --mask: rgba(15, 23, 42, 0.35);
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.14);
}

:root[data-color-mode="cn"] {
  --up: #ff5d6c;
  --down: #2bd5a5;
}
:root[data-theme="light"][data-color-mode="cn"] {
  --up: #e5484d;
  --down: #12a150;
}
:root[data-color-mode="us"] {
  --up: #2bd5a5;
  --down: #ff5d6c;
}
:root[data-theme="light"][data-color-mode="us"] {
  --up: #12a150;
  --down: #e5484d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(56, 189, 248, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(129, 140, 248, 0.08), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  flex-wrap: wrap;
}

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

.logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  position: relative;
  display: inline-block;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35), inset 0 0 8px rgba(56, 189, 248, 0.25);
}
.logo::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
}

.brand-text h1 {
  font-size: 17px;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.brand-text .sub {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.32em;
}

.stats {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
.stat { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.stat b { color: var(--text-1); font-weight: 600; }
.stat b.up { color: var(--up); }
.stat b.down { color: var(--down); }
.stat b.flat { color: var(--flat); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.up { background: var(--up); box-shadow: 0 0 8px var(--glow-up); }
.dot.down { background: var(--down); box-shadow: 0 0 8px var(--glow-down); }
.dot.flat { background: var(--flat); }

.controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 13px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.btn:hover {
  color: var(--text-1);
  border-color: var(--border-strong);
  background: var(--accent-soft);
}
.btn.accent {
  color: #04121f;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  border: none;
  font-weight: 600;
}
.btn.accent:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

main {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.map-panel {
  flex: 1.7;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(700px 340px at 70% 30%, rgba(56, 189, 248, 0.05), transparent 65%),
    var(--panel);
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 6px;
  flex-wrap: wrap;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  cursor: pointer;
  transition: all 0.16s;
}
.chip:hover { color: var(--text-1); border-color: var(--border-strong); }
.chip.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.map-hint {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
}

.map-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 4px 10px 10px;
}
#worldMap { width: 100%; height: 100%; display: block; }

#worldMap .continent {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: 0.8;
  transition: fill 0.25s, opacity 0.25s;
}
#worldMap .continent.dim { fill: var(--land-dim); opacity: 0.55; }
#worldMap .continent.active {
  fill: rgba(56, 189, 248, 0.14);
  stroke: var(--accent);
  stroke-width: 1.1;
}
#worldMap .sea { fill: var(--bg-0); stroke: var(--land-stroke); stroke-width: 0.6; }
#worldMap .graticule { stroke: var(--sea-line); stroke-width: 0.7; fill: none; }
#worldMap .continent-label {
  fill: var(--text-3);
  font-size: 13px;
  letter-spacing: 0.35em;
  font-family: var(--font);
  opacity: 0.75;
  pointer-events: none;
}
#worldMap .continent-label.dim { opacity: 0.18; }

#worldMap .bubble {
  stroke: var(--bg-0);
  stroke-width: 1.4;
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 0.25s;
  opacity: 0.92;
}
#worldMap .b-up { fill: var(--up); }
#worldMap .b-down { fill: var(--down); }
#worldMap .b-flat { fill: var(--flat); }
#worldMap .bubble.dim { opacity: 0.08; pointer-events: none; }
#worldMap .bubble:hover { opacity: 1; }
#worldMap .bubble.pulse { animation: bubblePulse var(--dur, 3.4s) ease-in-out infinite; }

@keyframes bubblePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(var(--pulse, 1.18)); }
}

#mapTooltip {
  position: absolute;
  pointer-events: none;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 12px;
  color: var(--text-2);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 30;
  min-width: 168px;
  transform: translate(-50%, calc(-100% - 14px));
}
#mapTooltip.show { opacity: 1; }
#mapTooltip .tt-name { color: var(--text-1); font-size: 13px; font-weight: 600; margin-bottom: 4px; }
#mapTooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; margin-top: 2px; }

.list-panel {
  width: 430px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.list-head {
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-1);
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 13px;
  outline: none;
  transition: border-color 0.18s;
}
.search-box input::placeholder { color: var(--text-3); }
.search-box input:focus { border-color: var(--accent); }

.tabs { display: flex; gap: 6px; }
.tab {
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.16s;
}
.tab:hover { color: var(--text-1); }
.tab.active { color: var(--accent); background: var(--accent-soft); }

.idx-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 6px 8px 10px;
}
.idx-list::-webkit-scrollbar { width: 8px; }
.idx-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.idx-list::-webkit-scrollbar-track { background: transparent; }

.idx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.idx-item:hover { background: var(--accent-soft); border-color: var(--border); }
.idx-item.selected { background: var(--accent-soft); border-color: var(--accent); }

.idx-rank {
  width: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  font-weight: 600;
  flex-shrink: 0;
}

.idx-main { flex: 1; min-width: 0; }
.idx-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.idx-country { font-size: 11.5px; color: var(--text-3); font-weight: 400; margin-left: 6px; }
.idx-point { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.idx-spark { flex-shrink: 0; }

.idx-chg { text-align: right; flex-shrink: 0; min-width: 74px; }
.idx-chg .pct { font-size: 13.5px; font-weight: 700; }
.idx-chg .abs { font-size: 11.5px; opacity: 0.8; margin-top: 2px; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px 0;
}

.drawer-mask {
  position: fixed;
  inset: 0;
  background: var(--mask);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 40;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--panel-solid);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 19px; }
.drawer-head p { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }

.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; }

.drawer-price { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.d-point { font-size: 34px; font-weight: 700; letter-spacing: 0.01em; }
.d-chg { display: flex; gap: 10px; font-size: 14.5px; font-weight: 600; }
.d-chg span { background: var(--accent-soft); border-radius: 7px; padding: 3px 9px; }

.d-range-tabs { margin: 18px 0 10px; display: flex; gap: 6px; }

.d-chart-wrap {
  height: 240px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-0);
}
#dChart { width: 100%; height: 100%; display: block; }

.d-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.d-cell {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
}
.d-cell .k { font-size: 11.5px; color: var(--text-3); }
.d-cell .v { font-size: 14px; font-weight: 600; margin-top: 3px; }

.ticker {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
  white-space: nowrap;
}
.ticker-track {
  display: inline-flex;
  align-items: center;
  padding: 11px 0;
  animation: tickerScroll 70s linear infinite;
  will-change: transform;
}
.ticker:hover .ticker-track { animation-play-state: paused; }
@keyframes tickerScroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.tk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 44px;
  font-size: 12.5px;
  color: var(--text-2);
}
.tk b { font-weight: 600; }

@media (max-width: 1100px) {
  body { overflow: auto; }
  main { flex-direction: column; overflow: visible; }
  .map-panel { min-height: 430px; flex: none; }
  .list-panel { width: auto; flex: 1; min-height: 360px; }
  .idx-list { overflow: visible; }
  .drawer { width: 100vw; }
}

@media (max-width: 900px) {
  .stat.extra { display: none; }
  .map-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track, #worldMap .bubble.pulse { animation: none; }
}
