:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --panel-2: #f3eee6;
  --ink: #221d18;
  --ink-2: #5d544b;
  --ink-3: #8b8178;
  --line: #e4ddd2;
  --accent: #b5523b;
  --accent-ink: #ffffff;
  --chip: #f1ebe2;
  --chip-on: #2d2620;
  --chip-on-ink: #fffaf2;
  --shadow: 0 10px 30px rgba(40, 28, 16, .16), 0 2px 6px rgba(40, 28, 16, .08);
  --radius: 14px;
  --panel-w: 384px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Noto Serif", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171411; --panel: #1f1b17; --panel-2: #29241f; --ink: #f2ece4; --ink-2: #c3b9ae;
    --ink-3: #8f857b; --line: #3a332c; --accent: #e07a5f; --chip: #2c2621; --chip-on: #f2ece4;
    --chip-on-ink: #1b1714; --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171411; --panel: #1f1b17; --panel-2: #29241f; --ink: #f2ece4; --ink-2: #c3b9ae;
  --ink-3: #8f857b; --line: #3a332c; --accent: #e07a5f; --chip: #2c2621; --chip-on: #f2ece4;
  --chip-on-ink: #1b1714; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; }

/* ---------- side panel ---------- */
#panel {
  position: absolute; z-index: 5; top: 12px; left: 12px; bottom: 12px; width: var(--panel-w);
  display: flex; flex-direction: column; background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line);
}
.panel-handle { display: none; }
.panel-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.title-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
h1 { font: 700 19px/1.2 var(--serif); margin: 0; letter-spacing: -.01em; }
.subtitle { margin: 4px 0 0; color: var(--ink-2); font-size: 12.5px; }
h2 { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; flex: none; background: var(--panel-2); }
.lang button { border: 0; background: transparent; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.lang button[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); }

.search { position: relative; margin-top: 14px; }
.search svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--ink); font: inherit; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); background: var(--panel); }
#results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 340px; overflow: auto; }
#results li { display: flex; gap: 9px; align-items: flex-start; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
#results li[aria-selected="true"], #results li:hover { background: var(--panel-2); }
#results .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(0,0,0,.15); }
#results .r-name { font-weight: 600; }
#results .r-sub { color: var(--ink-3); font-size: 12px; }
#results .r-empty { color: var(--ink-3); cursor: default; }

.countbar { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.countbar b { font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 12px; }
.link:hover { text-decoration: underline; }
.mini-actions { display: inline-flex; gap: 10px; }

.panel-body { overflow-y: auto; padding: 6px 18px 18px; flex: 1; overscroll-behavior: contain; }
section { padding: 14px 0; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* timeline legend */
.timeline { list-style: none; margin: 0; padding: 0 0 0 10px; position: relative; }
.timeline::before { content: ""; position: absolute; left: 15px; top: 10px; bottom: 10px; width: 2px; background: linear-gradient(var(--line), var(--line)); }
.tl-item { position: relative; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; padding: 4px 4px 4px 0; border-radius: 8px; cursor: pointer; user-select: none; }
.tl-item:hover { background: var(--panel-2); }
.tl-item input { position: absolute; opacity: 0; pointer-events: none; }
.tl-sw { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--c); margin-left: 0; z-index: 1; transition: transform .15s; }
.tl-item.off .tl-sw { background: var(--panel); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--ink-3); transform: scale(.8); }
.tl-item.off .tl-text { opacity: .45; }
.tl-item.multi { margin-top: 6px; }
.tl-text { min-width: 0; }
.tl-name { font-weight: 600; font-size: 13px; display: block; }
.tl-range { font-size: 11px; color: var(--ink-3); display: block; }
.tl-bar { height: 3px; border-radius: 2px; background: var(--c); margin-top: 3px; opacity: .7; transition: width .25s ease; }
.tl-count { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-2); text-align: right; min-width: 38px; }
.tl-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--chip); padding: 4px 9px; border-radius: 999px; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; transition: background .12s, color .12s; }
.chip .n { font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: 11px; }
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }
.chip .acc-ico { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.chip .acc-ico.approximate { border-style: dashed; }
.chip .acc-ico.unverified { border-style: dotted; opacity: .7; }
.chip .imp-ico { border-radius: 50%; background: currentColor; flex: none; }

.switch-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; cursor: pointer; color: var(--ink-2); }
.switch-row input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.timeline + .switch-row { margin-top: 8px; font-size: 12px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 10px; margin-bottom: 8px; }
.seg button { border: 0; background: transparent; padding: 6px 4px; border-radius: 8px; font-size: 12px; font-weight: 500; color: var(--ink-2); }
.seg button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }

.about summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.about-body { font-size: 12.5px; color: var(--ink-2); }
.about-body p { margin: 8px 0; }
.about-body ul { margin: 6px 0; padding-left: 18px; }
.about-body a { color: var(--accent); }

