:root {
  --ink: #1c1915;
  --muted: #5e584f;
  --paper: #f4f0e6;
  --panel: #fbf8f2;
  --line: #ddd4c4;
  --slope: #b45309;
  --scar: #9f1239;
  --focus: #1d4e3a;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.45 "Segoe UI", "PingFang HK", "Noto Sans CJK TC", "Noto Sans TC", "WenQuanYi Micro Hei", "Droid Sans Fallback", "Noto Sans", sans-serif;
}

.utility {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 0;
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px 8px 8px;
  box-sizing: border-box;
  border: 1px solid #c9bfae;
  border-radius: 999px;
  background: #fff;
  color: var(--focus);
  font-size: 16px;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.home-link:hover { border-color: var(--ink); color: var(--ink); }

.home-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.home-chevron {
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  transform: translateY(-1px);
}

.lang-switch {
  display: inline-flex;
  border: 1px solid #c9bfae;
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}

.lang-switch button {
  min-height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px 14px;
  font-weight: 650;
}

.lang-switch button + button { border-left: 1px solid #c9bfae; }

.lang-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: #fbf8f2;
}

.signal-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin: 0 16px 10px;
  padding: 8px 12px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-left-width: 6px;
  border-radius: 6px;
  background: #fff;
}

.signal-kicker {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.signal-bar strong {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.signal-when { color: var(--muted); font-size: 13px; }

.signal-bar[data-tone="pending"],
.signal-bar[data-tone="off"],
.signal-bar[data-tone="error"] { background: #fff; }

.signal-bar[data-tone="amber"] { background: #fff6df; border-color: #e0a33a; }
.signal-bar[data-tone="red"] { background: #fde8e4; border-color: #dc2626; }
.signal-bar[data-tone="red"] strong { color: #9f1239; }
.signal-bar[data-tone="black"] { background: #1c1917; border-color: #1c1917; color: #faf7f2; }
.signal-bar[data-tone="black"] .signal-kicker,
.signal-bar[data-tone="black"] .signal-when { color: #d6d3cd; }
.signal-bar[data-tone="error"] { background: #f6f3ec; }

button, select, input { font: inherit; color: inherit; }

a { color: var(--focus); }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  padding: 12px 16px 10px;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", "Times New Roman", serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.header-note {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  text-align: right;
}

.disclaimer {
  margin: 0 16px 10px;
  padding: 8px 12px;
  border: 1px solid #e7c07a;
  background: #fff6df;
  color: #3f2e10;
  font-size: 13.5px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 0;
  border-top: 1px solid var(--line);
}

.map-wrap, .panel { min-height: 0; }
.map-wrap { position: relative; }

#map { height: 100%; background: #e7e1d6; }

.legend {
  position: absolute;
  z-index: 500;
  left: 12px;
  bottom: 12px;
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  background: rgba(251, 248, 242, 0.94);
  border: 1px solid var(--line);
  font-size: 12px;
}

.legend li { display: flex; align-items: center; gap: 8px; margin: 2px 0; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: inline-block;
}

.swatch.slope { background: var(--slope); }
.swatch.boundary {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  background: rgba(217, 119, 6, 0.55);
  border: 1.5px solid #7c2d12;
}
.swatch.scar { background: var(--scar); }
.swatch.pin { background: #fff; box-shadow: 0 0 0 3px rgba(28, 25, 21, 0.18); }

.panel {
  overflow: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 4px 16px 20px;
}

.block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }

h2 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h3 { margin: 0; font-size: 15px; }

.subhead {
  margin: 14px 0 6px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.status { margin: 0 0 8px; font-variant-numeric: tabular-nums; }

.hint, .counts { margin: 0; color: var(--muted); font-size: 13px; }

.actions { display: flex; gap: 8px; margin-bottom: 10px; }

button, select {
  background: #fff;
  border: 1px solid #c9bfae;
  border-radius: 4px;
  padding: 6px 10px;
}

button { cursor: pointer; }
button:hover { border-color: var(--ink); }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.field { display: grid; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.field input[type="range"] { width: 100%; accent-color: var(--ink); }
#radius-readout { color: var(--ink); font-variant-numeric: tabular-nums; }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.section-head h2 { margin: 0; }

.nearby, .gauges { list-style: none; margin: 8px 0 0; padding: 0; }

.nearby li, .gauges li { border-top: 1px solid var(--line); }

.nearby button {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px 0;
}

.nearby button:hover { background: #f3ecdf; }

.nearby .title, .gauges .title { display: flex; justify-content: space-between; gap: 8px; }
.nearby .meta, .gauges .meta { color: var(--muted); font-size: 12.5px; }

.kind {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.warns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

.warn {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  min-height: 96px;
}

.warn header { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.warn .code { font-size: 11px; letter-spacing: 0.08em; color: var(--muted); }
.warn .state { margin: 8px 0 4px; font-size: 16px; font-weight: 650; line-height: 1.25; }
.warn .when { margin: 0; font-size: 12px; color: var(--muted); }

.warn[data-tone="amber"] { background: #fff6df; border-color: #e0a33a; }
.warn[data-tone="red"] { background: #fde8e4; border-color: #dc2626; }
.warn[data-tone="red"] .state { color: #9f1239; }
.warn[data-tone="black"] { background: #1c1917; border-color: #1c1917; color: #faf7f2; }
.warn[data-tone="black"] .code, .warn[data-tone="black"] .when { color: #d6d3cd; }
.warn[data-tone="landslip"] { background: #ffedd5; border-color: #c2410c; }
.warn[data-tone="landslip"] .state { color: #9a3412; }

.gauges li { padding: 7px 0; }

.credits {
  padding: 8px 16px 10px;
  border-top: 1px solid var(--line);
  background: #ebe4d6;
  font-size: 12px;
  color: #3f3a33;
}

.credits p { margin: 0; }

.pin-dot {
  width: 16px;
  height: 16px;
  border: 2px solid #1c1915;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 5px rgba(28, 25, 21, 0.16);
}

.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 14px; }
.leaflet-popup-content p { margin: 0 0 4px; }

@media (max-width: 860px) {
  .top { flex-direction: column; align-items: start; }
  .header-note { text-align: left; }
  .utility { padding-top: 6px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(160px, 28vh) minmax(0, 1fr); }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .signal-bar strong { font-size: 17px; }
}
