:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --ink: #1a2233;
  --muted: #5b6577;
  --brand: #2f6df6;
  --brand-dark: #1f4fc0;
  --border: #e6e9f0;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(26, 34, 51, 0.06);
  --maxw: 1100px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  font-size: 16px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---------- Header / footer ---------- */
header.site {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header.site .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand span { color: var(--brand); }
header nav a { color: var(--muted); margin-left: 22px; font-size: 15px; }
header nav a.lang {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  white-space: nowrap;
}

main { padding: 40px 0 64px; }

footer.site {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}
footer.site .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 24px 20px;
}

/* ---------- Compact hero ---------- */
.hero { margin-bottom: 22px; }
.hero h1 {
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.hero p.lead {
  font-size: 17px;
  color: var(--muted);
  margin: 0 0 6px;
  max-width: 720px;
}
.updated { font-size: 13px; color: var(--muted); margin: 0; }

.section-title {
  margin: 40px 0 16px;
  font-size: 24px;
  letter-spacing: -0.01em;
}

/* ---------- Homepage cards ---------- */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 8px 0 10px;
}
@media (min-width: 900px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
a.tool-card { display: block; color: inherit; }
a.tool-card:hover {
  border-color: var(--brand);
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(26, 34, 51, 0.09);
}
/* Tool-card headings are h2 (they sit directly under the page H1 in the
   document outline, and each card is a top-level section of the homepage).
   The declaration is unchanged from the old `h3` rule, so the rendered size,
   weight and spacing are byte-identical. */
.tool-card h2 { margin: 0 0 6px; font-size: 20px; }
.tool-card .tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: #eaf1ff;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.tool-card p { color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.tool-card .go {
  display: inline-block;
  color: var(--brand);
  font-weight: 600;
  font-size: 15px;
}

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 15px;
  border: none;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }

/* ---------- Content sections ---------- */
.explain { margin-top: 8px; color: var(--muted); font-size: 16px; }
.explain h2 { color: var(--ink); font-size: 22px; margin: 32px 0 10px; }
.explain h3 { color: var(--ink); font-size: 17px; margin: 18px 0 6px; }
.explain p { margin: 0 0 14px; }
.explain li { margin-bottom: 12px; }
.explain li strong { color: var(--ink); }

.howto {
  background: #f0f6ff;
  border: 1px solid #d6e4ff;
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 28px 0;
}
.howto h2 { font-size: 17px; margin: 0 0 6px; }
.howto p { margin: 0; color: var(--muted); font-size: 15px; }

.bio {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-top: 30px;
}
.bio .avatar {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
}
.bio .who strong { display: block; font-size: 16px; }
.bio .who p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }

details.faq {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
}
details.faq summary { font-weight: 600; cursor: pointer; color: var(--ink); }
details.faq p { margin: 10px 0 0; color: var(--muted); }

.refs { margin: 0; padding-left: 20px; }
.refs li { margin-bottom: 10px; }

.related-grid { display: grid; gap: 12px; margin-top: 8px; }
.related-grid a.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  color: var(--ink);
  font-weight: 600;
}
.related-grid a.card:hover { border-color: var(--brand); text-decoration: none; }
.related-grid a.card span {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}
.related-grid .soon {
  color: var(--muted);
  font-size: 14px;
  padding: 14px 18px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ---------- Two-column tool layout ---------- */
.tool { display: block; }
@media (min-width: 1024px) {
  .tool {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 28px;
    align-items: start;
  }
  .tool-results { position: sticky; top: 16px; }
}

.calc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.field-group { margin-bottom: 18px; }
.field-group:last-child { margin-bottom: 0; }
.group-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
}
.fields-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .fields-grid { grid-template-columns: 1fr 1fr; }
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px #eaf1ff;
  background: #fff;
}
.input-wrap { position: relative; }
.input-wrap .adorn {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}
.input-wrap .adorn.right { left: auto; right: 12px; }
.input-wrap input { padding-left: 26px; }
.input-wrap.has-right input { padding-left: 12px; padding-right: 26px; }

