:root {
  --ink: #1f2a33;
  --muted: #69747e;
  --paper: #fbf9f4;
  --card: rgba(251, 249, 244, 0.94);
  --line: #e4dfd4;
  --accent: #e8453c;
  --shadow: 0 2px 10px rgba(31, 42, 51, 0.16);
  --sheet-peek: 300px;
  --sheet-full: 78vh;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9e4d8; color: var(--ink); font: 14px/1.45 var(--font); }
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; }

/* ---------- 加载 ---------- */
#loading { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #efeae0; transition: opacity .5s; }
#loading.done { opacity: 0; pointer-events: none; }
#loading p { color: var(--muted); margin: 14px 0 0; }
.spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #d9d2c4; border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 顶栏 ---------- */
#topbar { position: fixed; z-index: 5; top: calc(8px + var(--safe-t)); left: 8px; right: 64px; display: flex; gap: 8px; align-items: stretch; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { background: var(--card); border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); min-width: 0; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.brand b { display: block; font-size: 15px; letter-spacing: .5px; }
.brand span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#legend { background: var(--card); border-radius: 12px; padding: 7px 9px 4px; box-shadow: var(--shadow); width: 150px; flex: none; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#legend .bar { height: 9px; border-radius: 5px; }
#legend .ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- 视角 chips ---------- */
#views { position: fixed; z-index: 5; top: calc(64px + var(--safe-t)); left: 8px; display: flex; gap: 6px; }
#views button, .chips button { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 16px; padding: 5px 12px; font-size: 13px; }
#views button.on, .chips button.on { background: var(--ink); color: #fff; }

/* ---------- 右侧工具 ---------- */
#tools { position: fixed; z-index: 5; right: 8px; top: calc(8px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
#tools button { width: 46px; height: 46px; border: 0; border-radius: 12px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; line-height: 1.05; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#tools button small { font-size: 9.5px; font-weight: 400; color: var(--muted); }
#tools button.on { background: var(--ink); color: #fff; }
#tools button.on small { color: #c9d1d8; }
#btn-fly.on { background: var(--accent); color: #fff; }

/* ---------- 图层弹层 ---------- */
.pop { position: fixed; z-index: 6; right: 62px; top: calc(8px + var(--safe-t)); width: 250px; background: var(--paper); border-radius: 14px; padding: 6px 14px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-height: calc(100vh - var(--sheet-peek) - 30px); overflow: auto; }
.pop h4 { margin: 10px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.pop label { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13.5px; }
.pop input { width: 17px; height: 17px; accent-color: var(--ink); }
.pop .note { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; }
.seg { display: flex; background: #ebe6db; border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 6px 0; font-size: 13px; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.sw { display: inline-block; width: 46px; height: 6px; border-radius: 3px; margin-left: auto; }
.sw.slope { background: linear-gradient(90deg, #2e9d57 0 25%, #e2c400 25% 50%, #f08a24 50% 75%, #d7301f 75%); }
.rt-swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }

/* ---------- 底部面板 ---------- */
#sheet { position: fixed; z-index: 8; left: 0; right: 0; bottom: 0; height: calc(var(--sheet-peek) + var(--safe-b)); background: var(--paper);
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.15); display: flex; flex-direction: column; transition: height .28s ease; }
#sheet.full { height: var(--sheet-full); }
#sheet .grab { height: 18px; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; flex: none; }
#sheet .grab span { width: 40px; height: 4px; border-radius: 2px; background: #cfc8ba; }
.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { border: 0; background: none; padding: 6px 10px 8px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
#sheet .body { overflow-y: auto; padding: 8px 12px calc(12px + var(--safe-b)); flex: 1; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { white-space: nowrap; box-shadow: none; border: 1px solid var(--line); background: #fff; }
.chips button .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

#route-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 8px 0 4px; }
#route-stats div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px; text-align: center; }
#route-stats b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
#route-stats span { font-size: 11px; color: var(--muted); }

#profile-wrap { position: relative; margin-top: 4px; }
#profile { width: 100%; height: 132px; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#profile .grid line { stroke: #e7e1d5; stroke-width: 1; }
#profile .grid text, #profile .axis text { fill: #8a929a; font-size: 10px; font-variant-numeric: tabular-nums; }
#profile .wp text { font-size: 10px; font-weight: 600; fill: #fff; }
#profile-tip { position: absolute; top: -2px; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 11.5px; padding: 2px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; }
.hint { font-size: 11.5px; color: var(--muted); margin: 4px 0 6px; }

#route-steps { list-style: none; padding: 0; margin: 4px 0; }
#route-steps li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
#route-steps li .n { width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 1px; }
#route-steps li b { font-size: 14px; }
#route-steps li p { margin: 2px 0 0; font-size: 12.5px; color: #4b5560; }
#route-steps li .m { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#route-steps li .seg-info { grid-column: 2 / 4; font-size: 11.5px; color: var(--muted); background: #f3efe6; border-radius: 6px; padding: 2px 6px; margin-top: 2px; }
#route-notes { font-size: 13px; color: #3c4650; }
#route-notes h5 { margin: 12px 0 4px; font-size: 13px; }
#route-notes ul { margin: 0; padding-left: 18px; }
#route-notes li { margin: 3px 0; }

#poi-filter { margin-bottom: 6px; }
#poi-list { list-style: none; padding: 0; margin: 0; }
#poi-list li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
#poi-list li .ic { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
#poi-list li b { font-size: 14px; }
#poi-list li p { margin: 2px 0 0; font-size: 12.5px; color: #4b5560; }
#poi-list li .m { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
#tab-about { font-size: 13px; color: #36414b; }
#tab-about h5 { margin: 12px 0 4px; font-size: 13.5px; color: var(--ink); }
#tab-about p, #tab-about li { margin: 4px 0; }
#tab-about ul { padding-left: 18px; margin: 4px 0; }
#tab-about a { color: #2f6fb5; }

/* ---------- 地图上的景点标记 ---------- */
.poi { display: flex; align-items: center; gap: 3px; cursor: pointer; }
.poi .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--c, #2f6fb5); color: #fff; font-size: 11.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); flex: none; }
.poi .lbl { background: rgba(255,255,255,.93); border-radius: 9px; padding: 1px 7px 2px; font-size: 12px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.22); }
.poi .lbl i { font-style: normal; color: var(--muted); margin-left: 3px; font-size: 11px; font-variant-numeric: tabular-nums; }
.poi.big .dot { width: 26px; height: 26px; font-size: 13px; }
.poi.big .lbl { font-size: 13px; font-weight: 600; }
.poi.nolabel .lbl, .poi.clash .lbl { display: none; }
.poi.left { flex-direction: row-reverse; }
.poi.small .dot { width: 16px; height: 16px; font-size: 9px; border-width: 1.5px; }
.poi.sel .dot { outline: 3px solid rgba(232, 69, 60, .45); }
.cursor-dot { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 4px solid var(--ink); box-shadow: 0 0 0 4px rgba(31,42,51,.2); }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }

