:root {
  --bg: #ffffff;
  --fg: #1f2933;
  --muted: #5f6b7a;
  --line: #d5dae1;
  --panel: rgba(255, 255, 255, 0.96);
  --accent: #0b5cad;
  --accent-fg: #ffffff;
  --bad: #c62828;
  --burn: #b8322a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font-num: "Space Mono", ui-monospace, monospace; /* 年・数字（ポートフォリオの本文書体） */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191e;
    --fg: #e6e9ed;
    --muted: #9aa5b1;
    --line: #3a424c;
    --panel: rgba(28, 33, 39, 0.96);
    --accent: #5aa2ec;
    --accent-fg: #0b1620;
    --burn: #e0645a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
button, input, label.btn { font: inherit; }
[hidden] { display: none !important; }

/* ---------- 地図 ---------- */
#mapwrap { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-top-right { top: calc(var(--safe-t) + 112px); }

/* 出典は地図の右下に小さく出す。スマホでは下部パネルのすぐ上（--sheet-h は app.js が設定） */
.credit {
  position: fixed; right: 0; bottom: var(--sheet-h, 0px); z-index: 5;
  max-width: 100%;
  padding: 1px 6px;
  font-size: 10px; line-height: 1.4; text-align: right;
  color: #333;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 4px 0 0 0;
}
body.georef .credit { position: absolute; bottom: 0; }
@media (min-width: 720px) {
  .credit { bottom: 0; }
}
.credit a { color: #0b4f94; }
.credit-info {
  border: 0; padding: 0; background: none; font: inherit;
  color: #0b4f94; text-decoration: underline; cursor: pointer;
}

/* ---------- 上部バー ---------- */
#topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  padding: calc(var(--safe-t) + 8px) 10px 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
.views, .timebar {
  width: min(100%, 420px); pointer-events: auto;
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow);
}
/* 主役：1945年の焼失区域。赤は古地図の焼失区域に合わせた色 */
.views { width: auto; padding: 3px; }
.main-view {
  min-height: 34px; padding: 0 18px; border-radius: 7px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  font-family: inherit; font-size: 13px; font-weight: 500; letter-spacing: 0.08em;
}
.main-view b { font-family: var(--font-num); font-size: 14px; font-weight: 700; letter-spacing: 0.04em; }
/* 選んでいるときは赤い文字と枠。空撮を選んでいる間は白黒（地の文字色） */
.main-view[aria-pressed="true"] { border-color: var(--burn); color: var(--burn); }

/* 空撮の年代：左端の欄。閉じているときは縦書きのつまみだけ */
.drawer {
  position: absolute; left: 0; top: calc(var(--safe-t) + 118px); z-index: 3;
  display: flex; align-items: flex-start;
}
.drawer-tab {
  order: 2; writing-mode: vertical-rl; letter-spacing: 0.2em;
  border: 0; background: var(--panel); color: var(--fg); box-shadow: var(--shadow);
  border-radius: 0 8px 8px 0; padding: 12px 7px; min-width: 32px; cursor: pointer;
  font-size: 14px; font-weight: 600;
}
.drawer-chev { display: inline-block; margin-top: 6px; writing-mode: horizontal-tb; transition: transform 0.2s; }
.drawer:not(.collapsed) .drawer-chev { transform: rotate(180deg); }
.drawer-body {
  order: 1; display: flex; flex-direction: column; gap: 2px; padding: 4px;
  background: var(--panel); box-shadow: var(--shadow); border-radius: 0 0 8px 0;
}
.drawer.collapsed .drawer-body { display: none; }
.drawer-body button {
  display: flex; flex-direction: column; align-items: flex-start;
  border: 0; background: transparent; color: var(--fg); text-align: left;
  padding: 6px 12px; min-height: 44px; border-radius: 8px; cursor: pointer;
  font-size: 14px; line-height: 1.3; white-space: nowrap;
}
.drawer-body button b { font-family: var(--font-num); font-weight: 700; font-size: 13px; }
.drawer-body button small { font-size: 11px; color: var(--muted); }
.drawer-body button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.drawer-body button[aria-pressed="true"] small { color: inherit; }
body.georef .drawer { display: none; }

/* 今↔過去のバー */
.timebar {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 14px; min-height: 40px;
  font-size: 14px; font-weight: 600;
}
.timebar input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
#pastLabel { font-family: var(--font-num); font-size: 13px; min-width: 3.2em; text-align: right; }
/* 「今」の下地の切り替え（地図／2019年の写真） */
.now-switch { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.now-switch button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 500; padding: 5px 8px; min-height: 30px;
}
.now-switch button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }

/* ---------- 下部パネル ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--panel);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.15);
  border-radius: 14px 14px 0 0;
  padding-bottom: calc(var(--safe-b) + 18px);
  max-height: 60vh; overflow-y: auto;
}
#sheet { padding-bottom: calc(var(--safe-b) + 22px); }
@media (min-width: 720px) {
  .sheet { left: 12px; right: auto; bottom: 28px; width: 400px; border-radius: 14px; padding-bottom: 8px; }
  #sheet { padding-bottom: 8px; }
}
.sheet-head { display: flex; align-items: center; padding: 6px 8px 0 0; }
.sheet-handle {
  display: flex; flex: 1; gap: 8px; align-items: center;
  border: 0; background: transparent; color: var(--fg);
  min-height: 40px; padding: 4px 16px; font-weight: 600; cursor: pointer; text-align: left;
}
.sheet-handle .chev { margin-left: auto; }
.sheet.collapsed .sheet-body { display: none; }
.sheet.collapsed .chev { transform: rotate(180deg); }
.sheet-body { padding: 6px 16px 4px; }

.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.row-title { font-size: 13px; color: var(--muted); width: 3.5em; flex: none; }
.row.buttons { gap: 8px; }
input[type="range"] { flex: 1; min-width: 100px; accent-color: var(--accent); }
input[type="text"] {
  flex: 1; min-width: 0; min-height: 40px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg);
  font-size: 16px; /* iOS で入力時に拡大されないよう16px */
}

