:root {
  --content-width: 85%;
  --side-panel-width: 340px;
  --side-panel-max-width: calc(100% - 20px);
  --panel-border: 1px solid var(--line-soft);
  --legend-grid-columns: 20px 30px minmax(0, 1fr);
  --legend-grid-gap: 10px;
  --tooltip-background: rgba(0, 0, 0, 0.8);
  --desktop-map-height: 680px;
  --mobile-map-height: 400px;
  --search-max-height: 540px;
  --search-body-max-height: 488px;
  --mobile-search-max-height: 1100px;
  --legend-max-height: min(52vh, 420px);
  --legend-collapsed-height: 40px;
  --legend-color-list-max-height: min(30vh, 240px);
  --chart-frame-max-height: 920px;
  --chart-canvas-height: 800px;
  --month-chart-height: 40vh;
  --font-body: Verdana, "BIZ UDPGothic", "Yu Gothic", "Yu Gothic UI", Meiryo, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Yu Gothic UI", monospace;
  --page-bg: #eef3f6;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --surface-muted: #edf3f7;
  --text-main: #22313f;
  --text-muted: #607181;
  --line-soft: #d6e0e8;
  --accent: #386f9e;
  --accent-soft: #e7f1f8;
  --panel-radius: 13px;
  --panel-shadow: 0 12px 30px rgba(28, 45, 62, 0.12);
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--text-main);
  background:
    radial-gradient(circle at top left, rgba(93, 143, 178, 0.16), transparent 34rem),
    linear-gradient(180deg, #f7fafc 0%, var(--page-bg) 45%, #e9eff3 100%);
  min-height: 200vh;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

/* ヘッダー部分のスタイル */
header {
  text-align: center; /* タイトルをセンターに配置 */
  margin: 18px auto 16px; /* 上部の余白 */
  padding: 18px 20px 12px;
  width: 100%; /* 幅を100%に設定 */
  position: relative;
  box-sizing: border-box;
}

/* タイトルのフォントサイズを調整 */
header h1 {
  font-size: clamp(1.55rem, 2.6vw, 2.1rem); /* 文字サイズを調整 */
  color: var(--text-main); /* 文字色 */
  line-height: 1.32;
  max-width: var(--content-width);
  margin: 0 auto;
  letter-spacing: 0.01em;
}

#mapid,
.tab-container {
  width: var(--content-width);
  margin: 0 auto;
}

#mapid {
  position: relative; /* 地図を基準とする */
  top: 0;
  bottom: 0;
  height: var(--desktop-map-height);
  margin-bottom: 8px;
  z-index: 1;
}

.maplibregl-ctrl-bottom-left {
  z-index: 2 !important;
}

/* 検索コンテナの基本スタイル */
.search-container,
.legend {
  width: var(--side-panel-width);
  max-width: var(--side-panel-max-width);
  background: #fff;
  border: var(--panel-border);
  box-sizing: border-box;
}

.search-container {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 0; /* 内側の余白はヘッダー・ボディ各自で確保する */
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
  box-shadow: 0 10px 26px rgba(26, 43, 58, 0.16);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transition: max-height 0.3s ease-out;
  max-height: var(--search-max-height);
  overflow: hidden;
}

.search-header {
  position: relative;   /* 必要に応じて */
  display: flex;
  align-items: center;
  padding: 10px 12px 9px;
  border-bottom: 1px solid #d6dde5;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, #fdfefe 0%, #eef3f7 100%);
  box-sizing: border-box;
}

.search-header .toggle-button {
  margin-right: 8px; /* タイトルとの間隔 */
  /* rotate 周りの transition はそのまま */
}

.search-body {
  max-height: var(--search-body-max-height) !important;
  padding: 8px;
  overflow-y: auto;     /* 縦スクロールを有効に */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(180deg, #fbfcfd 0%, #f6f9fb 100%);
}

/* searchContainerが閉じられている時のスタイル */
.search-container.closed {
  max-height: 40px; /* 高さを0にして隠す */
  overflow: hidden;
}

/* toggle-button（三角形）のスタイル */
.toggle-button {
  position: absolute;
  right: 12px;
  bottom: 10px;
  background: transparent;
  border: none;
  font-size: 17px;
  color: #5f6c79;
  cursor: pointer;
  transition: transform 0.5s ease; /* 回転アニメーション */
  transform: rotate(180deg);
}

/* 三角印が回転した状態 */
.toggle-button.rotate {
  transform: rotate(360deg); /* 180度回転 */
}

#reset-button {
  min-height: 31px;
  padding: 5px 12px;
  border: 1px solid #c2cdd8;
  border-radius: 8px;
  background: #f3f6f9;
  color: #314252;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: block;
  width: 100%;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.maplibregl-popup {
  z-index: 100;  /* ポップアップを前面に表示 */
}

.maplibregl-popup-content {
  overflow: hidden;
  border: 1px solid rgba(49, 66, 82, 0.18);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(20, 34, 47, 0.24);
  z-index: 50;
  width: min(30vw, 420px);
  min-width: min(280px, calc(100vw - 36px));
  padding: 0;
  word-wrap: break-word; /* 長い単語を折り返す */
  word-break: break-word; /* 必要に応じて単語を途中で改行 */
  white-space: normal; /* 折り返しを有効にする */
}

.maplibregl-popup-close-button {
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #586a7a;
  font-size: 18px;
  line-height: 22px;
}

.maplibregl-popup-close-button:hover {
  background: rgba(221, 229, 236, 0.9);
  color: #213447;
}

.popup-link-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.popup-link-label {
  font-weight: bold;
}

.popup-link-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border: 1px solid #7d8791;
  border-radius: 999px;
  background: #f7fafc;
  color: #0b4a6f;
  text-decoration: none;
  font-size: 0.82em;
  line-height: 1.35;
  white-space: nowrap;
}

