/* ===========================================================================
   WikiBarrio — Public Service Signage
   The atlas set like Spanish public signage: one grotesk (Archivo, its width
   axis carrying the hierarchy), geometric theme marks, flat fields. Chroma
   belongs to the data: the chrome takes its only colour from the active
   variable's ramp (--var-ramp, set by main.js). Signage white is reserved for
   "you are here": the plate of the hovered or selected place.
   Loaded after main.css; tokens first, then components.
=========================================================================== */

/* ===== TOKENS ===== */
:root {
  --font-ui:   'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  /* The wordmark alone: a monospace name plate against the grotesk interface */
  --font-wordmark: 'Geist Mono', ui-monospace, 'SF Mono', monospace;
  --font-mono: var(--font-ui);
  --font-sans: var(--font-ui);

  --fs-micro:   11px;
  --fs-body:    13px;
  --fs-emph:    15px;
  --fs-title:   26px;
  --fs-display: 34px;
  --lh-body:    1.45;

  /* Width axis: condensed for names and labels, wide for headings */
  --w-cond:  76%;
  --w-semi:  88%;
  --w-wide:  108%;

  --radius-sm: 2px;
  --radius-md: 3px;
  --radius-lg: 4px;

  /* Light: paper panels, ink plates */
  --color-surface:         #fbfbfa;
  --color-surface-alt:     #efefec;
  --color-surface-muted:   #e7e7e3;
  --color-surface-inset:   #dcdcd7;
  --color-surface-hover:   #f0f0ec;
  --color-ink:             #111317;
  --color-ink-secondary:   #24272d;
  --color-text:            #2b2e34;
  --color-text-muted:      #565961;
  --color-text-subtle:     #6c6f77;
  --color-border:          rgba(17, 19, 23, 0.14);
  --color-border-subtle:   rgba(17, 19, 23, 0.07);
  --color-border-strong:   rgba(17, 19, 23, 0.32);

  /* "You are here": the plate. Ink on paper here, white on ink in the dark. */
  --plate-bg:    #111317;
  --plate-ink:   #f2f0ea;
  --plate-muted: #b9b8b2;
  --plate-rule:  #f2f0ea;

  --color-signal:      #111317;
  --color-signal-weak: rgba(17, 19, 23, 0.08);
  --color-high: #2166ac;
  --color-low:  #b35806;

  --shadow-sm: 0 1px 0 var(--color-border);
  --shadow-md: 0 2px 6px rgba(17, 19, 23, 0.10);
  --shadow-lg: 0 6px 18px rgba(17, 19, 23, 0.14);
  --shadow-float: 0 2px 8px rgba(17, 19, 23, 0.12);

  --focus-ring: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-ink);

  --var-ramp: linear-gradient(90deg, #67001f, #d6604d, #f7f7f7, #4393c3, #053061);

  --na-hatch-base: #e6e6e1;
}

html.dark-mode, .dark-mode {
  --color-surface:         #181b21;
  --color-surface-alt:     #111317;
  --color-surface-muted:   #20242b;
  --color-surface-inset:   #2b3038;
  --color-surface-hover:   #22262d;
  --color-ink:             #eceae4;
  --color-ink-secondary:   #d8d6d0;
  --color-text:            #c8c6c0;
  --color-text-muted:      #a2a19c;
  --color-text-subtle:     #888a91;
  --color-border:          rgba(236, 234, 228, 0.13);
  --color-border-subtle:   rgba(236, 234, 228, 0.06);
  --color-border-strong:   rgba(236, 234, 228, 0.28);

  --plate-bg:    #f2f0ea;
  --plate-ink:   #111317;
  --plate-muted: #4a4e57;
  --plate-rule:  #111317;

  --color-signal:      #f2f0ea;
  --color-signal-weak: rgba(242, 240, 234, 0.12);
  --color-high: #6aaed6;
  --color-low:  #e0a35c;

  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-float: 0 2px 8px rgba(0, 0, 0, 0.40);
  --focus-ring: 0 0 0 2px var(--color-surface-alt), 0 0 0 4px var(--color-ink);

  --na-hatch-base: #262a31;
}
@media (prefers-color-scheme: dark) {
  html:not(.light-mode) {
    --color-surface:         #181b21;
    --color-surface-alt:     #111317;
    --color-surface-muted:   #20242b;
    --color-surface-inset:   #2b3038;
    --color-surface-hover:   #22262d;
    --color-ink:             #eceae4;
    --color-ink-secondary:   #d8d6d0;
    --color-text:            #c8c6c0;
    --color-text-muted:      #a2a19c;
    --color-text-subtle:     #888a91;
    --color-border:          rgba(236, 234, 228, 0.13);
    --color-border-subtle:   rgba(236, 234, 228, 0.06);
    --color-border-strong:   rgba(236, 234, 228, 0.28);

    --plate-bg:    #f2f0ea;
    --plate-ink:   #111317;
    --plate-muted: #4a4e57;
    --plate-rule:  #111317;

    --color-signal:      #f2f0ea;
    --color-signal-weak: rgba(242, 240, 234, 0.12);
    --color-high: #6aaed6;
    --color-low:  #e0a35c;

    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-float: 0 2px 8px rgba(0, 0, 0, 0.40);
    --focus-ring: 0 0 0 2px var(--color-surface-alt), 0 0 0 4px var(--color-ink);

    --na-hatch-base: #262a31;
  }
}

