:root {
  --ink: #efe4c6;
  --ink-dim: #b9ab88;
  --gold: #c9a45c;
  --gold-bright: #ecd08e;
  --panel: rgba(16, 25, 35, 0.98);
  --panel-2: rgba(28, 41, 56, 0.98);
  --line: rgba(201, 164, 92, 0.55);
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
  --topbar-h: 40px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d2a47; color: var(--ink); font-family: var(--sans); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--ink-dim); }
svg.icon { display: inline-block; flex: none; }
.emoji { display: inline-block; line-height: 1; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }

.figure-citation {
  display: block; width: fit-content; max-width: 100%; min-height: 26px; padding: 2px 0;
  border: 0; background: transparent; color: var(--gold-bright); font: 12px/1.25 var(--sans);
  text-align: left; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.figure-citation-dialog {
  width: min(28rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto;
  margin: auto; padding: clamp(16px, 4vw, 24px); color: var(--ink); font: 15px/1.5 var(--sans);
}
.figure-citation-dialog::backdrop { background: rgba(6, 12, 20, .68); }
.figure-citation-header, .figure-citation-actions, .figure-citation-source { display: flex; align-items: center; gap: 12px; }
.figure-citation-header { justify-content: space-between; }
.figure-citation-header h2 { margin: 0; font: 600 22px/1.2 var(--serif); }
.figure-citation-close { min-width: 40px; min-height: 40px; border: 0; background: transparent; font-size: 24px; cursor: pointer; }
.figure-citation-text { margin: 12px 0; padding-left: 12px; border-left: 2px solid var(--gold); white-space: pre-line; overflow-wrap: anywhere; }
.figure-citation-source { flex-wrap: wrap; justify-content: space-between; color: var(--ink-dim); font-size: 12px; }
.figure-citation-source a { display: inline-flex; align-items: center; min-height: 32px; color: var(--gold-bright); text-underline-offset: 3px; }
.figure-citation-actions { margin-top: 14px; flex-wrap: wrap; font-size: 13px; }
.figure-citation-copy { min-height: 42px; padding: 7px 16px; background: var(--gold-bright); color: #17212b; border: 0; border-radius: 4px; font-weight: 650; cursor: pointer; }
.figure-citation-dialog textarea { margin-top: 12px; width: 100%; padding: 8px; font: 14px/1.4 var(--sans); color: var(--ink); background: #101923; border: 1px solid var(--line); }
@media (pointer: coarse) {
  .figure-citation { min-height: 44px; }
  .figure-citation-close, .figure-citation-copy, .figure-citation-source a { min-height: 44px; }
}

#map { position: fixed; inset: 0; width: 100%; height: 100%; cursor: grab; display: block; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map-hover { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; display: block; z-index: 1; }

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 8px 24px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,235,190,.08);
  border-radius: 6px;
}

.icon-btn {
  display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0; cursor: pointer;
  background: rgba(0,0,0,.3); border: 1px solid rgba(201,164,92,.45); border-radius: 50%; color: var(--ink-dim);
}
.icon-btn:hover { color: var(--gold-bright); border-color: var(--gold); }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 0 12px;
  background: linear-gradient(180deg, #24364a, #131e2a);
  border-bottom: 1px solid var(--gold);
  box-shadow: 0 2px 10px rgba(0,0,0,.5), inset 0 -3px 0 rgba(0,0,0,.25);
  font-variant-numeric: tabular-nums;
}
.brand {
  font-family: var(--serif); font-size: 16px; line-height: inherit; font-weight: bold;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold-bright); white-space: nowrap;
  display: flex; align-items: center; flex: none;
  background: none; border: 0; padding: 0; margin: 0; border-radius: 4px; cursor: pointer;
}
.brand:hover .brand-emblem svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.7)) brightness(1.08); }
.brand:hover .brand-text { color: #fff6d6; }
.brand:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
/* The emblem is an inline SVG red hex (index.html): no badge background of its own. */
.brand-emblem { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 6px; flex: none; }
.brand-emblem svg { display: block; width: 24px; height: 24px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.55)); }
.yields { display: flex; gap: 14px; flex: none; }
.yield {
  position: relative; display: flex; align-items: center; gap: 5px; font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer; border-radius: 4px;
  background: none; border: 1px solid transparent; padding: 2px 4px; margin: 0 -5px; line-height: 20px; font-variant-numeric: tabular-nums;
}
.yield .ico { display: inline-flex; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
/* The caret sits over the button's bottom padding (out of the flex flow), so the bar is exactly as wide as before. */
.yield .caret { position: absolute; left: 50%; bottom: 0; margin-left: -3.5px; width: 0; height: 0; border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; border-top: 3px solid var(--gold); opacity: .45; transition: transform .15s, opacity .15s; pointer-events: none; }
.yield:hover { background: rgba(201,164,92,.12); border-color: rgba(201,164,92,.35); }
.yield:hover .caret { opacity: 1; }
.yield.open { background: linear-gradient(180deg, rgba(90,74,36,.85), rgba(58,47,21,.85)); border-color: var(--gold-bright); }
.yield.open .caret { opacity: 1; transform: rotate(180deg); border-top-color: var(--gold-bright); }
.spacer { flex: 1; min-width: 0; }
.turn { font-family: var(--serif); color: var(--ink-dim); font-size: 13px; white-space: nowrap; flex: none; }
.turn b { color: var(--gold-bright); }
.tb-buttons { display: flex; gap: 6px; flex: none; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none;
  background: linear-gradient(180deg, #3a5068, #223244); border: 1px solid var(--gold); border-radius: 4px;
  padding: 4px 10px; cursor: pointer; font-family: var(--serif); font-size: 13px; color: var(--gold-bright); line-height: 18px;
  box-shadow: inset 0 1px 0 rgba(255,235,190,.15), 0 1px 2px rgba(0,0,0,.5);
}
.btn:hover { background: linear-gradient(180deg, #4a6584, #2b4057); }
.btn[aria-expanded="true"] { background: linear-gradient(180deg, #5a4a24, #3a2f15); }
.btn-icon { padding: 4px 7px; }

/* search */
.search { position: relative; display: flex; align-items: center; flex: 0 1 262px; min-width: 150px; }
.search-ic { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--ink-dim); display: inline-flex; pointer-events: none; }
#search-input {
  width: 100%; height: 28px; padding: 0 34px 0 28px; border-radius: 14px; text-overflow: ellipsis; font: 13px var(--sans); color: var(--ink);
  background: rgba(0,0,0,.35); border: 1px solid rgba(201,164,92,.5); outline: none;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5);
}
#search-input::placeholder { color: rgba(185,171,136,.75); }
#search-input:focus { border-color: var(--gold-bright); background: rgba(0,0,0,.5); }
#search-input::-webkit-search-cancel-button { display: none; }
.search-kbd { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); pointer-events: none; }
#search-input:focus ~ .search-kbd { display: none; }
kbd {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 3px; font: 11px/16px var(--sans); text-align: center;
  color: var(--gold-bright); background: rgba(255,235,190,.08); border: 1px solid rgba(201,164,92,.5); border-bottom-width: 2px;
}
.search-results { position: fixed; z-index: 40; max-height: min(420px, 70vh); overflow-y: auto; padding: 4px; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.sr-item.sel { background: linear-gradient(90deg, rgba(201,164,92,.28), rgba(201,164,92,.08)); }
.sr-ic { color: var(--gold); display: inline-flex; }
.sr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sr-main b { font-family: var(--serif); color: var(--gold-bright); font-weight: normal; font-size: 14px; }
.sr-sub { color: var(--ink-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-item.sel .sr-sub { color: var(--ink); }
.sr-pop { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.sr-empty { padding: 10px; color: var(--ink-dim); font-size: 13px; }

/* share popover + toast */
.share-pop { position: fixed; z-index: 40; width: 250px; padding: 8px; }
.sp-title { font-family: var(--serif); color: var(--gold); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; padding: 2px 6px 6px; }
.sp-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px; border-radius: 4px; cursor: pointer; background: none; border: 1px solid transparent; color: var(--ink); font-size: 13px; }
.sp-item svg { color: var(--gold-bright); }
.sp-item:hover, .sp-item:focus-visible { background: rgba(201,164,92,.15); border-color: rgba(201,164,92,.35); }
.sp-item .muted { font-size: 11px; margin-left: 4px; }
.sp-status { font-size: 12px; color: var(--ink-dim); padding: 4px 8px 0; min-height: 0; }
.sp-status:empty { display: none; }
.sp-url { width: 100%; margin-top: 6px; font: 12px var(--sans); padding: 5px; color: var(--ink); background: rgba(0,0,0,.4); border: 1px solid var(--line); border-radius: 3px; }
.toast {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 45; padding: 7px 14px; border-radius: 16px;
  background: rgba(16,25,35,.96); border: 1px solid var(--gold); color: var(--gold-bright); font: 13px var(--serif); letter-spacing: .04em;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}

/* ---------- top-bar reports (ui/yieldReport.js) ---------- */
.yield-report {
  --yc: var(--gold-bright);
  position: fixed; z-index: 28; width: 450px; max-width: calc(100vw - 16px); max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px);
  overflow-y: auto; overscroll-behavior: contain; padding: 0 0 12px; outline: none;
  border: 1px solid var(--gold); border-top: 3px solid var(--gold);
  box-shadow: 0 0 0 1px rgba(0,0,0,.7), inset 0 0 0 1px rgba(255,235,190,.07), 0 14px 34px rgba(0,0,0,.6);
}
.yr-head { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,235,190,.07), transparent); }
.yr-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, var(--yc), transparent 70%); opacity: .7; }
.yr-ic { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 35%, #2a3c52, #121b26); border: 2px solid var(--gold); box-shadow: 0 0 0 1px #120d06, inset 0 0 6px rgba(0,0,0,.6); }
.yr-ic svg, .yr-ic .emoji { filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
.yr-titles { flex: 1; min-width: 0; }
.yr-kind { font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); }
.yr-head h2 { margin: 0; font: normal 21px var(--serif); letter-spacing: .08em; text-transform: uppercase; color: var(--gold-bright); line-height: 1.15; }
.yr-close { flex: none; align-self: flex-start; }
.yr-total { padding: 10px 16px 2px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.yr-total > b { font: bold 34px/1 var(--serif); letter-spacing: .02em; text-shadow: 0 2px 3px rgba(0,0,0,.6); font-variant-numeric: tabular-nums; }
/* The total's unit (residents, stalls, ha, workers, students, sites), smaller beside the figure. */
.yr-total .yr-unit { font: normal 14px var(--serif); letter-spacing: .04em; color: var(--ink-dim); text-shadow: none; }
.yr-ctx { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--ink); line-height: 1.5; flex: 1; min-width: 180px; }
.yr-ctx li::before { content: "◆"; color: var(--gold); font-size: 8px; margin-right: 6px; vertical-align: 2px; }
.yr-def { margin: 8px 16px 2px; font-size: 12px; line-height: 1.45; color: var(--ink-dim); }
.yr-src { margin: 2px 16px 0; font-size: 11px; color: var(--gold); font-style: italic; }
.yr-sec { padding: 10px 16px 0; }
.yr-sec h3 {
  margin: 4px 0 8px; font-family: var(--serif); font-weight: normal; font-size: 12px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--gold); display: flex; align-items: center; gap: 8px;
}
.yr-sec h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line), transparent); }
.yr-sec h4 { margin: 8px 0 4px; font: normal 10.5px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.yr-note { margin: -4px 0 6px; font-size: 11px; color: var(--ink-dim); }
.yr-note:empty { display: none; }
.yr-bar { display: grid; grid-template-columns: 20px 1fr auto; gap: 1px 7px; align-items: center; font-size: 12px; margin-bottom: 5px; }
.yr-bar.noic { grid-template-columns: 1fr auto; }
.yr-bar.noic .yr-track { grid-column: 1 / 3; }
.yr-bic { display: inline-flex; color: var(--gold-bright); }
.yr-bl { min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.yr-bl .muted { font-size: 11px; }
.yr-bv { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.yr-bar.strong .yr-bl { color: var(--gold-bright); font-family: var(--serif); font-size: 13px; }
.yr-track { grid-column: 2 / 4; height: 5px; background: rgba(255,255,255,.07); border-radius: 3px; overflow: hidden; }
.yr-track i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, color-mix(in srgb, var(--yc) 70%, #000), var(--yc)); }
.yr-track i.good { background: #7fbf3f; }
.yr-track i.bad { background: #e0704f; }
.yr-more { margin: 2px 0 0 27px; padding: 2px 0; background: none; border: none; color: var(--gold-bright); font-size: 12px; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.yr-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.yr-tabs, .yr-modes, .cp-seg { display: inline-flex; border: 1px solid rgba(201,164,92,.5); border-radius: 4px; overflow: hidden; background: rgba(0,0,0,.25); }
.cp-seg { margin: 2px 0 8px; }
.yr-tabs button, .yr-modes button, .cp-seg button { background: none; border: none; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--ink-dim); white-space: nowrap; }
.yr-tabs button + button, .yr-modes button + button, .cp-seg button + button { border-left: 1px solid rgba(201,164,92,.35); }
.yr-tabs button { font-family: var(--serif); letter-spacing: .08em; text-transform: uppercase; font-size: 11.5px; }
.yr-tabs button:hover:not([disabled]), .yr-modes button:hover, .cp-seg button:hover { color: var(--gold-bright); background: rgba(201,164,92,.12); }
.yr-tabs button[aria-selected="true"], .yr-modes button[aria-pressed="true"], .cp-seg button[aria-pressed="true"] { color: var(--gold-bright); background: linear-gradient(180deg, #5a4a24, #3a2f15); }
.yr-tabs button[disabled] { opacity: .4; cursor: default; }
.yr-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.yr-row {
  display: grid; grid-template-columns: 20px 1fr auto; gap: 2px 8px; align-items: center; width: 100%; text-align: left; cursor: pointer;
  padding: 5px 8px 6px; border-radius: 4px; background: rgba(0,0,0,.22); border: 1px solid rgba(201,164,92,.2); font-size: 13px;
}
.yr-row:hover, .yr-row:focus-visible { border-color: var(--gold); background: rgba(201,164,92,.12); }
.yr-row .yr-track { height: 3px; }
.yr-rk { grid-row: 1 / 3; align-self: center; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font: bold 11px var(--serif); color: #1a1408; background: radial-gradient(circle at 50% 35%, var(--gold-bright), var(--gold)); }
.yr-nm { font-family: var(--serif); color: var(--gold-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.yr-nm .muted { font-family: var(--sans); font-size: 11px; }
.yr-v { font-variant-numeric: tabular-nums; font-weight: 600; }
.yr-empty { font-size: 12px; }
.yr-foot { padding: 12px 16px 0; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.yr-foot .yr-note { margin: 0; flex: 1; min-width: 0; }
#city-panel:focus { outline: none; }

/* ---------- extension hosts (app/api.js: app.ui.dock, app.ui.addTopButton) ---------- */
/* Docks sit flush under the top bar at the screen edge; the map stays full-size underneath and app.visibleArea()
   shrinks instead. --dock-left / --dock-right on <body> hold the visible docks' widths (0px when closed). */
.app-dock {
  position: fixed; top: var(--topbar-h); bottom: 0; width: var(--dock-w, 380px); max-width: calc(100vw - 120px); z-index: 12;
  overflow-y: auto; overscroll-behavior: contain; border-radius: 0; border-top: none;
}
.app-dock-left { left: 0; border-left: none; }
.app-dock-right { right: 0; border-right: none; }
.btn-ext.active, .btn-ext[aria-pressed="true"] { background: linear-gradient(180deg, #5a4a24, #3a2f15); border-color: var(--gold-bright); }
/* Keep Advisors' label visible on standard laptops (1201px–1720px) alongside Share and Almanac; trim .turn cleanly first. */
@media (max-width: 1720px) { .turn { max-width: 175px; overflow: hidden; text-overflow: ellipsis; } }
@media (max-width: 1460px) { .turn { max-width: 125px; } }
@media (max-width: 1360px) and (min-width: 701px) { body.tb-ext .brand-text { display: none; } }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 280px;
  background: rgba(12, 18, 26, .96); border: 1px solid var(--line); border-radius: 4px;
  padding: 6px 9px; font-size: 12px; line-height: 1.45; color: var(--ink);
  contain: layout style;
}
.tooltip b { color: var(--gold-bright); font-family: var(--serif); }
.tooltip .muted { color: var(--ink-dim); }
.tooltip svg.icon { vertical-align: -2px !important; }

/* ---------- city / state panel ---------- */
#city-panel {
  position: fixed; top: 52px; right: calc(12px + var(--dock-right, 0px)); bottom: 12px; width: 370px; z-index: 12;
  overflow-y: auto; padding: 0 0 12px; overscroll-behavior: contain;
}
.sheet-grip { display: none; }
.cp-head { padding: 12px 16px 12px 20px; border-bottom: 1px solid var(--line); position: relative; background: linear-gradient(180deg, rgba(255,235,190,.05), transparent); }
.cp-head .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: 6px 0 0 0; box-shadow: inset -1px 0 0 rgba(0,0,0,.4); }
.cp-kind { font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); }
.cp-name { margin: 0; font-weight: normal; font-family: var(--serif); font-size: 24px; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-bright); padding-right: 34px; line-height: 1.15; }
.cp-name .cap { color: #ffe9a8; }
.cp-full { color: var(--ink-dim); font-size: 12px; margin-top: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font: 11px var(--sans); letter-spacing: .06em; padding: 1px 7px; border-radius: 9px; border: 1px solid rgba(201,164,92,.5); background: rgba(0,0,0,.25); color: var(--gold-bright); }
button.chip { cursor: pointer; }
a.chip { text-decoration: none; }
button.chip:hover, a.chip:hover { background: rgba(201,164,92,.2); }
.cp-pop { margin-top: 8px; font-size: 13px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.cp-pop svg { color: var(--ink-dim); }
.cp-pop b { font-size: 16px; }
.cp-pop .growth { white-space: nowrap; }
.cp-pop .growth .since { color: var(--ink-dim); font-size: 12px; }
.cp-pop .growth.nil { color: var(--ink-dim); font-size: 12px; border-bottom: 1px dotted rgba(185,171,136,.6); cursor: help; }
.cp-emp { margin-top: 3px; font-size: 12px; color: var(--ink-dim); display: flex; align-items: flex-start; gap: 6px; line-height: 1.4; }
.cp-emp > span { flex: 1; min-width: 0; }
.cp-emp svg, .cp-emp .emoji { color: var(--ink-dim); margin-top: 2px; }
/* A note quoted from the data (why a figure is missing, an estimate or a lower bound). */
.cp-note { margin: 5px 0 0; font-size: 11px; line-height: 1.4; color: var(--ink-dim); padding-left: 7px; border-left: 2px solid rgba(201,164,92,.45); }
.cp-section .cp-note { margin: 2px 0 8px; }
.cp-src { margin: 6px 0 0; font-size: 11px; line-height: 1.4; color: var(--ink-dim); }
.chip.plain { border-color: rgba(201,164,92,.25); color: var(--ink-dim); background: none; }
.cp-close { position: absolute; top: 10px; right: 10px; }
.cp-section { padding: 10px 16px 4px; }
.cp-section h3 {
  margin: 4px 0 8px; font-family: var(--serif); font-weight: normal; font-size: 12px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--gold); display: flex; align-items: center; gap: 8px;
}
.cp-section h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line), transparent); }
.yield-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.yield-tile { background: rgba(0,0,0,.25); border: 1px solid rgba(201,164,92,.25); border-radius: 5px; padding: 6px 2px; text-align: center; cursor: help; }
.yield-tile .ico { display: flex; justify-content: center; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
.yield-tile .val { font-weight: 700; font-size: 14px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.yield-tile .lbl { font-size: 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .06em; }
/* The yield's unit (stalls, ha, workers, students, sites): Gold counts workers, not money. */
.yield-tile .unit { font-size: 10px; color: rgba(185,171,136,.8); line-height: 1.2; overflow-wrap: anywhere; }
.yield-tile .rank { font-size: 10px; color: var(--gold-bright); margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.yield-tile .val .mk { font-size: 11px; font-weight: 600; opacity: .9; }
.yield-tile.nil { border-style: dashed; }
.yield-tile.nil .val { color: var(--ink-dim) !important; font-weight: 400; }
/* Why a yield is ≈, ≥ or has no data (the record's notes), under the tiles. */
.cp-notes { list-style: none; margin: 8px 0 2px; padding: 0; font-size: 11px; line-height: 1.4; color: var(--ink-dim); }
.cp-notes li { margin-bottom: 4px; }
.cp-notes b { font-weight: 600; }
.cp-notes .tag, .stat-row .cnt { color: var(--gold-bright); }
.cp-notes .tag { margin-right: 2px; }
.ind { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 6px; align-items: center; margin-bottom: 5px; font-size: 12px; }
.ind .bar { grid-column: 2 / 4; height: 5px; background: rgba(255,255,255,.07); border-radius: 3px; overflow: hidden; }
.ind .bar i { display: block; height: 100%; border-radius: 3px; }
.ind .n { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.lq { font-size: 10px; padding: 0 4px; border-radius: 3px; margin-left: 4px; }
.lq.hi { background: rgba(127,191,63,.25); color: #b9e486; }
.lq.lo { background: rgba(255,255,255,.06); color: var(--ink-dim); }
/* Label | value: a long label wraps, the value and its "SG" comparison stay on one line. */
.stat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed rgba(201,164,92,.15); }
.stat-row .sl { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.stat-row .sl svg, .stat-row .sl .emoji { color: var(--ink-dim); width: 14px; flex: none; }
.stat-row > span:last-child { text-align: right; white-space: nowrap; }
.stat-row .cmp { font-size: 11px; color: var(--ink-dim); margin-left: 6px; white-space: nowrap; }
.stat-row .cnt { font-size: 10.5px; margin-left: 5px; white-space: nowrap; color: var(--ink-dim); }
.stat-row[title] .sl { cursor: help; }
.stat-row.nil b { color: var(--ink-dim); font-weight: 400; }
.stat-note { margin: 2px 0 4px 20px; font-size: 11px; line-height: 1.35; color: var(--ink-dim); }
.good { color: #9fd76a !important; } .bad { color: #f08a6a !important; }
.city-list { display: flex; flex-direction: column; gap: 3px; }
.city-row {
  display: grid; grid-template-columns: 1fr auto 12px; gap: 8px; align-items: center; width: 100%; text-align: left; cursor: pointer;
  padding: 6px 8px; border-radius: 4px; background: rgba(0,0,0,.22); border: 1px solid rgba(201,164,92,.2); font-size: 13px;
}
.city-row:hover, .city-row:focus-visible { border-color: var(--gold); background: rgba(201,164,92,.12); }
.cr-name { font-family: var(--serif); color: var(--gold-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-name .muted { font-family: var(--sans); font-size: 11px; }
.cr-pop { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.cr-go { color: var(--gold); }
.cp-section p.muted { font-size: 12px; margin: 4px 0; }
.cp-foot { padding: 10px 16px 0; font-size: 11px; color: var(--ink-dim); }
.cp-foot a { color: var(--gold); cursor: pointer; }

/* ---------- lenses ---------- */
#lens-area {
  position: fixed; left: calc(12px + var(--dock-left, 0px)); right: calc(12px + var(--dock-right, 0px)); bottom: 12px; z-index: 11; pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
#lens-area > * { pointer-events: auto; }
body.panel-open #lens-area { right: calc(394px + var(--dock-right, 0px)); }
#lens-area { container-type: inline-size; }
/* A narrow dock (e.g. beside the open panel) shows icons only for the quick lenses. */
@container (max-width: 560px) {
  .lens-quick .lens-btn:not(.active) span, .res-toggle span { display: none; }
}
.lens-dock { position: relative; display: flex; align-items: center; gap: 4px; padding: 5px; max-width: 100%; min-width: 0; }
.lens-quick { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; }
.lens-quick::-webkit-scrollbar { display: none; }
.lens-quick.more-r:not(.more-l) { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); }
.lens-quick.more-l:not(.more-r) { -webkit-mask-image: linear-gradient(90deg, transparent, #000 22px); mask-image: linear-gradient(90deg, transparent, #000 22px); }
.lens-quick.more-l.more-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); }
.lens-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  background: rgba(0,0,0,.25); border: 1px solid rgba(201,164,92,.3); border-radius: 4px; padding: 5px 9px;
  cursor: pointer; font-size: 12px; white-space: nowrap; color: var(--ink);
}
.lens-btn:hover { border-color: var(--gold); }
.lens-btn.active { background: linear-gradient(180deg, #5a4a24, #3a2f15); border-color: var(--gold-bright); color: var(--gold-bright); }
.hex-inspector {
  position: fixed; z-index: 27; left: calc(12px + var(--dock-left, 0px)); top: calc(var(--topbar-h) + 12px);
  width: min(320px, calc(100vw - 24px)); max-height: 42dvh; overflow: auto; overscroll-behavior: contain;
  padding: 10px; font-size: 13px; line-height: 1.4;
}
.hex-inspector header, .hex-inspector-controls { display: flex; align-items: center; gap: 5px; }
.hex-inspector header { justify-content: space-between; }
.hex-inspector h2 { font: 18px var(--serif); margin: 0; }
.hex-inspector p { margin: 6px 0; }
.hex-inspector-controls { margin-bottom: 8px; }
.hex-inspector-controls .lens-btn { min-width: 30px; justify-content: center; }
.hex-inspector-controls .lens-btn:disabled { opacity: .65; cursor: default; }
#hex-inspector-reading b { color: var(--gold-bright); }
body.rt-on .hex-inspector { top: 8px; left: max(12px, calc((100vw - 320px) / 2)); }
@media (max-width: 700px) {
  .hex-inspector { left: 8px; width: min(320px, calc(100vw - 16px)); }
  body.rt-on .hex-inspector { left: 8px; }
}
.lens-more { font-family: var(--serif); color: var(--gold-bright); border-color: rgba(201,164,92,.6); background: linear-gradient(180deg, #33465c, #1d2b3a); }
.lens-more .caret { font-size: 10px; opacity: .8; }
.lens-more[aria-expanded="true"] .caret { display: inline-block; transform: rotate(180deg); }
.res-toggle { color: var(--ink-dim); margin-right: 4px; }
.res-toggle.active { color: var(--gold-bright); border-color: var(--gold-bright); }

.lens-picker { width: 700px; max-width: 100%; max-height: calc(100vh - 140px); display: flex; flex-direction: column; overflow: hidden; }
.lp-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 6px 14px; border-bottom: 1px solid var(--line);
  font-family: var(--serif); color: var(--gold-bright); letter-spacing: .14em; text-transform: uppercase; font-size: 13px; }
.lp-body { overflow-y: auto; padding: 6px 10px 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
.lp-group h4 { margin: 8px 0 5px; display: flex; align-items: center; gap: 6px; font: normal 11px var(--serif); letter-spacing: .18em; text-transform: uppercase; color: var(--gold); }
.lp-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.lp-tile {
  position: relative; display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 2px 7px; text-align: left; cursor: pointer;
  padding: 6px 7px 9px; border-radius: 5px; background: rgba(0,0,0,.25); border: 1px solid rgba(201,164,92,.25); color: var(--ink); font-size: 12px; overflow: hidden;
}
.lp-tile:hover, .lp-tile:focus-visible { border-color: var(--gold); background: rgba(201,164,92,.1); }
.lp-tile.active { border-color: var(--gold-bright); background: linear-gradient(180deg, rgba(90,74,36,.9), rgba(58,47,21,.9)); color: var(--gold-bright); }
.lp-ic { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #1b2838; border: 1px solid rgba(201,164,92,.55); color: var(--gold-bright); }
.lp-nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-ramp { position: absolute; left: 6px; right: 6px; bottom: 3px; height: 3px; border-radius: 2px; }
.lp-ramp.terrain { background: linear-gradient(90deg, #2d6d97, #4f7a35, #a8a05a, #8a7a64, #e6e6e6); }

.legend { padding: 8px 10px 9px; width: 300px; max-width: 100%; font-size: 11px; }
.legend.behind { display: none; }
.lg-head { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.lg-ic { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #1b2838; border: 1px solid var(--gold); color: var(--gold-bright); flex: none; }
.legend .title { font-family: var(--serif); color: var(--gold-bright); font-size: 15px; letter-spacing: .06em; flex: 1; }
.lg-close { width: 20px; height: 20px; }
.legend .desc { color: var(--ink-dim); margin-bottom: 6px; line-height: 1.4; max-height: 4.3em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.lg-scale { position: relative; cursor: crosshair; touch-action: none; padding-top: 2px; border-radius: 3px; }
.lg-hist { display: block; width: 100%; height: 38px; }
.legend .ramp { position: relative; height: 11px; border-radius: 2px; border: 1px solid rgba(0,0,0,.5); box-shadow: 0 0 0 1px rgba(201,164,92,.25); }
.band-mark { position: absolute; top: -45px; bottom: -3px; border: 1px solid var(--gold-bright); border-radius: 2px; background: rgba(255,233,168,.12); box-shadow: 0 0 6px rgba(255,214,110,.5); pointer-events: none; }
.legend .ticks { position: relative; height: 15px; margin-top: 3px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.legend .ticks span { position: absolute; top: 0; white-space: nowrap; font-size: 10.5px; }
.legend .lg-unit { display: none; margin-top: 1px; color: var(--ink-dim); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 5px; color: var(--ink-dim); font-size: 10.5px; }
.hib { font-weight: 600; }
.lg-hint { margin-top: 4px; font-size: 10.5px; color: rgba(185,171,136,.75); font-style: italic; }
.lg-hint.on { color: var(--gold-bright); font-style: normal; }
/* A lens's caveat (lens.note), e.g. what a religion count does and does not measure. Shown everywhere, even on phones.
   A band across the whole card, ruled above and below, so it reads as part of the legend and not as a box inside it:
   its side margins undo the legend's padding (.legend). */
.lg-note { margin: 0 -10px 7px; padding: 5px 10px 6px; border-top: 1px solid rgba(201,164,92,.24); border-bottom: 1px solid rgba(201,164,92,.24);
  background: rgba(201,164,92,.07); color: var(--ink); font-size: 10.5px; line-height: 1.35; }
/* "≈ estimate" beside a lens whose values are estimates made here (lenses.json estimated). */
.lg-est { flex: none; font-size: 10px; padding: 0 5px; border-radius: 8px; border: 1px solid rgba(201,164,92,.5); color: var(--gold-bright); white-space: nowrap; cursor: help; }
/* Values that are only "at least" (lenses.json lower_bound). */
.lg-bound { margin: -2px 0 6px; font-size: 10.5px; color: var(--ink); }
.lg-bound b { color: var(--gold-bright); }
.lg-meta .lvl { cursor: help; }
.lg-meta .lvl, .lg-nodata, .lg-zero { white-space: nowrap; }
/* The source and its date: three lines at most (land use cites six layers); the tooltip has all of it. */
.lg-meta .src { flex-basis: 100%; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.lg-nodata i { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 2px; vertical-align: -1px; background: #55534d; box-shadow: inset 0 0 0 1px rgba(0,0,0,.5); }
.lg-zero i { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 2px; vertical-align: -1px; background: #171c22; box-shadow: inset 0 0 0 1px rgba(201,164,92,.4); }
.estate-filter { display: inline-flex; align-items: center; gap: 5px; margin-top: 5px; padding: 3px 7px;
  border: 1px solid #8d809f; border-radius: 3px; background: #202336; color: #fff3d3; font: inherit; cursor: pointer; }
.estate-filter i { width: .8em; height: .8em; }
.estate-filter[aria-pressed="true"] { background: #40304e; border-color: #e1c2ff; }
.estate-filter:focus-visible { outline: 2px solid #fff3d3; outline-offset: 2px; }
/* Categorical lenses: swatches instead of the histogram; click one to show only it. Land use has 26 categories, so
   the list scrolls rather than covering the map. */
.lg-cats { display: flex; flex-wrap: wrap; gap: 3px 4px; max-height: 196px; overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }
.lg-cat { display: inline-flex; align-items: center; gap: 5px; padding: 2px 6px 2px 4px; cursor: pointer; font-size: 11px;
  background: rgba(0,0,0,.22); border: 1px solid rgba(201,164,92,.25); border-radius: 3px; }
.lg-cat i { width: 11px; height: 11px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.45); flex: none; }
.lg-cat .n { color: var(--ink-dim); font-size: 10px; font-variant-numeric: tabular-nums; }
.lg-cat:hover { border-color: var(--gold); }
/* A category no hex has (a language or religion that leads in no town) stays listed, greyed. */
.lg-cat.zero { opacity: .5; border-style: dashed; }
.lg-cats.filtered .lg-cat:not(.on) { opacity: .45; }
.lg-cat.on { border-color: var(--gold-bright); color: var(--gold-bright); opacity: 1; }

/* Map layers menu (app.ui.addMapToggle): one dock button, a small menu of switches above the dock. */
.map-layers-btn { position: relative; }
.map-layers-btn .ml-count { min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--gold); color: #1a1208;
  font-size: 10px; line-height: 15px; text-align: center; }
/* Overlay the legend so its height does not push the switches outside the viewport. */
.map-layers-pop { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 1; width: 240px; max-width: 100cqw;
  max-height: min(60vh, calc(100dvh - var(--topbar-h) - 64px - env(safe-area-inset-bottom))); overflow-y: auto;
  overscroll-behavior: contain; touch-action: pan-y; padding: 4px 0 6px; }
.ml-head { padding: 4px 12px 6px; font: normal 11px var(--serif); letter-spacing: .18em; text-transform: uppercase; color: var(--gold);
  border-bottom: 1px solid var(--line); margin-bottom: 3px; }
.ml-row { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 12px; min-height: 36px; cursor: pointer; text-align: left;
  background: none; border: 0; font-size: 12.5px; color: var(--ink-dim); }
.ml-row:hover, .ml-row:focus-visible { background: rgba(201,164,92,.1); }
.ml-row.on { color: var(--ink); }
.ml-ic { display: inline-grid; place-items: center; width: 18px; flex: none; }
.ml-lbl { flex: 1; }
.ml-switch { position: relative; width: 28px; height: 16px; border-radius: 8px; background: rgba(0,0,0,.4); border: 1px solid rgba(201,164,92,.4); flex: none; }
.ml-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--ink-dim); transition: left .12s; }
.ml-row.on .ml-switch { background: #5a4a24; border-color: var(--gold-bright); }
.ml-row.on .ml-switch::after { left: 14px; background: var(--gold-bright); }
/* The details toggle only matters beside a docked dashboard (advisors), where the legend is a compact strip at the
   top right of the map instead of a card over the south-east. */
.lg-more { display: none; width: 20px; height: 20px; font-size: 14px; line-height: 1; }
@media (min-width: 701px) {
  body.dock-open .lg-more { display: inline-grid; place-items: center; }
  body.dock-open #legend { position: absolute; right: 0; bottom: calc(100vh - 12px - var(--topbar-h) - 10px); transform: translateY(100%); }
  body.dock-open #legend:not(.expanded) { width: 230px; padding: 5px 8px 4px; }
  body.dock-open #legend:not(.expanded) .lg-ic { width: 20px; height: 20px; }
  body.dock-open #legend:not(.expanded) .title { font-size: 13px; }
  body.dock-open #legend:not(.expanded) :is(.desc, .lg-hist, .lg-meta, .lg-hint, .lg-note, .lg-bound, .lg-cats) { display: none; }
  body.dock-open #legend:not(.expanded) .band-mark { top: -3px; }
  body.dock-open #legend:not(.expanded) .ticks span:nth-child(2n) { display: none; }
  body.dock-open #legend:not(.expanded) .lg-unit { display: block; }
}

/* ---------- modals: the Almanac + help ---------- */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: grid; place-items: center; }
.modal-card { width: min(980px, 94vw); height: min(680px, 88vh); display: grid; grid-template-columns: 210px 1fr; position: relative; overflow: hidden; }
.modal-card .close { position: absolute; top: 10px; right: 12px; z-index: 2; }
#pedia-nav { border-right: 1px solid var(--line); padding: 16px 0; background: rgba(0,0,0,.2); overflow-y: auto; }
#pedia-nav .hd { font-family: var(--serif); color: var(--gold-bright); font-size: 18px; letter-spacing: .12em; text-transform: uppercase; padding: 0 16px 12px; }
#pedia-nav button { display: block; width: 100%; text-align: left; background: none; border: none; padding: 7px 16px; cursor: pointer; font-size: 13px; color: var(--ink); }
#pedia-nav button.active, #pedia-nav button:hover { background: rgba(201,164,92,.15); color: var(--gold-bright); }
#pedia-body { padding: 20px 28px; overflow-y: auto; font-size: 14px; line-height: 1.55; }
#pedia-body h2 { font-family: var(--serif); color: var(--gold-bright); letter-spacing: .08em; margin: 0 0 12px; font-weight: normal; font-size: 24px; display: flex; align-items: center; gap: 10px; }
#pedia-body h2 svg { color: var(--gold); }
#pedia-body h3.grp { font-family: var(--serif); font-weight: normal; color: var(--gold); font-size: 13px; letter-spacing: .18em; text-transform: uppercase; margin: 22px 0 4px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
#pedia-body h4 { margin: 18px 0 4px; color: var(--gold); font-family: var(--serif); font-size: 15px; display: flex; align-items: center; gap: 6px; }
#pedia-body a { color: var(--gold-bright); }
.pd-change { margin: 18px 0; }
.pd-change h3, .pd-age-changes h3 { margin: 0 0 8px; font: 20px/1.3 var(--serif); }
.pd-change-kind { display: inline-block; color: var(--ink-dim); font: 12px/1.4 var(--sans); margin-left: 6px; }
.pd-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border: 1px solid var(--line); border-radius: 5px; }
.pd-comparison > div { padding: 10px 12px; min-width: 0; overflow-wrap: anywhere; }
.pd-comparison > div + div { border-left: 1px solid var(--line); background: rgba(201,164,92,.06); }
.pd-comparison dt, .pd-change-releases { color: var(--ink-dim); font-size: 12px; }
.pd-comparison dd { margin: 2px 0 0; font-size: 13px; }
.pd-comparison dd strong { display: block; font: 600 19px/1.35 var(--serif); }
.pd-comparison dd span { display: block; }
.pd-comparison dd a { display: inline-block; padding: 4px 0; font-size: 12px; text-underline-offset: 2px; }
.pd-change-releases { display: flex; gap: 4px 18px; flex-wrap: wrap; margin-top: 18px; }
.pd-age-changes { margin-top: 18px; }
.pd-town-change { margin: 0; border-top: 1px solid var(--line); }
.pd-town-change summary { cursor: pointer; padding: 9px 0; }
.pd-town-change[open] { padding-bottom: 12px; }
#pedia-body .muted { color: var(--ink-dim); font-size: 12px; }
#pedia-body table { border-collapse: collapse; width: 100%; font-size: 12px; margin-top: 6px; }
#pedia-body td, #pedia-body th { border-bottom: 1px solid rgba(201,164,92,.2); padding: 4px 6px; text-align: left; vertical-align: top; }
#pedia-body th { color: var(--gold); font-weight: normal; font-family: var(--serif); letter-spacing: .06em; }
#pedia-body td.ic { width: 34px; vertical-align: middle; }
#pedia-body td.nm { white-space: nowrap; }
#pedia-body td.num { text-align: right; font-variant-numeric: tabular-nums; }
#pedia-body code { font-size: 11px; color: var(--ink-dim); word-break: break-all; }
.res-ic { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--gold); color: #f8f0d8; box-shadow: 0 0 0 1px #120d06; }
/* A rule quoted from the data files (rules, notes, descriptions): the Almanac never retypes them. Set in the Almanac's
   serif, the face of its headings and labels, so a quoted rule reads apart from the page's own prose. */
#pedia-body .rule { margin: 10px 0; font-family: var(--serif); font-size: 14px; line-height: 1.55; color: var(--ink); }
#pedia-body .rule b { color: var(--gold-bright); font-weight: normal; }
#pedia-body .pd-note { margin: 4px 0; font-size: 12.5px; color: var(--ink-dim); font-style: italic; }
.pd-entry { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; margin-top: 8px; }
/* A grid column may shrink below its tables' width (they scroll in .pd-scroll), so the page never scrolls sideways. */
.pd-entry > div, .lens-entry > div { min-width: 0; }
.pd-entry h4 { margin-top: 10px !important; }
.pd-ic { margin-top: 12px; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #1b2838; border: 1px solid var(--gold); }
#pedia-body table.kv th { width: 96px; white-space: nowrap; }
#pedia-body .pd-list { margin: 4px 0 8px; padding-left: 18px; font-size: 13px; }
#pedia-body .pd-list li { margin: 2px 0; }
#pedia-body table.kv .pd-list { margin: 0; padding-left: 16px; font-size: 12px; }
.pd-more { margin: 4px 0 8px; font-size: 12.5px; }
.pd-more > summary { cursor: pointer; color: var(--gold-bright); padding: 2px 0; }
.pd-more > summary:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
/* Wide tables scroll sideways inside the page on phones instead of squeezing their columns. */
.pd-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pd-mark { margin-left: 8px; font: 11px var(--sans); padding: 0 6px; border-radius: 8px; border: 1px solid rgba(201,164,92,.5); color: var(--gold-bright); white-space: nowrap; }
.pd-cats { display: flex; flex-wrap: wrap; gap: 3px 10px; margin: 2px 0 4px; font-size: 11.5px; color: var(--ink-dim); }
.pd-cats i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.45); }
.lens-entry { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; }
.lens-entry h4 { margin-top: 14px !important; }
.le-ic { margin-top: 14px; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #1b2838; border: 1px solid var(--gold); color: var(--gold-bright); }
.le-ramp { display: block; height: 6px; border-radius: 3px; margin: 6px 0 3px; max-width: 260px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0,0,0,.4); }

.help-card { width: min(720px, 94vw); max-height: 88vh; overflow-y: auto; padding: 18px 24px 16px; position: relative; }
.help-card h2 { margin: 0 0 10px; font: normal 22px var(--serif); letter-spacing: .1em; text-transform: uppercase; color: var(--gold-bright); display: flex; align-items: center; gap: 10px; }
.help-card h2 svg { color: var(--gold); }
.help-close { position: absolute; top: 12px; right: 12px; }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 4px 22px; }
.help-card h3 { margin: 10px 0 6px; font: normal 11px var(--serif); letter-spacing: .2em; text-transform: uppercase; color: var(--gold); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.help-row { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 4px 0; font-size: 13px; }
.help-row .keys { display: flex; flex-wrap: wrap; gap: 4px; }
.help-about .help-p { margin: 6px 0; font-size: 13px; line-height: 1.45; }
.help-about b { color: var(--gold-bright); font-weight: normal; }
.help-foot { margin: 14px 0 0; font-size: 12px; color: var(--ink-dim); }
.help-foot a { color: var(--gold-bright); }
.help-licence { margin: 8px 0 0; font-size: 12px; color: var(--ink-dim); }
.help-licence summary { cursor: pointer; color: var(--gold-bright); }
.help-licence-text { margin: 6px 0 0; max-height: 180px; overflow: auto; white-space: pre-wrap; font-size: 11px;
  line-height: 1.4; color: var(--ink-dim); }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: #0c2238;
  font-family: var(--serif); font-size: 22px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold-bright);
}
#loading.error { font-size: 15px; letter-spacing: 0; text-transform: none; padding: 40px; text-align: center; }

/* ---------- narrower desktops ---------- */
#topbar { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#topbar::-webkit-scrollbar { display: none; }
@media (max-width: 1440px) and (min-width: 1201px) {
  #topbar { gap: 11px; }
  .yields { gap: 9px; }
  .yield { font-size: 13px; }
  .search { flex-basis: 185px; min-width: 130px; }
  .btn { padding: 4px 8px; font-size: 12.5px; }
}
/* Keep .turn visible on standard laptops (>= 1280px); hide below 1280px. */
@media (max-width: 1279px) { .turn { display: none; } }
@media (max-width: 1200px) {
  #topbar { gap: 12px; }
  .yields { gap: 10px; }
  .yield { font-size: 13px; }
  .btn .lbl { display: none; }
  .btn { padding: 4px 7px; }
  .search { flex-basis: 180px; min-width: 130px; }
}
@media (max-width: 1000px) and (min-width: 701px) {
  .brand-text { display: none; }
  .lp-body { grid-template-columns: 1fr; }
  #topbar { gap: 10px; padding: 0 10px; }
  .yields { gap: 8px; }
  .yield { font-size: 12.5px; gap: 4px; }
  .search { flex: 0 1 150px; min-width: 112px; }
}
/* The yields row gives way first when the bar is short of room (topbar.js marks it .clipped). */
@media (max-width: 1000px) and (min-width: 701px) {
  .yields { flex: 0 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .yields::-webkit-scrollbar { display: none; }
  .yields.clipped { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); }
}

/* ---------- short screens: a phone held sideways (844 × 390) gets the desktop layout ---------- */
@media (max-height: 500px) and (min-width: 701px) {
  #lens-area { bottom: 8px; gap: 6px; }
  /* The legend is the compact strip (as beside a docked dashboard), its details a tap on + away, and it scrolls
     inside the height left between the top bar and the lens dock. */
  .lg-more { display: inline-grid; place-items: center; }
  #legend { max-height: calc(100vh - var(--topbar-h) - 62px); overflow-y: auto; overscroll-behavior: contain; }
  #legend:not(.expanded) { width: 280px; padding: 5px 8px 4px; }
  #legend:not(.expanded) .lg-ic { width: 20px; height: 20px; }
  #legend:not(.expanded) .title { font-size: 13px; }
  #legend:not(.expanded) :is(.desc, .lg-hist, .lg-meta, .lg-hint:not(.on), .lg-note, .lg-bound) { display: none; }
  #legend:not(.expanded) .band-mark { top: -3px; }
  #legend:not(.expanded) .ticks span:nth-child(2n) { display: none; }
  #legend:not(.expanded) .lg-unit { display: block; }
  .lg-cats { max-height: 120px; }
  /* Keep rows compact on short landscape screens. */
  .ml-row { min-height: 32px; padding-top: 5px; padding-bottom: 5px; }
  .search-results { max-height: calc(100vh - var(--topbar-h) - 14px); }
  .sr-item { padding-top: 4px; padding-bottom: 4px; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  :root { --topbar-h: 68px; }
  #topbar {
    height: var(--topbar-h); flex-wrap: wrap; align-content: center; gap: 3px 6px; padding: 3px 8px;
    overflow: hidden;
  }
  .brand-text, .spacer, .turn, .search-kbd { display: none; }
  .brand { order: 1; }
  .brand-emblem { margin-right: 0; width: 22px; height: 22px; }
  .brand-emblem svg { width: 22px; height: 22px; }
  .search { order: 2; flex: 1 1 80px; min-width: 76px; margin-left: 0; }
  #search-input { height: 27px; padding: 0 8px 0 26px; font-size: 12.5px; }
  .tb-buttons { order: 3; gap: 4px; align-items: center; }
  .tb-buttons .btn { padding: 4px 6px; font-size: 11.5px; gap: 4px; line-height: 16px; }
  .tb-buttons .btn-ext .lbl, #btn-pedia .lbl { display: inline; }
  #btn-share .lbl { display: none; }
  .yields {
    order: 4; flex: 0 0 100%; min-width: 0; gap: 10px; padding: 1px 2px 0;
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-behavior: smooth;
  }
  .yields::-webkit-scrollbar { display: none; }
  .yield { font-size: 12.5px; line-height: 18px; }
  .yields.more-r:not(.more-l) { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); }
  .yields.more-l:not(.more-r) { -webkit-mask-image: linear-gradient(90deg, transparent, #000 22px); mask-image: linear-gradient(90deg, transparent, #000 22px); }
  .yields.more-l.more-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); }

  #lens-area { left: 0; right: 0; bottom: 0; gap: 6px; align-items: stretch; z-index: 13; }
  body.panel-open #lens-area { right: 0; }
  .lens-dock { border-radius: 10px 10px 0 0; border-left: none; border-right: none; border-bottom: none; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .lens-quick { flex: 1; }
  .res-toggle span, .lens-more span:not(.caret) { display: none; }
  .map-layers-pop { left: 8px; right: 8px; width: auto; }
  .ml-row { min-height: 42px; }
  .legend { width: auto; margin: 0 8px; }
  .legend .desc { display: none; }
  .lg-cats { max-height: 22vh; }
  .lens-picker { width: auto; margin: 0 8px; max-height: 60vh; }
  .lp-body { grid-template-columns: 1fr; }

  #city-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 55vh; height: 55dvh; z-index: 25;
    border-radius: 14px 14px 0 0; border-left: none; border-right: none; border-bottom: none;
    padding-bottom: calc(12px + env(safe-area-inset-bottom)); transition: transform .18s ease-out;
    box-shadow: 0 -8px 30px rgba(0,0,0,.55);
  }
  #city-panel.dragging-sheet { transition: none; }
  .app-dock {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; height: 55vh; height: 55dvh; z-index: 24;
    border-radius: 14px 14px 0 0; border: 1px solid var(--line); border-bottom: none; border-left: none; border-right: none;
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -8px 30px rgba(0,0,0,.55);
  }
  /* A tapped map item's tooltip (it takes no touches) shows over the bottom sheet rather than under it. */
  .tooltip { z-index: 26; }
  .sheet-grip { display: block; position: sticky; top: 0; z-index: 2; height: 18px; margin-bottom: -18px; touch-action: none; }
  .sheet-grip::before { content: ""; position: absolute; left: 50%; top: 6px; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: rgba(201,164,92,.6); }
  /* No touch-action of its own: at the top the head is much of the sheet, so a finger on it must scroll the sheet.
     A pull down from it still closes the sheet (installSheetSwipe in js/ui/infoPanel.js tells the two apart). */
  .cp-head { padding-top: 18px; }
  .cp-close { top: 14px; width: 32px; height: 32px; }
  .cp-name { font-size: 21px; }
  .yield-tile .val { font-size: 13px; }

  .modal-card { grid-template-columns: 1fr; grid-template-rows: auto 1fr; width: 100vw; height: 100%; height: 100dvh; border-radius: 0; }
  /* The tab row ends before the close button (a tab scrolled under it would read "Resou" and a tap could close the
     Almanac); the line under the row is the page's top border, so it still runs the full width. */
  #pedia-nav { display: flex; overflow-x: auto; border-right: none; border-bottom: none; padding: 8px 0; margin-right: 46px; }
  #pedia-nav .hd { display: none; }
  .modal-card .close { background: #1c2836; top: 7px; right: 8px; }
  #pedia-nav button { width: auto; white-space: nowrap; padding: 6px 12px; }
  #pedia-body { padding: 14px 16px; overflow-wrap: anywhere; border-top: 1px solid var(--line); }
  #pedia-body td.nm { white-space: normal; }
  /* Column heads and figures break between words, never inside one ("Co|de", "136 km|²"): a table too wide scrolls. */
  #pedia-body th, #pedia-body td.num { overflow-wrap: normal; }
  #pedia-body td.num { white-space: nowrap; }
  .help-card { padding: 16px; }
  .toast { top: calc(var(--topbar-h) + 8px); }

  .yield-report {
    left: 0 !important; right: 0; width: auto; max-width: none; z-index: 28;
    max-height: calc(100vh - var(--topbar-h) - 64px); max-height: calc(100dvh - var(--topbar-h) - 64px);
    border-radius: 0 0 12px 12px; border-left: none; border-right: none; border-top-width: 2px;
  }
  .yr-total > b { font-size: 30px; }
  .yr-row { padding: 7px 8px; }
}
@media (max-width: 365px) {
  #btn-pedia .lbl { display: none; }
}

/* ---------- extension entry controls shown before lazy mode stylesheets load ---------- */
.cv-open {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 10px; padding: 7px 10px; cursor: pointer;
  font: 13px var(--serif); letter-spacing: .12em; text-transform: uppercase; color: #1c1408;
  background: linear-gradient(180deg, #f3dc9c, #c9a45c 55%, #a8843f);
  border: 1px solid #120d06; border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,250,230,.7), inset 0 -1px 0 rgba(80,55,15,.6), 0 2px 6px rgba(0,0,0,.45);
}
.cv-open:hover { filter: brightness(1.08); }
.cv-open:active { transform: translateY(1px); }
.cv-open .cv-open-ic { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #24384f; color: #f8f0d8; box-shadow: 0 0 0 1px #120d06; }
.cv-open .cv-open-go { margin-left: auto; font-size: 18px; line-height: 1; }
.cv-plink { margin: 8px 0 0; font-size: 11.5px; line-height: 1.4; color: var(--ink-dim, #b9ab8a); }
.cv-plink button {
  margin-left: 4px; padding: 1px 8px; cursor: pointer; font: 11px var(--serif); letter-spacing: .08em; text-transform: uppercase;
  color: var(--gold-bright, #f3dc9c); background: rgba(201,164,92,.12); border: 1px solid rgba(201,164,92,.55); border-radius: 3px;
}
.cv-plink button:hover, .cv-plink button:focus-visible { background: rgba(201,164,92,.25); }

body.rt-on #topbar,
body.rt-on #lens-area,
body.rt-on #city-panel { display: none !important; }
.rt-entry { display: none; }
@media (max-width: 700px) {
  .rt-entry {
    position: fixed; right: 8px; top: calc(var(--topbar-h) + 8px); z-index: 11;
    display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px 0 11px; border-radius: 19px;
    color: var(--gold-bright); font: 13px/1 var(--serif); letter-spacing: .03em; white-space: nowrap; cursor: pointer;
  }
  .rt-entry:active { border-color: var(--gold-bright); }
  body.rt-on .rt-entry, body.cv-on .rt-entry, body.dock-open .rt-entry { display: none; }
}
