:root {
  --paper: #f6f4ee; --paper2: #eeeae0; --ink: #23301f; --ink2: #5a6653; --line: #d9d3c4;
  --green: #3f6b3a; --green2: #6d9a55; --terracotta: #b5533c; --water: #2f6f8f; --soil: #7a5230; --sun: #d9a21b;
  --good: #3f7d3a; --caution: #c2811a; --warn: #b5423c; --info: #4b6b8a;
  --side-w: 400px; --tabs-w: 64px; --top-h: 48px;
  font-size: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif; color: var(--ink); background: var(--paper); line-height: 1.45; }
button { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--green2); }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover { background: #335a2f; }
button.primary:disabled { background: #9db096; border-color: #9db096; cursor: not-allowed; }
button.danger { color: var(--warn); }
button.mini { padding: 2px 8px; font-size: 12px; }
button.big { padding: 9px 16px; font-size: 15px; }
input, select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cfe0c6; border-color: var(--green2); }
textarea { width: 100%; resize: vertical; }
a { color: var(--water); cursor: pointer; }
a[data-learn], a[data-tab] { text-decoration: underline dotted; }
h2 { font-size: 20px; margin: 4px 0 8px; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 650; }
p { margin: 6px 0; }
.lead { font-size: 15px; color: var(--ink); }
.hint { color: var(--ink2); font-size: 13px; }
.muted { color: var(--ink2); }
.small { font-size: 12px; }
.auto { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--green); border: 1px solid var(--green2); border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: middle; }
.badge { display: inline-block; background: var(--paper2); border: 1px solid var(--line); border-radius: 12px; padding: 1px 9px; font-size: 12px; }

#top { height: var(--top-h); display: flex; align-items: center; gap: 16px; padding: 0 14px; background: #fff; border-bottom: 1px solid var(--line); }
#top .brand { display: flex; align-items: baseline; gap: 8px; }
#top .logo { color: var(--green); font-size: 20px; line-height: 1; }
#top .brand b { font-size: 17px; letter-spacing: -0.01em; }
#top .tag { color: var(--ink2); font-size: 12px; }
#top .proj { display: flex; gap: 6px; align-items: center; margin-left: auto; }
#top .proj input { width: 180px; }
#top .right { display: flex; align-items: center; gap: 10px; }
.switch { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink2); cursor: pointer; }

#main { display: flex; height: calc(100% - var(--top-h)); }
#tabs { width: var(--tabs-w); display: flex; flex-direction: column; background: var(--paper2); border-right: 1px solid var(--line); }
#tabs button { border: 0; border-radius: 0; background: transparent; padding: 10px 0 8px; font-size: 11px; color: var(--ink2); display: flex; flex-direction: column; align-items: center; gap: 2px; border-left: 3px solid transparent; }
#tabs button .ico { font-size: 18px; line-height: 1; }
#tabs button.active { background: var(--paper); color: var(--green); border-left-color: var(--green); font-weight: 600; }
#side { width: var(--side-w); overflow-y: auto; padding: 14px 16px 40px; border-right: 1px solid var(--line); background: var(--paper); }
#side.wide { width: 560px; }
#map { flex: 1; min-width: 0; background: #dfe6dc; position: relative; }
.tab { display: none; }
.tab.active { display: block; }

