:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d9dee4;
  --text: #1d2430;
  --muted: #626d7d;
  --accent: #1c6ea4;
  --accent-soft: #e3f0f9;

  /* 差分の色。増えた＝緑、減った＝赤。 */
  --added: #2e7d4f;
  --added-soft: #e4f3ea;
  --removed: #b3413a;
  --removed-soft: #fae9e8;

  /* デフォルメ地図の色（薄い→濃い）。件数の対数で 0〜4 を割り当てる。 */
  --heat-0: #eceff3;
  --heat-1: #d3e6f3;
  --heat-2: #a8cfe8;
  --heat-3: #6fb0d8;
  --heat-4: #2e8bc4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a1f;
    --surface: #1e242b;
    --border: #333c47;
    --text: #e6eaef;
    --muted: #9aa6b4;
    --accent: #58b0e0;
    --accent-soft: #21384a;

    --added: #6cc48f;
    --added-soft: #1f3a2b;
    --removed: #e8837b;
    --removed-soft: #3d2726;

    --heat-0: #262d35;
    --heat-1: #26414f;
    --heat-2: #2c5b74;
    --heat-3: #2f7ba1;
    --heat-4: #3a9fd0;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    'Hiragino Kaku Gothic ProN',
    'Noto Sans JP',
    Meiryo,
    sans-serif;
  line-height: 1.6;
}

/* ── ヘッダ ─────────────────────────────────────── */

.header {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.header-meta {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

a {
  color: var(--accent);
}

/* ── レイアウト ─────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 1px;
  background: var(--border);
  height: calc(100vh - 108px);
  min-height: 480px;
}

.panel {
  background: var(--bg);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.section-head h2 {
  margin: 0;
  font-size: 0.9rem;
}

.count {
  font-size: 0.8rem;
  color: var(--muted);
}

.link-button {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}

.link-button:hover {
  text-decoration: underline;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── 地方タブ ───────────────────────────────────── */

.region-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}

.region-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.region-tab:hover {
  border-color: var(--accent);
}

.region-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── デフォルメ日本地図 ─────────────────────────── */

.japan-map {
  display: grid;
  gap: 2px;
  aspect-ratio: 13 / 15;
  width: 100%;
}

.pref-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: var(--heat-0);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  line-height: 1.1;
  /* タイルが小さくなっても文字が破綻しないよう、幅に応じて縮める。 */
  font-size: clamp(0.45rem, 1.1vw, 0.72rem);
}

.pref-tile[data-heat='1'] {
  background: var(--heat-1);
}
.pref-tile[data-heat='2'] {
  background: var(--heat-2);
}
.pref-tile[data-heat='3'] {
  background: var(--heat-3);
}
.pref-tile[data-heat='4'] {
  background: var(--heat-4);
  color: #fff;
}

.pref-tile:hover {
  border-color: var(--accent);
}

.pref-tile.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  font-weight: 700;
}

.pref-tile.is-empty {
  color: var(--muted);
  cursor: default;
}

.pref-name {
  white-space: nowrap;
}

.pref-count {
  font-size: 0.82em;
  opacity: 0.8;
}

/* ── 機種フィルタ ───────────────────────────────── */

.game-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.game-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.game-chip:hover {
  border-color: var(--accent);
}

.game-chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chip-count {
  color: var(--muted);
  font-size: 0.9em;
}

/* ── 店舗一覧 ───────────────────────────────────── */

