/* IYKYDK Maps：介面樣式。色票、字型與 iykydk.com 共用設計系統一致。
   鐵則：字級不小於 11px、無陰影、無圓角、1px 分隔線、識別紅每頁不超過三處且帶意義
   （三處：作用中的分頁、主要輸出鈕、地圖上的已選頁框）。 */
:root {
  --base: #0D0D0D; --surface: #161616; --surface-2: #1F1F1F;
  --border: #2E2E2E; --border-lt: #3A3A3A;
  --text-1: #E8E4DC; --text-2: #A0998E; --text-3: #5C5650;
  --accent: #C0392B; --silver: #BCBCBC;
  --serif: 'Noto Serif TC', Georgia, serif;
  --sans: 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', 'Helvetica Neue', sans-serif;
  --mono: 'IBM Plex Mono', Consolas, 'Courier New', monospace;
  --top-h: 56px; --panel-w: 348px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { font-size: 16px; }
body { background: var(--base); color: var(--text-1); font-family: var(--sans); font-weight: 400; line-height: 1.6; -webkit-font-smoothing: antialiased; overflow: hidden; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--silver); outline-offset: 2px; }
[hidden] { display: none !important; }

/* 頁首 */
.top { height: var(--top-h); display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 1rem; border-bottom: 1px solid var(--border); background: var(--base); }
.brand { display: flex; align-items: baseline; gap: 0.6rem; text-decoration: none; white-space: nowrap; }
.brand__mark { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; letter-spacing: 0.04em; }
.brand__x { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.12em; color: var(--text-2); }
.search { position: relative; display: flex; gap: 0.4rem; flex: 0 1 560px; min-width: 0; }
.search input { flex: 1; min-width: 0; height: 36px; padding: 0 0.7rem; background: var(--surface); border: 1px solid var(--border-lt); font-size: 0.82rem; }
.search input::placeholder { color: var(--text-3); }
.results { position: absolute; top: 40px; left: 0; right: 0; z-index: 30; list-style: none; background: var(--surface); border: 1px solid var(--border-lt); max-height: 320px; overflow: auto; }
.results li { padding: 0.5rem 0.7rem; font-size: 0.8rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.results li:last-child { border-bottom: 0; }
.results li:hover, .results li.is-on { background: var(--surface-2); }
.results small { display: block; color: var(--text-2); font-size: 0.7rem; }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; height: 36px; padding: 0 0.9rem; background: transparent; border: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.08em; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--silver); }
.btn:disabled { color: var(--text-3); border-color: var(--border); cursor: not-allowed; }
.btn--icon { width: 36px; padding: 0; }
.btn--sm { height: 30px; padding: 0 0.7rem; font-size: 0.7rem; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: #a83226; border-color: #a83226; }
.btn--primary:disabled { background: transparent; }

/* 版面 */
.app { display: flex; height: calc(100% - var(--top-h)); }
.panel { width: var(--panel-w); flex: none; overflow-y: auto; border-right: 1px solid var(--border); background: var(--base); scrollbar-width: thin; scrollbar-color: var(--border-lt) transparent; }
.mapwrap { position: relative; flex: 1; min-width: 0; background: #f6f3ea; }
#map { position: absolute; inset: 0; }

/* 分頁 */
.tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--base); z-index: 5; }
.tabs button { flex: 1; height: 44px; background: none; border: 0; border-bottom: 2px solid transparent; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; color: var(--text-2); cursor: pointer; }
.tabs button:hover { color: var(--text-1); }
.tabs button[aria-selected="true"] { color: var(--text-1); border-bottom-color: var(--accent); }

