:root {
  --bg: #f3ede3;
  --panel: rgba(255, 250, 242, 0.9);
  --line: rgba(72, 49, 38, 0.14);
  --ink: #1e1713;
  --muted: #6f6258;
  --accent: #cb4f34;
  --accent-2: #efc85a;
  --shadow: 0 18px 48px rgba(40, 25, 17, 0.16);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(239, 200, 90, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(203, 79, 52, 0.1), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: "Noto Sans SC", sans-serif;
}

body { padding: 18px; }

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  min-height: calc(100vh - 36px);
}

.sidebar, .stage {
  border-radius: 28px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  background: linear-gradient(180deg, rgba(255,251,246,0.94), rgba(255,248,239,0.84));
  padding: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 800;
}

.sidebar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.lede {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
  margin: 14px 0 0;
}

.panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255,255,255,0.46);
  border: 1px solid rgba(72,49,38,0.08);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel-head h2, .map-header h2 {
  margin: 0;
  font-size: 18px;
}

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

.metric-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,0.62);
  border: 1px solid rgba(72,49,38,0.08);
}

.metric-card .label {
  color: var(--muted);
  font-size: 12px;
}

.metric-card .value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 800;
}

.segmented {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented button {
  border: 1px solid rgba(72,49,38,0.1);
  background: rgba(255,255,255,0.72);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
}

.segmented button.is-active {
  background: linear-gradient(90deg, rgba(203,79,52,0.18), rgba(239,200,90,0.28));
  border-color: rgba(203,79,52,0.28);
}

.switch-row {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
}

.explain {
  color: var(--muted);
  line-height: 1.75;
  font-size: 14px;
}

.ranking {
  display: grid;
  gap: 10px;
}

.rank-item {
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(72,49,38,0.1);
}

.rank-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.rank-name {
  font-weight: 700;
}

.rank-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.stage {
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(255,252,247,0.88);
  min-height: calc(100vh - 36px);
}

.map-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.map-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.badge-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.badge-group span {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(72,49,38,0.08);
  color: var(--muted);
  font-size: 12px;
}

.map-wrap {
  position: relative;
  height: 100%;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 640px;
}

.label-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  overflow: hidden;
}

.reset-view-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 20;
  border: 1px solid rgba(34, 93, 216, 0.22);
  background: rgba(255, 255, 255, 0.9);
  color: #245dd8;
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(24, 60, 142, 0.14);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.reset-view-btn.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.reset-view-btn:hover {
  background: rgba(238, 245, 255, 0.98);
}

.map-label {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  color: #4d3d35;
  text-shadow:
    0 0 2px rgba(255, 251, 245, 0.95),
    0 0 6px rgba(255, 251, 245, 0.95);
  opacity: 0.92;
  font-weight: 700;
}

.map-label.province {
  font-size: 14px;
  color: #3d2f29;
}

.map-label.city {
  font-size: 11px;
  color: #69574d;
  font-weight: 500;
}

.map-label.county {
  font-size: 10px;
  color: #6a564d;
  font-weight: 500;
  opacity: 0.92;
  text-shadow:
    0 0 2px rgba(255, 251, 245, 0.98),
    0 0 8px rgba(255, 251, 245, 0.98),
    0 0 14px rgba(255, 251, 245, 0.92);
}

.maplibregl-popup-content {
  font-family: "Noto Sans SC", sans-serif;
  border-radius: 16px;
  padding: 14px 16px;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}
