/* Lenses: the dock, the lens picker and the legend. */
/* left: 266px keeps the area clear of the 252px-wide minimap; it never overlaps it. */
#lens-area {
  position: fixed; left: calc(266px + 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 {
  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; }
.lens-quick::-webkit-scrollbar { display: none; }
.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);
}
.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: 580px; 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. On phones
   it is behind the legend's details toggle (narrow.css). */
.lg-note {
  margin: -2px 0 6px; padding: 4px 7px; border-left: 2px solid var(--gold);
  background: rgba(201,164,92,.08); color: var(--ink); font-size: 10.5px; line-height: 1.35;
}
/* Categorical lenses: swatches instead of the histogram; click one to show only it. */
.lg-cats { display: flex; flex-wrap: wrap; gap: 3px 4px; }
.lg-cat {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px 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:hover { border-color: var(--gold); }
.lg-cats.filtered .lg-cat:not(.on) { opacity: .45; }
.lg-cat.on { border-color: var(--gold-bright); color: var(--gold-bright); }
/* Hexes a lens has no value for (lenses.json `no_value`). */
.lg-none {
  display: flex; align-items: center; gap: 5px; margin-top: 3px; font-size: 10.5px;
  color: var(--ink-dim);
}
.lg-none i {
  width: 11px; height: 11px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.45);
  flex: none;
}
.lg-none-n { margin-left: auto; font-variant-numeric: tabular-nums; }

/* A lens whose values are still loading (main/lens.js): a gentle pulse, or a plain dim. */
.lens-btn.loading, .lp-tile.loading, .lens-more.loading {
  cursor: progress; animation: lens-loading 1.1s ease-in-out infinite alternate;
}
@keyframes lens-loading { from { opacity: 1; } to { opacity: .5; } }
@media (prefers-reduced-motion: reduce) {
  .lens-btn.loading, .lp-tile.loading, .lens-more.loading { animation: none; opacity: .6; }
}
/* The upstream lenses Canada has no data for, under the picker (lenses.json `omitted`). */
.lp-foot {
  margin: 0; padding: 7px 14px 9px; border-top: 1px solid var(--line); font-size: 11.5px;
  color: var(--ink-dim);
}
.lp-why {
  background: none; border: 0; padding: 0; font: inherit; color: var(--gold); cursor: pointer;
  text-decoration: underline;
}
.lp-why:hover, .lp-why:focus-visible { color: var(--gold-bright); }
