/* ============================================================
   Mangroves. Carbon. A living register. - RCoE Arts & Maps 2026
   Native-scroll scrollytelling: sticky basemap behind paper steps.
   ============================================================ */

:root {
  --navy: #06201a;
  --paper: rgba(255, 254, 249, 0.94);
  --ink: #0b2521;
  --muted: #48615b;
  --line: #d8e5df;
  --green: #0f7a45;
  --teal: #0b6e6f;
  --gold: #9a6a00;
  --hl: #e6550d;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  min-height: 100%;
  margin: 0;
  background: var(--navy);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; }

a { color: var(--green); overflow-wrap: anywhere; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

#legend-toggle:focus-visible,
#rail button:focus-visible { outline-color: var(--gold); }

/* ---------- Layout ---------- */

.scrolly { position: relative; z-index: 1; }

.scrolly-map-wrap {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  z-index: 0;
}

#map { position: absolute; inset: 0; background: #dbe7e0; }

#story-caption {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 57;
  max-width: min(46vw, 360px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  padding: 8px 14px;
  pointer-events: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #eaf7f0;
  background: rgba(6, 32, 26, 0.85);
  border: 1px solid rgba(234, 247, 240, 0.28);
  border-radius: 999px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#tile-error {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid var(--gold);
  border-radius: 10px;
  background: #fff8e8;
  color: #6b4a00;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

#tile-error[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(64px, calc(env(safe-area-inset-bottom) + 58px));
  transform: translateX(-50%);
  z-index: 900;
  max-width: min(80vw, 520px);
  padding: 9px 14px;
  border-radius: 10px;
  background: #06201a;
  color: #eaf7f0;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(4, 24, 20, 0.3);
  pointer-events: none;
}
.toast[hidden] { display: none; }

.invite-row { display: flex; flex-wrap: wrap; gap: 8px; }
.mpa-filters label[title] { cursor: help; }

.term {
  border-bottom: 1px dotted rgba(6, 32, 26, 0.4);
  cursor: help;
}
.term:focus-visible,
.term:hover { border-bottom-color: var(--green); }

.scrolly-steps {
  position: relative;
  z-index: 500;
  margin-top: -100vh;
  margin-top: -100svh;
  padding-top: 1px;
  padding-bottom: 24vh;
  padding-bottom: 24svh;
  pointer-events: none;
}

.step {
  pointer-events: auto;
  width: min(420px, 92vw);
  margin: 16vh 0 16vh 14px;
  margin: 16svh 0 16svh 14px;
  padding: 22px 24px 24px;
  max-height: min(70vh, 640px);
  max-height: min(70svh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(6, 32, 26, 0.24) transparent;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(4, 24, 20, 0.18);
  color: var(--ink);
  transform: translateY(10px);
  transition: transform 0.45s ease, box-shadow 0.45s ease, background 0.45s ease;
}

.step:not(.active) {
  background: rgba(255, 254, 249, 0.86);
  box-shadow: 0 6px 18px rgba(4, 24, 20, 0.12);
}

.step.active {
  transform: none;
  box-shadow: 0 16px 44px rgba(4, 24, 20, 0.26);
}

.step.hero {
  margin-top: 34vh;
  margin-top: 34svh;
  max-height: min(72vh, 680px);
  max-height: min(72svh, 680px);
  padding: 30px 32px 34px;
}

.step.sources-step,
.step.mpa-step {
  width: min(560px, calc(100vw - 28px));
  margin: 14vh 0 14vh 14px;
  margin: 14svh 0 14svh 14px;
  max-height: min(76vh, 780px);
  max-height: min(76svh, 780px);
}

/* ---------- Typography ---------- */

.kicker {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
}

.step h1 {
  margin: 0 0 12px;
  font-size: clamp(34px, 6.4vw, 52px);
  line-height: 1.04;
  color: var(--ink);
}

.step h1 em { font-style: italic; color: var(--green); }

.step h2 {
  margin: 0 0 12px;
  font-size: clamp(22px, 3.4vw, 28px);
  line-height: 1.12;
  color: var(--ink);
}

.step p {
  margin: 12px 0;
  font-size: clamp(15px, 1.05vw, 16.5px);
  line-height: 1.65;
}

.hero-tag {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-tagline {
  margin: 0 0 6px;
  font-size: clamp(16px, 1.4vw, 19px);
  color: var(--muted);
}

.hero-byline {
  margin: 0 0 14px;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--muted);
}
.hero-byline strong { color: var(--ink); font-weight: 650; }

.muted { color: var(--muted); }

/* ---------- Stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 6px;
}

.stat-grid--2cols { grid-template-columns: repeat(2, 1fr); }

.stat {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(11, 118, 111, 0.05);
}

.stat strong {
  display: block;
  font-size: clamp(19px, 1.7vw, 23px);
  font-weight: 700;
  color: var(--green);
}

.stat span {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
}

.stat .unit {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Gazi chart ---------- */

#gazi-chart { margin: 18px 0 4px; }

.gazi-labels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.gazi-labels span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.25;
  color: var(--muted);
  text-align: center;
}

.gazi-track {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  align-items: end;
  min-height: 110px;
}

.gbar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.gbar strong {
  display: block;
  width: 100%;
  max-width: 54px;
  min-height: 4px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #2fbf71 0%, #0f7a45 100%);
  box-shadow: inset 0 0 0 1px rgba(6, 32, 26, 0.12);
  transition: height 0.6s ease;
}

.gbar.verified strong { background: linear-gradient(180deg, #4fc3c4 0%, #0b6e6f 100%); }
.gbar.proj strong { background: linear-gradient(180deg, #f4b400 0%, #8a6a1f 100%); }
.gbar.restore strong { background: linear-gradient(180deg, #7fc4e8 0%, #2c7fb8 100%); }
.gbar.earn strong { background: linear-gradient(180deg, #c07fd0 0%, #762a83 100%); }

.gbar span {
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  color: var(--ink);
}

.gazi-note {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  background: rgba(154, 106, 0, 0.07);
  border-radius: 0 10px 10px 0;
  font-size: 13.5px;
  line-height: 1.55;
}

/* ---------- Sources ---------- */

.sources-step .inner > strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
}

.sources-step p {
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0 0 10px;
}

/* ---------- Protected-area UI ---------- */

.mpa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 12px;
}

.mpa-chips[hidden] { display: none; }

.mpa-chip {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.mpa-chip:hover { border-color: var(--teal); color: var(--teal); }

.mpa-chip[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.mpa-clear {
  margin: 4px 0 12px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.mpa-clear[hidden] { display: none; }

.mpa-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.mpa-cards[hidden] { display: none; }

.mpa-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mpa-card:hover { border-color: var(--teal); }

.mpa-card[aria-pressed="true"] {
  border-color: var(--hl);
  box-shadow: 0 0 0 2px rgba(230, 85, 13, 0.35);
}

.mpa-card[hidden] { display: none; }

.mpa-card .idtag,
.mpa-detail .idtag {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mpa-card .n { display: block; margin-top: 4px; font-size: 14.5px; font-weight: 700; }
.mpa-card .d { display: block; margin-top: 3px; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.mpa-card .a { display: block; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--green); }

.mpa-detail {
  margin: 14px 0 12px;
  padding: 16px 18px;
  border: 1px solid rgba(8, 81, 156, 0.32);
  border-radius: 14px;
  background: #f4faff;
}

.mpa-detail[hidden] { display: none; }

.mpa-detail h3 { margin: 4px 0 0; font-size: 18px; line-height: 1.25; }

.mpa-detail .designation {
  margin: 5px 0 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}

.mpa-detail-grid {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px 18px;
}

.mpa-detail-item { border-top: 1px solid var(--line); padding-top: 8px; }

.mpa-detail-item dt {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mpa-detail-item dd {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
  color: var(--ink);
}

.mpa-detail-note { margin: 12px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* ---------- Chapter rail ---------- */

#rail {
  position: fixed;
  right: 14px;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 14px));
  z-index: 600;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 10px;
  border-radius: 16px;
  background: rgba(6, 32, 26, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.rail-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: rgba(234, 247, 240, 0.72);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.rail-btn > span:first-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(234, 247, 240, 0.18);
  font-size: 10px;
}

.rail-label {
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  transition: max-width 0.25s ease, opacity 0.25s ease;
}

.rail-btn:hover .rail-label,
.rail-btn.on .rail-label { max-width: 160px; opacity: 1; }

.rail-btn:hover { color: #eaf7f0; background: rgba(234, 247, 240, 0.12); }

.rail-btn.on { color: #fff; background: rgba(230, 85, 13, 0.9); }
.rail-btn.on > span:first-child { background: rgba(255, 255, 255, 0.28); }

/* ---------- Legend ---------- */

#legend-toggle {
  position: fixed;
  right: 240px;
  bottom: max(46px, calc(env(safe-area-inset-bottom) + 42px));
  z-index: 600;
  padding: 8px 14px;
  border: 1px solid rgba(234, 247, 240, 0.35);
  border-radius: 999px;
  background: rgba(6, 32, 26, 0.78);
  color: #eaf7f0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#legend {
  position: fixed;
  right: 240px;
  bottom: max(90px, calc(env(safe-area-inset-bottom) + 86px));
  z-index: 600;
  width: 248px;
  max-height: min(62vh, 460px);
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(4, 24, 20, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#legend[hidden] { display: none; }

.leg-item { padding: 4px 0; border-bottom: 1px solid var(--line); }
.leg-item:last-of-type { border-bottom: none; }

.leg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 2px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 12.5px;
  line-height: 1.3;
  cursor: pointer;
}

.leg-row[aria-pressed="false"] { opacity: 0.45; }

.leg-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(6, 32, 26, 0.25);
  flex: none;
}

.leg-name { font-weight: 600; }
.leg-name small { font-weight: 500; font-size: 10.5px; color: var(--muted); }

.leg-opacity { display: flex; align-items: center; gap: 8px; padding: 0 2px 4px 24px; }

.leg-op-text {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.leg-opacity input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--green);
}

.leg-foot { padding-top: 8px; border-top: 1px solid var(--line); }

.leg-reset {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 118, 111, 0.08);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--teal);
  cursor: pointer;
}

.leg-reset:hover { background: rgba(11, 118, 111, 0.16); }

/* ---------- Ask panel ---------- */

#ask-toggle {
  position: fixed;
  top: max(14px, calc(env(safe-area-inset-top) + 14px));
  right: 14px;
  z-index: 620;
  padding: 8px 14px;
  border: 1px solid rgba(234, 247, 240, 0.35);
  border-radius: 999px;
  background: rgba(6, 32, 26, 0.78);
  color: #eaf7f0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#ask {
  position: fixed;
  top: max(56px, calc(env(safe-area-inset-top) + 56px));
  right: 14px;
  z-index: 620;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(340px, calc(100vw - 28px));
  max-height: min(70vh, 560px);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 16px 44px rgba(4, 24, 20, 0.28);
}

#ask[hidden] { display: none; }

.ask-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ask-head strong { font-size: 14px; }

.ask-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.ask-hint { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--muted); }

.ask-log {
  flex: 1 1 auto;
  min-height: 60px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ask-msg {
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.ask-msg.you { background: rgba(11, 118, 111, 0.1); font-weight: 600; }
.ask-msg.map { background: rgba(15, 122, 69, 0.08); border-left: 3px solid var(--green); }
.ask-msg.err { background: rgba(230, 85, 13, 0.1); border-left: 3px solid var(--hl); }

.ask-form { display: flex; gap: 6px; }

.ask-form input,
.ask-key input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.ask-form button,
.ask-key button {
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ask-key { display: flex; flex-wrap: wrap; gap: 6px; }
.ask-key[hidden] { display: none; }

.ask-note { margin: 4px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }
.ask-note code { font-size: 10.5px; }

.ask-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Load error ---------- */

#load-error {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 14px));
  transform: translateX(-50%);
  z-index: 700;
  width: min(560px, 92vw);
  padding: 12px 16px;
  border: 1px solid #a33;
  border-radius: 12px;
  background: #fff4f2;
  color: #7c1d0e;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(4, 24, 20, 0.3);
}

/* ---------- MapLibre attribution ---------- */

.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  background: rgba(255, 254, 249, 0.75) !important;
}

.maplibregl-ctrl-attrib a { color: var(--muted); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .step {
    width: min(480px, calc(100vw - 28px));
    margin: 58vh 14px 16vh;
    margin: 58svh 14px 16svh;
    max-height: min(38vh, 430px);
    max-height: min(38svh, 430px);
  }

  .step.hero {
    margin-top: 48vh;
    margin-top: 48svh;
    max-height: min(44vh, 420px);
    max-height: min(44svh, 420px);
  }

  .step.sources-step,
  .step.mpa-step {
    width: calc(100vw - 28px);
    margin: 56vh 14px 18vh;
    margin: 56svh 14px 18svh;
    max-height: min(42vh, 520px);
    max-height: min(42svh, 520px);
  }

  #story-caption {
    max-width: calc(100vw - 130px);
    bottom: max(74px, calc(env(safe-area-inset-bottom) + 70px));
  }

  #rail {
    left: 10px;
    right: 10px;
    bottom: max(64px, calc(env(safe-area-inset-bottom) + 58px));
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
  }

  .rail-label { display: none; }
  .rail-btn { padding: 4px 6px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .mpa-cards { grid-template-columns: repeat(2, 1fr); }
  #ask { max-height: min(60vh, 460px); }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .mpa-cards { grid-template-columns: 1fr; }
  .gazi-labels span { font-size: 8.5px; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .step { transform: none; transition: none; }
  #rail button,
  .mpa-chip,
  .mpa-card,
  .rail-label,
  .gbar strong { transition: none; }
}

/* ---------- Expanded controls (target-only) ---------- */

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 800;
  padding: 8px 14px;
  border-radius: 0 0 10px 10px;
  background: var(--navy);
  color: #eaf7f0;
  font-size: 13px;
  text-decoration: none;
  transition: top .18s ease;
}
.skip-link:focus { top: 0; }

#map-loading {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12.5px;
  box-shadow: 0 6px 18px rgba(4, 24, 20, .18);
}
#map-loading[hidden] { display: none; }

#chapter-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  z-index: 55;
  background: rgba(255, 254, 249, .35);
}
#chapter-progress::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--p, 12.5%);
  background: var(--hl);
  transition: width .35s ease;
}

.map-tools {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 58;
  width: min(640px, calc(100% - 150px));
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.map-search { display: block; flex: 1 1 240px; min-width: 200px; }
.map-search input,
.map-search select {
  width: 100%;
  max-width: 100%;
  cursor: pointer;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.map-search-results {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(4, 24, 20, .18);
}
.map-search-results[hidden] { display: none; }
.map-search-results button {
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.map-search-results button:last-child { border-bottom: none; }
.map-search-results button:hover { background: rgba(15, 122, 69, .08); }
.map-search-none { margin: 0; padding: 8px 10px; font-size: 12.5px; color: var(--muted); }

.map-tool-row { display: flex; flex-wrap: wrap; gap: 6px; }
.map-tool-row button,
.bulk-btn {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.map-tool-row button:hover,
.bulk-btn:hover { border-color: var(--teal); color: var(--teal); }

.coords {
  min-height: 16px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

#return-story {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  z-index: 58;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
#return-story[hidden] { display: none; }

.leg-key,
.leg-group,
.leg-site-note {
  margin: 6px 0 2px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}
.leg-group { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink); }
.leg-links { display: flex; align-items: center; gap: 8px; padding: 2px 0 4px; font-size: 11px; }
.leg-links .js-focus {
  border: none;
  background: transparent;
  color: var(--teal);
  font: inherit;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.leg-links .js-src { color: var(--muted); }
.leg-state { color: var(--muted); margin-left: auto; }
.leg-foot-row { display: flex; gap: 6px; }

.mpa-filter-label,
.mpa-filters label,
.mpa-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}
.mpa-filter-label { margin: 8px 0 4px; }
.mpa-filter-note { margin: 2px 0 8px; font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.mpa-filter-label input,
.mpa-filter-label select,
.mpa-filters select,
.mpa-toolbar select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}
.mpa-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 6px 0;
}
.mpa-filters button,
.mpa-toolbar button {
  align-self: end;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.mpa-filters button:hover,
.mpa-toolbar button:hover { border-color: var(--teal); color: var(--teal); }
.mpa-count { margin: 4px 0; font-size: 11.5px; color: var(--muted); }
.mpa-toolbar { display: flex; align-items: end; gap: 8px; margin: 6px 0; }

.mpa-compare-view {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  overflow: hidden;
}
.mpa-compare-view[hidden] { display: none; }
.mpa-compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.mpa-compare-head button {
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.mpa-compare-table-wrap { max-height: 260px; overflow: auto; }

.gazi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.gazi-head button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.gazi-head button:hover { border-color: var(--teal); color: var(--teal); }

.gazi-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 11.5px;
}
.gazi-table th,
.gazi-table td {
  padding: 5px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.gazi-table th { color: var(--ink); font-weight: 700; }

.suggested { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.suggested-q {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--teal);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.suggested-q:hover { border-color: var(--teal); }

.ask-status { margin: 4px 0; font-size: 11.5px; color: var(--muted); }
.ask-status[hidden] { display: none; }
.ask-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.ask-actions button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.ask-actions button[hidden] { display: none; }
.ask-log.expanded { max-height: none; }

.src-ref { color: var(--teal); text-decoration: none; }
.src-ref:hover { text-decoration: underline; }

.layer-sources { margin: 4px 0 8px; padding-left: 18px; font-size: 12px; line-height: 1.6; }
.layer-sources code { font-size: 11px; }

@media (max-width: 900px) {
  .map-tools { width: min(260px, calc(100% - 28px)); }
  .mpa-filters { grid-template-columns: 1fr; }
  /* rail becomes a full-width bottom row on small screens: park the legend above it, left */
  #legend-toggle { right: auto; left: max(14px, calc(env(safe-area-inset-left) + 14px)); bottom: max(112px, calc(env(safe-area-inset-bottom) + 106px)); }
  #legend { right: auto; left: max(14px, calc(env(safe-area-inset-left) + 14px)); bottom: max(156px, calc(env(safe-area-inset-bottom) + 150px)); max-height: min(46vh, 380px); }
}