.popup-link-pill:hover {
  background: #eaf2f8;
}

.literature-link-pill {
  margin-left: 6px;
}

.reference-url-link {
  margin-left: 6px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.popup-note-reference-heading {
  font-weight: 700;
  margin-top: 2px;
}

.popup-note-reference-list {
  margin: 3px 0 0 1.6em;
  padding: 0;
}

.popup-note-reference {
  margin: 2px 0;
  padding-left: 0.1em;
}

.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-top-left, .maplibregl-ctrl-top-right {
  z-index: 31; /*attributionをlegendより手前に表示*/
}

.current-location-control .current-location-button {
  width: auto;
  min-width: 0;
  padding: 0 10px;
  font-size: 12px;
  font-family: inherit;
}

.marker-scope-control .marker-scope-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  padding: 0;
}

.marker-scope-control .marker-scope-button:disabled {
  color: #9aa4ad;
  cursor: default;
}

.marker-scope-control .marker-scope-button:disabled .marker-scope-icon {
  opacity: 0.68;
}

.marker-scope-icon {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* 種と都道府県のセレクトボックスの間の区切り線 */
.select-box-divider-one {
  border-top: 1px solid #d8e0e7;
  margin: 2px 0 0;
}

/* 文献のセレクトボックスと検索窓の間の区切り線 */
.select-box-divider-two {
  border-top: 1px solid #d8e0e7;
  margin: 2px 0 0;
}

/* Legendの基本スタイル */
.legend {
  position: absolute;
  bottom: 30px;
  right: 10px;
  padding: 0;
  font-size: 14px;
  z-index: 29;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 0.3s ease-out; /* 高さの変化をスムーズに */
  max-height: var(--legend-max-height); /* 初期状態では最大高さ */
  max-width: min(380px, calc(100vw - 28px));
  border: var(--panel-border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
  box-shadow: 0 10px 26px rgba(26, 43, 58, 0.16);
}

/* Legend ヘッダー部分のスタイル */
.legend-item {
  display: grid;
  grid-template-columns: var(--legend-grid-columns);
  align-items: center;
  column-gap: var(--legend-grid-gap);
}

.legend-header {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 28px;
  align-items: center;
  column-gap: 10px;
  min-height: var(--legend-collapsed-height);
  padding: 8px 12px;
  margin: 0;
  font-weight: bold;
  position: relative; /* トグルボタンの配置を調整 */
  border-bottom: 1px solid #d6dde5;
  background: linear-gradient(180deg, #fdfefe 0%, #eef3f7 100%);
  box-sizing: border-box;
}

.legend-header::before {
  content: none;
}

.legend-header {
  border-radius: 12px 12px 0 0;
}

.legend-header input[type="checkbox"],
.legend-item input[type="checkbox"] {
  width: 13px;
  height: 13px;
  margin: 0;
}

.legend-header input[type="checkbox"] {
  grid-column: 1; /* 1列目（他のチェックボックスと統一） */
}

/* 「マーカーの種類」のタイトルをテキスト列に移動 */
.legend-header span {
  grid-column: 2; /* 2列目に配置（チェックボックスの横） */
  min-width: 0;
  text-align: left;
}

/* トグルボタンのスタイル */
.legend-toggle-button {
  position: absolute;
  right: 12px;
  bottom: 10px;
  top: auto;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  color: #5f6c79;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.5s ease;
  transform: rotate(0deg);
}

/* 折りたたみ時のスタイル（高さを0に） */
.legend.collapsed {
  max-height: var(--legend-collapsed-height); /* タイトル部分だけを表示 */
  overflow: hidden;
}

.legend.collapsed .legend-header {
  border-bottom: 0;
  border-radius: 12px;
}

.legend:not(.collapsed) {
  max-height: none;
  overflow: visible;
}

.legend.collapsed .legend-toggle-button::after {
  content: "\25B2"; /* 閉じているときは「▲」 */
}

.legend-toggle-button::after {
  content: "\25BC"; /* 開いているときは「▼」 */
}

.legend > .legend-item,
.legend > .legend-color-block {
  margin-inline: 10px;
}

.legend > .legend-item:first-of-type {
  margin-top: 10px;
}

.legend > .legend-item:last-of-type {
  margin-bottom: 10px;
}

.legend-color-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #d6dde5;
  max-width: 100%;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.legend-color-block[hidden] {
  display: none !important;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.legend-color-title {
  font-weight: 700;
  margin-bottom: 8px;
  color: #2e3c4a;
  line-height: 1.35;
}

.legend-color-title:empty,
.legend-color-title[hidden] {
  display: none !important;
  margin-bottom: 0;
}

.legend-color-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  max-height: var(--legend-color-list-max-height);
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.legend-color-list:empty,
.legend-color-list[hidden] {
  display: none !important;
}

.legend-color-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  column-gap: 8px;
  align-items: center;
  padding: 3px 2px;
  border-radius: 6px;
  outline-offset: 2px;
  cursor: default;
}

.legend-color-item:hover,
.legend-color-item:focus-within {
  background: rgba(226, 235, 242, 0.72);
}

.legend-color-chip {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.28);
}

.legend-color-label {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.legend-item .marker {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: auto; /* 上下左右の中央配置 */
}

.legend-item-text {
  position: relative;
  display: inline-block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-item .marker.legend-marker-neutral {
  background-color: #a7b1bc !important;
  border-color: #66727d !important;
}

.legend-item .marker.marker-square.legend-marker-neutral {
  border-width: 3px;
  border-style: solid;
}

.legend-item .marker.marker-circle.legend-marker-neutral {
  background-color: #a7b1bc !important;
  border-color: #66727d !important;
}

.legend-item .marker.legend-marker-hollow {
  background-color: #ffffff !important;
  border-color: #66727d !important;
}

.legend-item-text::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin: auto;
  background: var(--tooltip-background);
  color: white;
  padding: 5px 8px;
  font-size: 12px;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 200px;
  border-radius: 4px;
  box-shadow: 0 8px 18px rgba(20, 34, 47, 0.22);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
  z-index: 50; /* 地図より前面に表示 */
}

.legend-item-text:hover::after {
  opacity: 1;
  visibility: visible;
}

.marker-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate3d(-9999px, -9999px, 0);
  background: var(--tooltip-background);
  color: white;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none; /* ツールチップがクリックイベントを妨げないようにする */
  z-index: 50;
  will-change: transform;
  display: none; /* 初期状態では非表示 */
}

/* 星のマーカー（サイズを大きくする） */
.marker-star {
  width: 20px;
  height: 20px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  border: none;
}

/* バツ印のマーカー */
.marker-cross {
  width: 14px;
  height: 14px;
  clip-path: polygon(
    0% 12%, 12% 0%, 50% 38%, 88% 0%, 100% 12%, 62% 50%, 
    100% 88%, 88% 100%, 50% 62%, 12% 100%, 0% 88%, 38% 50%
  );
  border: none;
}

/* 丸のマーカー */
.marker-circle {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 3px solid darkred;
}

/* 四角形のマーカー */
.marker-square {
  width: 10px;
  height: 10px;
  border-radius: 0;
  border: 3px solid black;
}

/* カラーバリエーション */
.marker.blue {
  background-color: blue;
}

.marker.purple {
  background-color: purple;
}

.marker.pink {
  background-color: pink;
}

.marker.red {
  background-color: red;
}

.marker.white {
  background-color: white;
  border: 3px solid red; /* 文献記録用の縁取り */
}

/* クリック可能なマーカーのホバー時のポインタ変更 */
.marker-clickable {
  cursor: pointer; /* マウスの形状をポインタに変更 */
}

.record-marker {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
  contain: layout paint style;
  position: relative;
  overflow: visible;
  -webkit-clip-path: none;
  clip-path: none;
  transition: opacity 120ms ease;
}

.record-marker.is-color-dimmed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.record-marker.is-color-highlight {
  opacity: 1;
  visibility: visible;
  z-index: 5;
}

.record-marker.kind-type {
  width: 32px;
  height: 32px;
}

.maplibregl-marker.record-marker {
  position: absolute;
}

.record-marker svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.record-marker:focus {
  outline: 3px solid rgba(0, 95, 255, 0.45);
  outline-offset: 2px;
  border-radius: 4px;
}

.popup-title-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
  column-gap: 7px;
  margin-bottom: 1px;
}

.popup-title-marker {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: -1px;
}

.popup-title-marker.kind-type {
  width: 24px;
  height: 24px;
}

.popup-title-marker svg {
  width: 100%;
  height: 100%;
  display: block;
}

.popup-title-text {
  min-width: 0;
}

#checkbox-container {
  display: flex;
  flex-direction: column; /* チェックボックスを縦に並べる */
  gap: 5px; /* 各ラベル間の間隔を調整 */
}

