/* 江東区の公共施設　俯瞰と主観（画面仕様 v0.2）
 * 色はすべて :root の変数にまとめる。明るい配色だけ。 */

:root {
  color-scheme: light;

  /* 文字・面・線 */
  --bg: #ffffff;
  --ink: #1f2933;
  --ink-2: #4a5663;
  --ink-3: #616e7c;
  --line: #dde1e5;
  --line-soft: #eef0f1;
  --line-strong: #c3cad1;
  --panel-bg: #ffffff;
  --chip-bg: #f3f4f2;
  --hover-bg: #f1f3f4;
  --hover-bg-soft: #f4f5f4;
  --on-ink: #ffffff;               /* 濃い面の上の文字 */
  --halo: #ffffff;                 /* 文字の縁取り */
  --overlay-bg: rgba(255, 255, 255, 0.94);

  /* 地図 */
  --map-bg: #ffffff;
  --land-neighbor: #f3f3f0;
  --land-neighbor-line: #e7e7e3;
  --land-block: #e3e3df;
  --land-block-hover: #cfcfc9;
  --block-line: #ffffff;
  --label-ink: #8d8d86;
  --place-ink: #3b4550;            /* 江東区の地名（町名・町丁目名）。明るい灰色の面の上でも読める濃い灰色 */

  /* 施設の点・棒（緑）＝データ */
  --green: #2f9e5b;
  --green-edge: #14452a;
  --green-text: #1b6b3c;
  --green-soft: #e4f3ea;           /* 選ばれているボタンの地 */
  /* 歩いて届く道（青）＝選んだ地点の側。施設の点（緑）と色相を分ける。
     地点の印と直線距離の円（--marker、紺）と同じ青系にそろえる */
  --road: #2f6db5;
  --bar-off: #d5d9dd;              /* 外した大区分の横棒 */

  /* 区内全体との比較の面：「ここ」より少ない側（濃い）／同じ値（中間）／多い側（薄い） */
  --area-below: #1b6b3c;
  --area-equal: #62b784;
  --area-above: #cfe6d9;

  /* 選んだ地点と直線距離の円 */
  --marker: #1d3557;

  --focus: #1d4ed8;

  /* 注意・エラー */
  --warn-line: #c9a227;
  --warn-bg: #fff8e1;
  --error: #9b1c1c;

  /* ツールチップ */
  --tooltip-bg: rgba(31, 41, 51, 0.95);
  --tooltip-ink: #ffffff;

  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:disabled { cursor: default; opacity: 0.45; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a { color: var(--green-text); }

/* ---------- 上段 ---------- */

.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}

.top h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.switch {
  display: inline-flex;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.switch button {
  appearance: none;
  border: 0;
  background: var(--bg);
  padding: 6px 20px 6px 22px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

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

.switch button:focus-visible { outline-offset: -4px; outline-color: var(--focus); }
.switch button[aria-pressed="true"]:focus-visible { outline-color: var(--on-ink); }

kbd {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  min-width: 22px;
  padding: 0 6px;
  border: 1px solid currentColor;
  border-radius: 5px;
  line-height: 20px;
  text-align: center;
  opacity: 0.75;
}

.question {
  margin: 0;
  flex: 1 1 320px;
  font-size: 20px;
  line-height: 1.4;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
}
/* 問いの言いかえ（主観視点：「私にとってどんな意味があるか」）。問いより一段小さく添える */
.question .gloss { font-size: 16px; color: var(--ink-2); }
.question .gloss[hidden] { display: none; }

.question .who {
  flex: 0 0 auto;
  font-size: 16px;
  font-weight: 700;
  padding: 1px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
}

/* ---------- 本体 ---------- */

.stage {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(360px, 1fr);
}

/* 左の列：操作の帯 → 地図 → 出典 */
.map-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 主観視点の操作の帯（地図の上端。地図には重ねず、地図の領域を帯の分だけ下げる） ---------- */

.subj-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}
.bar-label { flex: 0 0 auto; font-weight: 700; color: var(--ink-2); }
.bar-hint { color: var(--ink-3); font-size: 16px; }

.presets, .minutes { display: flex; flex-wrap: wrap; gap: 6px; }
.presets { flex: 1 1 0; min-width: 0; }

.subj-bar button {
  appearance: none;
  background: var(--bg);
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 2px 12px;
  min-height: 36px;
  font-size: 16px;
  white-space: nowrap;
}
.subj-bar button:hover { background: var(--hover-bg); }
.subj-bar button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
  font-weight: 700;
}
.minutes button { min-width: 3.6em; font-weight: 700; }

/* 町丁目のドロップダウン（用意した地点のボタンの後ろ。文字は 16px 以上） */
.subj-bar select {
  flex: 0 0 auto;
  background: var(--bg);
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 2px 8px;
  min-height: 36px;
  max-width: 100%;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.subj-bar select:hover { background: var(--hover-bg); }
.subj-bar select.is-chosen { border-color: var(--ink); border-width: 2px; font-weight: 700; }

/* ---------- 地図 ---------- */

.map {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  background: var(--map-bg);
  overflow: hidden;
}

#map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#map-svg:active { cursor: grabbing; }

#map-svg path,
#map-svg circle {
  vector-effect: non-scaling-stroke;
}

.neighbor {
  fill: var(--land-neighbor);
  stroke: var(--land-neighbor-line);
  stroke-width: 1;
  pointer-events: none;
}

.neighbor-label {
  fill: var(--label-ink);
  font-weight: 500;
  text-anchor: middle;
  stroke: var(--halo);
  stroke-width: 3px;
  paint-order: stroke;
  stroke-linejoin: round;
  pointer-events: none;
}

/* 江東区の地名：画面上で 14px。font-size と stroke-width は、拡大しても画面上の大きさが変わらないよう app.js が 1/k 倍の値を属性で設定する（CSS には書かない）。クリックやカーソルを妨げない */
.place-label {
  fill: var(--place-ink);
  font-weight: 500;
  font-family: var(--font);
  text-anchor: middle;
  dominant-baseline: central;
  stroke: var(--halo);
  paint-order: stroke;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
#layer-places { pointer-events: none; }
.place-measure { visibility: hidden; }

.chome {
  fill: var(--land-block);
  stroke: var(--block-line);
  stroke-width: 0.8;
}
.chome.is-hover { fill: var(--land-block-hover); }

.facility {
  fill: var(--green);
  fill-opacity: 0.92;
  stroke: var(--green-edge);
  stroke-width: 1;
  cursor: pointer;
}
.facility.is-hover { stroke-width: 2.5; }
/* 主観視点で地点を選ぶ前：全施設を薄く */
.facility.is-dim { fill-opacity: 0.3; stroke-opacity: 0.35; }

/* 主観視点：歩いて届く道、直線距離の円、点（道は投影しても見えるよう、幅 1.6px 以上・青・不透明度 0.8 以上） */
.walk-roads {
  fill: none;
  stroke: var(--road);
  stroke-width: 1.8;
  stroke-opacity: 0.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.subj-circle {
  fill: none;
  stroke: var(--marker);
  stroke-width: 2.2;
  stroke-dasharray: 9 6;
  pointer-events: none;
}
.subj-dot {
  fill: var(--green);
  stroke: var(--green-edge);
  stroke-width: 1.2;
  cursor: pointer;
}
.subj-hollow .subj-dot {
  fill: var(--bg);
  stroke: var(--green-text);
  stroke-width: 2;
}
.subj-dot.is-hover { stroke-width: 3; }

.marker-ring {
  fill: var(--bg);
  fill-opacity: 0.9;
  stroke: var(--marker);
  stroke-width: 3px;
  vector-effect: none;
}
.marker-dot { fill: var(--marker); }
.marker-label {
  fill: var(--marker);
  font-size: 17px;
  font-weight: 700;
  stroke: var(--halo);
  stroke-width: 4px;
  paint-order: stroke;
  stroke-linejoin: round;
  font-family: var(--font);
}
#layer-marker { pointer-events: none; }

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 300px;
  padding: 6px 10px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.45;
  pointer-events: none;
}
.tooltip strong { font-weight: 700; }
.tooltip .t-sub { display: block; opacity: 0.9; font-size: 14px; white-space: pre-line; }

.zoom-ctl {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-ctl button {
  appearance: none;
  min-width: 44px;
  height: 40px;
  padding: 0 8px;
  background: var(--overlay-bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.zoom-ctl #zoom-reset, .zoom-ctl #labels-toggle { font-size: 16px; }
.zoom-ctl button:hover:not(:disabled) { background: var(--hover-bg); }
/* 「地名」：表示しているときは濃い色（aria-pressed = true） */
.zoom-ctl button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
}
.zoom-ctl button[aria-pressed="true"]:hover { background: var(--ink-2); }

/* 主観視点で地点がまだ選ばれていないとき、地図の中央に出す案内 */
.map-guide {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 100px);
  text-wrap: balance;
  margin: 0;
  padding: 12px 22px;
  background: var(--overlay-bg);
  border: 2px solid var(--marker);
  border-radius: 12px;
  color: var(--marker);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

.map-status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--ink-2);
  font-size: 18px;
}
.map-status.is-error { color: var(--error); font-weight: 700; }
.map-status:empty { display: none; }

/* ---------- 出典（地図の下の行。常に表示し、折りたたまない） ---------- */

.source {
  flex: 0 0 auto;
  padding: 6px 14px 8px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
}
.source ul { margin: 0; padding: 0; list-style: none; }
.source li { display: inline; }
.source li + li::before { content: "／"; margin: 0 0.35em; color: var(--ink-3); }

/* ---------- パネル ---------- */

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
  padding: 0 24px;
}

.sec {
  flex: 0 0 auto;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.sec-headline { border-top: 0; padding: 12px 0 10px; }

.panel h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.04em;
}

/* 見出しの数字（俯瞰・主観で同じ位置・同じ大きさ） */
.lead {
  margin: 0;
  min-height: 1.3em;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}
.headline {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  line-height: 1.05;
}
.headline .num { font-size: 64px; font-weight: 700; letter-spacing: -0.01em; }
.headline .unit { font-size: 26px; font-weight: 700; }

.sub, .note {
  margin: 4px 0 0;
  color: var(--ink-3);
  font-size: 16px;
}
.sub:empty { display: none; }
.note { margin: 0; color: var(--ink-2); }

.subj-message { margin: 0; font-size: 16px; color: var(--ink-2); }
.subj-message.is-warn {
  padding: 10px 12px;
  border: 1.5px solid var(--warn-line);
  background: var(--warn-bg);
  color: var(--ink);
  font-weight: 700;
}
.subj-message.is-error { color: var(--error); font-weight: 700; }
#headline-msg { font-size: 20px; font-weight: 700; line-height: 1.4; color: var(--ink); }
#headline-msg.is-warn { font-size: 18px; }

/* ---------- 絞り込み ---------- */

.filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.filter-all { display: flex; gap: 8px; }
.filter-all button,
.basis button {
  appearance: none;
  background: var(--bg);
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 2px 12px;
  min-height: 36px;
  font-size: 16px;
}
.filter-all button:hover,
.basis button:hover { background: var(--hover-bg); }

.filter-list { list-style: none; margin: 0; padding: 0; }

.cat {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 18px 6.2em minmax(0, 1fr) 3em;
  align-items: center;
  gap: 8px;
  padding: 2px 6px;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 16px;
}
.cat:hover { background: var(--hover-bg-soft); }

.cat .swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--green-edge);
  background: var(--bg);
}
.cat[aria-pressed="true"] .swatch { background: var(--green); }

