:root {
  --bg: #eef2f7;
  --bg-2: #f7f9fc;
  --panel: #ffffff;
  --panel-2: #f4f7fb;
  --line: #e4eaf2;
  --line-2: #d9e2ed;
  --txt: #16202c;
  --txt-2: #55677d;
  --txt-3: #8496ac;
  --red: #e0454b;
  --green: #0f9d58;
  --yellow: #d99a06;
  --off: #93a3b5;
  --accent: #2f7bff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 42, 66, .04), 0 6px 18px rgba(23, 42, 66, .07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font-family: inherit; }

/* ---------------------------------------------------------- 布局 */
.app {
  display: grid;
  grid-template-columns: 352px 1fr;
  height: 100vh;
  height: 100dvh;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  background: linear-gradient(180deg, #f8fafd, #eef2f7 60%);
  border-right: 1px solid var(--line);
}

.side::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-thumb { background: #d6e0eb; border-radius: 3px; }

.stage { position: relative; overflow: hidden; background: #eaeff5; }
#map { position: absolute; inset: 0; }
#map img { max-width: none; }

/* ---------------------------------------------------------- 品牌 */
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 2px 4px; }

.brand .logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, #2b6cf6, #17c1a3);
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(45, 120, 255, .28);
}

.brand .logo svg { width: 21px; height: 21px; }
.brand h1 { font-size: 15px; margin: 0; letter-spacing: .3px; font-weight: 650; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--txt-3); letter-spacing: .2px; }

/* ---------------------------------------------------------- 卡片 */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px 13px;
  box-shadow: var(--shadow);
}

.card-hd {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--txt-2);
  letter-spacing: .6px; margin-bottom: 10px;
  text-transform: uppercase;
}