.step { display: flex; gap: 10px; margin: 14px 0; }
.step .num { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; margin-top: 2px; }
.step .body { flex: 1; min-width: 0; }
.step h3 { margin-bottom: 4px; }
.row { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.row input { flex: 1; }
.results { display: flex; flex-direction: column; gap: 2px; }
.results button { text-align: left; font-size: 12px; padding: 4px 8px; background: #fff; }
.summary { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-top: 6px; }
.linklike { color: var(--water); text-decoration: underline dotted; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chips label { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 2px 10px; font-size: 12.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.chips label:has(input:checked) { background: #e6efe0; border-color: var(--green2); color: var(--green); }
.chips input { margin: 0; }
.chips.small label { font-size: 11.5px; padding: 1px 8px; }
.progress { font-size: 13px; color: var(--ink2); min-height: 1.2em; margin: 6px 0; white-space: pre-line; }
.findings { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.finding { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--green2); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.finding b { color: var(--green); }
ol.path { padding-left: 20px; margin: 4px 0; }
ol.path li { margin: 4px 0; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.layers { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--ink2); margin: 4px 0 8px; }
.layers label { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.result { font-size: 13px; }
.result table { border-collapse: collapse; width: 100%; font-size: 12.5px; margin: 6px 0; }
.result th, .result td { text-align: left; padding: 2px 6px 2px 0; border-bottom: 1px solid #efece4; vertical-align: top; }
.result th { color: var(--ink2); font-weight: 600; }
.result td.num, .result th.num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; }
.kv b { color: var(--ink2); font-weight: 600; }
.bars { display: flex; height: 12px; border-radius: 4px; overflow: hidden; margin: 4px 0; }
.bars span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--ink2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 3px; vertical-align: -1px; }
.reading { display: flex; gap: 8px; margin: 5px 0; font-size: 12.5px; }
.reading .dot { flex: 0 0 9px; height: 9px; border-radius: 50%; margin-top: 5px; }
.reading .dot.good { background: var(--good); } .reading .dot.caution { background: var(--caution); } .reading .dot.warn { background: var(--warn); } .reading .dot.info { background: var(--info); }
.reading b { font-weight: 600; }
.unit { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.unit:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.unit .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; border: 1px solid rgba(0,0,0,.2); }
.notes { font-size: 12px; color: var(--ink2); margin-top: 6px; }
.notes li { margin: 3px 0; }
svg.rose, svg.sunpath { display: block; margin: 6px auto; max-width: 100%; }
canvas.mchart { display: block; width: 100%; height: 120px; margin: 6px 0; }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 8px 0; }
.palette button { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 6px 8px; text-align: left; }
.palette button i { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }
.palette button.active { outline: 2px solid var(--green); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin: 6px 0; }
.grid2 label, .card label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink2); }
.grid2 label.span2 { grid-column: 1 / -1; }
.unitin { display: flex; align-items: center; gap: 4px; }
.unitin input { flex: 1; width: 100%; }
.unitin em { font-style: normal; color: var(--ink2); font-size: 12px; min-width: 22px; }
.list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.item { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.item:hover { border-color: var(--green2); }
.item.selected { outline: 2px solid var(--green2); }
.item .sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.item .t { flex: 1; min-width: 0; }
.item .t small { display: block; color: var(--ink2); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .tags { display: flex; gap: 3px; flex-wrap: wrap; }
.item .tags span { font-size: 10.5px; background: var(--paper2); border-radius: 3px; padding: 0 5px; color: var(--ink2); }
table.web { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.web td, table.web th { padding: 2px 4px; border-bottom: 1px solid #efece4; text-align: left; }
table.web td.ok { color: var(--good); } table.web td.no { color: var(--warn); }

.filters { display: flex; flex-wrap: wrap; gap: 6px 8px; margin: 6px 0; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--ink2); }
.filters label.grow { flex: 1; min-width: 120px; }
.filters input, .filters select { padding: 3px 6px; font-size: 13px; }
.guild-role { border-top: 1px solid var(--line); padding: 6px 0; }
.guild-role b { display: block; font-size: 13px; }
.guild-role .why { color: var(--ink2); font-size: 12px; }
.guild-role .picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.guild-role .picks span { background: #e6efe0; border-radius: 12px; padding: 1px 9px; font-size: 12px; cursor: pointer; }
.guild-role .picks span:hover { background: #d3e3c8; }

#learnGroups h4 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); }
.lp { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.lp:hover { background: #fff; }
.lp b { font-weight: 600; }
.lp small { color: var(--ink2); }
.lp .own { margin-left: auto; font-size: 11px; color: var(--green); white-space: nowrap; }
.article { font-size: 14px; line-height: 1.55; max-width: 62ch; }
.article h1 { font-size: 22px; margin: 6px 0 10px; line-height: 1.2; }
.article h2 { font-size: 17px; margin: 18px 0 6px; }
.article h3 { font-size: 15px; margin: 14px 0 4px; }
.article p, .article li { margin: 6px 0; }
.article blockquote { border-left: 3px solid var(--green2); margin: 8px 0; padding: 2px 10px; color: var(--ink2); }
.article table { border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.article th, .article td { border: 1px solid var(--line); padding: 3px 7px; text-align: left; vertical-align: top; }
.article code { background: var(--paper2); padding: 0 4px; border-radius: 3px; font-size: 12.5px; }
.article .rule { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--sun); padding: 6px 10px; border-radius: 6px; margin: 8px 0; }
.hits { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.hit { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.hit-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hit-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { font-size: 12.5px; color: var(--ink2); margin-top: 3px; line-height: 1.4; }
.snip mark { background: #fff1b0; color: var(--ink); padding: 0 2px; border-radius: 2px; }
.pagetext { white-space: pre-wrap; font: 13px/1.5 Georgia, "Times New Roman", serif; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; max-height: 60vh; overflow: auto; margin: 0; }
.pagetext mark { background: #fff1b0; padding: 0 2px; border-radius: 2px; }
.hit a[data-page] { text-decoration: underline dotted; cursor: pointer; }
#searchBox .row select { max-width: 150px; }
#searchResults [data-facet] { text-decoration: underline dotted; }
.owned { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 8px; }
.owned h4 { margin: 4px 0; font-size: 13px; }
.owned .doc { display: flex; gap: 6px; align-items: center; font-size: 12px; padding: 2px 0; }
.owned .doc span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.owned .doc button { padding: 0 6px; font-size: 11px; }

.calc .out { background: var(--paper); border-radius: 6px; padding: 6px 10px; font-size: 13px; margin-top: 4px; }
.calc .out b { color: var(--green); }

#drawer { position: absolute; left: calc(var(--tabs-w) + var(--side-w)); right: 0; bottom: 0; height: 200px; background: #fff; border-top: 1px solid var(--line); z-index: 800; padding: 6px 12px; }
#side.wide ~ #drawer { left: calc(var(--tabs-w) + 560px); }
.drawer-head { display: flex; gap: 10px; align-items: center; margin-bottom: 2px; }
.drawer-head button { margin-left: auto; }
#profileCanvas { width: 100%; height: 160px; display: block; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 2000; max-width: 70vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
#modal { position: fixed; inset: 0; background: rgba(20,30,15,.45); z-index: 1500; display: flex; align-items: center; justify-content: center; }
.modal-body { background: #fff; border-radius: 12px; padding: 18px 22px; width: min(640px, 92vw); max-height: 85vh; overflow: auto; position: relative; }
.modal-body .close { position: absolute; top: 8px; right: 10px; border: 0; background: transparent; font-size: 20px; }
.modal-body h3 { font-size: 18px; margin-bottom: 2px; }
.modal-body .latin { color: var(--ink2); font-style: italic; }

.leaflet-container { font: inherit; }
.leaflet-tooltip.contour { background: rgba(255,255,255,.85); border: 0; box-shadow: none; font-size: 11px; padding: 1px 4px; }
.leaflet-popup-content { font-size: 13px; line-height: 1.4; }
.leaflet-popup-content h4 { margin: 0 0 4px; }
.maplegend { background: rgba(255,255,255,.92); padding: 6px 10px; border-radius: 6px; font-size: 11.5px; box-shadow: 0 1px 4px rgba(0,0,0,.2); line-height: 1.5; }
.maplegend i { display: inline-block; width: 12px; height: 10px; margin-right: 4px; vertical-align: -1px; border-radius: 2px; }
.divicon { background: transparent; border: 0; }
.divicon .pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.divicon .lbl { font-size: 11px; background: rgba(255,255,255,.85); padding: 0 4px; border-radius: 3px; white-space: nowrap; position: absolute; left: 18px; top: -2px; }

/* one page, two truths: the local app reads your own disk, the hosted one cannot.
   app.js puts .hosted on <body> from /api/config, and the copy follows. */
body.hosted .local-only { display: none; }
.hosted-only { display: none; }
body.hosted .hosted-only { display: inline; }
body.hosted p.hosted-only { display: block; }

#credits { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--ink2); font-size: 11px; line-height: 1.5; }
#credits p { margin: 0 0 7px; }
#credits a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
#credits a:hover { color: var(--green); }

@media (max-width: 900px) {
  #main { flex-direction: column; }
  #tabs { flex-direction: row; width: auto; height: 46px; }
  #tabs button { flex: 1; border-left: 0; border-bottom: 3px solid transparent; }
  #tabs button.active { border-bottom-color: var(--green); }
  #side, #side.wide { width: auto; height: 45%; }
  #drawer { left: 0; }
}
