:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.82);
  --panel-border: rgba(125, 211, 252, 0.25);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --l1: #ef4444;   /* 一级 红 */
  --l2: #38bdf8;   /* 二级 蓝 */
  --l4: #34d399;   /* 四级 绿 */
  --l5: #9ca3af;   /* 五级 灰 */
  --sat: #64748b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif; }
#map { position: absolute; inset: 0; background: #0b1220; z-index: 1; }

/* 标注层（注入到地图容器内，z-index 仅高于瓦片，低于弹窗） */
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.lbl {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 13px; line-height: 1; white-space: nowrap;
  padding: 2px 6px; border-radius: 4px; pointer-events: none;
  background: rgba(2, 6, 23, 0.55); color: #fff; font-weight: 600;
  text-shadow: 0 1px 2px #000; will-change: transform;
}
.lbl.l1 { color: #fecaca; }
.lbl.l2 { color: #bae6fd; }
.lbl.l4 { color: #bbf7d0; font-size: 12px; font-weight: 500; }
.lbl.l5 { color: #e5e7eb; font-size: 11.5px; font-weight: 400; }

/* 通用面板 */
.panel {
  position: absolute; z-index: 10; color: var(--text);
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; backdrop-filter: blur(10px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.45);
}

/* 顶部栏：标题 + 搜索 */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 12;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; padding: 12px 16px; pointer-events: none;
}
.topbar .brand, .topbar .search-panel { pointer-events: auto; }
.topbar .brand { max-width: 380px; }
.topbar .brand h1 { margin: 0; font-size: 18px; letter-spacing: .5px; color: var(--text); text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.topbar .brand .sub { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-shadow: 0 1px 4px rgba(0,0,0,.6); }

/* 控制面板 */
/* 控制面板：高度不超过地图可视区（顶部留 80px、底部留 16px），内容区可滚动 */
.ctrl-panel {
  top: 80px; left: 16px; width: 268px; padding: 0; z-index: 11;
  max-height: calc(100vh - 96px);
  display: flex; flex-direction: column;
}
.ctrl-head { flex: 0 0 auto; }   /* 标题固定，不随内容滚动 */
.ctrl-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; font-size: 13px; font-weight: 700; border-bottom: 1px solid var(--panel-border);
}
.ctrl-head button {
  background: transparent; border: 1px solid var(--panel-border); color: var(--text);
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer; line-height: 1;
}
.ctrl-body { padding: 10px 14px; font-size: 13px; overflow-y: auto; flex: 1 1 auto; }
.ctrl-body.collapsed { display: none; }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.row input { accent-color: var(--accent); }
.swatch { width: 18px; height: 4px; border-radius: 2px; display: inline-block; flex: 0 0 auto; }
.swatch.l1 { background: var(--l1); height: 5px; }
.swatch.l2 { background: var(--l2); height: 3px; }
.swatch.l4 { background: var(--l4); height: 2px; }
.swatch.l5 { background: var(--l5); height: 1.5px; }
.swatch.water { background: rgba(59,130,246,0.55); border: 1px solid #60a5fa; width: 14px; height: 10px; border-radius: 2px; }
.swatch.dot { background: #cbd5e1; width: 8px; height: 8px; border-radius: 50%; }
.swatch.dot2 { background: transparent; border: 1px dashed #94a3b8; width: 14px; height: 0; }
.swatch.sat { background: var(--sat); width: 14px; height: 14px; border-radius: 3px; }
/* 底图三选一（分段控件） */
.bm-title { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.bm-seg { display: flex; gap: 6px; margin-bottom: 4px; }
.bm-opt {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 5px;
  padding: 6px 2px; font-size: 12px; cursor: pointer; color: var(--muted);
  background: rgba(2,6,23,0.35); border: 1px solid var(--panel-border); border-radius: 8px;
}
.bm-opt input { accent-color: var(--accent); margin: 0; }
.bm-opt.active { color: var(--text); border-color: var(--accent); background: rgba(8,145,178,0.16); }
.divider { height: 1px; background: var(--panel-border); margin: 10px 0; }
/* 站内导航按钮（作品介绍 / 全部地图）：与下载链接同属面板底部的链接区 */
.ctrl-nav { display: flex; gap: 8px; margin: 4px 0 8px; }
.ctrl-nav a {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center;
  padding: 6px 8px; border-radius: 8px; text-decoration: none;
  font-size: 12.5px; font-weight: 600; color: var(--text);
  background: rgba(2,6,23,0.35); border: 1px solid var(--panel-border);
  transition: color .15s, border-color .15s, background .15s;
}
.ctrl-nav a:hover {
  color: var(--accent); border-color: var(--accent); background: rgba(8,145,178,0.16);
}
.dl-link {
  display: flex; align-items: center; gap: 6px; margin: 6px 0 2px;
  font-size: 12.5px; color: var(--accent); text-decoration: none; font-weight: 600;
}
.dl-link:hover { text-decoration: underline; }
.tk-box { margin-top: 6px; }
.tk-box input {
  width: 100%; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(2,6,23,0.6); color: var(--text); font-size: 12px;
}
.hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
.legend-note { font-size: 11.5px; color: var(--muted); line-height: 1.7; }
.legend-note b { color: var(--text); }

/* 搜索（位于顶部栏右侧） */
.search-panel {
  width: 320px; max-width: 42vw; color: var(--text);
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 8px; backdrop-filter: blur(10px);
}
.search-panel input {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--panel-border);
  background: rgba(2,6,23,0.6); color: var(--text); font-size: 13px;
}
#searchResult { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; }
#searchResult li {
  padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text);
  display: flex; justify-content: space-between; align-items: center;
}
/* 河流名称为亮白，避免暗色面板下辨认困难 */
#searchResult li > span:first-child { color: #f8fafc; font-weight: 600; }
#searchResult li:hover { background: rgba(56,189,248,0.15); }
#searchResult li .tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; }
#searchResult li .tag.l1 { background: rgba(239,68,68,0.2); color: #fecaca; }
#searchResult li .tag.l2 { background: rgba(56,189,248,0.2); color: #bae6fd; }
#searchResult li .tag.l4 { background: rgba(52,211,153,0.2); color: #bbf7d0; }
#searchResult li .tag.l5 { background: rgba(156,163,175,0.22); color: #e5e7eb; }
#searchResult .empty { color: var(--muted); cursor: default; }

/* 图例色块 + 计数（位于图层与显示面板内） */
.legend-inline { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; margin: 4px 0 2px; }
.legend-inline span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend-inline i { width: 20px; height: 0; }
.cnt-box {
  font-size: 12px; color: var(--text); margin: 6px 0 2px;
  background: rgba(56,189,248,0.08); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 6px 10px;
}

/* maplibre popup 暗色化 */
.maplibregl-popup { z-index: 30 !important; }   /* 必须高于 #labels(5)，避免被河流名称遮挡 */
.maplibregl-popup-content {
  background: var(--panel) !important; color: var(--text) !important;
  border: 1px solid var(--panel-border); border-radius: 10px; font-size: 13px; padding: 12px 14px;
}
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.pop h3 { margin: 0 0 6px; font-size: 15px; }
.pop .lv { font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-left: 6px; }
.pop .lv.l1 { background: rgba(239,68,68,0.25); color: #fecaca; }
.pop .lv.l2 { background: rgba(56,189,248,0.25); color: #bae6fd; }
.pop .lv.l4 { background: rgba(52,211,153,0.25); color: #bbf7d0; }
.pop .lv.l5 { background: rgba(156,163,175,0.28); color: #e5e7eb; }
.pop .lv.lw { background: rgba(59,130,246,0.28); color: #bfdbfe; }
.pop table { border-collapse: collapse; margin-top: 4px; }
.pop td { padding: 2px 0; vertical-align: top; }
.pop td.k { color: var(--muted); padding-right: 10px; white-space: nowrap; }
.pop .note { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.6; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 10px; }
  .topbar .brand { max-width: none; }
  .topbar .brand h1 { font-size: 15px; }
  .topbar .brand .sub { font-size: 10.5px; margin-top: 3px; line-height: 1.4; }
  .topbar .search-panel { width: auto; max-width: none; }
  .topbar .search-panel input { font-size: 14px; padding: 10px 12px; }
  #searchResult { max-height: 36vh; }

  /* 控制面板 -> 底部抽屉（上拉出现） */
  .ctrl-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    border-radius: 16px 16px 0 0; max-height: 72vh; overflow-y: auto;
    transform: translateY(calc(100% - 46px)); transition: transform .3s ease;
    z-index: 20;
  }
  .ctrl-panel.open { transform: translateY(0); }
  /* 把手横条在上、标题居中（原 space-between + margin:auto 会把文字推到右侧） */
  .ctrl-head {
    cursor: pointer; user-select: none; padding: 12px 14px 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
  }
  .ctrl-head span { color: var(--text); font-size: 13px; }
  .ctrl-head::before {
    content: ""; display: block; flex: 0 0 auto; width: 40px; height: 4px; border-radius: 999px;
    background: var(--muted); opacity: .55; margin: 0 auto 9px;
  }
  #ctrlToggle { display: none; }
  .ctrl-body { font-size: 12.5px; }
  .maplibregl-ctrl-bottom-right { bottom: 52px; }
}
