/* =============================================================
   PayoffLab — mortgage payoff calculator
   1. Tokens
   ============================================================= */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0d1b2a;
  --ink-2: #33465c;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --navy: #0d2a4a;
  --accent: #0f766e;
  --accent-soft: #e6f4f1;
  --c-base: #94a3b8;
  --c-extra: #0f766e;
  --c-recast: #b45309;
  --c-invest: #4f46e5;
  --c-good: #15803d;
  --c-warn: #b45309;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(13, 27, 42, .05), 0 8px 24px -12px rgba(13, 27, 42, .18);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --maxw: 1120px;
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { text-wrap: pretty; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.15; letter-spacing: -.01em; text-wrap: balance; color: var(--navy); }
h1 { font-size: clamp(1.55rem, 1.05rem + 2.6vw, 2.9rem); font-weight: 700; }
h2 { font-size: clamp(1.3rem, 1.05rem + 1vw, 1.7rem); font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: min(100% - 2rem, var(--maxw)); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -100px; left: 1rem; z-index: 999; padding: .6rem 1rem; background: var(--navy); color: #fff; border-radius: 8px; }
.skip-link:focus { top: 1rem; }

/* =============================================================
   4. Header / footer
   ============================================================= */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 62px; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; color: var(--navy); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); }
.site-nav { display: flex; gap: .85rem; flex-wrap: wrap; font-size: .85rem; font-weight: 500; }
.nav-secondary { display: none; }
.site-nav a { color: var(--ink-2); }
.site-nav a:hover { color: var(--accent); }

