/* ============================================================
 * 信息学地图 · Informatics Map
 * 视觉样式：深空底色 / 玻璃面板 / 学科色相
 * ============================================================ */

:root {
  --bg: #060911;
  --bg-soft: #0a0f1c;
  --panel: rgba(11, 16, 28, 0.94);
  --panel-strong: rgba(13, 19, 33, 0.97);
  --line: rgba(126, 158, 210, 0.15);
  --line-strong: rgba(126, 158, 210, 0.3);
  --text: #c6d3e8;
  --text-dim: #7a89a4;
  --text-faint: #55637d;
  --text-bright: #eef4ff;
  --accent: #5ea8ff;
  --accent-soft: rgba(94, 168, 255, 0.14);
  --ancestor: #ffb45c;
  --descendant: #4fd8e8;
  --radius: 12px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: var(--bg);
}

/* 拖拽时全屏暗角也停掉：它是一整屏的 radial-gradient 叠加层，
   画布每次被 transform 移动都要求合成器重算这一层，是拖动掉帧的隐性大户 */
/* 指针按下就提到独立合成层，保证第一个 move 之前图层已经就位 */
#stage.pan-ready { will-change: transform; }

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(120% 90% at 50% 50%, transparent 42%, rgba(3, 5, 10, 0.55) 100%);
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  z-index: 0;
  /* 手机上禁止浏览器自带的滚动/双指缩放，手势由脚本接管 */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#stage.dragging { cursor: grabbing; }
#stage.pointing { cursor: pointer; }

/* 选中脉冲环：用 DOM + CSS 动画，避免为了一个脉冲每帧重绘整张图 */
#focus-ring {
  position: fixed;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.6px solid rgba(150, 195, 255, 0.62);
  box-shadow: 0 0 12px rgba(120, 180, 255, 0.35);
  pointer-events: none;
  z-index: 1;
  will-change: transform, opacity;
  animation: focusPulse 2.2s cubic-bezier(0.33, 0, 0.55, 1) infinite;
}
#focus-ring.hidden { display: none; }

@keyframes focusPulse {
  0% { transform: scale(0.86); opacity: 0.62; }
  68% { transform: scale(2.15); opacity: 0; }
  100% { transform: scale(2.15); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #focus-ring { animation: none; opacity: 0.7; }
}

.edge-fade {
  position: fixed;
  left: 0;
  right: 0;
  height: 92px;
  pointer-events: none;
  z-index: 2;
}
.edge-fade.top {
  top: 0;
  background: linear-gradient(to bottom, rgba(6, 9, 17, 0.92), transparent);
}
.edge-fade.bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(6, 9, 17, 0.9), transparent);
}

/* ---------------- 品牌区 ---------------- */
.brand {
  position: fixed;
  top: 24px;
  left: 28px;
  display: flex;
  align-items: center;
  gap: 13px;
  z-index: 10;
  pointer-events: none;
}