.cat .name { white-space: nowrap; }
.cat .track { height: 10px; display: block; }
.cat .bar {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--green);
}
.cat .count { text-align: right; font-weight: 700; }

.cat[aria-pressed="false"] { color: var(--ink-3); }
.cat[aria-pressed="false"] .swatch { border-color: var(--line-strong); }
.cat[aria-pressed="false"] .bar { background: var(--bar-off); }
.cat[aria-pressed="false"] .count { font-weight: 500; }

/* 主観視点：件数つきの小さなボタンを折り返して並べる（3〜4行） */
body[data-view="subjective"] .filter-list { display: flex; flex-wrap: wrap; gap: 5px 6px; }
body[data-view="subjective"] .cat {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 1px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg);
  white-space: nowrap;
}
body[data-view="subjective"] .cat:hover { background: var(--hover-bg); }
body[data-view="subjective"] .cat .track { display: none; }
body[data-view="subjective"] .cat .swatch { display: none; }
body[data-view="subjective"] .cat[aria-pressed="true"] {
  background: var(--green-soft);
  border-color: var(--green-text);
  color: var(--ink);
}
body[data-view="subjective"] .cat[aria-pressed="false"] { color: var(--ink-3); }
/* その地点から届く施設が 0 件の大区分：破線の枠で控えめにする（押して選択を切り替えることはできる） */
body[data-view="subjective"] .cat.is-zero {
  border-style: dashed;
  background: var(--bg);
  color: var(--ink-3);
}
/* 件数が何の数かの添え書き（主観視点） */
.sec-filter .h-note { margin-left: 4px; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }

/* ---------- 主観視点のパネル ---------- */

/* 円との比較 */
.circle-line { margin: 0; font-size: 18px; line-height: 1.5; }
.circle-line strong { font-size: 22px; }
.legend { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 16px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.key { display: inline-block; flex: 0 0 auto; vertical-align: -2px; }
.key-reached, .key-hollow {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--green-edge);
  background: var(--green);
}
.key-hollow { background: var(--bg); border-color: var(--green-text); }
.key-circle { width: 22px; height: 0; border-top: 2.5px dashed var(--marker); }
.key-road { width: 22px; height: 0; border-top: 3px solid var(--road); }

/* 区内全体との比較 */
.compare-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.basis { display: flex; align-items: center; gap: 6px; }
.basis-label { font-size: 16px; color: var(--ink-3); margin-right: 2px; }
.basis button { min-width: 4em; padding: 0 10px; min-height: 34px; font-weight: 700; }
.basis button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
}
.compare-wait, .compare-empty { padding: 6px 0 2px; }
.compare-sentence { margin: 4px 0 0; font-size: 17px; line-height: 1.45; text-wrap: balance; }
.compare-sentence .nb { white-space: nowrap; }
.compare-sentence strong { font-size: 20px; padding: 0 1px; }
.sw {
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 5px;
  vertical-align: -1px;
  border-radius: 3px;
}
.sw-below { background: var(--area-below); }
.sw-equal { background: var(--area-equal); }
.compare-chart { margin-top: 2px; }
.compare-svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); font-variant-numeric: tabular-nums; }
.compare-svg text { font-size: 15px; fill: var(--ink-2); }
.compare-svg .ax-title { font-size: 15px; fill: var(--ink-3); }
.compare-svg .ax-grid line { stroke: var(--line); stroke-width: 1; }
.compare-svg .ax-tick line, .compare-svg .ax-base { stroke: var(--ink-3); stroke-width: 1; }
.compare-svg .area-below { fill: var(--area-below); }
.compare-svg .area-equal { fill: var(--area-equal); }
.compare-svg .area-above { fill: var(--area-above); }
.compare-svg .here-line { stroke: var(--marker); stroke-width: 2.5; }
.compare-svg .here-label {
  fill: var(--marker); font-size: 16px; font-weight: 700;
  stroke: var(--halo); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round;
}

