/* 市区町村合併マップ */
:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dde3ea;
  --text: #1a2433;
  --text-2: #55627a;
  --text-3: #8b95a8;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --danger: #e34948;
  --shinsetsu: #2a78d6;
  --hennyu: #eb6834;
  --shisei: #1baf7a;
  --chosei: #1baf7a;
  --meisho: #4a3aa7;
  --seirei: #e87ba4;
  --gun: #8b95a8;
  --shadow: 0 2px 10px rgba(15, 30, 60, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14171c;
    --surface: #1d2127;
    --surface-2: #242a32;
    --border: #343c48;
    --text: #e8ecf2;
    --text-2: #a8b2c4;
    --text-3: #768296;
    --accent: #3987e5;
    --accent-soft: #1d3252;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic",
    Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ---------- ヘッダー ---------- */
#header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.title-block h1 { margin: 0; font-size: 19px; letter-spacing: 0.02em; }
.subtitle { margin: 2px 0 0; font-size: 11.5px; color: var(--text-2); }
.stats { display: flex; gap: 10px; margin-left: auto; }
.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 14px;
  text-align: center;
  min-width: 86px;
}
.stat-value { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-label { display: block; font-size: 10.5px; color: var(--text-2); }
.stat-note { color: var(--text-3); }
.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--accent-soft); }

/* ---------- レイアウト ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

#sidebar {
  width: 332px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- タイムライン ---------- */
#timeline {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  z-index: 5;
}
#timeline button {
  background: none; border: none; cursor: pointer;
  font-size: 15px; color: var(--accent);
  padding: 4px 6px; border-radius: 6px;
}
#timeline button:hover { background: var(--accent-soft); }
#date-slider { flex: 1; accent-color: var(--accent); }
#timeline-date {
  font-size: 13px; font-weight: 700; min-width: 84px; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- チャート ---------- */
#chart-box {
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
}
#chart-box h2 { margin: 0 0 4px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
#count-chart svg { width: 100%; height: auto; display: block; cursor: pointer; }
.chart-line {
  fill: none; stroke: var(--accent); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round;
}
.chart-marker { stroke: var(--danger); stroke-width: 1.5; }
.tick { font-size: 9px; fill: var(--text-3); }

/* ---------- イベント一覧 ---------- */
#list-controls {
  display: flex; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
#search-box, #pref-filter {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
}
#search-box { flex: 1; min-width: 0; }
#event-list { flex: 1; overflow-y: auto; padding: 6px 8px 16px; }
.ev-year {
  position: sticky; top: 0;
  background: var(--surface);
  font-size: 11.5px; font-weight: 700; color: var(--text-3);
  padding: 8px 6px 3px;
}
.ev-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}
.ev-row:hover { background: var(--surface-2); }
.ev-row.focused { background: var(--accent-soft); }
.ev-row:not(.applied) .ev-name { color: var(--text-3); }
.ev-badge {
  grid-row: span 2;
  align-self: center;
  font-size: 10px;
  color: #fff;
  border-radius: 5px;
  padding: 3px 6px;
  white-space: nowrap;
}
.t-shinsetsu { background: var(--shinsetsu); }
.t-hennyu { background: var(--hennyu); }
.t-shisei, .t-chosei { background: var(--shisei); }
.t-meisho { background: var(--meisho); }
.t-seirei { background: var(--seirei); }
.t-gun, .t-other { background: var(--gun); }
.t-ward { background: var(--text-3); }
.ev-row.info .ev-name { font-weight: 500; color: var(--text-2); }
.ev-name { font-weight: 600; }
.ev-meta { font-size: 11px; color: var(--text-3); }
.ev-empty { color: var(--text-3); text-align: center; padding: 24px 0; }

/* ---------- イベント詳細 ---------- */
#event-detail {
  position: absolute;
  top: 12px; right: 12px;
  width: 300px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  z-index: 6;
  font-size: 13px;
}
.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.detail-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; font-size: 16px;
  color: var(--text-3); cursor: pointer;
}
.detail-close:hover { color: var(--text); }
.before-list { margin: 0; padding-left: 18px; }
.before-list li { margin: 2px 0; }
.arrow { text-align: center; color: var(--text-3); margin: 4px 0; }
.after-name { font-size: 14px; }
.code { color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.partial { color: var(--hennyu); font-size: 11px; }
.detail-desc { color: var(--text-2); font-size: 12px; margin: 8px 0 0; }
.detail-src { margin: 8px 0 0; }
.detail-src a { color: var(--accent); font-size: 12px; margin-right: 8px; }

/* ---------- 市区町村ポップアップ ---------- */
#muni-popup {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  width: min(430px, calc(100vw - 32px));
  max-height: 44vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
  z-index: 20;
  font-size: 13px;
}
#muni-popup h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
#muni-popup h4 { margin: 10px 0 4px; font-size: 12px; color: var(--text-2); }
.hist { margin: 0; padding-left: 18px; }
.hist li { margin: 3px 0; }
.hist a { color: var(--accent); text-decoration: none; }
.hist a:hover { text-decoration: underline; }
.hist-none { color: var(--text-3); }
.units-note { color: var(--text-2); margin: 4px 0; }

/* ---------- モーダル ---------- */
#about-modal {
  position: fixed; inset: 0;
  background: rgba(10, 16, 26, 0.55);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#about-content {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  max-width: 700px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 24px 28px;
  font-size: 13.5px;
  line-height: 1.75;
}
#about-content h2 { margin-top: 0; font-size: 18px; }
#about-content h3 { font-size: 14.5px; margin: 18px 0 6px; }
#about-content a { color: var(--accent); }
#about-close { position: sticky; top: 0; float: right; background: var(--surface); }

.hidden { display: none !important; }

/* ---------- MapLibre 調整 ---------- */
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- モバイル ---------- */
@media (max-width: 860px) {
  #main { flex-direction: column; }
  #map-wrap { height: 58vh; flex: none; }
  #sidebar { width: 100%; flex: 1; border-left: none; border-top: 1px solid var(--border); }
  .stats { margin-left: 0; }
  #header { gap: 10px; }
  #event-detail { width: min(300px, calc(100vw - 24px)); }
}
