/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --ink: #101828;
  --ink-soft: #475467;
  --ink-faint: #8792a2;
  --border: #e2e6ed;
  --border-strong: #cbd2dd;

  --primary: #1e3a5f;
  --primary-dark: #142942;
  --primary-soft: #e8edf4;
  --accent: #0f9d6d;
  --accent-dark: #0b7e57;
  --accent-soft: #e4f5ee;
  --danger: #d92d20;
  --danger-soft: #fbeae8;
  --warn: #b54708;
  --warn-soft: #fef6e7;

  --ad-bg: #f1f2f4;
  --ad-border: #b8bdc7;
  --ad-ink: #7a808c;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Manrope", var(--sans);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-soft: cubic-bezier(0.25, 0.46, 0.45, 0.94);

  --container: 1180px;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #151b24;
    --surface-2: #1b2330;
    --ink: #eef1f6;
    --ink-soft: #b0b9c6;
    --ink-faint: #7a8494;
    --border: #29323f;
    --border-strong: #38424f;

    --primary: #6f9bc9;
    --primary-dark: #4c7099;
    --primary-soft: #1c2836;
    --accent: #35c290;
    --accent-dark: #24a075;
    --accent-soft: #113328;
    --danger: #f0685e;
    --danger-soft: #3a1c1a;
    --warn: #f2b155;
    --warn-soft: #3a2c14;

    --ad-bg: #1b2028;
    --ad-border: #3a4351;
    --ad-ink: #8c94a1;

    color-scheme: dark;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { font-family: var(--display); text-wrap: balance; line-height: 1.15; letter-spacing: -0.01em; color: var(--ink); }
ul, ol { padding-left: 1.2em; }
::selection { background: var(--accent-soft); color: var(--accent-dark); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* =============================================================
   3. Utilities
   ============================================================= */
.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--ink); color: var(--bg);
  z-index: 9999; border-radius: 8px; font-weight: 600;
  transition: top .2s var(--ease-out);
}
.skip-link:focus { top: 1rem; }

.container { max-width: var(--container); margin-inline: auto; padding-inline: var(--gutter); }
.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;
}
.section { padding-block: clamp(2.5rem, 6vw, 4.5rem); }
.section-head { max-width: 62ch; margin-bottom: clamp(1.5rem, 4vw, 2.5rem); }
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-dark);
}
.text-lede { color: var(--ink-soft); font-size: clamp(1rem, 1.6vw, 1.15rem); }

/* =============================================================
   4. Typography
   ============================================================= */
h1 { font-size: clamp(2rem, 4.6vw, 3.1rem); font-weight: 800; }
h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); font-weight: 800; }
h3 { font-size: clamp(1.1rem, 1.8vw, 1.35rem); font-weight: 700; }
.tabular { font-variant-numeric: tabular-nums; }

