/* 跨域投資供應鏈地圖 — 研究終端風格（淺色預設，可切深色／跟隨系統）
   深色配色經 dataviz 驗證：六領域 dark categorical（最差相鄰 CVD ΔE 35.8）、
   態勢色沿用 status palette，強調文字變體對所在底色均達標。 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  color-scheme: light;
  --page: #f6f5f1;
  --surface: #fdfcf9;
  --raised: #efede6;
  --ink: #201f1b;
  --ink-2: #4c4a43;
  --ink-3: #75726a;
  --hairline: #e4e2da;
  --hairline-2: #d2cfc5;
  --ring: rgba(0, 0, 0, 0.08);
  --edge: #b3b0a4;
  --accent: #3987e5;      /* 由 JS 依領域與外觀模式切換 */
  --accent-ink: #1e5cad;  /* 領域強調文字變體（對所在底色 ≥4.5:1） */
  --warn: #fab219;
  --warn-text: #7a5a10;
  --warn-text-b: #5f450a;
  --tint-ink: #16150f;    /* 態勢／標籤文字變體的混色端點 */
  --hl-in: #2668bd;
  --hl-out: #c8541f;
  --shadow-pop: 0 12px 36px rgba(32, 31, 27, .18);
  --shadow-drawer: -12px 0 36px rgba(32, 31, 27, .16);
  --shadow-sheet: 0 -14px 44px rgba(32, 31, 27, .2);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", monospace;
}
:root[data-mode="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --raised: #232322;
  --ink: #f2f1ed;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --hairline: #2c2c2a;
  --hairline-2: #3a3a37;
  --ring: rgba(255, 255, 255, 0.09);
  --edge: #47473f;
  --accent-ink: #86b6ef;  /* 領域亮色文字變體（深色面 ≥7:1） */
  --warn-text: #e8c672;
  --warn-text-b: #f3d795;
  --tint-ink: #fff;
  --hl-in: #5598e7;
  --hl-out: #ec835a;
  --shadow-pop: 0 16px 48px rgba(0, 0, 0, .55);
  --shadow-drawer: -16px 0 48px rgba(0, 0, 0, .5);
  --shadow-sheet: 0 -18px 56px rgba(0, 0, 0, .6);
}
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
* { scrollbar-width: thin; scrollbar-color: var(--hairline-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hairline-2); border-radius: 5px; border: 2px solid var(--page); }
::-webkit-scrollbar-track { background: transparent; }

/* ── 頂欄：品牌列＋搜尋、獨立分頁列 ───────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  position: sticky; top: 0; z-index: 50;
}
.topbar-row {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 24px; filter: saturate(.9); }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .03em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 外觀模式切換（淺色／深色／跟隨系統），位於搜尋框左側 */
.mode-switch {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--page); border: 1px solid var(--hairline-2);
  border-radius: 7px; padding: 2px;
}
.mode-switch button {
  border: 0; background: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: inherit; font-size: 11.5px; color: var(--ink-3);
  padding: 3px 9px; border-radius: 5px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.mode-switch button:hover { color: var(--ink); }
.mode-switch button.active {
  background: var(--raised); color: var(--ink); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--hairline-2);
}

.search-wrap { position: relative; flex: 0 1 340px; min-width: 0; }
#search {
  width: 100%; padding: 7px 12px; border-radius: 6px;
  border: 1px solid var(--hairline-2); background: var(--page);
  font-size: 13px; font-family: inherit; color: var(--ink);
}
#search::placeholder { color: var(--ink-3); }
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0;
  min-width: min(360px, calc(100vw - 24px));
  background: var(--raised); border: 1px solid var(--hairline-2);
  border-radius: 8px; box-shadow: var(--shadow-pop);
  max-height: 60vh; overflow: auto; z-index: 90;
}
.sr-group {
  padding: 9px 12px 3px; font-size: 10.5px; color: var(--ink-3);
  letter-spacing: .1em; text-transform: uppercase; font-family: var(--mono);
}
.sr-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--ink); text-align: left;
}
.sr-item:hover, .sr-item.focus { background: var(--surface); }
.sr-item .sr-tag {
  font-size: 10.5px; padding: 1px 6px; border-radius: 4px; white-space: nowrap; font-weight: 600;
  background: color-mix(in srgb, var(--c, var(--ink-3)) 22%, var(--surface));
  color: color-mix(in srgb, var(--c, var(--ink-3)) 60%, var(--tint-ink));
}
.sr-item .sr-sub { color: var(--ink-3); font-size: 11.5px; margin-left: auto; white-space: nowrap; font-family: var(--mono); }

