:root {
  --ink: #1b2430;
  --muted: #5b6776;
  --line: #d9dee5;
  --panel: #ffffff;
  --declining: #c0392b;
  --rising: #1f6fb2;
  --stable: #8a94a0;
  --short: #c9ced6;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: #f4f6f8;
}
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1.5rem;
  padding: 0.6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.tagline { margin: 0.1rem 0 0; font-size: 0.85rem; color: var(--muted); }
.topnav { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.85rem; }
.topnav a { color: #1f6fb2; text-decoration: none; }
.topnav a:hover { text-decoration: underline; }
.stage { position: relative; flex: 1; min-height: 320px; }
#map { position: absolute; inset: 0; }
.map-status {
  position: absolute; left: 50%; top: 1rem; transform: translateX(-50%); margin: 0;
  padding: 0.5rem 0.8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  font-size: 0.9rem; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* Legend and well panel */
.card {
  position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); padding: 0.75rem 0.9rem; font-size: 0.85rem;
}
.card h2 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.fine { margin: 0.4rem 0 0; font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
/* Top right, over Hudson Bay, so it does not hide southern Ontario. */
.legend { right: 3.4rem; top: 0.6rem; width: 15.5rem; max-height: calc(100% - 2.6rem); overflow-y: auto; }
.switch { display: flex; margin-bottom: 0.5rem; }
.switch button {
  flex: 1; padding: 0.3rem 0.4rem; font: inherit; font-size: 0.8rem; cursor: pointer;
  background: #fff; color: var(--ink); border: 1px solid #9aa4b1;
}
.switch button:first-child { border-radius: 5px 0 0 5px; }
.switch button:last-child { border-radius: 0 5px 5px 0; border-left: 0; }
.switch button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.legend-list { list-style: none; margin: 0 0 0.5rem; padding: 0; }
.legend-list li { display: flex; align-items: center; gap: 0.45rem; padding: 0.12rem 0; }
.legend-list .dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.35); flex: none; }
.legend-list .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.backdrop { margin-top: 0.6rem; padding-top: 0.55rem; border-top: 1px solid var(--line); }
.ramp { height: 0.6rem; margin-top: 0.4rem; border: 1px solid rgba(0, 0, 0, 0.25); border-radius: 3px; }
.ramp-ends { display: flex; justify-content: space-between; margin-top: 0.15rem; font-size: 0.72rem; color: var(--muted); }

.panel { left: 0.75rem; top: 0.75rem; bottom: 1.75rem; width: 23rem; max-width: calc(100% - 1.5rem); overflow-y: auto; }
.panel .close {
  position: absolute; right: 0.4rem; top: 0.3rem; border: 0; background: none; font-size: 1.4rem;
  line-height: 1; cursor: pointer; color: var(--muted); padding: 0.2rem 0.45rem;
}
.panel h2 { padding-right: 1.6rem; }
.sub { margin: 0; color: var(--muted); }
.trendline { margin: 0.6rem 0 0.2rem; font-weight: 600; }
.trendline .pill { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; color: #fff; font-size: 0.8rem; margin-right: 0.35rem; }
.chart { margin-top: 0.4rem; min-height: 190px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis text { font-size: 10px; fill: var(--muted); }
.chart .axis path, .chart .axis line { stroke: #b8c0ca; }
.chart .grid line { stroke: #e7ebf0; }
.chart .zero { stroke: #7b8794; stroke-dasharray: 3 3; }
.chart .level { fill: none; stroke: #1b2430; stroke-width: 1.2; }
.chart .fit { fill: none; stroke-width: 2; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.8rem; margin: 0.7rem 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

@media (max-width: 720px) {
  .legend { left: 0.5rem; right: 0.5rem; top: auto; bottom: 2.4rem; width: auto; max-height: 55%; }
  .legend .fine { display: none; }
  .backdrop { margin-top: 0.4rem; padding-top: 0.4rem; }
  .panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-width: none; max-height: 62%; border-radius: 12px 12px 0 0; z-index: 3; }
}
