@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #2b2a26;
  --muted: #8a8168;
  --cream: #faf5e9;
  --paper: #f2ead9;
  --line: #ddd3bd;
  --forest: #38513f;
  --accent: #b4553a;
  --accent-soft: #e8cfc0;
  --olive: #7d8a5a;
  --card: #fffdf5;
  --shadow: 0 8px 22px rgba(60, 50, 30, .18);
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: linear-gradient(120deg, #2e4235, #43564a 60%, #5a6a50);
  color: #f4eddd;
  border-bottom: 3px solid #b9a77e;
}
.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent);
  display: inline-block; position: relative;
}
.mark::before {
  content: ''; position: absolute; left: 50%; top: 6px;
  border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-bottom: 11px solid #f7f1e3; transform: translateX(-50%);
}
.brand h1 {
  font-family: var(--serif); font-weight: 600; font-size: 22px;
  letter-spacing: .3px; margin: 0; line-height: 1;
}
.brand .tagline { font-size: 11.5px; margin: 2px 0 0; opacity: .82; letter-spacing: .4px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.chip {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 13px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff8ef; }
.topbar .chip { background: #f6efdf; color: #2e4235; border-color: #d8c9a4; }
.chat-chip { background: var(--accent); border-color: var(--accent); color: #fff8ef; }

/* ---------- layout ---------- */
.layout { display: flex; flex: 1 1 auto; min-height: 0; }
.sidepanel {
  width: 300px; overflow-y: auto; padding: 14px 16px;
  background: var(--cream); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
.mapwrap { flex: 1 1 auto; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--paper); }

/* ---------- side panel cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; box-shadow: 0 1px 4px rgba(60,50,30,.08);
}
.card h2 {
  font-family: var(--serif); font-weight: 600; font-size: 14.5px;
  margin: 0 0 8px; display: flex; align-items: center; gap: 6px;
}
.minilink { font-size: 11px; color: var(--muted); background: none; border: none; cursor: pointer; }
.hint { font-size: 11.5px; color: var(--muted); margin: 4px 0 8px; line-height: 1.45; }

.searchwrap { position: relative; }
#search, #versesearch, #chat-input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; font-size: 13.5px; background: #fffdf5; color: var(--ink);
}
#search:focus, #versesearch:focus, #chat-input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(180,85,58,.18);
}
.suggestions {
  list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto;
  position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
}
.suggestions li { padding: 7px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #efe6d0; }
.suggestions li { display: flex; align-items: center; gap: 8px; }
.suggestions .sugtext { flex: 1 1 auto; min-width: 0; }
.suggestions li:last-child { border-bottom: none; }
.suggestions li:hover, .suggestions li.sel { background: var(--accent-soft); }
.suggestions small { color: var(--muted); display: block; font-size: 11px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip.active[data-t] {}
#jumps { display: flex; flex-wrap: wrap; gap: 6px; }
#jumps .jumpchip { font-size: 12px; padding: 4px 10px; }

.legend { list-style: none; margin: 0; padding: 0; }
.legend li {
  display: flex; align-items: center; gap: 9px; padding: 5px 6px 5px 2px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
}
.legend li:hover { background: #f6efdf; }
.legend li svg { flex: 0 0 18px; }
.legend li .lname { flex: 1 1 auto; }
.legend li .lcount { color: var(--muted); font-size: 11.5px; }
.legend li.off { opacity: .42; text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.legend-regions { margin-top: 4px; }
.mapnote {
  position: absolute; left: 12px; bottom: 74px; z-index: 599;
  background: rgba(255, 253, 245, .95); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 11.5px; color: var(--ink); max-width: 300px;
  box-shadow: var(--shadow);
}

.verse-results { margin-top: 6px; font-size: 12.5px; }
.verse-results hr { border: none; border-top: 1px solid var(--line); margin: 6px 0; }
.verse-results .vr-title { font-weight: 600; color: var(--ink); margin: 0 0 4px; }
.verse-results ul { margin: 0; padding: 0 0 0 14px; }
.verse-results li { margin-bottom: 2px; }
.verse-results .vr-empty { color: var(--muted); font-style: italic; }

#count-note { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.note { font-size: 11.5px; color: var(--muted); line-height: 1.45; }

/* ---------- layers ---------- */
.layers {
  position: absolute; left: 12px; bottom: 34px; z-index: 600;
  display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; box-shadow: 0 3px 10px rgba(60,50,30,.2);
}
.layers button {
  border: none; background: transparent; font-size: 12px; padding: 5px 9px;
  border-radius: 7px; cursor: pointer; color: var(--ink); font-weight: 500;
}
.layers button.active { background: var(--forest); color: #f4eddd; }

/* ---------- detail card ---------- */
.detail {
  position: absolute; right: 14px; top: 14px; z-index: 602;
  width: 320px; max-height: calc(100% - 90px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; box-shadow: var(--shadow);
}
.detail h3 { font-family: var(--serif); font-weight: 600; font-size: 19px; margin: 0; }
.detail .meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.detail .summary { font-size: 13px; line-height: 1.5; color: var(--ink); margin: 6px 0 10px; }
.detail .refbox h4 { font-family: var(--serif); font-size: 13px; margin: 8px 0 4px; font-weight: 600; }
.refs { display: flex; flex-wrap: wrap; gap: 5px; }
.refs .ref {
  border: 1px solid #c9b895; background: #faf3e2; color: #5b4a24;
  border-radius: 999px; padding: 2.5px 8px; font-size: 11.5px; cursor: pointer;
}
.refs .ref:hover { background: var(--accent-soft); }
.refs .ref.active { background: var(--accent); color: #fff8ef; border-color: var(--accent); }
.refs-more { font-size: 11.5px; color: var(--muted); font-style: italic; margin: 7px 0 0; }
.detail .close-detail { position: absolute; right: 10px; top: 8px; border: none; background: none; font-size: 18px; color: var(--muted); cursor: pointer; }
.related { margin-top: 8px; }
.related h4 { font-family: var(--serif); font-size: 12.5px; margin: 0 0 5px; font-weight: 600; }
.related ul { margin: 0; padding-left: 16px; font-size: 12.5px; }
.related li { margin-bottom: 3px; cursor: pointer; color: #4d5a3a; }
.related li:hover { text-decoration: underline; }
.detail .appr { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 4px; }

/* ---------- build a map ---------- */
.build-pick { display: flex; gap: 6px; }
.build-pick .chip { flex: 1 1 auto; padding: 5px 8px; }
#selection-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 190px; overflow-y: auto; }
#selection-list li {
  display: flex; align-items: center; gap: 6px; padding: 4px 2px;
  border-top: 1px solid #efe6d0; font-size: 12.5px;
}
#selection-list li:first-child { border-top: none; }
#selection-list .sel-name {
  flex: 1 1 auto; text-align: left; background: none; border: none;
  font: inherit; color: var(--ink); cursor: pointer; padding: 2px 4px; border-radius: 6px;
}
#selection-list .sel-name:hover { background: #f6efdf; }
#selection-list .sel-del {
  border: none; background: none; color: var(--muted); font-size: 16px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
#selection-list .sel-del:hover { color: var(--accent); }
#selection-list .sel-empty { color: var(--muted); font-style: italic; border: none; }

.add-sel {
  flex: 0 0 auto; border: 1px solid #c9b895; background: #faf3e2; color: #5b4a24;
  border-radius: 999px; font-size: 11.5px; line-height: 1.6; padding: 1px 8px; cursor: pointer;
}
.add-sel:hover { background: var(--accent-soft); }
.add-sel.on { background: var(--accent); color: #fff8ef; border-color: var(--accent); }

.detail .buildrow { margin: -4px 0 0; }
.detail .add-sel { font-size: 12px; padding: 3px 11px; }
.verse-results li, .related li { display: flex; align-items: center; gap: 6px; }
.verse-results li > span, .related li .rel-name { flex: 1 1 auto; }

/* ---------- chat ---------- */
.chatcard {
  position: fixed; right: 18px; bottom: 14px; z-index: 900;
  width: 370px; max-width: calc(100vw - 32px); height: 480px; max-height: calc(100vh - 120px);
  display: flex; flex-direction: column; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.chathead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; background: var(--forest); color: #f4eddd;
  font-family: var(--serif); font-weight: 600; font-size: 14.5px; border-radius: 15px 15px 0 0;
}
.chathead button { border: none; background: none; color: #f4eddd; font-size: 17px; cursor: pointer; }
.chatscroll { flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.chatscroll .row { margin: 0 0 9px; padding: 7px 10px; border-radius: 10px; max-width: 92%; white-space: pre-wrap; }
.chatscroll .user { background: #e8e3d2; margin-left: auto; }
.chatscroll .guide { background: #fdf6e4; }
.chatscroll .who { font-size: 10.5px; color: var(--muted); display: block; margin-bottom: 1px; }
.chatscroll .sys { text-align: center; color: var(--muted); font-size: 11.5px; margin: 8px 0; font-style: italic; }
.chatform { display: flex; border-top: 1px solid var(--line); }
.chatform input { flex: 1 1 auto; border: none; background: #f6efdf; border-radius: 8px; margin: 6px; padding: 8px 10px; font-size: 13px; color: var(--ink); }
.chatform input:focus { outline: none; }
.chatform button {
  border: none; background: var(--accent); color: #fff8ef; border-radius: 8px;
  margin: 6px 4px 6px 0; padding: 0 14px; font-weight: 600; cursor: pointer;
}
.chatform button:disabled { opacity: .55; cursor: default; }
.chatcontext {
  font-size: 11px; color: var(--muted); text-align: center; margin: 0; padding: 3px 0;
  background: var(--accent-soft); border-radius: 8px; display: none;
}

/* ---------- about ---------- */
.about {
  position: fixed; inset: 0; z-index: 950; background: rgba(40, 34, 22, .55);
  display: flex; align-items: center; justify-content: center;
}
.about .card2 { position: relative;
  width: 560px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px 26px;
  box-shadow: var(--shadow);
}
.about h2 { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 0 0 10px; }
.about h3 { font-family: var(--serif); font-weight: 600; font-size: 15px; margin: 14px 0 4px; }
.about p { font-size: 13.5px; line-height: 1.55; margin: 0 0 10px; }
.about ul { font-size: 13px; margin: 0 0 12px; padding-left: 20px; }
.about li { margin-bottom: 3px; }
.about-close { position: absolute; right: 14px; top: 12px; border: none; background: none; font-size: 20px; color: var(--muted); cursor: pointer; }

/* ---------- attribution ---------- */
.attribution {
  position: absolute; right: 12px; bottom: 12px; z-index: 599;
  font-size: 10px; color: #6b6150; background: rgba(255, 253, 245, .92);
  padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line);
}

/* ---------- clusters ---------- */
.marker-cluster {
  background-clip: padding-box;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(60, 50, 30, .35);
}
.marker-cluster-small { background-color: #c96a4a; }
.marker-cluster-medium { background-color: #a8653a; }
.marker-cluster-large { background-color: #855230; }
.marker-cluster div {
  width: 30px; height: 30px; margin-left: 5px; margin-top: 5px;
  text-align: center; border-radius: 50%;
  background-color: #fffdf5;
}
.marker-cluster span {
  line-height: 30px; font-weight: 600; font-size: 12px; color: #5b4a24;
}

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .sidepanel {
    position: fixed; top: 0; bottom: 0; left: 0; width: 84%;
    max-width: 320px; z-index: 640; transform: translateX(-102%); transition: transform .18s;
    box-shadow: var(--shadow); background: var(--cream);
  }
  .sidepanel.open { transform: translateX(0); }
  .layout { flex-direction: column; }
  .mapwrap { flex: 1 1 auto; min-height: 60vh; }
  #toggle-panel.active { background: var(--accent); color: #fff8ef; border-color: var(--accent); }
  .detail { right: 8px; left: 8px; width: auto; max-height: 60%; }
  .chatcard { right: 8px; bottom: 8px; width: calc(100vw - 16px); height: 400px; }
  #map { height: 100%; }
}