/* 分頁列：底線式分頁，窄螢幕可橫向滑動 */
.tabs {
  display: flex; gap: 2px; padding: 0 12px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 9px 13px 8px; font-size: 13px; color: var(--ink-3); font-family: inherit;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--tab-c, var(--accent)); opacity: .5; transition: opacity .15s; }
.tab:hover { color: var(--ink); }
.tab:hover .dot { opacity: .85; }
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--tab-c); }
.tab.active .dot { opacity: 1; }

/* ── 副欄（領域說明＋圖例＋子分類）─────────── */
.subbar {
  padding: 9px 18px 10px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--accent) 6%, var(--page));
}
.subbar-line { font-size: 13px; color: var(--ink-2); max-width: 1200px; }
.subbar-meta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 5px; }
.stats { font-size: 12px; color: var(--ink-3); }
.stats b { color: var(--accent-ink); font-weight: 700; font-family: var(--mono); }
.legend { display: inline-flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--ink-2); }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .lg i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.legend .lg.unlisted i { background: none; border: 1.5px dashed var(--ink-3); }
/* 競爭態勢圖例：可點擊切換態勢篩選（亮顯地圖上對應卡片） */
.legend .lg-btn {
  border: 1px solid var(--hairline-2); background: var(--raised); cursor: pointer;
  font-family: inherit; font-size: 11.5px; color: var(--ink-2);
  padding: 2px 8px; border-radius: 5px; margin: -3px 0;
  transition: border-color .15s, background .15s, color .15s;
}
.legend .lg-btn:hover { border-color: var(--lg-c); color: var(--ink); }
.legend .lg-btn.active {
  background: color-mix(in srgb, var(--lg-c) 20%, var(--surface));
  border-color: var(--lg-c);
  color: color-mix(in srgb, var(--lg-c) 65%, var(--tint-ink));
  font-weight: 600;
}

.theme-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 9px; padding-top: 9px;
  border-top: 1px solid color-mix(in srgb, var(--accent) 22%, var(--hairline));
}
.theme-label {
  font-size: 10.5px; color: var(--ink-3); letter-spacing: .1em;
  font-family: var(--mono); white-space: nowrap; margin-right: 4px;
}
.theme-chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  font-size: 12px; color: var(--ink-2); font-family: inherit;
  background: var(--raised); border: 1px solid var(--hairline-2);
  padding: 4px 10px; border-radius: 5px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.theme-chip::before { content: "#"; color: var(--ink-3); font-family: var(--mono); font-size: 11px; }
.theme-chip small { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); }
.theme-chip:hover { border-color: var(--accent); color: var(--ink); }
.theme-chip.active {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface));
  border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.theme-chip.active::before, .theme-chip.active small { color: var(--accent-ink); opacity: .75; }

/* ── 主版面 ─────────────────────────────── */
.layout { display: flex; flex: 1; min-height: 0; }
.map-area { flex: 1; overflow: auto; min-width: 0; overscroll-behavior: contain; }
.map-content { position: relative; padding: 18px 18px 60px; counter-reset: band; }
#edge-svg { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
#edge-svg path.edge { fill: none; stroke: var(--edge); stroke-width: 1.4; opacity: .6; pointer-events: visibleStroke; transition: opacity .15s, stroke .15s; }
#edge-svg path.edge:hover { stroke: var(--ink-2); opacity: 1; }
#edge-svg path.edge.hl-in { stroke: var(--hl-in); stroke-width: 2.4; opacity: .95; }
#edge-svg path.edge.hl-out { stroke: var(--hl-out); stroke-width: 2.4; opacity: .95; }
#edge-svg path.edge.dim { opacity: .07; }

.band { position: relative; z-index: 1; margin-bottom: 28px; counter-increment: band; }
.band-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.band-header::after { content: ""; flex: 1; border-top: 1px solid var(--hairline); align-self: center; }
.band-title { font-size: 13px; font-weight: 700; color: var(--accent-ink); letter-spacing: .06em; }
.band-title::before {
  content: counter(band, decimal-leading-zero);
  font-family: var(--mono); font-size: 11px; font-weight: 400;
  color: var(--ink-3); margin-right: 8px; letter-spacing: 0;
}
.band-count { font-size: 11px; color: var(--ink-3); font-family: var(--mono); }
.band-desc { font-size: 11.5px; color: var(--ink-3); }
.band-grid { display: flex; flex-wrap: wrap; gap: 10px; }