#checkbox-container label {
  display: flex;
  align-items: center; /* チェックボックスとテキストを垂直方向に揃える */
  font-size: 14px;
  cursor: pointer;
}

#checkbox-container input[type="checkbox"] {
  margin: 2px 4px 2px 4px; /* 上下2px、左右4pxに設定して幅を減少 */
  width: auto; /* 必要に応じて幅を調整 */
}

/* セレクトボックスとボタンを横並びに */
.select-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 3px; /* ボタンとの間隔 */
}

.filter-primary-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 8px;
  border: 1px solid #d9e1e8;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.display-settings-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  padding: 0;
  border: none;
  border-radius: 9px;
  background: transparent;
  box-shadow: none;
}

.marker-color-by-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid #d9e1e8;
  border-radius: 9px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.marker-color-by-label {
  font-size: 12px;
  font-weight: 700;
  color: #526170;
}

.marker-color-by-container .filter-dropdown,
.marker-color-by-container .filter-dropdown-trigger {
  width: 100%;
}

.search-body > .map-filter-container,
.search-body > #box-select-buttons,
.search-body > .year-filter,
.search-body > .biennial-filter,
.search-body > #month-container,
.search-body > .life-stage-filter,
.search-body > #checkbox-container {
  padding: 6px 8px;
  border: 1px solid #d9e1e8;
  border-radius: 9px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.map-filter-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-container[data-select-mode="multi"] .select-container[data-select-filter="normal"] .nav-button {
  display: none;
}

.search-container[data-select-mode="single"] .display-settings-group {
  display: none;
}

.select-mode-toggle {
  display: flex;
  gap: 4px;
  margin: 0 0 3px;
  padding: 3px;
  border: 1px solid #c9d3dd;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: none;
}

.filter-primary-group #reset-button {
  margin-top: 2px;
}

.select-mode-option {
  flex: 1 1 0;
}

.select-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.select-mode-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #5b6875;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.select-mode-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(56, 89, 124, 0.22);
}

.select-mode-option input:focus-visible + span,
.filter-dropdown-action-button:focus-visible {
  outline: 2px solid #2d6ca2;
  outline-offset: 2px;
}

