:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --text: #1f1a17;
  --muted: #6b625c;
  --line: #ebe3da;
  --brand: #d9480f;
  --brand-strong: #b8390a;
  --brand-soft: #fff0e6;
  --ok: #2b8a3e;
  --ok-soft: #e9f7ec;
  --info: #1864ab;
  --info-soft: #e7f1fb;
  --warn: #8a5a00;
  --warn-soft: #fff6db;
  --gray-soft: #f1eeeb;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 4px 16px rgba(60, 40, 20, 0.06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --card: #221e1b;
    --text: #f3eee9;
    --muted: #a99f97;
    --line: #3a332e;
    --brand: #ff7a3d;
    --brand-strong: #ff9461;
    --brand-soft: #3a2418;
    --ok: #69db7c;
    --ok-soft: #1f3324;
    --info: #74c0fc;
    --info-soft: #1b2a3a;
    --warn: #ffd43b;
    --warn-soft: #3a3117;
    --gray-soft: #2c2723;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  padding: 20px 16px 8px;
  max-width: 720px;
  margin: 0 auto;
}
.top h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }

main { max-width: 720px; margin: 0 auto; padding: 8px 16px 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 1.05rem; margin: 0 0 12px; }

.notice {
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--warn-soft);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  font-size: 0.92rem;
}
.notice.error { background: #ffe9e9; border-color: #f5b5b5; }
@media (prefers-color-scheme: dark) { .notice.error { background: #3b1f1f; border-color: #6b3434; } }

.grid-2 { display: grid; grid-template-columns: 136px minmax(0, 1fr); gap: 12px; }
@media (max-width: 380px) { .grid-2 { grid-template-columns: 1fr; } }

.field { margin-bottom: 12px; min-width: 0; }
.field > label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

input, select, button { font: inherit; color: inherit; }
input[type='number'], input[type='search'], input[type='text'], select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 8px 12px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper input { text-align: center; padding: 8px 4px; min-width: 0; }
.stepper .unit { color: var(--muted); font-size: 0.9rem; }
.step {
  flex: 0 0 40px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--gray-soft);
  font-size: 1.2rem;
  cursor: pointer;
}

.budget { display: flex; gap: 6px; }
.budget input { flex: 1; min-width: 0; }
.budget select { flex: 0 0 76px; padding: 8px 6px; }

.radius-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.radius-picker button {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: 0.92rem;
}
.radius-picker button[aria-pressed='true'] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.radius-picker .custom { display: inline-flex; align-items: center; gap: 4px; }
.radius-picker .custom input { width: 88px; min-height: 40px; text-align: right; }
.radius-picker .unit { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
.btn.primary { width: 100%; background: var(--brand); color: #fff; font-size: 1.1rem; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.secondary { width: 100%; background: var(--brand-soft); color: var(--brand-strong); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.88rem; border-radius: 10px; background: var(--gray-soft); border-color: var(--line); }
.btn.small.primary { width: auto; font-size: 0.88rem; background: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn[disabled] { opacity: 0.6; cursor: progress; }
#more { width: 100%; margin-top: 8px; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }

.candidates { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.88rem; }
.candidates button {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  text-align: left;
}
.candidates button[aria-pressed='true'] { border-color: var(--brand); background: var(--brand-soft); font-weight: 700; }

.results-section { margin-top: 4px; }
.results-head h2 { margin: 6px 0 2px; font-size: 1.15rem; }
.summary { margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }
.progress { margin: 6px 0 10px; }
.progress .bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width 0.3s; }
.progress small { color: var(--muted); }

.filters { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; margin-bottom: 4px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.chips button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.chips button[aria-pressed='true'] { background: var(--text); color: var(--bg); border-color: var(--text); }
.toggles { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 0.86rem; }
.toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--brand); }

.map { height: 320px; border-radius: var(--radius); border: 1px solid var(--line); margin: 8px 0 12px; overflow: hidden; }
.price-pin {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -100%);
  display: inline-block;
}
.price-pin.est { background: #868e96; }
.price-pin.top { background: var(--brand-strong); font-size: 13px; }

.results { list-style: none; margin: 0; padding: 0; }
.result {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 4px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.result.top1 { border-color: color-mix(in srgb, var(--brand) 55%, var(--line)); }
.rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  background: var(--gray-soft);
}
.result.top1 .rank, .result.top2 .rank, .result.top3 .rank { background: var(--brand); color: #fff; }
.r-body { min-width: 0; }
.r-name { font-weight: 800; font-size: 1.02rem; color: var(--text); text-decoration: none; word-break: keep-all; overflow-wrap: anywhere; }
.r-name:hover { text-decoration: underline; }
.r-meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; overflow-wrap: anywhere; }
.r-meta .open-yes { color: var(--ok); font-weight: 700; }
.r-meta .open-no { color: #c92a2a; font-weight: 700; }
.r-menu { margin-top: 6px; font-size: 0.92rem; overflow-wrap: anywhere; }
.r-menu .menu-name { font-weight: 600; }
.r-actions { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.r-actions a, .r-actions button {
  font-size: 0.8rem;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 4px 9px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.r-price { text-align: right; white-space: nowrap; }
.r-total { font-size: 1.2rem; font-weight: 800; color: var(--brand-strong); }
.r-total.est { color: var(--muted); }
.r-per { font-size: 0.78rem; color: var(--muted); }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.badge.gp { background: var(--ok-soft); color: var(--ok); }

.src { display: inline-block; font-size: 0.72rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.src-user { background: var(--brand-soft); color: var(--brand-strong); }
.src-menu { background: var(--info-soft); color: var(--info); }
.src-goodprice { background: var(--ok-soft); color: var(--ok); }
.src-estimate { background: var(--gray-soft); color: var(--muted); border: 1px dashed var(--line); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.foot { max-width: 720px; margin: 0 auto; padding: 8px 16px 40px; font-size: 0.86rem; color: var(--muted); }
.foot ul { padding-left: 0; list-style: none; }
.foot li { margin: 4px 0; }
.muted { color: var(--muted); }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  width: min(480px, calc(100vw - 32px));
  max-height: 80vh;
  padding: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog[open] { display: flex; flex-direction: column; }
#menu-dialog .menu-list { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
#menu-dialog .dialog-actions { margin-top: 8px; }
.dlg-head h3:focus { outline: none; }
.est-note { color: var(--muted); font-size: 0.78rem; }
dialog h3 { margin: 0 0 4px; }
.menu-list { list-style: none; padding: 0; margin: 8px 0; }
.menu-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.menu-list li.best { font-weight: 800; color: var(--brand-strong); }
.menu-list li.skip { color: var(--muted); }
.menu-list .price { white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.key-card { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.key-help { margin: 0 0 12px; font-size: 0.92rem; }
.key-help a { color: var(--brand-strong); font-weight: 700; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.key-row .btn { min-height: 44px; flex: 0 0 auto; }
.key-msg { margin: 8px 0 0; font-size: 0.9rem; min-height: 1.2em; }
.key-msg.ok { color: var(--ok); font-weight: 700; }
.key-msg.err { color: #c92a2a; font-weight: 700; }
code { font-size: 0.9em; background: var(--gray-soft); padding: 0 4px; border-radius: 4px; }

body.secret-mode .local-only,
body.secret-mode #key-card { display: none !important; }