.brand-badge {
  width: 40px;
  height: 40px;
  position: relative;
  flex: 0 0 auto;
}
.brand-badge i {
  position: absolute;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(94, 168, 255, 0.8);
}
.brand-badge i:nth-child(1) { width: 7px;  height: 7px;  left: 3px;  top: 17px; opacity: 0.55; }
.brand-badge i:nth-child(2) { width: 9px;  height: 9px;  left: 13px; top: 8px;  opacity: 0.78; }
.brand-badge i:nth-child(3) { width: 9px;  height: 9px;  left: 13px; top: 26px; opacity: 0.78; }
.brand-badge i:nth-child(4) { width: 7px;  height: 7px;  left: 27px; top: 17px; opacity: 0.95; background: #7ee7c7; box-shadow: 0 0 14px rgba(126, 231, 199, 0.85); }
.brand-badge::before,
.brand-badge::after {
  content: "";
  position: absolute;
  left: 6px;
  width: 24px;
  height: 1px;
  background: linear-gradient(90deg, rgba(94,168,255,0.15), rgba(94,168,255,0.75));
  transform-origin: left center;
}
.brand-badge::before { top: 20px; transform: rotate(-30deg); }
.brand-badge::after  { top: 22px; transform: rotate(30deg); }

.brand-copy h1 {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 3px;
  line-height: 1.1;
  color: var(--text-bright);
  text-shadow: 0 0 26px rgba(94, 168, 255, 0.4);
}
.brand-copy p {
  margin-top: 5px;
  font-size: 9px;
  letter-spacing: 3.4px;
  color: var(--text-faint);
  font-weight: 500;
}

.brand-note {
  position: fixed;
  top: 78px;
  left: 81px;
  z-index: 10;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  pointer-events: none;
}
.brand-note em {
  font-style: normal;
  color: var(--text-faint);
  margin-left: 8px;
  letter-spacing: 0.1px;
}

/* ---------------- 工具栏 ---------------- */
.toolbar {
  position: fixed;
  top: 22px;
  right: 26px;
  display: flex;
  align-items: center;
  gap: 9px;
  z-index: 20;
}

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.lang {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow);
}
.lang button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.5px;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.16s, background 0.16s;
}
.lang button:hover { color: var(--text); }
.lang button.active {
  color: #06101f;
  background: linear-gradient(180deg, #8fc4ff, #5ea8ff);
  box-shadow: 0 2px 12px rgba(94, 168, 255, 0.45);
  font-weight: 600;
}

.levels {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow);
}
.levels button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.5px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.16s, background 0.16s;
}
.levels button:hover { color: var(--text); }
.levels button.active {
  color: #04160f;
  background: linear-gradient(180deg, #a9ecc8, #46cf98);
  box-shadow: 0 2px 12px rgba(70, 207, 152, 0.4);
  font-weight: 600;
}

.tool {
  width: 37px;
  height: 37px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text-dim);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color 0.16s, border-color 0.16s, transform 0.16s;
}
.tool:hover { color: var(--text-bright); border-color: var(--line-strong); }
.tool:active { transform: scale(0.94); }
.tool svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- 搜索 ---------------- */
#searchbox {
  position: fixed;
  top: 70px;
  right: 26px;
  width: 372px;
  z-index: 30;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: drop 0.18s ease-out;
}
@keyframes drop {
  from { opacity: 0; transform: translateY(-7px); }
  to   { opacity: 1; transform: translateY(0); }
}
#search-input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-bright);
  font: inherit;
  font-size: 13.5px;
  padding: 13px 15px;
  letter-spacing: 0.2px;
}
#search-input::placeholder { color: var(--text-faint); }
#search-results {
  max-height: 388px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding: 5px;
}
.sr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.sr-item:hover, .sr-item.active { background: var(--accent-soft); }
.sr-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto;
}
.sr-main { min-width: 0; flex: 1; }
.sr-zh {
  font-size: 13px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sr-en {
  font-size: 10.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.sr-topic {
  font-size: 10px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.sr-empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}
.sr-hint {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent);
  opacity: 0.85;
}

/* ---------------- 图例 ---------------- */
#legend {
  position: fixed;
  left: 26px;
  bottom: 84px;
  width: 272px;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  z-index: 15;
  background: rgba(9, 13, 23, 0.97);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: max-height 0.24s ease, opacity 0.2s, background 0.24s;
}
#legend:hover,
#legend:focus-within {
  background: rgba(9, 13, 23, 0.97);
}
#legend.collapsed { max-height: 42px; }

.legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 9px;
  flex: 0 0 auto;
}
.legend-title {
  font-size: 10.5px;
  letter-spacing: 1.6px;
  color: var(--text-faint);
  text-transform: uppercase;
}
#legend-collapse {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  border-radius: 5px;
}
#legend-collapse:hover { background: rgba(255, 255, 255, 0.07); color: var(--text-bright); }

#legend-list {
  overflow-y: auto;
  padding: 0 8px 10px;
  flex: 1 1 auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 158, 210, 0.28) transparent;
}
#legend-list::-webkit-scrollbar { width: 6px; }
#legend-list::-webkit-scrollbar-thumb { background: rgba(126, 158, 210, 0.24); border-radius: 3px; }

