/* Shared research-atlas surface. The map uses data colors; the interface stays neutral. */
:root {
  --ink: #223638;
  --muted-ink: #4c6162;
  --paper: #f5f4ee;
  --surface: #fdfcf7;
  --rule: #cbd2c8;
  --strong-rule: #a7b4ad;
  --wash: #ebefe8;
  --accent: #23514e;
  --accent-dark: #183b39;
  --rust: #884a32;
  --focus: #376d9b;
  --edition-serif: Georgia, "Times New Roman", serif;
}

html { scroll-behavior: auto; }
body.atlas-page, body.detail-page { background: var(--paper); color: var(--ink); }
body:is(.atlas-page, .detail-page) :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
:where(.atlas-page, .detail-page) [hidden] { display: none !important; }
:where(.atlas-page, .detail-page) :is(main, .topbar) { box-sizing: border-box; }
:where(.atlas-page, .detail-page) main { max-width: 1480px; padding: 28px clamp(16px, 3vw, 46px) 0; }
:where(.atlas-page, .detail-page) .panel { border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); box-shadow: none; }
:where(.atlas-page, .detail-page) .topbar {
  padding: 0 max(18px, calc((100vw - 1390px) / 2));
  min-height: 66px;
  height: auto;
  gap: 24px;
  background: var(--surface);
  border-color: var(--rule);
}
.topbar .brand > span { display: grid; gap: 3px; }
.topbar .brand strong { color: var(--ink); font-size: 17px; line-height: 1.2; white-space: nowrap; }
.topbar .brand small { color: var(--muted-ink); font-size: 9px; letter-spacing: .1em; }
.topbar nav { min-height: 66px; margin-inline-start: auto; gap: clamp(12px, 2.4vw, 32px); }
:where(.atlas-page, .detail-page) .topbar nav :is(a, button) {
  display: inline-flex; align-items: center; position: relative; height: 100%; min-height: 44px;
  padding: 0; color: var(--muted-ink); text-decoration: none; text-align: start; font-size: 13px;
  font-weight: 650; line-height: 1.25; white-space: nowrap; border: 0; background: transparent;
}
:where(.atlas-page, .detail-page) .topbar nav .nav-active {
  color: var(--accent-dark); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 8px;
}
:where(.atlas-page, .detail-page) .topbar nav .nav-active::after { display: none; }
:where(.atlas-page, .detail-page) .language {
  display: inline-flex; gap: 2px; padding: 0; flex-shrink: 0; border: 1px solid var(--rule);
  border-radius: 4px; background: var(--surface);
}
:where(.atlas-page, .detail-page) .language button {
  background: transparent; color: var(--muted-ink); border: 0; border-radius: 2px;
  min-width: 44px; min-height: 38px; padding: 4px 8px; box-shadow: none;
}
:where(.atlas-page, .detail-page) .language button[aria-pressed=true] { background: var(--accent); color: #fff; }
:where(.atlas-page, .detail-page) :is(.intro, .detail-intro) {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin: 0 0 22px;
  padding-bottom: 17px; border-bottom: 1px solid var(--strong-rule);
}
body :is(.intro, .detail-intro, .welcome-copy) .study-kicker {
  color: var(--rust); font-size: 12px; font-weight: 700; line-height: 1.4;
  letter-spacing: .045em; margin: 0 0 5px;
}
:where(.atlas-page, .detail-page) :is(.intro, .detail-intro) h1 {
  font-family: var(--edition-serif); font-weight: 500; font-size: clamp(33px, 4vw, 57px);
  line-height: 1.06; letter-spacing: -.026em; color: var(--ink); margin: 0 0 8px;
}
:where(.atlas-page, .detail-page) :is(.intro, .detail-intro) > div:first-child p:not(.study-kicker) {
  color: var(--muted-ink); font-size: clamp(13px, 1.5vw, 15px); line-height: 1.55; max-width: 66ch; margin: 0;
}
.intro-credit {
  display: flex; flex-direction: column; align-items: flex-start; flex-shrink: 0;
  border-inline-start: 1px solid var(--rule); padding-inline-start: 14px;
  color: var(--muted-ink); font-size: 12px; line-height: 1.5;
}
.intro-credit > bdi { color: var(--ink); font-weight: 700; font-size: 14px; }
:where(.atlas-page, .detail-page) .intro-credit .text-button { min-height: 32px; margin-block-start: 1px; padding: 0; }

:where(.atlas-page, .detail-page) :is(.primary, .secondary, .text-button) {
  min-height: 42px; border-radius: 4px; font-size: 13px; line-height: 1.35;
}
:where(.atlas-page, .detail-page) .primary {
  background: var(--accent); color: #fff; font-weight: 700; box-shadow: none; max-width: none;
}
:where(.atlas-page, .detail-page) .primary:hover:not(:disabled) { background: var(--accent-dark); }
:where(.atlas-page, .detail-page) .secondary {
  background: var(--surface); color: var(--accent-dark); border: 1px solid var(--strong-rule);
  text-decoration: none;
}
:where(.atlas-page, .detail-page) .secondary:hover:not(:disabled) { background: var(--wash); border-color: var(--accent); }
:where(.atlas-page, .detail-page) .text-button { color: var(--accent-dark); font-weight: 650; text-underline-offset: .22em; }
:where(.atlas-page, .detail-page) :is(button, input, select):disabled { opacity: .56; cursor: not-allowed; }
:where(.atlas-page, .detail-page) :is(select, input[type=text], input[type=number], input[type=search]) {
  border: 1px solid var(--strong-rule); min-height: 42px; border-radius: 4px; max-width: 100%;
  background: var(--surface); color: var(--ink); font-size: 14px;
}
:where(.atlas-page, .detail-page) input { accent-color: var(--accent); }
:where(.atlas-page, .detail-page) :is(.micro, .stat-sub) { color: var(--muted-ink); }
:where(.atlas-page, .detail-page) .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* Welcome: shown for each fresh entry or reload, not stored in a cookie. */
.atlas-welcome {
  max-width: 950px; width: calc(100% - 42px); max-height: calc(100dvh - 34px);
  border: 1px solid var(--strong-rule); border-radius: 6px; color: var(--ink); background: var(--surface);
  box-shadow: 0 18px 56px #14232630; overscroll-behavior: contain;
}
.atlas-welcome::backdrop { background: rgba(21, 37, 37, .72); backdrop-filter: none; }
.welcome-layout { display: grid; grid-template-columns: 1.07fr 1fr; }
.welcome-copy { padding: clamp(22px, 3.7vw, 46px); }
.welcome-masthead { display: flex; align-items: center; gap: 11px; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.welcome-masthead a { flex: 0 0 auto; }
.welcome-masthead img { display: block; width: 60px; height: auto; }
.welcome-masthead > div:nth-child(2) { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.welcome-masthead strong { line-height: 1.25; font-size: 14px; }
.welcome-masthead span { color: var(--muted-ink); font-size: 12px; line-height: 1.3; }
:where(.atlas-page, .detail-page) .welcome-language { align-self: start; }
:where(.atlas-page, .detail-page) .welcome-language button { min-width: 32px; min-height: 36px; padding: 4px 5px; font-size: 11px; }
.atlas-welcome .welcome-copy .study-kicker { margin: 22px 0 8px; }
.welcome-copy h2 {
  font-family: var(--edition-serif); font-weight: 500; color: var(--ink); font-size: clamp(34px, 3.7vw, 57px);
  letter-spacing: -.032em; line-height: 1.03; margin: 0;
}
.welcome-description { color: var(--muted-ink); font-size: 14px; line-height: 1.6; margin: 13px 0 18px; }
.welcome-credits { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 15px; border-top: 1px solid var(--rule); padding-top: 13px; margin: 0 0 18px; }
.welcome-credits dt { color: var(--muted-ink); font-size: 12px; margin-bottom: 2px; }
.welcome-credits dd { font-size: 15px; font-weight: 700; line-height: 1.25; margin: 0; }
.atlas-welcome .welcome-enter { padding-inline: 18px; min-height: 46px; }
.welcome-plate { display: flex; flex-direction: column; justify-content: center; min-width: 0; margin: 0; background: #193238; }
.welcome-plate img { display: block; width: 100%; height: auto; }
.welcome-plate figcaption {
  color: #e5dfce; margin-inline: 23px; padding-block: 12px 16px; border-top: 1px solid #6d847b;
  display: grid; gap: 4px; font-size: 12px; line-height: 1.35;
}
.welcome-plate figcaption span { color: #bccdc3; font-size: 10px; }

.atlas-page .workspace-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(258px, .33fr);
  grid-template-areas: "map inspector" "stats inspector" "layers inspector";
  gap: 14px; align-items: start;
}
.atlas-page .map-panel { grid-area: map; padding: 0; overflow: clip; min-width: 0; }
.atlas-page .insights { grid-area: inspector; display: grid; width: 100%; grid-template-columns: 1fr; gap: 14px; min-width: 0; }
.atlas-page .stats { grid-area: stats; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.atlas-page .controls { grid-area: layers; display: block; width: 100%; padding: 15px 18px; margin: 0; }
.map-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 15px 0;
}
.map-heading h2, .drawing-controls h2 { color: var(--ink); margin: 0; font-size: 17px; }
.atlas-page .map-toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px 13px; padding: 3px 15px 11px;
  height: auto; min-height: 0;
  align-items: end; color: var(--ink); background: var(--surface); border: 0;
}
.area-select, .grid-chooser { min-width: 0; }
.area-select span, .grid-chooser > span { display: block; font-size: 12px; font-weight: 700; margin: 0 0 5px; }
.atlas-page .area-select select { width: 100%; min-height: 42px; }
.atlas-page .segmented, .atlas-page .map-tabs {
  background: transparent; border: 0; display: flex; gap: 4px; padding: 0;
}
.atlas-page :is(.segmented, .map-tabs) button, .atlas-page .map-control {
  min-height: 42px; min-width: 44px; padding: 6px 10px;
  border: 1px solid var(--strong-rule); border-radius: 4px;
  background: var(--surface); color: var(--ink); box-shadow: none; font-weight: 650;
  font-size: 12px; line-height: 1.25; white-space: normal;
}
.atlas-page .segmented button { white-space: nowrap; }
.atlas-page :is(.segmented,.map-tabs) button[aria-pressed=true] { background: var(--accent); color: #fff; border-color: var(--accent); }
.atlas-page .map-view-controls { grid-column: 1/-1; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.atlas-page .map-view-controls .map-tabs { margin-inline-end: auto; }
.atlas-page .map-wrap {
  flex: none; height: clamp(410px, 54svh, 660px); min-height: 0; width: 100%;
  border-block: 1px solid var(--rule); background: #edede5; isolation: isolate;
}
.atlas-page .map-wrap canvas, .detail-page .draw-map-wrap canvas {
  touch-action: pan-y pinch-zoom;
  inset: 0;
}
.atlas-page .map-wrap canvas.touch-active, .detail-page .draw-map-wrap canvas.touch-active,
.detail-page .draw-map-wrap canvas.drawing { touch-action: none; }
.atlas-page #mapSelection { pointer-events: none; }
.atlas-page #map:focus-visible, .detail-page #drawMap:focus-visible { outline-offset: -3px; }
.map-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; z-index: 2; background: #edede5e8; color: var(--ink); text-align: center; padding: 15px;
}
.map-north { position: absolute; left: 15px; top: 13px; color: var(--ink); pointer-events: none; }
.map-north svg { display: block; fill: currentColor; }
:where(.atlas-page, .detail-page) :is(.zoom-tools, .detail-zoom) {
  top: 12px; right: 12px; left: auto; z-index: 1;
  border: 1px solid var(--strong-rule); border-radius: 4px; box-shadow: none;
}
:where(.atlas-page, .detail-page) :is(.zoom-tools, .detail-zoom) button {
  width: 44px; height: 44px; background: var(--surface); color: var(--ink); font-size: 20px;
  border: 0; box-shadow: none;
}
:where(.atlas-page, .detail-page) :is(.zoom-tools, .detail-zoom) button + button { border-top: 1px solid var(--rule); }
:where(.atlas-page, .detail-page) :is(.zoom-tools, .detail-zoom) button:hover { background: var(--wash); color: var(--ink); }
.atlas-page .scale, .detail-page .draw-scale {
  left: auto; right: 13px; color: var(--ink); border-color: var(--ink); background: #fdfcf7e8;
  font-weight: 700; max-width: 105px; z-index: 1;
}
.atlas-page .map-wrap .zoom-tools, html[dir=rtl] .atlas-page .map-wrap .zoom-tools { right: 12px; left: auto; }
.atlas-page .scale, html[dir=rtl] .atlas-page .map-wrap .scale { bottom: 12px; right: 13px; left: auto; }
.detail-page .draw-scale { bottom: 12px; height: 20px; line-height: 18px; }
.map-touch-button {
  display: none; position: absolute; z-index: 1; top: 12px; left: 12px; min-height: 44px; min-width: 76px;
  padding: 6px 10px; border: 1px solid var(--strong-rule); border-radius: 4px; background: var(--surface);
  color: var(--ink); font-size: 12px; font-weight: 700;
}
.map-touch-button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.atlas-page .map-touch-button { top: auto; bottom: 10px; }
.atlas-page .map-tooltip {
  display: block; z-index: 1; padding: 6px 8px; color: var(--ink); background: var(--surface); border: 1px solid var(--rule);
  border-radius: 3px; box-shadow: none; white-space: nowrap; pointer-events: none; font-size: 11px;
}
.atlas-page .map-legend, html[dir=rtl] .atlas-page .map-legend {
  position: static; max-width: none; padding: 11px 15px; background: var(--surface); border: 0;
  border-bottom: 1px solid var(--rule); border-radius: 0; backdrop-filter: none; color: var(--ink);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 14px; align-items: center;
}
.atlas-page .map-legend strong { color: var(--ink); font-size: 13px; }
.atlas-page .map-legend small { display: block; margin: 3px 0 0; color: var(--muted-ink); font-size: 11px; line-height: 1.4; }
.legend-bands { flex: 1 0 175px; max-width: 290px; }
.atlas-page .legend-colors { display: grid; grid-template-columns: repeat(7, 1fr); height: 13px; overflow: hidden; border: 1px solid var(--strong-rule); border-radius: 2px; gap: 0; margin: 0; }
.atlas-page .legend-colors span { background: var(--density-tone); }
.atlas-page .legend-labels { display: grid; grid-template-columns: repeat(7, 1fr); color: var(--muted-ink); font-size: 10px; margin-top: 3px; text-align: center; gap: 0; }
.road-key-items { display: flex; gap: 7px 16px; flex-wrap: wrap; font-size: 11px; color: var(--ink); }
.road-key-items span { display: inline-flex; gap: 5px; align-items: center; }
.road-key-items i { display: inline-block; width: 14px; height: 3px; }
.map-help { color: var(--muted-ink); padding: 8px 15px; margin: 0; font-size: 12px; line-height: 1.4; }
.atlas-page :is(.map-footer, .map-footer > div) { display: flex; min-height: 0; height: auto; gap: 6px 14px; align-items: center; flex-wrap: wrap; }
.atlas-page .map-footer { padding: 4px 15px 6px; border-top: 1px solid var(--rule); justify-content: space-between; }
.atlas-page .map-footer > div { font-size: 11px; color: var(--muted-ink); }
.atlas-page .map-footer a { color: var(--accent-dark); }
.atlas-page .map-footer :is(a.text-button, button) { align-content: center; min-height: 36px; font-size: 12px; }
.atlas-page .inspect, .atlas-page .share-panel { padding: 17px; }
.atlas-page .cell-id { color: var(--accent-dark); font: 650 12px system-ui; border: 1px solid var(--rule); border-radius: 3px; padding: 4px 7px; }
.atlas-page .inspect-density { margin: 12px 0 10px; color: var(--accent-dark); }
.atlas-page .inspect-density strong { color: inherit; }
.cell-coverage { color: var(--muted-ink); border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 8px; margin: 11px 0 0; padding: 8px 0 0; font-size: 12px; }
.atlas-page #detailCellBtn { margin: 13px 0 7px; min-height: 44px; }
.atlas-page .inspect .compare-actions button { min-height: 44px; }
.atlas-page .stat { min-width: 0; padding: 11px 12px; background: var(--surface); border-color: var(--rule); border-radius: 4px; box-shadow: none; }
.atlas-page .stat .stat-head { color: var(--muted-ink); font-size: 12px; }
.atlas-page .stat .stat-value { gap: 4px 8px; flex-wrap: wrap; margin: 4px 0; }
.atlas-page .stat .stat-value strong { font-size: clamp(20px, 2.4vw, 31px); color: var(--ink); }
.atlas-page .density-stat { border-top: 2px solid var(--accent); background: #eaf1e9; }
.atlas-page .controls summary, .detail-settings summary { color: var(--accent-dark); font-weight: 700; cursor: pointer; padding: 9px 0; min-height: 44px; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 22px; }
.filter-grid section { min-width: 0; }
.atlas-page .controls .boundary-note { margin: 8px 0; color: var(--muted-ink); }
.atlas-page .controls .switch-row, .atlas-page .controls .group-row { min-height: 40px; }
.atlas-page .controls .group-value { white-space: nowrap; }
.atlas-page .study-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.atlas-page :is(.research-desk,.bottom-grid) { margin-top: 16px; }
.atlas-page .research-tabs button { min-height: 42px; }
.atlas-page .research-card { border-radius: 4px; background: var(--surface); border-color: var(--rule); }
.atlas-page .research-card img { max-width: 100%; height: auto; }
.atlas-page .research-table-wrap { overflow: auto; }
.atlas-page .rank-row { min-height: 44px; }
:where(.atlas-page, .detail-page) .page-footer { border-color: var(--rule); color: var(--muted-ink); gap: 8px 16px; }

/* Detailed analysis keeps the drawing tools with the drawing surface. */
.detail-page .engine-notice {
  margin: 0 0 9px; padding: 11px 13px; color: var(--muted-ink); border: 1px solid var(--rule);
  border-inline-start: 3px solid var(--accent); border-radius: 4px; background: var(--surface); font-size: 13px;
}
.engine-notice strong { color: var(--ink); }
.detail-page .engine-notice.unavailable { border-inline-start-color: var(--rust); }
.engine-notice p { margin: 5px 0; line-height: 1.45; max-width: 100ch; }
.engine-notice code { display: inline-block; padding: 2px 5px; border: 1px solid var(--rule); border-radius: 2px; }
.detail-page .page-status:empty { display: none; }
.detail-page .page-status { border-radius: 4px; margin-bottom: 10px; font-size: 13px; }
.detail-page .analysis-busy {
  position: sticky; inset: 0 auto auto; z-index: 3; display: block; padding: 12px 15px; background: var(--wash);
  margin-bottom: 8px; color: var(--ink); border: 1px solid var(--rule); border-radius: 4px; backdrop-filter: none;
}
.detail-page .analysis-busy.hidden { display: none; }
.detail-page .selection-workspace {
  grid-template-columns: minmax(0, 1fr) minmax(240px, .31fr);
  grid-template-areas: "draw settings"; align-items: start; gap: 14px;
}
.detail-page .selection-map-panel { grid-area: draw; width: 100%; min-width: 0; position: relative; top: auto; }
.detail-page .detail-controls { grid-area: settings; width: 100%; min-width: 0; }
.drawing-controls { background: var(--surface); padding: 12px 14px 5px; }
.detail-page .shape-tools { display: flex; gap: 5px; flex-wrap: wrap; margin: 8px 0 4px; }
.detail-page .shape-tools button {
  min-height: 44px; border: 1px solid var(--strong-rule); border-radius: 4px; padding: 6px 9px;
  background: var(--surface); color: var(--ink); font-size: 12px;
}
.detail-page .shape-tools button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.detail-page .shape-tools button { justify-content: center; text-align: center; gap: 0; }
.detail-page .shape-tools button > span:first-child { color: inherit; font-size: inherit; line-height: 1.35; width: auto; }
.detail-page .shape-actions { margin: 5px 0 0; gap: 6px; }
.detail-page .shape-actions button { min-height: 40px; white-space: normal; }
.detail-page #toolHint { font-size: 12px; line-height: 1.4; margin: 5px 0 0; }
.detail-page .selection-map-toolbar { padding: 3px 14px 8px; gap: 8px; flex-wrap: wrap; }
.detail-page .map-focus { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 5px; }
.detail-page .map-focus button {
  min-height: 39px; padding: 5px 8px; border: 1px solid var(--rule); border-radius: 4px;
  color: var(--accent-dark); background: var(--surface); font-size: 12px;
}
.detail-page .draw-map-wrap { height: clamp(370px, 54svh, 650px); min-height: 0; background: #edede5; }
.detail-page .draw-source { bottom: 12px; inset-inline-start: 12px; color: var(--ink); background: #fdfcf7ed; font-size: 9px; padding: 3px 4px; }
.detail-page .selection-map-footer {
  align-items: center; justify-content: flex-start; flex-wrap: wrap; padding: 10px 14px; gap: 8px; color: var(--ink);
}
.selection-status { display: grid; gap: 3px; flex: 1 0 210px; min-width: 0; color: var(--ink); font-size: 12px; line-height: 1.4; }
.selection-status :is(span,small) { color: var(--muted-ink); font-size: 12px; }
.selection-status :is(span,small):empty { display: none; }
.detail-page .selection-map-footer .street-toggle { min-height: 34px; white-space: normal; }
.detail-settings { margin-top: 9px; border-top: 1px solid var(--rule); }
.detail-page .report-actions { max-width: none; }
.detail-page .detail-report { scroll-margin-top: 16px; }
.detail-page .detail-table-wrap { overflow-x: auto; overscroll-behavior-inline: contain; }
.detail-page .report-card :is(.orientation-svg, svg) { max-width: 100%; }
.detail-page .map-tooltip-detail { max-width: calc(100vw - 20px); }

html[lang=ckb] :is(.intro h1,.welcome-copy h2,.detail-intro h1) {
  font-family: NotoArabic, system-ui, sans-serif; letter-spacing: 0; line-height: 1.53; font-weight: 700;
}
html[lang=ckb] :is(.study-kicker,.topbar .brand small) { letter-spacing: 0; }
html[lang=ckb] .welcome-copy h2 { font-size: clamp(27px, 3.2vw, 43px); }
html[lang=ckb] :is(.topbar nav button, .topbar nav a, .welcome-credits dd) { line-height: 1.35; }

@media (pointer: coarse) {
  .map-touch-button { display: block; }
  :where(.atlas-page, .detail-page) :is(.primary,.secondary,.language button,.text-button) { min-height: 44px; }
  .atlas-page .map-tooltip { display: none; }
  .atlas-page :is(.group-row,.switch-row) input { width: 18px; height: 18px; flex-shrink: 0; }
}

@media (max-width: 960px) {
  :where(.atlas-page, .detail-page) .topbar { gap: 12px; }
  .atlas-page .workspace-grid { grid-template-columns: minmax(0, 1fr) 252px; }
  .atlas-page .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .welcome-copy { padding: 29px; }
}

@media (max-width: 760px) {
  :where(.atlas-page, .detail-page) main { padding: 16px 12px 0; }
  :where(.atlas-page, .detail-page) .topbar {
    padding: 7px 12px 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 8px; align-items: center;
  }
  :where(.atlas-page, .detail-page) .topbar .header-right { grid-column: 2; grid-row: 1; }
  :where(.atlas-page, .detail-page) .topbar .brand { min-width: 0; }
  .topbar .brand strong { font-size: 15px; white-space: normal; }
  :where(.atlas-page, .detail-page) .topbar nav {
    grid-column: 1/-1; grid-row: 2; display: flex; justify-content: space-between; min-height: 0;
    width: 100%; height: auto; overflow: visible; gap: 5px 9px; margin: 0; padding: 3px 0 0;
  }
  :where(.atlas-page, .detail-page) .topbar nav :is(a,button) { font-size: 12px; min-height: 44px; white-space: normal; text-align: start; }
  :where(.atlas-page, .detail-page) .topbar nav .nav-active { text-underline-offset: 5px; }
  :where(.atlas-page, .detail-page) :is(.intro,.detail-intro) {
    flex-wrap: wrap; gap: 7px 10px; margin-bottom: 12px; padding-bottom: 9px;
  }
  :where(.atlas-page, .detail-page) :is(.intro,.detail-intro) h1 { font-size: clamp(30px, 8.8vw, 39px); margin: 0 0 4px; }
  :where(.atlas-page, .detail-page) :is(.intro,.detail-intro) > div:first-child p:not(.study-kicker) { line-height: 1.4; }
  .intro-credit { border: 0; padding: 0; flex-direction: row; align-items: center; gap: 4px 8px; flex-wrap: wrap; flex-shrink: 1; font-size: 11px; }
  .intro-credit > bdi { font-size: 12px; }
  :where(.atlas-page, .detail-page) .intro-credit .text-button { margin: 0; font-size: 11px; min-height: 30px; }
  .atlas-page .workspace-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "inspector" "stats" "layers" "composition"; gap: 10px; }
  .atlas-page .map-wrap { height: clamp(295px, 46svh, 445px); }
  .map-heading { padding-inline: 10px; }
  .map-heading h2, .drawing-controls h2 { font-size: 15px; }
  .atlas-page .map-toolbar { padding: 3px 10px 9px; gap: 7px; }
  .atlas-page :is(.map-tabs,.segmented) button, .atlas-page .map-control { padding-inline: 7px; font-size: 11px; }
  .atlas-page .map-view-controls { gap: 4px; }
  .atlas-page .map-legend, html[dir=rtl] .atlas-page .map-legend { padding: 9px 10px; }
  .map-help { padding: 7px 10px; }
  .atlas-page .map-footer { padding: 5px 10px; gap: 2px 10px; }
  .atlas-page .legend-bands { max-width: none; }
  .atlas-page .insights { display: contents; }
  .atlas-page .insights .inspect { grid-area: inspector; }
  .atlas-page .insights .share-panel { grid-area: composition; }
  .atlas-page .insights .inspect { padding: 13px; }
  .atlas-page .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .atlas-page .controls { padding: 11px 13px; }
  .atlas-page .research-desk, .atlas-page .bottom-grid { margin-top: 12px; }
  .atlas-page .bottom-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .atlas-page .research-desk { padding: 13px; }
  .detail-page .selection-workspace { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "draw" "settings"; gap: 10px; }
  .detail-page .draw-map-wrap { height: clamp(285px, 43svh, 440px); }
  .detail-page .selection-map-footer { padding: 9px 10px; }
  .detail-page .selection-status { flex-basis: 100%; }
  .detail-page .shape-tools { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 4px; }
  .detail-page .shape-tools button { min-width: 0; overflow-wrap: anywhere; line-height: 1.2; }
  .detail-page .shape-actions button, .detail-page .map-focus button { min-height: 42px; }
  .detail-page .selection-map-toolbar, .detail-page .drawing-controls { padding-inline: 10px; }
  .detail-page .report-actions button { max-width: 100%; white-space: normal; }
  .detail-page .detail-map-head { min-height: 0; }
  .detail-page .result-map { height: clamp(245px, 42svh, 385px); }
  .detail-page .detail-report { min-width: 0; }
}

@media (max-width: 680px) {
  .atlas-welcome { width: calc(100% - 24px); max-height: calc(100dvh - 20px); }
  .welcome-layout { grid-template-columns: minmax(0, 1fr); }
  .welcome-copy { padding: 16px 17px 15px; }
  .welcome-masthead { padding-bottom: 10px; gap: 8px; }
  .welcome-masthead img { width: 49px; }
  .welcome-masthead strong { font-size: 13px; }
  .welcome-masthead span { font-size: 11px; }
  .atlas-welcome .welcome-copy .study-kicker { margin: 13px 0 6px; }
  .welcome-copy h2 { font-size: clamp(30px, 8.8vw, 43px); }
  .welcome-description { font-size: 13px; line-height: 1.45; margin: 8px 0 12px; }
  .welcome-credits { padding-top: 9px; margin-bottom: 12px; }
  .welcome-credits dd { font-size: 14px; }
  .welcome-plate img { max-height: 210px; object-fit: contain; }
  .welcome-plate figcaption { margin-inline: 16px; padding-block: 7px 9px; }
}

@media (max-width: 425px) {
  .atlas-page .map-toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .atlas-page .area-select select { font-size: max(12px, 3.33vw); }
  .atlas-page .segmented button { min-width: 41px; flex: 1; }
  .atlas-page .legend-labels { font-size: 9px; }
  .atlas-page .filter-grid { grid-template-columns: minmax(0, 1fr); }
  .atlas-page .map-view-controls .map-tabs { margin-inline-end: 0; }
  .atlas-page .map-view-controls > button:last-child { margin-inline-start: auto; }
  .atlas-page .legend-bands { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  :where(.atlas-page, .detail-page) *, :where(.atlas-page, .detail-page) *::before,
  :where(.atlas-page, .detail-page) *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .atlas-welcome, .atlas-welcome::backdrop, .atlas-page .controls, .detail-page .engine-notice,
  .atlas-page .map-north, .atlas-page .zoom-tools, .atlas-page .map-touch-button, .atlas-page .map-toolbar,
  .atlas-page #openLayers, .atlas-page #mapCellFooter, .atlas-page .map-help,
  .intro-credit button, .detail-page .intro-credit, .atlas-page #toast { display: none !important; }
  .atlas-page .workspace-grid { display: block; }
  .atlas-page .map-wrap { height: 420px; }
  .atlas-page .map-wrap canvas, .atlas-page .legend-colors { print-color-adjust: exact; }
  .atlas-page .stats { margin-top: 10px; }
  .atlas-page .insights { display: none; }
  .detail-page main { padding: 0; }
}

.atlas-page .inspect[data-empty=true] :is(.inspect-density, .inspect-pair, #detailCellBtn, .compare-actions) { display: none; }
.detail-page .inventory-sort { display: none; }
@media (max-width: 640px) {
  .detail-page .inventory-sort { display: grid; gap: 4px; font-size: 13px; grid-column: 1 / -1; }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) {
    overflow-x: visible;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table {
    display: block; width: 100%; min-width: 0; border-collapse: separate; background: transparent;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table thead {
    clip-path: inset(50%); position: absolute; width: 1px; height: 1px; overflow: hidden;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table thead button {
    visibility: hidden;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table tbody {
    display: grid; gap: 10px;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table tbody tr {
    display: grid; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 8px; gap: 1px 10px; border: 1px solid var(--rule); border-radius: 4px;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table tbody td {
    display: block; margin: 0; padding: 5px 3px; border: 0; min-width: 0; line-height: 1.35;
    text-align: start; color: var(--ink); white-space: normal; overflow-wrap: anywhere;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table tbody td:first-child {
    grid-column: 1/-1; border-bottom: 1px solid var(--rule); font-weight: 700;
  }
  .detail-page :is(#roadTable,#categoryTable,#tagTable,#contextTable) .detail-table tbody td::before {
    display: block; content: attr(data-label); color: var(--muted-ink);
    font-size: 10px; line-height: 1.3; margin-bottom: 3px; font-weight: 550;
  }
  .detail-page #roadTable .detail-table tbody td:nth-child(6) { grid-column: 1/-1; }
  .detail-page .inventory-controls { align-items: end; }
}
