/* Census Curiosities: mobile-first, typography-led, one accent colour. */

:root {
  --bg: #fbfaf7;
  --ink: #1d1c1a;
  --muted: #6b675f;
  --rule: #e4e0d8;
  --track: #efebe3;
  --accent: #b3261e;
  --accent-soft: #e9b8b3;
  --land: #ebe7de;
  --hl: #f6ebe7;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --measure: 40rem;
  --gutter: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --ink: #ece9e3;
    --muted: #a19c92;
    --rule: #34312d;
    --track: #2a2825;
    --accent: #f06b5f;
    --accent-soft: #7a3631;
    --land: #2c2a27;
    --hl: #2a201e;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
}

a { color: inherit; }

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---- Masthead ----------------------------------------------------------- */

.masthead,
main,
.colophon {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.masthead { padding-top: 2.5rem; padding-bottom: 1.5rem; }

.kicker {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.25rem, 9vw, 3.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.lede {
  margin: 1rem 0 0;
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.45;
}

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
}

.toc a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.25rem 0;   /* larger tap target without visual bulk */
}

.toc a:hover { color: var(--accent); }

/* ---- Ranking sections --------------------------------------------------- */

.ranking {
  padding-top: 2.5rem;
  scroll-margin-top: 0.5rem;
}

.ranking + .ranking,
.callout + .ranking {
  border-top: 1px solid var(--rule);
  margin-top: 2.5rem;
}

h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.75rem;
  line-height: 1.15;
}

h2 .anchor { text-decoration: none; }

h2 .anchor::after {
  content: "#";
  margin-left: 0.4rem;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.7em;
  opacity: 0;
  transition: opacity 0.15s;
}

h2 .anchor:hover::after,
h2 .anchor:focus-visible::after { opacity: 1; }

.dek {
  margin: 0.5rem 0 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  color: var(--ink);
}

