/* ============================================================
   位置回传 · 浅灰主题 + 动效系统
   动效只用 transform / opacity / path 绘制，避免布局抖动
   ============================================================ */

:root {
  /* 色板：浅灰底 + 白卡 + 单一琥珀强调色 */
  --bg: #f3f4f6;
  --bg-2: #eceef1;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f0f2f5;
  --line: rgba(16, 18, 22, 0.08);
  --line-2: rgba(16, 18, 22, 0.14);
  --fg: #14171c;
  --fg-2: #5a6068;
  --fg-3: #8a9099;
  --fg-4: #b6bbc2;
  --accent: #e8890c;
  --accent-ink: #8a4d00;
  --accent-soft: rgba(232, 137, 12, 0.1);
  --ok: #12a150;
  --bad: #d93a45;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --rail: 356px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas,
    monospace;

  /* 动效令牌：小 120 / 中 180 / 大 260 */
  --d-fast: 120ms;
  --d-base: 180ms;
  --d-slow: 260ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --shadow-1: 0 1px 2px rgba(16, 18, 22, 0.05);
  --shadow-2: 0 1px 2px rgba(16, 18, 22, 0.05), 0 6px 18px rgba(16, 18, 22, 0.06);
  --shadow-3: 0 2px 4px rgba(16, 18, 22, 0.06), 0 14px 32px rgba(16, 18, 22, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
code { font-family: var(--mono); font-size: 12px; }
a { color: var(--accent-ink); }

/* 图标：统一线性描边（Lucide 风格） */
svg.ic {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: rgba(16, 18, 22, 0.14);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(16, 18, 22, 0.24); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================ 入场编排 */

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px) scale(0.995); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in {
  0% { opacity: 0; transform: translateY(18px) scale(0.98); }
  70% { opacity: 1; }
  100% { opacity: 1; transform: none; }
}
@keyframes ping {
  0% { transform: scale(0.7); opacity: 0.7; }
  70% { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}
@keyframes shimmer {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(220%); }
}
@keyframes edge-run {
  0% { offset-distance: 0%; opacity: 0; }
  12% { opacity: 1; }
  88% { opacity: 1; }
  100% { offset-distance: 100%; opacity: 0; }
}
@keyframes spin { to { transform: rotate(1turn); } }

/* 首次进入：左栏逐块抬起（只跑一次） */
.rail > .brand { animation: rise-in var(--d-slow) var(--ease-out) both; }
.rail > .latest { animation: rise-in var(--d-slow) var(--ease-out) 40ms both; }
.rail > .actions { animation: rise-in var(--d-slow) var(--ease-out) 80ms both; }
.rail > .stats { animation: rise-in var(--d-slow) var(--ease-out) 120ms both; }
.rail > .history { animation: rise-in var(--d-slow) var(--ease-out) 160ms both; }
.rail > .rail-foot { animation: fade-in var(--d-slow) var(--ease-out) 220ms both; }
.stage-bar { animation: fade-in var(--d-slow) var(--ease-out) 180ms both; }

/* 入场：容器依次抬起（stagger 0.05s） */
.stagger > * {
  animation: rise-in var(--d-slow) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 50ms);
}

/* ============================================================ 骨架屏 */
.skeleton { position: relative; overflow: hidden; border-radius: var(--r-sm); }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  animation: shimmer 1.15s var(--ease-out) infinite;
}
.sk-line {
  height: 10px;
  border-radius: 5px;
  background: var(--surface-3);
}
.sk-line.lg { height: 22px; }
.sk-line.sm { height: 8px; }

/* ============================================================ 布局 */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
}
.rail > :not(.history) { flex: 0 0 auto; }
.sheet-grab { display: none; }

.stage { position: relative; min-width: 0; background: var(--bg-2); }

#map { position: absolute; inset: 0; background-color: var(--bg-2); }

/* ============================================================ 品牌区 */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 0;
}
.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  color: var(--accent);
  background: var(--accent-soft);
  transition: transform var(--d-base) var(--ease-spring);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.06); }

