/* 1. Tokens */
:root {
  color-scheme: light dark;
  --bg: #f7f6f1; --surface: #ffffff; --surface-2: #f0efe8; --ink: #1c2420; --muted: #5c665f;
  --line: #dcdbd2; --accent: #14532d; --accent-ink: #ffffff; --error: #b42318;
  --pi: #166534; --tax: #c2730a; --ins: #2563a8; --hoa: #8a4fb0;
  --chart-balance: #166534; --chart-interest: #c2730a;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714; --surface: #1b221e; --surface-2: #252e29; --ink: #edf1ee; --muted: #a5b0a9;
    --line: #333d37; --accent: #4ade80; --accent-ink: #0d1f14; --error: #ff8a7a;
    --pi: #4ade80; --tax: #f5b04c; --ins: #6cb0f5; --hoa: #c79af0;
    --chart-balance: #4ade80; --chart-interest: #f5b04c;
  }
}

/* 2. Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--sans); font-size: 16px; line-height: 1.6; background: var(--bg); color: var(--ink); overflow-x: clip; }
img, svg, canvas { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
h1, h2 { line-height: 1.12; letter-spacing: -0.015em; text-wrap: balance; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* 3. Utilities */
.container { width: min(1080px, 100% - 24px); margin-inline: auto; }
.skip-link { position: fixed; top: -100px; left: 1rem; padding: .5rem 1rem; background: var(--surface); border-radius: 8px; z-index: 10; }
.skip-link:focus { top: .5rem; }
.muted { color: var(--muted); font-size: .94rem; }

/* 4. Header & hero */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-header .container { height: 46px; display: flex; align-items: center; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; font-size: .95rem; }
.hero { padding: 12px 0 10px; }
.hero h1 { font-family: var(--serif); font-size: clamp(1.55rem, 5vw, 2.5rem); font-weight: 700; }
.lede { color: var(--muted); font-size: .92rem; line-height: 1.35; }

/* 5. Tool card */
.tool-card { display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgb(0 0 0 / .05); }
.noscript { grid-column: 1 / -1; padding: 10px; background: var(--surface-2); border-radius: 8px; }
.results { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.result-label { font-size: .82rem; color: var(--muted); }
.payment { font-family: var(--serif); font-size: clamp(2rem, 9vw, 3.1rem); font-weight: 700; line-height: 1.08; color: var(--accent); font-variant-numeric: tabular-nums; }
.form-error { color: var(--error); font-size: .9rem; font-weight: 600; margin-top: 4px; }
.tool-card[data-state="error"] .payment { color: var(--muted); }
.bar { display: flex; gap: 2px; height: 9px; border-radius: 5px; overflow: hidden; margin: 8px 0; background: var(--line); }
.seg { display: block; width: 0; transition: width .2s ease-out; }
.seg-pi { background: var(--pi); } .seg-tax { background: var(--tax); } .seg-ins { background: var(--ins); } .seg-hoa { background: var(--hoa); }
.breakdown, .stats { display: grid; grid-template-columns: 1fr; gap: 1px; font-size: .84rem; }
.breakdown div, .stats div { display: flex; justify-content: space-between; gap: 6px; min-width: 0; }
.breakdown dt, .stats dt { color: var(--muted); }
dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.stats { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.notice { font-size: .82rem; line-height: 1.4; margin-top: 8px; color: var(--muted); }
.notice.good { color: var(--accent); font-weight: 600; }

.inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; align-content: start; min-width: 0; }
.field { min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.affix { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding-inline: 10px; }
.affix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.affix span { color: var(--muted); }
.affix input { width: 100%; min-width: 0; height: 40px; border: 0; background: transparent; padding-inline: 5px; outline: 0; font-size: 16px; font-variant-numeric: tabular-nums; }
.affix:has(input[aria-invalid="true"]) { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
select { width: 100%; height: 42px; padding-inline: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.more { grid-column: 1 / -1; }
.more summary { cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--accent); padding: 4px 0; }
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding-top: 6px; }
.link-btn { grid-column: 1 / -1; justify-self: start; font-size: .82rem; color: var(--muted); text-decoration: underline; padding: 2px 0; }
.badge { display: flex; align-items: flex-start; gap: 6px; color: var(--muted); font-size: .82rem; line-height: 1.4; padding: 10px 2px 0; }
.badge svg { flex: none; margin-top: 1px; color: var(--accent); }

/* 6. Sections */
.ad-slot { display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.ad-leaderboard { min-height: 100px; margin-top: 20px; }
.ad-content { min-height: 250px; margin: 26px 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 20px; }
.panel h2 { font-family: var(--serif); font-size: 1.35rem; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; list-style: none; padding: 0; margin: 8px 0; font-size: .85rem; color: var(--muted); }
.chart-balance { background: var(--chart-balance); } .chart-interest { background: var(--chart-interest); }
#chart { width: 100%; height: 280px; }
.compare-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.table-wrap { overflow-x: auto; }
.schedule-wrap { max-height: 460px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-size: .8rem; background: var(--surface); }
.schedule thead th { position: sticky; top: 0; box-shadow: 0 1px 0 var(--line); }
.schedule tbody tr:last-child td { border-bottom: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 5px 12px; font-size: .85rem; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ghost { padding: 5px 12px; font-size: .85rem; border: 1px solid var(--line); border-radius: 8px; }

.prose { max-width: 760px; padding-block: 34px 26px; }
.prose h2 { font-family: var(--serif); font-size: 1.45rem; margin: 26px 0 8px; }
.prose p { margin-bottom: 11px; }
.prose code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: .9em; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 5px; }
.prose details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.prose summary { cursor: pointer; font-weight: 600; }
.prose details p { margin: 7px 0 0; color: var(--muted); }
.legal h1 { font-family: var(--serif); font-size: 2rem; }
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 16px 0; margin-top: 18px; font-size: .85rem; color: var(--muted); }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 6px 20px; justify-content: space-between; }
.site-footer nav { display: flex; gap: 14px; }

/* 8. Responsive */
@media (min-width: 720px) {
  .hero { padding: 24px 0 16px; }
  .lede { font-size: 1.05rem; }
  .tool-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; padding: 22px; }
  .inputs { order: -1; }
  .results { padding: 20px; }
  .breakdown { grid-template-columns: 1fr; gap: 3px; font-size: .92rem; }
  .stats { gap: 3px; font-size: .92rem; margin-top: 12px; padding-top: 12px; }
  .bar { margin: 12px 0; }
  .panel { padding: 24px; }
  #chart { height: 340px; }
}

/* Print: the summary and full schedule only */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #fff; --ink: #000; --muted: #333; --line: #bbb; --accent: #000; }
  .site-header, .inputs, .badge, .ad-slot, .prose, .site-footer, .actions, .skip-link, .bar, .panel:has(#chart), .panel:has(.compare) { display: none !important; }
  .tool-card, .panel { border: 0; box-shadow: none; padding: 0; display: block; }
  .stats { display: grid; }
  .schedule-wrap { max-height: none; overflow: visible; border: 0; }
  .schedule thead th { position: static; }
  tr { break-inside: avoid; }
}
