:root {
  --bg: #12100e;
  --card: #1b1714;
  --card2: #221d18;
  --line: rgba(255,255,255,.08);
  --txt: #f1eae1;
  --dim: #a89c8d;
  --gold: #d9a441;
  --gold2: #f0c778;
  --green: #4ade80;
  --red: #f87171;
  --gray: #8b8378;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  word-break: keep-all;
}

img { max-width: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(18,16,14,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 10px; align-items: center; }
.logo { font-size: 28px; }
.brand b { font-size: 15px; letter-spacing: -.02em; }
.brand small { display: block; color: var(--dim); font-size: 11px; margin-top: 2px; }

main {
  padding: 12px 12px 28px;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel-head h2 { font-size: 13px; color: var(--gold2); letter-spacing: .02em; margin: 0; font-weight: 700; }

input, select, textarea {
  width: 100%;
  background: var(--card2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(217,164,65,.5); outline-offset: 1px; }

.field-row { display: grid; grid-template-columns: 68px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.field-row label { color: var(--dim); font-size: 12px; }

.range-inputs { display: flex; gap: 6px; align-items: center; }
.range-inputs input { width: 100%; text-align: center; font-variant-numeric: tabular-nums; }
.range-inputs .unit { color: var(--dim); font-size: 12px; }

.seg { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; }
.seg button { padding: 9px 0; font-size: 13px; border-radius: 10px; background: var(--card2); color: var(--dim); border: 1px solid var(--line); }
.seg button.on { background: rgba(217,164,65,.16); color: var(--gold2); border-color: rgba(217,164,65,.5); font-weight: 700; }

.field-col label { display: block; color: var(--dim); font-size: 12px; margin-bottom: 6px; }
.field-col textarea { resize: vertical; min-height: 62px; line-height: 1.5; }
#btnResetExcludes { margin-top: 6px; }

.select-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.select-row select:last-child { grid-column: 1/-1; }

.primary { width: 100%; height: 46px; border: 0; border-radius: 12px; background: linear-gradient(180deg,var(--gold2),var(--gold)); color: #241a06; font-weight: 800; font-size: 15px; }
.primary.small { width: auto; padding: 0 18px; height: 40px; }
.primary:disabled { opacity: .45; }

.mini { background: rgba(217,164,65,.14); color: var(--gold2); border: 1px solid rgba(217,164,65,.4); border-radius: 9px; padding: 7px 11px; font-size: 12px; font-weight: 700; }
.mini.ghost { background: transparent; color: var(--dim); border-color: var(--line); }

.icon-btn { width: 38px; height: 38px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); color: var(--gold2); font-size: 16px; }

.banner { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; background: rgba(217,164,65,.1); border: 1px solid rgba(217,164,65,.35); border-radius: 14px; padding: 12px; }
.banner-txt b { display: block; font-size: 13px; }
.banner-txt span { font-size: 12px; color: var(--dim); display: block; margin-top: 3px; }
.banner-actions { display: flex; gap: 8px; }

.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
#barFill { height: 100%; width: 0; background: linear-gradient(90deg,var(--gold),var(--gold2)); transition: width .25s; }

.progress-meta { display: flex; justify-content: space-between; color: var(--dim); font-size: 11px; margin-top: 8px; }

.hint, .usage-mini { color: var(--dim); font-size: 11px; line-height: 1.6; margin: 8px 0 0; }

.sum-text { font-size: 13px; color: var(--txt); margin-bottom: 8px; }
.sum-text b { color: var(--gold2); }

.chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.chip { padding: 7px 12px; border-radius: 99px; font-size: 12px; background: var(--card); color: var(--dim); border: 1px solid var(--line); }
.chip.on { background: rgba(217,164,65,.16); color: var(--gold2); border-color: rgba(217,164,65,.45); font-weight: 700; }
#sortSel { width: auto; padding: 7px 10px; font-size: 12px; border-radius: 99px; }

.map-panel { padding: 0; overflow: hidden; }
#map { height: 300px; width: 100%; background: var(--card2); }

.list { display: flex; flex-direction: column; gap: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 13px; }
.card.cand { border-color: rgba(74,222,128,.35); }
.card.blocked { opacity: .82; }

.card-head { display: flex; align-items: flex-start; gap: 8px; }
.rank { min-width: 26px; height: 26px; border-radius: 8px; background: var(--card2); color: var(--dim); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.name { flex: 1; font-size: 15px; font-weight: 700; letter-spacing: -.02em; line-height: 1.35; }
.badge { font-size: 10px; padding: 3px 7px; border-radius: 6px; font-weight: 800; white-space: nowrap; }
.b-cand { background: rgba(74,222,128,.16); color: var(--green); }
.b-blocked { background: rgba(248,113,113,.14); color: var(--red); }
.b-many { background: rgba(240,199,120,.16); color: var(--gold2); }
.b-out { background: rgba(139,131,120,.18); color: var(--gray); }
.b-skip { background: rgba(139,131,120,.18); color: var(--gray); }

.card-meta { color: var(--dim); font-size: 12px; line-height: 1.5; margin-top: 6px; }
.card-meta .addr { display: block; color: #cfc5b8; overflow-wrap: anywhere; }

.card-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.stat { font-size: 11px; padding: 4px 8px; border-radius: 7px; background: var(--card2); color: var(--dim); }
.stat b { color: var(--txt); }
.stat.warn { background: rgba(248,113,113,.12); color: #f4b3b3; }
.stat.good { background: rgba(74,222,128,.12); color: #b8f0c9; }
.stat.bonus { background: #1d2a1f; color: #a7f3c0; font-size: 11px; word-break: keep-all; }
.stat.bonus-score { background: #2a2318; color: #f5d18a; }

.card-actions { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; margin-top: 11px; }
.btn-ghost { display: grid; place-items: center; height: 34px; border-radius: 9px; background: var(--card2); border: 1px solid var(--line); color: var(--dim); font-size: 11.5px; text-decoration: none; font-family: inherit; padding: 0; cursor: pointer; }
.btn-ghost:active { background: #2b241d; }

.cafe-list { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.cafe { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.cafe .n { color: var(--txt); }
.cafe .d { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cafe.hit .n { color: var(--red); font-weight: 700; }

.empty { color: var(--dim); font-size: 13px; text-align: center; padding: 26px 0; line-height: 1.7; }

.foot { color: #6b6357; font-size: 10.5px; text-align: center; padding: 6px 0 26px; }

/* ---------- 상단 안내 카드 ---------- */
.intro-card {
  background: linear-gradient(160deg, rgba(217,164,65,.14), rgba(217,164,65,.05));
  border: 1px solid rgba(217,164,65,.34);
  border-radius: 16px;
  padding: 14px 15px;
}
.intro-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.72;
  color: #e8dccb;
  letter-spacing: -.01em;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.intro-card p.intro-maker {
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: #a29786;
  opacity: .9;
}

/* ---------- 기본값 버튼 ---------- */
.btn-default {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  letter-spacing: -.01em;
  word-break: keep-all;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.btn-default:active { background: #2b241d; color: var(--gold2); }

/* ---------- 메인 하단 아코디언 ---------- */
.accordion { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.acc-title { font-size: 13px; color: var(--gold2); margin: 4px 2px 2px; font-weight: 700; letter-spacing: -.01em; }
.acc-item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.acc-item summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--txt);
  line-height: 1.45;
  word-break: keep-all;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.acc-item summary::-webkit-details-marker { display: none; }
.acc-item summary::after {
  content: "+";
  flex: none;
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}
.acc-item[open] summary::after { content: "−"; }
.acc-item[open] summary { border-bottom: 1px solid var(--line); }
.acc-body { padding: 12px 14px 14px; font-size: 12.5px; line-height: 1.75; color: #cfc5b8; }
.acc-body p { margin: 0 0 9px; word-break: keep-all; }
.acc-body p:last-child { margin-bottom: 0; }
.acc-body b { color: var(--txt); }
.acc-body ul { margin: 0 0 9px; padding-left: 17px; }
.acc-body li { margin-bottom: 5px; word-break: keep-all; }

/* ---------- 하단 메뉴 ---------- */
.foot { padding: 2px 0 26px; }
.foot-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; margin-bottom: 8px; }
.foot-nav a { color: #8d8475; font-size: 11.5px; text-decoration: none; padding: 3px 2px; }
.foot-nav a:hover { color: var(--gold2); }
.foot-copy { color: #4f483f; font-size: 10.5px; margin: 0; text-align: center; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: grid; place-items: end center; z-index: 900; padding: 0; }
.modal[hidden] { display: none; }

.modal-card { width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; background: #17130f; border-radius: 20px 20px 0 0; border-top: 1px solid rgba(217,164,65,.28); padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { font-size: 15px; margin: 0; }

.key-state { font-size: 12px; line-height: 1.7; color: var(--dim); background: var(--card2); border-radius: 10px; padding: 10px; margin-bottom: 12px; }
.key-state b.ok { color: var(--green); }
.key-state b.no { color: var(--red); }

.modal label { display: block; font-size: 12px; color: var(--dim); margin: 10px 0 6px; }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.test-result { background: #0d0b09; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 11px; color: var(--dim); white-space: pre-wrap; word-break: break-all; margin-top: 12px; }

.help { margin-top: 14px; font-size: 11.5px; color: var(--dim); line-height: 1.65; }
.help summary { color: var(--gold2); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2a231b; color: var(--txt); border: 1px solid var(--line); border-radius: 12px; padding: 11px 15px; font-size: 12.5px; z-index: 1000; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100% - 32px); }

@media (max-width:360px) {
  .seg button { font-size: 12px; }
  .select-row { grid-template-columns: 1fr 1fr; }
  .select-row select:last-child { grid-column: 1/-1; }
  .card-actions { grid-template-columns: 1fr 1fr; }
}

/* ---------- 동별 세대 구성 패널 ---------- */
.dong-ym { font-size: 11px; color: var(--dim); }
.dong-rows { display: flex; flex-direction: column; gap: 6px; }
.dong-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--dim); }
.dong-row .dn { color: var(--txt); font-weight: 700; min-width: 62px; }
.dong-row .dv { font-variant-numeric: tabular-nums; text-align: right; }
.dong-row .dv b { color: var(--gold2); }