.lg-group { margin-top: 8px; }
.lg-group:first-child { margin-top: 2px; }
.lg-group-title {
  font-size: 9.5px;
  letter-spacing: 1.3px;
  color: var(--text-faint);
  padding: 3px 7px 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lg-group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.lg-topic {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.14s;
  line-height: 1.25;
}
.lg-topic:hover { background: rgba(255, 255, 255, 0.055); }
.lg-topic.active {
  background: rgba(94, 168, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(94, 168, 255, 0.32);
}
.lg-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.lg-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lg-en {
  font-size: 9.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
  flex: 0 0 auto;
  margin-left: auto;
}
.lg-topic.active .lg-name { color: var(--text-bright); }

/* ---------------- 详情面板 ---------------- */
#detail {
  position: fixed;
  top: 74px;
  right: 26px;
  width: 336px;
  max-height: calc(100vh - 268px);
  overflow-y: auto;
  z-index: 16;
  padding: 17px 18px 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  box-shadow: var(--shadow);
  animation: drop 0.2s ease-out;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 158, 210, 0.3) transparent;
}
#detail::-webkit-scrollbar { width: 6px; }
#detail::-webkit-scrollbar-thumb { background: rgba(126, 158, 210, 0.26); border-radius: 3px; }

.dt-topic {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 9px;
}
.dt-topic .lg-dot { width: 6px; height: 6px; }

.dt-zh {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
  line-height: 1.35;
  letter-spacing: 0.3px;
}
.dt-en {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.4;
  letter-spacing: 0.2px;
}

.dt-modes {
  display: inline-flex;
  margin-top: 10px;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 14, 26, 0.86);
}
.dt-modes button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 11.5px;
  padding: 4px 13px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.16s, background 0.16s;
}
.dt-modes button:hover { color: var(--text); }
.dt-modes button.on {
  color: #06101f;
  background: linear-gradient(180deg, #8fc4ff, #5ea8ff);
  font-weight: 600;
}
.dt-body .dt-note {
  margin-top: 9px;
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
}

.dt-body {
  margin-top: 12px;
  font-size: 12.5px;
  line-height: 1.68;
  color: #a8b8d2;
}
.dt-body p + p { margin-top: 7px; }
.dt-body .en {
  margin-top: 9px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-faint);
  border-top: 1px dashed var(--line);
  padding-top: 9px;
}

