:root {
  --bg: #0E1116;
  --card: #171B22;
  --card-hi: #1D232C;
  --line: #262D38;
  --text: #F2F4F7;
  --muted: #8D96A5;
  --accent: #4C8DFF;
  --accent-ink: #FFFFFF;
  --bg-rgb: 14, 17, 22;
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F8FAFC; --card: #FFFFFF; --card-hi: #EFF4FE; --line: #E2E8F0;
    --text: #111827; --muted: #64748B; --accent: #2563EB; --accent-ink: #FFFFFF;
    --bg-rgb: 248, 250, 252;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F8FAFC; --card: #FFFFFF; --card-hi: #EFF4FE; --line: #E2E8F0;
  --text: #111827; --muted: #64748B; --accent: #2563EB; --accent-ink: #FFFFFF;
  --bg-rgb: 248, 250, 252;
  color-scheme: light;
}
* { box-sizing: border-box; }
/* 라이트/다크 전환이 뚝 끊기지 않고 부드럽게 이어지도록. prefers-reduced-motion에서는 아래 미디어쿼리가 다시 꺼준다. */
*, *::before, *::after { transition: background-color .2s ease, border-color .2s ease, color .2s ease; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) max(20px, calc((100% - 480px) / 2)) env(safe-area-inset-bottom);
  background: var(--bg) radial-gradient(60% 260px at 50% -40px, rgba(198, 244, 50, .16), transparent 72%) no-repeat;
  color: var(--text);
  word-break: keep-all;
  overflow-wrap: break-word;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}
a { color: var(--accent); }
h1 { margin: 0; font-size: 30px; line-height: 1.25; letter-spacing: -.03em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.crumb { margin: 14px 0 0; font-size: 13px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }
.lang-switch { position: relative; display: inline-block; margin: 8px 0 0; }
.lang-toggle {
  height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: 99px;
  background: var(--card); color: var(--muted); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: border-color .2s, color .2s;
}
.lang-toggle:hover, .lang-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--text); }
.lang-menu[hidden] { display: none; }
.lang-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 15;
  margin: 0; padding: 6px; list-style: none; min-width: 120px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, .5);
}
.lang-menu li + li { margin-top: 2px; }
.lang-menu a { display: block; padding: 8px 10px; border-radius: 10px; color: var(--text); font-size: 13px; text-decoration: none; }
.lang-menu a:hover, .lang-menu a:focus-visible { background: var(--card-hi); }
.lang-menu a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.theme-toggle {
  position: fixed; z-index: 20; top: calc(14px + env(safe-area-inset-top, 0px)); right: max(14px, calc((100% - 480px) / 2 + 14px));
  width: 38px; height: 38px; margin: 0; padding: 0; max-width: none; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card); font-size: 16px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .4);
}
.theme-toggle:hover { border-color: var(--accent); }

.hero { padding-top: 20px; padding-bottom: 20px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.accent { color: var(--accent); }
.lead { margin: 10px 0 0; color: var(--muted); text-wrap: balance; }

/* 지역·건물유형·거래유형·기간·평형·가격·검색까지 세로로 쌓이는 줄들 사이 간격을 여기 gap
   하나로 통일한다. 전에는 줄마다 margin-top을 따로 줘서(0/8/10/14px) 줄마다 간격이 달랐고,
   DOM 순서가 바뀌면서(#deal-type + .selects) 그 조정값 중 하나는 더 이상 적용되지도 않았다. */
/* 예전엔 이 영역을 position:sticky로 화면 위에 고정하고 스크롤하면 자동으로 접었는데,
   접힌 상태에서 지역 드롭박스가 살짝 삐져나와 보이는 버그가 있었고(overflow:hidden인
   상자에 padding을 또 줘서 0 높이로 완전히 안 접힘) 사용성도 안 좋았다 — 그냥 평범하게
   스크롤을 따라 같이 내려가는 고정 안 된 영역으로 바꿨다. */
.filters { padding: 12px 0 20px; background: var(--bg); display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
.filters-body-inner { display: flex; flex-direction: column; gap: 10px; }
/* 지역·평형·가격은 가로 스크롤 없이 같은 줄에서 "같은 너비"로 나란히 둔다(호갱노노처럼 압축하되,
   내용 길이에 따라 칸마다 폭이 들쭉날쭉해지는 걸 피해 한눈에 비교하기 쉽게). overflow를 쓰지 않아서
   포커스 테두리(outline-offset 2px)가 위아래로 잘리는 문제도 함께 없앤다. */
.selects { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.month-select { width: 100%; }
.month-range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.month-range .tilde { color: var(--muted); font-weight: 700; }
/* 이름 검색 중엔 월 지정이 적용되지 않는다(항상 최근 12개월) — 숨기지 않고 흐리게만 둬서
   "방금 있던 칸이 사라졌다"는 느낌 없이 자리와 이유를 함께 보여준다. */
.month-range.disabled { opacity: .45; pointer-events: none; }
.search-wrap { position: relative; }
.search-form { display: flex; gap: 8px; }
.search-form input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text); font: inherit;
}
.search-form input::placeholder { color: var(--muted); }
.search-btn {
  flex: none; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); font-size: 16px; cursor: pointer; transition: border-color .2s;
}
.search-btn:hover { border-color: var(--accent); }
/* 아파트명 자동완성. 네이티브 <datalist> 대신 직접 구현해서, 타이핑한 만큼만 걸러 보여준다(포커스만
   해도 수백 개가 펼쳐져 타이핑을 가리던 문제를 없앴다). */
