/* kenyaciv — chrome in the visual language of karpathy.ai/usaciv (MIT).
   Dark navy UI, gold accents, parchment map. The map keeps the attention. */

:root {
  --bg: #0b1220;
  --header: #0c1520;
  --panel: rgba(12, 20, 30, 0.94);
  --tile: #152232;
  --control: #16212e;
  --border: #1e2a38;
  --border2: #2a3a4c;
  --text: #ffffff;
  --text2: #a7b4c2;
  --text3: #6e7d8d;
  --gold: #d9a93a;
  --gold-bright: #e8c05a;
  --gold-pale: #f2dfa6;
  --green: #5fd08a;
  --red: #f0716a;
  --sans: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text); font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

/* ---- top bar: brand, national KPI strip, search, actions ---- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 7;
  display: flex; align-items: center; gap: 14px; height: 46px; padding: 0 12px;
  background: rgba(12, 21, 32, 0.97); border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
#brand { display: flex; align-items: center; gap: 7px; flex: none; }
.brand-mark { color: var(--gold-bright); font-size: 11px; line-height: 1; }
#brand h1 {
  margin: 0; font: 700 14px/1 var(--sans); letter-spacing: 0.2em; color: #fff; white-space: nowrap;
}
#brand h1 span { color: var(--gold); letter-spacing: 0.04em; font-weight: 500; }

#kpis {
  display: flex; align-items: center; gap: 13px; flex: 1; min-width: 0; overflow: hidden;
}
.kpi {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  font-size: 11.5px; color: #dfe6ee; font-variant-numeric: tabular-nums; white-space: nowrap;
  cursor: default;
}
.kpi i { font-style: normal; font-size: 12px; line-height: 1; filter: saturate(0.9); }
.kpi b { font-weight: 600; letter-spacing: 0.01em; }

/* ---- search ---- */
#search-wrap {
  position: relative; display: flex; align-items: center; gap: 6px; flex: none;
  width: 252px; height: 26px; padding: 0 6px 0 8px;
  background: var(--control); border: 1px solid #243447; border-radius: 6px;
}
#search-wrap:focus-within { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(217, 169, 58, 0.14); }
.search-icon { width: 12px; height: 12px; color: var(--text3); flex: none; }
#search {
  flex: 1; min-width: 0; background: none; border: 0; outline: 0;
  color: #fff; font: 12px var(--sans);
}
#search::placeholder { color: #7c8a9a; }
#search::-webkit-search-cancel-button { display: none; }
#search-wrap kbd {
  font: 10px/1 var(--mono); color: var(--text3); flex: none;
  border: 1px solid #2c3d50; border-radius: 3px; padding: 2px 4px;
}
#search-results {
  position: absolute; top: 32px; left: 0; right: 0; z-index: 20;
  max-height: 300px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border2); border-radius: 8px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.55); backdrop-filter: blur(12px);
}
.sr-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  font-size: 12px; color: #dfe7ef; cursor: pointer;
}
.sr-item:hover, .sr-item.active { background: #1b2b3d; }
.sr-item .sr-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-item .sr-type {
  font: 600 8.5px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--text3);
}
.sr-empty { padding: 8px 10px; font-size: 11.5px; color: var(--text3); }

