:root {
  --ink: #1a2332;
  --muted: #5c6b7a;
  --paper: #f3f0ea;
  --panel: rgba(250, 248, 244, 0.96);
  --line: #c8c0b4;
  --accent: #0b6e4f;
  --warn: #8a4b08;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #d9d2c5;
}
body {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
  overflow-x: hidden;
}
.banner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.85rem;
  background: linear-gradient(120deg, #1a2332 0%, #243447 55%, #2f4a3c 100%);
  color: #f7f3ec;
  min-height: 0;
}
.banner h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  max-width: none;
  line-height: 1.2;
}
.banner .sub { font-size: 0.78rem; opacity: 0.85; }
.banner-main { min-width: 0; flex: 1 1 auto; }
.badge {
  flex: 0 0 auto;
  padding: 0.12rem 0.45rem;
  border: 1px solid #e0b089;
  color: #f0d2a8;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr minmax(220px, 300px);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
#map {
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(217, 210, 197, 0.72);
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.map-loading.hidden {
  opacity: 0;
  visibility: hidden;
}
.map-loading-card {
  background: #f7f3ec;
  border: 1px solid var(--line);
  padding: 0.85rem 1.2rem;
  font: 600 0.95rem "Source Sans 3", sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  overflow-x: hidden;
  padding: 0.85rem 1rem 1.25rem;
  backdrop-filter: blur(6px);
  min-width: 0;
}
.panel.right { border-right: none; border-left: 1px solid var(--line); }
.panel h2 {
  margin: 0.2rem 0 0.55rem;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1rem;
}
.panel h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.layer-group {
  margin: 0.55rem 0;
  border-top: 1px solid #e7e0d6;
  padding-top: 0.35rem;
}
.layer-group > summary {
  cursor: pointer;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.layer-group > summary::-webkit-details-marker { display: none; }
.layer-group > summary::before {
  content: "▸";
  font-size: 0.7rem;
  color: var(--ink);
}
.layer-group[open] > summary::before { content: "▾"; }
.group label {
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
  font-size: 0.88rem;
  margin: 0.28rem 0;
  cursor: pointer;
}
.hint {
  margin: 0.2rem 0 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}
.legend { font-size: 0.8rem; line-height: 1.4; }
.legend-box { margin-top: 0.75rem; }
.legend-box summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; }
.legend-note {
  margin: 0.35rem 0 0.55rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}
.swatch {
  display: inline-block;
  width: 1.4rem;
  height: 0.35rem;
  margin-right: 0.35rem;
  vertical-align: middle;
  border-radius: 1px;
}
.swatch.dashed { border-top: 3px dashed #52b788; height: 0; background: none; }
.swatch.dotted { border-top: 3px dotted #95d5b2; height: 0; background: none; }
.dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
}
.note {
  font-size: 0.78rem;
  color: var(--warn);
  background: #f8ead7;
  border-left: 3px solid var(--warn);
  padding: 0.45rem 0.55rem;
  margin: 0.6rem 0;
}
.sources { font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
.stats-block { min-width: 0; }
.stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem 0.65rem;
  align-items: start;
  font-size: 0.85rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid #e7e0d6;
  min-width: 0;
}
.stat-label {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.3;
}
.stat-value {
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 9.5rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.density-legend {
  margin: 0.4rem 0 0.6rem;
  padding: 0.45rem;
  background: #efeae1;
  border-radius: 4px;
}
.density-scale {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
}
.density-scale-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
}
.density-swatch {
  width: 1.1rem;
  height: 0.75rem;
  border: 1px solid rgba(0,0,0,0.15);
  flex: 0 0 auto;
}
.map-ui {
  position: absolute;
  z-index: 2;
  top: 0.65rem;
  left: 0.65rem;
  display: none;
  gap: 0.4rem;
}
.map-btn {
  border: 1px solid #b08968;
  background: #f7f3ec;
  font: 600 0.82rem "Source Sans 3", sans-serif;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}
#fly-cable {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translateX(-50%);
  bottom: 2.6rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid #1d4e89;
  background: #f7f3ec;
  font: 600 0.85rem "Source Sans 3", sans-serif;
  cursor: pointer;
}
#fly-cable.flying {
  border-color: #9d0208;
  color: #9d0208;
}
.maplibregl-popup-content {
  max-height: min(42vh, 280px);
  overflow-y: auto;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  max-width: 260px;
}
.maplibregl-popup {
  z-index: 3;
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drawer-close {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 20;
}

@media (max-width: 900px) {
  .banner h1 { font-size: 0.95rem; }
  .banner .sub { display: none; }
  .layout {
    grid-template-columns: 1fr;
  }
  .panel.drawer {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    /* 22-S3: keep close button inside the viewport */
    width: min(359px, 100vw);
    max-width: 100%;
    box-sizing: border-box;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 24px rgba(0,0,0,0.25);
  }
  .panel.drawer.right {
    left: auto;
    right: 0;
    transform: translateX(105%);
  }
  .panel.drawer.open { transform: translateX(0); }
  .drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0.25rem;
    z-index: 2;
    min-width: 2.25rem;
    min-height: 2.25rem;
  }
  .map-ui { display: flex; }
  #fly-cable { bottom: 3.2rem; }
}

