:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --text: #1a2233;
  --text-soft: #5a6577;
  --border: #e2e7f0;
  --brand: #2563eb;
  --brand-soft: #dbe6ff;
  --brand-ink: #1d4ed8;
  --principal: #2563eb;
  --interest: #f59e0b;
  --success-bg: #e7f7ee;
  --success-ink: #0f7a45;
  --error: #d92d20;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 8px 24px rgba(20, 30, 60, 0.06);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1040px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0e1320;
  --bg-elev: #171e2e;
  --text: #e8ecf5;
  --text-soft: #98a3b8;
  --border: #283248;
  --brand: #4f86ff;
  --brand-soft: #1e2c4a;
  --brand-ink: #7aa5ff;
  --principal: #4f86ff;
  --interest: #fbbf24;
  --success-bg: #123526;
  --success-ink: #46d999;
  --error: #ff6b60;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320;
    --bg-elev: #171e2e;
    --text: #e8ecf5;
    --text-soft: #98a3b8;
    --border: #283248;
    --brand: #4f86ff;
    --brand-soft: #1e2c4a;
    --brand-ink: #7aa5ff;
    --principal: #4f86ff;
    --interest: #fbbf24;
    --success-bg: #123526;
    --success-ink: #46d999;
    --error: #ff6b60;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* Header */
.site-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { font-size: 22px; }
.brand-name { font-size: 17px; letter-spacing: -0.01em; }
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  width: 40px; height: 40px;
  cursor: pointer;
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: background .15s, transform .1s;
}
.theme-toggle:hover { background: var(--brand-soft); }
.theme-toggle:active { transform: scale(0.94); }

/* Intro */
.intro { padding: 34px 0 8px; }
h1 {
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  line-height: 1.15;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}
.lede { color: var(--text-soft); max-width: 68ch; margin: 0; font-size: 1.02rem; }

/* Layout grid */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  margin: 0 0 18px;
  font-weight: 700;
}

/* Form */
.field { margin-bottom: 16px; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.opt { color: var(--text-soft); font-weight: 400; }

input, select {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235a6577' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-left: 30px; }
.input-wrap .prefix {
  position: absolute;
  left: 12px;
  color: var(--text-soft);
  font-size: 1rem;
  pointer-events: none;
}
.input-wrap .suffix {
  position: absolute;
  right: 12px;
  color: var(--text-soft);
  pointer-events: none;
}
.input-wrap:has(.suffix) input { padding-right: 30px; padding-left: 12px; }

.error {
  color: var(--error);
  font-size: 0.88rem;
  margin: 6px 0 0;
  font-weight: 600;
}

/* Results */
.headline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-ink) 100%);
  color: #fff;
  margin-bottom: 18px;
}
.headline-label { font-size: 0.82rem; opacity: 0.9; font-weight: 600; }
.headline-value { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-label { font-size: 0.78rem; color: var(--text-soft); font-weight: 600; }
.stat-value { font-size: 1.12rem; font-weight: 700; letter-spacing: -0.01em; }

/* Split bar */
.split { margin-top: 18px; }
.split-bar {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}
.split-principal { background: var(--principal); }
.split-interest { background: var(--interest); }
.split-legend {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-soft);
}
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: middle;
}
.dot-principal { background: var(--principal); }
.dot-interest { background: var(--interest); }

/* Savings */
.savings {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--success-bg);
  color: var(--success-ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 600;
}
.savings-icon { font-size: 1.1rem; }
.savings p { margin: 0; }

/* Schedule */
.schedule-card { margin-top: 20px; padding: 0; overflow: hidden; }
details > summary {
  cursor: pointer;
  padding: 20px 22px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  user-select: none;
}
details > summary::-webkit-details-marker { display: none; }
.summary-title { font-weight: 700; font-size: 1.02rem; }
.summary-title::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--brand);
  transition: transform .18s;
}
details[open] .summary-title::before { transform: rotate(90deg); }
.summary-hint { font-size: 0.84rem; color: var(--text-soft); padding-left: 20px; }

.table-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: right;
  padding: 10px 14px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th:nth-child(2) { text-align: left; }
tbody td {
  padding: 9px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody td:nth-child(2) { text-align: left; color: var(--text-soft); }
tbody tr:hover { background: var(--brand-soft); }
tbody tr.year-mark td { border-bottom: 2px solid var(--border); }
.num { width: 48px; }

/* Prose / FAQ */
.prose { margin-top: 20px; }
.prose h2 {
  font-size: 1.2rem;
  margin: 6px 0 10px;
  letter-spacing: -0.01em;
}
.prose h2:not(:first-child) { margin-top: 26px; }
.prose p { color: var(--text-soft); margin: 0 0 12px; }
.prose code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.86em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: var(--bg);
}
.faq summary {
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  position: relative;
  padding-right: 40px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--brand);
}
.faq details[open] summary::after { content: "–"; }
.faq details p { padding: 0 16px 14px; margin: 0; }
.disclaimer { font-size: 0.84rem; font-style: italic; }

/* Footer */
.site-footer {
  text-align: center;
  padding: 30px 20px 40px;
  color: var(--text-soft);
  font-size: 0.9rem;
}
.site-footer a { color: var(--brand-ink); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

@media (max-width: 460px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .stats { grid-template-columns: 1fr; }
  .headline-value { font-size: 1.7rem; }
}