.brand-txt { flex: 1; min-width: 0; }
.brand-txt h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11px;
  color: var(--fg-3);
  white-space: nowrap;
  transition: color var(--d-base), border-color var(--d-base), background var(--d-base);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-4);
  transition: background var(--d-base), box-shadow var(--d-base);
}
.status[data-state="live"] { color: var(--ok); border-color: rgba(18, 161, 80, 0.28); background: rgba(18, 161, 80, 0.07); }
.status[data-state="live"] .status-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 161, 80, 0.16); animation: ping 2.2s var(--ease-out) infinite; }
.status[data-state="wait"] { color: var(--accent-ink); border-color: rgba(232, 137, 12, 0.3); background: var(--accent-soft); }
.status[data-state="wait"] .status-dot { background: var(--accent); }
.status[data-state="off"] { color: var(--bad); border-color: rgba(217, 58, 69, 0.26); background: rgba(217, 58, 69, 0.06); }
.status[data-state="off"] .status-dot { background: var(--bad); }

/* ============================================================ 卡片 */

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--d-base) var(--ease-out), transform var(--d-base) var(--ease-out);
}

.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--fg-3);
}
.sec-tail {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}

/* 最新位置卡：3D 倾斜 + 聚光 */
.latest {
  transform-style: preserve-3d;
  will-change: transform;
}
.latest::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 0%), rgba(232, 137, 12, 0.12), transparent 60%);
  opacity: 0;
  transition: opacity var(--d-slow) var(--ease-out);
  pointer-events: none;
}
.latest:hover::before { opacity: 1; }
.latest:hover { box-shadow: var(--shadow-2); }

.coord {
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 1px 0 8px;
  transition: color var(--d-fast) var(--ease-out), letter-spacing var(--d-base) var(--ease-out);
}

.coord.is-changing { color: var(--accent); }

.meta { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 11px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
  transition: transform var(--d-base) var(--ease-spring), border-color var(--d-base);
}
.tag:hover { transform: translateY(-1px); border-color: var(--line-2); }
.tag svg { width: 12px; height: 12px; opacity: 0.55; }
.tag b { color: var(--fg); font-weight: 600; font-family: var(--mono); }
.tag.warn { color: var(--accent-ink); border-color: rgba(232, 137, 12, 0.32); background: var(--accent-soft); }
.tag.warn b { color: var(--accent-ink); }

.pulse-line {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--fg-2);
}
.pulse-line::before {
  content: "";
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pulse-line.muted { color: var(--fg-3); }
.pulse-line.muted::before { background: var(--fg-4); box-shadow: none; }

/* ============================================================ 按钮 */

.actions { display: flex; gap: 8px; }

.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--fg-2);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  transition: background var(--d-fast) var(--ease-out), color var(--d-fast),
    border-color var(--d-fast), box-shadow var(--d-base) var(--ease-out),
    width var(--d-slow) var(--ease-spring), padding var(--d-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.ic { display: block; width: 15px; height: 15px; flex: none; }
.btn .ic { flex: none; }
.btn svg { width: 15px; height: 15px; flex: 0 0 15px; transition: transform var(--d-base) var(--ease-spring); }
.btn:hover { background: var(--surface-2); border-color: var(--line-2); color: var(--fg); box-shadow: var(--shadow-2); }
.btn:focus-visible { outline: 2px solid rgba(232, 137, 12, 0.5); outline-offset: 2px; }

/* 按下：压回 + 回弹，用 JS 触发 WAAPI 过冲 */
.btn.is-pressed { animation: none; }

.btn.primary {
  background: var(--fg);
  border-color: var(--fg);
  color: #fff;
  box-shadow: 0 1px 2px rgba(16, 18, 22, 0.18), 0 6px 16px rgba(16, 18, 22, 0.12);
}
.btn.primary:hover { background: #23272e; border-color: #23272e; color: #fff; }
.btn.primary svg { color: var(--accent); }

.btn.quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--fg-3); }
.btn.quiet:hover { background: rgba(217, 58, 69, 0.07); color: var(--bad); border-color: transparent; }

.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

/* 图标按钮（只有图标，配 aria-label） */
.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--fg-2);
  box-shadow: var(--shadow-1);
  transition: background var(--d-fast), color var(--d-fast), border-color var(--d-fast);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

/* 水波：从指针坐标扩散 */
.ripple {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: currentColor;
  opacity: 0.22;
  transform: scale(0);
}