/* ===== GLOBAL ===== */
html, body { font-family: var(--font-ui); font-feature-settings: 'tnum' 1; }
::selection { background: var(--plate-bg); color: var(--plate-ink); }
input, textarea { caret-color: var(--color-ink); }
* { scrollbar-width: thin; scrollbar-color: var(--color-border-strong) transparent; }
:focus-visible { box-shadow: var(--focus-ring); }

/* Flat world: no atmosphere, no glass */
.map-vignette, .map-grain { display: none; }
*, *::before, *::after { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
.modal::before, .barrio-finder::before { background: rgba(17, 19, 23, 0.78); }

/* The label voice: condensed capitals, short tracking */
.tp-table th, .tp-ledger-k, .tp-poi-tile .tp-poi-name, .tp-flat-cell .k,
.custom-optgroup, .search-result-kind, .bf-result-kind,
#timelapse .tl-label, .tp-spark-national-key, .bfc-vs, .bfc-label,
.panel-3d .p3-color > [data-k], .poi-row-label, .bf-or, .bf-loading-label {
  font-stretch: var(--w-cond);
  font-weight: 650;
  letter-spacing: 0.035em;
  font-size: var(--fs-micro);
}

/* Eyebrows and section numbers leave: headings carry their own weight */
.tp-report-eyebrow, .tp-sec-num, .tp-flat-eyebrow, .bf-eyebrow { display: none !important; }
.tp-body { counter-reset: none; }
.tp-section-header > span::before, .tp-hero-label::before, .tp-poi-heading::before { content: none !important; }

/* ===== THEME ICONS =====
   One drawn icon per theme (Lucide, ISC licence: users, wallet, briefcase, graduation-cap, globe, vote),
   used as a mask so it takes the current text colour. No ramp: the icons are wayfinding, not data. */
:root {
  --ic-people: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/><path d='M16 3.128a4 4 0 0 1 0 7.744'/><path d='M22 21v-2a4 4 0 0 0-3-3.87'/><circle cx='9' cy='7' r='4'/></svg>");
  --ic-income: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1'/><path d='M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4'/></svg>");
  --ic-work: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16'/><rect width='20' height='14' x='2' y='6' rx='2'/></svg>");
  --ic-education: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z'/><path d='M22 10v6'/><path d='M6 12.5V16a6 3 0 0 0 12 0v-3.5'/></svg>");
  --ic-origin: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><path d='M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20'/><path d='M2 12h20'/></svg>");
  --ic-elections: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><path d='m9 12 2 2 4-4'/><path d='M5 7c0-1.1.9-2 2-2h10a2 2 0 0 1 2 2v12H5V7Z'/><path d='M22 19H2'/></svg>");
  --ic-check: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'><path d='M20 6 9 17l-5-5'/></svg>");
}
.wb-mark {
  --mk: 26px;
  display: inline-block;
  flex: 0 0 auto;
  width: var(--mk);
  height: var(--mk);
  background: currentColor;
  -webkit-mask: var(--ic) center / contain no-repeat;
  mask: var(--ic) center / contain no-repeat;
}
.wb-mark[data-mark="people"], html[data-var-theme="people"] { --ic: var(--ic-people); }
.wb-mark[data-mark="income"], html[data-var-theme="income"] { --ic: var(--ic-income); }
.wb-mark[data-mark="work"], html[data-var-theme="work"] { --ic: var(--ic-work); }
.wb-mark[data-mark="education"], html[data-var-theme="education"] { --ic: var(--ic-education); }
.wb-mark[data-mark="origin"], html[data-var-theme="origin"] { --ic: var(--ic-origin); }
.wb-mark[data-mark="elections"], html[data-var-theme="elections"] { --ic: var(--ic-elections); }

/* ===== SIDEBAR ===== */
#sidebar { background: var(--color-surface); border-right: 1px solid var(--color-border); }
#controls { gap: 26px; padding: 24px 24px 20px; }
.sidebar-header h1 {
  font-family: var(--font-wordmark);
  font-size: 29px;
  font-weight: 500;
  font-stretch: 100%;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--color-ink);
}
/* The bar under the wordmark is the chrome's one patch of colour: the active variable's ramp as six
   registered colour stops (set on .sidebar-header by updateLegend), so a variable switch morphs it
   stop by stop on the map's 900 ms clock instead of snapping from one gradient to the next */