.section-list {
  flex: 1;
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.store-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.store-item {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.store-item:hover {
  background: var(--accent-soft);
}

.store-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.store-name {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 600;
}

.store-address {
  margin: 0.1rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.store-games {
  margin: 0.25rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.7rem;
}

.store-more,
.empty {
  padding: 0.5rem 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

/* ── 地図 ───────────────────────────────────────── */

.map-wrap {
  position: relative;
  background: var(--surface);
}

#map {
  width: 100%;
  height: 100%;
}

.map-note {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  z-index: 500;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 60%;
}

/* ピンは画像を持たず CSS だけで描く（余計なリクエストを増やさない）。 */
.pin {
  transform: translate(-50%, -100%);
  background: var(--accent);
  color: #fff;
  border-radius: 999px 999px 999px 2px;
  padding: 0.1rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}

/* 住所を丸めて出した座標は破線にして、確度が低いことを見た目で示す。 */
.pin-approx {
  background: var(--surface);
  color: var(--accent);
  border: 1px dashed var(--accent);
}

.popup h3 {
  margin: 0 0 0.2rem;
  font-size: 0.92rem;
}

.popup-address {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.4rem 0;
}

.popup-badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.74rem;
  text-decoration: none;
}

.popup-warn {
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.popup-links {
  margin: 0.4rem 0 0;
  display: flex;
  gap: 0.75rem;
  font-size: 0.78rem;
}

/* ── 差分ページ ─────────────────────────────────── */

/* 地図が無いぶん、左の履歴を細くして本文を広く使う。 */
.layout-diff {
  grid-template-columns: minmax(200px, 260px) 1fr;
}

.diff-main {
  background: var(--bg);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.history-item:hover {
  background: var(--accent-soft);
}

.history-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.history-date {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
}

.history-stats {
  margin: 0.15rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.pill {
  border-radius: 999px;
  padding: 0.02rem 0.4rem;
  font-size: 0.72rem;
  background: var(--heat-0);
  color: var(--muted);
}

.pill-added {
  background: var(--added-soft);
  color: var(--added);
}

.pill-removed {
  background: var(--removed-soft);
  color: var(--removed);
}

.pill-changed {
  background: var(--accent-soft);
  color: var(--accent);
}

/* 増減のサマリ。左から 新規 / 掲載終了 / 変更 / 総数。 */
.delta-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.delta-card {
  flex: 1 1 5.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  display: flex;
  flex-direction: column;
}

.delta-num {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.delta-label {
  font-size: 0.74rem;
  color: var(--muted);
}

.delta-added {
  border-color: var(--added);
}

.delta-added .delta-num {
  color: var(--added);
}

.delta-removed {
  border-color: var(--removed);
}

.delta-removed .delta-num {
  color: var(--removed);
}

.delta-changed {
  border-color: var(--accent);
}

.delta-changed .delta-num {
  color: var(--accent);
}

/* 0 件のカードまで色を付けると、何も起きていない日が派手に見える。 */
.delta-card.is-zero {
  border-color: var(--border);
}

.delta-card.is-zero .delta-num {
  color: var(--muted);
}

.game-deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.game-delta {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
}

.game-delta-num {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.game-delta.is-up {
  border-color: var(--added);
}

.game-delta.is-up .game-delta-num {
  color: var(--added);
}

.game-delta.is-down {
  border-color: var(--removed);
}

.game-delta.is-down .game-delta-num {
  color: var(--removed);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.filter-row select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
}

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

.diff-item {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

.diff-item:last-child {
  border-bottom: none;
}

.change-note {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.change-added {
  color: var(--added);
}

.change-removed {
  color: var(--removed);
}

.diff-links {
  margin: 0.25rem 0 0;
  display: flex;
  gap: 0.75rem;
  font-size: 0.76rem;
}

/* ── フッタ ─────────────────────────────────────── */

.footer {
  padding: 0.5rem 1rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0;
}

/* ── 狭い画面 ───────────────────────────────────── */

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .panel {
    max-height: none;
    overflow: visible;
  }

  .map-wrap {
    height: 60vh;
  }

  .japan-map {
    max-width: 340px;
    margin-inline: auto;
  }

  .store-list {
    overflow: visible;
  }

  .layout-diff {
    grid-template-columns: 1fr;
  }

  /* 履歴は横に流して、本文を上に持ってくる。 */
  .layout-diff .section-list {
    flex: initial;
    min-height: 0;
  }

  .history-list {
    overflow-x: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .history-item {
    border-bottom: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    white-space: nowrap;
  }

  .diff-main {
    overflow: visible;
  }
}
