:root {
  --bg: #ffffff;
  --fg: #1c1b1f;
  --muted: #5f5b66;
  --line: #85818c; /* 検索欄・チップ・セレクト等の枠線として使うため、背景(--panel)との比が3:1以上になる濃さにしてある */
  --panel: #ffffff;
  --panel-2: #f5f3f7;
  --accent: #b3261e;
  --warn-bg: #fff4d6;
  --warn-fg: #4a3500;
  --link: #0b57d0;
  --closed: #c62828;
  --partial: #cc6f00; /* 白文字・白枠との比が3:1以上になるよう #e67e00 から少し濃くしてある */
  --sns: #7b3fb3;
  --unknown: #6b6b6b;
  --lifted: #5b8a72;
  --focus: #0b57d0;
  --handle-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
/* この配色は :root[data-theme="dark"]（下のブロック）と同じ値に保つこと（OS設定によるダークと、
   アプリの明示指定によるダークを両方サポートしているため、値は2箇所ある） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141316; --fg: #eceaf0; --muted: #b3aebb; --line: #75717d;
    --panel: #1d1b20; --panel-2: #26232a; --warn-bg: #3b2f0d; --warn-fg: #ffe7a3;
    --link: #8ab4f8; --focus: #8ab4f8; color-scheme: dark;
  }
}
/* 上の @media (prefers-color-scheme: dark) ブロックと同じ値に保つこと */
:root[data-theme="dark"] {
  --bg: #141316; --fg: #eceaf0; --muted: #b3aebb; --line: #75717d;
  --panel: #1d1b20; --panel-2: #26232a; --warn-bg: #3b2f0d; --warn-fg: #ffe7a3;
  --link: #8ab4f8; --focus: #8ab4f8; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 100%; /* 端末・ブラウザの文字サイズ設定に従う（既定16px） */
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
a { color: var(--link); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; z-index: 3000; background: var(--panel); padding: 8px 12px; }

/* ヘッダー */
.bar {
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 4px 8px 4px 16px;
  background: var(--accent); color: #fff;
  flex: none;
}
.bar__title { margin: 0; font-size: 1.05rem; line-height: 1.3; flex: 1; min-width: 0; }
.bar__sub { display: block; font-size: 0.75rem; font-weight: normal; opacity: .9; }
.iconbtn {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.8); background: transparent; color: #fff;
  font: 700 1.1rem/1 Georgia, serif; cursor: pointer;
}

/* 常設の警告 */
.warn {
  margin: 0; padding: 6px 16px; flex: none;
  background: var(--warn-bg); color: var(--warn-fg);
  font-size: 0.875rem; line-height: 1.5;
  border-bottom: 1px solid var(--line);
}
.warn a { color: inherit; font-weight: 700; }
.warn__asof { display: block; font-size: 0.8125rem; opacity: .9; }
.warn__short, .warn--panel { display: none; }
/* 文字が大きい・画面が低いとき：注意の全文はシートの先頭へ移し、上部は1行にする（消さずに置き場所を変える） */
body.is-compact .warn__full, body.is-compact .bar__sub { display: none; }
body.is-compact .warn__short { display: inline; }
body.is-compact .warn--panel { display: block; margin: 0 -16px 8px; }
body.is-compact .warn { padding-top: 2px; padding-bottom: 2px; }

/* レイアウト（スマホ：地図が全面、一覧は下からのシート） */
.layout { position: relative; flex: 1; min-height: 0; }
.mapwrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0 0 calc(var(--handle-h) + var(--safe-b)) 0; background: #e8e6e3; }

.panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1200; /* Leaflet のコントロール(1000)より上 */
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 16px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
  max-height: calc(var(--handle-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
}
.panel.is-open { max-height: calc(100% - 56px); } /* 見出し＋本体が必ず収まり、上に地図が少し見える */
.panel__handle {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 8px;
  min-height: 56px; width: 100%; /* 実高さは JS が --handle-h に反映する */
  padding: 8px 16px; border: 0; background: transparent; color: var(--fg);
  font: inherit; text-align: left; cursor: pointer;
  position: relative;
}
.panel__handle::before {
  content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
  border-radius: 2px; background: var(--line);
}
.panel__count { font-weight: 700; min-width: 0; flex: 1 1 9em; }
.panel__detail { display: block; font-weight: normal; font-size: 0.8125rem; color: var(--muted); }
.panel__hint { flex: none; color: var(--link); font-size: 0.9375rem; }
.panel__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 16px; display: none; }
.panel.is-open .panel__body { display: block; }

/* 絞り込み */
.filters { display: grid; gap: 8px; padding: 4px 0 12px; border-bottom: 1px solid var(--line); }
.search input {
  width: 100%; min-height: 44px; padding: 8px 12px;
  font-size: max(16px, 1rem); border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); color: var(--fg);
}
.more > summary {
  display: flex; align-items: center; min-height: 44px; cursor: pointer; color: var(--link); font-size: 0.9375rem;
  list-style: none;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "▸"; margin-right: 6px; }
