:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5c6b7a;
  --border: #e2e8ee;
  --primary: #1e3a5f;
  --primary-ink: #f4f7fb;
  --accent: #1d4e89;
  --chip: #e8eef3;
  --shadow: 0 10px 28px rgba(20, 32, 48, 0.1);
  --map-bg: #d5dee6;
  --land: #f7f4ef;
  --land-edge: #8b9aab;
  --v400: #e10600;
  --v275: #e6a100;
  --v220: #008c5a;
  --v132: #1d4ed8;
  --hvdc: #7c3aed;
  --boundary: #0891b2;
  --tx: #c026d3;
  --comp: #9a3412;
  --demand: #334155;
  --danger: #b42318;
  --header-h: 56px;
  --sheet-peek: calc(96px + env(safe-area-inset-bottom));
  --sans: "Segoe UI", "Helvetica Neue", "PingFang HK", "PingFang SC", "Noto Sans CJK TC", "Noto Sans CJK SC", "Noto Sans TC", "Noto Sans SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}
html.dark {
  --bg: #12161c;
  --card: #1b2129;
  --text: #e7edf3;
  --muted: #a8b3bf;
  --border: #2c3540;
  --primary: #9ec5ff;
  --primary-ink: #102033;
  --accent: #9ec5ff;
  --chip: #262e38;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --map-bg: #0e141a;
  --land: #1c2833;
  --land-edge: #5c7386;
  --v400: #ff5a4f;
  --v275: #ffc44d;
  --v220: #3ddc97;
  --v132: #7aa2ff;
  --hvdc: #c084fc;
  --boundary: #22d3ee;
  --tx: #f472b6;
  --comp: #fdba74;
  --demand: #cbd5e1;
  --danger: #ffb4ab;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 15px;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.skip { position: absolute; left: 12px; top: -48px; background: var(--primary); color: var(--primary-ink); padding: 8px 12px; border-radius: 8px; z-index: 80; }
.skip:focus { top: 8px; }
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}
.header-inner { height: var(--header-h); display: flex; align-items: center; gap: 12px; padding: 0 12px; max-width: 1440px; margin: 0 auto; }
.brand { display: flex; flex-direction: column; line-height: 1.15; text-decoration: none; color: inherit; min-width: 0; }
.wordmark { font-weight: 700; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.primary-nav, .drawer { display: flex; gap: 4px; align-items: center; }
.primary-nav a, .drawer a, .lang-switch a, .home-link, .icon-btn, .menu-toggle {
  text-decoration: none; color: var(--muted); font-weight: 650; border-radius: 10px;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 12px;
}
.primary-nav a[aria-current="page"], .drawer a[aria-current="page"] { color: var(--text); background: var(--chip); }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.lang-switch { display: flex; background: var(--chip); border-radius: 12px; padding: 2px; }
.lang-switch a { min-height: 44px; padding: 0 10px; font-size: 0.85rem; }
.lang-switch a[aria-current="page"] { background: var(--card); color: var(--text); }
.icon-btn, .menu-toggle { background: var(--chip); border: 0; min-width: 44px; justify-content: center; }
.home-link { font-size: 0.85rem; }
.menu-toggle, .drawer { display: none; }
.drawer { position: fixed; inset: calc(var(--header-h) + env(safe-area-inset-top)) 0 auto 0; background: var(--card); border-bottom: 1px solid var(--border); padding: 8px; z-index: 45; flex-direction: column; align-items: stretch; }
.drawer.open { display: flex; }
.map-page { height: 100dvh; overflow: hidden; overscroll-behavior: none; display: flex; flex-direction: column; }
.map-page .site-footer { display: none; }
.map-shell { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 420px; }
#map { background: var(--map-bg); min-height: 0; touch-action: none; }
.panel { min-height: 0; overflow: auto; background: var(--card); border-left: 1px solid var(--border); overscroll-behavior: contain; }
.sheet-handle { display: none; }
.peek-line { display: none; }
.detail { position: sticky; top: 0; z-index: 3; background: var(--card); border-bottom: 1px solid var(--border); padding: 12px 14px 10px; }
.detail h2 { margin: 0 0 4px; font-size: 1.05rem; line-height: 1.3; }
.kicker { color: var(--accent); font-size: 0.75rem; font-weight: 750; letter-spacing: 0.04em; text-transform: uppercase; }
.facts { display: grid; grid-template-columns: 7.2rem 1fr; gap: 3px 8px; margin: 8px 0; font-size: 0.92rem; }
.facts dt { color: var(--muted); margin: 0; }
.facts dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.actions a, .actions button, .text-btn {
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--chip); color: var(--text); text-decoration: none; display: inline-flex; align-items: center;
}
.note { color: var(--muted); font-size: 0.88rem; margin: 6px 0 0; }
.warn { color: var(--danger); }
.panel-body { padding: 12px 14px 24px; }
.search { position: relative; }
.search input, .filters select, .filters input, .data-tools input, .data-tools select {
  width: 100%; min-height: 44px; font-size: 16px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); padding: 0 12px;
}
.results { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); max-height: 50dvh; overflow: auto; }
.results button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 10px 12px; min-height: 44px; }
.results button small { display: block; color: var(--muted); }
.results button:hover, .results button:focus { background: var(--chip); }
.filters { display: grid; gap: 8px; margin: 12px 0; }
.layer-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.layer-row { display: flex; align-items: center; gap: 6px; }
.layer-row label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.layer-only {
  flex: none; min-height: 44px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--chip); color: var(--muted);
  font-size: 0.78rem; font-weight: 700;
}
.swatch { width: 14px; height: 14px; border-radius: 99px; display: inline-block; border: 2px solid transparent; }
.swatch.v400 { background: var(--v400); }
.swatch.v275 { background: var(--v275); }
.swatch.v220 { background: var(--v220); }
.swatch.v132 { background: var(--v132); }
.swatch.hvdc { background: var(--hvdc); }
.swatch.tx { background: var(--tx); }
.swatch.comp { background: var(--comp); }
.swatch.demand { background: var(--demand); }
.swatch.boundaries { background: var(--boundary); border-radius: 2px; height: 4px; opacity: 0.25; }
.estimate-flag {
  display: flex; align-items: flex-start; gap: 8px; margin: 8px 0 0; padding: 8px 10px;
  border: 2px solid #9a3412; border-radius: 10px; background: #fff7ed; color: #7c2d12; font-weight: 650;
}
.estimate-flag strong {
  flex: none; padding: 2px 8px; border-radius: 999px; background: #9a3412; color: #fff;
  font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase;
}
html.dark .estimate-flag { background: #3b2416; color: #ffedd5; border-color: #fdba74; }
html.dark .estimate-flag strong { background: #c2410c; color: #fff7ed; }
.diagram-note { color: var(--muted); font-size: 0.88rem; margin: 0 0 10px; }
.legend-note { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); font-size: 0.82rem; margin: 6px 0 0; min-height: 44px; }
.layer-hint { color: var(--muted); font-size: 0.78rem; line-height: 1.35; margin: -2px 0 8px 28px; list-style: none; }
.gen-legend {
  position: absolute; z-index: 800; top: 10px; right: 10px;
  max-width: min(220px, 46vw); max-height: min(70dvh, 420px); overflow: auto;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 8px 10px;
}
.gen-legend[hidden] { display: none; }
.gen-legend p { margin: 0 0 6px; font-size: 0.78rem; font-weight: 750; }
.gen-legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.gen-legend li { display: flex; align-items: center; gap: 8px; min-height: 28px; font-size: 0.82rem; }
.gen-legend i { width: 12px; height: 12px; border-radius: 99px; border: 1px solid #102033; flex: none; }
.row-actions { display: flex; gap: 8px; margin: 8px 0 14px; }
.page { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
.page-narrow { max-width: 760px; }
.prose h1, .prose h2 { line-height: 1.25; }
.muted { color: var(--muted); }
.table-wrap { overflow: auto; max-height: calc(100dvh - 240px); border: 1px solid var(--border); border-radius: 12px; }
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 0.9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; background: var(--card); }
th { position: sticky; top: 0; z-index: 2; cursor: pointer; }
td:first-child, th:first-child { position: sticky; left: 0; z-index: 1; }
th:first-child { z-index: 3; }
tr.hit td { background: color-mix(in srgb, var(--accent) 16%, var(--card)); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs button { min-height: 44px; border-radius: 999px; border: 1px solid var(--border); background: transparent; padding: 0 12px; }
.tabs button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.data-tools { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.site-footer { padding: 18px 16px 28px; color: var(--muted); font-size: 0.9rem; }
.leaflet-container { font-family: var(--sans); background: var(--map-bg); }
.gen-icon { background: transparent; border: 0; }
.gen-icon span {
  display: block; width: 22px; height: 22px; border-radius: 99px; color: white; font-size: 11px; font-weight: 750;
  line-height: 22px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
@media (max-width: 899px) {
  .primary-nav, .home-link { display: none; }
  .menu-toggle { display: inline-flex; }
  .map-shell { display: block; position: relative; }
  #map { position: absolute; inset: 0; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 500;
    border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow); height: min(48dvh, 460px);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel[data-sheet="peek"] { height: var(--sheet-peek); overflow: hidden; }
  .panel[data-sheet="half"] { height: min(48dvh, 460px); }
  .panel[data-sheet="full"] { height: calc(100% - 8px); }
  .sheet-handle { display: flex; justify-content: center; align-items: center; height: 44px; touch-action: none; background: transparent; border: 0; width: 100%; }
  .sheet-handle::before { content: ""; width: 42px; height: 5px; border-radius: 99px; background: var(--border); }
  .panel[data-sheet="peek"] .detail, .panel[data-sheet="peek"] .panel-body { display: none; }
  .panel[data-sheet="peek"] .peek-line { display: block; padding: 0 16px 8px; font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .detail { position: static; }
}
@media (pointer: coarse) {
  .leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
  .gen-icon span { width: 44px; height: 44px; line-height: 44px; font-size: 16px; }
}
@media (min-width: 900px) {
  .peek-line, .sheet-handle, .mobile-only { display: none !important; }
}
