:root {
  --bg: #f4f1ea;
  --ink: #1b1b1a;
  --muted: #77726a;
  --rule: #ddd6c8;
  --accent: #1f2f5c;
  --panel: #fbf9f4;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171c28;
    --ink: #ece7db;
    --muted: #8d93a3;
    --rule: #2c3445;
    --accent: #b9c6ee;
    --panel: #1e2433;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head head" "nav main" "foot foot";
  column-gap: 28px;
  padding: 22px 32px 14px;
  max-width: 1500px;
  margin: 0 auto;
}

/* header */
header { grid-area: head; display: flex; align-items: center; gap: 24px; padding-bottom: 20px; }
h1 { font-size: 26px; font-weight: 400; letter-spacing: -0.01em; margin: 0; display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.mark { width: 15px; height: 15px; background: var(--accent); border-radius: 46% 54% 51% 49% / 53% 47% 55% 45%; transition: background .6s; }
.search { position: relative; margin-left: auto; width: min(320px, 100%); }
#q {
  width: 100%; background: none; border: 0; border-bottom: 1px solid var(--rule);
  padding: 6px 2px; font-size: 18px; outline: none; border-radius: 0;
}
#q::placeholder { color: var(--muted); font-style: italic; }
#q:focus { border-bottom-color: var(--ink); }
#q::-webkit-search-cancel-button { display: none; }
#results {
  position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px;
  list-style: none; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .08);
}
#results li { padding: 7px 10px; border-radius: 6px; cursor: pointer; line-height: 1.25; }
#results li small { display: block; color: var(--muted); font-size: 15px; }
#results li[aria-selected="true"], #results li:hover { background: var(--rule); }
#results li.none { color: var(--muted); font-style: italic; cursor: default; background: none; }
.quiet { color: var(--muted); font-size: 16px; white-space: nowrap; }
.quiet:hover { color: var(--ink); }

/* metrics */
#metrics { grid-area: nav; display: flex; flex-direction: column; gap: 2px; align-self: start; padding-top: 44px; }
#metrics button {
  display: flex; align-items: center; gap: 11px; padding: 5px 0; text-align: left;
  color: var(--muted); font-size: 18px; transition: color .2s;
}
#metrics button:hover { color: var(--ink); }
#metrics button i {
  width: 9px; height: 9px; flex: none; background: var(--sw);
  border-radius: 46% 54% 51% 49% / 53% 47% 55% 45%; opacity: .55; transition: transform .25s, opacity .25s;
}
#metrics button[aria-pressed="true"] { color: var(--ink); }
#metrics button[aria-pressed="true"] i { transform: scale(1.5); opacity: 1; }

/* main */
main { grid-area: main; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; }
.bar { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding-bottom: 10px; }
#place { margin: 0; font-size: 22px; }
#place small { color: var(--muted); font-size: 17px; margin-left: 8px; }
#scales { display: flex; gap: 18px; }
#scales button { color: var(--muted); font-size: 18px; padding: 2px 0; border-bottom: 1px solid transparent; }
#scales button:hover { color: var(--ink); }
#scales button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
#scales .sep { width: 1px; background: var(--rule); align-self: stretch; }

#stage { position: relative; min-height: 260px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); overflow: hidden; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity .35s; }
#c.dragging { cursor: grabbing; }
#stage.loading #c { opacity: .3; }
#status { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; text-align: center; color: var(--muted); font-style: italic; pointer-events: none; }
#status button { pointer-events: auto; text-decoration: underline; text-underline-offset: 3px; font-style: normal; color: var(--ink); }
#tip {
  position: absolute; z-index: 3; pointer-events: none; background: var(--panel); border: 1px solid var(--rule);
  border-radius: 8px; padding: 6px 11px 7px; line-height: 1.2; white-space: nowrap; box-shadow: 0 6px 20px rgb(0 0 0 / .07);
}
#tip b { display: block; font-weight: 500; font-size: 19px; }
#tip span { color: var(--muted); font-size: 15px; }
.zoom { position: absolute; right: 8px; bottom: 30px; display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--rule); border-radius: 999px; padding: 2px 8px; }
.zoom button { min-width: 26px; height: 28px; color: var(--muted); font-size: 19px; line-height: 1; }
.zoom button.word { font-size: 16px; padding: 0 4px; }
.zoom button:hover { color: var(--ink); }