.card-hd .tag {
  text-transform: none; letter-spacing: 0;
  font-size: 11px; color: var(--txt-3);
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: #c8d3e0; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(15, 157, 88, .13); }
.dot.warn { background: var(--yellow); box-shadow: 0 0 0 4px rgba(217, 154, 6, .14); }
.dot.err { background: var(--red); box-shadow: 0 0 0 4px rgba(224, 69, 75, .12); }

/* ---------------------------------------------------------- 表单 */
.field { margin-bottom: 9px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block; font-size: 11.5px; color: var(--txt-3);
  margin-bottom: 5px; letter-spacing: .3px;
}

.input, .select {
  width: 100%; height: 34px;
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  color: var(--txt);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.input::placeholder { color: #a8b6c6; }
.input:focus, .select:focus {
  border-color: #8fb4ee;
  box-shadow: 0 0 0 3px rgba(47, 123, 255, .12);
}

.input.mono, .mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.btn {
  height: 34px; padding: 0 13px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--txt);
  font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:hover { background: #f3f7fc; border-color: #c3d2e3; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #3d88ff, #2f6fe0);
  border-color: #2f7bff;
  color: #fff;
  box-shadow: 0 6px 14px rgba(47, 123, 255, .22);
}
.btn.primary:hover { background: linear-gradient(180deg, #4d93ff, #3576e8); }

.btn.danger {
  color: #c93a3a; border-color: #f6d5d3; background: #fff6f5;
}
.btn.danger:hover { background: #ffeceb; border-color: #f0c2c0; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* 开关 */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
  font-size: 12.5px; color: var(--txt-2);
}

.switch { position: relative; width: 40px; height: 22px; flex: 0 0 40px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch span {
  position: absolute; inset: 0;
  background: #dbe4ee; border-radius: 999px;
  transition: background .18s;
  cursor: pointer;
}

.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(20, 40, 70, .25);
  transition: transform .18s;
}

.switch input:checked + span { background: #2f7bff; }
.switch input:checked + span::after { transform: translateX(18px); }

/* tabs */
.tabs {
  display: flex; gap: 3px; padding: 3px;
  background: var(--panel-2); border-radius: 10px; margin-bottom: 11px;
  border: 1px solid var(--line);
}

.tabs button {
  flex: 1; height: 28px; border: 0; border-radius: 8px;
  background: transparent; color: var(--txt-3);
  font-size: 12.5px; cursor: pointer; transition: all .15s;
}

.tabs button.active {
  background: #fff; color: var(--txt); font-weight: 550;
  box-shadow: 0 1px 3px rgba(23, 42, 66, .1);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* 状态行 */
.kv { display: flex; flex-direction: column; gap: 7px; }

.kv .row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; gap: 10px;
}

.kv .row .k { color: var(--txt-3); }
.kv .row .v { color: var(--txt); font-variant-numeric: tabular-nums; text-align: right; }
.kv .row .v.small { font-size: 11.5px; color: var(--txt-2); max-width: 210px; }

.cfg .v.ok { color: var(--green); font-weight: 600; }
.cfg .v.no { color: var(--red); font-weight: 600; }
.tag-wait { color: var(--txt-3); font-style: normal; }

.hint {
  font-size: 11.5px; line-height: 1.65; color: var(--txt-3);
  margin: 8px 0 0;
}

.hint code {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; color: #2f6fe0; font-size: 11px;
}

.log {
  margin-top: 9px; max-height: 88px; overflow-y: auto;
  font-size: 11px; line-height: 1.7; color: var(--txt-3);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.log div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log div.err { color: #d33a3a; }
.log div.ok { color: #0d8a4e; }

details.raw summary {
  cursor: pointer; font-size: 12px; color: var(--txt-2);
  list-style: none;
}
details.raw summary::-webkit-details-marker { display: none; }
details.raw summary::before { content: "▸ "; color: var(--txt-3); }
details.raw[open] summary::before { content: "▾ "; }

details.raw pre {
  margin: 9px 0 0; max-height: 220px; overflow: auto;
  background: #f8fafd; border: 1px solid var(--line);
  border-radius: 9px; padding: 9px;
  font-size: 10.5px; line-height: 1.6; color: #47617f;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all;
}

.foot { margin-top: auto; padding: 6px 4px 2px; font-size: 10.5px; color: #a2b1c2; line-height: 1.6; }

/* ---------------------------------------------------------- 地图覆盖层 */
.map-badge {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  display: flex; gap: 14px; align-items: center;
  padding: 9px 13px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid rgba(220, 230, 242, .9);
  border-radius: 11px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 11.5px; color: var(--txt-2);
  box-shadow: 0 6px 20px rgba(23, 42, 66, .1);
}

.map-badge b { color: var(--txt); font-weight: 600; font-variant-numeric: tabular-nums; }
.map-badge .sep { width: 1px; height: 22px; background: var(--line); }

.legend {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  display: flex; gap: 12px; align-items: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid rgba(220, 230, 242, .9);
  border-radius: 11px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 11px; color: var(--txt-2);
  box-shadow: 0 6px 20px rgba(23, 42, 66, .1);
}

.legend i {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 5px; vertical-align: 1px;
}

.legend i.lg-red { background: var(--red); }
.legend i.lg-yellow { background: var(--yellow); }
.legend i.lg-green { background: var(--green); }
.legend i.lg-off { background: var(--off); }

/* ---------------------------------------------------------- HUD */
.hud {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 10; width: max-content; min-width: 420px; max-width: calc(100% - 40px);
  padding: 12px 14px 13px;
  background: rgba(255, 255, 255, .93);
  border: 1px solid rgba(214, 225, 238, .95);
  border-radius: 18px;
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  box-shadow: 0 16px 40px rgba(23, 42, 66, .16), 0 1px 0 rgba(255, 255, 255, .9) inset;
}

.hud-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 11px; padding: 0 2px;
}

.hud-head .t {
  font-size: 12px; color: var(--txt-2); letter-spacing: .8px;
  display: flex; align-items: center; gap: 8px;
}

.hud-head .t .pill {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: rgba(47, 123, 255, .1); color: #2f6fe0;
  border: 1px solid rgba(47, 123, 255, .18); letter-spacing: 0;
}

.hud-head .t .pill.mock {
  background: rgba(217, 154, 6, .1); color: #a5720a;
  border-color: rgba(217, 154, 6, .22);
}

.hud-head .d {
  font-size: 11.5px; color: var(--txt-3); font-variant-numeric: tabular-nums;
}

.hud-head .d b { color: var(--txt); font-size: 13px; font-weight: 650; }

.hud-body { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }

.dir-card {
  --c: var(--off);
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px 10px 11px;
  min-width: 178px;
  border-radius: 13px;
  background: #fff;
  border: 1px solid #e6edf6;
  box-shadow: 0 1px 3px rgba(23, 42, 66, .05);
  overflow: hidden;
  transition: border-color .25s, box-shadow .25s;
}

.dir-card::after {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px;
  width: 3px; border-radius: 3px; background: var(--c);
  opacity: .9; transition: background .25s;
}

.dir-card[data-state="red"] {
  --c: var(--red);
  border-color: #f7dcdd;
  background: linear-gradient(180deg, #fffafa, #fff);
  box-shadow: 0 2px 12px rgba(224, 69, 75, .12);
}
.dir-card[data-state="green"] {
  --c: var(--green);
  border-color: #d9eee4;
  background: linear-gradient(180deg, #f9fefb, #fff);
  box-shadow: 0 2px 12px rgba(15, 157, 88, .12);
}
.dir-card[data-state="yellow"] {
  --c: var(--yellow);
  border-color: #f6e8c6;
  background: linear-gradient(180deg, #fffdf7, #fff);
  box-shadow: 0 2px 12px rgba(217, 154, 6, .13);
}
.dir-card[data-state="off"] { --c: var(--off); background: #fafbfd; }
.dir-card[data-state="none"] { --c: #b6c3d2; border-style: dashed; background: #fbfcfe; box-shadow: none; }
.dir-card[data-state="expired"] { --c: #b08c4a; border-style: dashed; background: #fbfcfe; }

.dc-left { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 54px; flex: 0 0 54px; }

.dc-arrow {
  width: 32px; height: 32px; color: var(--c);
  filter: drop-shadow(0 1px 2px rgba(23, 42, 66, .12));
  transition: color .25s;
}

.dc-arrow svg { width: 100%; height: 100%; display: block; }
.dc-arrow path, .dc-arrow circle { fill: none; stroke: currentColor; stroke-width: 9.5; stroke-linecap: round; stroke-linejoin: round; }

.dc-name { font-size: 11.5px; color: var(--txt-2); letter-spacing: .3px; white-space: nowrap; }

.dc-state {
  font-size: 10px; color: var(--c); letter-spacing: .2px;
  white-space: nowrap; transition: color .25s;
}

.dc-right { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }

.dc-ring { position: relative; width: 62px; height: 62px; flex: 0 0 62px; }

.dc-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dc-ring .ring-bg { fill: none; stroke: #eef2f8; stroke-width: 5; }
.dc-ring .ring-fg {
  fill: none; stroke: var(--c); stroke-width: 5; stroke-linecap: round;
  transition: stroke-dashoffset .95s linear, stroke .25s;
}

.dc-num {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 700; letter-spacing: -.5px;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  transition: color .25s;
}

.dc-num.sm { font-size: 15px; letter-spacing: 0; }
.dc-unit { position: absolute; right: 8px; bottom: 7px; font-size: 9px; color: var(--txt-3); }

.dc-sub { font-size: 10.5px; color: var(--txt-3); font-variant-numeric: tabular-nums; }

.dir-card.flash .dc-arrow, .dir-card.flash .dc-num { animation: blink 1s steps(2, start) infinite; }

@keyframes blink { 50% { opacity: .28; } }

.hud-empty {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; color: var(--txt-3); font-size: 12.5px;
}

.hud-empty .spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #e3eaf3;
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hud-foot {
  display: flex; align-items: center; gap: 14px;
  margin-top: 10px; padding: 8px 2px 0;
  border-top: 1px solid #edf1f7;
  font-size: 10.5px; color: var(--txt-3);
  font-variant-numeric: tabular-nums;
}

.hud-foot b { color: var(--txt-2); font-weight: 600; }

/* ---------------------------------------------------------- 地图未配置提示 */
.map-cover {
  position: absolute; inset: 0; z-index: 8;
  display: grid; place-items: start center;
  padding: 56px 24px 24px;
  background: linear-gradient(180deg, #f7fafd, #e9eff6);
}

.map-cover.hide { display: none; }

.cover-inner {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: 0 18px 44px rgba(23, 42, 66, .1);
}

.cover-inner h2 { margin: 0 0 8px; font-size: 15.5px; font-weight: 650; }
.cover-inner p { margin: 0 0 10px; font-size: 12.5px; line-height: 1.75; color: var(--txt-2); }
.cover-inner p:last-child { margin-bottom: 0; }
.cover-inner .hint { color: var(--txt-3); }

.cover-inner code {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; color: #2f6fe0; font-size: 11.5px;
}

/* ---------------------------------------------------------- 移动端 */
/* 单列上下布局只在「窄且够高」时启用；横屏手机高度不足，继续用左右布局，避免 HUD 被裁 */
@media (max-width: 900px) and (min-height: 560px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 52vh 1fr; }
  .side { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  .stage { order: 1; }
  /* max-width 必须跟着改：桌面端的 calc(100% - 40px) 会让 HUD 比左右 10px 的定位窄 20px，
     左定位生效后余量全堆在右侧，看起来就是左边贴边、右边空一截 */
  .hud {
    min-width: 0; width: auto; max-width: calc(100% - 20px);
    left: 10px; right: 10px; bottom: 10px; transform: none;
    padding: 9px 10px 10px; border-radius: 16px;
  }

  /* 两行两列：4 个流向正好铺满，不再横向溢出 */
  .hud-body {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 7px; justify-content: normal; flex-wrap: nowrap;
    overflow: visible;
  }
  .hud-body > .hud-empty { grid-column: 1 / -1; padding: 10px 4px; font-size: 12px; }

  .dir-card { min-width: 0; padding: 6px 8px; gap: 8px; border-radius: 11px; justify-content: center; }
  .dir-card::after { top: 7px; bottom: 7px; width: 2.5px; }
  .dc-left { width: 40px; flex: 0 0 40px; gap: 0; }
  .dc-arrow { width: 24px; height: 24px; }
  .dc-name { font-size: 10px; letter-spacing: 0; line-height: 1.35; }
  .dc-ring { width: 44px; height: 44px; flex: 0 0 44px; }
  .dc-num { font-size: 17px; letter-spacing: -.3px; }
  .dc-num.sm { font-size: 12px; }
  /* 44px 小环里放不下右下角单位，小屏隐藏（读秒语义由 HUD 标题说明） */
  .dc-unit { display: none; }
  .dc-state { font-size: 9.5px; line-height: 1.3; }
  .dc-sub { font-size: 9.5px; line-height: 1.3; }
  /* 距离文字居中在圆环下方，否则整块内容重心偏左 */
  .dc-right { align-items: center; }

  .hud-head { margin-bottom: 7px; gap: 8px; }
  .hud-head .t { font-size: 11px; letter-spacing: .4px; gap: 6px; }
  .hud-head .t .pill { font-size: 9px; padding: 1px 6px; }
  .hud-head .d { font-size: 10.5px; }
  .hud-head .d b { font-size: 12px; }
  .hud-foot { margin-top: 7px; gap: 10px; font-size: 10px; }
  .legend { display: none; }
  .map-badge { display: none; }
  .map-cover { padding: 8px; background: transparent; }
  /* 小屏上把提示收成一条横幅，避免被底部 HUD 遮掉半截文字 */
  .cover-inner { padding: 9px 11px; border-radius: 12px; width: 100%; box-shadow: 0 6px 18px rgba(23, 42, 66, .1); }
  .cover-inner h2 { font-size: 12px; margin: 0; }
  .cover-inner p { font-size: 11px; line-height: 1.6; margin: 4px 0 0; }
  .cover-inner p:not(.hint) { display: none; }
}

/* 平板竖屏（640~900px）：仍是单列，但 HUD 限宽居中，避免两列卡片被拉成大片空白 */
@media (min-width: 640px) and (max-width: 900px) and (min-height: 560px) {
  .hud { left: 50%; right: auto; transform: translateX(-50%); width: min(446px, calc(100% - 20px)); }
  .dir-card { padding: 8px 12px 8px 11px; gap: 10px; }
  .dc-left { width: 44px; flex: 0 0 44px; }
  .dc-arrow { width: 27px; height: 27px; }
  .dc-ring { width: 52px; height: 52px; flex: 0 0 52px; }
  .dc-num { font-size: 20px; }
  .dc-num.sm { font-size: 13.5px; }
  .dc-name { font-size: 11px; }
  .dc-state, .dc-sub { font-size: 10px; }
  .hud-head .t { font-size: 11.5px; }
  .hud-head .d { font-size: 11px; }
  .hud-head .d b { font-size: 12.5px; }
  .hud-foot { font-size: 10.5px; }
}

/* 短屏（如 320×568）：地图区太矮，提示层只留标题一行，避免被 HUD 压住 */
@media (max-width: 900px) and (max-height: 640px) {
  .cover-inner p { display: none; }
}

/* 横屏手机：高度不够铺两行 HUD，保留左右布局并收窄侧栏，把宽度让给地图 */
@media (max-width: 900px) and (max-height: 559px) {
  .app { grid-template-columns: 286px 1fr; }
  .side { padding: 10px; gap: 8px; }
  .hud { bottom: 10px; min-width: 0; padding: 10px 12px 11px; }
  /* 同样按两列排，避免 3+1 的孤儿卡片 */
  .hud-body { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; justify-content: normal; }
  .hud-body > .hud-empty { grid-column: 1 / -1; }
  .dir-card { min-width: 0; }
  .legend { display: none; }
  .map-cover { padding: 8px; background: transparent; }
  .cover-inner { padding: 9px 12px; width: 100%; box-shadow: 0 6px 18px rgba(23, 42, 66, .1); }
  .cover-inner h2 { font-size: 12px; margin: 0; }
  .cover-inner p { display: none; }
  .map-badge { display: none; }
}