/* 复制按钮：成功后收缩成圆 + 画对勾 */
.btn.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.done svg { color: #fff; }
.check {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  animation: draw-check 420ms var(--ease-out) forwards;
}
@keyframes draw-check { to { stroke-dashoffset: 0; } }

/* ============================================================ 统计 */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--line);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  transition: background var(--d-base);
}
.stat:hover { background: var(--surface-2); }
.stat-k { font-size: 10.5px; color: var(--fg-3); }
.stat-v {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-v .unit { font-size: 10.5px; font-weight: 400; color: var(--fg-3); margin-left: 2px; }

/* ============================================================ 历史列表 */

.history {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 160px;
  flex: 1 1 auto;
  overflow: hidden;
}
.history .sec-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 14px 8px;
  margin: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.hist-list { overflow-y: auto; padding: 4px 6px 8px; min-height: 0; }
.hist-empty { padding: 22px 8px; text-align: center; font-size: 12px; color: var(--fg-4); }

.hist-day {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 6px;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--fg-4);
}
.hist-day::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.hist-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto 22px 22px;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), transform var(--d-base) var(--ease-spring);
  animation: rise-in var(--d-slow) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
.hist-row:focus-visible { outline: 2px solid rgba(232, 137, 12, 0.45); outline-offset: -2px; }
.hist-row:hover { background: var(--surface-3); transform: translateX(2px); }
.hist-row[data-active="1"] { background: var(--accent-soft); }
.hist-row[data-active="1"] .hist-t { color: var(--accent-ink); }

.row-nav,
.row-del {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-4);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--d-fast), color var(--d-fast), background var(--d-fast);
}
.row-nav .ic,
.row-del .ic { width: 13px; height: 13px; }
.hist-row:hover .row-nav,
.hist-row:hover .row-del,
.hist-row[data-active="1"] .row-nav,
.hist-row[data-active="1"] .row-del,
.row-nav:focus-visible,
.row-del:focus-visible { opacity: 1; }
.row-nav:hover { color: var(--accent); background: var(--accent-soft); }
.row-del:hover { color: var(--bad); background: rgba(217, 58, 69, 0.09); }

/* 地图气泡里的导航入口 */
.pop-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11.5px;
  text-decoration: none;
  transition: background var(--d-fast);
}
.pop-nav:hover { background: rgba(232, 137, 12, 0.2); }

.hist-t { font-family: var(--mono); font-size: 11.5px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.hist-c {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-a { font-family: var(--mono); font-size: 10.5px; color: var(--fg-4); font-variant-numeric: tabular-nums; }
.hist-a.bad { color: var(--bad); }

/* ============================================================ 页脚 */

.rail-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 2px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-4);
}
.rail-foot .spacer { flex: 1; }

.linkbtn {
  border: 0;
  background: none;
  padding: 0 2px;
  font: inherit;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-3);
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  transition: color var(--d-fast);
}
.linkbtn:hover { color: var(--bad); }

.modetag {
  padding: 1px 6px;
  border-radius: var(--r-xs);
  border: 1px solid rgba(232, 137, 12, 0.3);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 10px;
  white-space: nowrap;
}

/* ============================================================ 地图上层 */

.stage-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  color: var(--fg-2);
  font-size: 11.5px;
  box-shadow: var(--shadow-1);
  transition: color var(--d-fast), border-color var(--d-fast), background var(--d-base),
    transform var(--d-base) var(--ease-spring);
}
.chip svg { width: 13px; height: 13px; }
.chip:hover { color: var(--fg); transform: translateY(-1px); box-shadow: var(--shadow-2); }
.chip[data-on="1"] { color: var(--accent-ink); border-color: rgba(232, 137, 12, 0.34); background: var(--accent-soft); }

/* 弹性开关（跟随） */
.switch {
  position: relative;
  width: 26px;
  height: 15px;
  border-radius: 999px;
  background: var(--fg-4);
  transition: background var(--d-base) var(--ease-out);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--d-slow) var(--ease-spring), width var(--d-fast) var(--ease-out);
}
.chip[data-on="1"] .switch { background: var(--accent); }
.chip[data-on="1"] .switch::after { transform: translateX(11px); }
.chip:active .switch::after { width: 16px; }

.chip.ghost { color: var(--fg-4); border-style: dashed; background: rgba(255, 255, 255, 0.8); }

/* ============================================================ 空状态 */