.maplibregl-popup-content { border-radius: 12px; padding: 10px 12px 10px; box-shadow: 0 4px 18px rgba(0,0,0,.22); font: 13px/1.5 var(--font); color: var(--ink); max-width: 270px; }
.maplibregl-popup-close-button { font-size: 18px; width: 26px; height: 26px; }
.pp h3 { margin: 0 18px 2px 0; font-size: 15px; }
.pp .meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.pp p { margin: 4px 0; }
.pp .tip { background: #f5f0e5; border-radius: 6px; padding: 3px 6px; font-size: 12px; }
.pp .acts { display: flex; gap: 6px; margin-top: 8px; }
.pp .acts a, .pp .acts button { flex: 1; text-align: center; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 0; font-size: 12.5px; color: var(--ink); text-decoration: none; }
.pp .acts .pri { background: var(--ink); color: #fff; border-color: var(--ink); }
.pp.tap h3 { font-size: 14px; }

#toast { position: fixed; z-index: 20; left: 50%; top: calc(108px + var(--safe-t)); transform: translateX(-50%); background: rgba(31,42,51,.92); color: #fff;
  padding: 7px 14px; border-radius: 18px; font-size: 13px; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 86vw; text-align: center; }
#toast.show { opacity: 1; }

.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: calc(var(--sheet-peek) + var(--safe-b) + 2px); transition: bottom .28s; }
body.sheet-full .maplibregl-ctrl-bottom-right, body.sheet-full .maplibregl-ctrl-bottom-left { bottom: calc(var(--sheet-full) + 2px); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-scale { border-color: #6b747c; color: #333; background: rgba(255,255,255,.75); font-size: 10px; }

/* ---------- 桌面：面板放左侧 ---------- */
@media (min-width: 900px) {
  :root { --sheet-peek: 0px; }
  #sheet, #sheet.full { left: 12px; top: 12px; bottom: 12px; right: auto; width: 390px; height: auto; border-radius: 16px; }
  #sheet .grab { display: none; }
  .tabs { padding-top: 8px; }
  #topbar { left: 414px; right: 70px; }
  #views { left: 414px; }
  #profile { height: 170px; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left, body.sheet-full .maplibregl-ctrl-bottom-right { bottom: 0; }
  .maplibregl-ctrl-bottom-left { left: 404px; }
  #toast { left: calc(50% + 200px); }
  .pop { max-height: calc(100vh - 30px); }
}
@media (max-width: 380px) {
  #legend { width: 118px; }
  .brand span { font-size: 10.5px; }
}