.more[open] > summary::before { content: "▾"; }
.more[open] { display: grid; gap: 8px; }
.chips { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2);
  font-size: 0.9375rem;
}
.chip input:checked + span { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip input:checked + span::before { content: "✓ "; }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.selects { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; }
.selects select {
  width: 100%; min-height: 44px; font-size: max(16px, 1rem); padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--fg);
}
.inview { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 0.9375rem; }
.inview input { width: 22px; height: 22px; }

/* 一覧 */
.list { list-style: none; margin: 0; padding: 0; }
.list__group { margin: 12px 0 4px; font-size: 0.875rem; color: var(--muted); font-weight: 700; }
.item {
  display: grid; grid-template-columns: 28px minmax(0,1fr); gap: 10px; align-items: start;
  width: 100%; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--fg); font: inherit; text-align: left; cursor: pointer;
}
.item:hover { background: var(--panel-2); }
.item__road { display: block; font-weight: 700; overflow-wrap: anywhere; }
.stale { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-fg); font-size: 0.75rem; }
.emergency, .about__emergency { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-fg); font-size: 0.9375rem; }
.emergency a, .about__emergency a { color: inherit; font-weight: 700; }
.item__meta { display: block; font-size: 0.875rem; color: var(--muted); overflow-wrap: anywhere; }
.item .mk { margin-top: 2px; }
.list__empty { padding: 16px 0; color: var(--muted); }

.scope { margin: 12px 0 0; font-size: 0.875rem; color: var(--muted); }
.official { margin-top: 16px; padding-top: 8px; border-top: 1px solid var(--line); }
.official h2 { font-size: 1rem; margin: 8px 0; }
.official ul { margin: 0; padding-left: 1.2em; }
.official li { margin: 6px 0; overflow-wrap: anywhere; }

/* 地図上のボタン */
.fab {
  position: absolute; right: 12px; bottom: calc(var(--handle-h) + var(--safe-b) + 16px); z-index: 900;
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); box-shadow: 0 2px 8px rgba(0,0,0,.25);
  display: grid; place-items: center; cursor: pointer;
}
.legend-btn {
  position: absolute; right: 12px; top: 12px; z-index: 900;
  min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font: inherit; font-size: 0.9375rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer;
}
.legend {
  position: absolute; right: 12px; top: 64px; z-index: 1001; max-width: min(320px, calc(100% - 24px));
  max-height: calc(100% - 76px); overflow-y: auto;
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; box-shadow: 0 2px 12px rgba(0,0,0,.25); font-size: 0.875rem;
}
.legend ul { list-style: none; margin: 0; padding: 0; }
.ln { flex: none; display: inline-block; width: 24px; height: 5px; border-radius: 2px; background: var(--closed); }
.legend li { display: flex; align-items: center; gap: 8px; margin: 6px 0; }