.sec { padding: 1.1rem 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.sec > * + * { margin-top: 0.7rem; }
.eyebrow { font-family: var(--mono); font-weight: 500; font-size: 0.7rem; letter-spacing: 0.16em; color: var(--text-2); display: flex; align-items: center; gap: 0.6rem; }
.eyebrow::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.sec > .eyebrow:not(:first-child) { margin-top: 1.3rem; }
.note { font-size: 0.76rem; line-height: 1.65; color: var(--text-2); }
.note b { color: var(--text-1); font-weight: 500; }
.note code, .sec--foot code { font-family: var(--mono); font-size: 0.72rem; color: var(--text-1); background: var(--surface-2); padding: 0 0.25rem; }

/* 分段選擇 */
.seg { display: flex; border: 1px solid var(--border-lt); }
.seg button { flex: 1; min-width: 0; height: 32px; padding: 0 0.3rem; background: none; border: 0; border-left: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--text-1); }
.seg button.is-on { background: var(--text-1); color: var(--base); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.rowbtn { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.rowbtn--3 .btn { flex: 1; }
.count { margin-left: auto; font-family: var(--mono); font-size: 0.72rem; color: var(--text-2); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.actions .btn--primary { grid-column: 1 / -1; height: 40px; font-size: 0.8rem; }
.opt { display: grid; grid-template-columns: 4.6rem 1fr; align-items: center; gap: 0.6rem; }
.opt > span { font-size: 0.78rem; color: var(--text-2); }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 0.6rem; padding-top: 0.3rem; }
.checks label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--text-1); cursor: pointer; }
.checks input { appearance: none; width: 14px; height: 14px; padding: 2px; border: 1px solid var(--border-lt); background: transparent content-box; flex: none; cursor: pointer; }
.checks input:checked { background-color: var(--text-1); border-color: var(--text-1); }
.field { display: flex; align-items: center; gap: 0.5rem; font-size: 0.76rem; color: var(--text-2); }
.field select { flex: 1; min-width: 0; height: 32px; padding: 0 0.4rem; background: var(--surface); border: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.72rem; }
.field--full select { width: 100%; }
.field input[type="number"] { flex: 1; min-width: 0; height: 32px; padding: 0 0.4rem; background: var(--surface); border: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.72rem; }
.stack > * + * { margin-top: 0.6rem; }
.check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--text-1); cursor: pointer; }
.check input { appearance: none; width: 14px; height: 14px; padding: 2px; border: 1px solid var(--border-lt); background: transparent content-box; flex: none; cursor: pointer; }
.check input:checked { background-color: var(--text-1); border-color: var(--text-1); }
.btn.is-on { background: var(--text-1); color: var(--base); border-color: var(--text-1); }
#area-go { width: 100%; }
/* 標示分頁 */
.seg--6 button { font-size: 0.7rem; letter-spacing: 0; padding: 0 0.1rem; }
.swatches { display: flex; gap: 0.4rem; }
.swatch { width: 26px; height: 26px; padding: 0; border: 1px solid var(--border-lt); cursor: pointer; background-clip: content-box; }
.swatch.is-on { border: 2px solid var(--text-1); padding: 2px; }
.mk-list { list-style: none; max-height: 300px; overflow-y: auto; border-top: 1px solid var(--border); scrollbar-width: thin; scrollbar-color: var(--border-lt) transparent; }
.mk-list:empty { border-top: 0; }
.mk-list li { display: grid; grid-template-columns: 12px 2.2rem 1fr auto auto; align-items: center; gap: 0.35rem; padding: 0.4rem 0.2rem; border-bottom: 1px solid var(--border); }
.mk-list li.is-on { background: var(--surface-2); }
.mk-list .mk-dot { width: 12px; height: 12px; }
.mk-list .mk-type { font-family: var(--mono); font-size: 0.7rem; color: var(--text-2); }
.mk-list input { min-width: 0; height: 28px; padding: 0 0.4rem; background: var(--surface); border: 1px solid var(--border-lt); font-size: 0.78rem; }
.mk-list small { grid-column: 3 / -1; font-family: var(--mono); font-size: 0.7rem; color: var(--text-2); }
.mk-list .btn--sm { height: 28px; padding: 0 0.5rem; }
.sec--foot { border-bottom: 0; }
.sec--foot p { font-size: 0.7rem; line-height: 1.7; color: var(--text-2); }
.sec--foot a { text-decoration: underline; text-decoration-color: var(--border-lt); text-underline-offset: 2px; }
.sec--foot .ver { font-family: var(--mono); color: var(--text-3); letter-spacing: 0.08em; }

/* 地圖上的浮層 */
.chip { position: absolute; top: 12px; left: 12px; z-index: 3; padding: 0.35rem 0.7rem; background: var(--base); border: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.08em; }
.mode { position: absolute; top: 12px; right: 12px; z-index: 3; display: flex; border: 1px solid var(--border-lt); background: var(--base); }
.mode button { width: 44px; height: 32px; background: none; border: 0; border-left: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; color: var(--text-2); cursor: pointer; }
.mode button:first-child { border-left: 0; }
.mode button.is-on { background: var(--text-1); color: var(--base); }
.readout { position: absolute; left: 12px; bottom: 12px; z-index: 3; padding: 0.5rem 0.7rem; background: rgba(13, 13, 13, 0.92); border: 1px solid var(--border-lt); font-family: var(--mono); font-size: 0.72rem; line-height: 1.65; white-space: pre; pointer-events: none; }
.readout b { font-weight: 500; color: var(--text-2); }
.job { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(13, 13, 13, 0.72); }
.job__box { width: min(360px, 86%); padding: 1.2rem; background: var(--base); border: 1px solid var(--border-lt); display: grid; gap: 0.8rem; }
.job__title { font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.14em; color: var(--text-2); }
.job__bar { height: 4px; background: var(--surface-2); }
.job__bar i { display: block; height: 100%; width: 0; background: var(--text-1); transition: width 0.2s ease; }
.job__msg { font-size: 0.8rem; min-height: 1.3em; }
.job__box .btn { justify-self: start; }
.toast { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 25; max-width: 80%; padding: 0.55rem 0.9rem; background: var(--base); border: 1px solid var(--silver); font-size: 0.8rem; }

/* MapLibre 控制項：去圓角與陰影 */
.maplibregl-ctrl-group, .maplibregl-ctrl-attrib, .maplibregl-ctrl-scale { border-radius: 0 !important; box-shadow: none !important; }
.maplibregl-ctrl-group { border: 1px solid #3a3a3a; }
.maplibregl-ctrl-scale { font-family: var(--mono); font-size: 11px; border-color: #111; color: #111; background: rgba(255, 255, 255, 0.8); }
.maplibregl-ctrl-attrib { font-size: 11px; }
.maplibregl-ctrl-attrib a { color: #333; }

/* 窄螢幕：地圖在上、面板在下 */
@media (max-width: 860px) {
  body { overflow: auto; }
  .top { height: auto; flex-wrap: wrap; padding: 0.6rem 0.8rem; gap: 0.5rem; }
  .search { flex: 1 1 100%; }
  .app { flex-direction: column-reverse; height: auto; }
  .mapwrap { height: 62vh; min-height: 360px; flex: none; }
  .panel { width: 100%; border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  .readout { font-size: 0.7rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