.stage-empty {
  position: absolute;
  inset: 0;
  z-index: 450;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.empty-card {
  pointer-events: auto;
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-3);
  text-align: center;
  animation: sheet-in var(--d-slow) var(--ease-out) both;
}
.empty-ring {
  position: relative;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(232, 137, 12, 0.32);
  color: var(--accent);
}
.empty-ring svg { width: 20px; height: 20px; }
.empty-ring::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(232, 137, 12, 0.45);
  animation: ping 2.6s var(--ease-out) infinite;
}
.empty-card h2 { margin: 0 0 6px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.empty-card p { margin: 0 0 16px; font-size: 12.5px; color: var(--fg-3); line-height: 1.6; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.empty-url {
  margin-top: 14px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-3);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-3);
  text-align: left;
  word-break: break-all;
  line-height: 1.5;
}

/* ============================================================ Leaflet 适配 */

.leaflet-container { background: var(--bg-2) !important; font-family: var(--font) !important; outline: none; }
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.82) !important;
  color: var(--fg-4) !important;
  font-size: 9.5px !important;
  padding: 1px 6px !important;
  border-radius: 0 var(--r-xs) 0 0;
  backdrop-filter: blur(6px);
}
.leaflet-control-attribution a { color: var(--fg-3) !important; }
.leaflet-bar, .leaflet-bar a {
  border-radius: var(--r-sm) !important;
  background: rgba(255, 255, 255, 0.96) !important;
  color: var(--fg-2) !important;
  border-color: var(--line-2) !important;
  box-shadow: var(--shadow-1);
}
.leaflet-bar a { border-bottom-color: var(--line) !important; }
.leaflet-bar a:hover { background: var(--surface-3) !important; color: var(--fg) !important; }

.beacon { position: relative; display: block; width: 16px; height: 16px; }
.beacon i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(16, 18, 22, 0.3), 0 0 0 1px rgba(232, 137, 12, 0.35);
}
.beacon::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 1px solid rgba(232, 137, 12, 0.55);
  animation: ping 2.4s var(--ease-out) infinite;
}

.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--fg) !important;
  border: 1px solid var(--line-2) !important;
  border-radius: var(--r-md) !important;
  box-shadow: var(--shadow-3) !important;
}
.leaflet-popup-content { margin: 10px 12px !important; font-size: 12px !important; line-height: 1.5 !important; }
.leaflet-popup-tip { background: var(--surface) !important; box-shadow: none !important; }
.leaflet-popup-close-button { color: var(--fg-3) !important; }
.pop-t { font-family: var(--mono); font-size: 11px; color: var(--fg-3); }
.pop-c { font-family: var(--mono); font-size: 12px; color: var(--fg); margin-top: 2px; }

body[data-tiles="amap-sat"] .leaflet-tile { filter: saturate(0.9); }

/* ============================================================ 弹窗 */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 23, 28, 0.28);
  backdrop-filter: blur(6px);
  animation: fade-in var(--d-base) var(--ease-out);
}
.modal {
  width: min(660px, 100%);
  max-height: min(86dvh, 820px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  transform-origin: var(--origin, 50% 0%);
  animation: sheet-in var(--d-slow) var(--ease-out) both;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.modal-head p { margin: 2px 0 0; font-size: 12px; color: var(--fg-3); }

.modal-body { flex: 1 1 auto; min-height: 0; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-body > * { flex: 0 0 auto; }

.note {
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid rgba(232, 137, 12, 0.22);
  background: var(--accent-soft);
  font-size: 12px;
  color: var(--accent-ink);
  line-height: 1.6;
}
.note strong { font-weight: 600; }

.step { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; }
.step-n span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-2);
}
.step-b h3 { margin: 0 0 5px; font-size: 12.5px; font-weight: 600; }
.step-b p { margin: 0 0 7px; font-size: 12px; color: var(--fg-2); line-height: 1.6; }
.step-b b { color: var(--fg); font-weight: 600; }

.mini-list { margin: 0 0 7px; padding-left: 17px; font-size: 12px; color: var(--fg-2); line-height: 1.65; }
.mini-list li { margin-bottom: 2px; }
.mini-list code { color: var(--accent-ink); background: var(--accent-soft); padding: 1px 4px; border-radius: 4px; }
/* 步骤内部不再重复编号，避免和步骤序号打架 */
.step-b ol.mini-list { list-style: none; padding-left: 0; }
.step-b ol.mini-list > li { position: relative; padding-left: 14px; }
.step-b ol.mini-list > li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--fg-4);
}

.copyline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 5px 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  transition: border-color var(--d-base);
}
.copyline:hover { border-color: var(--line-2); }
.copyline code { flex: 1; min-width: 0; color: var(--fg-2); font-size: 11px; line-height: 1.5; word-break: break-all; }

