:root {
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;

  --bg: #f4f0e8;
  --surface: #fffcf7;
  --surface-2: #efe9de;
  --ink: #1f1b16;
  --ink-2: #4b453c;
  --muted: #847b6e;
  --line: #e5ddcf;

  --land: #e4ddd0;
  --land-hover: #d7cdbc;
  --ctx: #ece6db;
  --lit: #d4471f;
  --lit-hover: #b93a17;
  --lit-soft: #fae3d8;
  --on-lit: #fff;
  --mesh-city: #fffcf7;
  --mesh-prov: #a99e8c;
  --outline: #8a8072;
  --halo: rgba(255, 252, 247, .85);
  --lv1: #f6cdb5;
  --lv2: #f0a888;
  --lv3: #e7845d;
  --lv4: #db6237;
  --lv5: #c2401a;
  --danger: #b42318;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(70, 50, 20, .05), 0 6px 20px rgba(70, 50, 20, .06);
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519;
    --surface: #1a1e23;
    --surface-2: #242a31;
    --ink: #eeebe6;
    --ink-2: #c3beb6;
    --muted: #8d939b;
    --line: #2b3239;

    --land: #2c333b;
    --land-hover: #38414b;
    --ctx: #20262c;
    --lit: #ff7043;
    --lit-hover: #ff8a63;
    --lit-soft: #3a2219;
    --on-lit: #1d0d06;
    --mesh-city: #1a1e23;
    --mesh-prov: #57616c;
    --outline: #6c7783;
    --halo: rgba(26, 30, 35, .85);
    --lv1: #4a2b21;
    --lv2: #723725;
    --lv3: #a3452a;
    --lv4: #d6582f;
    --lv5: #ff7a4d;
    --danger: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--lit); outline-offset: 2px; }

/* ---------- 顶栏 & 导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 19px; letter-spacing: .04em; }
.brand-mark { width: 24px; height: 24px; fill: var(--lit); }
.brand-mark circle { fill: var(--bg); }
.poster-btn { margin-left: auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500;
}
.tabs a .ico { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--lit); }
.tabs a[aria-current="page"] .ico { stroke-width: 2.1; }

main {
  max-width: 1180px; margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left));
}

@media (min-width: 900px) {
  /* backdrop-filter 会让 fixed 子元素以顶栏为参照，所以只在桌面端（导航不再 fixed）启用 */
  .topbar {
    padding-left: 28px; padding-right: 28px;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
  }
  .tabs { position: static; padding: 0; margin-left: 20px; background: none; border: 0; gap: 4px; }
  .tabs a { flex: none; flex-direction: row; gap: 6px; padding: 7px 14px; border-radius: 999px; font-size: 14px; }
  .tabs a .ico { width: 18px; height: 18px; }
  .tabs a:hover { color: var(--ink); }
  .tabs a[aria-current="page"] { background: var(--lit-soft); }
  main { padding: 8px 28px 48px; }
}

body.is-shared .tabs { display: none; }
body.is-shared main { padding-bottom: 40px; }

/* ---------- 通用组件 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card h2 { font-size: 16px; font-weight: 700; }
.link { color: var(--lit); text-decoration: none; font-size: 14px; font-weight: 500; }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: .02em; margin: 6px 0 2px; }
.page-sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 9px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn .ico { width: 18px; height: 18px; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 14px; border-radius: 10px; }
.btn-primary { background: var(--lit); border-color: var(--lit); color: var(--on-lit); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
@media (hover: hover) {
  .btn:hover { border-color: var(--mesh-prov); }
  .btn-primary:hover { background: var(--lit-hover); border-color: var(--lit-hover); }
  .btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
}

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn.sm .ico { width: 17px; height: 17px; }
@media (hover: hover) { .icon-btn:hover { background: var(--surface-2); } }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 11px; }
.seg button {
  border: 0; background: transparent; padding: 5px 13px; border-radius: 8px;
  color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.field { display: flex; align-items: center; gap: 10px; }
.field span { color: var(--muted); font-size: 14px; flex: none; }
.field input, .search input {
  width: 100%; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: 16px;
}
.field input:focus, .search input:focus { outline: none; border-color: var(--lit); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 34px; padding: 5px 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-size: 14px; cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
.chip[aria-pressed="true"] { background: var(--lit); border-color: var(--lit); color: var(--on-lit); font-weight: 600; }
.chip.ghost { color: var(--muted); background: transparent; }
.chip.sel { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
@media (hover: hover) { .chip:not([aria-pressed="true"]):hover { border-color: var(--mesh-prov); color: var(--ink); } }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ---------- 地图 ---------- */
.map-layout { display: grid; gap: 12px; grid-template-areas: "stats" "map" "rank"; }
.stats { grid-area: stats; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.map-layout > .map-card { grid-area: map; }
.rank-card { grid-area: rank; padding: 16px; }
@media (min-width: 900px) {
  .map-layout { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "map stats" "map rank"; grid-template-rows: auto 1fr; align-items: start; gap: 16px; }
  .stats { grid-template-columns: 1fr; gap: 10px; }
  .rank-card { max-height: calc(100dvh - 330px); overflow: auto; }
}

.stat { padding: 12px 12px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.stat-num { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-num small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; letter-spacing: 0; }
.stat-label { margin-top: 3px; font-size: 12px; color: var(--muted); }
@media (min-width: 900px) {
  .stat { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px; }
  .stat-label { order: -1; margin: 0; font-size: 14px; }
}

.map-card { position: relative; overflow: hidden; }
.map-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 0 12px; }
.zoom-ctrl { display: flex; gap: 2px; }
.zoom-ctrl.floating {
  position: absolute; top: 8px; right: 8px; z-index: 2; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 90%, transparent); border: 1px solid var(--line); border-radius: 12px; padding: 2px;
}
.map-box { position: relative; width: 100%; }
.china-box { aspect-ratio: 5 / 4; max-height: 74vh; }
@media (min-width: 900px) { .china-box { aspect-ratio: 4 / 3; max-height: calc(100dvh - 170px); } }
.map-svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.prov-box .map-svg { height: 320px; }

