:root {
  --bg: #ffffff;
  --bg2: #f5f6f8;
  --fg: #1d2129;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #4f46e5;
  --shadow: 0 4px 18px rgba(0, 0, 0, .12);
  --panel-w: 300px;
  --top-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d22; --bg2: #25282e; --fg: #e8eaed; --muted: #9aa0a6; --line: #34373d; --accent: #8b87ff;
    --shadow: 0 4px 18px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d22; --bg2: #25282e; --fg: #e8eaed; --muted: #9aa0a6; --line: #34373d; --accent: #8b87ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  word-break: keep-all; overflow-wrap: anywhere; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 1001;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; margin: 0; white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 420px; min-width: 0; }
.search input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--fg); font: inherit;
}
#results {
  position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto;
}
#results li { padding: 8px 12px; cursor: pointer; }
#results li:hover, #results li.on { background: var(--bg2); }
#results small { color: var(--muted); display: block; }
.btn { height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); display: none; }
.panel {
  position: fixed; top: var(--top-h); left: 0; bottom: 0; width: var(--panel-w); z-index: 1000;
  background: var(--bg); border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 16px 24px;
}
#map { position: fixed; top: var(--top-h); left: var(--panel-w); right: 0; bottom: 0; background: var(--bg2); }
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip .n { opacity: .6; font-size: 11px; }
.types label { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.types input { margin: 0; accent-color: var(--accent); }
.types .sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.types .nm { flex: 1; }
.types .n { color: var(--muted); font-size: 12px; }
.types .desc { display: block; color: var(--muted); font-size: 11px; line-height: 1.3; }
.legend .lg { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 2px 0; }
.legend .sw { width: 22px; height: 14px; display: inline-block; flex: none; }
.sw.solid { border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 25%, transparent); }
.sw.dashed { border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.sw.circle { border: 2px dotted var(--accent); border-radius: 50%; width: 16px; height: 16px; margin: 0 3px; }
.sw.district { border: 2px dashed #8a6d3b; }
.meta p { margin: 4px 0; font-size: 12px; }
.muted { color: var(--muted); }

.basetiles { filter: saturate(.35) brightness(1.04) contrast(.92); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .basetiles { filter: invert(1) hue-rotate(180deg) saturate(.3) brightness(.85) contrast(.9); }
}
/* popup */
.leaflet-popup-content-wrapper { border-radius: 12px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--bg); }
.leaflet-popup-content { margin: 14px 16px; width: 300px !important; max-width: calc(100vw - 72px); font-size: 13px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pp h3 { margin: 0 0 6px; font-size: 15px; line-height: 1.35; padding-right: 14px; }
.pp .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.pp .tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; color: #fff; }
.pp .st { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; font-weight: 600; }
.pp .steps { display: flex; gap: 2px; margin: 10px 0 4px; }
.pp .steps i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.pp .steps i.done { background: var(--accent); }
.pp .steps i.cur { background: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.pp .steplabel { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.pp .now { margin: 6px 0 8px; font-weight: 600; }
.pp dl { display: grid; grid-template-columns: 64px 1fr; gap: 3px 8px; margin: 8px 0; }
.pp dt { color: var(--muted); }
.pp dd { margin: 0; }
.pp .box { background: var(--bg2); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.pp .box b { display: block; margin-bottom: 2px; }
.pp .warn { color: #b45309; font-size: 12px; margin: 6px 0; }
.pp .srcs a { color: var(--accent); font-size: 12px; margin-right: 8px; }
.pp .cl { max-height: 120px; overflow-y: auto; }
.pp .cl div { font-size: 12px; padding: 2px 0; }
.leaflet-tooltip.lbl {
  background: rgba(255,255,255,.85); border: 0; box-shadow: none; padding: 0 4px; font-size: 11px; color: #222;
  font-weight: 600; border-radius: 4px;
}
.leaflet-tooltip.lbl::before { display: none; }

@media (max-width: 760px) {
  :root { --top-h: 52px; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar h1 { font-size: 14px; }
  .btn { display: inline-block; }
  #map { left: 0; }
  .panel {
    top: auto; width: auto; right: 0; max-height: 72vh; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow); transform: translateY(105%); transition: transform .25s;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .panel.open { transform: none; }
}
@media (max-width: 420px) {
  .topbar h1 { display: none; }
}