/* ---- action buttons ---- */
#actions { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 26px; padding: 0; list-style: none;
  background: var(--control); border: 1px solid #243447; border-radius: 6px;
  color: var(--text2); cursor: pointer; font: 600 12px var(--sans);
}
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { color: #fff; border-color: #3a4e63; }
.icon-btn svg { width: 14px; height: 14px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  background: var(--control); border: 1px solid #243447; border-radius: 6px;
  color: var(--text2); font: 600 11.5px var(--sans); cursor: pointer;
}
.pill-btn:hover { color: #fff; border-color: #3a4e63; }
.pill-btn svg { width: 13px; height: 13px; }
.pill-btn[aria-pressed="true"] { color: #fff; border-color: var(--gold); background: #22303f; }

/* ---- layers menu ---- */
#layers-menu { position: relative; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 7px); width: 178px;
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border2); border-radius: 8px;
  backdrop-filter: blur(12px); box-shadow: 0 16px 38px rgba(0, 0, 0, 0.55);
}
.menu-body label {
  display: flex; align-items: center; gap: 8px; padding: 3px 0;
  cursor: pointer; font-size: 11.5px; color: #cfd9e3;
}
.menu-body label:hover { color: #fff; }
.menu-body input { accent-color: var(--gold); width: 12px; height: 12px; }

/* ---- bottom toolbar: a floating segmented lens bar ---- */
#toolbar {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 7;
  display: flex; align-items: stretch; max-width: calc(100vw - 24px); overflow-x: auto;
  padding: 2px; background: rgba(16, 26, 38, 0.95);
  border: 1px solid var(--border2); border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); backdrop-filter: blur(12px);
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
.tb-item {
  display: flex; align-items: center; gap: 6px; flex: none; height: 28px; padding: 0 10px;
  background: none; border: 0; border-radius: 5px; cursor: pointer; white-space: nowrap;
  color: #9fb0c2; font: 500 11px var(--sans); letter-spacing: 0.01em;
}
.tb-item + .tb-item { box-shadow: inset 1px 0 0 #22303f; }
.tb-item:hover { color: #dfe7ef; background: #1a2836; }
.tb-item.active { color: #fff; background: #2a3b4e; }
.tb-item i { font-style: normal; font-size: 12px; line-height: 1; }
.tb-item .chev { color: var(--text3); font-size: 8px; margin-left: 1px; }
.tb-item.active .chev { color: #cfd9e3; }

#lens-pop {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); z-index: 8;
  min-width: 208px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border2); border-radius: 8px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.55); backdrop-filter: blur(12px);
}
.lp-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 9px;
  background: none; border: 0; border-radius: 5px; cursor: pointer;
  color: #cfd9e3; font: 500 11.5px var(--sans); text-align: left;
}
.lp-item:hover { background: #1b2b3d; color: #fff; }
.lp-item.active { color: #fff; background: #2a3b4e; }
.lp-item .lp-group {
  margin-left: auto; font: 600 8.5px var(--sans); letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text3);
}

/* ---- zoom + compass: a small floating stack under the topbar, LEFT edge ----
   The left gutter is the only band that stays clear in every state: the county card and the
   almanac both open on the right, the legend sits bottom-left and the lens toolbar is centred. */
#zoombar {
  position: absolute; left: 12px; top: 56px; z-index: 9;
  display: flex; flex-direction: column; align-items: stretch;
  padding: 2px; background: rgba(16, 26, 38, 0.95);
  border: 1px solid var(--border2); border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45); backdrop-filter: blur(12px);
}
.zoom-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; padding: 0;
  background: none; border: 0; border-radius: 5px; cursor: pointer;
  color: #9fb0c2; font: 600 15px/1 var(--sans);
}
.zoom-btn + .zoom-btn, #zoom-step + .zoom-btn { box-shadow: inset 0 1px 0 #22303f; }
.zoom-btn:hover { color: #fff; background: #1a2836; }
.zoom-btn:active { background: #2a3b4e; }
.zoom-btn:disabled { color: #48566a; cursor: default; background: none; }
.zoom-btn svg { width: 14px; height: 14px; }
#zoom-step {
  padding: 2px 0 3px; text-align: center;
  font: 500 8.5px var(--mono); letter-spacing: 0.02em; color: var(--text3);
  font-variant-numeric: tabular-nums;
}

/* ---- legend: quiet card, bottom-RIGHT, stacked above the scale bar ----
   The scale bar is drawn on the canvas (art.js drawScaleBar) at x = cw-24, y = ch-26, so the legend
   sits in the same right-hand column and clears it. The county card, almanac and help card share
   that column, so below 1380px the legend tucks under them (max-height, see the media block). */

#legend {
  position: absolute; right: 12px; bottom: 46px; z-index: 4; width: 238px;
  padding: 11px 12px 10px;
  background: var(--panel); border: 1px solid var(--border2); border-radius: 8px;
  backdrop-filter: blur(10px); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
}
#legend h2 {
  margin: 0 0 8px; font: 600 9.5px var(--sans); letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--text3);
}
#legend-body .ramp {
  height: 10px; border-radius: 2px; border: 1px solid rgba(255, 255, 255, 0.14);
}
#legend-body .ramp-labels {
  display: flex; justify-content: space-between; margin-top: 4px;
  color: #dfe7ef; font-size: 11px; font-variant-numeric: tabular-nums;
}
#legend-body .ramp-unit {
  margin-top: 2px; color: var(--text3); font-size: 9.5px;
  letter-spacing: 0.06em; text-transform: uppercase;
}
#legend-body .ramp-note {
  margin-top: 3px; color: var(--gold); font-size: 9.5px; letter-spacing: 0.02em;
}
#legend-body .cat {
  display: flex; align-items: center; gap: 7px; margin: 3px 0;
  font-size: 11px; color: #cdd7e1;
}
#legend-body .cat i {
  width: 11px; height: 11px; border-radius: 2px; flex: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
}
#legend-body .unknown {
  margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--border);
  color: var(--text3); font-size: 10px;
}
#legend-body .unknown i {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  vertical-align: -1px; margin-right: 4px;
}
#legend-source {
  margin: 7px 0 0; color: #8b99a7; font-size: 9.5px; line-height: 1.45;
  padding-top: 6px; border-top: 1px solid var(--border);
}
#legend-credit { margin: 5px 0 0; color: #5f6e7d; font-size: 9px; line-height: 1.4; }
#legend { overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2a3a4c transparent; }
#legend::-webkit-scrollbar { width: 6px; }
#legend::-webkit-scrollbar-thumb { background: #2a3a4c; border-radius: 3px; }

