:root {
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #f5f5f5;
  --ink: #1a1a1a;
  --ink-mute: #666666;
  --accent: #e8610a;
  --accent-soft: #f5934a;
  --accent-pale: #fff3eb;
  --line: #e0e0e0;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 6px 18px rgba(0, 0, 0, .05);
  --radius: 10px;
  --radius-sm: 6px;
  --space: 16px;
  --max: 1200px;
  --font-jp: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --font-ui: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space);
  padding: 18px 24px 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
}
.brand h1 {
  margin: 0;
  font-family: var(--font-jp);
  font-size: 26px;
  letter-spacing: .04em;
  color: #0a0a0a;
}
.brand h1 span {
  color: var(--accent);
}
.brand .tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: .04em;
}
.header-btns {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.ghost-btn {
  font: inherit;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-mute);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.ghost-btn:hover { border-color: var(--accent-soft); color: var(--accent); }

/* ---- controls ---- */
.controls {
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px 24px 0;
}
.search-row {
  display: flex; gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.search-field {
  flex: 1 1 280px;
  position: relative;
}
.search-field input {
  width: 100%;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-field input:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(232, 97, 10, .18);
}
.view-switch {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-btn {
  font: inherit;
  background: transparent;
  border: none;
  padding: 8px 16px;
  cursor: pointer;
  color: var(--ink-mute);
  transition: background .15s, color .15s;
}
.view-btn.is-active {
  background: var(--accent);
  color: #fff;
}
.view-btn:not(.is-active):hover { background: var(--bg-soft); color: var(--ink); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: flex-start;
  margin-top: 12px;
}
details.filter {
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 0;
  min-width: 0;
}
details.filter > summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 12px;
  font-size: 13px;
  user-select: none;
}
details.filter > summary::-webkit-details-marker { display: none; }
details.filter[open] > summary { border-bottom: 1px solid var(--line); }
.filter-count {
  font-size: 11px;
  color: var(--ink-mute);
  margin-left: 4px;
}
.chip-list {
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(70vw, 700px);
  max-height: 240px;
  overflow-y: auto;
}
.chip {
  font: inherit;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: #ebebeb; }
.chip.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip .count {
  margin-left: 4px;
  opacity: .65;
  font-size: 10px;
}

.year-range {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.year-range label { font-size: 13px; }
#yearRangeLabel { color: var(--accent); margin-left: 4px; font-variant-numeric: tabular-nums; }
.year-inputs {
  position: relative;
  width: 220px;
  height: 30px;
}
.year-inputs input[type="range"] {
  position: absolute;
  width: 100%; left: 0; top: 50%;
  transform: translateY(-50%);
  -webkit-appearance: none;
  background: transparent;
  pointer-events: none;
}
.year-inputs input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}
.year-inputs input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  pointer-events: auto;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.year-inputs input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  pointer-events: auto;
  cursor: pointer;
  border: 2px solid #fff;
}
.year-inputs input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  min-height: 24px;
}
.active-filters .chip { background: var(--accent-soft); color: #fff; border-color: var(--accent-soft); }
.active-filters .chip::after {
  content: " ×";
  margin-left: 2px;
}
.result-meta {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

/* ---- views ---- */
main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px 24px 40px;
}
.view { display: none; }
.view.is-active { display: block; }

/* grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .12s ease, box-shadow .12s ease;
  border: 1px solid var(--line);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.10), 0 12px 28px rgba(0,0,0,.08);
}
.card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--bg-soft);
  background-image: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-mute);
  font-size: 11px;
  letter-spacing: .1em;
  position: relative;
  overflow: hidden;
}
.card .thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.card .thumb-count {
  position: absolute;
  bottom: 5px;
  right: 5px;
  min-width: 1.25em;
  padding: 1px 5px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  letter-spacing: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.38);
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
  pointer-events: none;
}
.card .thumb .placeholder-mark {
  font-family: var(--font-jp);
  text-align: center;
  padding: 8px;
}
.card .meta {
  padding: 10px 12px 12px;
  flex: 1;
  display: flex; flex-direction: column; gap: 4px;
}
.card .title {
  font-family: var(--font-jp);
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .submeta {
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: .03em;
}
.card .tags {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.card .tags .tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink-mute);
}

.empty-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-mute);
}

/* map */
#map {
  width: 100%;
  height: calc(100vh - 290px);
  min-height: 420px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
.map-popup {
  font: inherit;
  display: flex; gap: 10px;
  max-width: 280px;
}
.map-popup .ph {
  width: 80px; height: 60px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background-image: linear-gradient(135deg, #f0f0f0, #e0e0e0);
}
.map-popup .ph img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); }
.map-popup .pop-title {
  font-weight: 600;
  font-size: 13px;
  margin: 0 0 4px;
  font-family: var(--font-jp);
}
.map-popup .pop-meta {
  font-size: 11px;
  color: var(--ink-mute);
}
.map-popup .loc-wiki-link {
  color: var(--accent);
  text-decoration: underline;
  white-space: nowrap;
}
.map-popup button {
  margin-top: 6px;
  font: inherit; font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-soft);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

/* timeline */
.timeline-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.year-block {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
}
.year-block h3 {
  margin: 0 0 8px;
  font-family: var(--font-jp);
  font-size: 18px;
  color: var(--accent);
}
.year-block h3 .count {
  font-size: 12px;
  color: var(--ink-mute);
  margin-left: 8px;
  font-family: var(--font-ui);
}
.year-block .row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.year-block .row .card .title { font-size: 13px; }
.year-block .row .card .thumb { aspect-ratio: 4 / 3; }

/* detail dialog */
.detail-dialog, .about-dialog {
  border: none;
  padding: 0;
  border-radius: var(--radius);
  max-width: min(720px, 92vw);
  width: 100%;
  background: var(--bg-card);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.detail-dialog::backdrop, .about-dialog::backdrop {
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
}
.close-btn {
  position: absolute;
  top: 8px; right: 12px;
  background: transparent;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--ink-mute);
  cursor: pointer;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  z-index: 2;
}
.close-btn:hover { background: var(--bg-soft); color: var(--ink); }

.detail-content {
  padding: 28px 28px 24px;
}
.detail-content .images {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.detail-content .images.multi { grid-template-columns: repeat(2, 1fr); }
.detail-content .images .ph {
  aspect-ratio: 4 / 3;
  background-image: linear-gradient(135deg, #f0f0f0, #e0e0e0);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  color: var(--ink-mute);
  font-family: var(--font-jp);
  text-align: center;
  padding: 12px;
}
.detail-content .images .ph img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); }
.detail-content .images .ph--missing {
  flex-direction: column;
  gap: 6px;
  background-image: repeating-linear-gradient(
    45deg, #f5f5f5, #f5f5f5 4px, #eaeaea 4px, #eaeaea 8px
  );
}
.detail-content .images .ph--missing .missing-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-mute);
}
.detail-content .images .ph--has-iiif {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  overflow: hidden;
}
.detail-content .images .ph--has-iiif img {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: cover;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  height: auto;
}
.iiif-ref-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  padding: 4px 8px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink-mute);
  cursor: pointer;
}
.iiif-ref-btn:hover {
  background: #fff;
  color: var(--accent);
}
.jpeg-direct-link {
  flex-shrink: 0;
  display: block;
  font-size: 12px;
  padding: 7px 12px;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  color: #333;
  text-align: center;
  text-decoration: none;
  font-weight: bold;
  letter-spacing: .02em;
}
.jpeg-direct-link:hover {
  color: var(--accent);
  background: var(--accent-pale);
}
.detail-content h2 {
  margin: 0 0 6px;
  font-family: var(--font-jp);
  color: var(--accent);
  font-size: 22px;
}
.detail-content .submeta {
  font-size: 12px;
  color: var(--ink-mute);
  margin-bottom: 14px;
}
.detail-content .description {
  font-family: var(--font-jp);
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink);
  white-space: pre-wrap;
  background: var(--bg);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 14px;
}
.detail-content .description--empty {
  color: var(--ink-mute);
  font-style: italic;
  font-size: 13px;
}
.detail-content dl {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 12px;
  font-size: 13px;
  margin: 0 0 10px;
}
.detail-content dt { color: var(--ink-mute); }
.detail-content dd { margin: 0; }
.detail-content .tags-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 4px;
}
.detail-content .tags-row .chip { cursor: pointer; }