select {
  flex: 1; min-width: 0; min-height: 40px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit; font-size: 16px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 34px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 17px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.chip.on { color: var(--fg); border-color: var(--fg); }
.chip:not(.on) .dot { opacity: 0.3; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.ddone { background: #0072B2; }
.duc { background: #009E73; }
.dpl { background: #ffffff; border: 2.5px solid #009E73; box-shadow: none; }

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.status { margin: 6px 0 2px; font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ---------- ポップアップ ---------- */
.maplibregl-popup-content { padding: 12px 14px; border-radius: 10px; color: #1f2933; }
.popup h3 { margin: 0 0 6px; padding-right: 22px; font-size: 20px; line-height: 1.3; }
.popup p { margin: 4px 0; font-size: 13px; line-height: 1.5; }
.popup .meta { color: #5f6b7a; font-size: 12px; }
.popup details { margin-top: 6px; font-size: 12px; }
.popup summary { cursor: pointer; color: #0b4f94; }
.popup .sources { margin: 4px 0 0; padding-left: 1.2em; }
.popup .sources li { margin: 2px 0; word-break: break-all; }
.popup .status-under_construction, .popup .status-planned { color: #00684c; font-weight: 600; }
.popup .pick { list-style: none; margin: 6px 0 0; padding: 0; }
.popup .pick li { border-top: 1px solid #e3e7ec; }
.popup .pick button {
  width: 100%; min-height: 40px; padding: 6px 2px; text-align: left;
  border: 0; background: transparent; color: #0b4f94; font: inherit; font-size: 14px; cursor: pointer;
}
.popup .burned { display: inline-block; margin: 4px 0; padding: 2px 8px; border-radius: 4px; font-size: 13px; font-weight: 600; }
.popup .burned-true { background: #f4c9c0; color: #8a1f0e; }
.popup .burned-partial { background: #f8e2dc; color: #8a1f0e; }
.popup .burned-false { background: #efe7d2; color: #5a4a20; }
.popup .quote-src { color: #5f6b7a; font-size: 12px; }
.popup .note { margin: 8px 0; }
.popup .note img { width: 100%; border-radius: 6px; display: block; }
.popup .note figcaption { font-size: 12px; margin-top: 4px; line-height: 1.5; }
.maplibregl-popup-close-button { font-size: 20px; width: 30px; height: 30px; }

/* ---------- 位置合わせモード ---------- */
body.georef { display: flex; flex-direction: column; height: 100dvh; }
body.georef #imgpane { flex: 1 1 0; }
body.georef #mapwrap { position: relative; inset: auto; flex: 1 1 0; }
body.georef #georefPanel { position: relative; flex: none; max-height: 38dvh; border-radius: 0; left: auto; right: auto; bottom: auto; width: auto; padding-bottom: calc(var(--safe-b) + 4px); }
/* 位置合わせ中は過去の地図の切り替えを隠し、古地図の重ね表示は「重ねて確認」で切り替える */
body.georef #topbar { display: none; }
body.georef .maplibregl-ctrl-top-right { top: 0; }

#imgpane {
  position: relative; overflow: hidden;
  background: #8a8a8a;
  touch-action: none; user-select: none; -webkit-user-select: none;
  padding-top: var(--safe-t);
}
#imgstage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#imgstage canvas { display: block; }
#imgmarkers { position: absolute; inset: 0; pointer-events: none; }

.crosshair {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  width: 44px; height: 44px; margin: -22px 0 0 -22px;
  pointer-events: none;
  background:
    linear-gradient(#e00000, #e00000) center / 2px 100% no-repeat,
    linear-gradient(#e00000, #e00000) center / 100% 2px no-repeat;
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff);
}
.pane-label {
  position: absolute; left: 8px; bottom: 6px; z-index: 2;
  font-size: 12px; padding: 2px 6px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.6); color: #fff; pointer-events: none;
}
#maplabel { bottom: auto; top: 6px; }
.zoombtns { position: absolute; right: 8px; bottom: 8px; z-index: 2; display: flex; flex-direction: column; gap: 6px; }
.zoombtns button {
  width: 40px; height: 40px; border-radius: 8px; border: 0;
  background: rgba(255, 255, 255, 0.92); color: #1f2933; font-size: 20px; box-shadow: var(--shadow); cursor: pointer;
}

.cp {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px;
  background: #e00000; color: #fff; font-size: 12px; font-weight: 700;
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
#imgmarkers .cp { position: absolute; transform: translate(-50%, -50%); }

#cpList { list-style: none; margin: 4px 0; padding: 0; max-height: 120px; overflow-y: auto; }
#cpList li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
#cpList li.bad .cp-res { color: var(--bad); font-weight: 700; }
.cp-go {
  flex: 1; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: var(--fg); text-align: left;
  min-height: 36px; padding: 2px 0; cursor: pointer;
}
.cp-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-res { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cp-del { border: 0; background: transparent; color: var(--muted); width: 40px; height: 36px; font-size: 16px; cursor: pointer; }

/* ---------- ダイアログ・トースト ---------- */
dialog {
  max-width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 48px);
  border: 0; border-radius: 14px; padding: 0;
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-body { padding: 16px 20px; line-height: 1.6; font-size: 14px; }
.dialog-body h2 { font-size: 16px; margin: 12px 0 4px; }
.dialog-body ul, .dialog-body ol { padding-left: 1.3em; margin: 4px 0; }
.dialog-body a { color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 60px); z-index: 10;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px);
  padding: 8px 14px; border-radius: 8px;
  background: rgba(20, 24, 28, 0.9); color: #fff; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