.legend { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 12px; font-size: 16px; color: var(--muted); min-height: 40px; }
#ramp { display: inline-flex; gap: 5px; align-items: center; }
#ramp i { width: 10px; height: 10px; border-radius: 46% 54% 51% 49% / 53% 47% 55% 45%; }
#ramp i:nth-child(even) { border-radius: 53% 47% 46% 54% / 48% 55% 45% 52%; }
#caption { margin: 0 0 0 auto; font-style: italic; text-align: right; }

footer { grid-area: foot; padding-top: 10px; display: flex; align-items: baseline; gap: 28px; font-size: 16px; color: var(--muted); }
.link { color: var(--muted); white-space: nowrap; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 4px; }
.link:hover { color: var(--ink); }

/* about the data: a sheet that rises over the page */
dialog {
  width: min(1080px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 48px);
  margin: auto auto 24px; padding: 0; border: 1px solid var(--rule); border-radius: 16px;
  background: var(--panel); color: var(--ink); box-shadow: 0 30px 80px rgb(0 0 0 / .18);
  opacity: 0; transform: translateY(16px); transition: opacity .25s, transform .3s, overlay .3s allow-discrete, display .3s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
@starting-style { dialog[open] { opacity: 0; transform: translateY(16px); } }
dialog::backdrop { background: rgb(10 12 20 / .28); }
.sheet { padding: 26px 36px 34px; overflow: auto; max-height: calc(100dvh - 50px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 14px; margin-bottom: 22px; border-bottom: 1px solid var(--rule); }
.sheet h2 { margin: 0; font-size: 24px; font-weight: 400; }
.close { width: 38px; height: 38px; border-radius: 50%; font-size: 26px; line-height: 1; color: var(--muted); border: 1px solid var(--rule); }
.close:hover { color: var(--ink); border-color: var(--ink); }
.cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 40px; }
.cols h3 { margin: 0 0 10px; font-size: 14px; font-weight: 500; letter-spacing: .06em; color: var(--muted); }
.cols p { margin: 0 0 12px; font-size: 16.5px; font-weight: 300; line-height: 1.55; color: color-mix(in srgb, var(--ink) 82%, var(--bg)); }

/* radar */
#radar { position: absolute; inset: 0; z-index: 1; background: var(--bg); }
#radar[hidden] { display: none; }
#radar .leaflet-tile-pane { filter: sepia(.25) opacity(.7); }
#radar[data-mode="dark"] .leaflet-tile-pane { filter: hue-rotate(195deg) sepia(.15) opacity(.75); }
#radar .leaflet-labels-pane { opacity: .8; }
.radar-dots { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 450; pointer-events: none; }
#radar .here { stroke: var(--ink); }
#radar .leaflet-control-attribution { background: color-mix(in srgb, var(--bg) 80%, transparent); color: var(--muted); font: 12px/1.4 "Newsreader", Georgia, serif; }
#radar .leaflet-control-attribution a { color: var(--muted); }
.leaflet-container { font-family: inherit; }
#tip { z-index: 600; }
.zoom { z-index: 600; }
body.on-radar #metrics button { opacity: .45; }
body.on-radar #metrics button[aria-pressed="true"] i { transform: none; opacity: .55; }

@media (max-width: 820px) {
  body { font-size: 17px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "head" "nav" "main" "foot"; padding: 14px 16px 10px; }
  header { flex-wrap: wrap; gap: 10px 16px; padding-bottom: 12px; }
  h1 { font-size: 22px; }
  .search { order: 3; width: 100%; margin: 0; }
  #units { margin-left: auto; }
  #metrics { flex-direction: row; gap: 18px; overflow-x: auto; padding: 0 16px 10px; margin: 0 -16px; scrollbar-width: none; }
  #metrics::-webkit-scrollbar { display: none; }
  #metrics button { white-space: nowrap; font-size: 17px; }
  #place { font-size: 19px; }
  #place small { font-size: 15px; }
  #scales { gap: 14px; }
  #scales button { font-size: 17px; }
  #caption { margin-left: 0; text-align: left; width: 100%; }
  footer { flex-direction: column; gap: 6px; }
  dialog { margin: auto 0 0; width: 100vw; border-radius: 16px 16px 0 0; border-bottom: 0; max-height: 88dvh; }
  .sheet { padding: 20px 20px 28px; max-height: 88dvh; }
  .cols { grid-template-columns: 1fr; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
