:root {
  --paper: #f1f2ee;
  --sheet: #fafaf7;
  --ink: #172019;
  --muted: #626b64;
  --line: #aeb5ae;
  --red: #ad392e;
  --blue: #385865;
  --body: "Hiragino Sans", "Yu Gothic", sans-serif;
  --mono: "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 58px; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body);
  line-height: 1.7;
}

a { color: inherit; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 30;
  padding: 0.6rem 0.9rem;
  color: #fff;
  background: var(--red);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 58px;
  align-items: stretch;
  justify-content: space-between;
  border-bottom: 1px solid var(--ink);
  background: rgba(241, 242, 238, 0.97);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.2rem;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--ink);
  color: var(--red);
  font-family: var(--mono);
  font-size: 0.65rem;
}

nav { display: flex; flex-wrap: wrap; max-width: 100%; overflow: hidden; }

nav a {
  display: grid;
  min-width: 105px;
  place-items: center;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  text-decoration: none;
}

nav a:hover { color: #fff; background: var(--ink); }

.hero-strip {
  margin: 0;
  padding: 0.5rem clamp(1rem, 3vw, 1.6rem);
  border-bottom: 1px solid var(--ink);
  color: var(--muted);
  background: var(--sheet);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.eyebrow,
.record-number,
.record-region,
.coordinate {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.explorer {
  display: grid;
  height: calc(100dvh - 58px - 32px);
  scroll-margin-top: 58px;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 34vw);
  grid-template-rows: minmax(0, 1fr);
  border-bottom: 1px solid var(--ink);
}

.explorer-map {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.explorer-map #world-map-canvas {
  width: 100%;
  height: 100%;
  min-height: 420px;
}

.explorer-tabs {
  display: none;
}

.explorer-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--ink);
  background: var(--sheet);
}

.world-map-cluster-badge {
  display: grid;
  min-width: 116px;
  max-width: 180px;
  min-height: 42px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.6rem;
  box-sizing: border-box;
  border: 1px solid var(--ink);
  color: var(--ink);
  background: rgba(250, 250, 247, 0.96);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  box-shadow: 3px 3px 0 rgba(23, 32, 25, 0.22);
  cursor: pointer;
}