.fine { font-size: 11.5px !important; color: var(--fg-3) !important; }
.selftest { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.selftest-out { font-size: 11.5px; color: var(--fg-4); font-family: var(--mono); }
.selftest-out.ok { color: var(--ok); }
.selftest-out.bad { color: var(--bad); }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--line);
  overflow: hidden;
}
.kv-grid > div { display: flex; flex-direction: column; gap: 2px; padding: 9px 12px; background: var(--surface); }
.kv-grid span { font-size: 10.5px; color: var(--fg-4); }
.kv-grid b { font-size: 11.5px; font-weight: 500; color: var(--fg-2); word-break: break-all; }
.kv-grid b.mono { font-family: var(--mono); }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* ============================================================ 登录 */

.gate {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  animation: fade-in var(--d-base) var(--ease-out);
}
.gate-card {
  width: min(330px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  animation: rise-in var(--d-slow) var(--ease-out) both;
}
.gate-mark { width: 40px; height: 40px; margin: 0 auto 2px; color: var(--accent); }
.gate-mark svg { width: 100%; height: 100%; }
.gate-brand { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-4); }
.gate-card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.gate-card p { margin: 0 0 6px; font-size: 12px; color: var(--fg-3); line-height: 1.65; }

.input {
  height: 38px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color var(--d-base), box-shadow var(--d-base);
}
.input:focus { border-color: rgba(232, 137, 12, 0.55); box-shadow: 0 0 0 3px var(--accent-soft); }
.gate-err { min-height: 16px; font-size: 11.5px; color: var(--bad); }
.gate-foot {
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 11px;
  line-height: 1.7;
  color: var(--fg-3);
  text-align: left;
}
.gate-foot code { font-family: var(--mono); font-size: 10px; color: var(--fg-2); overflow-wrap: anywhere; }

/* ============================================================ Toast */

.toast {
  position: fixed;
  width: max-content;
  max-width: calc(100vw - 32px);
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--fg);
  color: #fff;
  font-size: 12.5px;
  box-shadow: var(--shadow-3);
  opacity: 0;
  transform: translate(-50%, 14px) scale(0.96);
  pointer-events: none;
  transition: opacity var(--d-base) var(--ease-out), transform var(--d-slow) var(--ease-spring);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast svg { width: 14px; height: 14px; color: var(--accent); }
.toast-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

/* ============================================================ 响应式 */

/* ============================================================ 跨端适配
   三档：宽屏桌面 / 窄桌面与平板 / 手机
   外加横屏手机、触屏设备、刘海安全区
   ============================================================ */

@media (max-width: 1180px) {
  :root { --rail: 320px; }
  .coord { font-size: 19px; }
  .hist-row { grid-template-columns: 54px minmax(0, 1fr) auto; }
}

/* —— 平板与手机：地图铺满，详情收进底部面板 —— */
@media (max-width: 1000px) {
  .app { display: block; height: 100vh; height: 100dvh; }
  .stage { position: fixed; inset: 0; order: 0; }
  #map { position: absolute; inset: 0; }

  .rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 480;
    height: 72dvh;
    max-height: 72dvh;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 12px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    background: var(--surface);
    box-shadow: 0 -10px 34px rgba(16, 18, 22, 0.14);
    transform: translateY(calc(100% - var(--peek, 232px)));
    transition: transform 300ms var(--ease-spring);
    will-change: transform;
  }
  body.sheet-open .rail { transform: translateY(0); }

  .sheet-grab {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    margin: 0 -12px;
    background: linear-gradient(var(--surface) 60%, rgba(255, 255, 255, 0));
    cursor: pointer;
    border-radius: 16px 16px 0 0;
  }
  .grab-bar {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--line-2);
    transition: width var(--d-base) var(--ease-spring), background var(--d-base);
  }
  .grab-chevron {
    width: 12px;
    height: 12px;
    color: var(--fg-4);
    transition: transform 300ms var(--ease-spring);
  }
  body.sheet-open .grab-chevron { transform: rotate(180deg); }
  body.sheet-open .grab-bar { width: 44px; background: var(--fg-4); }

  .brand { padding-top: 2px; }
  .history { flex: 1 1 auto; min-height: 120px; }
  .hist-list { max-height: none; }
  .rail-foot { padding-bottom: 2px; }

  .stage-empty { padding-bottom: calc(var(--peek, 224px) + 12px); align-items: center; }
  .stage-bar { top: 10px; left: 10px; right: 10px; max-width: none; }
  /* 地图控件让开底部面板 */
  .leaflet-bottom { bottom: calc(var(--peek, 232px) + 6px); transition: bottom 300ms var(--ease-spring); }
  body.sheet-open .leaflet-bottom { bottom: 8px; }
  .stage-empty { padding-bottom: calc(var(--peek, 232px) + 16px); }

  .modal-backdrop { padding: 0; align-items: end; }
  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    transform-origin: 50% 100%;
    animation: sheet-up var(--d-slow) var(--ease-out) both;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .kv-grid { grid-template-columns: minmax(0, 1fr); }
  .toast { bottom: calc(var(--peek, 224px) + 16px); }
}