.dt-actions {
  display: flex;
  gap: 7px;
  margin-top: 14px;
}
.dt-btn {
  flex: 1;
  padding: 7px 10px;
  font: inherit;
  font-size: 11.5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dt-btn:hover { background: rgba(94, 168, 255, 0.14); color: var(--text-bright); }

.dt-sec { margin-top: 16px; }
.dt-sec-title {
  font-size: 10px;
  letter-spacing: 1.2px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.dt-sec-title .count {
  color: var(--text-dim);
  letter-spacing: 0;
  font-size: 10px;
}
.dt-rel {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 11.5px;
  color: #9fb0cc;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dt-rel:hover { background: rgba(255, 255, 255, 0.055); color: var(--text-bright); }
.dt-rel .lg-dot { width: 5px; height: 5px; }
.dt-none { font-size: 11.5px; color: var(--text-faint); padding: 3px 6px; }

/* ---------------- 小地图 ---------------- */
#minimap-wrap {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 15;
  padding: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: crosshair;
  line-height: 0;
}
#minimap { display: block; border-radius: 7px; }

/* ---------------- 状态栏 ---------------- */
#status {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  background: rgba(10, 15, 26, 0.88);
  border: 1px solid var(--line);
  border-radius: 30px;
  white-space: nowrap;
}
#status .sep { color: var(--text-faint); opacity: 0.6; }
#status b { color: #9fb6d8; font-weight: 600; }

/* ---------------- 悬停提示 ---------------- */
#tooltip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  max-width: 306px;
  padding: 10px 13px 11px;
  background: rgba(12, 18, 31, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.14s, transform 0.14s;
}
#tooltip.show { opacity: 1; transform: translateY(0); }
.tt-zh {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  line-height: 1.35;
}
.tt-en {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 2px;
  line-height: 1.35;
}
.tt-meta {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--text-faint);
  display: flex;
  gap: 10px;
}
.tt-meta b { color: #8fa6c8; font-weight: 500; }

/* ---------------- 帮助 ---------------- */
#help {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 12, 0.7);
}
.help-card {
  width: 470px;
  max-width: calc(100vw - 40px);
  padding: 26px 28px 22px;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  animation: drop 0.2s ease-out;
}
.help-card h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.help-card p {
  font-size: 12.5px;
  line-height: 1.75;
  color: #9db0cb;
}
.help-card ul {
  margin: 14px 0 4px;
  padding-left: 2px;
  list-style: none;
}
.help-card li {
  font-size: 12.5px;
  line-height: 1.95;
  color: #9db0cb;
}
.help-card li b { color: var(--text-bright); font-weight: 600; }
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
  color: var(--text-bright);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  text-align: center;
}
.help-foot {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
#help-close {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  font: inherit;
  font-size: 12.5px;
  color: #06101f;
  background: linear-gradient(180deg, #8fc4ff, #5ea8ff);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 1px;
}
#help-close:hover { filter: brightness(1.08); }

/* ---------------- 加载 ---------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--bg);
  transition: opacity 0.5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.loading-ring {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(94, 168, 255, 0.16);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p {
  font-size: 11.5px;
  letter-spacing: 2px;
  color: var(--text-faint);
}

/* ---------------- 工具类 ---------------- */
.hidden { display: none !important; }

@media (max-width: 860px) {
  #legend { width: 216px; bottom: 74px; max-height: 38vh; }
  .lg-en { display: none; }
  #detail { width: 280px; max-height: calc(100vh - 250px); }
  #searchbox { width: 300px; }
  .brand-note { display: none; }
  #minimap-wrap { display: none; }
  #status { font-size: 10px; padding: 6px 11px; }
}


/* ================= 手机端适配 =================
   窄屏把面板改成「底部抽屉」：详情占满宽度从底部升起，
   图例收成一条，工具栏分两行，全部让位给地图本体。 */
@media (max-width: 720px) {
  .brand { top: 10px; left: 12px; gap: 9px; }
  .brand-badge { width: 28px; height: 28px; transform: scale(0.7); transform-origin: left center; }
  .brand-copy h1 { font-size: 15px; letter-spacing: 2px; }
  .brand-copy p { margin-top: 3px; font-size: 7px; letter-spacing: 2px; }
  .brand-note { display: none; }

  /* 第一行：语言 + 工具；第二行：级别（整行居中，避免孤零零挂在一边） */
  .toolbar {
    top: 8px; left: 10px; right: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 5px;
    row-gap: 6px;
  }
  .levels { order: 3; flex: 0 0 100%; justify-content: center; margin-top: 2px; }
  .lang button { padding: 6px 8px; font-size: 11.5px; }
  .levels button { padding: 6px 9px; font-size: 11px; }
  .tool { width: 32px; height: 32px; border-radius: 9px; }

  #searchbox { left: 10px; right: 10px; width: auto; top: 84px; }
  /* iOS 上字号小于 16px 时聚焦输入框会把页面放大 */
  #search-input, #search-input::placeholder { font-size: 16px; }

  #legend {
    left: 10px; right: 10px; width: auto;
    bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    max-height: 44vh;
    border-radius: 14px;
  }
  #legend.collapsed { max-height: 40px; }
  .lg-en { display: none; }
  .lg-topic { padding: 7px 8px; }

  /* 详情面板：底部抽屉 */
  #detail {
    top: auto; left: 0; right: 0; width: auto;
    bottom: 0;
    max-height: 62vh;
    border-radius: 18px 18px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    animation: sheet-up 0.22s ease-out;
  }
  #detail::before {
    content: "";
    position: sticky;
    top: 0;
    display: block;
    width: 38px;
    height: 4px;
    margin: -6px auto 10px;
    border-radius: 3px;
    background: rgba(150, 180, 220, 0.32);
  }

  #minimap-wrap { display: none; }

  #status {
    left: 10px; right: 10px;
    bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    transform: none;
    justify-content: center;
    font-size: 9.5px;
    padding: 5px 10px;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #help .help-card { width: calc(100vw - 30px); max-height: 78vh; overflow-y: auto; padding: 20px 18px; }
  #help .help-card h2 { font-size: 17px; }

  /* 触屏没有 hover，悬浮提示一律不弹 */
  #tooltip { display: none !important; }
}