/* =============================================================
   5. Components
   ============================================================= */

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .8rem 1.4rem; border-radius: var(--radius-sm);
  font-weight: 700; font-size: .95rem; line-height: 1;
  transition: transform .15s var(--ease-out), box-shadow .15s var(--ease-out), background-color .15s var(--ease-out);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-accent:hover { background: var(--accent-dark); box-shadow: var(--shadow); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: .55rem 1rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-icon { width: 1.1em; height: 1.1em; flex: none; }

/* --- Cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* --- Form --- */
.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field select {
  appearance: none;
  width: 100%;
  padding: .75rem .9rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-family: var(--sans);
  transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: none;
}
.field .hint { font-size: .78rem; color: var(--ink-faint); }
.field .error-msg { font-size: .78rem; color: var(--danger); display: none; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field.has-error .error-msg { display: block; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.6rem; }
.input-suffix .suffix {
  position: absolute; right: .9rem; top: 50%; transform: translateY(-50%);
  color: var(--ink-faint); font-size: .9rem; font-weight: 600; pointer-events: none;
}

.segmented {
  display: inline-flex; padding: .25rem; background: var(--surface-2);
  border-radius: var(--radius-sm); gap: .2rem; width: 100%;
}
.segmented button {
  flex: 1; padding: .55rem .8rem; border-radius: 6px; font-weight: 600; font-size: .88rem;
  color: var(--ink-soft); transition: background-color .15s var(--ease-out), color .15s var(--ease-out);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.checkbox-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .8rem .9rem; border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.checkbox-row input[type="checkbox"] { width: 1.2rem; height: 1.2rem; accent-color: var(--primary); flex: none; }
.checkbox-row label { font-weight: 600; font-size: .92rem; }

.fieldset-extra {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
  margin-top: .9rem;
}
.fieldset-extra.is-open { display: grid; }
@media (max-width: 539px) { .fieldset-extra { grid-template-columns: 1fr; } }

.variable-extra {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
  margin-top: .2rem;
}
.variable-extra.is-open { display: grid; }
@media (max-width: 539px) { .variable-extra { grid-template-columns: 1fr; } }

/* --- Badge / privacy --- */
.badge-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .8rem; font-weight: 600; color: var(--ink-soft);
  background: var(--surface-2); border-radius: 999px; padding: .4rem .8rem;
}
.badge svg { width: 1em; height: 1em; }
.badge.badge-accent { color: var(--accent-dark); background: var(--accent-soft); }

/* --- Tool card --- */
.tool-card { padding: clamp(1.1rem, 3vw, 2rem); }
.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: clamp(1.2rem, 3vw, 2rem);
}
@media (max-width: 959px) { .tool-grid { grid-template-columns: 1fr; } }

.tool-form { display: flex; flex-direction: column; gap: .9rem; }
.tool-form .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
@media (max-width: 539px) { .tool-form .field-row { grid-template-columns: 1fr; } }

.tool-results { display: flex; flex-direction: column; gap: 1.2rem; min-width: 0; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .7rem;
}
@media (min-width: 720px) { .summary-grid { grid-template-columns: repeat(4, 1fr); } }
.summary-item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .85rem .9rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.summary-item .label { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-faint); }
.summary-item .value { font-size: clamp(1.05rem, 2vw, 1.35rem); font-weight: 800; color: var(--primary); }
.summary-item.is-savings { background: var(--accent-soft); }
.summary-item.is-savings .value { color: var(--accent-dark); }
.summary-item .sub { font-size: .74rem; color: var(--ink-faint); }

.savings-banner {
  display: none;
  align-items: center; gap: .8rem;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-sm); padding: .9rem 1.1rem;
}
.savings-banner.is-visible { display: flex; }
.savings-banner svg { width: 1.6rem; height: 1.6rem; flex: none; color: var(--accent-dark); }
.savings-banner strong { color: var(--accent-dark); }

.chart-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; }
.chart-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--ink-soft); }
.legend-item { display: flex; align-items: center; gap: .4rem; }
.legend-dot { width: .7rem; height: .7rem; border-radius: 2px; flex: none; }

.downloads { display: flex; flex-wrap: wrap; gap: .6rem; }

/* --- Amortization table --- */
.table-toolbar { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.amort-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.amort-table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 560px; }
table.amort-table th, table.amort-table td { padding: .65rem .8rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.amort-table th:first-child, table.amort-table td:first-child { text-align: left; }
table.amort-table thead th { background: var(--surface-2); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); position: sticky; top: 0; }
table.amort-table tbody tr.row-year { background: var(--surface); cursor: pointer; font-weight: 700; }
table.amort-table tbody tr.row-year:hover { background: var(--surface-2); }
table.amort-table tbody tr.row-month { background: var(--bg); font-weight: 400; font-size: .85rem; display: none; }
table.amort-table tbody tr.row-month.is-open { display: table-row; }
table.amort-table tbody tr.row-extra td { color: var(--accent-dark); }
.row-year .expand-arrow { display: inline-block; transition: transform .2s var(--ease-out); margin-right: .4rem; }
.row-year.is-expanded .expand-arrow { transform: rotate(90deg); }
.table-note { font-size: .82rem; color: var(--ink-faint); margin-top: .7rem; }

/* --- Ad slots --- */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  border: 1.5px dashed var(--ad-border);
  border-radius: var(--radius-sm);
  background: repeating-linear-gradient(135deg, var(--ad-bg), var(--ad-bg) 10px, var(--surface) 10px, var(--surface) 20px);
  color: var(--ad-ink);
  font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.ad-leaderboard { min-height: 100px; margin-block: 1.2rem; }
.ad-incontent { min-height: 250px; max-width: 336px; margin: 2rem auto; }
.ad-popup { min-height: 250px; margin-block: 1rem; }
.ad-corner { min-height: 90px; width: 100%; }

