/* =========================================================
   色・サイズはここでまとめて管理
   ========================================================= */
:root {
  --bg: #0b0b0e;
  --panel: #111115;
  --panel-2: #18181d;
  --line: #24242b;
  --line-2: #33333c;
  --text: #ececf0;
  --muted: #8b8b96;
  --accent: #a3e635;       /* 発見ボタン・進捗バー */
  --accent-ink: #1a2e05;
  --official: #e8c45a;
  --community: #e59c4b;
  --unverified: #8b8b96;
  --topbar-h: 56px;
  --side-w: 256px;
  --stats-w: 288px;
  --tabbar-h: 0px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: #9cc9ff; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- 共通部品 ---------- */
.chip {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--panel-2);
  font-size: 12px;
  white-space: nowrap;
}
.chip:hover { border-color: #4a4a55; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 700;
}

select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel-2);
}

.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); }

/* ---------- ヘッダー ---------- */
.topbar {
  position: relative;
  z-index: 1000;
  flex-shrink: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 800; font-size: 16px; min-width: 0; }
.brand-mark {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 13px;
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-progress { margin-left: auto; width: 150px; font-size: 11px; color: var(--muted); }
.top-progress .bar { margin-top: 5px; }
.top-pct { display: none; }
.seg { display: flex; padding: 3px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--panel); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.seg button[aria-selected="true"] { background: var(--panel-2); color: var(--text); }

/* ---------- レイアウト ----------
   body を縦並びの flex にして「ヘッダー＋本体」を画面いっぱいに置く。
   本体を position: fixed にすると重なり順の基準ができてしまい、
   スマホのシートが背景の暗幕より下に潜るため、通常の流れで配置している */
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  margin-bottom: var(--tabbar-h);
}
.center { position: relative; flex: 1; min-width: 0; }
.map { position: absolute; inset: 0; z-index: 0; } /* Leaflet の重なりをマップ内に閉じ込める */

