/* =====================================================================
   台灣地震與活動斷層三維圖 — 版面
   方向：全版 3D 圖面，設定以半透明「毛玻璃」浮在圖上，地圖從後方透出。
   標題沿用地質圖幅的圖簽（雙線外框＋格線）。
   ===================================================================== */
:root {
  --ink: #142029;
  --ink-2: #44535d;
  --ink-3: #6b7a83;
  --glass: rgba(244, 247, 246, 0.72);
  --glass-strong: rgba(248, 250, 249, 0.86);
  --glass-line: rgba(255, 255, 255, 0.55);
  --rule: rgba(20, 32, 41, 0.16);
  --rule-2: rgba(20, 32, 41, 0.08);
  --teal: #0e6170;
  --teal-ink: #0a4853;
  --teal-wash: rgba(14, 97, 112, 0.12);
  --site: #f2b705;
  --scene: #1a232b;
  --danger: #b3261e;
  --sans: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --serif: "Noto Serif TC", "PMingLiU", "Songti TC", serif;
  --field: rgba(255, 255, 255, 0.6);
  --field-hi: #fff;
  --track: rgba(20, 32, 41, 0.22);
  --overlay-ink: #c9d4d8;
  --overlay-fade: rgba(15, 21, 26, 0.8);
  --panel-w: 360px;
  --gap: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font: 13.5px/1.55 var(--sans); color: var(--ink); background: var(--scene); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.app { position: fixed; inset: 0; }
.canvas { position: absolute; inset: 0; }
.canvas canvas { display: block; }
.label-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

/* 毛玻璃 */
/* 毛玻璃效果放在不含內容的底層（::before），避免 Chrome 在 GPU 記憶體吃緊時把含捲動內容的毛玻璃面板整塊畫成空白 */
.glass {
  isolation: isolate;
  background: transparent;
  border: 1px solid var(--glass-line);
  box-shadow: 0 10px 30px rgba(5, 12, 18, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border-radius: 10px;
}
.glass::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass::before { background: var(--glass-strong); }
}

/* ------------------------------------------------------------- 左側面板 */
.panel {
  position: absolute; z-index: 5; left: var(--gap); top: var(--gap); bottom: var(--gap);
  width: var(--panel-w); display: flex; flex-direction: column; overflow: hidden;
  transition: transform .32s cubic-bezier(.2, .8, .2, 1), opacity .25s;
}
.app.is-collapsed .panel { transform: translateX(calc(-100% - 2 * var(--gap))); opacity: 0; pointer-events: none; }

.titleblock { position: relative; margin: 12px 12px 4px; padding: 12px 12px 10px 16px; border-radius: 12px; background: var(--field); border: 1px solid var(--rule-2); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); overflow: hidden; }
.titleblock::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: linear-gradient(180deg, var(--teal), color-mix(in srgb, var(--teal) 35%, var(--site))); }
.tb-head { display: flex; align-items: flex-start; gap: 6px; }
.tb-text { flex: 1; min-width: 0; }
.tb-title { font: 700 17px/1.3 var(--sans); letter-spacing: .01em; margin: 0; }
.tb-slogan { margin: 0 0 3px; font-size: 12.5px; font-weight: 700; letter-spacing: .32em; color: var(--teal-ink); }
.tb-title { text-wrap: balance; }
.tb-grid { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.tb-grid div { display: flex; align-items: baseline; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--teal-wash); }
.tb-grid dt { font-size: 10.5px; color: var(--ink-3); }
.tb-grid dd { margin: 0; font-weight: 700; font-size: 12px; color: var(--teal-ink); font-variant-numeric: tabular-nums; }

.sections { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 12px 12px; scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }

.sec { border-bottom: 1px solid var(--rule); }
.sec:last-child { border-bottom: 0; }
.sec-head { display: flex; align-items: center; gap: 8px; }
.sec-toggle { flex: 1; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 10px 0; text-align: left; font-weight: 700; font-size: 14px; }
.sec-toggle .chev { width: 8px; height: 8px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(-45deg); transition: transform .2s; margin: 0 2px; }
.sec-toggle[aria-expanded="true"] .chev { transform: rotate(45deg); }
.sec-meta { margin-left: auto; font-style: normal; font-weight: 500; font-size: 12px; color: var(--teal-ink); font-variant-numeric: tabular-nums; }
.sec-body { padding: 0 0 12px; display: flex; flex-direction: column; gap: 7px; }
.sec-body[hidden] { display: none; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lbl { font-weight: 500; color: var(--ink-2); font-size: 12.5px; }
.value { font-variant-numeric: tabular-nums; color: var(--teal-ink); font-weight: 700; font-size: 12.5px; white-space: nowrap; }
.hint { font-size: 11.5px; color: var(--ink-3); margin: 0; line-height: 1.5; }
.small { font-size: 12px; }
.muted { color: var(--ink-3); }

.year-row { display: flex; align-items: center; gap: 8px; }
.year-row input { flex: 1; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* 按鈕 */
.btn { border: 1px solid var(--rule); background: var(--field); padding: 5px 12px; border-radius: 6px; font-weight: 500; }
.btn:hover { border-color: var(--ink-2); background: var(--field-hi); }
.btn-sm { padding: 3px 10px; font-size: 12.5px; }
.btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-ink); border-color: var(--teal-ink); }
.btn-primary.is-playing { background: var(--ink); border-color: var(--ink); }
.btn-block { width: 100%; margin-top: 10px; padding: 8px 12px; }
.btn-text { background: none; border: 0; padding: 1px 0; color: var(--teal); font-weight: 500; font-size: 12.5px; }
.btn-text:hover:not(:disabled) { text-decoration: underline; }
.btn-text:disabled { color: var(--ink-3); cursor: default; }
.btn-text.danger { color: var(--danger); }
.icon-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--rule); background: var(--field); line-height: 1; padding: 0; display: inline-grid; place-items: center; }
.icon-btn.ghost { border-color: transparent; background: none; }
.icon-btn.ghost:hover { background: var(--rule-2); }
.icon-btn svg { width: 14px; height: 14px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--field); }
.seg button { border: 0; background: none; padding: 4px 0; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--teal); color: #fff; font-weight: 700; }