/* マーカー（色だけに頼らず、記号でも区別する） */
.mk {
  --c: var(--closed);
  flex: none; position: relative; display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--c); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5);
  color: #fff; font: 700 14px/1 sans-serif;
}
.mk--closed::after { content: ""; width: 12px; height: 3px; background: #fff; border-radius: 1px; }
.mk--partial { --c: var(--partial); border-radius: 4px; transform: rotate(45deg); width: 21px; height: 21px; }
.mk--partial::after { content: "!"; transform: rotate(-45deg); }
.mk--sns { --c: #fff; color: var(--sns); border: 3px dashed var(--sns); }
.mk--sns::after { content: "?"; }
.mk--unknown { --c: var(--unknown); }
.mk--unknown::after { content: "?"; }
.mk--lifted { --c: var(--lifted); }
.mk--lifted::after { content: "✓"; font-size: 13px; }
.mk--approx { outline: 2px dashed var(--c); outline-offset: 4px; }
.mk--sns.mk--approx { outline-color: var(--sns); }
.mk-icon { display: grid; place-items: center; }
.mk--selected { box-shadow: 0 0 0 4px rgba(11,87,208,.55), 0 1px 3px rgba(0,0,0,.5); }

/* ポップアップ */
.leaflet-popup-content { margin: 12px 14px; font-size: 0.9375rem; line-height: 1.55; }
.pop p { margin: 6px 0; }
.pop .pop__foot { margin: 8px 0 0; }
.pop .pop__alert { margin: 6px 0; }
.pop__src--sns a { color: var(--sns); }
.pop { max-width: 300px; }
.pop h3 { margin: 0 0 4px; font-size: 1.05rem; line-height: 1.35; overflow-wrap: anywhere; }
.pop__badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8125rem; border: 1px solid currentColor; }
.badge--closed { color: var(--closed); }
.badge--partial { color: #a35a00; }
.badge--sns { color: var(--sns); }
.badge--lifted { color: #3f6b55; }
.badge--muted { color: var(--muted); }
.pop dl { margin: 6px 0; display: grid; grid-template-columns: auto minmax(0,1fr); gap: 2px 8px; }
.pop dt { color: var(--muted); font-size: 0.8125rem; white-space: nowrap; }
.pop dd { margin: 0; overflow-wrap: anywhere; }
.pop__alert { margin: 6px 0; padding: 6px 8px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 0.875rem; }
.pop__src { margin: 6px 0 0; padding-left: 1.1em; font-size: 0.875rem; }
.pop__src li { margin: 2px 0; overflow-wrap: anywhere; }
.pop__foot { margin: 8px 0 0; font-size: 0.8125rem; color: var(--muted); }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--fg); }
.leaflet-container a.leaflet-popup-close-button { width: 44px; height: 44px; font-size: 26px; line-height: 44px; }
.leaflet-popup-content-wrapper { padding-right: 16px; }
.leaflet-control-layers label { min-height: 44px; display: flex; align-items: center; }
.leaflet-bar a { width: 44px !important; height: 44px !important; line-height: 44px !important; font-size: 22px !important; }
.leaflet-control-layers-toggle { width: 44px !important; height: 44px !important; }
.user-loc { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }

/* クラスタ */
.mk-icon, .cl { width: 44px; height: 44px; }
.cl { display: grid; place-items: center; border-radius: 50%; box-sizing: border-box; background: rgba(40,40,48,.88); color: #fff; font: 700 14px/1 sans-serif; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.cl--closed { background: rgba(198,40,40,.92); }

/* 通知 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--handle-h) + var(--safe-b) + 76px); z-index: 4000;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #222; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 0.9375rem;
  opacity: 0; pointer-events: none;
}
.toast.is-on { opacity: 1; }

/* 同意ゲート */
.gate {
  position: fixed; inset: 0; z-index: 5000;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center; padding: 16px;
  overflow-y: auto;
}
.gate[hidden] { display: none; }
.gate__box, .about__box {
  width: 100%; max-width: 560px; max-height: 100%; overflow-y: auto;
  background: var(--panel); color: var(--fg); border-radius: 16px; padding: 20px 18px;
}
.gate__box h2, .about__box h2 { margin: 0 0 8px; font-size: 1.15rem; line-height: 1.4; }
.gate__list { margin: 0 0 8px; padding-left: 1.2em; }
.gate__list li { margin: 6px 0; }
.gate__terms { margin: 8px 0; }
.gate__terms a { display: inline-flex; align-items: center; min-height: 44px; }
/* 見出しへのプログラム的フォーカス（app.js: $('gate-h').focus()）を隠さない。
   グローバルな :focus-visible がここにも適用される（WCAG 2.4.7 Focus Visible） */
.gate__agree {
  display: flex; gap: 10px; align-items: flex-start; margin: 12px 0;
  padding: 10px 12px; border: 2px solid var(--accent); border-radius: 10px; cursor: pointer;
}
.gate__agree input { width: 24px; height: 24px; flex: none; margin: 2px 0 0; }
.gate__alt { font-size: 0.875rem; color: var(--muted); margin: 10px 0 0; }
.btn {
  display: block; width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--fg); font: inherit; font-weight: 700; cursor: pointer;
}
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.about { border: 0; padding: 0; background: transparent; max-width: calc(100% - 32px); max-height: calc(100% - 32px); }
.about::backdrop { background: rgba(0,0,0,.55); }
.about h3 { font-size: 1rem; margin: 14px 0 4px; }
.about ul { padding-left: 1.2em; margin: 4px 0; }
.about form { margin-top: 16px; }

.noscript { position: fixed; inset: auto 0 0 0; z-index: 6000; background: var(--warn-bg); color: var(--warn-fg); padding: 16px; }

/* PC：左に一覧、右に地図 */

@media (max-width: 899px) {
  .panel.is-open + .mapwrap .fab { visibility: hidden; } /* シートを開いている間は地図のボタンを隠す（スマホのみ） */
}

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 400px minmax(0,1fr); }
  .panel {
    position: relative; inset: auto; max-height: none; border-radius: 0; box-shadow: none;
    border-top: 0; border-right: 1px solid var(--line); padding-bottom: 0; min-height: 0;
  }
  .panel__handle { cursor: default; }
  .panel__handle::before, .panel__hint { display: none; }
  .panel__body { display: block; flex: 1; }
  .mapwrap { position: relative; }
  #map { inset: 0; }
  .fab { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