@property --rs0 { syntax: '<color>'; inherits: true; initial-value: #67001f; }
@property --rs1 { syntax: '<color>'; inherits: true; initial-value: #d6604d; }
@property --rs2 { syntax: '<color>'; inherits: true; initial-value: #fddbc7; }
@property --rs3 { syntax: '<color>'; inherits: true; initial-value: #d1e1f0; }
@property --rs4 { syntax: '<color>'; inherits: true; initial-value: #4393c3; }
@property --rs5 { syntax: '<color>'; inherits: true; initial-value: #053061; }
.sidebar-header {
  transition: --rs0 900ms var(--ease-out), --rs1 900ms var(--ease-out), --rs2 900ms var(--ease-out),
    --rs3 900ms var(--ease-out), --rs4 900ms var(--ease-out), --rs5 900ms var(--ease-out);
}
@media (prefers-reduced-motion: reduce) { .sidebar-header { transition: none; } }
.sidebar-header::after {
  content: '';
  display: block;
  height: 6px;
  margin-top: 12px;
  background: linear-gradient(90deg, var(--rs0), var(--rs1), var(--rs2), var(--rs3), var(--rs4), var(--rs5));
}
.subtitle { font-size: var(--fs-body); line-height: 1.45; color: var(--color-text-muted); margin-top: -14px; max-width: 34ch; }

.control-group { gap: 10px; }
.control-group:has(.select-wrapper) > h3 {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.control-group h3 {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--color-text-muted);
}

/* The primary action: raised graphite, flat (the ramp stays under the wordmark) */
.bf-launch {
  margin-top: 0;
  padding: 12px 14px;
  background: var(--color-surface-muted);
  color: var(--color-ink);
  border: 0;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0;
}
@media (hover: hover) { .bf-launch:hover { background: var(--color-surface-inset); } }

/* Theme rail: marks, then the theme's variables (built by ThemeRail in main.js) */
.select-wrapper .custom-select { display: none; }
.theme-marks {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}
/* The plate behind the theme on the map: one element that glides to the new theme when a variable of
   another theme is chosen (ThemeRail.placePlate) */
.theme-plate {
  position: absolute;
  left: 0; top: 0;
  z-index: -1;
  border-radius: var(--radius-md);
  background: var(--plate-bg);
  pointer-events: none;
  transition: transform 460ms cubic-bezier(0.22, 1, 0.36, 1), width 460ms cubic-bezier(0.22, 1, 0.36, 1),
    height 460ms cubic-bezier(0.22, 1, 0.36, 1), background-color 300ms var(--ease-out), opacity 200ms;
}
.theme-plate.no-anim { transition: none; }
@media (prefers-reduced-motion: reduce) { .theme-plate { transition: none; } }
.theme-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 0 8px;
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 12px;
  font-weight: 600;
  transition: background-color var(--dur-fast), box-shadow var(--dur-fast), color 220ms var(--ease-out) 120ms;
}
.theme-mark .wb-mark { --mk: 26px; }
/* On the map: the plate sits behind it. Open for browsing (another theme's variables listed below):
   a quiet outlined tile, so the plate keeps saying what the map shows */
.theme-mark.is-current { color: var(--plate-ink); font-weight: 800; }
.theme-mark[aria-pressed="true"]:not(.is-current) { color: var(--color-ink); font-weight: 800; background: var(--color-surface-muted); box-shadow: inset 0 0 0 1.5px var(--color-ink); }
@media (hover: hover) { .theme-mark:not(.is-current):not([aria-pressed="true"]):hover { background: var(--color-surface-hover); color: var(--color-ink); } }

.theme-vars { display: flex; flex-direction: column; margin-top: 6px; }
.theme-var {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 7px 0;
  border-top: 1px solid var(--color-border-subtle);
  text-align: left;
  font-size: 14px;
  line-height: 1.25;
  color: var(--color-text);
}
.theme-var:first-child { border-top: 0; }
.theme-var .tv-year { font-size: 12px; color: var(--color-text-subtle); display: flex; align-items: center; gap: 8px; }
.theme-var[aria-pressed="true"] { color: var(--color-ink); font-weight: 750; }
.theme-var[aria-pressed="true"] .tv-year::after {
  content: '';
  width: 14px;
  height: 14px;
  background: var(--color-ink);
  -webkit-mask: var(--ic-check) center / contain no-repeat;
  mask: var(--ic-check) center / contain no-repeat;
}
@media (hover: hover) { .theme-var:hover { color: var(--color-ink); } }
.theme-more {
  align-self: flex-start;
  margin-top: 4px;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-ink-secondary);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}
@media (hover: hover) { .theme-more:hover { color: var(--color-ink); } }

/* Mini-map: a quiet locator, not a feature tile */
.sidebar-minimap { max-width: 220px; background: transparent; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 10px; aspect-ratio: 100 / 58; }
.sidebar-minimap .spain-outline, .sidebar-minimap .minimap-balearics circle { fill: var(--color-surface-muted); stroke: var(--color-border-strong); }
.sidebar-minimap .minimap-viewport { stroke: var(--color-ink); stroke-width: 1.5; }
.sidebar-minimap .minimap-selection { fill: var(--color-ink); stroke: var(--color-surface); }

/* Cities: wayfinding entries, square bullets */
.city-presets { display: flex; flex-wrap: wrap; gap: 0 18px; }
.city-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 650;
  color: var(--color-ink-secondary);
}
.city-chip::before { content: ''; width: 7px; height: 7px; background: currentColor; }
@media (hover: hover) { .city-chip:hover { background: none; color: var(--color-ink); text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; } }

/* Points of interest */
.poi-toggles { gap: 6px; }
.poi-chip {
  padding: 6px 10px 6px 8px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 550;
  color: var(--color-text);
}
.poi-chip[aria-pressed="true"] { background: var(--color-surface-muted); border-color: var(--color-ink); color: var(--color-ink); font-weight: 700; }

/* Featured ranking: rank in condensed capitals, names, tabular values */
.featured-note { font-size: 12px; color: var(--color-text-muted); }
.featured-list { border: 0; border-top: 1px solid var(--color-border); border-radius: 0; overflow: visible; }
.featured-item {
  font-family: var(--font-ui);
  padding: 9px 0;
  background: transparent;
  border-bottom: 1px solid var(--color-border-subtle);
  grid-template-columns: 5.2ch minmax(0, 1fr) auto;
  will-change: transform;
}
html[lang="es"] .featured-item { grid-template-columns: 6.4ch minmax(0, 1fr) auto; }
@media (hover: hover) { .featured-item:hover { background: var(--color-surface-hover); } }
.featured-rank { font-size: 11px; font-weight: 700; font-stretch: var(--w-cond); letter-spacing: .03em; color: var(--color-text-subtle); }
.featured-name { font-size: 14px; color: var(--color-ink-secondary); }
.featured-value { font-size: 14px; font-weight: 700; color: var(--color-ink); }
.featured-placeholder { text-transform: none; letter-spacing: 0; font-size: 12px; }

.sidebar-footer { opacity: 0.7; font-size: 11px; }

/* ===== FLOATING CONTROLS (search, toolbar, toggle, locate, zoom) ===== */
.area-search-input, .toolbar, #sidebar-toggle, .locate-btn, .zoom-pill {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
}
#sidebar-toggle { border-left: none; border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.area-search-input { font-family: var(--font-ui); font-size: 14px; }
.area-search-input::placeholder { color: var(--color-text-subtle); }
.area-search-input:focus { border-color: var(--color-ink); box-shadow: var(--shadow-float), 0 0 0 1px var(--color-ink); }
.toolbar-btn { color: var(--color-ink-secondary); font-family: var(--font-ui); }
.toolbar-btn[aria-pressed="true"] { background: var(--color-surface-inset); color: var(--color-ink); box-shadow: inset 0 -3px 0 var(--color-ink); }
@media (hover: hover) { .toolbar-btn[aria-pressed="true"]:hover { background: var(--color-surface-inset); color: var(--color-ink); } }
.toolbar-lang .language-indicator { font-family: var(--font-ui); font-weight: 750; letter-spacing: 0.02em; font-size: 13px; }
.zoom-pill .zoom-btn, .locate-btn { color: var(--color-ink-secondary); }
.zoom-pill .zoom-btn { font-size: 17px; font-weight: 500; }
.maplibregl-ctrl-scale { font-family: var(--font-ui); font-size: 11px; font-weight: 650; color: var(--color-ink-secondary); background: var(--color-surface); border-color: var(--color-ink-secondary); }
.maplibregl-ctrl-attrib { font-family: var(--font-ui); opacity: 1; color: var(--color-text-muted); background: color-mix(in srgb, var(--color-surface) 82%, transparent) !important; border-radius: var(--radius-sm); }
.maplibregl-ctrl-attrib a { color: var(--color-ink-secondary); }

.search-results, .bf-results { font-family: var(--font-ui); }

/* View caption: place in condensed capitals, variable after */
#view-caption { font-family: var(--font-ui); border-radius: var(--radius-md); box-shadow: var(--shadow-float); border-color: var(--color-border-strong); padding: 6px 14px; }
#view-caption .vc-place { font-size: 15px; font-weight: 800; font-stretch: var(--w-cond); letter-spacing: .02em; }
#view-caption .vc-var { font-size: 12px; letter-spacing: 0; text-transform: none; }

/* ===== THE VARIABLE BAND (legend) ===== */
#legend {
  font-family: var(--font-ui);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  padding: 12px 16px 10px;
}
body:not(.legend-compact) #legend {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title title" "scale na";
  column-gap: 16px;
  row-gap: 10px;
  align-items: end;
  width: min(560px, calc(100vw - var(--map-left) - var(--map-right) - 220px));
}
body:not(.legend-compact) #legend .legend-heading { grid-area: title; min-width: 0; }
body:not(.legend-compact) #legend .legend-inner { grid-area: scale; width: 100%; }
body:not(.legend-compact) #legend .legend-na { grid-area: na; padding-bottom: 2px; }
#legend .legend-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "mark title mode" "mark scope mode";
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
}
#legend .legend-scale-controls { display: contents; }
#legend .legend-heading::before {
  content: '';
  grid-area: mark;
  width: 26px;
  height: 26px;
  align-self: center;
  background: var(--color-ink);
  -webkit-mask: var(--ic, var(--ic-income)) center / contain no-repeat;
  mask: var(--ic, var(--ic-income)) center / contain no-repeat;
}
.legend-title, #legend-title {
  grid-area: title;
  font-size: 17px;
  font-weight: 750;
  font-stretch: 100%;
  letter-spacing: -0.005em;
  text-transform: none;
  color: var(--color-ink);
  line-height: 1.15;
}
#legend-title { max-width: none; }
#legend-title .legend-year { font-weight: 500; color: var(--color-text-muted); margin-left: 8px; font-size: 14px; }
.legend-scope { grid-area: scope; font-size: 12px; letter-spacing: 0; color: var(--color-text-muted); }
.legend-scope::before { width: 7px; height: 7px; border-radius: 0; background: var(--color-text-subtle); }
#legend[data-scale="local"] .legend-scope::before { background: var(--color-ink); }
.legend-scale-mode { grid-area: mode; padding: 0; gap: 0; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); overflow: hidden; align-self: center; }
.legend-scale-mode button { padding: 6px 11px; font-size: 13px; font-weight: 650; border-radius: 0; color: var(--color-text-muted); }
.legend-scale-mode button[aria-pressed="true"] { background: var(--color-surface-inset); color: var(--color-ink); font-weight: 800; box-shadow: inset 0 -3px 0 var(--color-ink); }
.legend-scale { height: 14px; }
.legend-ramp { border-radius: 0; }
.legend-color { top: -4px; bottom: -4px; border-radius: 0; }
@media (hover: hover) { .legend-color:hover { box-shadow: inset 0 0 0 2px var(--color-ink); } }
.legend-median-tick { top: -5px; bottom: -5px; width: 3px; margin-left: -1.5px; border-radius: 0; background: var(--color-ink); box-shadow: 0 0 0 1px var(--color-surface); }
.legend-labels { height: 18px; line-height: 18px; margin-top: 5px; font-size: 13px; font-weight: 650; color: var(--color-ink-secondary); }
.legend-label-median { font-weight: 800; color: var(--color-ink); }
.legend-diverging-caption .cap-arrow { display: none; }
.legend-diverging-caption { font-size: 11px; letter-spacing: 0; text-transform: none; margin-top: 1px; color: var(--color-text-muted); }
.legend-na { font-size: 12px; color: var(--color-text-muted); }
.legend-na-color { width: 16px; height: 12px; border-radius: 0; }