.chips { display: flex; gap: 4px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: inline-block; min-width: 30px; text-align: center; padding: 1px 6px; border: 1px solid var(--rule); border-radius: 5px; background: var(--field); font-weight: 700; font-size: 12px; }
.chip input:checked + span { background: var(--teal-wash); border-color: var(--teal); color: var(--teal-ink); }
.chip input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }

/* 開關 */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch.line { display: flex; padding: 2px 0; font-size: 12.5px; }
.switch input { position: absolute; left: 0; top: 50%; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch .track { flex: none; width: 30px; height: 17px; border-radius: 9px; background: var(--track); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track::after { transform: translateX(13px); }
.switch input:focus-visible + .track { outline: 2px solid var(--teal); outline-offset: 2px; }

input[type="range"] { width: 100%; accent-color: var(--teal); margin: 0; }

/* 地質敏感區類別 */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cat-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.cat { position: relative; display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--rule); background: var(--field); cursor: pointer; font-size: 12.5px; font-weight: 500; }
.cat input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.cat .sw { width: 14px; height: 14px; border-radius: 3px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.cat:has(input:not(:checked)) { opacity: .5; }
.cat:has(input:not(:checked)) .sw { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.cat:has(input:focus-visible) { outline: 2px solid var(--teal); outline-offset: 2px; }

/* 圖層清單 */
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-list:empty { display: none; }
.layer-item { border: 1px solid var(--rule); background: var(--field); border-radius: 7px; padding: 6px 9px; }
.layer-item.is-active { border-color: var(--site); box-shadow: inset 3px 0 0 var(--site); }
.layer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.layer-name { font-weight: 700; overflow-wrap: anywhere; }
.layer-count { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.layer-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 4px; padding-left: 24px; }
.layer-opts .hint { flex-basis: 100%; }
.layer-opts input[type="color"] { width: 24px; height: 20px; padding: 0; border: 1px solid var(--rule); border-radius: 3px; background: none; }
.check { display: flex; align-items: center; gap: 7px; cursor: pointer; min-width: 0; }
.check input { accent-color: var(--teal); width: 15px; height: 15px; margin: 0; flex: none; }
.check.small { font-size: 12.5px; gap: 5px; }
.swatch { display: inline-block; flex: none; width: 16px; height: 4px; border-radius: 2px; background: var(--c); }
.swatch.is-dashed { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.crs-select, .field select, .field input { border: 1px solid var(--rule); border-radius: 4px; background: var(--field); padding: 2px 4px; font-size: 12px; max-width: 100%; }
.dxf-layers { flex-basis: 100%; display: flex; flex-direction: column; gap: 2px; max-height: 140px; overflow-y: auto; }

/* 拖放區 */
.drop { border: 1.5px dashed var(--ink-3); border-radius: 8px; padding: 9px 10px; text-align: center; background: var(--field); cursor: pointer; transition: background .15s, border-color .15s; }
.drop strong { display: block; font-weight: 700; font-size: 13px; }
.drop span { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.drop:hover, .drop.is-over { border-color: var(--teal); background: var(--field); }
.drop-site { border-color: #b8900a; }
.drop-site:hover, .drop-site.is-over { border-color: #8f6f00; background: rgba(251, 241, 207, .85); }

.paste summary { cursor: pointer; color: var(--teal); font-weight: 500; font-size: 12.5px; }
.field { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: 12.5px; }
.field span { width: 36px; flex: none; color: var(--ink-2); }
.field input, .field select { flex: 1; padding: 3px 6px; }
.paste textarea, #analysis-text { width: 100%; margin: 6px 0; border: 1px solid var(--rule); border-radius: 4px; padding: 6px 8px; font-size: 12px; font-variant-numeric: tabular-nums; resize: vertical; background: var(--field); }

.explain p { margin: 4px 0; line-height: 1.7; }
.pager { display: flex; align-items: center; gap: 6px; }
.howto, .sources { margin: 0; padding-left: 18px; font-size: 12px; color: var(--ink-2); }
.howto li, .sources li { margin: 2px 0; }

.panel-tab { position: absolute; z-index: 5; left: var(--gap); top: var(--gap); display: flex; align-items: center; gap: 6px; padding: 8px 12px 8px 8px; font-weight: 700; font-size: 13px; border-radius: 8px; }
.panel-tab svg { width: 14px; height: 14px; }
.panel-tab:hover { background: var(--glass-strong); }

/* ------------------------------------------------------------- 右側 */
.toolbar { position: absolute; z-index: 5; right: var(--gap); top: var(--gap); display: flex; align-items: stretch; overflow: hidden; padding: 0; }
.compass { position: relative; display: grid; place-items: center; width: 52px; border: 0; border-right: 1px solid var(--rule); background: none; padding: 0; }
.compass::before { content: ""; position: absolute; width: 40px; height: 40px; border-radius: 50%; background: var(--scene); }
.compass svg { position: relative; width: 40px; height: 40px; }
#compass-needle { transform-origin: 24px 24px; }
.view-btn { border: 0; background: none; padding: 0 10px; font-size: 13px; font-weight: 500; min-height: 44px; }
.view-btn + .view-btn { border-left: 1px solid var(--rule-2); }
.view-btn:hover:not(:disabled) { background: var(--field); }
.view-btn.is-active, .view-btn.is-active:hover:not(:disabled) { background: var(--teal); color: #fff; font-weight: 700; }
.view-btn[data-view="site"]:not(:disabled) { box-shadow: inset 0 -3px 0 var(--site); }
.view-btn:disabled { color: var(--ink-3); cursor: default; }

.analysis { position: absolute; z-index: 4; right: var(--gap); top: 70px; width: 340px; max-height: calc(100% - 70px - 52px); display: flex; flex-direction: column; overflow: hidden; border-top: 4px solid var(--site); }
.an-head { display: flex; align-items: flex-start; gap: 8px; padding: 10px 10px 6px 14px; }
.an-head > div { flex: 1; min-width: 0; }
.an-kicker { font-size: 11.5px; color: var(--ink-3); }
.a-title { font: 700 16px/1.35 var(--sans, system-ui); margin: 0; overflow-wrap: anywhere; }
.an-body { overflow-y: auto; padding: 0 14px 14px; scrollbar-width: thin; }
.analysis.is-min .an-body { display: none; }
.a-sub { font-size: 13px; font-weight: 700; margin: 12px 0 4px; padding-top: 10px; border-top: 1px solid var(--rule); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0; font-size: 12.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv-num dd { font-weight: 700; text-align: right; }
.scope { font-size: 11.5px; margin: 4px 0; color: var(--teal-ink); background: var(--teal-wash); padding: 3px 8px; border-radius: 4px; }
.analysis .seg { margin-bottom: 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.tbl th { text-align: left; font-weight: 500; color: var(--ink-3); border-bottom: 1px solid var(--rule); padding: 2px 4px; }
.tbl td { padding: 3px 4px; border-bottom: 1px solid var(--rule-2); }
.tbl tbody tr.click, .tbl-click tbody tr { cursor: pointer; }
.tbl tbody tr.click:hover td, .tbl-click tbody tr:hover td { background: var(--field); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td .swatch { margin-right: 6px; vertical-align: middle; width: 12px; }
.geo-yes { color: #9a1b3c; font-weight: 700; }
.geo-no { color: var(--ink-3); }
.sq { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-right: 6px; vertical-align: -1px; }

.detail { position: absolute; z-index: 6; right: var(--gap); bottom: 52px; width: 300px; max-height: 46%; overflow-y: auto; padding: 8px 12px 10px; }
.detail-head { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
.detail-head h2 { flex: 1; margin: 0; font: 700 14.5px/1.35 var(--sans, system-ui); }
.detail-head .swatch { width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
#detail-body { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 6px 0 0; font-size: 12.5px; }
#detail-body dt { color: var(--ink-3); }
#detail-body dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#detail-body dd.hl { font-weight: 700; }
#detail-body a { color: var(--teal); }
.detail .hint { margin-top: 6px; }

/* 圖例 */
.legend { position: absolute; z-index: 4; left: calc(var(--panel-w) + 2 * var(--gap)); bottom: 34px; padding: 6px 12px; font-size: 11.5px; transition: left .32s cubic-bezier(.2, .8, .2, 1); }
.app.is-collapsed .legend { left: var(--gap); }
.lg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.lg-row + .lg-row { margin-top: 2px; }
.lg-row:empty { display: none; }
.lg-title { font-weight: 700; width: 52px; }
.lg-item { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.size { width: var(--s); height: var(--s); border-radius: 50%; background: var(--ink-2); }
.ln { width: 16px; height: 3px; background: var(--c); }
.ln-dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.ln-site { background: var(--site); height: 4px; box-shadow: 0 0 0 1px var(--ink); }

/* 地圖標籤 */
.map-label { position: absolute; left: 0; top: 0; white-space: nowrap; }  /* 不用 will-change：數百個標籤各自佔一層會耗盡顯示卡記憶體，導致面板整塊不顯示 */
.fault-label { font-size: 11.5px; font-weight: 700; color: #fff; padding: 0 3px; text-shadow: 0 0 3px #000, 0 0 2px #000, 0 0 1px #000; line-height: 1.2; transform-origin: 0 0; }
.fault-label::after { content: ''; display: block; height: 2px; margin-top: 1px; background: var(--c); border-radius: 1px; opacity: .9; }
.site-label { font: 700 13px/1.2 var(--sans); background: var(--site); color: var(--ink); padding: 4px 8px; border: 1.5px solid var(--ink); border-radius: 3px; translate: -50% -100%; margin-top: -6px; }
.site-label::after { content: ""; position: absolute; left: 50%; bottom: -7px; translate: -50% 0; border: 6px solid transparent; border-top-color: var(--ink); border-bottom: 0; }

.statusbar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 5px 240px 5px calc(var(--panel-w) + 2 * var(--gap)); font-size: 12px; color: var(--overlay-ink); background: linear-gradient(to top, var(--overlay-fade), transparent); font-variant-numeric: tabular-nums; pointer-events: none; transition: padding .32s; }
.app.is-collapsed .statusbar { padding-left: var(--gap); }

/* 簽名改由 3D 畫面最底層繪製（buildSigTexture），網頁元件只當字元畫來源，不顯示 */
.signature { visibility: hidden; position: absolute; right: 1.2%; bottom: 1.2%; z-index: 1; pointer-events: none; user-select: none; text-align: center; color: var(--overlay-ink); opacity: .62; }
#asciiCv { display: block; margin-left: auto; margin-right: auto; }
.sigw { font-size: 12px; font-weight: 600; letter-spacing: .06em; margin-top: 4px; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.sigw.sm { font-size: 10.5px; font-weight: 400; margin-top: 0; }
.visitor { flex: none; padding: 7px 12px 8px; border-top: 1px dashed var(--rule); font-size: 12px; color: var(--ink-2); text-align: center; font-variant-numeric: tabular-nums; }

.toast { position: absolute; left: 50%; bottom: 44px; translate: -50% 0; z-index: 8; max-width: min(560px, 90%); background: var(--glass-strong); backdrop-filter: blur(10px); border: 1px solid var(--glass-line); border-left: 5px solid var(--teal); padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.toast.is-error { border-left-color: var(--danger); }

.loading { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: var(--scene); transition: opacity .45s; }
.loading.is-done { opacity: 0; pointer-events: none; }
.loading-box { width: 280px; color: #c9d4d8; font-size: 13px; text-align: center; }
.loading-bar { height: 3px; background: #2c3a44; overflow: hidden; margin-bottom: 12px; }
.loading-bar i { display: block; height: 100%; width: 35%; background: var(--site); animation: load 1.2s ease-in-out infinite; }
.loading.is-error .loading-bar i { background: var(--danger); animation: none; width: 100%; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

/* ------------------------------------------------------------- 手機 */
@media (max-width: 768px) {
  :root { --gap: 8px; }
  .panel { top: auto; height: 62dvh; left: 0; right: 0; bottom: 0; width: auto; border-radius: 14px 14px 0 0; }
  .app.is-collapsed .panel { transform: translateY(105%); }
  .panel-tab { top: auto; bottom: 40px; }
  .toolbar { left: var(--gap); right: var(--gap); }
  .toolbar .view-btn { flex: 1; padding: 0 4px; }
  .analysis { left: var(--gap); right: var(--gap); width: auto; top: 64px; max-height: 40dvh; }
  .detail { left: var(--gap); right: var(--gap); width: auto; bottom: auto; top: 64px; }
  .legend, .statusbar { display: none; }
  /* 手機也顯示簽名（原字元畫，不加底色）：縮小放右下；面板拉起時移到面板上緣之上，不被蓋住 */
  .signature { right: 8px; bottom: 8px; transition: bottom .3s ease; }
  .app:not(.is-collapsed) .signature { bottom: calc(62dvh + 4px); }
  .sigw { font-size: 10.5px; margin-top: 2px; }
  .sigw.sm { font-size: 9px; }
}

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

/* 播放速度 */
.seg-sm { width: 180px; }
/* 逐年長條圖 */
.hist { margin: 6px 0 2px; }
.hist svg { width: 100%; height: auto; display: block; }
/* 分析報告 */
.report { font-size: 12.5px; line-height: 1.75; background: var(--field); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; }
.report h4 { margin: 8px 0 2px; font: 700 13px/1.4 var(--sans, system-ui); }
.report h4:first-child { margin-top: 0; }
.report p { margin: 0 0 4px; }

/* 斷層面、深度標籤 */
.plane { width: 16px; height: 10px; border-radius: 2px; background: linear-gradient(180deg, #e9a3ff 0%, #a23bd6 45%, #3b0f52 100%); opacity: .9; }
.swatch.is-fill { height: 10px; width: 12px; border-radius: 2px; }
.check.sub2 { padding-left: 18px; }
.depth-label { font-size: 11px; font-weight: 600; color: #fff; padding: 1px 5px; border-radius: 4px; background: color-mix(in srgb, var(--c) 70%, #000); transform-origin: 0 0; pointer-events: none; margin-left: 4px; margin-top: -8px; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
/* 人口指標 */
.pop-legend { margin: 8px 0 6px; }
.pop-legend-title { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.pop-legend-items { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; }
.pop-legend .lg-item, .legend .lg-item { display: inline-flex; align-items: center; gap: 4px; }
.sq { display: inline-block; width: 11px; height: 11px; border-radius: 2px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
#btn-example-101 { margin: 0 0 8px; }
#osm-attr { margin-left: 14px; opacity: .85; }
/* 地震規模浮字 */
.mag-pop { position: absolute; left: 0; top: 0; pointer-events: none; font: 700 15px/1 "Noto Sans TC", system-ui, sans-serif; color: #fff; letter-spacing: .02em;
  text-shadow: 0 0 6px rgba(0,0,0,.65), 0 1px 2px rgba(0,0,0,.8); white-space: nowrap; }
.mag-pop small { font-weight: 500; font-size: .72em; opacity: .85; margin-left: 3px; }
.mag-pop.big { font-size: 21px; }
.mag-pop.huge { font-size: 28px; }

/* 基地分析：尚未有基地時的提示卡 */
.analysis-empty { position: absolute; z-index: 4; right: var(--gap); top: 70px; width: 300px; padding: 12px 14px; border-top: 4px solid var(--site); font-size: 13px; }
.analysis-empty h3 { margin: 0 0 6px; font-size: 14px; }
.analysis-empty p { margin: 0 0 8px; color: var(--ink-2); line-height: 1.55; }
.analysis-empty .btn { margin-right: 6px; }
.check.is-disabled { opacity: .45; }

/* 拉近時基地標籤放在基地右側（箭頭朝左） */
.site-label.is-side { translate: 12px -50%; margin-top: 0; }
.site-label.is-side::after { left: -7px; top: 50%; bottom: auto; translate: 0 -50%; border: 6px solid transparent; border-right-color: var(--ink); border-left: 0; }

/* 外框只裁切、不可被捲動：避免點選開關時瀏覽器把整個面板往上捲，造成面板上半消失、下半空白 */
.app, .panel, .analysis, .toolbar { overflow: clip; }

/* ------------------------------------------------------------- 外觀主題
   night：淺色面板＋夜空（預設）；day：淺色面板＋白天天空；dark：深色面板＋夜空
   主色可自訂（--teal），衍生色由 color-mix 算出 */
body { --teal-ink: color-mix(in srgb, var(--teal) 72%, #000); --teal-wash: color-mix(in srgb, var(--teal) 13%, transparent); }
body.theme-day { --scene: #cfe0ea; --overlay-ink: #24343e; --overlay-fade: rgba(236, 243, 247, 0.85); --glass: rgba(250, 252, 252, 0.8); --glass-strong: rgba(252, 253, 253, 0.92); }
body.theme-dark {
  --ink: #e4ecef; --ink-2: #b3c1c8; --ink-3: #8797a0;
  --glass: rgba(16, 24, 30, 0.76); --glass-strong: rgba(16, 24, 30, 0.9); --glass-line: rgba(255, 255, 255, 0.12);
  --rule: rgba(255, 255, 255, 0.16); --rule-2: rgba(255, 255, 255, 0.08);
  --field: rgba(255, 255, 255, 0.07); --field-hi: rgba(255, 255, 255, 0.16); --track: rgba(255, 255, 255, 0.24);
  --teal-ink: color-mix(in srgb, var(--teal) 55%, #fff); --teal-wash: color-mix(in srgb, var(--teal) 22%, transparent);
  color-scheme: dark;
}
body.theme-dark select option { background: #1b252c; color: var(--ink); }
.theme-row { display: flex; align-items: center; gap: 8px; }
.theme-row input[type="color"] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--rule); border-radius: 5px; background: none; cursor: pointer; }
.swatches { display: flex; gap: 5px; }
.swatches button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--glass-line); background: var(--c); padding: 0; }
.swatches button[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 1px; }
/* 白天主題：簽名頭像改深色並提高不透明度，與亮背景對比一致，不會變淡 */
body.theme-day .signature { opacity: .88; }
body.theme-day .sigw { text-shadow: 0 1px 2px rgba(255, 255, 255, .8); }
body.theme-day .statusbar { text-shadow: 0 1px 1px rgba(255, 255, 255, .6); }

/* ------------------------------------------------------------- 功能導覽 */
.tour-btn { margin-top: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 9px; font-weight: 700; font-size: 13.5px; color: #fff; letter-spacing: .04em;
  background: linear-gradient(100deg, var(--teal), color-mix(in srgb, var(--teal) 55%, var(--site))); box-shadow: 0 2px 8px color-mix(in srgb, var(--teal) 35%, transparent); }
.tour-btn:hover { filter: brightness(1.08); }
.tour-card { position: absolute; z-index: 7; top: 18px; left: calc(50% + (var(--panel-w) - 300px) / 2); translate: -50% 0; width: min(500px, calc(100vw - var(--panel-w) - 340px)); min-width: 300px; padding: 14px 16px 12px; }
.tour-head { display: flex; align-items: center; gap: 10px; }
.tour-head h2 { flex: 1; margin: 0; font-size: 17px; }
.tour-step { font-size: 11.5px; font-weight: 700; color: var(--teal-ink); background: var(--teal-wash); padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.tour-card p { margin: 8px 0 10px; font-size: 13.5px; line-height: 1.75; }
.tour-progress { height: 3px; border-radius: 2px; background: var(--rule-2); overflow: hidden; }
.tour-progress i { display: block; height: 100%; width: 0; background: var(--teal); }
.tour-ctrl { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.tour-ctrl .btn:disabled { opacity: .4; cursor: default; }
@media (max-width: 1100px) { .tour-card { left: 50%; top: auto; bottom: 70px; width: min(500px, 92vw); } }
.tb-title .nw { display: inline-block; white-space: nowrap; }

/* ------------------------------------------------------------- 說明與資料來源 */
.about { gap: 10px; }
.credit { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink);
  background: var(--teal-wash); border: 1px solid color-mix(in srgb, var(--teal) 30%, transparent); transition: background .15s; }
.credit:hover { background: color-mix(in srgb, var(--teal) 20%, transparent); }
.credit-k { font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--teal-ink); }
.credit-v { font-size: 13.5px; font-weight: 700; }
.credit-v i { font-style: normal; margin-left: 4px; color: var(--teal-ink); }
.about-h { margin: 6px 0 0; font-size: 12.5px; font-weight: 700; color: var(--ink-2); letter-spacing: .06em; }
.quick { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 12.5px; color: var(--ink-2); }
.quick li { display: flex; gap: 8px; align-items: baseline; line-height: 1.5; }
.quick b { flex: none; width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 6px; background: var(--teal); color: #fff; font-size: 12px; }
.srcs { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; margin: 0; font-size: 12px; line-height: 1.5; }
.srcs dt { font-weight: 700; color: var(--ink); white-space: nowrap; }
.srcs dd { margin: 0; color: var(--ink-2); }
.cite { font-size: 11.5px; color: var(--ink-3); }
.cite summary { cursor: pointer; color: var(--teal-ink); font-weight: 600; }
.cite p { margin: 6px 0 0; line-height: 1.6; }

/* ------------------------------------------------------------- GPS 定位 */
.gps-btn { display: inline-flex; align-items: center; gap: 5px; }
.gps-btn svg { width: 18px; height: 18px; }
.gps-btn.is-busy svg { animation: gpsSpin 1s linear infinite; }
.gps-btn[aria-pressed="true"], .gps-btn[aria-pressed="true"]:hover:not(:disabled) { background: #1a73e8; color: #fff; font-weight: 700; }
@keyframes gpsSpin { to { transform: rotate(360deg); } }
.detail-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
@media (max-width: 768px) { .gps-btn span { display: none; } .gps-btn { justify-content: center; } }

/* ------------------------------------------------------------- 單點與地圖點選 */
.pick-box { display: flex; flex-direction: column; gap: 6px; padding: 9px 10px; border-radius: 8px; background: var(--field); border: 1px solid var(--rule); }
.pt-r { font-size: 12px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; }
.pt-r input { width: 64px; border: 1px solid var(--rule); border-radius: 4px; background: var(--field); padding: 2px 5px; font-size: 12px; text-align: right; }
.pick-seg button { padding: 6px 4px; font-size: 12.5px; }
.paste-mode { margin-top: 6px; }
.paste-mode button { padding: 4px; font-size: 12px; }
.pick-bar { position: absolute; z-index: 8; top: 70px; left: 50%; translate: -50% 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.pick-bar #pick-msg { margin-right: 4px; }
body.is-picking #canvas-container canvas { cursor: crosshair; }
@media (max-width: 768px) { .pick-bar { top: 64px; left: 8px; right: 8px; translate: none; white-space: normal; flex-wrap: wrap; } }

/* ------------------------------------------------------------- 地址查詢與附近資訊 */
.geo-search { display: flex; flex-direction: column; gap: 6px; }
.addr-row { display: flex; gap: 6px; }
.addr-row input { flex: 1; min-width: 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--field); padding: 6px 9px; font-size: 13px; }
.addr-results { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--field); }
.addr-results li { padding: 7px 10px; font-size: 12.5px; cursor: pointer; border-top: 1px solid var(--rule-2); }
.addr-results li:first-child { border-top: 0; }
.addr-results li:hover, .addr-results li:focus { background: var(--teal-wash); outline: none; }
.addr-results li small { color: var(--ink-3); margin-left: 6px; }
#btn-pick-info { width: 100%; }
.near-list { margin: 2px 0 0; padding-left: 16px; }
.near-list li { margin: 1px 0; }
.detail dd.wrap { white-space: normal; }
.detail.is-place { width: 380px; max-height: 72%; }
@media (max-width: 768px) { .detail.is-place { width: auto; max-height: 60dvh; } }

/* 地下光罩 */
.mini-label { margin: 8px 0 4px; font-size: 12px; opacity: .72; }
#mask-opts .seg button { font-size: 12px; }
.mask-big { font-size: 18px; color: #c78a00; }
.mask-mag { margin: 4px 0 0; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.mask-max { width: 100%; text-align: left; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 6px; background: var(--field); font-variant-numeric: tabular-nums; cursor: pointer; }
.mask-max:hover:not(:disabled) { border-color: #c78a00; }

/* 導覽：匯入基地範圍閃爍提示 */
@keyframes dropFlash { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 183, 5, 0); background: var(--field); } 50% { box-shadow: 0 0 0 6px rgba(242, 183, 5, .55); background: rgba(242, 183, 5, .22); } }
.drop.is-flash { animation: dropFlash .9s ease-in-out 4; border-color: #f2b705; }
@media (prefers-reduced-motion: reduce) { .drop.is-flash { animation: none; box-shadow: 0 0 0 4px rgba(242, 183, 5, .55); } }

/* 導覽：介面閃爍提示（次數由 --n 指定） */
@keyframes tourFlash { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 183, 5, 0); } 50% { box-shadow: 0 0 0 4px rgba(242, 183, 5, .9), 0 0 18px 2px rgba(242, 183, 5, .55); background-color: rgba(242, 183, 5, .16); } }
.tour-flash { animation: tourFlash .8s ease-in-out var(--n, 4); border-radius: 10px; }
@media (prefers-reduced-motion: reduce) { .tour-flash { animation: none; box-shadow: 0 0 0 3px rgba(242, 183, 5, .9); } }

/* 導覽 Z 軸標籤 */
.zaxis-label { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; white-space: nowrap; font-weight: 700; font-size: 13px; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; font-variant-numeric: tabular-nums; }
.zaxis-label.is-range { margin: -9px 0 0 -16px; translate: -100% 0; padding: 2px 8px 2px 6px; border-radius: 6px; background: rgba(15, 25, 32, .72); text-shadow: none; display: flex; align-items: center; gap: 6px; }
.zaxis-label.is-range i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.zaxis-label.is-tick { margin: -9px 0 0 18px; font-size: 12px; }
.zaxis-label.is-title { margin: -36px 0 0 0; translate: -70% 0; font-size: 13.5px; }

/* 1935 歷史地震標記 */
.hist-row { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.hist-btns { display: flex; flex-wrap: wrap; gap: 5px; }
.hist-btns .btn { padding-left: 8px; padding-right: 8px; }
.hist-label { position: absolute; left: 0; top: 0; z-index: 3; margin: 0; padding: 4px 9px 5px; translate: none; border: 0; border-radius: 6px; background: rgba(120, 24, 16, .86); color: #fff; font: 600 12px/1.25 var(--sans, system-ui); text-align: left; cursor: pointer; white-space: nowrap; box-shadow: 0 0 0 1px rgba(255, 130, 110, .7); }
.hist-label b { display: block; font-size: 13px; }
.hist-label b.short { display: none; }
.hist-label span { opacity: .9; font-size: 11.5px; }
.hist-label:hover, .hist-label:focus-visible { background: rgba(165, 34, 22, .95); outline: none; }
.hist-label.is-top { background: rgba(70, 20, 110, .88); box-shadow: 0 0 0 1px rgba(200, 120, 255, .75); }
.hist-label.is-top:hover, .hist-label.is-top:focus-visible { background: rgba(105, 30, 165, .95); }
.hist-btns .btn.is-top { border-color: rgba(176, 76, 255, .7); }
.detail.is-hist { width: 440px; max-height: 72%; }
@media (max-width: 768px) {
  .detail.is-hist { width: auto; max-height: 60%; }
  .hist-label { padding: 3px 7px 4px; }
  .hist-label b { font-size: 12px; } .hist-label span, .hist-label b.full { display: none; } .hist-label b.short { display: block; }
}
#detail-body dd.full { grid-column: 1 / -1; margin: 4px 0 6px; overflow-x: auto; }
.hist-src { width: 100%; border-collapse: collapse; font-size: 11.5px; line-height: 1.35; }
.hist-src th, .hist-src td { padding: 3px 4px; border: 1px solid var(--rule, rgba(128,128,128,.35)); vertical-align: top; text-align: left; }
.hist-src th { color: var(--ink-3); font-weight: 600; white-space: nowrap; }
.hist-src td:nth-child(4), .hist-src td:nth-child(5) { white-space: nowrap; }
.hist-intro { position: absolute; z-index: 4; left: 16px; top: 72px; translate: 0 -8px; max-width: 400px; padding: 10px 14px 9px; border-radius: 10px; background: rgba(28, 12, 48, .84); color: #fff; box-shadow: 0 0 0 1px rgba(196, 92, 255, .6), 0 6px 24px rgba(0,0,0,.35); opacity: 0; transition: opacity .5s, translate .5s; cursor: pointer; pointer-events: auto; }
.hist-intro.is-on { opacity: 1; translate: 0 0; }
.hist-intro h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: #e6c4ff; }
.hist-intro .hi-item { display: grid; grid-template-columns: 10px 1fr; column-gap: 8px; align-items: start; margin: 0 0 7px; }
.hist-intro .hi-item > i { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: #d48cff; box-shadow: 0 0 6px #c45cff; }
.hist-intro .hi-item b { display: block; font-size: 13px; line-height: 1.45; }
.hist-intro .hi-item p { margin: 1px 0 0; font-size: 12.5px; line-height: 1.5; color: rgba(255,255,255,.88); }
.hist-intro .hi-note { margin: 8px 0 0; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.18); font-size: 11.5px; line-height: 1.55; color: rgba(255,255,255,.72); }
@media (max-width: 768px) { .hist-intro { top: auto; bottom: 92px; z-index: 7; left: 8px; right: 8px; translate: 0 8px; max-width: none; padding: 9px 12px 8px; } .hist-intro.is-on { translate: 0 0; } .hist-intro .hi-note { display: none; } .hist-intro h3 { font-size: 13.5px; margin-bottom: 6px; } }
@media (prefers-reduced-motion: reduce) { .hist-intro { transition: none; } }
.hist-leader { position: absolute; left: 0; top: 0; z-index: 3; height: 0; border-top: 2px solid rgba(255, 110, 90, .95); filter: drop-shadow(0 0 1px rgba(0,0,0,.6)); transform-origin: 0 0; pointer-events: none; display: none; }
.hist-leader.is-top { border-top-color: rgba(200, 130, 255, .95); }

/* 收合／展開鈕：文字＋箭頭，一看就知道可以按 */
.min-btn { flex: none; display: inline-flex; align-items: center; gap: 3px; height: 26px; padding: 0 8px; border: 1px solid var(--rule); border-radius: 999px; background: var(--field); color: var(--ink-2); font: 600 12px/1 var(--sans, system-ui); cursor: pointer; white-space: nowrap; }
.min-btn:hover { border-color: var(--teal); color: var(--teal-ink); }
.min-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.min-btn svg { width: 12px; height: 12px; }
.min-btn i { font-style: normal; font-size: 10px; }
.ae-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ae-head h3 { margin: 0; }
.ae-body { margin-top: 6px; }
.analysis-empty.is-min { width: auto; padding: 7px 10px 7px 12px; }
.analysis-empty.is-min .ae-body { display: none; }
.analysis.is-min .an-head { padding-bottom: 8px; }
@media (max-width: 768px) {
  .panel { height: 56dvh; }
  .app:not(.is-collapsed) .signature { bottom: calc(56dvh + 4px); }
  .panel::before { content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: rgba(0,0,0,.18); z-index: 2; }
  .titleblock { padding: 10px 12px 10px; }
  .tb-slogan { font-size: 11px; }
  .tb-title { font-size: 16px; }
  .tour-btn { padding: 8px 10px; font-size: 14px; }
  .tb-grid { gap: 4px; margin-top: 8px; }
  .tb-grid div { padding: 2px 7px; }
  .tb-grid dt { font-size: 10px; } .tb-grid dd { font-size: 11px; }
  .analysis-empty { right: var(--gap); top: 64px; width: min(300px, calc(100% - 2 * var(--gap))); }
  .analysis-empty.is-min { width: auto; }
  .analysis { max-height: 45dvh; }
  .tour-card { font-size: 13.5px; }
}
@media (max-width: 768px) {
  #btn-collapse svg { transform: rotate(-90deg); }
  .tour-card p { font-size: 13px; line-height: 1.6; margin: 6px 0 8px; }
}
@media (max-width: 768px) {
  /* 手機面板疊在地圖上，底色加深避免文字被地圖干擾 */
  .panel { background: var(--glass-strong); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
  .titleblock { background: var(--field); }
}
@media (max-width: 768px) {
  /* 手機導覽：面板暫時拉起來閃爍時，導覽卡移到畫面上方，不蓋住正在閃的介面 */
  .app:not(.is-collapsed) .tour-card { top: 60px; bottom: auto; max-height: 30dvh; overflow-y: auto; }
  .app:not(.is-collapsed) .tour-card p { font-size: 12.5px; line-height: 1.5; }
}

/* ------------------------------------------------------------- 導覽精簡橫條（覆蓋舊樣式） */
.tour-card { top: auto; bottom: 16px; left: 50%; translate: -50% 0; width: min(780px, calc(100vw - 32px)); min-width: 0; padding: 8px 10px 0 12px; background: transparent; }
.tour-card::before { background: rgba(248, 250, 249, 0.78); }
body.theme-dark .tour-card::before { background: rgba(16, 24, 30, 0.8); }
.tour-bar-row { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.tour-bar-row h2 { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tour-bar-row .tour-ctrl { margin: 0; gap: 4px; }
.tour-card #tour-text { display: none; margin: 4px 2px 8px; font-size: 13px; line-height: 1.65; }
.tour-card.is-text #tour-text { display: block; }
.tour-card .tour-progress { margin: 6px -10px 0 -12px; border-radius: 0 0 10px 10px; }
/* 導覽時隱藏圖例與狀態列 */
body.is-touring .legend, body.is-touring .statusbar { display: none; }
@media (max-width: 1100px) { .tour-card { left: 50%; top: auto; bottom: 16px; width: min(780px, calc(100vw - 32px)); } }
@media (max-width: 768px) {
  .tour-card { bottom: 8px; width: calc(100vw - 16px); padding: 6px 8px 0 10px; }
  .tour-bar-row { flex-wrap: wrap; row-gap: 4px; }
  .tour-bar-row h2 { font-size: 14px; }
  .tour-bar-row .tour-ctrl { order: 5; flex-basis: 100%; justify-content: flex-end; }
  .tour-card #tour-text { font-size: 12.5px; line-height: 1.55; max-height: 22dvh; overflow-y: auto; }
  .tour-card .tour-progress { margin: 6px -8px 0 -10px; }
  .app:not(.is-collapsed) .tour-card { top: 60px; bottom: auto; max-height: none; overflow: visible; }
  body.is-touring .panel-tab { display: none; }
}
