:root {
  --bg: #12161c;
  --panel: rgba(20, 25, 32, 0.94);
  --panel-solid: #161b22;
  --line: rgba(233, 216, 166, 0.14);
  --line-strong: rgba(233, 216, 166, 0.3);
  --text: #e8e6e1;
  --muted: #9aa3ad;
  --gold: #e9c46a;
  --gold-soft: rgba(233, 196, 106, 0.14);
  --danger: #f87171;
  --radius: 10px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --serif: "Cinzel", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); overflow: hidden; }
button { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; background: #263e54; }
.leaflet-container { background: #263e54; font: inherit; }
.leaflet-control-zoom a { background: var(--panel-solid) !important; color: var(--text) !important; border-color: var(--line) !important; }

.entity-canvas { position: absolute; left: 0; top: 0; pointer-events: none; }

/* ---------- panels ---------- */
.panel {
  position: fixed; z-index: 1000; background: var(--panel); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
#sidebar {
  top: 12px; left: 12px; bottom: 12px; width: 340px; display: flex; flex-direction: column;
}
/* Collapsed: shrink to just the brand row, so nothing peeks out from the edge. */
#sidebar.collapsed { bottom: auto; width: auto; }
#sidebar.collapsed > :not(.brand) { display: none; }
#sidebar.collapsed .brand { padding: 10px 10px 10px 12px; }
#sidebar.collapsed #collapse { transform: rotate(180deg); }

.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.brand img { width: 34px; height: 34px; object-fit: contain; }
.brand h1 { font: 700 22px/1 var(--serif); letter-spacing: 0.06em; margin: 0; color: var(--gold); }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.brand > div { flex: 1; min-width: 0; }

.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 8px; width: 30px; height: 30px;
  cursor: pointer; font-size: 18px; line-height: 1; display: grid; place-items: center; flex: none;
  transition: transform 0.25s ease, background 0.15s;
}
.icon-btn:hover { background: var(--gold-soft); }

.search { position: relative; padding: 0 14px 10px; }
.search input {
  width: 100%; padding: 10px 36px 10px 12px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.3); color: var(--text); font: inherit; outline: none;
}
.search input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.search kbd {
  position: absolute; right: 24px; top: 9px; font: 11px var(--sans); color: var(--muted);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 6px;
}

.tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none; border: 0; padding: 8px 10px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--gold); border-bottom-color: var(--gold); }
#result-count { font-size: 11px; color: var(--muted); }

.tab { display: none; flex: 1; overflow-y: auto; padding: 10px 14px 14px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.tab.active { display: block; }

.map-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.map-switch button {
  flex: 1; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.2); cursor: pointer;
}
.map-switch button.active { border-color: var(--gold); background: var(--gold-soft); color: var(--gold); }

.quick { display: flex; gap: 6px; margin-bottom: 8px; }
.quick button {
  flex: 1; font-size: 12px; padding: 5px; border-radius: 6px; border: 1px solid var(--line); background: none; cursor: pointer; color: var(--muted);
}
.quick button:hover { color: var(--text); border-color: var(--line-strong); }

.group h3 {
  font: 600 11px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  margin: 12px 0 4px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.group h3 span { font-weight: 500; letter-spacing: 0; text-transform: none; }
.layer {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; user-select: none;
}
.layer:hover { background: rgba(255, 255, 255, 0.04); }
.layer input { display: none; }
.layer .sw {
  width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); opacity: 0.35; transition: opacity 0.15s;
}
.layer .sw img { width: 18px; height: 18px; object-fit: contain; }
.layer .sw i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.6); }
.layer .name { flex: 1; color: var(--muted); }
.layer .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.layer.on .sw { opacity: 1; border-color: var(--line-strong); }
.layer.on .name { color: var(--text); }