/* ---------- map widgets ---------- */
.maplibregl-ctrl-group { border-radius: 10px !important; box-shadow: 0 2px 8px rgba(0,0,0,.18) !important; }
.maplibregl-ctrl-group button.ctl-txt { width: auto; padding: 0 9px; font-weight: 700; font-size: 12px; }
.maplibregl-ctrl-group button.ctl-txt.on { background: var(--accent); color: var(--accent-ink); }
.maplibregl-ctrl-group button svg { width: 18px; height: 18px; display: block; margin: auto; fill: none; stroke: #333; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.maplibregl-ctrl-attrib { font-size: 10.5px; }

.cl-marker { cursor: pointer; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); transition: transform .12s; }
.cl-marker:hover { transform: scale(1.08); }
.cl-marker text { font: 700 11px var(--font); fill: #2a221c; }

/* popup */
.maplibregl-popup-content { padding: 0; border-radius: 12px; box-shadow: var(--shadow); background: var(--panel); color: var(--ink); overflow: hidden; }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-close-button { font-size: 20px; width: 30px; height: 30px; color: var(--ink-2); right: 2px; top: 2px; border-radius: 8px; }
.pp { width: min(330px, 80vw); font-size: 13px; }
.pp-top { padding: 12px 34px 10px 14px; border-top: 5px solid var(--c); background: linear-gradient(color-mix(in srgb, var(--c) 10%, var(--panel)), var(--panel)); }
.pp-kicker { font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; font-weight: 700; color: var(--ink-2); }
.pp h3 { font: 700 17px/1.25 var(--serif); margin: 3px 0 0; }
.pp-alt { color: var(--ink-2); font-size: 13px; }
.pp-body { padding: 4px 14px 12px; max-height: 42vh; overflow: auto; }
.pp dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 6px 0 8px; }
.pp dt { color: var(--ink-3); font-size: 12px; }
.pp dd { margin: 0; }
.pp-desc { margin: 6px 0; line-height: 1.5; }
.pp-note { color: var(--ink-3); font-size: 11.5px; font-style: italic; }
.pp-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.pp-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); }
.pp-tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); display: inline-block; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.badge.verified { background: #dcefe1; color: #1d5b2f; }
.badge.approximate { background: #fbedd0; color: #7a5208; }
.badge.unverified { background: #f6dcdc; color: #8a2424; }
.badge.heritage { background: #e3e4f7; color: #2f3480; }
.pp-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pp-links a, .pp-links button { font-size: 12px; font-weight: 600; text-decoration: none; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.pp-links a:hover, .pp-links button:hover { background: var(--panel-2); }
.pp-coords { font: 12px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--ink-2); margin-top: 8px; }
.pp details { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.pp summary { cursor: pointer; font-weight: 600; }
.pp-list ul { list-style: none; margin: 0; padding: 4px 6px 8px; max-height: 42vh; overflow: auto; }
.pp-list button { display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left; padding: 6px 8px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; cursor: pointer; }
.pp-list button:hover, .pp-list button:focus-visible { background: var(--panel-2); }
.pp-list button i { flex: none; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--c); }
.pp-list b { display: block; font-weight: 600; }
.pp-list small { color: var(--ink-3); font-size: 11.5px; }
.hover-pop .maplibregl-popup-content { padding: 5px 9px; font-size: 12.5px; font-weight: 600; border-radius: 8px; pointer-events: none; }
.hover-pop .maplibregl-popup-tip { display: none; }
.hover-pop small { display: block; font-weight: 500; color: var(--ink-3); }

.load-err { position: absolute; z-index: 30; left: 50%; top: 20px; transform: translateX(-50%); background: #8a2424; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; }

/* ---------- mobile: bottom sheet ---------- */
@media (max-width: 760px) {
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(78vh, 680px);
    border-radius: 18px 18px 0 0; border-bottom: 0;
    transform: translateY(calc(100% - 58px - env(safe-area-inset-bottom)));
    transition: transform .28s cubic-bezier(.2,.8,.2,1);
  }
  #panel.open { transform: none; }
  .panel-handle {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px;
    padding: 18px 18px 10px; min-height: 58px; cursor: pointer; position: relative; border-bottom: 1px solid var(--line);
  }
  .grip { position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line); }
  .handle-count { font-size: 14px; }
  .handle-count b { font-size: 17px; }
  .handle-hint { font-size: 12px; color: var(--accent); font-weight: 600; }
  .panel-head { padding: 12px 16px 10px; }
  h1 { font-size: 17px; }
  .panel-body { padding: 4px 16px calc(16px + env(safe-area-inset-bottom)); }
  .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 58px; }
  .pp-body { max-height: 34vh; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
