:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #23211d;
  --ink-2: #5f5a51;
  --line: #e2ddd2;
  --accent: #d6322c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe5e3;
  --focus: #2f6fd6;
  --shadow: 0 6px 24px rgba(40, 30, 10, 0.12);
  --radius: 14px;
  --header-h: 60px;
  --footer-h: 34px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b;
    --surface: #212327;
    --surface-2: #2a2d32;
    --ink: #eeece7;
    --ink-2: #a9a59c;
    --line: #34373d;
    --accent: #f0544c;
    --accent-soft: #3b2322;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: "M PLUS Rounded 1c", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

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

/* ---------- header ---------- */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  white-space: nowrap;
}

/* モンスターボール風ではなく、マンホールの蓋をイメージした丸 */
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background:
    repeating-linear-gradient(45deg, transparent 0 4px, rgba(255,255,255,.35) 4px 6px),
    var(--accent);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.15);
}

.search { margin-left: auto; flex: 0 1 320px; }

.search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
}

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 400px 1fr;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 14px 16px 10px;
  font-size: .85rem;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}

.crumbs a { text-decoration: none; padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); color: var(--ink); }
.crumbs .sep { opacity: .5; }
.crumbs .current { color: var(--ink); font-weight: 700; padding: 2px 6px; }

.panel-body { overflow-y: auto; overflow-x: hidden; padding: 16px; flex: 1; }

.panel-title { font-size: 1.25rem; font-weight: 800; margin: 0 0 4px; }
.panel-sub { margin: 0 0 16px; color: var(--ink-2); font-size: .88rem; line-height: 1.6; }

/* ---------- region / pref grid ---------- */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}

.chip:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.chip:disabled { opacity: .45; cursor: default; }

.chip .count {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

.chip:disabled .count { color: var(--ink-2); background: var(--surface-2); }

.pref-about {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 10px;
  font-size: .85rem;
  line-height: 1.7;
  color: var(--ink-2);
}

/* ---------- manhole list ---------- */
.card-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.card:hover, .card.is-active { border-color: var(--accent); background: var(--accent-soft); }

.card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}

.card-main { min-width: 0; }
.card-title { display: block; font-weight: 700; font-size: .95rem; }
.card-title small { color: var(--accent); font-size: .75rem; margin-right: 4px; }
.card-meta { display: block; font-size: .8rem; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { color: var(--ink-2); font-size: .9rem; padding: 24px 0; text-align: center; }

/* ---------- detail drawer ---------- */
.detail {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 12px;
  bottom: calc(var(--footer-h) + 12px);
  width: min(420px, calc(100vw - 24px));
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transform: translateX(calc(100% + 24px));
  transition: transform .25s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.detail.is-open { transform: none; }

.detail-inner { overflow-y: auto; padding: 18px; }

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 1;
}

.detail-pref { font-size: .8rem; color: var(--accent); font-weight: 700; }
.detail-title { font-size: 1.35rem; font-weight: 800; margin: 2px 40px 14px 0; line-height: 1.35; }

.detail-img {
  display: block;
  width: 78%;
  max-width: 300px;
  aspect-ratio: 1;
  margin: 0 auto 16px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
}

.poke-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; justify-content: center; }

.poke-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .85rem;
  font-weight: 700;
  text-decoration: none;
}

.poke-tag:hover { filter: brightness(1.08); }

.detail-section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.detail-section h3 { font-size: .95rem; margin: 0 0 8px; }
.detail-section p { margin: 0; font-size: .88rem; line-height: 1.75; color: var(--ink-2); white-space: pre-line; }

.address { color: var(--ink) !important; font-weight: 700; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

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

.nearby { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.nearby button { width: 100%; }
.nearby .card img { width: 44px; height: 44px; }

/* ---------- nearby photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.photo {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--surface-2);
  cursor: zoom-in;
}

.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.photo:hover img { transform: scale(1.06); }

.photo-dist {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
}

.detail-section p.photo-note { font-size: .75rem; margin-top: 8px; line-height: 1.6; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(10, 10, 12, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox[hidden] { display: none; }

.lightbox-fig { position: relative; margin: 0; max-width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; }

.lightbox-fig img {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  object-fit: contain;
  border-radius: 10px;
  background: #222;
}

.lightbox-fig figcaption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 10px;
  color: #eee;
  font-size: .82rem;
}

.lightbox-fig figcaption a { color: #9cc4ff; }

.lightbox-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: #fff;
  color: #222;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

/* ---------- map markers ---------- */
.pf-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  background: #ccc center / cover no-repeat;
  transition: transform .15s;
}

.pf-marker.is-active { border-color: var(--accent); transform: scale(1.45); z-index: 1000; }

.pf-cluster {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}

.leaflet-container { font-family: inherit; }

/* ---------- footer ---------- */
.site-footer {
  min-height: var(--footer-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 16px;
  font-size: .72rem;
  color: var(--ink-2);
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  body { height: auto; min-height: 100%; }
  html, body { overflow-x: hidden; }
  .site-header { gap: 10px; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 42vh auto; }
  .map-wrap { grid-row: 1; min-height: 42vh; position: sticky; top: 0; z-index: 1; }
  .panel { grid-row: 2; border-right: 0; }
  .panel-body { overflow: visible; }
  .brand span:last-child { font-size: 1rem; }
  .search { flex: 1 1 auto; min-width: 0; }
  .detail {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    position: fixed;
  }
  .detail.is-open { transform: none; }
}