/* ---------- 左サイドバー ---------- */
.sidebar {
  width: var(--side-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
}
.sheet-head { display: none; }

.search { position: relative; }
.search input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  outline: none;
}
.search input:focus { border-color: #55555f; }
.search-results {
  position: absolute;
  z-index: 10;
  left: 0; right: 0; top: 44px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.search-results button {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border: 0; border-radius: 6px; background: none; text-align: left;
}
.search-results button:hover, .search-results button:focus { background: var(--panel-2); outline: none; }
.search-results .sub { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.search-results .empty { padding: 10px; color: var(--muted); }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

.cat-group-label { margin: 10px 0 4px; color: var(--muted); font-size: 12px; }
.cat-group-label:first-child { margin-top: 0; }
.cat-row {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.cat-row:hover { background: var(--panel); }
.cat-row[aria-pressed="false"] { opacity: .38; }
.cat-row .name { flex: 1; }
.cat-row .count { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* カテゴリのアイコン（ピンと同じ見た目の小さい版） */
.glyph {
  width: 20px; height: 20px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 6px;
  background: var(--c);
  color: #111;
  font-size: 11px; font-weight: 900; line-height: 1;
}

.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.spoiler-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.spoiler-row select { height: 32px; font-size: 12px; }
.spoiler-note { margin: 8px 0; padding-left: 8px; border-left: 2px solid var(--accent); font-size: 12px; color: var(--muted); }
.legend summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.legend dl, .info dl { margin: 8px 0 0; }
dt .badge { margin-top: 6px; }
dd { margin: 4px 0 8px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* 情報源バッジ */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  border: 1px solid currentColor;
}
.badge.official { color: var(--official); background: rgba(232,196,90,.1); }
.badge.community { color: var(--community); background: rgba(229,156,75,.1); }
.badge.unverified { color: var(--unverified); background: rgba(139,139,150,.1); }

/* ---------- 右：進捗 ---------- */
.stats {
  width: var(--stats-w);
  flex-shrink: 0;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  border-left: 1px solid var(--line);
}
.stats-card {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.stats-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stats-pct { font-size: 40px; font-weight: 800; line-height: 1.1; }
.stats-bars { list-style: none; margin: 14px 0 0; padding: 0; }
.stats-bars li { display: grid; grid-template-columns: minmax(0, 1fr) 64px 40px; align-items: center; gap: 8px; height: 24px; font-size: 12px; }
.stats-bars li > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-bars li .n { text-align: right; color: var(--muted); font-family: var(--mono); }
.stats-bars li .bar > i { background: var(--c); }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li button {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 7px 4px; border: 0; background: none; text-align: left; font-size: 13px;
}
.recent li button:hover { background: var(--panel-2); border-radius: 6px; }
.recent .ago { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.recent .empty { color: var(--muted); font-size: 12px; }

/* ---------- マップ上のピン ---------- */
.pin {
  position: relative;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--c);
  color: #111;
  font-size: 14px; font-weight: 900; line-height: 1;
  border: 2px solid rgba(0,0,0,.55);
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
}
/* 情報源で枠線を変える：公式=実線 / コミュニティ=破線 / 未確認=点線+やや薄く */
.pin.community { outline: 2px dashed rgba(255,255,255,.75); outline-offset: 1px; }
.pin.unverified { outline: 2px dotted rgba(255,255,255,.6); outline-offset: 1px; opacity: .72; }
/* 発見済み：薄く＋チェックマーク */
.pin.found { opacity: .32; outline: none; }
/* 引いて見ているときはピンを小さく（.zoom-far は app.js がズームに応じて付ける） */
.leaflet-marker-icon.pin-wrap { display: grid; place-items: center; }
.zoom-far .pin { width: 22px; height: 22px; border-radius: 7px; font-size: 11px; border-width: 1.5px; }
.zoom-far .pin.found::after { width: 12px; height: 12px; font-size: 8px; right: -4px; top: -4px; }
.pin.found::after {
  content: "✓";
  position: absolute;
  right: -5px; top: -5px;
  width: 15px; height: 15px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px;
}

.region-label {
  color: rgba(255,255,255,.88);
  font-weight: 800;
  letter-spacing: .08em;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,.9), 0 0 8px rgba(0,0,0,.6);
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: inline-block;
}

/* ---------- ポップアップ ---------- */
.leaflet-container { background: var(--sea, #2c66a5); font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { margin: 14px 16px; width: 250px !important; font-size: 13px; line-height: 1.6; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); width: 34px; height: 34px; font-size: 20px; line-height: 34px; }
.pp-title { margin: 0 22px 2px 0; font-size: 16px; font-weight: 800; line-height: 1.35; }
.pp-en { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.pp-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pp-desc { margin: 8px 0; }
.pp-links { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.pp-found {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  border: 0; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800;
}
.pp-found.is-found { background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); }
.pp-tools { display: flex; gap: 6px; margin-top: 8px; }
.pp-tools .icon-btn { width: auto; padding: 0 10px; height: 32px; font-weight: 500; font-size: 12px; }
.pp-note { margin-top: 8px; font-size: 11px; color: var(--muted); }

/* Leaflet のボタン類 */
.leaflet-bar { border: 1px solid var(--line-2) !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-bottom-color: var(--line-2); width: 36px !important; height: 36px !important; line-height: 36px !important; }
.leaflet-bar a:hover { background: var(--panel-2); }
.leaflet-control-attribution {
  background: rgba(11,11,14,.82) !important;
  color: #b9b9c3 !important;
  font-size: 10.5px;
  border-radius: 6px 0 0 0;
  max-width: 100%;
}
.leaflet-control-attribution a { color: #fff; }
.map-credit-btn { display: none; }

/* ---------- チェックリスト ---------- */
.checklist { position: absolute; inset: 0; z-index: 800; overflow-y: auto; padding: 20px; background: var(--bg); }
.cl-summary {
  max-width: 900px; margin: 0 auto 16px;
  display: flex; flex-wrap: wrap; gap: 20px 32px; align-items: flex-start;
  padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
}
.cl-big { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.cl-big b { font-size: 34px; }
.cl-big span { font-weight: 700; }
.cl-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
#cl-body { max-width: 900px; margin: 0 auto; }
.cl-section { margin-bottom: 18px; }
.cl-head { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 15px; }
.cl-head .count { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; font-weight: 400; }
.cl-items { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cl-item { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.cl-item:first-child { border-top: 0; }
.cl-item input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.cl-item .t { flex: 1; min-width: 0; border: 0; background: none; padding: 0; text-align: left; }
.cl-item .t b { display: block; font-weight: 600; }
.cl-item .t small { color: var(--muted); }
.cl-item.found .t b { color: var(--muted); text-decoration: line-through; }
.cl-empty { max-width: 900px; margin: 0 auto; padding: 16px; border: 1px dashed var(--line-2); border-radius: 10px; color: var(--muted); }

/* ---------- スマホ用の部品（PCでは非表示） ---------- */
.fab, .tabbar, .backdrop { display: none; }

/* ---------- ダイアログ ---------- */
.info {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 22px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  line-height: 1.7;
}
.info::backdrop { background: rgba(0,0,0,.6); }
.info h2 { margin: 0 0 8px; font-size: 18px; }
.info h3 { margin: 18px 0 6px; font-size: 14px; }
.info p { margin: 0 0 8px; }
.info-close { position: absolute; right: 14px; top: 14px; margin: 0; }
.credits { margin: 0; padding-left: 18px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 3000;
  padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

/* =========================================================
   レスポンシブ
   ========================================================= */

/* 共通：シート（下から出るパネル）の見た目 */
@media (max-width: 1179px) {
  .sheet.open {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 72dvh;
    z-index: 2100;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line-2);
    border-radius: 16px 16px 0 0;
    background: var(--bg);
  }
  .sheet.open .sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 700;
  }
  .backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.45); }
  .fab {
    position: fixed;
    bottom: calc(18px + var(--tabbar-h) + env(safe-area-inset-bottom));
    z-index: 1500;
    width: 54px; height: 54px;
    display: grid; place-items: center;
    border: 1px solid var(--line-2); border-radius: 50%;
    background: var(--panel);
    box-shadow: 0 6px 18px rgba(0,0,0,.5);
  }
  .fab svg, .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .fab-left { left: 14px; display: none; }
  .fab-right { right: 14px; }
  .view-list .map-credit-btn { display: none !important; }
  /* チェックリストでもフィルタ（検索・カテゴリ・ネタバレ防止）を開けるよう丸ボタンは残し、最後の行が隠れないよう下に余白 */
  .checklist { padding-bottom: 96px; }

  /* タブレット：右の進捗パネルはシートに */
  .stats { display: none; }
}

/* スマホ */
@media (max-width: 767px) {
  :root { --topbar-h: 52px; --tabbar-h: calc(58px + env(safe-area-inset-bottom)); }

  .top-progress, .seg, .top-spoiler, .topbar > .btn-info { display: none; }
  .top-pct { display: inline-block; margin-left: 4px; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); font-size: 13px; }

  .sidebar { display: none; }
  .fab-left { display: grid; }

  .search-results { max-height: 36dvh; }
  .checklist { padding: 12px 12px 96px; }
  .cl-summary { padding: 16px; gap: 14px 24px; }
  .cl-actions { margin-left: 0; }

  /* 長いクレジットはボタンに格納（タップで全文表示） */
  .leaflet-control-attribution { display: none; }
  .map-credit-btn {
    display: grid;
    position: absolute; right: 14px; top: 14px; z-index: 900;
    width: 36px; height: 36px; place-items: center;
    border: 1px solid var(--line-2); border-radius: 8px;
    background: var(--panel); font-weight: 800;
  }
  .leaflet-control-zoom { display: none; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1600;
    height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--line);
  }
  .tabbar button {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: none; color: var(--muted); font-size: 11px;
  }
  .tabbar button[aria-current="true"] { color: var(--text); box-shadow: inset 0 2px 0 var(--text); }
}

/* ---------- 印刷：チェックリストだけ ---------- */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .sidebar, .stats, .fab, .tabbar, .map, .map-credit-btn, .cl-actions { display: none !important; }
  .layout, .checklist { position: static; overflow: visible; }
  .checklist { display: block !important; }
  .cl-summary, .cl-items, .cl-item { background: #fff; border-color: #ccc; }
  .cl-item .t small, .muted { color: #555; }
}
