:root {
  --bg: #fbfaf7; --surface: #ffffff; --fg: #1f1e1b; --muted: #66645e; --line: #e4e1d9; --accent: #2b5d8a; --accent-soft: #e7eff7;
  --active: #2e7d4f; --closed: #a3452f; --demolished: #6d2e8a; --converted: #a8740f; --relocated: #2f6f8a; --unknown: #8a8a84;
  --radius: 8px; --max: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --surface: #1d1d1b; --fg: #ecebe6; --muted: #a3a29c; --line: #33322e; --accent: #8ab8e6; --accent-soft: #1f2c39; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 24px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-mark { font-weight: 800; font-size: 26px; letter-spacing: -0.02em; line-height: 1; color: var(--accent); }
.brand-name { font-size: 13px; line-height: 1.25; color: var(--muted); padding-left: 12px; border-left: 1px solid var(--line); }
.brand-name small { display: block; font-size: 12px; }
@media (max-width: 480px) {
  .brand-name { display: none; }
  .brand-mark { font-size: 22px; }
  .site-header .wrap { gap: 4px 8px; }
  nav { gap: 0; }
  nav a { padding: 6px 8px; font-size: 14px; }
}
nav { display: flex; gap: 4px; margin-left: auto; }
nav a { padding: 6px 12px; border-radius: 999px; color: var(--fg); font-size: 15px; }
nav a[aria-current="page"], nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

main { padding: 24px 0 48px; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; }
h2 { font-size: 19px; margin: 32px 0 10px; }
.lede { color: var(--muted); margin: 0 0 20px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Controls */
.controls { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; margin: 16px 0 8px; }
.controls input, .controls select { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--fg); font: inherit; font-size: 15px; }
.years { display: flex; gap: 6px; align-items: center; }
.years input { min-width: 0; }
.summary-line { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 12px; color: var(--muted); font-size: 14px; flex-wrap: wrap; gap: 8px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
@media (max-width: 860px) { .controls { grid-template-columns: 1fr 1fr; } .controls .search { grid-column: 1 / -1; } }

/* Index table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none; background: var(--surface); position: sticky; top: 0; }
th[aria-sort="ascending"]::after { content: " \2191"; } th[aria-sort="descending"]::after { content: " \2193"; }
tr:last-child td { border-bottom: 0; }
td .code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.more { display: block; margin: 14px auto 0; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: inherit; cursor: pointer; }
@media (max-width: 640px) { .hide-sm { display: none; } }

/* Status badge */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.s-active { background: var(--active); } .s-closed { background: var(--closed); } .s-demolished { background: var(--demolished); }
.s-converted { background: var(--converted); } .s-relocated { background: var(--relocated); } .s-unknown { background: var(--unknown); }

/* Map page */
.map-page main { padding: 0; }
.map-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 61px); }
.map-side { border-right: 1px solid var(--line); background: var(--surface); padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.map-side input, .map-side select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--fg); font: inherit; font-size: 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend .badge { cursor: pointer; }
.legend .badge.off { opacity: .4; }
#map { height: 100%; width: 100%; }
.leaflet-container.no-basemap { background: #dfe7ec; }
@media (prefers-color-scheme: dark) { .leaflet-container.no-basemap { background: #20262b; } }
@media (max-width: 760px) { .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 70vh; height: auto; } .map-side { border-right: 0; border-bottom: 1px solid var(--line); } }
.leaflet-popup-content { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 15px; }

/* Profile */
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.profile-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.profile-head .code { font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.facts-line { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); margin: 8px 0 18px; font-size: 15px; }
.grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h2 { margin-top: 0; }
.summary { font-size: 17px; max-width: 70ch; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 15px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }
.timeline li { display: grid; grid-template-columns: 64px 1fr; gap: 12px; }
.timeline .yr { font-weight: 600; font-variant-numeric: tabular-nums; }
#mini-map { height: 260px; border-radius: var(--radius); border: 1px solid var(--line); }
.note { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; margin: 12px 0; }
.cite { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; word-break: break-word; }

footer.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 18px 0 28px; }
.prose { max-width: 72ch; }
.prose li { margin: 4px 0; }

/* References (APA, hanging indent) and links */
ol.refs { padding-left: 1.6em; }
.refs li { margin: 0 0 8px; font-size: 15px; word-break: break-word; }
ul.plain-refs { list-style: none; padding: 0; }
ul.plain-refs li { padding-left: 2em; text-indent: -2em; margin-bottom: 12px; }
ul.plain-refs li .muted { text-indent: 0; }
.links-card ul.plain li { padding: 7px 0; }
details summary { cursor: pointer; color: var(--accent); }
h3 { font-size: 16px; margin: 20px 0 8px; }