@keyframes sheet-up {
  from { transform: translateY(22px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* 横屏 / 矮视口：高度是瓶颈。
   注意不能只按宽度判断——横屏手机宽度往往 >720px，会掉进桌面样式，
   而 100vh 只有 390px，右侧面板和图例立刻打架。所以这里只看高度和朝向。 */
@media (max-height: 520px) and (orientation: landscape) {
  .brand { display: none; }
  .toolbar { top: 8px; right: 10px; gap: 6px; flex-wrap: nowrap; }
  .levels { order: 0; flex: 0 0 auto; margin-top: 0; }
  .lang button { padding: 5px 9px; font-size: 11.5px; }
  .levels button { padding: 5px 9px; font-size: 11.5px; }
  .tool { width: 30px; height: 30px; }
  #searchbox { top: 50px; right: 10px; left: auto; width: min(340px, 48vw); }
  #legend {
    left: 10px; right: auto; width: 190px;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    max-height: 46vh; font-size: 11px;
  }
  #legend .lg-en { display: none; }
  #legend .lg-topic { padding: 5px 7px; }
  #minimap-wrap { display: none; }
  #detail {
    top: 50px; right: 10px; width: min(360px, 46vw);
    max-height: calc(100vh - 88px);
  }
  #status {
    left: 10px; right: 10px; transform: none; bottom: 6px;
    font-size: 9.5px; padding: 4px 10px;
    justify-content: center; overflow: hidden;
  }
  #help .help-card { max-height: 88vh; overflow-y: auto; padding: 18px; }
}

/* 平板：宽度够但点按仍然用手指，收一点面板尺寸、放宽按钮点击区 */
@media (min-width: 721px) and (max-width: 1100px) {
  .brand h1 { font-size: 20px; }
  .brand-note { font-size: 11px; }
  .tool { width: 38px; height: 38px; }
  .lang button, .levels button { padding: 8px 12px; font-size: 13px; }
  #legend { width: 250px; max-height: 42vh; font-size: 12px; }
  #legend .lg-topic { padding: 6px 8px; }
  #detail { width: 330px; }
  #searchbox { width: 380px; }
}

/* 任何触屏设备：没有真实 hover，去掉悬停位移与高亮，避免点按后“粘住” */
@media (hover: none) {
  .tool:hover, .lang button:hover, .levels button:hover,
  .lg-topic:hover, #legend:hover { transform: none; }
  .lg-topic:hover { background: transparent; }
}

/* 触屏点按反馈：只对可点的东西给一点按压感 */
@media (hover: none) {
  .tool:active, .lang button:active, .levels button:active { transform: scale(0.94); }
  .lg-topic:active { background: rgba(110,150,220,.18); }
}

/* 详情面板右上角关闭（移动端底部抽屉尤其需要） */
#detail .dt-close {
  position: absolute;
  top: 9px; right: 9px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: #9fb0c8;
  font-size: 17px; line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
#detail .dt-close:hover { background: rgba(255, 255, 255, .13); color: #e6eefc; }
@media (max-width: 720px) {
  #detail .dt-close { top: 14px; right: 12px; width: 32px; height: 32px; font-size: 19px; }
}

/* 全屏按钮激活态 */
#btn-full.active {
  color: #06101f;
  background: linear-gradient(180deg, #8fc4ff, #5ea8ff);
  border-color: transparent;
}
#btn-full.active svg { stroke: #06101f; }

/* 触屏备用缩放按钮：只在触摸设备出现，桌面端用滚轮即可 */
#zoom-pad {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  flex-direction: column;
  gap: 9px;
  z-index: 21;
}
@media (hover: none) and (pointer: coarse) {
  #zoom-pad { display: flex; }
}
#zoom-pad button {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--panel-strong);
  color: var(--text-bright);
  font-size: 22px; line-height: 1;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .12s;
}
#zoom-pad button:active {
  transform: scale(.92);
  background: rgba(94, 168, 255, .28);
}
/* 横屏时按钮略小一点，位置保持右侧居中 */
@media (max-height: 520px) and (orientation: landscape) {
  #zoom-pad { gap: 7px; }
  #zoom-pad button { width: 40px; height: 40px; font-size: 20px; }
}
