:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #5d6670;
  --line: #e3e6ea;
  --chip: #ffffff;
  --chip-on: #1f2328;
  --chip-on-fg: #ffffff;
  --naver: #03c75a;
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  --walk: #16a34a; --run: #f97316; --bike: #2563eb;
  --exercise: #dc2626; --rest: #7c3aed; --park: #15803d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1f23; --fg: #e8eaed; --muted: #a2a9b1; --line: #343a40;
    --chip: #2a2f35; --chip-on: #e8eaed; --chip-on-fg: #1c1f23;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1f23; --fg: #e8eaed; --muted: #a2a9b1; --line: #343a40;
  --chip: #2a2f35; --chip-on: #e8eaed; --chip-on-fg: #1c1f23;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--fg); font-size: 16px;
}
#map { position: fixed; inset: 0; }

#chips {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; z-index: 1000;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-width: 44px; height: 44px; padding: 0 12px; border-radius: 22px; border: 0;
  background: var(--chip); color: var(--fg); box-shadow: var(--shadow); font-size: 20px; cursor: pointer;
}
.chip[data-cat="all"] { font-size: 15px; font-weight: 600; }
.chip.on { background: var(--chip-on); color: var(--chip-on-fg); }
.radius {
  flex: 0 0 auto; height: 44px; padding: 0 30px 0 14px; border-radius: 22px; border: 2px solid #0f766e;
  background: var(--chip) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%230f766e'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--fg); box-shadow: var(--shadow); font-size: 15px; font-weight: 700; appearance: none; cursor: pointer;
}

.fab {
  position: fixed; right: 12px; z-index: 1000; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--chip); color: var(--fg); box-shadow: var(--shadow); font-size: 22px; cursor: pointer;
}
#locate { bottom: calc(var(--sheet-h, 110px) + 70px); }
#measure-btn { bottom: calc(var(--sheet-h, 110px) + 182px); }
#help-btn { bottom: calc(var(--sheet-h, 110px) + 238px); font-weight: 800; font-size: 22px; }
#memo-btn { bottom: calc(var(--sheet-h, 110px) + 126px); }
.fab.active { background: #0f766e; color: #fff; }
#home { bottom: calc(var(--sheet-h, 110px) + 14px); }

#toast {
  position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 1100;
  background: var(--chip-on); color: var(--chip-on-fg); padding: 10px 14px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow);
}

#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--bg);
  border-radius: 16px 16px 0 0; box-shadow: 0 -2px 12px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; height: var(--sheet-h, 110px);
  transition: height .2s ease; padding-bottom: env(safe-area-inset-bottom);
}
#sheet.peek { --sheet-h: 110px; }
#sheet.half { --sheet-h: 45vh; }
#sheet.full { --sheet-h: 85vh; }
body:has(#sheet.half) { --sheet-h: 45vh; }
body:has(#sheet.full) { --sheet-h: 85vh; }
#grip { padding: 10px 0 6px; cursor: grab; touch-action: none; }
#grip span { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
#sheet-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 16px 6px; }
#list-count { color: var(--muted); font-size: 13px; }
#list, #detail { flex: 1; overflow-y: auto; margin: 0; padding: 0 16px; list-style: none; }
#list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.dot { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; }
.li-body { flex: 1; min-width: 0; }
.li-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-dist { color: var(--muted); font-size: 13px; margin-top: 2px; }
.naver {
  flex: 0 0 auto; background: var(--naver); color: #fff; border: 0; border-radius: 8px; padding: 8px 10px;
  font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
#detail h2 { font-size: 19px; margin: 4px 0 6px; }
#detail .back { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 6px 0; cursor: pointer; }
#detail dl { margin: 10px 0; display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; font-size: 14px; }
#detail dt { color: var(--muted); }
#detail dd { margin: 0; word-break: keep-all; overflow-wrap: anywhere; }
#detail .rel { list-style: none; padding: 0; margin: 4px 0 0; }
#detail .rel li { padding: 4px 0; border: 0; }
#detail .rel a { color: inherit; }
.badge { display: inline-block; background: #db2777; color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 700; vertical-align: 1px; }
#tool { flex: 1; overflow-y: auto; padding: 0 16px 12px; }
#tool h2 { font-size: 18px; margin: 4px 0 4px; }
#tool .hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
#tool table { width: 100%; border-collapse: collapse; font-size: 14px; }
#tool td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
#tool td.num { text-align: right; white-space: nowrap; }
#tool tr.total td { font-weight: 700; border-bottom: 0; }
#tool .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
#tool button.btn { border: 1px solid var(--line); background: var(--chip); color: var(--fg); border-radius: 10px; padding: 10px 14px; font-size: 14px; cursor: pointer; }
#tool button.primary { background: #0f766e; border-color: #0f766e; color: #fff; }
#tool input, #tool textarea { width: 100%; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); }
#tool textarea { min-height: 96px; resize: vertical; }
#tool .err { color: #dc2626; font-size: 14px; margin-top: 6px; }
#tool ul.memos { list-style: none; padding: 0; margin: 8px 0 0; }
#tool ul.memos li { padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
#tool ul.memos small { color: var(--muted); }
.mpin { width: 24px; height: 24px; border-radius: 50%; background: #0f766e; color: #fff; border: 2px solid #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.memo-pin { font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
#help {
  width: min(560px, calc(100vw - 24px)); max-height: min(88vh, 760px); padding: 0; border: 0; border-radius: 16px;
  background: var(--bg); color: var(--fg); box-shadow: 0 10px 40px rgba(0,0,0,.35); display: none; flex-direction: column;
}
#help[open] { display: flex; }
#help::backdrop { background: rgba(0, 0, 0, .45); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.help-head h2 { margin: 0; font-size: 20px; }
#help-close { border: 0; background: none; color: var(--muted); font-size: 22px; width: 44px; height: 44px; cursor: pointer; }
#help-body { overflow-y: auto; padding: 4px 16px 8px; font-size: 15px; line-height: 1.55; }
#help-body h3 { font-size: 16px; margin: 16px 0 4px; }
#help-body p { margin: 4px 0; }
.help-cats { list-style: none; padding: 0; margin: 6px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.help-cats li:last-child { grid-column: 1 / -1; }
.help-foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); }
#help-ok { width: 100%; height: 48px; border: 0; border-radius: 12px; background: #0f766e; color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; }
#credits { font-size: 11px; color: var(--muted); padding: 6px 16px 8px; border-top: 1px solid var(--line); }
#credits a { color: inherit; }
#sheet.peek #credits, #sheet.peek #detail, #sheet.peek #tool { display: none; }

.pin { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4);
  display: grid; place-items: center; font-size: 12px; }
.me { width: 18px; height: 18px; border-radius: 50%; background: #2563eb; border: 3px solid #fff;
  box-shadow: 0 0 0 8px rgba(37, 99, 235, .25); }
.center-pin { font-size: 24px; line-height: 1; }

/* PC: 목록을 왼쪽 패널로 */
@media (min-width: 768px) {
  #sheet, #sheet.peek, #sheet.half, #sheet.full {
    top: 70px; left: 12px; bottom: 12px; right: auto; width: 380px; height: auto; border-radius: 14px;
  }
  #grip { display: none; }
  #sheet.peek #credits, #sheet.peek #detail, #sheet.peek #tool { display: block; }
  #chips { left: 12px; right: auto; max-width: calc(100vw - 24px); }
  #locate { bottom: 76px; } #home { bottom: 20px; } #help-btn { bottom: 244px; } #memo-btn { bottom: 132px; } #measure-btn { bottom: 188px; }
}