@media (max-width: 700px) {
  .badge { font-size: 0.58rem; padding: 0.1rem 0.35rem; }
  .banner {
    padding: 0.35rem 0.55rem;
    flex-direction: column;
    align-items: flex-start;
  }
  .banner h1 { font-size: 0.92rem; }
}

@media (pointer: coarse) {
  #terrain-hint { display: none; }
  #terrain-hint-touch { display: block; }
}
#terrain-hint-touch { display: none; }

.banner-links { display: flex; gap: 0.55rem; flex-wrap: wrap; }
.banner-link {
  background: transparent;
  border: none;
  color: #f0d2a8;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  padding: 0;
}
.guided-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: #ebe4d8;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.guided-btn {
  border: 1px solid var(--line);
  background: #f7f3ec;
  color: var(--ink);
  border-radius: 4px;
  padding: 0.28rem 0.55rem;
  font: 600 0.78rem "Source Sans 3", sans-serif;
  cursor: pointer;
}
.guided-btn[aria-pressed="true"] {
  background: #1a2332;
  color: #f7f3ec;
  border-color: #1a2332;
}
.guided-select-wrap { display: none; margin-left: auto; }
.guided-select-wrap select {
  font: 600 0.78rem "Source Sans 3", sans-serif;
  padding: 0.25rem 0.4rem;
}
.guided-caption {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 4;
  max-width: min(420px, 88vw);
  background: rgba(250, 248, 244, 0.94);
  border: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}
.welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.welcome-modal[hidden] { display: none !important; }
.welcome-card {
  background: #f7f3ec;
  border: 1px solid var(--line);
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
  padding: 1.1rem 1.25rem 1.25rem;
  box-shadow: 0 16px 40px rgba(0,0,0,0.25);
}
.welcome-card h2 {
  margin: 0 0 0.55rem;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.25rem;
}
.welcome-card h3 { margin: 0.85rem 0 0.35rem; font-size: 0.95rem; }
.welcome-card p, .welcome-card li { font-size: 0.9rem; line-height: 1.45; }
.welcome-draft { margin-top: 0.75rem; }
.welcome-guided {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.85rem 0;
}
.welcome-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.glossary { margin: 0.5rem 0 1rem; }
.glossary dt { font-weight: 700; margin-top: 0.55rem; }
.glossary dd { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.88rem; }
.method-note { margin: 0.75rem 0; font-size: 0.82rem; }
.method-note summary { cursor: pointer; font-weight: 600; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
.gap-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid #e7e0d6;
  background: transparent;
  padding: 0.35rem 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.gap-row:hover { background: rgba(0,0,0,0.04); }
body {
  grid-template-rows: auto auto 1fr;
}

@media (max-width: 900px) {
  .guided-bar .guided-btn { display: none; }
  .guided-select-wrap { display: block; width: 100%; }
  .guided-select-wrap select { width: 100%; }
}

/* ---- Context data group (REVIEW_NOTES_24) ---- */
.ctx-layer { margin: 0.45rem 0 0.6rem; padding-bottom: 0.35rem; border-bottom: 1px dotted #e0d9ce; }
.ctx-sub { margin: 0.2rem 0 0.2rem 1.4rem; }
.ctx-sub[hidden], .ctx-facts[hidden] { display: none; }
.ctx-subhead { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 0.15rem; }
.ctx-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; margin: 0.15rem 0 0.3rem; }
.ctx-seg button { font: inherit; font-size: 0.78rem; padding: 0.18rem 0.6rem; border: 0; border-right: 1px solid var(--line); background: #fbf9f5; cursor: pointer; color: var(--ink); }
.ctx-seg button:last-child { border-right: 0; }
.ctx-seg button.on { background: #1a2332; color: #f7f3ec; }
.ctx-seg button:disabled { opacity: 0.45; cursor: default; }
.ctx-radios label, .ctx-inline { font-size: 0.82rem !important; margin: 0.18rem 0 !important; }
.ctx-checks { display: flex; flex-wrap: wrap; gap: 0 0.7rem; }
.ctx-years { display: flex; gap: 0.6rem; font-size: 0.8rem; margin: 0.25rem 0; align-items: center; }
.ctx-years label { display: inline-flex !important; align-items: center; gap: 0.3rem; margin: 0 !important; }
.ctx-years select { font: inherit; font-size: 0.8rem; padding: 0.05rem 0.2rem; }
.ctx-legend { font-size: 0.78rem; line-height: 1.35; margin: 0.3rem 0; }
.ctx-legend .ctx-plain { margin: 0 0 0.25rem; color: var(--ink); }
.ctx-legend .ctx-row { display: flex; align-items: center; gap: 0.4rem; margin: 0.08rem 0; }
.ctx-sw { display: inline-block; width: 1.15rem; height: 0.7rem; border: 1px solid rgba(26,35,50,0.25); flex: 0 0 auto; }
.ctx-sw.grey { background: #b8bcc2; border-style: dashed; }
.ctx-sw.round { border-radius: 50%; width: 0.7rem; }
.ctx-source { font-size: 0.7rem; color: var(--muted); line-height: 1.35; margin: 0.25rem 0 0.1rem; }
.ctx-spark { margin: 0.35rem 0; }
.ctx-spark svg { width: 100%; height: auto; display: block; }
.ctx-spark .ctx-spark-cap { font-size: 0.72rem; color: var(--muted); margin-top: 0.1rem; }
.ctx-facts { margin: 0.2rem 0 0.6rem; border: 1px solid #e0d9ce; background: #fbf9f5; padding: 0.3rem 0.5rem; }
.ctx-facts > summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; }
.ctx-facts-list { margin: 0.4rem 0 0.2rem; padding-left: 1rem; font-size: 0.8rem; line-height: 1.35; }
.ctx-facts-list li { margin: 0.3rem 0; }
.ctx-facts-list .ctx-fact-src { display: block; font-size: 0.68rem; color: var(--muted); }
.ctx-bar { display: flex; height: 12px; width: 220px; border: 1px solid rgba(26,35,50,0.3); margin: 4px 0; }
.ctx-bar span { display: block; height: 100%; }
.ctx-bar-key { font-size: 11px; line-height: 1.4; }
.ctx-bar-key i { display: inline-block; width: 8px; height: 8px; margin-right: 3px; vertical-align: baseline; }