.site-footer { margin-top: 3.5rem; background: var(--navy); color: #dbe4ee; padding: 2.2rem 0 1.4rem; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 1.4rem; justify-content: space-between; }
.footer-brand { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: #fff; }
.footer-tag { font-size: .9rem; max-width: 42ch; color: #b8c6d6; }
.site-footer nav { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; }
.site-footer a { color: #dbe4ee; }
.copyright { margin-top: 1.6rem; padding-top: 1rem; border-top: 1px solid rgba(255, 255, 255, .13); font-size: .8rem; color: #9fb1c4; }

/* =============================================================
   5. Hero
   ============================================================= */
.hero { padding: 1.2rem 0 1rem; text-align: center; }
.hero-sub { margin: .6rem auto 0; max-width: 62ch; color: var(--ink-2); font-size: clamp(.92rem, .88rem + .3vw, 1.1rem); }
.privacy-badge {
  display: inline-flex; align-items: flex-start; gap: .5rem; margin-top: .8rem;
  padding: .5rem .85rem; border-radius: 14px; background: var(--accent-soft);
  color: #115e59; font-size: .78rem; text-align: left; max-width: 68ch; line-height: 1.45;
}
.privacy-badge svg { flex: none; margin-top: .2rem; }

/* =============================================================
   6. Components
   ============================================================= */
.tool-card, .panel, .trust-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(1rem, .6rem + 1.4vw, 1.6rem); margin-bottom: 1.1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.section-label { font-size: 1.05rem; margin: 1.6rem 0 .9rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.tag { font-family: var(--sans); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); background: var(--accent-soft); padding: .2rem .5rem; border-radius: 999px; }

.field-grid { display: grid; grid-template-columns: 1fr; gap: .9rem 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
label { font-size: .84rem; font-weight: 600; color: var(--ink-2); }
.sub-label { font-weight: 500; color: var(--muted); }
.hint { font-size: .78rem; color: var(--muted); min-height: 1.1em; }

.input-wrap { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out); }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .13); }
.input-wrap .affix { padding-inline: .7rem 0; color: var(--muted); font-weight: 600; font-size: .9rem; }
.input-wrap .affix-r { padding-inline: 0 .7rem; }
input[type="text"], input[type="month"], input[type="email"], select, textarea {
  font: inherit; color: var(--ink); background: transparent; border: 0; width: 100%;
  padding: .55rem .7rem; min-width: 0;
}
input[type="month"], select {
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
input:focus, select:focus { outline: none; }
input[type="month"]:focus-visible, select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .13); }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 500; color: var(--ink-2); cursor: pointer; line-height: 1.4; }
.check input { margin-top: .22rem; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.sub-input { margin-top: .5rem; max-width: 260px; }

.btn { background: var(--accent); color: #fff; padding: .55rem 1rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .9rem; transition: background .15s var(--ease-out); }
.btn:hover { background: #0b5f59; }
.btn-ghost { border: 1px solid var(--line-strong); color: var(--ink-2); padding: .5rem .9rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .85rem; background: var(--surface); transition: border-color .15s var(--ease-out), color .15s var(--ease-out); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.notice { border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .86rem; line-height: 1.55; margin-top: 1rem; }
.notice-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a5f; }
.notice-warn { background: #fffbeb; border: 1px solid #fde68a; color: #713f12; }
.form-status { font-size: .85rem; color: var(--c-warn); margin-top: .6rem; min-height: 1.2em; }
.fine-print { font-size: .8rem; color: var(--muted); margin-top: .9rem; line-height: 1.55; }

/* =============================================================
   7. Results — scenarios
   ============================================================= */
.results-title { margin-bottom: .9rem; }
.scenario-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; }
.scenario {
  background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--c-base);
  border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.scenario.is-extra { border-top-color: var(--c-extra); }
.scenario.is-recast { border-top-color: var(--c-recast); }
.scenario h3 { font-size: 1.05rem; margin-bottom: .1rem; }
.scenario .sc-sub { font-size: .8rem; color: var(--muted); margin-bottom: .8rem; min-height: 2.4em; }
.sc-hero { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.sc-hero-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.sc-rows { margin-top: .9rem; border-top: 1px solid var(--line); }
.sc-row { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.sc-row span:first-child { color: var(--muted); }
.sc-row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.sc-row.is-good span:last-child { color: var(--c-good); }
.sc-note { font-size: .78rem; color: var(--muted); margin-top: .7rem; line-height: 1.5; }

/* =============================================================
   8. Panels: chart, invest, mini stats, table
   ============================================================= */
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.panel-lead { color: var(--ink-2); font-size: .92rem; margin-bottom: 1rem; max-width: 76ch; }
.panel-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.panel-row { display: grid; grid-template-columns: 1fr; gap: 1.1rem; }
.panel-row .panel { margin-bottom: 0; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px; gap: 3px; }
.seg-btn { font-size: .82rem; font-weight: 600; color: var(--muted); padding: .35rem .8rem; border-radius: 999px; }
.seg-btn.is-on { background: var(--navy); color: #fff; }

.chart-wrap { width: 100%; overflow: hidden; }
#chart { width: 100%; height: auto; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; font-size: .82rem; color: var(--ink-2); margin-top: .7rem; }
.chart-legend b { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.invest-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; margin-top: 1.1rem; }
.invest-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: var(--surface-2); }
.invest-card.is-winner { border-color: var(--accent); background: var(--accent-soft); }
.invest-card h3 { font-size: .98rem; }
.invest-hero { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; color: var(--navy); margin-top: .3rem; }
.invest-verdict { grid-column: 1 / -1; border-left: 4px solid var(--c-invest); background: #f5f3ff; border-radius: var(--radius-sm); padding: .9rem 1rem; font-size: .92rem; color: #312e81; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; }
.mini { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .8rem; }
.mini-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.mini-value { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.mini-value.small { font-size: 1.05rem; }

.table-years details { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: .5rem; background: var(--surface-2); }
.table-years summary { cursor: pointer; padding: .6rem .9rem; font-weight: 600; font-size: .9rem; color: var(--navy); display: flex; flex-wrap: wrap; gap: .4rem 1rem; justify-content: space-between; }
.table-years summary::marker { color: var(--accent); }
.year-meta { font-weight: 500; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
table.amort { width: 100%; border-collapse: collapse; font-size: .82rem; background: var(--surface); }
table.amort th, table.amort td { padding: .4rem .6rem; text-align: right; white-space: nowrap; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.amort th { background: var(--surface-2); color: var(--muted); font-weight: 600; text-align: right; position: sticky; top: 0; }
table.amort th:first-child, table.amort td:first-child { text-align: left; }
table.amort td.extra-cell { color: var(--accent); font-weight: 600; }

.share-row { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin: 1.2rem 0 .4rem; }
.share-note { font-size: .8rem; color: var(--muted); max-width: 60ch; }

/* =============================================================
   9. Content sections
   ============================================================= */
.prose { padding-top: 2.4rem; }
.prose > h2 { margin-bottom: .8rem; }
.prose > p { max-width: 76ch; color: var(--ink-2); margin-bottom: 1rem; }
.steps { list-style: none; display: grid; grid-template-columns: 1fr; gap: 1rem; padding: 0; margin-top: 1.2rem; }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.step-n { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .9rem; margin-bottom: .5rem; }
.steps h3 { margin-bottom: .3rem; }
.steps p { font-size: .9rem; color: var(--ink-2); }

.rule-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; margin: 1.2rem 0; }
.rule { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: var(--radius-sm); padding: .9rem 1.1rem; }
.rule-yes { border-left-color: var(--c-good); }
.rule-no { border-left-color: var(--c-warn); }
.rule h3 { margin-bottom: .3rem; }
.rule p { font-size: .89rem; color: var(--ink-2); }

#faq details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: .6rem; }
#faq summary { cursor: pointer; padding: .85rem 1rem; font-weight: 600; color: var(--navy); font-size: .95rem; }
#faq summary::marker { color: var(--accent); }
#faq details p { padding: 0 1rem 1rem; font-size: .9rem; color: var(--ink-2); max-width: 78ch; }

.trust { padding-top: 2.4rem; }
.trust-card p { font-size: .9rem; color: var(--ink-2); margin-bottom: .8rem; max-width: 82ch; }
.trust-card h2 { margin-bottom: .8rem; }
.todo-slot { background: #fef3c7; border-bottom: 1px dashed #d97706; color: #92400e; padding: 0 .2rem; }
.updated { font-size: .84rem; color: var(--muted); }
.disclaimer-inline { border-top: 1px solid var(--line); padding-top: .9rem; font-size: .85rem !important; }

/* =============================================================
   10. Ad placeholders (empty slots — owner pastes AdSense later)
   ============================================================= */
.ad-slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: repeating-linear-gradient(45deg, #fbfcfd, #fbfcfd 10px, #f4f6f9 10px, #f4f6f9 20px);
  color: var(--muted); text-align: center;
}
.ad-label { font-size: .72rem; font-weight: 700; letter-spacing: .12em; }
.ad-size { font-size: .68rem; opacity: .7; }
.ad-leaderboard { min-height: 100px; margin: 1.4rem 0; }
.ad-incontent { min-height: 280px; margin: 2.4rem auto 0; max-width: 336px; }
.ad-rect { min-height: 250px; width: 100%; }

.ad-dialog { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); margin: 0; max-height: none; max-width: none; overflow: auto; border: 0; border-radius: var(--radius); padding: 1.2rem; width: min(92vw, 340px); height: fit-content; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px -20px rgba(13, 27, 42, .5); }
.ad-dialog::backdrop { background: rgba(13, 27, 42, .55); }
.ad-dialog-note { font-size: .85rem; color: var(--muted); margin-bottom: .7rem; }
.ad-dialog .btn { display: block; width: 100%; margin-top: .9rem; text-align: center; }
.ad-close { position: absolute; top: .3rem; right: .5rem; font-size: 1.5rem; line-height: 1; color: var(--muted); padding: .2rem .4rem; }
.ad-close:hover { color: var(--ink); }

.ad-toast {
  position: fixed; right: .6rem; bottom: .6rem; z-index: 60; width: min(66vw, 240px); min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
  box-shadow: 0 12px 32px -14px rgba(13, 27, 42, .45); color: var(--muted); padding: .8rem;
}
.ad-toast .ad-close { top: 0; right: .2rem; }

/* =============================================================
   11. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .nav-secondary { display: inline; }
  .site-nav { gap: 1.1rem; font-size: .9rem; }
  .ad-toast { right: 1rem; bottom: 1rem; width: min(88vw, 300px); min-height: 100px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .invest-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .field-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .scenario-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rule-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { padding: 3rem 0 1.4rem; }
}

/* =============================================================
   12. Dark mode
   ============================================================= */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1420;
    --surface: #121e2d;
    --surface-2: #17263a;
    --ink: #e8eef6;
    --ink-2: #b9c8da;
    --muted: #8ba0b8;
    --line: #23364d;
    --line-strong: #33495f;
    --navy: #e8eef6;
    --accent: #2dd4bf;
    --accent-soft: #123b39;
    --c-base: #8ba0b8;
    --c-extra: #2dd4bf;
    --c-recast: #fbbf24;
    --c-good: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
  body { background: var(--bg); }
  .site-footer { background: #081019; }
  .privacy-badge { color: #99f6e4; }
  .notice-info { background: #10243c; border-color: #1e3a5f; color: #cfe0f5; }
  .notice-warn { background: #2b220c; border-color: #5c4813; color: #fde68a; }
  .invest-verdict { background: #1a1a3d; color: #c7d2fe; }
  .seg-btn.is-on { background: var(--accent); color: #06251f; }
  .ad-slot { background: repeating-linear-gradient(45deg, #131f2e, #131f2e 10px, #162435 10px, #162435 20px); }
  .todo-slot { background: #3a2c07; color: #fde68a; }
}

/* =============================================================
   13. Print
   ============================================================= */
@media print {
  .site-header, .site-footer, .ad-slot, .ad-toast, .ad-dialog, .share-row,
  .panel-actions, .seg, .skip-link, #how-it-works, #when-it-pays, #faq, .hero-sub,
  #calc-form .card-head button, .privacy-badge { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .tool-card, .panel, .trust-card, .scenario { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .scenario-grid { grid-template-columns: repeat(3, 1fr); }
  .table-years details { break-inside: auto; }
  table.amort { font-size: 9px; }
  table.amort th { position: static; }
  a { color: #000; text-decoration: none; }
}