/* --- Corner toast --- */
.corner-toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  width: min(280px, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .8rem;
  transform: translateY(140%); opacity: 0;
  transition: transform .35s var(--ease-out), opacity .35s var(--ease-out);
}
.corner-toast.is-visible { transform: translateY(0); opacity: 1; }
.corner-toast-head { display: flex; justify-content: flex-end; margin-bottom: .3rem; }
.corner-toast-close { width: 1.6rem; height: 1.6rem; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: var(--ink-faint); }
.corner-toast-close:hover { background: var(--surface-2); }

/* --- Download dialog --- */
dialog.download-dialog {
  border: none; border-radius: var(--radius-lg); padding: 0;
  width: min(420px, calc(100vw - 2rem));
  box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--ink);
}
dialog.download-dialog::backdrop { background: rgba(16, 24, 40, .55); }
.dialog-inner { padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.dialog-head svg { width: 2rem; height: 2rem; color: var(--accent); flex: none; }
.dialog-close { width: 2rem; height: 2rem; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex: none; }
.dialog-close:hover { background: var(--surface-2); }

/* --- FAQ --- */
.faq-list { display: flex; flex-direction: column; gap: .7rem; }
.faq-item { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.faq-item summary {
  list-style: none; cursor: pointer; padding: 1rem 1.2rem; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary .chevron { flex: none; transition: transform .2s var(--ease-out); color: var(--ink-faint); }
.faq-item[open] summary .chevron { transform: rotate(180deg); }
.faq-item .faq-body { padding: 0 1.2rem 1.1rem; color: var(--ink-soft); }

/* --- Use cases --- */
.usecase-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media (max-width: 719px) { .usecase-grid { grid-template-columns: 1fr; } }
.usecase-card { padding: 1.3rem; display: flex; flex-direction: column; gap: .6rem; }
.usecase-card .icon-wrap {
  width: 2.6rem; height: 2.6rem; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.usecase-card .icon-wrap svg { width: 1.4rem; height: 1.4rem; }

/* --- Steps --- */
.steps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
@media (max-width: 819px) { .steps-grid { grid-template-columns: 1fr; } }
.step-card { padding: 1.3rem; position: relative; }
.step-number {
  width: 2.4rem; height: 2.4rem; border-radius: 999px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; margin-bottom: .8rem;
}

/* =============================================================
   6. Sections
   ============================================================= */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; padding-block: .9rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--display); font-weight: 800; font-size: 1.15rem; }
.brand .brand-mark {
  width: 2.1rem; height: 2.1rem; border-radius: 8px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem;
}
.header-nav { display: flex; align-items: center; gap: 1.2rem; font-size: .9rem; font-weight: 600; color: var(--ink-soft); }
.header-nav a:hover { color: var(--primary); }

.hero { padding-block: clamp(2rem, 6vw, 3.2rem) clamp(1.2rem, 3vw, 1.6rem); }
.hero .container { max-width: 900px; text-align: center; }
.hero h1 { margin-bottom: .8rem; }
.hero .text-lede { max-width: 60ch; margin-inline: auto; }

.seo-copy { max-width: 74ch; color: var(--ink-soft); display: flex; flex-direction: column; gap: 1rem; }
.seo-copy h2 { color: var(--ink); }

.site-footer { border-top: 1px solid var(--border); padding-block: 2rem; margin-top: 2rem; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }
.footer-links { display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: .85rem; color: var(--ink-soft); }
.footer-links a:hover { color: var(--primary); }
.footer-note { font-size: .8rem; color: var(--ink-faint); max-width: 60ch; }

/* =============================================================
   7. Effects (kept minimal on purpose — tool pages read as fast, not flashy)
   ============================================================= */
.reveal { opacity: 1; }

/* =============================================================
   8. Responsive fine-tuning
   ============================================================= */
@media (max-width: 539px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .btn { font-size: .9rem; }
}

/* =============================================================
   9. Reduced-motion (only intrusive effects)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .corner-toast { transition: none; }
}

/* =============================================================
   10. Print
   ============================================================= */
@media print {
  .site-header, .site-footer, .ad-slot, .corner-toast, .downloads, .tool-form,
  .savings-banner ~ .btn, .chart-wrap, .table-toolbar .segmented { display: none !important; }
  table.amort-table tbody tr.row-month { display: table-row !important; }
  body { background: #fff; }
}