/* 環節卡片 */
.node-card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-left: 3px solid var(--status-c, var(--ink-3));
  border-radius: 8px;
  padding: 10px 12px 9px;
  width: 232px; flex: 0 1 232px;
  cursor: pointer; position: relative; z-index: 1;
  transition: border-color .15s, background .15s, opacity .2s, outline-color .15s;
  outline: 2px solid transparent;
}
.node-card:hover { background: var(--raised); border-color: var(--hairline-2); border-left-color: var(--status-c, var(--ink-3)); }
.node-card.selected { outline-color: var(--accent); background: var(--raised); }
.node-card.dim { opacity: .22; }
.node-card.status-hit { outline-color: var(--status-c); }
.nc-head { display: flex; align-items: flex-start; gap: 8px; }
.nc-name { font-weight: 700; font-size: 13.5px; line-height: 1.35; flex: 1; }
.nc-status {
  font-size: 10.5px; white-space: nowrap; font-weight: 600;
  padding: 1px 7px; border-radius: 4px;
  background: color-mix(in srgb, var(--status-c) 18%, var(--surface));
  color: color-mix(in srgb, var(--status-c) 60%, var(--tint-ink));
  border: 1px solid color-mix(in srgb, var(--status-c) 40%, transparent);
}
.nc-en { font-size: 11px; color: var(--ink-3); margin: 1px 0 7px; }
.nc-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--ink-2);
  background: var(--raised); border: 1px solid var(--hairline-2);
  padding: 1px 7px; border-radius: 4px; cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }
.chip.unlisted { border-style: dashed; }
.chip.more { color: var(--ink-3); cursor: default; background: none; border-color: transparent; }
.nc-metric { margin-top: 8px; font-size: 11px; color: var(--accent-ink); font-weight: 600; }
.nc-cross { position: absolute; right: 9px; bottom: 8px; font-size: 10px; color: var(--ink-3); font-family: var(--mono); }

