:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1c1a17;
  --text-2: #6b655c;
  --text-3: #9a9389;
  --line: #e2ddd4;
  --accent: #b4472e;
  --accent-soft: #fbeee9;
  --link: #1a62d6;
  --gold: #c8912a;
  --shadow: 0 1px 2px rgba(28, 26, 23, .05), 0 8px 24px -12px rgba(28, 26, 23, .18);
  --shadow-lg: 0 4px 12px rgba(28, 26, 23, .09), 0 24px 60px -20px rgba(28, 26, 23, .3);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #201e1b;
    --surface-2: #2a2724;
    --text: #efece6;
    --text-2: #a8a199;
    --text-3: #7c766e;
    --line: #35312d;
    --accent: #e57a5c;
    --accent-soft: #33231e;
  --link: #6ba4ff;
    --gold: #e0b055;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, .4), 0 24px 60px -20px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans KR", "Malgun Gothic", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 헤더 ---------- */
.hero {
  padding: 40px 20px 26px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.hero h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 38px);
  letter-spacing: -.02em;
  font-weight: 800;
}
.hero h1 span { color: var(--accent); }
.hero p {
  margin: 8px auto 0;
  max-width: 520px;
  color: var(--text-2);
  font-size: 14px;
}
.hero-stats {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.hero-stat b {
  display: block;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.hero-stat span { font-size: 12px; color: var(--text-3); }

/* ---------- 필터 ---------- */
.filters {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
}
.filters-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.search {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
}
.search input {
  width: 100%;
  padding: 9px 34px 9px 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search svg { position: absolute; left: 11px; top: 11px; opacity: .45; }
.search-clear {
  position: absolute; right: 6px; top: 6px;
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-3); cursor: pointer; font-size: 16px;
  line-height: 1; display: none;
}
.search-clear:hover { background: var(--surface-2); }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1 1 auto;
}
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: .12s;
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.chip .n { opacity: .55; margin-left: 5px; font-size: 11px; font-variant-numeric: tabular-nums; }

select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  max-width: 170px;
}
select:focus { outline: none; border-color: var(--accent); }

.count {
  font-size: 13px;
  color: var(--text-3);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.count b { color: var(--text); }

/* ---------- 그리드 ---------- */
.grid {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 20px 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 18px;
}
.grid[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: transparent;
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
}
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .4s ease;
}
.card:hover .thumb img { transform: scale(1.05); }

.rank {
  position: absolute; top: 9px; left: 9px;
  background: rgba(20, 18, 16, .78);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 7px;
  letter-spacing: .01em;
}
.rank.top { background: var(--gold); color: #241a04; }

.score {
  position: absolute; bottom: 9px; right: 9px;
  background: rgba(20, 18, 16, .82);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 9px 4px 7px;
  border-radius: 7px;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: center; gap: 3px;
}
.score i { color: var(--gold); font-style: normal; font-size: 12px; }

.award-flag {
  position: absolute; top: 9px; right: 9px;
  background: var(--gold);
  color: #241a04;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
}

.body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.meta { font-size: 12.5px; color: var(--text-2); }
.meta .dot { color: var(--text-3); margin: 0 5px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag {
  font-size: 11px;
  padding: 2.5px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
}
.tag.pref { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stats {
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  display: flex; gap: 12px;
  margin-top: auto;
  padding-top: 4px;
}
.budget { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.budget b { color: var(--text); font-weight: 600; }

.btns { display: flex; gap: 6px; padding: 0 14px 14px; }
.btn {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-2);
  background: var(--surface);
  transition: .12s;
  display: flex; align-items: center; justify-content: center;
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }
.btn.map:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 동기화 상태 바 ---------- */
.syncbar {
  max-width: 1280px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--text-3);
}
.sync-state::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  margin-right: 6px;
  vertical-align: 1px;
}
.sync-state.ok { color: var(--accent); }
.sync-state.ok::before { background: var(--accent); }
.sync-who { color: var(--text-2); }
.linkbtn {
  border: 0; background: transparent; padding: 0;
  color: var(--link); font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: underline;
}

/* ---------- 킵 ---------- */
.keep-btn {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: rgba(20, 18, 16, .55);
  backdrop-filter: blur(6px);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  transition: .14s;
}
.keep-btn svg { fill: none; }
.keep-btn:hover { background: rgba(20, 18, 16, .8); transform: scale(1.08); }
.keep-btn.on { background: var(--accent); }
.keep-btn.on svg { fill: currentColor; }
.card:has(.award-flag) .keep-btn { top: 40px; }

.budgets { display: flex; flex-direction: column; gap: 2px; }
.budget {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  display: flex; gap: 7px;
}
.budget > span { color: var(--text-3); flex: 0 0 26px; font-size: 11.5px; }
.budget b { color: var(--text); font-weight: 600; }
.budget .none { color: var(--text-3); font-weight: 400; font-style: normal; font-size: 11.5px; }

.card-note {
  font-size: 12px;
  color: var(--text-2);
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 6px 9px;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.vt-n {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  margin-left: 3px;
  border-radius: 8px;
  background: var(--line);
  color: var(--text-3);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.vt.on .vt-n { background: var(--accent); color: #fff; }

.keepbox {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  margin-bottom: 14px;
  transition: .15s;
}
.keepbox.on { border-color: var(--accent); background: var(--accent-soft); }
.keep-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-2); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 0 0 8px;
}
.keep-toggle svg { fill: none; }
.keepbox.on .keep-toggle { color: var(--accent); }
.keepbox.on .keep-toggle svg { fill: currentColor; }
.keep-note {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  resize: vertical;
}
.keep-note:focus { outline: none; border-color: var(--accent); }
.keep-saved { font-size: 11.5px; color: var(--accent); height: 15px; padding-top: 2px; }

.mapbar {
  display: flex; align-items: center; gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.mapbar-title { font-size: 14px; font-weight: 700; margin-right: auto; }
.mapbar-title b { color: var(--accent); font-variant-numeric: tabular-nums; }
.btn-sm {
  flex: 0 0 auto;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- 구글맵 링크 ---------- */
.maplink {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--link);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  align-self: flex-start;
}
.maplink:hover { text-decoration: underline; }
.maplink svg { flex: 0 0 auto; }
.acc-note { font-size: 12px; color: var(--text-3); }
.acc-ok { font-size: 12.5px; color: var(--accent); font-weight: 600; }

/* ---------- 목록/지도 탭 ---------- */
.viewtabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 3px;
  flex: 0 0 auto;
}
.vt {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 7px;
  cursor: pointer;
}
.vt.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- 지도 ---------- */
#mapwrap { max-width: 1280px; margin: 0 auto; padding: 22px 20px 40px; }
#map {
  height: min(72vh, 640px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--surface-2);
  z-index: 1;
}
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.92); }
}
.pin {
  display: block;
  width: 42px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 0;
  border-radius: 6px;
  border: 1.5px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.pin-area { background: var(--text-3); }
.maphint {
  margin: 12px 2px 0;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.acc-legend { display: inline-flex; align-items: center; gap: 5px; }
.acc-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.dot-exact { background: var(--accent); }
.dot-area { background: var(--text-3); }
#map.is-empty::after {
  content: "이 조건에 좌표가 있는 가게가 없습니다.";
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-3);
  font-size: 13px;
}