/* セレクトボックスの見出し */
.select-box-title {
  background-color: transparent;
  color: #263746;
  font-size: 14px;
  font-weight: bold;
  text-align: left;
  padding: 0;
  margin: 0;
  border-bottom: none;
}

.filter-section-title {
  font-size: 14px;
}

#month-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#collection-month-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
}

#collection-month-checkboxes label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  white-space: nowrap;
}

/* セレクトボックスの幅と高さを統一 */
.select-container select {
  flex-grow: 1; /* 幅を一定にするために調整 */
  width: 0px; /* 絶対幅を設定 */
  max-width: none;
  min-width: 200px;
  height: 24px; /* 高さを適切に調整 */
  font-size: 14px;
  padding: 2px; /* 内部の余白を調整 */
  box-sizing: border-box; /* 幅計算を内側の要素に含める */
}

.filter-select-native {
  display: none;
}

.filter-dropdown {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  font-size: 14px;
}

.filter-dropdown-trigger {
  width: 100%;
  min-height: 24px;
  border: 1px solid #cbd6df;
  border-radius: 4px;
  background: #fff;
  color: var(--text-main);
  text-align: left;
  font: inherit;
  padding: 2px 32px 2px 8px;
  box-sizing: border-box;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.filter-dropdown-trigger:hover {
  border-color: #9fb3c5;
  background: #fbfdff;
}

.filter-dropdown-trigger:focus-visible {
  outline: 2px solid rgba(56, 111, 158, 0.28);
  outline-offset: 1px;
}

.filter-dropdown-trigger.is-placeholder {
  color: #666;
}

.filter-dropdown-trigger-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-dropdown-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  user-select: none;
  background: none;
  border: none;
  padding: 0;
  line-height: 1;
}

.filter-dropdown-clear:hover {
  color: #e60000;
}

.filter-dropdown-clear[hidden],
.filter-dropdown-arrow[hidden] {
  display: none !important;
}

.filter-dropdown-arrow {
  position: absolute;
  right: 11px;
  top: 50%;
  width: 0;
  height: 0;
  transform: translateY(-30%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #666;
  pointer-events: none;
  transition: transform 0.16s ease;
}

.filter-dropdown.is-open .filter-dropdown-arrow {
  transform: translateY(-30%) rotate(180deg);
}

.filter-dropdown-portal {
  position: fixed;
  z-index: 2000;
}

.filter-dropdown-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid #aaa;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  box-sizing: border-box;
  overscroll-behavior: contain;
}

.filter-dropdown-search {
  width: 100%;
  height: 28px;
  padding: 4px 6px;
  font: inherit;
  box-sizing: border-box;
}

.filter-dropdown-options {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  overflow-y: auto;
  max-height: min(320px, 50vh);
  border: 1px solid #ddd;
  overscroll-behavior: contain;
}

.filter-dropdown-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 100%;
  width: max-content;
  box-sizing: border-box;
  padding: 6px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.filter-dropdown-option-label {
  display: block;
}

.filter-dropdown-option-count {
  color: #6b7280;
  font-size: 0.82rem;
  margin-left: auto;
  padding-left: 1rem;
  white-space: nowrap;
}

.filter-dropdown-option-checkbox {
  margin: 0;
  pointer-events: none;
}

.filter-dropdown-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.filter-dropdown-panel[data-select-mode="single"] .filter-dropdown-actions {
  display: none !important;
}

.filter-dropdown-actions-footer {
  justify-content: flex-end;
}

.filter-dropdown-action-button {
  min-height: 30px;
  padding: 4px 12px;
  border: 1px solid #c6d0da;
  border-radius: 999px;
  background: #f2f5f8;
  color: #40505f;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.filter-dropdown-action-button:hover {
  border-color: #aab7c4;
  background: #e8eef4;
  color: #263746;
}

.filter-dropdown-action-primary {
  border-color: #4873a3;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(56, 89, 124, 0.24);
}

.filter-dropdown-action-primary:hover {
  border-color: #3f6791;
  background: #2f628f;
  color: #fff;
}

.filter-dropdown-option:hover {
  background: #dfefff;
}

.filter-dropdown-option.is-highlighted {
  background: #dfefff;
}

.filter-dropdown-option.is-selected {
  font-weight: bold;
}

.filter-dropdown-empty {
  color: #666;
  padding: 6px 2px 2px;
}

.dual-range-slider {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

.dual-range-slider-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  border-radius: 999px;
  background: #d9d9d9;
}

.dual-range-slider-fill {
  position: absolute;
  top: 0;
  height: 6px;
  border-radius: 999px;
  background: #4a89dc;
}

.dual-range-slider-input {
  position: absolute;
  left: 0;
  width: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.dual-range-slider-input::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
}

.dual-range-slider-input::-moz-range-track {
  height: 6px;
  background: transparent;
}

.dual-range-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  border: 1px solid #3d6fb7;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  pointer-events: auto;
}

.dual-range-slider-input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #3d6fb7;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  pointer-events: auto;
}

.dual-range-slider[data-disabled="true"] {
  opacity: 0.55;
}

.dual-range-slider[data-disabled="true"] .dual-range-slider-input::-webkit-slider-thumb {
  cursor: not-allowed;
}

.dual-range-slider[data-disabled="true"] .dual-range-slider-input::-moz-range-thumb {
  cursor: not-allowed;
}

/* 左右ボタンのスタイル */
.nav-button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #c8d0d8;
  border-radius: 7px;
  background: #f2f5f8;
  color: #415160;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  line-height: 24px;
  margin-left: 0; /* セレクトボックスと隙間を作らない */
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

