:root {
  --bg: #fafaf8;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --line-strong: #c2c2bb;
  --accent: #3a6ea5;
  --disk: #2b5b8a;
  --disk-light: #a9c4dd;
  --gap: #c97a3a;
  --gap-light: #f1d6b8;
  --dup: #c44;
  --tier-1: #1f3b5a;
  --tier-2: #4d7aa6;
  --tier-3: #88a8c6;
  --tier-u: #b8b8b0;
  --region: #8a6b3a;
  --colonial: #6b3a8a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: var(--fg);
  background: var(--bg);
}

header {
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 16px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

header .meta {
  color: var(--muted);
  font-size: 12px;
}

header .meta .sep { margin: 0 6px; }

#map {
  height: 45vh;
  min-height: 320px;
  border-bottom: 1px solid var(--line);
}

#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

#controls label, #controls fieldset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

#controls fieldset {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 8px 2px 6px;
  margin: 0;
  gap: 8px;
}

#controls fieldset legend {
  padding: 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

#controls fieldset label {
  color: var(--fg);
  gap: 4px;
}

#controls select, #controls input[type="search"] {
  font: inherit;
  padding: 2px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
  color: var(--fg);
}

#controls input[type="search"] {
  width: 160px;
}

#controls .spacer { flex: 1; }

#visibleCount {
  font-size: 12px;
  color: var(--muted);
}

#table-wrap {
  padding: 0 20px 40px;
  overflow-x: auto;
}

table#cities {
  border-collapse: collapse;
  width: 100%;
  min-width: 1100px;
}

table#cities th, table#cities td {
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}

table#cities th {
  position: sticky;
  top: 0;
  background: var(--bg);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line-strong);
  z-index: 2;
}

table#cities td.col-name {
  white-space: nowrap;
}

table#cities td.col-vols, table#cities th.col-vols {
  text-align: right;
  font-variant-numeric: tabular-nums;
  width: 4em;
}

table#cities td.col-vols .vol-num {
  font-weight: 600;
}

table#cities td.col-vols.idx-only {
  color: var(--gap);
}

td.col-name .display {
  font-weight: 500;
}

td.col-name .meta-bits {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  color: var(--muted);
}

td.col-name .kind-region { color: var(--region); }
td.col-name .kind-colonial { color: var(--colonial); }
td.col-name .badge-dup {
  color: var(--dup);
  margin-left: 6px;
  cursor: help;
}

td.col-sources {
  font-size: 11px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Year grid */
td.col-years {
  width: 1%;
  padding-right: 16px;
}

.year-grid {
  display: flex;
  align-items: stretch;
  height: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 2px;
}

.year-grid .yc {
  flex: 1 1 0;
  min-width: 1px;
  border-right: 1px solid transparent;
}

.year-grid .yc.disk { background: var(--disk); }
.year-grid .yc.gap  { background: var(--gap-light); }
.year-grid .yc.empty { background: transparent; }

/* Decade gridlines */
.year-grid .yc.decade { border-right-color: rgba(0, 0, 0, 0.06); }
.year-grid .yc.century {
  border-right-color: rgba(0, 0, 0, 0.18);
  border-right-width: 1px;
}

.year-axis {
  display: flex;
  position: relative;
  height: 12px;
  margin-top: 1px;
  font-size: 10px;
  color: var(--muted);
}

.year-axis .tick {
  position: absolute;
  transform: translateX(-50%);
}

.year-axis-header {
  height: 14px;
}

/* Map marker tooltips */
.leaflet-tooltip.coverage-tip {
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 11px;
  box-shadow: none;
}

.leaflet-tooltip.coverage-tip::before { display: none; }

/* Row highlight when marker clicked */
tr.highlight {
  background: #fffaa8;
  transition: background-color 1.5s ease-out;
}

tr.row-region td.col-name .display { font-style: italic; color: var(--region); }
tr.row-colonial td.col-name .display { font-style: italic; color: var(--colonial); }

/* Footer / legend */
.legend {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}

.legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: -1px;
}

.legend .swatch.disk { background: var(--disk); }
.legend .swatch.gap { background: var(--gap-light); }