.suggest[hidden] { display: none; }
.suggest {
  position: absolute; left: 0; right: 46px; top: calc(100% + 4px); z-index: 6;
  margin: 0; padding: 6px; list-style: none; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, .5);
}
.suggest li + li { margin-top: 2px; }
.suggest button {
  display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.suggest button:hover, .suggest button:focus-visible { background: var(--card-hi); }
.search-active { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-hi); font-size: 13px; }
.search-active span { flex: 1; color: var(--muted); }
.search-active strong { color: var(--text); }
.search-active button { flex: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.search-active button:hover { color: var(--accent); }
#fav-toggle { font-size: 18px; padding: 0 4px; }
#fav-toggle[aria-pressed="true"] { color: var(--accent); }

.favorites[hidden] { display: none; }
.favorites-head { display: flex; justify-content: flex-end; margin-top: 10px; }
#compare-toggle { height: 28px; padding: 0 12px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; transition: border-color .2s, color .2s, background .2s; }
#compare-toggle[aria-pressed="true"] { border-color: var(--accent); background: rgba(76, 141, 255, .1); color: var(--accent); }
.compare-hint[hidden] { display: none; }
.compare-hint { margin: 6px 2px 0; color: var(--muted); font-size: 12px; }
.fav-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.fav-chip { height: 32px; padding: 0 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: border-color .2s; }
.fav-chip:hover { border-color: var(--accent); }
.fav-chip::before { content: "★ "; color: var(--accent); }
.fav-chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(76, 141, 255, .12); }