.options { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.options label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.options input { accent-color: var(--gold); }

.foot { padding: 8px 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }

/* ---------- results ---------- */
.hint { color: var(--muted); font-size: 13px; }
.result {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.result:hover, .result.active { background: rgba(255, 255, 255, 0.05); border-color: var(--line); }
.result .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 2px solid rgba(0, 0, 0, 0.5); }
.result .body { flex: 1; min-width: 0; }
.result .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .n { font-size: 12px; color: var(--gold); font-variant-numeric: tabular-nums; flex: none; }
.result-instances { margin: 0 0 6px 26px; display: grid; gap: 2px; }
.result-instances button {
  text-align: left; background: none; border: 0; padding: 3px 6px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12px;
}
.result-instances button:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

/* ---------- details ---------- */
#details {
  top: 12px; right: 12px; width: 360px; max-height: calc(100% - 24px); overflow-y: auto; padding: 16px;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
#details.hidden, .hidden { display: none; }
#details .close { position: absolute; top: 12px; right: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip.warn { color: #fbbf24; border-color: rgba(251, 191, 36, 0.4); }
.chip.boss { color: var(--danger); border-color: rgba(248, 113, 113, 0.5); }
#details h2 { font: 700 20px/1.2 var(--serif); margin: 10px 30px 2px 0; color: var(--gold); }
#details .where { color: var(--muted); margin-bottom: 10px; }
#details .desc { margin: 8px 0; color: #cfcac0; }
#details blockquote { margin: 6px 0; padding: 6px 10px; border-left: 2px solid var(--gold); background: rgba(0, 0, 0, 0.2); color: #d7d2c7; font-style: italic; border-radius: 0 6px 6px 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.stat { background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sec { margin-top: 14px; }
.sec h4 { font: 600 11px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list td.r { text-align: right; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list tr.sub td { color: var(--muted); font-size: 12px; border-bottom: 0; padding-top: 8px; }
.linkish { background: none; border: 0; padding: 0; color: var(--gold); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font: inherit; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.actions button {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: rgba(0, 0, 0, 0.25); cursor: pointer; font-size: 12px;
}
.actions button:hover { border-color: var(--gold); color: var(--gold); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); }

/* ---------- floating bits ---------- */
.tooltip {
  position: fixed; z-index: 1100; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 6px 10px; box-shadow: var(--shadow); max-width: 280px; font-size: 13px;
}
.tooltip b { color: var(--gold); font-weight: 600; }
.tooltip small { display: block; color: var(--muted); }
.coords {
  position: fixed; z-index: 900; left: 50%; transform: translateX(-50%); bottom: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); font: 12px ui-monospace, Consolas, monospace; pointer-events: none;
}
.toast {
  position: fixed; z-index: 1200; left: 50%; bottom: 48px; transform: translateX(-50%); background: var(--panel-solid);
  border: 1px solid var(--gold); color: var(--gold); padding: 6px 14px; border-radius: 999px; font-size: 13px;
}

/* ---------- waypoints ---------- */
.wp-panel { margin: 0 0 6px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.wp-panel-head { display: flex; align-items: center; justify-content: space-between; }
.wp-panel-head h3 { font: 600 11px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 4px 0; }
.wp-panel-head h3 span { letter-spacing: 0; color: var(--gold); }
.wp-panel-head label { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.wp-panel-head input { accent-color: var(--gold); }
#wp-list .hint { margin: 2px 0 0; font-size: 12px; }
.wp-item { display: flex; align-items: center; gap: 4px; }
.wp-item .go {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.wp-item .go:hover { background: rgba(255, 255, 255, 0.05); }
.wp-item img { width: 20px; height: 20px; object-fit: contain; flex: none; }
.wp-item .go span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-item .go small { color: var(--muted); margin-left: auto; flex: none; font-size: 11px; }
.wp-item .del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; width: 24px; height: 24px; border-radius: 6px; }
.wp-item .del:hover { color: var(--danger); background: rgba(248, 113, 113, 0.1); }

.wp-editor {
  position: fixed; z-index: 1150; width: min(280px, calc(100vw - 16px)); padding: 12px;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
}
.wp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
#wp-title { font: 700 15px var(--serif); color: var(--gold); }
#wp-name {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.3); color: var(--text); font: inherit; outline: none;
}
#wp-name:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.wp-icons { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 10px 0; }
.wp-icons button {
  aspect-ratio: 1; padding: 3px; border-radius: 6px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); cursor: pointer;
}
.wp-icons button img { width: 100%; height: 100%; object-fit: contain; display: block; }
.wp-icons button:hover { border-color: var(--line-strong); }
.wp-icons button[aria-checked="true"] { border-color: var(--gold); background: var(--gold-soft); }
.wp-actions { display: flex; gap: 6px; align-items: center; }
.wp-actions span { flex: 1; }
.wp-actions button {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: rgba(0, 0, 0, 0.25); cursor: pointer; font-size: 13px;
}
.wp-actions .primary { background: var(--gold); border-color: var(--gold); color: #1a1508; font-weight: 600; }
.wp-actions .danger { color: var(--danger); border-color: transparent; background: none; padding-left: 4px; }
.wp-actions .danger:hover { text-decoration: underline; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  #sidebar { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 46vh; }
  #sidebar.collapsed { top: auto; bottom: 8px; height: auto; width: auto; }
  #sidebar.collapsed #collapse { transform: rotate(90deg); }
  #collapse { transform: rotate(-90deg); }
  #details { left: 8px; right: 8px; top: 8px; width: auto; max-height: 50vh; }
  .coords { display: none; }
  .search kbd { display: none; }
}
