:root {
  --canvas: #f3f1ea;
  --surface: #fffdf9;
  --surface-muted: #f7f4ee;
  --border: #d9d3c7;
  --border-strong: #c8c0b1;
  --text: #1f1d19;
  --text-soft: #5f594f;
  --text-faint: #847d71;
  --brand: #167255;
  --brand-soft: #e6f2ed;
  --brand-strong: #115741;
  --sans: "IBM Plex Sans", "Noto Sans TC", sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--canvas);
}

.app-shell {
  width: min(720px, calc(100vw - 12px));
  min-height: calc(100vh - 12px);
  margin: 6px auto;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title-group {
  min-width: 0;
}

.topbar-title {
  font-size: 0.96rem;
  font-weight: 700;
}

.topbar-subtitle {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 0.77rem;
}

.status-value,
.section-meta,
.section-title,
.card-kicker,
.meta-list dt,
.detail-title {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
}

.status-value,
.section-meta {
  color: var(--text-faint);
}

.main {
  display: grid;
  gap: 0;
  min-width: 0;
}

.status-strip,
.result-section,
.filters-section,
.map-section {
  padding: 12px;
  min-width: 0;
}

.status-strip + .result-section,
.result-section + .filters-section,
.filters-section + .map-section {
  border-top: 1px solid var(--border);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title,
.card-kicker {
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

.status-text,
.result-description {
  margin: 10px 0 0;
  color: var(--text-soft);
  font-size: 0.94rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.result-main {
  min-width: 0;
}

.result-main h2 {
  margin: 10px 0 0;
  font-size: clamp(2rem, 8vw, 3.1rem);
  line-height: 0.98;
  letter-spacing: -0.05em;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.meta-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}

.meta-item {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.meta-list dt {
  color: var(--text-faint);
  text-transform: uppercase;
}

.meta-list dd {
  margin: 6px 0 0;
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.detail-title {
  color: var(--text-faint);
}

.detail-list {
  display: grid;
  gap: 0;
  margin: 10px 0 0;
}

.detail-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.detail-term {
  color: var(--text-faint);
  font-size: 0.84rem;
  line-height: 1.45;
}

.detail-description {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.detail-description a {
  color: var(--brand-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.detail-empty {
  margin: 10px 0 0;
  color: var(--text-faint);
  font-size: 0.88rem;
  line-height: 1.5;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
  min-width: 0;
}

.button,
.maps-link,
.filter-chip {
  font: inherit;
}

.button,
.maps-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  line-height: 1.25;
  white-space: normal;
  word-break: break-word;
  cursor: pointer;
}

.button-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.button:disabled,
.maps-link.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 500;
}

.filter-chip.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.map-section {
  background: var(--surface-muted);
}

#map {
  width: 100%;
  height: 220px;
  min-width: 0;
  margin-top: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.leaflet-container {
  max-width: 100%;
  overflow: hidden;
}

.leaflet-popup-content-wrapper {
  border-radius: 10px;
}

@media (min-width: 768px) {
  .app-shell {
    width: min(1120px, calc(100vw - 24px));
    min-height: calc(100vh - 24px);
    margin: 12px auto;
  }

  .main {
    grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
    grid-template-areas:
      "status status"
      "result map"
      "filters map";
  }

  .status-strip {
    grid-area: status;
  }

  .result-section {
    grid-area: result;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .filters-section {
    grid-area: filters;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .map-section {
    grid-area: map;
    border-top: 1px solid var(--border);
  }

  .action-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meta-list {
    max-width: 420px;
  }

  #map {
    height: 100%;
    min-height: 360px;
  }
}