/* The right rail is one column: topbar gap to scale bar. Everything anchored there sizes against it. */
#rail-space {
  position: absolute; right: 12px; top: 56px; bottom: 38px; width: 362px;
  visibility: hidden; pointer-events: none; z-index: -1;
}


/* ---- floating cards: county card, almanac, help ---- */
#info, #almanac, #help {
  position: absolute; z-index: 8; color: var(--text2);
  background: var(--panel); border: 1px solid var(--border2); border-radius: 10px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55); backdrop-filter: blur(14px);
}
#info, #almanac {
  top: 56px; right: 12px; width: 362px;
  /* The share of the rail column this card may use. `#rail-space` reserves the rest for the legend,
     so a card and the legend under it always fit the column instead of colliding. A shorter card
     leaves the spare room empty; a taller one scrolls rather than reaching the floor. */
  max-height: calc(100vh - 94px - 14rem);
  overflow-y: auto; padding: 16px;
  scrollbar-width: thin; scrollbar-color: #2a3a4c transparent;
}
#info::-webkit-scrollbar, #almanac::-webkit-scrollbar { width: 8px; }
#info::-webkit-scrollbar-thumb, #almanac::-webkit-scrollbar-thumb {
  background: #2a3a4c; border-radius: 4px;
}
.card-close {
  position: absolute; top: 12px; right: 12px; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  background: #1c2836; border: 1px solid var(--border2); border-radius: 50%;
  color: var(--text2); font-size: 10px; cursor: pointer; line-height: 1;
}
.card-close:hover { color: #fff; border-color: #3a4e63; }

.micro {
  margin: 0 0 3px; font: 600 9px var(--sans); letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--text3);
}
#info h2, #almanac h2, #help h2 {
  margin: 0 0 5px; font: 700 23px/1.12 var(--sans); letter-spacing: 0.11em;
  text-transform: uppercase; color: #fff; padding-right: 26px;
}
#info-sub, #almanac-sub {
  margin: 0 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
  font: 11px var(--mono); color: #8a99a9; letter-spacing: 0.02em;
}
#info-pop { margin: 0 0 2px; font-size: 12px; color: #c9d4df; }
#info-pop b { font-size: 15px; color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
#info-delta { margin: 0 0 4px; font-size: 11px; color: var(--text2); }
#info-delta .up { color: var(--green); }
#info-delta .down { color: var(--red); }