.about-dialog article {
  padding: 28px 32px;
}
.about-dialog h2 {
  margin: 0 0 14px;
  font-family: var(--font-jp);
  color: var(--accent);
}
.about-dialog p { font-size: 14px; }
.about-dialog .meta { color: var(--ink-mute); font-size: 12px; }

/* footer */
.sitefoot {
  text-align: center;
  padding: 16px;
  color: var(--ink-mute);
  border-top: 3px solid var(--accent);
  background: var(--ink);
  color: #fff;
}
.sitefoot small { opacity: .65; }
.sitefoot a { color: #fff; }

/* leaflet popup tweaks */
.leaflet-popup-content { margin: 12px 14px !important; }
.leaflet-popup-content-wrapper { border-radius: var(--radius) !important; }

/* ---- responsive ---- */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px 10px; }
  .brand h1 { font-size: 20px; }
  .brand .tagline { display: none; }
  .controls { padding: 12px 16px 0; }
  main { padding: 12px 16px 32px; }
  .search-row { gap: 8px; }
  .view-switch { width: 100%; }
  .view-btn { flex: 1; padding: 8px 4px; font-size: 13px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card .title { font-size: 13px; }
  .card .meta { padding: 8px 10px 10px; }
  #map { height: calc(100vh - 250px); }
  .year-inputs { width: 100%; }
  .year-range { width: 100%; }
  details.filter > summary { padding: 8px 12px; }
  .detail-content { padding: 20px 18px; }
  .detail-content dl { grid-template-columns: 90px 1fr; font-size: 12px; }
  .chip-list { max-width: calc(100vw - 48px); }
}

@media (max-width: 420px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