body.legend-compact #legend { padding: 10px 12px 8px; row-gap: 8px; }
body.legend-compact #legend .legend-heading { width: 100%; align-items: center; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "mark title title" "mark scope mode"; row-gap: 6px; }
body.legend-compact #legend #legend-title { font-stretch: var(--w-semi); }
#legend-title .legend-unit, #legend-title .legend-year { white-space: nowrap; }
body.legend-compact #legend #legend-title, body.legend-compact #legend .legend-title { text-align: left; justify-self: start; font-size: 15px; }
body.legend-compact #legend .legend-heading::before { width: 22px; height: 22px; }
/* Beside the Auto/Spain toggle the scope stacks its two parts rather than breaking after the dot */
body.legend-compact:not(.legend-stacked) #legend .legend-scope { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 0; align-items: center; line-height: 1.3; white-space: nowrap; }
body.legend-compact:not(.legend-stacked) #legend .legend-scope .ls-sep { display: none; }
body.legend-compact:not(.legend-stacked) #legend .legend-scope .ls-b { grid-column: 2; }
body.legend-stacked #legend .legend-heading { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "mark title" "scope scope" "mode mode"; justify-items: start; }
body.legend-stacked #legend .legend-scale-mode { justify-self: center; }

/* ===== TIME-LAPSE ===== */
#timelapse {
  font-family: var(--font-ui);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
}
#timelapse .tl-label { color: var(--color-text-muted); }
#timelapse .tl-hint { font-size: 12px; letter-spacing: 0; }
#timelapse .tl-play { border-radius: var(--radius-md); background: var(--color-surface-inset); color: var(--color-ink); border: 1px solid var(--color-border-strong); }
@media (hover: hover) { #timelapse .tl-play:hover { background: var(--color-surface-hover); border-color: var(--color-ink); } }
#timelapse .tl-range { height: 4px; border-radius: 0; background: var(--color-surface-inset); }
#timelapse .tl-range::-webkit-slider-thumb { width: 12px; height: 16px; border-radius: 2px; background: var(--color-ink); border: 2px solid var(--color-surface); }
#timelapse .tl-range::-moz-range-thumb { width: 12px; height: 16px; border-radius: 2px; background: var(--color-ink); }
#timelapse .tl-year { font-family: var(--font-ui); font-size: 22px; font-weight: 800; font-stretch: var(--w-semi); letter-spacing: -0.01em; color: var(--color-ink); }

/* ===== HOVER CARD: the plate ===== */
.maplibregl-popup { font-family: var(--font-ui); }
.maplibregl-popup-content {
  background: var(--plate-bg) !important;
  color: var(--plate-ink);
  border: 0;
  border-radius: var(--radius-md);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  padding: 10px 14px 11px !important;
  max-width: 260px;
}
.popup-header { display: grid; row-gap: 0; margin-bottom: 6px; }
/* MapLibre fits a card inside the map only when it is at most about two thirds of its width */
.tract-popup-mobile .maplibregl-popup-content { max-width: min(260px, calc((100vw - 16px) * 2 / 3)); }
.popup-name {
  font-size: 22px;
  font-weight: 850;
  font-stretch: var(--w-cond);
  text-transform: uppercase;
  letter-spacing: 0.005em;
  line-height: 0.98;
  color: var(--plate-ink);
  min-width: 0;
  overflow-wrap: anywhere;
}
.popup-code { font-size: 12px; color: var(--plate-muted); letter-spacing: 0; flex-basis: 100%; margin-top: 3px; }
.popup-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--plate-ink);
  border-top: 2.5px solid var(--plate-rule);
  padding-top: 6px;
}
.popup-var-label { font-size: 12px; color: var(--plate-muted); letter-spacing: 0; margin-top: 3px; }
/* A point of interest's category: muted text on the plate, its colour in a dot */
.popup-var-label[style*="--cat"] { display: flex; align-items: center; gap: 6px; }
.popup-var-label[style*="--cat"]::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--cat); flex: 0 0 auto; }
.maplibregl-popup-content .p3-popup-note { color: var(--plate-muted); border-top-color: color-mix(in srgb, var(--plate-ink) 18%, transparent); font-family: var(--font-ui); font-size: 12.5px; line-height: 1.4; }