/* ボタンのホバー時のスタイル */
.nav-button:hover {
  background: #e7edf3;
}

#selected-labels {
  width: calc(var(--content-width) - 20px); /* 地図の幅に合わせつつ、paddingの影響を排除 */
  margin: 0 auto; /* 中央揃え */
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 10px;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  display: none; /* 初期状態は非表示 */
  white-space: pre-line; /* 改行を有効化 */
  overflow-wrap: break-word;
  border: var(--panel-border);
}

.record-info-wrapper {
  display: flex;
  justify-content: flex-end;
  gap: 1em;
  font-weight: normal;
  font-size: 90%;
  margin-top: 0.3em;
}

.record-info-block {
  white-space: nowrap;
}

/* Shared visual polish for the map summary strip. */
#selected-labels {
  width: var(--content-width);
  margin: 0 auto;
  padding: 9px 12px;
  text-align: left;
  color: var(--text-main);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.55;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 6px 18px rgba(28, 45, 62, 0.09);
  box-sizing: border-box;
}

#selected-labels a {
  color: #245f8d;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

.record-info-wrapper {
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 7px;
  flex-wrap: wrap;
}

.record-info-block {
  padding: 2px 8px;
  border: 1px solid #dce5ed;
  border-radius: 999px;
  background: #f7fafc;
}

/* タブ全体のコンテナ */
.tab-container {
  background: #fff;
  border: var(--panel-border);
  box-sizing: border-box;
}

/* タブの見出し部分 */
.tab-header {
  list-style: none;
  display: flex;
  margin: 0;
  padding: 0;
  white-space: nowrap;
  border-bottom: 2px solid #ccc;
  overflow-x: auto;
}

.tab-header li {
  flex: 1;                    /* 均等に幅を割り当て */
  text-align: center;         /* 見出しの文字を中央揃え */
  padding: 10px;
  cursor: pointer;
  background-color: #f5f5f5;
  border-right: 1px solid #ccc;
  font-weight: bold;
  user-select: none;          /* テキスト選択防止 (お好みで) */
}

.tab-header li:last-child {
  border-right: none;         /* 最後のタブは右枠線を消す */
}

/* アクティブなタブの見た目 */
.tab-header li.active {
  background-color: #e1e1e1;
}

/* タブ切り替えコンテンツの共通スタイル */
.tab-content {
  display: none;  /* 非表示にしておき、active だけ表示 */
  padding: 20px;
  box-sizing: border-box;
}

/* アクティブなタブを表示 */
.tab-content.active {
  display: block;
}

.tab-container {
  overflow: hidden;
  border-radius: 0 0 14px 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(28, 45, 62, 0.08);
}

.tab-header {
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #fdfefe 0%, #eef3f7 100%);
}

.tab-header li {
  padding: 11px 14px;
  color: #33485b;
  background: transparent;
  border-right: 1px solid var(--line-soft);
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.tab-header li:hover {
  background: rgba(56, 111, 158, 0.08);
}

.tab-header li.active {
  color: #102b42;
  background: #ffffff;
  box-shadow: inset 0 -3px 0 var(--accent);
}

.tab-content {
  background: #ffffff;
}

.tab-content.tab-list-panel.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-panel-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-list-heading {
  margin: 0;
}

.download-panel-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  max-width: 720px;
}

.download-note,
.download-summary,
.download-empty-message {
  margin: 0;
  line-height: 1.6;
}

.download-summary strong {
  font-size: 1.05em;
}

.download-empty-message {
  color: #666;
}

#download-filtered-csv-button {
  max-width: 100%;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
}

#download-filtered-csv-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tab-list {
  margin: 0;
  padding-left: 1.5em;
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#prefecture-list,
#island-list {
  line-height: 1.55;
}

#prefecture-list li,
#island-list li {
  padding: 2px 0;
}

.location-map-link-pill {
  margin-left: 10px;
  padding: 1px 8px;
  font-size: 0.82em;
  line-height: 1.35;
  vertical-align: 0.08em;
  white-space: nowrap;
  border-color: #a8b4bf;
  background: #fbfcfd;
  color: #24556f;
}

.location-map-link-pill:hover {
  background: #eef5f9;
  border-color: #7f9caf;
}

.tab-list-plain {
  list-style: none;
  padding-left: 0;
  padding-right: 0.5em;
}

.tab-reference-list li {
  font-size: 13px;
  padding: 3px 0;
}

.tab-reference-list li a {
  overflow-wrap: break-word;
}

#chart-container {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 600px;
  width: 100%;
  min-height: 200px;
  max-height: 400px;
  position: relative;  /* Chart.jsが幅を自動調整できるように */
}

#chart-wrapper {
  display: flex;          /* 横並びにする */
  gap: 10px;              /* グラフとチェックボックスの間隔 */
  justify-content: center;
  align-items: center;    /* 上下方向で中央揃え（任意） */
}

#chart-area {
  position: relative;
  width: 100%;
}

#prefecture-chart-layout {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
}

#prefecture-chart-wrapper {
  flex: 1 1 auto;
  min-width: 0;
}

/* グラフラッパー共通 */
.chart-container-scroll {
  width: 100%;              /* 親要素いっぱいに広げる */
  max-height: var(--chart-frame-max-height);        /* 必要に応じて高さを拡大 (例: 600px) */
  overflow-x: auto;         /* 横スクロールを許可 */
  overflow-y: hidden;       /* 縦スクロールは要らなければ隠す */
  margin: 14px 0;           /* 上下余白 (お好みで) */
  border: var(--panel-border);   /* 視覚的に領域がわかりやすいように (任意) */
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  box-sizing: border-box;
  position: relative;
}

