:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e1db;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8883;
  --grid: #e8e6e0;
  --accent: #1f7a4d;
  --ele: #2a78d6;
  --ele-fill: rgba(42, 120, 214, .14);
  --kcal: #eb6834;
  --hr: #e34948;
  --cursor: #0b0b0b;
  --g-dn3: #1c5cab; --g-dn2: #3987e5; --g-dn1: #86b6ef;
  --g-flat: #a3a19b;
  --g-up1: #f2a28f; --g-up2: #e34948; --g-up3: #a42a2a;
  --z1: #9ec5f4; --z2: #1baf7a; --z3: #eda100; --z4: #eb6834; --z5: #d03b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151514;
    --surface: #1f1f1d;
    --surface-2: #2a2a27;
    --border: #33332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8d8c84;
    --grid: #2f2f2b;
    --accent: #4cc38a;
    --ele: #3987e5;
    --ele-fill: rgba(57, 135, 229, .22);
    --kcal: #d95926;
    --hr: #e66767;
    --cursor: #ffffff;
    --g-flat: #77766f;
    --g-up1: #e8907c; --g-up3: #c43b3b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151514; --surface: #1f1f1d; --surface-2: #2a2a27; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8d8c84; --grid: #2f2f2b;
  --accent: #4cc38a; --ele: #3987e5; --ele-fill: rgba(57, 135, 229, .22);
  --kcal: #d95926; --hr: #e66767; --cursor: #ffffff; --g-flat: #77766f;
  --g-up1: #e8907c; --g-up3: #c43b3b; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--text-3); font-size: 13px; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