/* ===== REPORT PANEL ===== */
.tract-panel { font-family: var(--font-ui); background: var(--color-surface); }
.tp-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  position: relative;
  isolation: isolate;
  margin: 0 16px;
  padding: 60px 16px 14px;
  background: transparent;
  color: var(--plate-ink);
  border: 0;
}
/* The plate itself sits under the title rows; the export chips stay on the panel above it */
.tp-header::before {
  content: '';
  position: absolute;
  inset: 48px 0 0 0;
  z-index: -1;
  background: var(--plate-bg);
  border-radius: var(--radius-md);
}
.tp-header .tp-title {
  order: 1;
  flex: 1 1 100%;
  font-size: 34px;
  font-weight: 850;
  font-stretch: var(--w-cond);
  text-transform: uppercase;
  letter-spacing: 0;
  line-height: 0.95;
  color: var(--plate-ink);
  min-width: 0;
  overflow-wrap: anywhere;
}
.tp-header .tp-eyebrow {
  order: 2;
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--plate-ink);
}
.tp-header .tp-eyebrow, .bf-metric-tag { text-transform: lowercase; }
.tp-header .tp-eyebrow::first-letter, .bf-metric-tag::first-letter { text-transform: uppercase; }
.tp-header .tp-eyebrow::after { content: '·'; margin: 0 7px; color: var(--plate-muted); font-weight: 400; }
.tp-header .tp-eyebrow:empty::after { content: none; }
/* A point of interest's category keeps its own capitals, and its dot only separates a subtitle */
#poi-panel .tp-header .tp-eyebrow { text-transform: none; }
#poi-panel .tp-header:has(> .tp-meta[style*="none"]) .tp-eyebrow::after { content: none; }
.tp-header .tp-meta { order: 3; flex: 1 1 0; margin-top: 8px; font-size: 12px; letter-spacing: 0; color: var(--plate-muted); }
.tp-header .tp-meta span::before { color: var(--plate-muted); }
#tract-panel .tp-title, .tp-header .tp-title { padding-right: 0; }
.tp-header .tp-actions { top: 12px; right: 0; }
.tp-header .tp-share, .tp-header .tp-print {
  color: var(--color-ink-secondary);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: transparent;
  font-family: var(--font-ui);
  font-weight: 700;
}
@media (hover: hover) { .tp-header .tp-share:hover, .tp-header .tp-print:hover { color: var(--color-ink); background: var(--color-surface-hover); border-color: var(--color-ink); } }
.tp-header .tp-close { color: var(--color-ink); font-size: 24px; }
.tp-header .tp-export-label { font-family: var(--font-ui); letter-spacing: 0.02em; font-weight: 750; }

