:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #20232a;
  --line: #2c3038;
  --text: #ece7dd;
  --muted: #9a958b;
  --gold: #e8b04b;
  --gold-dim: #a08a5c;
  --war: #c0503f;
  --violence: #9b5fa8;
  --accident: #4f8fc0;
  --nature: #3fa39a;
  --other: #8a8f98;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

#map { position: fixed; inset: 0; background: #0b0c0f; }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-attribution { background: rgba(14,15,18,.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-zoom { display: none; }

/* Top bar */
.topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 12px; align-items: center; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: linear-gradient(var(--bg) 60%, transparent); z-index: 1000; }
.brand { font: 600 24px var(--serif); letter-spacing: .5px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
@media (max-width: 480px) { .brand { font-size: 19px; letter-spacing: 0; gap: 6px; } }
.search { position: relative; flex: 1; max-width: 460px; }
.search input { width: 100%; padding: 10px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; outline: none; }
.search input:focus { border-color: var(--gold-dim); }
.results { position: absolute; top: 46px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; max-height: 60vh; overflow: auto; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.results li { padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.results li:hover, .results li.sel { background: var(--surface-2); }
.results .sub { font-size: 12px; color: var(--muted); }

/* Flame mark */
.flame { width: 12px; height: 18px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: radial-gradient(circle at 50% 70%, #fff3c4, var(--gold) 45%, #b5651d 90%); box-shadow: 0 0 12px rgba(232,176,75,.7); animation: flicker 3s infinite ease-in-out; }
.flame.big { width: 22px; height: 34px; margin: 0 auto 12px; }
@keyframes flicker { 0%,100% { transform: scale(1) rotate(-2deg); } 50% { transform: scale(1.06, .96) rotate(2deg); } }

/* Filter chips */
.chips { position: fixed; top: 62px; left: 0; right: 0; display: flex; gap: 8px; padding: 6px 16px; overflow-x: auto; z-index: 999; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 16px; border: 1px solid var(--line); background: rgba(23,25,30,.92); font-size: 13px; white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.off { opacity: .45; }
.chip.off i { background: transparent; border: 1px solid var(--c); }
.chip select { background: transparent; border: 0; color: var(--text); font: inherit; outline: none; }
.chip select option { background: var(--surface); }

.maptools { position: fixed; right: 16px; bottom: calc(84px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; z-index: 900; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 18px; box-shadow: 0 4px 14px rgba(0,0,0,.4); }

/* Markers */
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); border: 2px solid rgba(14,15,18,.85); box-shadow: 0 0 8px var(--c); }
.dot.c { background: transparent; border: 2px solid var(--c); box-shadow: none; width: 16px; height: 16px; }
.dot.visited { outline: 2px solid #fff; outline-offset: 2px; }
.cluster { display: grid; place-items: center; border-radius: 50%; background: radial-gradient(rgba(232,176,75,.35), rgba(232,176,75,.08) 70%); border: 1px solid rgba(232,176,75,.55); color: var(--text); font: 600 12px var(--sans); }
.me { width: 16px; height: 16px; border-radius: 50%; background: #5ab0ff; border: 3px solid #fff; box-shadow: 0 0 0 8px rgba(90,176,255,.25); }
.me.virtual { background: #c7c2b6; box-shadow: 0 0 0 8px rgba(199,194,182,.2); }

/* Bottom sheet / side panel */
.sheet, .panel { position: fixed; z-index: 1100; background: var(--surface); border-top: 1px solid var(--line); left: 0; right: 0; bottom: 0; max-height: 72vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(84px + var(--safe-b)); box-shadow: 0 -12px 40px rgba(0,0,0,.55); }
.panel { z-index: 1050; max-height: 64vh; }
@media (min-width: 820px) {
  .sheet, .panel { left: auto; top: 76px; bottom: 16px; right: 16px; width: 400px; max-height: none; border-radius: 18px; border: 1px solid var(--line); padding-bottom: 18px; }
  .panel { left: 16px; right: auto; bottom: 88px; }
  .tabbar { left: 16px !important; right: auto !important; width: 400px; bottom: 16px !important; border-radius: 30px; border: 1px solid var(--line); }
  .maptools { bottom: 24px; }
}
.sheet-close { position: sticky; top: 0; float: right; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); font-size: 20px; line-height: 1; }

.m-portrait { width: 96px; height: 120px; object-fit: cover; border-radius: 10px; float: left; margin: 0 14px 8px 0; background: var(--surface-2); }
.m-kicker { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--c, var(--gold)); }
.m-name { font: 600 30px/1.1 var(--serif); margin: 4px 0 4px; }
.m-dates { font: italic 500 18px var(--serif); color: var(--muted); }
.m-desc { margin: 6px 0 0; }
.m-place { clear: both; margin: 14px 0 0; padding: 12px; border-radius: 12px; background: var(--surface-2); display: flex; gap: 10px; align-items: flex-start; }
.m-place b { display: block; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; letter-spacing: .03em; }
.badge.exact { background: rgba(232,176,75,.16); color: var(--gold); }
.badge.approx { background: rgba(154,149,139,.16); color: var(--muted); }
.m-extract { margin: 14px 0; color: #d6d1c6; }
.m-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.m-actions .primary { grid-column: 1 / -1; }
.primary { padding: 12px 18px; border-radius: 24px; border: 0; background: var(--gold); color: #1a1407; font-weight: 600; }
.primary[disabled] { opacity: .5; cursor: default; }
.ghost { padding: 10px 14px; border-radius: 22px; border: 1px solid var(--line); background: transparent; text-align: center; text-decoration: none; color: var(--text); font-size: 14px; }
.m-section { margin-top: 20px; }
.m-section h3 { font: 600 20px var(--serif); margin: 0 0 8px; }
.photos { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.photo { flex: none; width: 150px; margin: 0; }
.photo img { width: 150px; height: 112px; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: block; }
.photo figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 8px; }
.seg button { background: transparent; border: 0; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.candles { color: var(--gold); font-size: 13px; margin-top: 6px; }
.note { font-size: 12px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; margin: 12px 0; }

/* Lists */
.panel h2 { font: 600 28px var(--serif); margin: 0; }
.panel-head .row { display: flex; gap: 8px; margin: 10px 0 4px; flex-wrap: wrap; }
.list { list-style: none; padding: 0; margin: 10px 0 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--surface-2); }
.list .meta { flex: 1; min-width: 0; }
.list .meta b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta span { font-size: 12px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist { text-align: right; font-size: 13px; min-width: 64px; }
.dist .arrow { display: inline-block; color: var(--gold); font-size: 16px; }
.dist.close { color: var(--gold); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font: 600 26px var(--serif); font-variant-numeric: lining-nums; color: var(--gold); }
.stat span { font-size: 12px; color: var(--muted); }
.marks { display: flex; flex-wrap: wrap; gap: 8px; }
.mark { padding: 6px 10px; border-radius: 14px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.mark.earned { border-color: var(--gold-dim); color: var(--gold); }

/* Tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: rgba(14,15,18,.96); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + var(--safe-b)); z-index: 1200; }
.tabbar button { flex: 1; background: transparent; border: 0; padding: 6px 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabbar button span { font-size: 18px; }
.tabbar button.active { color: var(--gold); }

/* Intro + loading */
.intro, .loading { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: rgba(8,9,11,.88); backdrop-filter: blur(6px); padding: 16px; }
.intro-card { max-width: 420px; text-align: center; }
.intro-card h1 { font: 600 48px var(--serif); margin: 0; }
.intro-card .lede { font: italic 500 21px var(--serif); color: var(--gold); margin: 4px 0 16px; }
.loading p { color: var(--muted); }
[hidden] { display: none !important; }

.toast { position: fixed; left: 50%; top: 110px; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--gold-dim); padding: 10px 16px; border-radius: 20px; z-index: 3000; font-size: 14px; }

/* Trails */
.trail h3 { font: 600 22px var(--serif); margin: 14px 0 4px; }
.trail .row { display: flex; gap: 8px; margin: 4px 0; }
.trail-chip { border-color: var(--gold-dim); color: var(--gold); }
.trail-chip span { margin-left: 4px; color: var(--muted); }
.legal-links { margin-top: 14px; }
.legal-links a { color: var(--muted); }