.empty { grid-column: 1/-1; text-align: center; padding: 70px 20px; color: var(--text-3); }
.empty b { display: block; font-size: 17px; color: var(--text-2); margin-bottom: 6px; }

.more { text-align: center; padding: 0 20px 60px; }
.more button {
  padding: 11px 30px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.more button:hover { background: var(--surface-2); }

/* ---------- 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 14, 12, .55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none !important; }
.sheet {
  background: var(--surface);
  border-radius: 18px;
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.sheet-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: rgba(20, 18, 16, .6);
  backdrop-filter: blur(6px);
  color: #fff; font-size: 17px; line-height: 1;
}
.sheet-imgs { display: grid; grid-template-columns: 2fr 1fr; gap: 2px; background: var(--surface-2); }
.sheet-imgs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-imgs img:first-child { grid-row: span 2; aspect-ratio: 1; }
.sheet-imgs img:not(:first-child) { aspect-ratio: 1; }
.sheet-body { padding: 20px 22px 24px; }
.sheet-body h2 { margin: 0 0 4px; font-size: 23px; letter-spacing: -.02em; }
.sheet-sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 14px; }
.sheet-score {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 11px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.sheet-score .big {
  font-size: 26px; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.sheet-score .sm { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
dl.info { display: grid; grid-template-columns: 88px 1fr; gap: 9px 12px; margin: 0 0 16px; font-size: 13.5px; }
dl.info dt { color: var(--text-3); font-size: 12.5px; }
dl.info dd { margin: 0; }
.awards { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 14px; }
.award {
  font-size: 11.5px; font-weight: 600;
  padding: 4px 9px; border-radius: 6px;
  background: color-mix(in srgb, var(--gold) 16%, transparent);
  color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 32%, transparent);
}
.quote {
  border-left: 3px solid var(--line);
  padding: 2px 0 2px 13px;
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-2);
}
.quote strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.sheet-btns { display: flex; gap: 8px; }
.sheet-btns .btn { padding: 12px; font-size: 13.5px; }
.sheet-btns .btn.map { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet-btns .btn.map:hover { filter: brightness(1.08); }

footer {
  text-align: center;
  padding: 26px 20px 40px;
  color: var(--text-3);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; padding: 16px 12px 50px; }
  .name { font-size: 14.5px; }
  .body { padding: 11px 11px 12px; }
  .btns { padding: 0 11px 11px; }
  .hero { padding: 28px 16px 20px; }
  .hero p { font-size: 13px; }
  dl.info { grid-template-columns: 76px 1fr; }

  /* 필터바를 2줄로 압축: 검색 + 가로 스크롤 컨트롤 스트립 */
  .filters { padding: 9px 0 10px; }
  .filters-inner { gap: 8px; padding: 0 12px; }
  .search { flex: 1 1 auto; min-width: 140px; }
  .vt { padding: 5px 11px; font-size: 12.5px; }
  .controls {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    margin: 0 -12px;
    padding: 2px 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .controls::-webkit-scrollbar { display: none; }
  .chips { flex-wrap: nowrap; }
  .chip { padding: 7px 12px; font-size: 12.5px; }
  select { flex: 0 0 auto; padding: 7px 8px; font-size: 12.5px; max-width: 130px; }
  .count { margin-left: 2px; padding-right: 4px; }
  .btn-long { display: none; }
  .btn { padding: 8px 4px; font-size: 12px; white-space: nowrap; }
}