.tp-nav { padding: 12px 16px 0; gap: 18px; border-bottom: 1px solid var(--color-border); }
.tp-nav-chip {
  padding: 2px 0 10px;
  border: 0;
  border-radius: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
  color: var(--color-text-muted);
  box-shadow: inset 0 -3px 0 transparent;
}
@media (hover: hover) { .tp-nav-chip:hover { background: none; color: var(--color-ink); } }
.tp-nav-chip.active { background: none; color: var(--color-ink); box-shadow: inset 0 -3px 0 var(--color-ink); border: 0; }

.tp-report { background: transparent; padding: 18px 16px 16px; }
.tp-report-summary { margin-top: 0; font-family: var(--font-ui); font-size: 17px; line-height: 1.45; font-weight: 450; color: var(--color-ink); letter-spacing: -0.005em; text-wrap: pretty; }
.tp-report-position { margin-top: 16px; }
.tp-report-position-k { font-family: var(--font-ui); font-size: 12px; letter-spacing: 0; text-transform: none; color: var(--color-text-muted); }

/* Position bars grow from the median (centre line): below left, above right */
.bf-metric { border-bottom-color: var(--color-border-subtle); }
.bf-metric-label { font-size: 14px; color: var(--color-ink-secondary); }
.bf-metric-value { font-size: 14px; font-weight: 750; }
.bf-metric-bar { height: 10px; border-radius: 0; background: var(--color-surface-muted); }
.bf-metric-fill { border-radius: 0; background: var(--color-low); transition: left var(--dur-slow) var(--ease-out), width var(--dur-slow) var(--ease-out); }
.bf-metric.is-high .bf-metric-fill { background: var(--color-high); }
.bf-metric-tick { left: 50%; top: -4px; width: 2px; height: 18px; margin-left: -1px; background: var(--color-ink); }
.bf-metric-marker { display: none; }
.bf-metric-tag { font-size: 12px; font-weight: 700; letter-spacing: 0; }
.bf-metric-tag.is-low { color: var(--color-low); }
.tp-report .bf-metric { grid-template-columns: 20px minmax(0, 1fr) 84px; padding: 8px 0; }
.bf-metric-icon .wb-mark { --mk: 18px; color: var(--color-text-muted); }
.tp-report .bf-metric-label, .tp-report .bf-metric-value { font-size: 13px; }
.tp-report .bf-metric-tag { font-size: 12px; letter-spacing: 0; }