.map-loading { position: absolute; inset: 0; display: none; place-items: center; color: var(--muted); font-size: 14px; }
body.loading .map-loading { display: grid; }

.legend {
  position: absolute; left: 12px; bottom: 10px; display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted); pointer-events: none;
}
.legend .key { display: inline-flex; align-items: center; gap: 5px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--land); }
.legend .ramp { display: inline-flex; gap: 2px; }
.legend .ramp .sw { width: 14px; height: 10px; border-radius: 2px; }
.sw.on, .sw.lv5 { background: var(--lit); }
.sw.lv1 { background: var(--lv1); } .sw.lv2 { background: var(--lv2); } .sw.lv3 { background: var(--lv3); } .sw.lv4 { background: var(--lv4); }

.map-hint, .edit-pill {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500; pointer-events: none;
  box-shadow: var(--shadow);
}
.edit-pill { background: var(--lit); color: var(--on-lit); }

/* SVG 图层 */
.units path, .provs path { fill: var(--land); cursor: pointer; transition: fill .18s; }
.units path.on { fill: var(--lit); }
.provs path.lv1 { fill: var(--lv1); } .provs path.lv2 { fill: var(--lv2); } .provs path.lv3 { fill: var(--lv3); }
.provs path.lv4 { fill: var(--lv4); } .provs path.lv5 { fill: var(--lv5); }
@media (hover: hover) {
  .units path:hover { fill: var(--land-hover); }
  .units path.on:hover { fill: var(--lit-hover); }
}
.ctx path { fill: var(--ctx); stroke: var(--surface); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: pointer; }
.mesh { fill: none; pointer-events: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.mesh-city { stroke: var(--mesh-city); stroke-width: .7; }
.mesh-prov { stroke: var(--mesh-prov); stroke-width: 1; }
.mesh-outline { stroke: var(--outline); stroke-width: 1.15; }
.prov-outline { stroke: var(--outline); stroke-width: 1.5; }
.jd { fill: var(--outline); pointer-events: none; }
.hover-outline, .sel-outline { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; pointer-events: none; }

.map-svg .provs { display: none; }
.map-svg.mode-province .provs { display: inline; }
.map-svg.mode-province .units, .map-svg.mode-province .mesh-city, .map-svg.mode-province .labels-city { display: none; }

.labels text {
  fill: var(--ink-2); font-weight: 500; text-anchor: middle; dominant-baseline: central;
  paint-order: stroke; stroke: var(--halo); stroke-linejoin: round;
  pointer-events: none; user-select: none;
}
.labels text.on { fill: var(--ink); font-weight: 700; }
.labels-ctx text { fill: var(--muted); font-weight: 400; }
.map-svg.editing .units path { cursor: copy; }

.inset { transition: opacity .2s; }
.inset.faded { opacity: 0; pointer-events: none; }
.inset-frame { fill: var(--surface); stroke: var(--outline); stroke-width: .8; }
.inset-title { fill: var(--muted); font-size: 10px; text-anchor: end; }

/* ---------- 排行 ---------- */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank a {
  display: grid; grid-template-columns: 4.6em 1fr auto; align-items: center; gap: 10px;
  padding: 7px 6px; margin: 0 -6px; border-radius: 10px; color: var(--ink); text-decoration: none;
}
@media (hover: hover) { .rank a:hover { background: var(--surface-2); } }
.rank .rname { font-weight: 600; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--lit); }
.rank .rnum { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; min-width: 3.6em; text-align: right; }
.rank .rnum small { color: var(--muted); font-weight: 500; }
.unlit { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--muted); line-height: 1.9; }
.unlit a { color: var(--muted); text-decoration: none; margin-right: 8px; white-space: nowrap; }
.unlit a:hover { color: var(--ink); }
.rank-empty { color: var(--muted); font-size: 14px; }
.rank-empty .btn { margin-top: 10px; }