.compare-row { display: flex; align-items: baseline; gap: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.compare-row strong { flex: none; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.compare-row.a strong { color: var(--accent); }
.compare-row.b strong { color: #E0A33C; }
.compare-chart .chart-svg polyline.series-a { stroke: var(--accent); fill: none; }
.compare-chart .chart-svg polyline.series-b { stroke: #E0A33C; fill: none; }
.compare-chart .chart-svg circle.series-a { fill: var(--accent); }
.compare-chart .chart-svg circle.series-b { fill: #E0A33C; }
.compare-chart .chart-svg circle { stroke: var(--card); stroke-width: 2; }
select {
  width: 100%; height: 36px; padding: 0 30px 0 14px;
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line); border-radius: 99px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238D96A5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
  color: var(--text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
option { background: var(--card); color: var(--text); }
/* 건물유형·거래유형·정렬 칩. 줄바꿈 대신 한 줄로 두고 넘치면 가로로 스와이프한다
   (칩이 5개까지 늘어나면서 줄바꿈이 보기 지저분해져서 — 내비게이션 바로 아래라 세로 공간도 아낀다). */
.sorts { display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 3px 2px; margin: 0 -2px; }
.sorts::-webkit-scrollbar { display: none; }
.sorts button { flex: 0 0 auto; height: 32px; padding: 0 14px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; transition: border-color .2s, color .2s, background .2s; }
.sorts button[aria-pressed="true"] { border-color: rgba(76, 141, 255, .6); background: rgba(76, 141, 255, .1); color: var(--accent); }

main { padding-top: 6px; }
.status { min-height: 1.5em; margin: 10px 0 12px; font-size: 13px; color: var(--muted); }

.chart[hidden] { display: none; }
.chart { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.chart-legend { min-width: 0; }
.chart-title { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.chart-row { display: flex; align-items: baseline; gap: 8px; }
.chart-row strong { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chart-row em { font-style: normal; font-size: 12px; font-weight: 700; }
.chart-row em.up { color: #E08A3C; }
.chart-row em.down { color: #4C8AD1; }
.chart-svg { flex: none; width: 132px; height: 40px; margin-left: auto; }
.chart-svg polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-svg circle { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.card { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); animation: rise .4s cubic-bezier(.2, .7, .2, 1) both; cursor: pointer; transition: border-color .2s; }
/* 정렬만 바꿀 때(데이터는 그대로, 순서만 바뀜)는 카드 전체가 다시 깜박이지 않게 진입 애니메이션을 끈다.
   새로 불러온 목록을 처음 그릴 때만 JS가 #list에 .enter를 붙여 애니메이션을 켠다. */
.list:not(.enter) .card { animation: none; }
.card:hover, .card[aria-expanded="true"] { border-color: rgba(76, 141, 255, .45); }
.map-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.map-wrap { margin: 12px -18px -16px; animation: rise .3s ease both; }
.map-status { margin: 0; padding: 14px 18px; color: var(--muted); font-size: 13px; text-align: center; }
.map-el { height: 220px; border-radius: 0 0 var(--radius) var(--radius); cursor: default; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 12px; }
.date { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.price strong { font-size: 26px; font-weight: 800; letter-spacing: -.02em; color: var(--accent); }
.price span { color: var(--muted); font-weight: 600; }
.pyeong { margin-left: auto; color: var(--muted); font-size: 13px; font-style: normal; }
/* 지금 목록(같은 조건) 평균 평단가 대비 배지 — 비싸면 붉게, 싸면 녹색으로. */
.pyeong-compare { flex: none; height: 20px; padding: 0 8px; border-radius: 99px; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; }
.pyeong-compare.up { background: rgba(249, 112, 102, .15); color: #F97066; }
.pyeong-compare.down { background: rgba(76, 175, 120, .15); color: #4CAF78; }
.name { margin: 0; font-size: 16px; font-weight: 700; }
.meta { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.skel { height: 108px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(100deg, var(--card) 30%, var(--card-hi) 50%, var(--card) 70%) 0 0 / 200% 100%; animation: shimmer 1.3s linear infinite; }
.notice { display: grid; justify-items: center; gap: 4px; padding: 40px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }
.notice strong { color: var(--text); font-size: 17px; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 20px; margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-hi); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }

.map-count { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.map-el-full { height: 56vh; min-height: 320px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

/* 지도 접기/펼치기 — 검색 조건 접기와 같은 방식(grid-template-rows 0fr↔1fr 아코디언 + 경계선에 걸친 캡슐 버튼). */
#map-wrap { position: relative; padding-bottom: 14px; }
#map-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s ease; }
#map-body.collapsed { grid-template-rows: 0fr; }
.map-body-inner { overflow: hidden; min-height: 0; }
.map-toggle {
  position: absolute; left: 50%; bottom: -1px; transform: translate(-50%, 50%);
  height: 28px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card-hi); color: var(--muted);
  display: flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 700;
  white-space: nowrap; box-shadow: 0 4px 10px -4px rgba(0, 0, 0, .35); z-index: 1;
}
.map-toggle:hover { border-color: var(--accent); color: var(--accent); }
.map-toggle .chevron { width: 14px; height: 14px; transition: transform .28s ease; }
.map-toggle[aria-expanded="false"] .chevron { transform: rotate(180deg); }

.map-sheet[hidden] { display: none; }
.map-sheet {
  margin-top: 12px; padding: 14px 0 0; border-top: 1px solid var(--line);
  display: grid; gap: 12px; max-height: 50vh; overflow-y: auto;
}
.map-sheet-title { margin: 0; font-size: 15px; font-weight: 800; }

.disclaimer { margin: 18px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.foot { padding-block: 32px 40px; color: var(--muted); font-size: 13px; }
.foot a { color: var(--muted); }

.top {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 10;
  width: 44px; height: 44px; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card-hi); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .5);
}
.top:hover { background: var(--card); border-color: var(--accent); }

/* ── 관련 뉴스 ── */
.related { padding-block: 28px; border-top: 1px solid var(--line); margin-top: 8px; }
.related h2 { margin: 0 0 4px; font-size: 17px; }
.news-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.news-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.news-item:last-child { border-bottom: 0; }
.news-item a { color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; }
.news-item a:hover { color: var(--accent); }
.news-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.news-list .skel { height: 44px; border-radius: 10px; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