/* 届く施設の一覧：パネルの残りの高さの中でスクロール */
.sec-list {
  flex: 1 1 0;
  min-height: 7.5em;
  display: flex;
  flex-direction: column;
}
.sec-list h2 { margin-bottom: 6px; flex: 0 0 auto; }
.sec-list .h-note { margin-left: 6px; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.reach-list {
  flex: 1 1 0;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.reach-list li {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr);
  gap: 8px;
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1.45;
}
.reach-list li + li { border-top: 1px solid var(--line-soft); }
.rl-min { font-weight: 700; text-align: right; color: var(--green-text); }
.rl-name { overflow-wrap: anywhere; }

/* ---------- 狭い画面（幅 800px 未満）：縦に積む ----------
 * 上から 上段 → 操作の帯 → 地図（画面の高さの約 40%）→ 出典 → パネル。ページ全体がスクロールする */

@media (max-width: 799px) {
  html, body { height: auto; min-height: 100%; }
  body { display: block; overflow: visible; }

  .top { padding: 8px 14px; gap: 6px 12px; }
  .top h1 { font-size: 20px; flex: 1 1 100%; }
  .switch { flex: 1 1 auto; }
  .switch button { flex: 1 1 0; justify-content: center; padding: 4px 12px; font-size: 17px; }
  kbd { display: none; }
  .question { flex: 1 1 100%; font-size: 16px; gap: 8px; }

  .stage { display: block; }
  .map-col { display: block; }
  .map { height: 40vh; min-height: 260px; }
  .subj-bar { padding: 6px 14px; gap: 4px; }
  .bar-row { gap: 4px 8px; }
  .presets { gap: 5px; }
  .subj-bar button { padding: 2px 8px; min-height: 36px; }
  .zoom-ctl { left: 8px; top: 8px; gap: 4px; }
  .zoom-ctl button { min-width: 40px; height: 36px; }
  .map-guide { font-size: 18px; padding: 10px 16px; max-width: calc(100% - 70px); }
  .source { padding: 6px 14px 8px; }

  .panel { display: block; overflow: visible; border-left: 0; border-top: 1px solid var(--line); padding: 0 14px 24px; }
  .headline .num { font-size: 52px; }
  .headline .unit { font-size: 22px; }
  .lead { font-size: 18px; }
  .circle-line { font-size: 17px; }
  .compare-sentence { font-size: 17px; }
  .compare-sentence strong { font-size: 21px; }
  .cat { min-height: 40px; grid-template-columns: 18px 5.8em minmax(0, 1fr) 2.6em; gap: 6px; }
  .sec-list { display: block; min-height: 0; }
  .reach-list { overflow: visible; }
}

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