/* 头部 */
.hero { padding: 8px 2px 4px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.hero h1 { font-size: 24px; line-height: 1.25; margin-top: 4px; font-weight: 700; text-wrap: balance; }
.hero .sub { color: var(--text-2); font-size: 14px; margin-top: 6px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; box-shadow: var(--shadow); min-width: 0;
}
.kpi.lead { grid-column: span 2; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.kpi .k { color: var(--text-2); font-size: 12px; }
.kpi .v { font-size: 24px; font-weight: 700; line-height: 1.2; margin-top: 2px; white-space: nowrap; }
.kpi.lead .v { font-size: 34px; }
.kpi .v small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.kpi .s { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.kpi .badge { font-size: 12px; color: var(--text-2); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.kpi.empty .v { color: var(--text-3); font-size: 18px; }

/* 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card h2 { font-size: 17px; font-weight: 650; }
.card h3 { font-size: 14px; font-weight: 600; color: var(--text-2); margin: 18px 0 8px; }
.card h3:first-of-type { margin-top: 4px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font-size: 13px;
  color: var(--text-2); cursor: pointer; min-height: 30px;
}
.seg.small button { padding: 4px 10px; font-size: 12px; min-height: 28px; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

/* 地图 */
.map-card { padding-bottom: 10px; }
.map { height: 320px; border-radius: 12px; overflow: hidden; background: var(--surface-2); z-index: 0; }
.map-tools { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 8px; }
.map3d { height: 400px; background: #6f8a7c; }
.map3d .maplibregl-ctrl-attrib { font-size: 10px; }
.tools3d { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 28px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.check select { background: var(--surface-2); border: 0; border-radius: 8px; padding: 3px 6px; font-size: 13px; }
.map-msg { height: 100%; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--text-2); background: var(--surface-2); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.leaflet-container { font: inherit; }
.pin {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin.start { background: #1f7a4d; }
.pin.end { background: #0b0b0b; }
.pin.peak { background: #a42a2a; }
.photo-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 2px solid #eda100; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.cursor-dot {
  width: 18px; height: 18px; border-radius: 50%; background: var(--ele); border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(42,120,214,.25), 0 1px 4px rgba(0,0,0,.4);
}

/* 回放 */
.readout {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 8px;
  background: var(--surface-2); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px;
}
.readout div { min-width: 0; }
.readout .k { font-size: 11px; color: var(--text-3); }
.readout .v { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout .v small { font-size: 11px; color: var(--text-2); font-weight: 500; margin-left: 1px; }
.chart { width: 100%; }
.chart-ele { height: 210px; }
.chart-hr { height: 110px; }
.chart-bars { height: 150px; }
.chart-grade { height: 190px; }
.empty-chart {
  display: grid; place-items: center; text-align: center; color: var(--text-3); font-size: 13px;
  border: 1px dashed var(--border); border-radius: 12px; padding: 14px;
}
.player { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.play {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.player input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.player select {
  flex: none; background: var(--surface-2); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.hint { color: var(--text-3); font-size: 12px; margin-top: 8px; }

/* 分段 */
.segments { display: flex; flex-direction: column; gap: 8px; }
.segment {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid transparent;
  cursor: pointer; text-align: left; width: 100%;
}
.segment.on { border-color: var(--ele); }
.segment .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 700; }
.segment.up .ico { background: var(--g-up2); }
.segment.down .ico { background: var(--g-dn2); }
.segment .t1 { font-weight: 600; font-size: 14px; }
.segment .t2 { color: var(--text-2); font-size: 12px; }
.segment .dz { font-weight: 700; font-size: 16px; text-align: right; }
.segment .dz small { display: block; font-size: 11px; color: var(--text-3); font-weight: 500; }

/* 能耗 */
.energy { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.energy > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.energy .k { font-size: 12px; color: var(--text-2); }
.energy .v { font-size: 20px; font-weight: 700; }
.energy .v small { font-size: 12px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.energy .s { font-size: 11px; color: var(--text-3); }
.tag { display: inline-block; font-size: 10px; padding: 0 6px; border-radius: 999px; vertical-align: 2px; margin-left: 4px; }
.tag.main { background: var(--accent); color: #fff; }
.tag.ref { background: var(--border); color: var(--text-2); }

/* 心率区间 */
.zones { display: flex; flex-direction: column; gap: 6px; }
.zone { display: grid; grid-template-columns: 70px 1fr 64px; align-items: center; gap: 8px; font-size: 12px; }
.zone .bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.zone .bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.zone .r { text-align: right; color: var(--text-2); }

/* 照片 */
.photos {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: 0 -14px; padding: 2px 14px 6px; scrollbar-width: none;
}
.photos::-webkit-scrollbar { display: none; }
.photo {
  flex: none; width: 132px; scroll-snap-align: start; border: 0; padding: 0; background: none;
  text-align: left; cursor: pointer;
}
.photo .img {
  width: 132px; height: 164px; border-radius: 12px; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; color: var(--text-3); font-size: 12px; position: relative;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .meta { margin-top: 6px; font-size: 12px; color: var(--text-2); line-height: 1.35; }
.photo .meta b { color: var(--text); font-weight: 600; }
.photo.on .img { outline: 2px solid var(--ele); outline-offset: 2px; }

.foot { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0; text-align: center; }
.ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px;
  cursor: pointer; font-size: 14px;
}
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 8px 20px; cursor: pointer; font-size: 14px; }

/* 设置面板 */
.sheet {
  border: 0; padding: 0; width: min(560px, 100%); max-width: 100%; max-height: 90vh; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.4); }
.sheet form { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.fields label.wide { grid-column: span 2; }
.fields input, .fields select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 15px; color: var(--text); min-width: 0;
}
.model { font-size: 13px; color: var(--text-2); }
.model summary { cursor: pointer; color: var(--text); }
.model p { margin-top: 8px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; }

/* 3D：行进形象（背包小胖子） */
.hiker-wrap { position: relative; width: 44px; height: 55px; pointer-events: none; }
.hiker { display: block; width: 44px; height: 55px; overflow: visible; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.35)); }
.hiker .h-flip, .hiker .h-leg, .hiker .h-top { transform-box: view-box; }
.hiker .h-flip { transform-origin: 24px 30px; transition: transform .25s ease; }
.hiker-wrap.left .h-flip { transform: scaleX(-1); }
.hiker .h-leg-b { transform-origin: 20px 40px; }
.hiker .h-leg-f { transform-origin: 28.5px 40px; }
.hiker-wrap.walking .h-leg-f { animation: hk-leg .42s ease-in-out infinite alternate; }
.hiker-wrap.walking .h-leg-b { animation: hk-leg .42s ease-in-out infinite alternate-reverse; }
.hiker-wrap.walking .h-top { animation: hk-bob .21s ease-in-out infinite alternate; }
@keyframes hk-leg { from { transform: rotate(-24deg); } to { transform: rotate(24deg); } }
@keyframes hk-bob { from { transform: translateY(0); } to { transform: translateY(-1.8px); } }
.hiker-wrap .bubble {
  position: absolute; left: 36px; top: -10px; display: none; white-space: nowrap;
  background: #ffffff; color: #333330; font-size: 11px; line-height: 1.4; padding: 2px 7px; border-radius: 9px;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.hiker-wrap.resting .bubble { display: block; }
/* 立体小人生效时，平面小人只保留气泡 */
.hiker-wrap.has-3d .hiker { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  .hiker-wrap.walking .h-leg-f, .hiker-wrap.walking .h-leg-b, .hiker-wrap.walking .h-top { animation: none; }
}

/* 3D：关键节点 */
.node-pin {
  border: 2px solid #ffffff; border-radius: 999px; padding: 1px 7px; font-family: inherit; font-weight: 700; font-size: 11px; line-height: 1.35;
  color: #ffffff; background: #3a3a37; box-shadow: 0 1px 5px rgba(0,0,0,.45); cursor: pointer; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.node-pin:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }
.node-pin.start { background: #1f7a4d; }
.node-pin.end { background: #0b0b0b; }
.node-pin.summit { background: #a42a2a; font-size: 12px; padding: 2px 8px; }
.node-pin.high { background: #c4473f; }
.node-pin.low { background: #2a6fc4; }

/* 3D：节点弹窗跟随页面主题 */
.map3d .maplibregl-popup-content {
  background: var(--surface); color: var(--text); border-radius: 14px; padding: 12px 14px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28); font: inherit;
}
.map3d .maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.map3d .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.map3d .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--surface); }
.map3d .maplibregl-popup-anchor-top .maplibregl-popup-tip,
.map3d .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.map3d .maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--surface); }
.map3d .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface); }
.map3d .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface); }
.map3d .maplibregl-popup-close-button { color: var(--text-2); font-size: 18px; padding: 0 8px; right: 2px; top: 4px; }
.node-pop { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.np-h { display: flex; align-items: baseline; gap: 8px; padding-right: 18px; }
.np-h b { font-size: 15px; }
.np-h span { font-size: 12px; color: var(--text-3); }
.np-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; }
.np-grid div { font-size: 15px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.np-grid small { display: block; font-size: 10.5px; font-weight: 500; color: var(--text-3); }
.np-grid i, .hud i { font-style: normal; font-size: 10px; font-weight: 500; color: var(--text-2); margin-left: 1px; }
.node-pop em { font-style: normal; font-size: 9.5px; background: var(--surface-2); color: var(--text-2); border-radius: 4px; padding: 0 3px; margin-left: 3px; }
.np-seg { font-size: 11.5px; color: var(--text-2); line-height: 1.45; }
.np-seg span { display: inline-block; font-weight: 600; color: var(--text); margin-right: 4px; }
.np-note { font-size: 10.5px; color: var(--text-3); }
.np-go { align-self: flex-start; border: 0; border-radius: 999px; padding: 6px 14px; background: var(--accent); color: #ffffff; font-size: 12.5px; font-weight: 600; cursor: pointer; }

/* 3D：地图内的回放按钮和数据浮层 */
.map-ov { position: absolute; left: 10px; bottom: 10px; z-index: 2; display: flex; gap: 8px; }
.ov-play {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 8px 14px 8px 11px;
  background: var(--accent); color: #ffffff; font-size: 13px; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.35); cursor: pointer; min-height: 36px;
}
.ov-full { border: 0; border-radius: 999px; padding: 8px 12px; background: rgba(18,18,17,.68); color: #ffffff; font-size: 12px; cursor: pointer; min-height: 36px; }
.hud {
  position: absolute; left: 10px; top: 10px; z-index: 2; max-width: calc(100% - 64px);
  display: grid; grid-template-columns: repeat(3, auto); gap: 2px 14px;
  background: rgba(18,18,17,.66); color: #ffffff; border-radius: 12px; padding: 7px 11px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); pointer-events: none;
}
.hud small { display: block; font-size: 10px; color: rgba(255,255,255,.7); }
.hud b { font-size: 14px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hud i { color: rgba(255,255,255,.75); }

.node-panel {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 3; max-height: calc(100% - 16px); overflow-y: auto;
  background: var(--surface); color: var(--text); border-radius: 14px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.3);
  overscroll-behavior: contain;
}
.np-close {
  position: absolute; right: 6px; top: 6px; width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2); font-size: 18px; line-height: 1; cursor: pointer;
}

/* 视频导出模式（?video=1）：只留全屏 3D 地图和视频浮层 */
.video-mode { background: #000000; }
.video-mode .page { max-width: none; padding: 0; gap: 0; }
.video-mode .page > :not(.map-card) { display: none !important; }
.video-mode .map-card { border: 0; border-radius: 0; padding: 0; box-shadow: none; background: #000000; }
.video-mode .map-card > :not(#map3d) { display: none !important; }
.video-mode #map3d { height: 100vh; border-radius: 0; }
.video-mode .maplibregl-ctrl-top-right, .video-mode .map-ov, .video-mode .node-panel { display: none !important; }
.video-mode .hud { top: 16px; left: 16px; padding: 10px 14px; gap: 4px 18px; border-radius: 14px; }
.video-mode .hud small { font-size: 11px; }
.video-mode .hud b { font-size: 19px; }
.video-card {
  position: absolute; left: 16px; right: 16px; bottom: 64px; z-index: 3; color: #ffffff;
  background: rgba(14,14,13,.62); border-radius: 18px; padding: 18px 18px 16px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.video-card.hidden { display: none; }
.video-card.intro { bottom: auto; top: 22%; text-align: center; background: rgba(14,14,13,.5); }
.video-card.intro .vc-grid { display: none; }
.vc-title { font-size: 26px; font-weight: 800; line-height: 1.2; text-wrap: balance; }
.vc-sub { font-size: 13px; color: rgba(255,255,255,.78); margin-top: 6px; }
.vc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; margin-top: 14px; }
.vc-grid small { display: block; font-size: 11px; color: rgba(255,255,255,.7); }
.vc-grid b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vc-grid i { font-style: normal; font-size: 11px; font-weight: 500; margin-left: 2px; color: rgba(255,255,255,.75); }
.video-progress { position: absolute; left: 16px; right: 16px; bottom: 34px; z-index: 3; height: 5px; border-radius: 3px; background: rgba(255,255,255,.3); overflow: hidden; }
.video-progress i { display: block; height: 100%; width: 0; background: #ffffff; border-radius: 3px; }
