:root {
  --ink: #172a25;
  --muted: #5d6e68;
  --line: #dce3dc;
  --paper: #f5f6f3;
  --card: #fff;
  --accent: #176b58;
  --deep: #173f35;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 "Source Sans 3", system-ui, sans-serif;
}

a { color: var(--accent); }

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin-inline: auto;
}

.top {
  padding: 1.1rem 0 1.75rem;
  background: var(--deep);
  color: #f4f7f5;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.4rem;
}

.brand,
.home {
  color: #f4f7f5;
  text-decoration: none;
  font-weight: 700;
}

.home { font-weight: 600; opacity: 0.85; }
.home:hover { opacity: 1; }

h1 {
  margin: 0 0 0.6rem;
  font-family: "EB Garamond", Georgia, serif;
  font-size: clamp(2rem, 4.5vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.lede {
  margin: 0 0 1.1rem;
  max-width: 40rem;
  color: rgba(244, 247, 245, 0.82);
}

.lede a {
  color: inherit;
  text-underline-offset: 0.15em;
}

.lede a:hover {
  color: #fff;
}

button,
select,
input[type="file"] {
  font: inherit;
}

button,
select {
  padding: 0.55rem 0.85rem;
  border: 1px solid #b9c7be;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.city-label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

#citySelect {
  width: 100%;
  margin-bottom: 0.35rem;
}

#citySelect optgroup {
  font-weight: 700;
  color: var(--ink);
}

.city-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0 0 0.75rem;
}

.city-head h2 { margin: 0; }

button.back {
  padding: 0.1rem 0.2rem;
  border: 0;
  background: none;
  border-radius: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

button.back:hover { color: var(--ink); }

aside > h2 {
  margin-top: 1.1rem;
}

main { padding: 1.25rem 0 2.5rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.15rem 1.2rem 1.25rem;
  margin-bottom: 1rem;
}

h2 {
  margin: 0 0 0.75rem;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1.35rem;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.1rem;
}

#map {
  height: 560px;
  background: #e5ece6;
  border-radius: 10px;
}

.map-wrap { position: relative; }

.city-dot {
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(23, 63, 53, 0.25);
}

.city-dot-us { background: #2474c1; }
.city-dot-ca { background: #d23a3a; }

.map-legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 500;
  margin: 0;
  padding: 0.35rem 0.55rem;
  background: rgba(247, 248, 245, 0.94);
  border-radius: 6px;
  font-size: 0.78rem;
  color: #173f35;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.map-legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.map-legend .swatch.us { background: #2474c1; }
.map-legend .swatch.ca { background: #d23a3a; margin-left: 0.35rem; }

.filters label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.45rem 0;
  cursor: pointer;
}

.dot {
  display: inline-block;
  width: 19px;
  height: 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.9rem 0 0.6rem;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

.status {
  margin: 0.7rem 0 0;
  padding: 0.7rem 0.8rem;
  background: #f4f0e4;
  border-radius: 7px;
  font-size: 0.92rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.stats {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  margin: 0.85rem 0 0.4rem;
}

.stats b {
  display: block;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}

.stats small { display: block; color: var(--muted); }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

th, td {
  padding: 0.55rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: #eef2ee;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

th.num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#connectedness tr.current {
  background: #e7f3ee;
}

#connectedness tr[data-city]:hover {
  background: #f3f7f4;
}

#connectedness .city-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.scroll {
  overflow: auto;
  max-height: 440px;
  margin-top: 0.6rem;
}

.scroll.connect-table {
  max-height: none;
}

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 1.4rem;
  margin: 0.85rem 0 0.2rem;
}

.cols div { margin: 0; }

.cols dt {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
}

.cols dd {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chart-wide {
  margin: 0.9rem 0 0;
}

.chart-wide figcaption {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.chart-wide svg {
  width: 100%;
  height: auto;
  display: block;
  background: #f7f8f5;
  border-radius: 8px;
}

.chart-wide .dot-ca { fill: #d23a3a; }
.chart-wide .dot-us { fill: #2474c1; }
.chart-wide .dot-current { fill: #c45c16; stroke: #173f35; stroke-width: 1.5; }
.chart-wide .trend { stroke: #5d6e68; stroke-dasharray: 4 3; fill: none; }
.chart-wide .dot-label {
  fill: #173f35;
  font-size: 10px;
  cursor: pointer;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  background: #f3f5f3;
  padding: 0.75rem;
  max-height: 260px;
  overflow: auto;
  border-radius: 8px;
}

.notes p { margin: 0 0 0.7rem; }
.notes p:last-child { margin-bottom: 0; }

.map-warning {
  margin: 0;
  padding: 0 1rem 0.8rem;
  color: #7c4a17;
  font-size: 0.9rem;
}

footer {
  padding: 1rem 0 1.4rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

footer a { font-weight: 600; text-decoration: none; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  #map { height: 420px; }
  .cols { grid-template-columns: 1fr; }
}