/* グラフホスト */
#month-chart,
#prefecture-chart,
#year-chart {
  width: 100%;
  margin: 0 auto;
}

.chart-svg-host {
  position: relative;
  display: block;
}

.chart-svg-host svg {
  display: block;
}

.chart-svg-host svg text {
  font-family: var(--font-body);
}

#month-chart {
  height: auto;
}

#month-chart.chart-svg-host {
  min-height: 0;
}

#prefecture-chart,
#year-chart {
  height: auto;
}

#prefecture-chart.chart-svg-host,
#year-chart.chart-svg-host {
  min-height: 0;
}

.chart-top-legend {
  display: block;
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid #e0e7ee;
  border-radius: 10px;
  background: #fdfefe;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
}

.chart-side-legend {
  flex: 0 0 clamp(180px, 22vw, 260px);
  max-width: 260px;
  max-height: var(--chart-frame-max-height);
  overflow-y: auto;
  margin: 14px 0;
  padding: 12px;
  border: var(--panel-border);
  border-radius: 12px;
  background: #fdfefe;
  box-sizing: border-box;
}

.chart-side-legend:empty {
  display: none;
}

.chart-legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
}

.chart-side-legend .chart-legend-list {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 8px;
}

.chart-legend-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  column-gap: 8px;
  align-items: start;
  font-size: 13px;
  line-height: 1.35;
  padding: 2px 4px;
  border-radius: 7px;
  transition: background-color 0.15s ease, font-weight 0.15s ease;
}

.chart-legend-item.is-clickable {
  cursor: pointer;
}

.chart-legend-item.is-clickable:hover {
  background: rgba(0, 0, 0, 0.04);
}

.chart-legend-item.is-clickable:focus-visible {
  outline: 2px solid rgba(52, 112, 196, 0.45);
  outline-offset: 1px;
}

.chart-legend-item.is-active {
  background: rgba(255, 214, 10, 0.18);
  font-weight: bold;
}

.chart-legend-item.is-disabled {
  opacity: 0.42;
}

.chart-legend-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
  margin-top: 2px;
}

.chart-legend-swatch-line {
  width: 18px;
  height: 0;
  margin-top: 9px;
  border: none;
  border-top: 3px solid #000;
  background: transparent;
}

.chart-legend-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  color: #666;
  text-align: center;
  box-sizing: border-box;
}

#chart-tooltip {
  position: fixed;
  display: none;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 2000;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}


/* ラジオボタン同士の間隔や配置を制御 */
#classification-radio {
  display: flex;
  justify-content: center;
  gap: 8px 14px;
  margin: 10px auto;
  padding: 9px 12px;
  background: #f9fbfd;
  border: var(--panel-border);
  border-radius: 12px;
  font-size: 14px;
  flex-wrap: wrap;
}

#classification-radio label,
.classification-radio label {
  margin-right: 1em;
  white-space: nowrap;
}

.chart-prefecture-sort-control {
  display: flex;
  align-items: center;
}

.chart-prefecture-sort-control label {
  margin-right: 0;
}

.chart-prefecture-sort-control.is-disabled {
  opacity: 0.55;
}

.chart-prefecture-sort-control.is-disabled label {
  cursor: not-allowed;
}

.chart-prefecture-sort-control input[type="checkbox"] {
  margin-right: 0.35em;
}

.prefecture-chart-bar {
  transition: opacity 0.15s ease, stroke-width 0.15s ease;
}

.prefecture-chart-bar.is-active {
  opacity: 1;
  stroke: #111;
  stroke-width: 2;
}

#touch-hint {
  position: absolute;
  top: 50%;                 /* 地図の中央あたりに表示する例 */
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;            /* 地図より前面に表示 */
  
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 16px;
  text-align: center;
  
  display: none;            /* 初期状態で非表示 */
  pointer-events: none;     /* タップ操作をブロックしない */
}

.external-chart-title {
  text-align: center;   /* 中央揃え */
  font-size: 16px;      /* 適度なサイズ */
  font-weight: bold;    /* 太字 */
  margin: 18px 0 10px;       /* 上下の余白を調整 */
  color: var(--text-main);
  letter-spacing: 0.01em;
}

.chart-divider {
  height: 6px;
  border: 0;  /* 線の太さと色 */
  border-radius: 999px;
  margin: 34px 0 30px;              /* 上下の余白 */
  width: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(184, 201, 215, 0.32) 18%, rgba(139, 167, 188, 0.38) 50%, rgba(184, 201, 215, 0.32) 82%, transparent 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

#month-chart-title {
  position: relative;
  margin-top: 30px;
  padding-top: 30px;
}

#month-chart-title::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent 0%, rgba(184, 201, 215, 0.32) 18%, rgba(139, 167, 188, 0.38) 50%, rgba(184, 201, 215, 0.32) 82%, transparent 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

/* 出版年・採集年グラフ共通ラッパー */
#year-chart-wrapper {
  min-height: 0;
  overflow-y: auto;
}


/* ポップアップ全体のラッパー */
.popup-wrapper {
  display: flex;
  flex-direction: column;
  color: #25384a;
  max-height: unset; /* ← JSで設定する */
}

/* 本文をスクロール可能にする */
.popup-scroll-container {
  overflow-y: auto;
  flex: 1;
  padding: 12px 14px;
  border: 0;
  scrollbar-gutter: stable;
}

