:root {
  --bg: #fffaf3;
  --fg: #1c1917;
  --muted: #57534e;
  --red: #b91c1c;
  --red-dark: #7f1d1d;
  --line: #d6d3d1;
  --ok: #15803d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 22px/1.5 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; cursor: pointer; }

/* 首頁 */
.home {
  min-height: 100dvh;
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px;
  max-width: 560px; margin: 0 auto;
}
h1 { margin: 0; font-size: 30px; text-align: center; }
.hint { margin: 0; padding: 14px 16px; background: #fef3c7; border-radius: 14px; font-size: 22px; }
.big {
  flex: 1; min-height: 24vh;
  border: 0; border-radius: 36px;
  background: var(--red); color: #fff;
  font-size: clamp(36px, 10vw, 56px); font-weight: 800; line-height: 1.25;
  box-shadow: 0 10px 0 var(--red-dark);
  transition: transform .08s, box-shadow .08s;
  touch-action: manipulation;
}
.big:active { transform: translateY(6px); box-shadow: 0 4px 0 var(--red-dark); }
.big:focus-visible, .btn:focus-visible, .link:focus-visible, .back:focus-visible, .seg button:focus-visible {
  outline: 4px solid #2563eb; outline-offset: 4px;
}
.last { margin: 0; text-align: center; color: var(--muted); min-height: 1.5em; }
.link {
  display: block; text-align: center; padding: 18px;
  border: 3px solid var(--fg); border-radius: 18px;
  color: var(--fg); font-size: 26px; font-weight: 700; text-decoration: none;
}

/* 完成畫面 */
.done {
  position: fixed; inset: 0; z-index: 1000; /* 蓋過地圖控制項（MapLibre 的控制項有自己的 z-index） */
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--ok); color: #fff; text-align: center;
}
.check { font-size: 160px; line-height: 1; font-weight: 800; }
.done p { font-size: 40px; font-weight: 800; margin: 16px; }

/* 共用按鈕 */
.btn {
  min-height: 64px; padding: 12px 20px;
  border: 3px solid var(--fg); border-radius: 18px;
  background: #fff; color: var(--fg); font-weight: 700;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }

.say, .status { margin: 0; font-size: 22px; font-weight: 700; }
.status.warn { color: var(--red); }
.mapbox { flex: 1; min-height: 200px; border-radius: 18px; border: 2px solid var(--line); }
.homewrap { position: relative; flex: none; height: 38vh; min-height: 220px; }
.homewrap .mapbox { height: 100%; }
.pin { position: absolute; left: 50%; top: 50%; width: 44px; height: 66px; transform: translate(-50%, -100%); pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0,0,0,.35)); }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* 地圖頁 */
.mappage { display: flex; flex-direction: column; height: 100dvh; }
.top, .bottom { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.back { color: var(--fg); font-weight: 700; text-decoration: none; font-size: 24px; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; min-height: 60px;
  border: 3px solid var(--fg); border-radius: 16px;
  background: #fff; color: var(--fg); font-weight: 700;
}
.seg button[aria-pressed="true"] { background: var(--fg); color: #fff; }
.mappage .mapbox { margin: 0 16px; border-radius: 18px; }
.legend { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.legend i { flex: 1; height: 18px; border-radius: 9px; background: linear-gradient(90deg, rgba(220,38,38,.12), rgba(220,38,38,.75)); }
.mapbox { overflow: hidden; }

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

/* 同意說明（首頁按鈕下方） */
.consent { margin: 0; text-align: center; line-height: 1.6; font-size: 18px; color: var(--muted); }
.consent a, .note a { color: var(--fg); font-weight: 700; }

/* 地圖頁免責說明 */
.note { margin: 0; font-size: 18px; color: var(--muted); }

/* 隱私權聲明 */
.doc { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
.doc h1 { text-align: left; margin-top: 12px; }
.doc h2 { font-size: 26px; margin: 32px 0 8px; }
.doc .muted { color: var(--muted); margin: 4px 0 0; }
.doc a { color: #1d4ed8; }
.doc ul { padding-left: 1.2em; }
.doc dt { font-weight: 800; margin-top: 20px; }
.doc dd { margin: 4px 0 0; }
.callout { background: #fef3c7; border-radius: 18px; padding: 4px 20px; margin-top: 20px; }
.callout h2 { margin-top: 16px; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 18px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; word-break: break-all; }

/* 申請表 */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.form input:not([type=radio]), .form textarea {
  font: inherit; padding: 12px; border: 2px solid var(--fg); border-radius: 12px; background: #fff;
}
.form fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.form legend { font-weight: 700; margin-bottom: 6px; }
.form .opt { flex-direction: row; align-items: center; gap: 12px; font-weight: 400; min-height: 48px; }
.form .opt input { width: 28px; height: 28px; }
.form .muted { margin: -6px 0 0; font-size: 18px; }
.done-msg { margin: 0; padding: 14px 16px; background: #dcfce7; border-radius: 12px; font-weight: 700; }
.home .consent { margin-top: auto; padding-top: 8px; }

/* 地圖頁「每一次」上一波／下一波 */
.evnav { display: flex; }
.evnav .btn { flex: none; min-height: 56px; }
.evrow span { flex: 1; text-align: center; font-size: 18px; color: var(--muted); }
.evnav .btn:disabled { opacity: .35; }
.seg button { padding: 0 4px; }
.evnav { flex-direction: column; align-items: stretch; gap: 4px; }
.evrow { display: flex; align-items: center; gap: 8px; }
.timeline { position: relative; height: 48px; margin: 0 18px; }
.timeline::before { content: ''; position: absolute; left: -18px; right: -18px; top: 50%; height: 4px; margin-top: -2px; background: var(--line); border-radius: 2px; }
.timeline button {
  position: absolute; top: 50%; width: 40px; height: 40px; padding: 0;
  transform: translate(-50%, -50%); border: 0; background: none;
}
.timeline button::after {
  content: ''; display: block; margin: auto; width: var(--s); height: var(--s);
  border-radius: 50%; background: var(--c); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.timeline button[aria-pressed="true"] { z-index: 1; }
.timeline button[aria-pressed="true"]::after { outline: 4px solid var(--fg); outline-offset: 2px; }
.axis { display: flex; justify-content: space-between; font-size: 16px; color: var(--muted); }

/* 管理者檢視 */
.maplibregl-popup-content { font-size: 16px; white-space: pre-line; }

/* 計算方式頁 */
.how {
  --d-ink: var(--fg); --d-mute: var(--muted); --d-line: var(--line); --d-dot: var(--fg);
  --d-odor: #c62828; --d-wind: #1d4ed8; --d-panel: #fff;
}
.how header, .how section { margin-top: 32px; }
.how h2 .n { display: block; font-size: 18px; color: var(--red); }
.how p { margin: 10px 0; }
.how .lead { color: var(--muted); }
.how figure { margin: 14px 0; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 12px; }
.how figure svg { width: 100%; height: auto; display: block; }
.how figcaption { font-size: 18px; color: var(--muted); margin-top: 8px; }
.how .formula { font: 18px/1.6 ui-monospace, Consolas, monospace; background: #fff; border-left: 4px solid var(--red); padding: 10px 14px; overflow-x: auto; white-space: pre; }
.how .tbl { overflow-x: auto; }
.how table { border-collapse: collapse; width: 100%; font-size: 18px; font-variant-numeric: tabular-nums; }
.how th, .how td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.how th:first-child, .how td:first-child { text-align: left; }
.how .ctl { display: grid; grid-template-columns: auto 1fr auto; gap: 10px 12px; align-items: center; font-size: 20px; margin-top: 10px; }
.how .ctl input { width: 100%; accent-color: var(--red); height: 32px; }
.how .ctl output { font-weight: 700; min-width: 6ch; text-align: right; }
.how .odor { color: #c62828; font-weight: 700; }
.how .wind { color: #1d4ed8; font-weight: 700; }
.how svg text { fill: var(--d-mute); font-size: 14px; font-family: inherit; }
.how svg .t-ink { fill: var(--d-ink); }

/* 風向比較 */
.rose summary { font-weight: 700; cursor: pointer; padding: 6px 0; }
.rose ul { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 6px; }
.rose li { display: grid; grid-template-columns: 4.5em 1fr 3.2em 6em; gap: 8px; align-items: center; font-size: 18px; font-variant-numeric: tabular-nums; }
.rose li i { height: 18px; border-radius: 9px; background:
  linear-gradient(90deg, var(--red) var(--o), transparent var(--o)) top / 100% 60% no-repeat,
  linear-gradient(90deg, var(--line) var(--a), transparent var(--a)) bottom / 100% 40% no-repeat; }
.rose li small { color: var(--muted); font-size: 16px; }
.rose li.hi span, .rose li.hi b { color: var(--red); }
.how .basis td { text-align: left; vertical-align: top; }
.how .basis td:nth-child(2) { white-space: nowrap; color: var(--ok); font-weight: 700; }
.how .basis td.guess { color: #b45309; }
.how .refs li { font-size: 17px; margin-top: 8px; }