/* ── 子分類供應鏈視圖 ───────────────────── */
.theme-map-head {
  position: relative; z-index: 1;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, var(--hairline));
}
.theme-map-head b { font-size: 16px; color: var(--ink); }
.tm-tag {
  font-size: 10.5px; font-weight: 600; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  color: var(--accent-ink);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.tm-en { font-size: 12px; color: var(--ink-3); font-family: var(--mono); }
.tm-exit {
  margin-left: auto; font-size: 12px; color: var(--ink-2); font-family: inherit;
  background: var(--raised); border: 1px solid var(--hairline-2);
  padding: 3px 10px; border-radius: 5px; cursor: pointer;
}
.tm-exit:hover { border-color: var(--accent); color: var(--accent-ink); }
.stage-flow {
  position: relative; z-index: 1;
  margin: -18px 0 10px; padding-left: 16px;
  font-size: 14px; color: var(--accent-ink); opacity: .6;
}
.node-card.ctx { opacity: .55; border-style: dashed; border-left-style: solid; }
.node-card.ctx:hover { opacity: 1; }
.nc-sec {
  display: inline-block; font-size: 10px;
  padding: 0 5px; border-radius: 4px; margin-right: 5px; vertical-align: 1.5px;
  font-weight: 700;
  background: color-mix(in srgb, var(--sec-c, var(--ink-3)) 22%, var(--surface));
  color: color-mix(in srgb, var(--sec-c, var(--ink-3)) 60%, var(--tint-ink));
  border: 1px solid color-mix(in srgb, var(--sec-c, var(--ink-3)) 40%, transparent);
}
.nc-theme-count { margin-top: 5px; font-size: 10.5px; color: var(--accent-ink); font-weight: 600; }
.nc-theme-count.ctx { color: var(--ink-3); font-weight: 400; }

/* ── 詳細面板 ───────────────────────────── */
.panel {
  width: 432px; flex: 0 0 432px;
  border-left: 1px solid var(--hairline);
  background: var(--surface);
  overflow-y: auto; padding: 18px 18px 40px;
  overscroll-behavior: contain;
  display: none;
}
.panel.open { display: block; }
.panel h2 { font-size: 17px; line-height: 1.35; margin: 8px 0 2px; }
.panel .p-en { color: var(--ink-3); font-size: 12px; margin-bottom: 10px; font-family: var(--mono); }
.p-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.p-status {
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 4px;
  background: color-mix(in srgb, var(--status-c, var(--ink-3)) 18%, var(--surface));
  color: color-mix(in srgb, var(--status-c, var(--ink-3)) 60%, var(--tint-ink));
  border: 1px solid color-mix(in srgb, var(--status-c, var(--ink-3)) 40%, transparent);
}
.p-band-tag {
  font-size: 11px; color: var(--accent-ink); border-radius: 4px; padding: 2px 9px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.p-close { margin-left: auto; border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--ink-3); padding: 2px 6px; }
.p-close:hover { color: var(--ink); }
.p-desc { color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }
.p-sec {
  margin: 18px 0 7px; font-size: 11px; font-weight: 700; color: var(--ink-3);
  letter-spacing: .09em; border-bottom: 1px solid var(--hairline); padding-bottom: 5px;
}
.p-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.p-metric { background: var(--raised); border: 1px solid var(--hairline-2); border-radius: 6px; padding: 8px 10px; }
.p-metric .k { font-size: 10.5px; color: var(--ink-3); }
.p-metric .v { font-size: 12px; font-weight: 600; margin-top: 2px; line-height: 1.4; font-variant-numeric: tabular-nums; }
.p-analysis {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  padding: 10px 12px; border-radius: 0 6px 6px 0; font-size: 13px; color: var(--ink-2);
}
.p-bottleneck {
  background: color-mix(in srgb, var(--warn) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 6px; padding: 9px 12px; font-size: 12.5px; color: var(--warn-text);
}
.p-bottleneck b { color: var(--warn-text-b); }
table.p-companies { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.p-companies th { text-align: left; font-size: 11px; color: var(--ink-3); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--hairline-2); }
.p-companies td { padding: 6px; border-bottom: 1px solid var(--hairline); vertical-align: top; color: var(--ink-2); }
.p-companies tr.rowbtn { cursor: pointer; }
.p-companies tr.rowbtn:hover td { background: var(--raised); }
.p-companies .cn { font-weight: 600; white-space: nowrap; color: var(--ink); }
.p-companies .tk { font-size: 11px; color: var(--accent-ink); white-space: nowrap; font-family: var(--mono); }
.p-companies .unlisted-tag { font-size: 10px; color: var(--ink-3); border: 1px dashed var(--ink-3); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-lg {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; background: var(--raised); border: 1px solid var(--hairline-2);
  border-radius: 5px; padding: 3px 10px; cursor: pointer; font-family: inherit; color: var(--ink);
  transition: border-color .15s, color .15s;
}
.chip-lg:hover { border-color: var(--accent); color: var(--accent-ink); }
.chip-lg .sec-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.chip-lg.status-chip:hover { border-color: var(--st-c); color: var(--ink); }
.chip-lg.status-chip.active {
  border-color: var(--st-c);
  background: color-mix(in srgb, var(--st-c) 18%, var(--surface));
  color: color-mix(in srgb, var(--st-c) 65%, var(--tint-ink));
  font-weight: 600;
}
.chip-lg.status-chip.active small { color: inherit; opacity: .8; }
.chip-lg.unlisted { border-style: dashed; }
.chip-lg small { color: var(--ink-3); font-family: var(--mono); }
.p-links a { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 6px; color: var(--accent-ink); text-decoration: none; font-size: 12.5px; }
.p-links a:hover { background: var(--raised); }
.p-links .dom { margin-left: auto; color: var(--ink-3); font-size: 11px; font-family: var(--mono); }
.news-item { padding: 7px 8px; border-radius: 6px; display: block; text-decoration: none; }
.news-item:hover { background: var(--raised); }
.news-item .nt { font-size: 12.5px; color: var(--ink); line-height: 1.45; }
.news-item .nm { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.p-note { font-size: 11px; color: var(--ink-3); margin-top: 6px; }
.p-note code, .p-desc code { font-family: var(--mono); font-size: 10.5px; background: var(--raised); border: 1px solid var(--hairline-2); border-radius: 4px; padding: 0 4px; }
.p-back { border: 0; background: none; color: var(--accent-ink); cursor: pointer; font-size: 12.5px; padding: 0; font-family: inherit; }
.p-back:hover { text-decoration: underline; }
.p-hl { padding-left: 18px; }
.p-hl li { margin: 6px 0; color: var(--ink-2); font-size: 13px; }
.p-count-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }

/* 行動版面板遮罩（桌機不顯示） */
#backdrop {
  display: none; position: fixed; inset: 0; z-index: 95;
  background: rgba(0, 0, 0, .55);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#backdrop.show { opacity: 1; pointer-events: auto; }

/* ── 頁尾 ─────────────────────────────── */
.footer {
  border-top: 1px solid var(--hairline); background: var(--surface);
  padding: 10px 18px; font-size: 11px; color: var(--ink-3);
}
.footer code { font-family: var(--mono); }
.footer b { color: var(--ink-2); }

/* ── 資料更新提示（快取過期彈窗）───────── */
#update-toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 24px)); transform: translateX(-50%);
  z-index: 300; display: flex; align-items: center; gap: 12px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 14px; border-radius: 10px;
  background: var(--raised); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  box-shadow: var(--shadow-pop);
  animation: ut-in .25s ease;
}
@keyframes ut-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
#update-toast .ut-icon { font-size: 20px; }
#update-toast .ut-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#update-toast .ut-text b { font-size: 13.5px; }
#update-toast .ut-text span { font-size: 12px; color: var(--ink-2); }
#update-toast .ut-reload {
  flex-shrink: 0; padding: 7px 14px; border: none; border-radius: 6px;
  background: var(--accent-ink); color: var(--page); font-family: inherit; font-size: 13px;
  font-weight: 700; cursor: pointer;
}
#update-toast .ut-reload:hover { filter: brightness(1.1); }
#update-toast .ut-close {
  flex-shrink: 0; border: none; background: none; color: var(--ink-3);
  font-size: 14px; cursor: pointer; padding: 4px; line-height: 1;
}
#update-toast .ut-close:hover { color: var(--ink); }