/* —— 手机：加大可点区域，压缩次要信息 —— */
@media (max-width: 560px) {
  .rail { gap: 10px; padding: 0 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .brand-mark { width: 28px; height: 28px; flex-basis: 28px; }
  .coord { font-size: 18px; padding-bottom: 6px; }
  .tag { height: 24px; }
  .btn { height: 40px; font-size: 13px; }
  .btn.small { height: 32px; }
  .icon-btn { width: 40px; height: 40px; flex-basis: 40px; }
  .chip { height: 34px; padding: 0 12px; }
  .hist-row { min-height: 40px; padding: 8px; }
  .stat { padding: 9px 10px; }
  .stat-v { font-size: 16px; }
  .card { padding: 12px; }
  .empty-card { padding: 18px; }
  .modal-head { padding: 14px 14px 10px; }
  .modal-body { padding: 14px; gap: 14px; }
  .modal-foot { padding: 10px 14px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* —— 超窄屏：只在开关上留图标 —— */
@media (max-width: 380px) {
  #chipFollow .chip-t { display: none; }
  #chipFollow { padding: 0 10px; }
}

/* —— 横屏手机：回到左右分栏，避免上下都被压扁 —— */
@media (max-height: 560px) and (orientation: landscape) {
  /* 横屏手机：底部面板取消，回到左右分栏 */
  .app {
    display: grid;
    grid-template-columns: minmax(260px, 34vw) minmax(0, 1fr);
    grid-template-rows: 100dvh;
  }
  .stage { position: relative; order: 0; }
  .rail {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    height: auto;
    max-height: none;
    transform: none;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    padding: 10px;
    gap: 10px;
  }
  .sheet-grab { display: none; }
  .history { flex: 1 1 auto; min-height: 0; }
  .hist-list { max-height: none; }
  .stage-bar { flex-wrap: nowrap; right: auto; }
  .stage-empty { padding-bottom: 24px; }
  .toast { bottom: 20px; }
  .modal { max-height: 96dvh; }
}

/* —— 触屏：放大可点区域（≥40px），去掉只对鼠标有意义的悬停/倾斜 —— */
@media (hover: none), (pointer: coarse) {
  .btn { height: 40px; }
  .btn.small { height: 34px; }
  .icon-btn { width: 40px; height: 40px; flex-basis: 40px; }
  .chip { height: 34px; padding: 0 12px; }
  .hist-row { min-height: 40px; padding: 8px; grid-template-columns: 58px minmax(0, 1fr) auto 30px 30px; }
  .row-nav,
  .row-del { opacity: 0.7; width: 30px; height: 30px; }
  .coord { cursor: default; }
  .latest:hover { box-shadow: var(--shadow-1); }
  .latest::before { display: none; }
  .chip:hover, .tag:hover, .hist-row:hover { transform: none; }
  .chip:active { transform: scale(0.97); }
  .btn:active { transform: scale(0.97); }
  .icon-btn:active { transform: scale(0.94); }
}

/* —— 只有鼠标才给悬停反馈 —— */
@media (hover: hover) and (pointer: fine) {
  .coord:hover { color: var(--accent); letter-spacing: 0.01em; }
}

/* —— 超宽屏：左栏不跟着无限拉伸 —— */
@media (min-width: 1500px) {
  :root { --rail: 380px; }
  .coord { font-size: 22px; }
}

@keyframes sheet-up {
  0% { opacity: 0.6; transform: translateY(26px); }
  78% { opacity: 1; transform: translateY(-3px); }
  100% { opacity: 1; transform: none; }
}

/* 尊重系统减少动效 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}