/* 前/次ボタンは常に下部に固定（本文の外） */
.popup-nav-fixed {
  display: grid;
  grid-template-columns: minmax(68px, 1fr) auto minmax(68px, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f6f9fc;
  flex-shrink: 0;
  user-select: none;
}

.popup-wrapper--below .popup-nav-fixed {
  padding-right: 38px;
  border-bottom: 1px solid #d8e1ea;
}

.popup-wrapper--above .popup-nav-fixed {
  border-top: 1px solid #d8e1ea;
}

.popup-wrapper--above .popup-scroll-container {
  padding-right: 38px;
}

.popup-nav-button {
  min-width: 68px;
  padding: 5px 12px;
  border: 1px solid #c3ced9;
  border-radius: 999px;
  background: #fff;
  color: #25384a;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(20, 34, 47, 0.08);
}

.popup-nav-button:hover {
  border-color: #8ea4b8;
  background: #eef5fb;
}

.popup-nav-button:focus-visible {
  outline: 2px solid #2f7fb4;
  outline-offset: 2px;
}

.popup-nav-button-prev {
  justify-self: start;
}

.popup-nav-button-next {
  justify-self: end;
}

.popup-nav-counter {
  min-width: 54px;
  padding: 3px 8px;
  border: 1px solid #d8e1ea;
  border-radius: 999px;
  background: #fff;
  color: #586a7a;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
}

.year-filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.year-filter label {
  font-size: 14px;
  cursor: pointer;
}

.slider-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#publication-year-slider,
#collection-year-slider {
  margin: 0 6px; /* スライダー左右余白調整 */
}

.year-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
}

.year-inputs input[type="text"] {
  width: 60px; /* サイズをお好みで */
  font-size: 12px;
  text-align: right; /* 年の桁数が4桁なので右寄せでもよい */
}

.biennial-filter {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
}

.biennial-inputs {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
}

.chart-options-box {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5em;
  align-items: center;
  justify-content: center;
  padding: 0.5em;
  border: var(--panel-border);
  border-radius: 6px;
  margin-bottom: 1em;
}

#graph-view-control {
  justify-content: flex-start;
  margin-bottom: 12px;
}

.graph-view-control-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.chart-control-label {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.graph-view-radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

#graph-view-control {
  align-items: stretch;
  padding: 10px 12px;
  border-color: var(--line-soft);
  border-radius: 12px;
  background: #f9fbfd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.graph-view-control-inner {
  width: 100%;
  gap: 8px 10px;
}

.chart-control-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
}

.chart-control-label::before {
  content: "";
  width: 7px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
}

.chart-control-scope {
  margin-right: auto;
  padding: 2px 8px;
  border: 1px solid #d7e2eb;
  border-radius: 999px;
  background: #fff;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}

.graph-view-radio-group {
  gap: 6px;
}

.graph-view-radio-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 0;
  padding: 4px 9px;
  border: 1px solid #d1dbe4;
  border-radius: 999px;
  background: #fff;
  color: #445668;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.graph-view-radio-group label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #173b58;
  font-weight: 700;
}

#toggle-higher-taxonomy-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin: 0;
  font-weight: normal;
  font-size: 0.95em;
}

#toggle-higher-taxonomy {
  margin: 0;
}

.life-stage-filter {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#life-stage-checkboxes label {
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  margin-right: 12px;
  gap: 4px;
}

.filter-body-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.filter-body-disabled input,
.filter-body-disabled select,
.filter-body-disabled button {
  pointer-events: none;
}

#language-switcher {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  text-align: right;
  margin-bottom: 5px;
  padding-right: 0;
  font-size: 14px;
  color: var(--text-main);
}

#language-switcher label,
#display-mode-switcher label {
  font-weight: bold;
  margin-right: 0;
}

#display-mode-switcher {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  text-align: right;
  margin-bottom: 5px;
  padding-right: 0;
  font-size: 14px;
  color: var(--text-main);
}

#display-mode-switcher[hidden] {
  display: none !important;
}

#language-selector,
#display-mode-selector {
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid #c4d0da;
  background: #fff;
  color: var(--text-main);
  width: 164px;
}

#reset-page-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 5px;
  z-index: 999; /* 必要に応じて他要素より前面に出す */
}

#reset-page-button {
  padding: 5px 10px;
  border: 1px solid #c4d0da;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(28, 45, 62, 0.08);
}

#reset-page-button:hover {
  background: #f3f7fa;
}