/* ---------- 省份详情 ---------- */
.detail-head { display: flex; align-items: center; gap: 6px; margin: 2px 0 12px -8px; }
.detail-title { min-width: 0; flex: 1; }
.detail-title h1 { font-size: 22px; font-weight: 800; }
.detail-sub { color: var(--muted); font-size: 13px; margin-top: 1px; font-variant-numeric: tabular-nums; }
.detail-layout { display: grid; gap: 12px; }
@media (min-width: 900px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; gap: 16px; }
}
.list-card { padding: 16px; }
.list-card h3 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 18px 0 10px; }
.list-card h3:first-of-type { margin-top: 14px; }
.list-card h3 span { margin-left: 4px; font-variant-numeric: tabular-nums; }
.sel-info { display: flex; align-items: center; gap: 8px; min-height: 30px; font-size: 15px; }
.sel-info.placeholder { color: var(--muted); font-size: 14px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.tag.on { background: var(--lit-soft); color: var(--lit); }
.list-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.edit-tip { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

/* ---------- 点亮城市 ---------- */
.search-bar {
  position: sticky; top: calc(env(safe-area-inset-top) + 58px); z-index: 5;
  margin: 0 -16px; padding: 4px 16px 10px; background: var(--bg);
}
@media (min-width: 900px) { .search-bar { margin: 0; padding: 4px 0 10px; } }
.search { position: relative; display: block; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search input { padding-left: 36px; background: var(--surface); }
.region { margin-top: 18px; }
.region-title { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .1em; margin: 0 0 8px 4px; }
.region-cards { display: grid; gap: 8px; }
@media (min-width: 900px) { .region-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.pcard-head {
  display: grid; grid-template-columns: 1fr 5em 4.2em 18px; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; border: 0; background: none; cursor: pointer; text-align: left;
}
.pname { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcount { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); text-align: right; }
.pcard.has .pcount { color: var(--ink); font-weight: 700; }
.pcard-head .ico { color: var(--muted); transition: transform .2s; width: 18px; height: 18px; }
.pcard-head[aria-expanded="true"] .ico { transform: rotate(90deg); }
.pcard-body { padding: 2px 14px 14px; }
.pcard-actions { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px -8px 0; }
.pcard-actions a { margin-left: auto; color: var(--lit); }

/* ---------- 我的 ---------- */
.me-grid { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 900px) { .me-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } .me-hero { grid-column: 1 / -1; } }
.me-card, .me-hero { padding: 18px; }
.me-card p { color: var(--muted); font-size: 14px; margin: 6px 0 14px; }
.me-card .field { margin-bottom: 12px; }
.me-card ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.me-card li + li { margin-top: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.me-hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.me-summary { display: flex; gap: 28px; flex-wrap: wrap; }
.me-summary .stat-num { font-size: 30px; }

/* ---------- 分享横幅 ---------- */
.share-banner {
  position: sticky; top: calc(env(safe-area-inset-top) + 58px); z-index: 15;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  max-width: 1180px; margin: 0 auto 8px; padding: 10px 16px;
  background: var(--lit-soft); color: var(--ink); font-size: 14px;
}
@media (min-width: 900px) { .share-banner { border-radius: 14px; margin: 0 auto 12px; width: calc(100% - 56px); } }
.share-banner-text b { color: var(--lit); }
.share-banner-actions { display: flex; gap: 6px; }

/* ---------- 浮层 ---------- */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none;
  padding: 7px 10px; border-radius: 10px; max-width: 240px;
  background: var(--ink); color: var(--bg); font-size: 13px; line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.tooltip b { font-weight: 700; }
.tooltip .t-sub { opacity: .7; font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 500; white-space: nowrap; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 32px; } }

dialog.sheet {
  width: min(540px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 0; border-radius: 22px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: rgba(18, 14, 10, .5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
@media (max-width: 600px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 4px 20px; }
.sheet-head h2 { font-size: 17px; }
.sheet-body { overflow: auto; padding: 8px 20px 4px; }
.poster-preview { background: var(--surface-2); border-radius: 14px; padding: 10px; }
.poster-preview img { display: block; width: 100%; max-height: 56dvh; object-fit: contain; border-radius: 6px; aspect-ratio: 3 / 4; }
.poster-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 14px; }
.poster-form .field { flex: 1 1 200px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px calc(16px + env(safe-area-inset-bottom)); }
.sheet-actions .btn { flex: 1; }
@media (min-width: 601px) { .sheet-actions .btn { flex: none; min-width: 120px; } }

.fatal { padding: 60px 20px; text-align: center; color: var(--muted); }
.fatal .btn { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