/* Advanced options */
details.advanced {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
}
details.advanced summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  list-style: none;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::after {
  content: "+";
  float: right;
  color: var(--brand);
  font-weight: 700;
}
details.advanced[open] summary::after { content: "−"; }
details.advanced summary .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
details.advanced .adv-body { padding: 2px 16px 16px; }
.adv-note {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  margin: 10px 0 0;
}
.adv-note:first-child { margin-top: 0; }

/* ---------- Results panel ---------- */
.results-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.hero-result { margin-bottom: 14px; }
.hr-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.hr-value {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brand);
  line-height: 1.15;
  margin-top: 2px;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}
.stat {
  background: #f3f6fd;
  border-radius: 10px;
  padding: 12px 14px;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; color: var(--ink); margin-top: 2px; }

/* PITI block: total monthly payment incl. taxes, insurance, PMI, HOA */
.piti {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: 10px;
  background: #f7f9fe;
}
.piti-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.piti-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
  margin-top: 2px;
}
.piti-breakdown {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.piti-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  color: var(--muted);
  padding: 3px 0;
}
.piti-row .v { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.piti-row.total {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 6px;
  font-weight: 700;
  color: var(--ink);
}
.piti-row.total .v { color: var(--brand); font-size: 15px; }

.note { font-size: 13px; color: var(--muted); margin-top: 14px; }
.warn {
  background: #fff5f2;
  border: 1px solid #ffd4c2;
  color: #9a3412;
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 14px;
  font-size: 14px;
}

/* ---------- SVG visuals ---------- */
.viz { display: flex; align-items: center; gap: 16px; margin: 4px 0 6px; }
.donut-bg { fill: none; stroke: #eef1f7; stroke-width: 16; }
.donut-a {
  fill: none;
  stroke: var(--brand);
  stroke-width: 16;
  transform: rotate(-90deg);
  transform-origin: center;
}
.donut-b {
  fill: none;
  stroke: #f59e0b;
  stroke-width: 16;
  transform: rotate(-90deg);
  transform-origin: center;
}
.donut-c {
  fill: none;
  stroke: #10b981;
  stroke-width: 16;
  transform: rotate(-90deg);
  transform-origin: center;
}
.donut-d {
  fill: none;
  stroke: #8b5cf6;
  stroke-width: 16;
  transform: rotate(-90deg);
  transform-origin: center;
}
.donut-num { font-size: 19px; font-weight: 700; fill: var(--ink); }
.donut-cap { font-size: 11px; fill: var(--muted); }
.viz-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 7px;
}
.dot-a { background: var(--brand); }
.dot-b { background: #f59e0b; }
.dot-c { background: #10b981; }
.dot-d { background: #8b5cf6; }
.bar-a { fill: #94a3b8; }
.bar-b { fill: var(--brand); }
.bar-cap { font-size: 12px; fill: var(--muted); }

/* ---------- Amortization schedule ---------- */
.schedule { margin: 24px 0 0; }
.sched-toggle { width: 100%; }
.schedule-body { margin-top: 18px; }
.sched-note {
  font-size: 15px;
  color: var(--ink);
  background: #f0f6ff;
  border: 1px solid #d6e4ff;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-height: 520px;
  overflow-y: auto;
}
table.amort {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 560px;
}
.amort th,
.amort td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.amort th:first-child,
.amort td:first-child { text-align: left; }
.amort thead th {
  background: #f7f9fd;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  z-index: 1;
}
.amort tr.yr td { font-weight: 600; background: #fbfcff; cursor: pointer; }
.amort tr.yr:hover td { background: #f0f6ff; }
.amort tr.mo td { color: var(--muted); font-weight: 400; }
.amort tr.mo td:first-child { padding-left: 34px; }
.exp {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--brand);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  margin-right: 8px;
  font-weight: 700;
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  main { padding: 28px 0 48px; }
  .hero h1 { font-size: 27px; }
  .hero p.lead { font-size: 16px; }
  .hr-value { font-size: 38px; }
  .piti-value { font-size: 26px; }
  header nav a { margin-left: 14px; }
  table.amort { font-size: 13px; min-width: 520px; }
  .amort th, .amort td { padding: 7px 9px; }
}