/* rank tiles */
#info-ranks {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0 2px;
}
.rank-tile {
  padding: 7px 4px 6px; text-align: center;
  background: var(--tile); border: 1px solid #26374a; border-radius: 6px;
}
.rank-tile .rt-icon { font-size: 12px; line-height: 1; }
.rank-tile .rt-val {
  display: block; margin-top: 3px; color: #fff;
  font: 700 12.5px var(--sans); font-variant-numeric: tabular-nums;
}
.rank-tile .rt-label {
  display: block; margin-top: 2px; color: var(--text3);
  font: 600 7.5px var(--sans); letter-spacing: 0.09em; text-transform: uppercase;
}
.rank-tile .rt-rank { display: block; margin-top: 3px; font: 9px var(--sans); color: #6e7d8d; }

/* section headings */
.sec {
  margin: 14px 0 6px; padding-top: 10px; border-top: 1px solid var(--border);
  font: 600 9px var(--sans); letter-spacing: 0.15em; text-transform: uppercase; color: var(--text3);
}

/* label / value / compare rows */
.row { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; font-size: 11.5px; }
.row .r-label { flex: 1; min-width: 0; color: #a7b4c2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-val { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.row .r-cmp {
  min-width: 66px; text-align: right; color: var(--text3);
  font-size: 10px; font-variant-numeric: tabular-nums;
}

/* sector bars */
.sector {
  display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; padding: 5px 0 4px;
  font-size: 11.5px;
}
.sector .s-name {
  color: #c3ced9; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sector .s-val { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.sector .s-bar { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: #1b2836; overflow: hidden; }
.sector .s-bar i {
  display: block; height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #b98a2e, #e8c05a);
}
#info-note { margin: 12px 0 0; color: var(--text3); font-size: 10px; line-height: 1.45; }

/* almanac list */
.alm-head {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 4px 6px 6px;
  font: 600 8.5px var(--sans); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text3); border-bottom: 1px solid var(--border);
}
.alm-row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center;
  width: 100%; padding: 5px 6px; background: none; border: 0; border-radius: 5px;
  color: #cfd9e3; font: 11.5px var(--sans); text-align: left; cursor: pointer;
  position: relative;
}
.alm-row:hover { background: #1b2b3d; color: #fff; }
.alm-row .alm-rank { color: var(--text3); font-variant-numeric: tabular-nums; font-size: 10px; }
.alm-row .alm-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alm-row .alm-val { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 11px; }
.alm-row .alm-bar {
  position: absolute; left: 28px; right: 8px; bottom: 1px; height: 2px;
  background: #1b2836; border-radius: 1px; overflow: hidden;
}
.alm-row .alm-bar i { display: block; height: 100%; background: #b98a2e; }
.alm-unknown { color: var(--text3); font-weight: 400; font-size: 10px; }

/* help card */
#help {
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px)); padding: 18px;
}
#help h2 { font-size: 19px; letter-spacing: 0.08em; }
.help-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 7px 14px;
  margin: 12px 0 0; font-size: 12px; color: #c9d4df;
}
.help-grid kbd {
  display: inline-block; padding: 2px 6px; border: 1px solid #2c3d50; border-radius: 4px;
  background: var(--control); font: 10.5px var(--mono); color: #dfe7ef;
}
.help-note {
  margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 10.5px; line-height: 1.55; color: var(--text3);
}

/* ---- tooltip + toast ---- */
#tooltip {
  position: absolute; z-index: 9; pointer-events: none; padding: 6px 9px;
  max-width: 260px; background: rgba(8, 16, 26, 0.96);
  border: 1px solid var(--border2); border-radius: 6px;
  font-size: 11.5px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}
#tooltip .tt-name { font-family: var(--serif); letter-spacing: 0.05em; color: var(--gold-pale); }
#tooltip .tt-val { color: #e8eef4; font-variant-numeric: tabular-nums; }
#tooltip .tt-unknown { color: var(--text3); font-style: italic; }
#tooltip .tt-sub { color: var(--text3); font-size: 10.5px; }

#toast {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 12;
  padding: 8px 14px; background: rgba(12, 20, 30, 0.97);
  border: 1px solid var(--border2); border-radius: 6px;
  font-size: 11.5px; color: #e8eef4; box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
}

/* The floating toolbar is centred and now reaches the legend's right-hand column, so below this
   width the legend lifts clear of it and caps its height so it never runs up into the county card. */
@media (max-width: 1380px) {
  /* cap: viewport - topbar 56 - gap 8 - toolbar 48 - legend gap 56 */
  #legend { bottom: 56px; }
  #toolbar { max-width: calc(100vw - 24px); }
}

/* ---- narrow screens ---- */
@media (max-width: 1180px) {
  #kpis .kpi:nth-child(n + 5) { display: none; }
}
@media (max-width: 960px) {
  #kpis .kpi:nth-child(n + 3) { display: none; }
  #search-wrap { width: 190px; }
  #legend { width: 210px; }
}
@media (max-width: 760px) {
  #topbar { gap: 8px; padding: 0 8px; }
  #brand h1 { font-size: 12px; letter-spacing: 0.14em; }
  #kpis { display: none; }
  #search-wrap { width: 150px; }
  #search-wrap kbd { display: none; }
  .pill-btn span { display: none; }
  #info, #almanac { left: 50px; right: 8px; width: auto; top: 52px; }
  #legend { right: 8px; left: auto; bottom: 48px; width: 200px; }
  #toolbar { bottom: 6px; }
  #toolbar .tb-item { padding: 0 8px; }
  #zoombar { left: 8px; top: 52px; right: auto; }
  .zoom-btn { width: 28px; }
}
