:root {
  --paper: #faf6ef;
  --ink: #241506;
  --muted: #6b6257;
  --line: #d8cdbd;
  --accent: #8b5a21;
  --ucs: #b8842a;
  --greedy: #c95b50;
  --astar: #34a853;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f3eee6;
}
header {
  padding: 16px 22px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
h1 { margin: 0; font-size: 22px; line-height: 1.15; letter-spacing: 0; }
header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
header a { color: var(--accent); font-weight: 750; text-decoration: none; }
.brand-block {
  display: flex;
  align-items: stretch;
  gap: 12px;
  min-width: min(100%, 620px);
  --brand-logo-height: 58px;
}
.brand-copy { min-width: 0; }
.brand-logo-link {
  flex: 0 0 auto;
  display: inline-flex;
  width: var(--brand-logo-height);
  height: var(--brand-logo-height);
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}
.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
main { max-width: 1400px; margin: 0 auto; padding: 16px; }
.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}
label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 650; }
select, button {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fffaf3;
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
}
button {
  cursor: pointer;
  font-weight: 700;
  background: var(--accent);
  color: #fffaf3;
  border-color: var(--accent);
}
button.secondary {
  width: auto;
  min-height: 30px;
  padding: 6px 9px;
  font-size: 12px;
  background: #fffaf3;
  color: var(--accent);
  border-color: #c8aa7b;
}
button.secondary.scenario-highlight {
  background: #1f6f8b;
  color: #fffaf3;
  border-color: #1f6f8b;
}
button.secondary.scenario-highlight:hover {
  background: #185973;
  border-color: #185973;
}
#scenarios {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 2px 0 12px;
}
#status {
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
  margin: 2px 0 10px;
}
.caminho-narrative {
  display: grid;
  gap: 10px;
  margin: 6px 0 12px;
}
.caminho-narrative:empty { display: none; }
.caminho-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--paper);
  padding: 10px 14px;
}
.caminho-card[data-origin="caminho_velho"] { border-left-color: #8b5a21; }
.caminho-card[data-origin="caminho_novo"] { border-left-color: #1f6f8b; }
.caminho-card[data-origin="caminho_do_sabarabucu"] { border-left-color: #7b4ab2; }
.caminho-card[data-origin="caminho_dos_diamantes"] { border-left-color: #2f8b57; }
.caminho-card[data-origin="descaminhos_do_ouro"] { border-left-color: #9a4b32; }
.caminho-card[data-origin="novo_caminho_da_piedade"] { border-left-color: #bf6f1a; }
.caminho-card.is-stub { background: #fbf5ea; border-left-style: dashed; }
.caminho-kicker {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}
.caminho-name { font-size: 14px; font-weight: 800; color: var(--ink); margin: 0; }
.caminho-cover { color: var(--muted); font-size: 11px; }
.caminho-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 6px;
}
.caminho-fields strong { color: var(--ink); font-weight: 700; }
.caminho-text {
  font-size: 13px;
  line-height: 1.55;
  color: #2f2519;
  max-height: 6.4em;
  overflow: hidden;
  position: relative;
  transition: max-height 0.25s ease;
}
.caminho-text.expanded { max-height: 80em; }
.caminho-text:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2em;
  background: linear-gradient(180deg, transparent, var(--paper));
  pointer-events: none;
}
.caminho-card.is-stub .caminho-text:not(.expanded)::after { background: linear-gradient(180deg, transparent, #fbf5ea); }
.caminho-toggle {
  margin-top: 6px;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}
.caminho-toggle:hover { text-decoration: underline; }
.caminho-stub {
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
}
.map-wrap {
  border: 1px solid var(--line);
  background: #fffaf3;
  border-radius: 8px;
  overflow: hidden;
}
#map { height: 62vh; min-height: 470px; width: 100%; }
.results {
  display: grid;
  grid-template-columns: minmax(360px, 1.2fr) minmax(360px, 1fr);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 12px;
}
.panel h2 { margin: 0 0 8px; font-size: 15px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid #e3dacd; padding: 7px 6px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.best { color: #1d7a36; font-weight: 800; }
.route-preview { color: var(--muted); font-size: 12px; max-width: 460px; }
#profile svg { width: 100%; height: 250px; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.semantic-tooltip {
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}
.popup-aliases {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.semantic-popup {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 8px;
  margin: 8px 0 0;
  font-size: 12px;
}
.semantic-popup dt { color: var(--muted); font-weight: 700; }
.semantic-popup dd { margin: 0; }
.paisagem-popup { max-width: 300px; }
.source-link {
  display: inline-block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.cultural-section { margin-top: 14px; }
.cultural-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.cultural-header h2 { margin: 0; font-size: 15px; }
.cultural-summary { color: var(--muted); font-size: 12px; font-weight: 650; }
.cultural-note { margin: 4px 0 10px; color: var(--muted); font-size: 12px; max-width: 720px; }
.cultural-stops { display: grid; gap: 6px; }
.cultural-stop {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf3;
  overflow: hidden;
}
.cultural-stop[open] { background: var(--paper); }
.cultural-stop summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  flex-wrap: wrap;
}
.cultural-stop summary::-webkit-details-marker { display: none; }
.cultural-stop summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 11px;
  width: 12px;
}
.cultural-stop[open] summary::before { content: "▾"; }
.stop-name { font-weight: 700; flex: 0 0 auto; }
.stop-route { color: var(--muted); font-size: 11px; font-style: italic; }
.stop-badges {
  margin-left: auto;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  font-size: 11px;
}
.stop-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(139, 90, 33, 0.1);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.stop-badge[data-cat="bem_cultural"] { background: rgba(216, 111, 69, 0.13); color: #b8501f; }
.stop-badge[data-cat="grupo_social"] { background: rgba(45, 143, 101, 0.13); color: #1f7a4f; }
.stop-badge[data-cat="sitio_arqueologico"] { background: rgba(51, 121, 189, 0.13); color: #265a91; }
.stop-badge[data-cat="gruta"] { background: rgba(143, 92, 184, 0.13); color: #6e3fa6; }
.stop-badge[data-cat="parque"] { background: rgba(92, 143, 45, 0.13); color: #467a18; }
.stop-badge[data-cat="unidade_conservacao"] { background: rgba(89, 125, 58, 0.15); color: #4a6a2c; }
.stop-badge[data-cat="municipio"] { background: rgba(95, 107, 115, 0.13); color: #4d575e; }
.stop-items {
  display: grid;
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
}
.stop-item {
  display: flex;
  align-items: stretch;
  background: #fffaf3;
  font-size: 13px;
}
.stop-item:hover { background: #fff5e3; }
.stop-item-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}
.stop-item .item-name { font-weight: 650; flex: 1; min-width: 0; }
.stop-item .item-meta { color: var(--muted); font-size: 11px; }
.stop-item .item-arrow { color: var(--accent); font-weight: 800; }
.stop-waze {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  margin: 5px 10px 5px 0;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(31, 111, 139, 0.12);
  color: #1f6f8b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  align-self: center;
}
.stop-waze:hover { background: #1f6f8b; color: #fff; }
.stop-overflow {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--accent);
  background: #fffaf3;
  cursor: pointer;
  border: none;
  text-align: left;
  font-weight: 700;
}
.stop-overflow:hover { background: #fff5e3; }
.stop-item.hidden { display: none; }
.cultural-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }
@media (max-width: 900px) {
  header { align-items: flex-start; }
  .brand-block { align-items: stretch; }
  .toolbar { grid-template-columns: 1fr; }
  .results { grid-template-columns: 1fr; }
  #map { height: 58vh; min-height: 390px; }
  .stop-badges { margin-left: 0; }
}

/* Em tela pequena os textos de cada item dos "Tesouros do trecho" sobrepunham:
   .stop-item-link nao tinha flex-wrap, e .stop-name era flex:0 0 auto (nao encolhia). */
@media (max-width: 600px) {
  .stop-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .stop-item-link {
    flex-wrap: wrap;
    align-items: center;
    column-gap: 10px;
    row-gap: 4px;
  }
  .stop-item .item-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .stop-item .item-arrow {
    flex: 0 0 auto;
    order: 2;
    margin-left: auto;
  }
  .stop-item .item-meta {
    flex: 1 1 100%;
    min-width: 0;
    order: 3;
    overflow-wrap: anywhere;
  }
}