.measure {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.measure strong { color: var(--ink); font-weight: 600; }

.measure [data-count] { white-space: nowrap; }

/* ---- Entries ------------------------------------------------------------ */

.entries {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.entry {
  display: grid;
  grid-template-columns: 1.75rem 1fr auto;
  grid-template-areas:
    "rank place value"
    "rank meta  meta"
    "rank bar   bar"
    "rank note  note";
  column-gap: 0.5rem;
  padding: 0.875rem 0;
  border-top: 1px solid var(--rule);
}

.entry:last-child { border-bottom: 1px solid var(--rule); }

.rank {
  grid-area: rank;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.6rem;
}

.place {
  grid-area: place;
  min-width: 0;
  font-family: var(--serif);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.place a {
  text-decoration: none;
  background-image: linear-gradient(var(--rule), var(--rule));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
}

.place a:hover {
  color: var(--accent);
  background-image: linear-gradient(var(--accent), var(--accent));
}

.value {
  grid-area: value;
  align-self: baseline;
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-align: right;
  white-space: nowrap;
}

.meta {
  grid-area: meta;
  margin-top: 0.125rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

.bar {
  grid-area: bar;
  position: relative;
  height: 0.375rem;
  margin-top: 0.5rem;
  background: var(--track);
  border-radius: 1px;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  border-radius: 1px;
}

.entry:not(:first-child) .bar-fill { background: var(--accent-soft); }

.bar-ref {
  position: absolute;
  top: -0.1875rem;
  bottom: -0.1875rem;
  width: 1px;
  background: var(--ink);
}

.note {
  grid-area: note;
  margin: 0.5rem 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9375rem;
  color: var(--ink);
}

.note:empty { display: none; }

/* Highlighted from the map (or by hovering the entry itself). The two side
   shadows widen the tint into the gutter without moving anything. */
.entry { transition: background-color 0.15s, box-shadow 0.15s; }

.entry.is-active {
  background: var(--hl);
  box-shadow: -0.5rem 0 0 var(--hl), 0.5rem 0 0 var(--hl);
}

.entry.is-active .rank { color: var(--accent); font-weight: 700; }
.entry.is-active .bar-fill { background: var(--accent); }

/* ---- Locator maps ------------------------------------------------------- */

/* The box sets the size; app.js fits Canada inside it, so space is reserved
   before the data arrives and nothing jumps. */
.map {
  width: 100%;
  max-width: 24rem;
  aspect-ratio: 7 / 6;
  margin: 1.25rem 0 0;
  /* Without this, the previous drawing's fixed height stops the box shrinking
     when the window narrows, so the map is never redrawn smaller. */
  overflow: hidden;
  position: relative;
}

.no-maps .map { display: none; }

.map-svg {
  display: block;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.map .land {
  fill: var(--land);
  stroke: var(--bg);
  stroke-width: 0.75;
  stroke-linejoin: round;
}

.map .leader { stroke: var(--muted); stroke-width: 0.75; }
.map .anchor { fill: var(--muted); }

.dots--numbered circle {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 1.25;
}

.dots--numbered text {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  pointer-events: none;
}

.dots--numbered .is-first circle { fill: var(--accent); }
.dots--numbered .is-first text { fill: var(--bg); }

/* Unnumbered dots for the callouts: many places, so small and see-through. */
.dots:not(.dots--numbered) circle {
  fill: var(--accent);
  fill-opacity: 0.6;
  stroke: var(--bg);
  stroke-width: 0.5;
}

.dot circle { transition: transform 0.15s; }
.dot.is-active circle { transform: scale(1.25); fill: var(--accent); fill-opacity: 1; }
.dots--numbered .is-active text { fill: var(--bg); }
.dots:not(.dots--numbered) .is-active circle { transform: scale(1.8); }

.map-svg.has-active .dot:not(.is-active),
.map-svg.has-active .leaders { opacity: 0.4; }

/* The label: HTML over the map, positioned by app.js. With a mouse it is
   display-only; after a tap it carries a "Census profile" link. */
.map-tip {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.75rem;
  line-height: 1.35;
  pointer-events: none;
}

.map-tip[hidden] { display: none; }
.map-tip.has-link { pointer-events: auto; }
.map-tip.is-measuring { white-space: nowrap; max-width: none !important; }

.tip-name { font-weight: 600; }
.tip-sub { color: var(--muted); white-space: nowrap; }
.is-stacked .tip-sep { display: none; }
.is-stacked .tip-sub { display: block; }

.tip-link {
  display: block;
  margin-top: 0.125rem;
  padding: 0.25rem 0;   /* comfortable tap target */
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.tip-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.map.is-pointing { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .entry, .dot circle { transition: none; }
}

/* ---- Callouts ----------------------------------------------------------- */

.callout {
  margin: 2.5rem 0 0;
  padding: 1.25rem 0 1.25rem 1rem;
  border-left: 3px solid var(--accent);
  font-family: var(--serif);
  font-size: 1.375rem;
  line-height: 1.3;
}

.callout-text { margin: 0; }

.callout .map { max-width: 20rem; }

.callout-foot {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.75rem;
  line-height: 1.4;
}

.callout strong { color: var(--accent); }

.callout-sub {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted);
}

/* ---- Loading and error status ------------------------------------------ */

.load-status {
  margin: 2rem 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.load-status.is-error {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--ink);
}

.retry {
  margin-left: 0.25rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.retry:hover { background: var(--accent); color: var(--bg); }

.retry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Footer ------------------------------------------------------------- */

.colophon {
  margin-top: 4rem;
  padding-top: 1.5rem;
  padding-bottom: 3rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.8125rem;
}

.colophon p { margin: 0 0 0.5rem; }

/* ---- Wider screens ------------------------------------------------------ */

@media (min-width: 40rem) {
  :root { --gutter: 1.5rem; }

  .masthead { padding-top: 4rem; }

  .entry {
    grid-template-columns: 2rem minmax(0, 1fr) 8rem 4.5rem;
    grid-template-areas:
      "rank place bar value"
      "rank meta  bar value"
      "rank note  note note";
    column-gap: 1rem;
  }

  .bar { align-self: center; margin-top: 0; }

  .callout { font-size: 1.5rem; }
}

@media (min-width: 60rem) {
  /* Wide enough for the list (long place names fit beside the bar) plus a map
     column; prose stays short. */
  :root {
    --measure: 68rem;
    --map-col: clamp(17rem, 28vw, 22rem);
  }

  /* Heading, text and list in the left column; the map sits beside them and
     stays in view while the list scrolls past. */
  .ranking,
  .callout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--map-col);
    column-gap: 3rem;
  }

  .ranking { align-items: start; }
  .ranking > * { grid-column: 1; }

  .ranking > .map {
    grid-column: 2;
    grid-row: 1 / span 4;
    position: sticky;
    top: 1.5rem;
    max-width: none;
    margin-top: 0.25rem;
  }

  .callout { align-items: center; }
  .callout .map { grid-column: 2; max-width: none; margin-top: 0; }
  .callout-foot { grid-column: 1 / -1; }

  .entry { grid-template-columns: 2rem minmax(0, 1fr) 11rem 4.5rem; }

  .lede, .dek, .callout-text, .colophon p { max-width: 38rem; }
}