/* ── 平板：面板改為右側抽屜 ─────────────── */
@media (max-width: 1100px) {
  #backdrop { display: block; }
  .panel {
    position: fixed; right: 0; top: 0; bottom: 0; z-index: 100;
    width: min(432px, 92vw);
    border-left: 1px solid var(--hairline-2);
    box-shadow: var(--shadow-drawer);
    transform: translateX(105%); transition: transform .22s ease;
    display: block;
  }
  .panel.open { transform: none; }
}

/* ── 手機：緊湊頂欄、橫向滑動列、卡片滿版、底部面板 ── */
@media (max-width: 760px) {
  .topbar-row { padding: 8px 12px 6px; gap: 10px; }
  .brand { gap: 8px; flex-shrink: 0; }
  .brand-mark { font-size: 20px; }
  .brand-title { font-size: 13.5px; }
  .brand-sub { display: none; }
  .mode-switch .ms-label { display: none; }
  .mode-switch button { padding: 4px 8px; }
  .search-wrap { flex: 1 1 auto; }
  #search { padding: 8px 12px; font-size: 16px; /* 16px 避免 iOS 聚焦自動放大 */ }
  .search-results { position: fixed; top: 52px; left: 12px; right: 12px; max-height: 55dvh; }

  .subbar { padding: 8px 12px 9px; }
  .subbar-line {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    font-size: 12.5px;
  }
  /* 手機：保留可點擊的態勢篩選鈕（橫向滑動），省略靜態圖例項（卡片徽章本身帶文字標籤） */
  .legend { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; gap: 6px; }
  .legend::-webkit-scrollbar { display: none; }
  .legend .lg-static { display: none; }
  .legend .lg-label { white-space: nowrap; }
  .legend .lg-btn { flex-shrink: 0; padding: 4px 10px; margin: 0; }
  .theme-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .theme-bar::-webkit-scrollbar { display: none; }

  .map-content { padding: 14px 12px 80px; }
  .band-grid { gap: 8px; }
  .node-card { width: 100%; flex: 1 1 100%; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    height: 84dvh;
    border-left: 0; border-top: 1px solid var(--hairline-2);
    border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow-sheet);
    transform: translateY(105%); transition: transform .24s ease;
    padding: 8px 16px calc(40px + env(safe-area-inset-bottom, 0px));
  }
  .panel::before {
    content: ""; display: block; width: 44px; height: 4px; border-radius: 2px;
    background: var(--hairline-2); margin: 2px auto 12px;
  }
  .panel.open { transform: none; }
  .p-metrics { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

  .footer { padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)); font-size: 10.5px; }
}

/* 觸控裝置：放大點擊目標 */
@media (pointer: coarse) {
  .chip { padding: 3px 9px; }
  .mode-switch button { padding: 6px 10px; }
  .theme-chip { padding: 6px 12px; }
  .tab { padding: 11px 14px 10px; }
  .chip-lg { padding: 6px 12px; }
  .p-close { padding: 6px 10px; font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
