/* 홈 계산기 — 전세 vs 월세 · 복비 · 대출이자 */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #141a22;
  --mute: #47505e;
  --faint: #8b939f;
  --line: #e2e5e9;
  --line-strong: #cfd4db;
  --acc: #1a56db;
  --acc-soft: #eaf0fd;
  --win: #f0f5ff;
  --win-warm: #fff6ef;
  --warn: #b4470c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 22px -14px rgba(16, 24, 40, .22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #161b22;
    --ink: #e8edf3;
    --mute: #b3bcc8;
    --faint: #7f8a98;
    --line: #242c36;
    --line-strong: #35404d;
    --acc: #6f9cff;
    --acc-soft: #1b2740;
    --win: #14213a;
    --win-warm: #2a1c13;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR",
    "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  word-break: keep-all;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
}

/* ── 상단 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 0 6px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--card);
  font-size: 17px;
  line-height: 1;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.basis {
  font-size: 11.5px;
  color: var(--faint);
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* ── 소개 ── */
.intro { padding: 6px 2px 14px; }
.intro h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.3;
  letter-spacing: -0.035em;
  font-weight: 800;
}
.intro h1 em { font-style: normal; color: var(--acc); }
.intro p { margin: 0; font-size: 13.5px; color: var(--mute); }

/* ── 탭 ── */
.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin: 0 0 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 14px -12px rgba(16, 24, 40, .35);
}
.tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--mute);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 4px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tabs button.on {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}
.tabs button:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }

/* ── 카드 ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card.result { padding: 16px; }

/* ── 입력 ── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 8px; }
.grid1 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.field { min-width: 0; }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--mute);
  margin-bottom: 5px;
}
.unit-inline { font-size: 11px; font-weight: 500; color: var(--faint); }
.money-field {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  padding: 0 10px;
  transition: border-color .15s, box-shadow .15s;
}
.money-field:focus-within {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 14%, transparent);
}
.money-field input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  padding: 9px 0;
  text-align: right;
}
.money-field input:focus { outline: none; }
.money-field input::placeholder { color: var(--faint); font-weight: 500; }
.money-field .unit { flex: 0 0 auto; font-size: 12px; color: var(--faint); }
.unit-hint {
  margin: 5px 1px 0;
  font-size: 11.5px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* 고급 설정 */
.adv { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
.adv summary {
  list-style: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 6px;
}
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: "＋"; font-weight: 700; }
.adv[open] summary::before { content: "−"; }
.adv > .grid3 { margin-top: 10px; }
.adv .money-field input { font-size: 15px; padding: 7px 0; }

/* ── 결과 공통 ── */
.verdict {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 14px;
  padding-left: 11px;
  border-left: 3px solid var(--acc);
}
.verdict b { font-size: 19px; font-weight: 800; letter-spacing: -0.03em; }
.verdict span { font-size: 12.5px; color: var(--mute); font-variant-numeric: tabular-nums; }

.meta { margin: 8px 0 0; font-size: 12px; color: var(--mute); line-height: 1.55; }
.meta.faint { color: var(--faint); font-size: 11.5px; }

/* 전세 vs 월세 대결 */
#compareResult[data-tone="wolse"] .verdict { border-left-color: var(--warn); }
.duel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.side {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 11px 10px;
  min-width: 0;
}
.side-label { margin: 0; font-size: 12px; font-weight: 700; color: var(--faint); display: flex; align-items: center; gap: 5px; }
.side-label .win {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--acc);
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--acc) 36%, var(--line));
  border-radius: 4px;
  padding: 0 4px;
  line-height: 1.5;
}
#compareResult[data-tone="wolse"] #sideWolse .win { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.side-value {
  margin: 2px 0 0;
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
.side-value b {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.15;
}
.side-value span { font-size: 11px; color: var(--faint); }
.side-sub {
  margin: 3px 0 0;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--faint);
}
.breakdown {
  list-style: none;
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 2px;
}
.breakdown li {
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
#compareResult[data-tone="jeonse"] #sideJeonse,
#compareResult[data-tone="wolse"] #sideWolse {
  background: var(--win);
  border-color: color-mix(in srgb, var(--acc) 30%, var(--line));
}
#compareResult[data-tone="wolse"] #sideWolse {
  background: var(--win-warm);
  border-color: color-mix(in srgb, var(--warn) 26%, var(--line));
}
#compareResult[data-tone="jeonse"] #sideJeonse .side-label,
#compareResult[data-tone="wolse"] #sideWolse .side-label { color: var(--acc); }
#compareResult[data-tone="wolse"] #sideWolse .side-label { color: var(--warn); }

.be-line {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--acc-soft);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.5;
}

/* ── 복비 ── */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--bg) 70%, var(--card));
  border: 1px solid var(--line);
  border-radius: 11px;
  margin-bottom: 12px;
}
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--mute);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(16, 24, 40, .1); }
.seg button:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
.seg.sub { margin-top: -4px; }
.seg.sub button { font-size: 12.5px; }