/* Section heads: semi-expanded bold, sentence case, year to the right */
.tp-section-header, .tp-hero-label, .tp-poi-heading, .tp-sec-title {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 800;
  font-stretch: var(--w-wide);
  letter-spacing: -0.005em;
  text-transform: none;
  color: var(--color-ink);
}
.tp-section-header { padding-top: 22px; }
.tp-hero-value { font-size: 34px; font-weight: 800; font-stretch: var(--w-semi); letter-spacing: -0.015em; }
.tp-hero-trend { font-size: 14px; font-weight: 600; }
.tp-hero-years, .tp-mini-year { font-size: 12px; letter-spacing: 0; }

.tp-table th { color: var(--color-text-muted); text-transform: uppercase; }
.tp-table td { font-size: 13px; }
.tp-footer { font-family: var(--font-ui); font-size: 11px; letter-spacing: 0; text-transform: none; color: var(--color-text-muted); }
.tp-empty { text-transform: none; letter-spacing: 0; font-size: 12px; }
.tp-mini-label { text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 650; }

/* Where it is: the report's minimap, for the PDF only (the live report sits beside the map itself).
   Hidden on screen; the PDF button renders it off screen (body.wb-mm-prep), freezes it as an image
   (.tp-mm-img) and prints it; a section never rendered (.mm-ready missing) stays out of the print. */
.tp-where { display: none; padding: var(--space-4) var(--space-4) var(--space-3); border-bottom: 1px solid var(--color-border); }
body.wb-mm-prep .tp-where { display: block; position: fixed; left: -10000px; top: 0; width: 560px; }
.tp-mm-img { display: none; position: absolute; inset: 0; width: 100%; height: 100%; }
.tp-where .tp-sec-head { align-items: center; }
.tp-mm-switch { margin-left: auto; display: inline-flex; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); overflow: hidden; }
.tp-mm-switch button { padding: 5px 10px; font-family: var(--font-ui); font-size: 12px; font-weight: 650; color: var(--color-text-muted); background: transparent; border: 0; border-radius: 0; cursor: pointer; }
.tp-mm-switch button[aria-pressed="true"] { background: var(--color-surface-inset); color: var(--color-ink); font-weight: 800; box-shadow: inset 0 -3px 0 var(--color-ink); }
@media (hover: hover) { .tp-mm-switch button:not([aria-pressed="true"]):hover { color: var(--color-ink); } }
.tp-mm-frame { position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 340px; overflow: hidden; border-radius: var(--radius-md); border: 1px solid var(--color-border); background: var(--color-surface-muted); }
.tp-mm-map { position: absolute; inset: 0; }
.tp-mm-frame .maplibregl-ctrl-bottom-left .maplibregl-ctrl-scale { margin: 0 0 8px 8px; }
.tp-mm-credit { position: absolute; right: 6px; bottom: 5px; z-index: 2; padding: 1px 5px; font-size: 10px; line-height: 1.4; color: var(--color-text-muted); background: color-mix(in srgb, var(--color-surface) 82%, transparent); border-radius: var(--radius-sm); pointer-events: none; }
.tp-mm-key { margin-top: 8px; font-size: 11px; line-height: 1.4; color: var(--color-text-subtle); }
@media (max-width: 768px) { .tp-mm-frame { aspect-ratio: 16 / 11; } }
@media print {
  .tp-where.mm-ready { display: block !important; position: static !important; width: auto !important; break-inside: avoid; }
  .tp-where.mm-ready .tp-mm-map { display: none; }
  .tp-where.mm-ready .tp-mm-img { display: block; }
  .tp-mm-switch { display: none; }
}