@media (max-width: 711px) {
  /* タイトル部分 */
  header {
    width: 100%;
    left: 0;
  }

  /* タイトルのフォントサイズを調整 */
  header h1 {
    font-size: 1.2em; /* 文字サイズを調整 */
  }

  #mapid,
  .tab-container {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  #selected-labels{
    margin-left: 0;
    width: 100%;
    border: var(--panel-border);
    box-sizing: border-box;
  }

  .tab-container {
    margin-top: 10px;
  }

  .search-container,
  .legend {
    margin-left: 0;
    left: 0;
    max-width: 100%;
    width: 100%;
  }

  .search-body {
    gap: 9px;
  }

  .filter-primary-group {
    gap: 7px;
    padding: 9px 8px;
  }

  .select-container {
    gap: 6px;
  }

  .select-container select {
    height: 32px;
    font-size: 14px;
    padding: 4px 6px;
  }

  .filter-dropdown-trigger {
    min-height: 32px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .select-mode-option span {
    min-height: 30px;
  }

  .nav-button {
    width: 32px;
    height: 32px;
    line-height: 30px;
  }

  .legend {
    margin-left: 0;
    left: 0;
    max-width: 100%;
    width: 100%;
  }

  .search-container {
    top: 0;
    box-shadow: none;
    position: relative;
    transition: max-height 0.3s ease-out;
    max-height: none;
    overflow: visible;
  }

  .search-body {
    max-height: none !important;      /* 高さ制限を解除 */
    overflow-y: visible;   /* 縦スクロールを無効化 */
  }

  .legend {
    position: relative;
    bottom: auto;
    right: auto;
    top: 0;
    margin-bottom: 10px;
    padding: 0;
    max-height: none;
    border-radius: 12px 12px 0 0;
    box-shadow: none;
  }

  .legend.collapsed {
    max-height: var(--legend-collapsed-height);
  }

  .legend-color-block {
    margin-top: 8px;
    padding-top: 8px;
  }

  .legend-color-list {
    max-height: min(24vh, 180px);
  }

  .legend-color-item {
    grid-template-columns: 16px minmax(0, 1fr);
    column-gap: 6px;
  }

  .legend-color-label {
    font-size: 12px;
  }

  #prefecture-chart-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  #prefecture-chart-layout .chart-container-scroll {
    margin: 0;
  }

  .chart-side-legend {
    order: -1;
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: 170px;
    margin: 0;
    padding: 8px 10px;
  }

  .chart-side-legend .chart-legend-list {
    gap: 6px;
  }

  .chart-top-legend {
    margin-bottom: 6px;
  }

  .chart-top-legend .chart-legend-list {
    flex-wrap: nowrap;
    justify-content: flex-start;
    width: max-content;
    min-width: 100%;
    padding-bottom: 2px;
  }

  .chart-top-legend .chart-legend-item {
    flex: 0 0 auto;
    font-size: 12px;
    line-height: 1.3;
    padding: 1px 3px;
  }

  .chart-top-legend .chart-legend-label {
    white-space: nowrap;
    overflow-wrap: normal;
  }

  .chart-container-scroll {
    margin: 12px 0;
  }

  .external-chart-title {
    font-size: 15px;
    margin: 8px 0;
  }

  .chart-divider {
    margin: 28px 0;
  }

  .toggle-button {
    right: 10px;
    top:auto;
    bottom: auto;
    transform: rotate(180deg);
    font-size: 18px;
  }
  .toggle-button.rotate {
    transform: rotate(0deg); /* クリック時に元の向きに戻す */
  }

  #mapid {
    height: var(--mobile-map-height);
    width: 100%;
    margin-bottom: 0;
  }

  .maplibregl-popup-content {
    width: min(88vw, 460px);
    min-width: min(280px, calc(100vw - 36px));
  }

  #language-switcher {
    font-size: 12px;
    padding-right: 6px;
  }

  #display-mode-switcher {
    font-size: 12px;
    padding-right: 6px;
  }

  #language-selector,
  #display-mode-selector {
    font-size: 12px;
    padding: 1px 4px;
    width: 136px;
  }

  .current-location-control .current-location-button {
    padding: 0 8px;
    font-size: 11px;
  }
}

/* ==================== Box Selection (Rectangle) ==================== */
.box-select-buttons {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.box-select-buttons button {
  flex: 1 1 0;
  height: 30px;
  border-radius: 5px;
  border: var(--panel-border);
  background-color: #eee;
  cursor: pointer;
}

#box-select-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 28; /* search-container(30)より下 */
  display: none;
  pointer-events: none;
}

#box-select-overlay.active {
  display: block;
  pointer-events: auto;
  cursor: crosshair;
}

#box-select-rect {
  position: absolute;
  border: 2px dashed rgba(0,0,0,0.6);
  background: rgba(0,0,0,0.08);
  display: none;
}

/* スマホ（タッチ）環境では範囲選択ボタン自体を非表示 */
@media (hover: none) and (pointer: coarse) {
  .search-body {
    gap: 10px;
  }

  .filter-primary-group {
    gap: 7px;
    padding: 9px 8px;
  }

  .select-container {
    gap: 6px;
  }

  .filter-dropdown-trigger {
    min-height: 34px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 14px;
  }

  .select-mode-option span {
    min-height: 30px;
  }

  .nav-button {
    width: 32px;
    height: 32px;
    line-height: 30px;
  }

  #reset-button,
  .box-select-buttons button,
  .filter-dropdown-action-button {
    min-height: 36px;
  }

  .map-filter-container,
  #box-select-buttons {
    display: none;
  }
}


.prefecture-polygon-popup {
  font-size: 13px;
  line-height: 1.45;
}
.prefecture-polygon-popup p {
  margin: 4px 0 6px;
}
.prefecture-polygon-popup ul {
  margin: 0;
  padding-left: 1.2em;
  max-height: 180px;
  overflow: auto;
}
.prefecture-polygon-popup .popup-note {
  color: #555;
  margin-top: 6px;
}

/* JSC Cloudflare additions */
#jsc-home-link-wrapper {
  position: absolute;
  top: 16px;
  left: 170px;
  z-index: 20;
}

#jsc-home-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(47, 98, 143, 0.45);
  border-radius: 999px;
  background: #ffffff;
  color: #234f74;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#jsc-home-link:hover,
#jsc-home-link:focus {
  background: #eef5fb;
  outline: none;
}

.choropleth-legend {
  margin: 10px 0 12px;
  padding: 9px 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
}

.choropleth-legend-title {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.choropleth-legend-list {
  display: grid;
  gap: 4px;
}

.choropleth-legend-item {
  display: grid;
  grid-template-columns: 24px auto;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1.3;
}

.choropleth-legend-swatch {
  display: inline-block;
  width: 22px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 3px;
}

@media (max-width: 720px) {
  #jsc-home-link-wrapper {
    position: static;
    margin: 8px 0 0;
    text-align: center;
  }
}