.world-map-cluster-badge span { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.world-map-cluster-badge strong { color: var(--red); font-family: var(--mono); font-size: 0.68rem; }
.world-map-cluster-badge.level-region { color: #fff; background: var(--ink); }
.world-map-cluster-badge.level-region strong { color: #fff; }
.world-map-cluster-badge.level-country {
  width: 126px;
  min-width: 0;
  min-height: 34px;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem;
  font-size: 0.67rem;
  box-shadow: 2px 2px 0 rgba(23, 32, 25, 0.18);
}
.world-map-cluster-badge:hover { color: #fff; background: var(--red); }
.world-map-cluster-badge:hover strong { color: #fff; }

.panel-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 1.2rem clamp(1rem, 2.5vw, 1.6rem);
  overflow-y: auto;
}

.panel-detail {
  position: relative;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-detail:not([hidden]) { display: flex; }

.back-to-list {
  align-self: flex-start;
  margin: 0.9rem clamp(1rem, 2.5vw, 1.6rem) 0;
  padding: 0.5rem 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-family: var(--mono);
  font-size: 0.7rem;
  cursor: pointer;
}

.back-to-list:hover { color: var(--red); }

.detail-tabs {
  display: flex;
  margin: 0.6rem clamp(1rem, 2.5vw, 1.6rem) 0;
  border: 1px solid var(--ink);
}

.detail-tab-button {
  flex: 1;
  border: 0;
  padding: 0.6rem;
  color: var(--muted);
  background: transparent;
  font-size: 0.72rem;
  cursor: pointer;
}

.detail-tab-button + .detail-tab-button { border-left: 1px solid var(--ink); }
.detail-tab-button:hover { color: var(--ink); }
.detail-tab-button[aria-selected="true"] { color: #fff; background: var(--red); }

.detail-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.detail-streetview {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1rem clamp(1rem, 2.5vw, 1.6rem) 1.5rem;
}

.map-frame {
  position: relative;
  flex: 1;
  height: auto;
  min-height: 300px;
  overflow: hidden;
  border: 1px solid #748078;
  background: var(--blue);
}

.map-frame.external-only {
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
  background: var(--sheet);
}

.map-frame.external-only .map-actions { position: static; }

#map {
  width: 100%;
  height: 100%;
  border: 0;
  filter: saturate(0.78) contrast(1.02);
  opacity: 1;
  transition: opacity 180ms ease;
}

.map-frame.is-switching #map { opacity: 0.35; }

.coordinate {
  color: #d7ddd8;
  background: transparent;
}
.filters label > span { display: block; margin-bottom: 0.35rem; color: var(--muted); font-size: 0.66rem; }

.map-actions {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  color: #fff;
  background: rgba(23, 32, 25, 0.94);
}

.map-actions a, .text-button { font-size: 0.7rem; text-decoration: none; }
.text-button { border: 0; color: #d7ddd8; background: transparent; cursor: pointer; }

.streetview-tour {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  border: 1px solid var(--ink);
  border-top: 0;
}

.streetview-tour button {
  min-width: 0;
  padding: 0.75rem;
  border: 0;
  color: var(--ink);
  background: var(--sheet);
  font-size: 0.72rem;
  cursor: pointer;
}

.streetview-tour button + button { border-left: 1px solid var(--ink); }
.streetview-tour button:hover:not(:disabled) { color: #fff; background: var(--red); }
.streetview-tour button:disabled { color: var(--line); cursor: default; }

.detail-info {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(0.65rem, 1.5vh, 1rem);
  width: 100%;
  padding: clamp(1rem, 2.2vh, 1.4rem) clamp(1rem, 2.5vw, 1.6rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background: var(--sheet);
  box-shadow: -12px 0 28px rgba(23, 32, 25, 0.16);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 260ms ease, visibility 0s linear 260ms;
}

.detail-body.info-open .detail-info {
  transform: translateX(0);
  visibility: visible;
  transition-delay: 0s;
}

.detail-info > * { flex: 0 0 auto; }

.record-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--ink);
}

.record-number { color: var(--red); }
.record-region { text-align: right; }

.detail-info h2 {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.45rem, 2.4vw, 2.05rem);
  line-height: 1.12;
  letter-spacing: -0.045em;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.native-name { margin: -0.5rem 0 0; overflow: hidden; color: var(--muted); font-family: var(--mono); font-size: 0.65rem; text-overflow: ellipsis; white-space: nowrap; }
.record-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--line);
}

.record-facts div {
  display: grid;
  grid-template-columns: 3.7rem minmax(0, 1fr);
  align-items: baseline;
  min-width: 0;
  padding: 0.45rem 0.55rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.record-facts div:last-child:nth-child(odd) { grid-column: 1 / -1; }

.record-facts dt { color: var(--muted); font-size: 0.66rem; }
.record-facts dd {
  display: -webkit-box;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 0.74rem;
  font-weight: 700;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.record-summary {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 0.8rem;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.record-note {
  min-height: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--paper);
}

.record-note span { color: var(--red); font-size: 0.63rem; font-weight: 700; }
.record-note p {
  display: -webkit-box;
  margin: 0.2rem 0 0;
  overflow: hidden;
  font-size: 0.7rem;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.live-camera-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0;
  padding: 0.55rem 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  text-decoration: none;
}
.live-camera-link span { color: var(--red); font-family: var(--mono); font-size: 0.62rem; }
.live-camera-link strong { font-size: 0.72rem; font-weight: 600; text-align: right; }
.live-camera-link:hover strong { color: var(--red); }
.source-links { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; margin-top: -0.2rem; }
.source-links a { color: var(--blue); font-size: 0.68rem; text-underline-offset: 0.2rem; }
.official-record { border-top: 1px solid var(--line); padding-top: 0.75rem; }
.official-record h3 { margin: 0 0 0.35rem; font-size: 0.68rem; letter-spacing: 0.08em; }
.official-record p { margin: 0; color: var(--muted); font-size: 0.72rem; line-height: 1.65; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--ink);
}

.section-heading h2, .about h2 { margin: 0.2rem 0 0; font-size: clamp(1.4rem, 2vw, 1.9rem); line-height: 1.2; letter-spacing: -0.04em; }
.section-heading > p { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 0.68rem; }

.filters {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.9rem 0 1.1rem;
}

.filters .search-field { grid-column: 1 / -1; }
.filters label { min-width: 0; }

.filters input, .filters select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #748078;
  border-radius: 0;
  padding: 0 0.8rem;
  color: var(--ink);
  background: transparent;
}

.filters select { appearance: auto; }
.ruin-list { display: flex; flex-direction: column; border-top: 1px solid var(--ink); }
.load-more {
  width: 100%;
  padding: 0.9rem;
  border: 0;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  background: transparent;
  font-size: 0.72rem;
  cursor: pointer;
}
.load-more:hover { color: #fff; background: var(--red); }

.ruin-card {
  display: grid;
  min-height: 74px;
  grid-template-columns: 3rem 1fr auto;
  grid-template-areas: "number title arrow" "region era era" "details details details";
  align-content: center;
  gap: 0.15rem 0.7rem;
  padding: 0.7rem 0.2rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.ruin-card::after { color: var(--red); content: "→"; grid-area: arrow; }
.ruin-card:hover, .ruin-card[aria-current="true"] { background: #dfe3de; }
.ruin-card[aria-current="true"] { box-shadow: inset 4px 0 0 var(--red); }
.card-top { display: contents; color: var(--muted); font-family: var(--mono); font-size: 0.6rem; }
.card-top span:first-child { grid-area: number; }
.card-top span:last-child { grid-area: region; }
.ruin-card h3 { align-self: end; margin: 0; font-size: 0.95rem; grid-area: title; line-height: 1.3; }
.ruin-card p { margin: 0; color: var(--muted); font-size: 0.66rem; grid-area: details; display: none; }
.ruin-card .card-meta { display: block; grid-area: details; overflow-wrap: anywhere; }
.ruin-card .card-era { grid-area: era; font-family: var(--mono); font-size: 0.62rem; white-space: nowrap; }
.empty-results { padding: 3rem 1rem; border: 1px solid var(--line); color: var(--muted); text-align: center; }

.about {
  display: grid;
  grid-template-columns: 0.45fr 1.25fr 0.7fr;
  gap: clamp(2rem, 5vw, 5rem);
  padding: clamp(3.5rem, 6vw, 5rem) max(clamp(1.2rem, 5vw, 4.5rem), calc((100vw - 1440px) / 2));
  color: #fff;
  background: var(--blue);
}

#about { scroll-margin-top: 58px; }

.about .eyebrow, .about div > p { color: #d8e0dd; }
.about h2 { margin-top: 0; }
.about div > p { max-width: 640px; margin-top: 1.2rem; font-size: 0.84rem; }
.about-links { display: flex; flex-direction: column; justify-content: end; gap: 0.6rem; }
.about-links a { padding-bottom: 0.5rem; border-bottom: 1px solid rgba(255,255,255,0.4); font-size: 0.7rem; text-decoration: none; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem max(clamp(1.2rem, 5vw, 4.5rem), calc((100vw - 1440px) / 2));
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.6rem;
}

footer p { margin: 0; }

@media (max-width: 980px) {
  .explorer {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "tabs" "body";
    height: calc(100dvh - 58px - 32px);
  }

  .explorer-tabs {
    grid-area: tabs;
    display: flex;
    border-bottom: 1px solid var(--ink);
  }

  .explorer-tab-button {
    flex: 1;
    border: 0;
    padding: 0.8rem;
    color: var(--muted);
    background: var(--sheet);
    font-size: 0.76rem;
    cursor: pointer;
  }

  .explorer-tab-button + .explorer-tab-button { border-left: 1px solid var(--line); }
  .explorer-tab-button[aria-selected="true"] { color: #fff; background: var(--ink); }

  .explorer-map { grid-area: body; }
  .explorer-panel { grid-area: body; border-left: 0; border-top: 0; }
  .explorer:not(.mobile-view-info) .explorer-panel { display: none; }
  .explorer.mobile-view-info .explorer-map { display: none; }

  .detail-info { max-width: none; }
  .about { grid-template-columns: 1fr 2fr; }
  .about-links { grid-column: 2; }
}

@media (max-width: 700px) {
  .brand { flex: 0 0 49px; justify-content: center; padding: 0; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 27px; height: 27px; }
  .site-header nav { flex: 1; flex-wrap: nowrap; }
  .site-header nav a { flex: 1; min-width: 0; padding: 0 0.3rem; font-size: 0.58rem; text-align: center; }
  .filters { grid-template-columns: minmax(0, 1fr); }
  .filters .search-field { grid-column: auto; }
  .map-frame { min-height: 320px; }
  .detail-info { gap: 0.55rem; padding-block: 0.8rem; }
  .record-facts { grid-template-columns: 1fr; }
  .record-facts div:last-child:nth-child(odd) { grid-column: auto; }
  .record-summary { -webkit-line-clamp: 3; }
  .record-note p { -webkit-line-clamp: 1; }
  .section-heading { align-items: start; flex-direction: column; }
  .about { grid-template-columns: 1fr; }
  .about-links { grid-column: auto; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