/* Over time: small multiples, one small chart per indicator, rows aligned across tiles */
.tp-multiples { padding: var(--space-4) var(--space-4) var(--space-3); border-bottom: 1px solid var(--color-border); container-type: inline-size; }
.tp-sm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 22px; row-gap: 0; }
@container (min-width: 540px) { .tp-sm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tp-sm { display: grid; grid-row: span 5; grid-template-rows: subgrid; row-gap: 0; margin: 0; min-width: 0; padding: 10px 0 18px; border-top: 1px solid var(--color-border-subtle); }
.tp-sm-label { font-size: 12px; font-weight: 650; line-height: 1.25; color: var(--color-text-muted); }
.tp-sm-value { align-self: end; margin-top: 4px; font-size: 20px; font-weight: 800; font-stretch: var(--w-semi); letter-spacing: -0.01em; line-height: 1.05; color: var(--color-ink); font-variant-numeric: tabular-nums; }
.tp-sm-ceil { font-size: 12px; font-weight: 600; font-stretch: 100%; letter-spacing: 0; color: var(--color-text-muted); }
.tp-sm-trend { margin-top: 2px; font-size: 12px; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.tp-sm-chart { position: relative; margin-top: 8px; color: var(--color-ink); }
.tp-sm-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.tp-sm-years { display: flex; justify-content: space-between; margin-top: 3px; font-size: 11px; color: var(--color-text-subtle); font-variant-numeric: tabular-nums; }
.tp-sm-cap { margin-top: 2px; font-size: 11px; line-height: 1.4; color: var(--color-text-subtle); }
@media print {
  .tp-multiples { break-inside: avoid; }
  .tp-sm-chart { color: #0c0f14 !important; }
  .tp-sm-chart svg path { stroke-width: 1.6; }
}

/* Panel bars and composition: flat, square */
.tp-bars-track, .tp-comp-bar { border-radius: 0 !important; }
.tp-bars-fill { border-radius: 0 !important; }

/* While a report is open the sidebar steps back: its colour and decoration go quiet, its text stays
   fully legible; the place on the report leads */
@media (min-width: 769px) {
  body.panel-open #controls .sidebar-minimap svg { filter: saturate(0.15); opacity: 0.55; transition: filter 400ms var(--ease-out), opacity 400ms var(--ease-out); }
  body.panel-open #controls .theme-plate { background: var(--color-surface-inset); }
  body.panel-open #controls .theme-mark.is-current { color: var(--color-ink); }
}

/* ===== FINDER, HELP, 3D, STORY: the world's type ===== */
.bf-locate {
  background: var(--color-surface-muted);
  color: var(--color-ink);
  border-bottom: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0;
}
@media (hover: hover) { .bf-locate:hover { opacity: 1; background: var(--color-surface-inset); } }
/* Disclosure: a drawn chevron, not a glyph */
.panel-3d summary { list-style: none; display: flex; align-items: center; gap: 10px; }
.panel-3d summary::-webkit-details-marker { display: none; }
.panel-3d summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur-fast) var(--ease-out); }
.panel-3d details[open] > summary::before { transform: rotate(45deg); }
.bf-card, .help-content, .panel-3d, .story-card, .wb-toast { font-family: var(--font-ui); }
/* The intro's last call to action is a plate: ink on paper in the light, paper on ink in the dark */
.story-cta-find { background: var(--plate-bg); color: var(--plate-ink); }
.bf-title { font-weight: 850; font-stretch: var(--w-wide); letter-spacing: -0.015em; }
.story-callout .sc-place { font-stretch: var(--w-cond); font-weight: 800; letter-spacing: 0.02em; }
.panel-3d .p3-title { font-stretch: var(--w-semi); font-weight: 800; letter-spacing: 0; text-transform: none; }

#help-modal h2, #help-modal h3 { font-family: var(--font-ui); font-weight: 800; font-stretch: var(--w-wide); letter-spacing: -0.005em; color: var(--color-ink); }

/* ===== LOADER ===== */
#loader h1 { font-family: var(--font-wordmark); font-weight: 500; font-stretch: 100%; letter-spacing: -0.03em; }
.loader-tagline { font-family: var(--font-ui); letter-spacing: 0; text-transform: none; font-size: 13px; }

/* ===== PHONES ===== */
@media (max-width: 768px) {
  .tp-header { margin: 0 12px; }
  .tp-header .tp-title { font-size: 30px; }
  .tp-nav { padding: 10px 12px 0; }
  .tp-report { padding: 16px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-header::after, .featured-item { transition: none !important; }
}

/* Print keeps main.css's paper palette; the header plate prints as ink on paper */
@media print {
  .tp-header { background: transparent !important; color: #0c0f14 !important; margin: 0 !important; padding-top: 0 !important; }
  .tp-header::before { content: none !important; }
  .tp-header .tp-title, .tp-header .tp-eyebrow { color: #0c0f14 !important; }
  .tp-header .tp-meta { color: #555 !important; }
}