.fee-lead { margin: 0; font-size: 15px; color: var(--mute); }
.fee-lead b {
  display: block;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.fee-nego { margin: 14px 0 0; font-size: 14px; color: var(--mute); }
.fee-nego b { font-size: 18px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.field.inline { margin-top: 14px; }
.field.inline .money-field { max-width: 190px; }
.field.inline .money-field input { font-size: 15px; padding: 7px 0; }

/* ── 표 ── */
.tablewrap { overflow-x: auto; margin-top: 10px; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
caption { text-align: left; font-size: 12px; font-weight: 700; color: var(--mute); padding-bottom: 6px; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 11px; color: var(--faint); font-weight: 600; border-bottom: 1px solid var(--line-strong); }
tbody th { font-weight: 600; color: var(--mute); }
tr.now th, tr.now td { background: var(--acc-soft); color: var(--ink); font-weight: 700; }
.tablewrap.schedule { max-height: 268px; overflow-y: auto; }
.tablewrap.schedule thead th { position: sticky; top: 0; background: var(--card); }

/* ── 대출 ── */
.loan-primary { margin: 0 0 4px; }
.loan-cap { display: block; font-size: 12px; font-weight: 600; color: var(--faint); }
.loan-primary b {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.bar {
  --share: 4%;
  height: 8px;
  border-radius: 999px;
  margin: 14px 0 6px;
  background: linear-gradient(90deg,
    var(--acc) 0 calc(100% - var(--share)),
    color-mix(in srgb, var(--acc) 55%, var(--warn)) calc(100% - var(--share)) 100%);
  overflow: hidden;
  position: relative;
}
.bar-fill { display: none; }
.bar-legend {
  display: flex;
  justify-content: space-between;
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--faint);
}
.bar-legend b { color: var(--mute); font-variant-numeric: tabular-nums; }

.kv { margin: 14px 0 0; display: grid; gap: 8px; }
.kv > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.kv > div:last-child { border-bottom: 0; padding-bottom: 0; }
.kv dt { font-size: 12.5px; color: var(--mute); }
.kv dd { margin: 0; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── 접기 ── */
.more { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.more summary {
  list-style: none;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--mute);
  display: flex;
  align-items: center;
  gap: 6px;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "▾"; margin-left: auto; color: var(--faint); }
.more[open] summary::after { content: "▴"; }

/* ── 제휴 추천 ── */
.picks {
  margin: 22px 0 6px;
  padding: 16px 16px 14px;
  border-top: 1px solid var(--line);
  background: transparent;
}
.picks-title { margin: 0 0 8px; font-size: 12.5px; font-weight: 700; color: var(--mute); }
.ad-note {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--faint);
  line-height: 1.55;
  max-width: 44em;
}
.ad-flag {
  display: inline-block;
  font-weight: 700;
  color: var(--mute);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 4px;
  font-size: 10.5px;
  letter-spacing: 0;
}
.pick-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pick-list li { min-width: 0; }
.pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  text-decoration: none;
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color .15s, color .15s, background .15s;
}
.pick:hover, .pick:focus-visible {
  color: var(--mute);
  border-color: var(--acc);
  background: color-mix(in srgb, var(--card) 60%, transparent);
}
.pick-line { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pick-dot { opacity: .55; }
.pick b { font-weight: 600; color: var(--mute); overflow: hidden; text-overflow: ellipsis; }
.pick-go { font-weight: 700; opacity: .7; }

/* ── 앱처럼 쓰기 ── */
.apptip {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.apptip summary {
  cursor: pointer;
  padding: 14px 16px;
  font-size: 13.5px;
  font-weight: 700;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.apptip summary::-webkit-details-marker { display: none; }
.apptip summary::after { content: "＋"; margin-left: auto; color: var(--faint); font-weight: 700; }
.apptip[open] summary::after { content: "−" }
.apptip-body { padding: 0 16px 16px; display: grid; gap: 12px; }
@media (min-width: 560px) { .apptip-body { grid-template-columns: 1fr 1fr; } }
.step h3 { margin: 0 0 4px; font-size: 12.5px; font-weight: 700; color: var(--acc); }
.step ol { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--mute); }
.step li { margin-bottom: 2px; }
.apptip-body .meta { grid-column: 1 / -1; margin: 0; }

/* ── 하단 ── */
.foot { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); }
.basis-note { margin: 0 0 10px; font-size: 11px; line-height: 1.65; color: var(--faint); }
.flinks { margin: 0 0 6px; font-size: 12px; color: var(--faint); display: flex; gap: 8px; }
.flinks a { color: var(--mute); text-decoration: none; }
.flinks a:hover { text-decoration: underline; }
.copy { margin: 0; font-size: 11px; color: var(--faint); }
.disclosure { margin: 8px 0 0; font-size: 11px; line-height: 1.55; color: var(--faint); }

/* ── 좁은 화면 ── */
@media (max-width: 359px) {
  .grid2, .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 .field:last-child { grid-column: 1 / -1; }
  .intro h1 { font-size: 21px; }
  .tabs button { font-size: 12.5px; }
  .side-value b { font-size: 24px; }
  .seg.three button { font-size: 12px; }
}
@media (max-width: 330px) {
  .grid2 { grid-template-columns: 1fr; }
}

/* ── 문서 페이지 ── */
.doc { padding: 8px 2px 0; }
.doc h1 { margin: 6px 0 10px; font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }
.doc h2 { margin: 22px 0 7px; font-size: 15px; font-weight: 800; letter-spacing: -0.02em; }
.doc p { margin: 0 0 9px; font-size: 13.5px; color: var(--mute); line-height: 1.7; }
.doc ul { margin: 0 0 10px; padding-left: 18px; font-size: 13.5px; color: var(--mute); line-height: 1.7; }
.doc li { margin-bottom: 4px; }
.doc b { color: var(--ink); }
.doc a { color: var(--acc); }
.doc .flinks { margin-top: 22px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
