/* ============ Tokens ============ */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f4f6;
  --text: #15202b;
  --muted: #5b6875;
  --border: #dde3e8;
  --brand: #0f766e;
  --brand-strong: #0b5e58;
  --brand-soft: #e6f4f2;
  --positive: #15803d;
  --negative: #b91c1c;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  --header-h: 104px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1317;
    --surface: #151d22;
    --surface-2: #1b252b;
    --text: #e6ecef;
    --muted: #96a3ad;
    --border: #2a363d;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #123330;
    --positive: #4ade80;
    --negative: #f87171;
    --focus: #60a5fa;
    --shadow: none;
    color-scheme: dark;
  }
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--surface); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { left: 8px; }

/* ============ Header ============ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; padding-bottom: 8px; }
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none;
}
.brand-icon { width: 28px; height: 28px; color: var(--brand); stroke-width: 2.4; }
.site-nav {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 0 16px;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  flex: none; padding: 6px 9px; border-radius: 999px;
  font-size: .88rem; font-weight: 500; color: var(--muted); text-decoration: none;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }

/* ============ Hero ============ */
.hero { padding: 28px 0 20px; }
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); letter-spacing: -.02em; max-width: 22ch; }
.lead { margin-top: 12px; color: var(--muted); font-size: 1.05rem; max-width: 62ch; }
.tiles {
  list-style: none; margin: 20px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.tiles a {
  display: flex; align-items: center; gap: 10px; height: 100%;
  padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .92rem; line-height: 1.25;
  transition: border-color .15s, transform .15s;
}
.tiles a:hover { border-color: var(--brand); transform: translateY(-1px); }
.tiles .icon { color: var(--brand); width: 22px; height: 22px; }

/* ============ Ads ============ */
.ad {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  margin: 8px 0 24px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.ad::before {
  content: "Advertisement";
  position: absolute; top: 4px; left: 8px;
  font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.ad ins { width: 100%; }
.ad-top { min-height: 100px; }
.ad-mid { min-height: 280px; margin: 0 0 24px; }
.ad-side { min-height: 280px; margin: 0; }

/* ============ Layout ============ */
.layout { display: grid; gap: 24px; padding-bottom: 40px; }
.content { display: grid; gap: 24px; min-width: 0; }
.sidebar { display: grid; gap: 24px; align-content: start; }

/* ============ Calculator card ============ */
.calc {
  scroll-margin-top: calc(var(--header-h) + 12px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
}
.calc.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 3px var(--brand); }
  100% { box-shadow: var(--shadow); }
}
.calc-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.calc-icon {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
}
.calc-icon .icon { width: 22px; height: 22px; }
.calc-head h2 { font-size: 1.3rem; letter-spacing: -.01em; }
.calc-head p { margin-top: 4px; color: var(--muted); font-size: .95rem; }

/* Fields */
.fields { display: grid; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; font-size: .9rem; }
.optional { font-weight: 400; color: var(--muted); }
.hint { color: var(--muted); font-size: .8rem; line-height: 1.35; }

.input-wrap {
  display: flex; align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-wrap.invalid { border-color: var(--negative); }
.affix {
  display: flex; align-items: center; padding: 0 0 0 12px;
  color: var(--muted); font-size: .95rem; user-select: none;
}
.affix[hidden] { display: none; }
.affix-end { padding: 0 12px 0 0; }
.input-wrap input, .input-wrap select {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1rem; /* 16px avoids iOS zoom */
  padding: 11px 12px; outline: none;
  font-variant-numeric: tabular-nums;
}
.input-wrap .affix + input { padding-left: 6px; }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; }
.select-wrap::after {
  content: ""; position: absolute; right: 14px; top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); pointer-events: none;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* Buttons */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 8px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s;
}
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); color: #fff; flex: 1 1 100%; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); flex: 1; }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-text { background: transparent; color: var(--muted); flex: none; }
.btn-text:hover { color: var(--text); }
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #04201d; }
}

/* Results */
.results {
  margin-top: 18px;
  border-radius: 10px;
  background: var(--surface-2);
  padding: 16px;
}
.results:empty { display: none; }
.result-primary { display: flex; flex-direction: column; gap: 2px; }
.result-primary .label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.result-primary .value {
  font-size: clamp(1.9rem, 7vw, 2.4rem); font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--brand);
}
.result-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-top: 14px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; min-width: 0;
}
.stat .label { display: block; font-size: .78rem; color: var(--muted); line-height: 1.3; }
.stat .value {
  display: block; margin-top: 2px; font-weight: 700; font-size: 1.05rem;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.is-pos { color: var(--positive) !important; }
.is-neg { color: var(--negative) !important; }
.result-note { margin-top: 12px; font-size: .9rem; color: var(--muted); }
.result-note strong { color: var(--text); }
.result-msg { color: var(--muted); font-size: .95rem; }
.result-msg.error { color: var(--negative); font-weight: 500; }

/* Margin bar */
.bar { margin-top: 14px; }
.bar-track {
  display: flex; height: 12px; border-radius: 999px; overflow: hidden;
  background: var(--border);
}
.bar-track span { display: block; height: 100%; }
.bar-cost { background: var(--muted); opacity: .55; }
.bar-profit { background: var(--brand); }
.bar-legend { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: .8rem; color: var(--muted); }
.bar-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

/* Amortization table */
.amort { margin-top: 14px; }
.amort summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--brand); }
.table-scroll { overflow-x: auto; margin-top: 10px; }
.amort table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.amort th, .amort td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.amort th:first-child, .amort td:first-child { text-align: left; }
.amort th { color: var(--muted); font-weight: 600; }

/* Formula */
.formula { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.formula summary { cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--muted); }
.formula summary:hover { color: var(--text); }
.formula p { margin-top: 10px; font-size: .9rem; color: var(--muted); }
.formula strong { color: var(--text); font-weight: 600; }

/* Sidebar nav */
.side-nav {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.side-heading { font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.side-nav ul { list-style: none; margin: 0; padding: 0; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem;
}
.side-nav a:hover { background: var(--surface-2); }
.side-nav .icon { color: var(--brand); width: 18px; height: 18px; }

/* ============ Footer ============ */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 32px 0 20px; }
.footer-grid { display: grid; gap: 24px; }
.footer-grid p { margin-top: 10px; color: var(--muted); font-size: .92rem; max-width: 52ch; }
.footer-heading { font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.footer-grid ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.footer-grid ul a { color: var(--text); text-decoration: none; font-size: .95rem; }
.footer-grid ul a:hover { color: var(--brand); text-decoration: underline; }
.footer-bottom {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: .82rem; color: var(--muted);
}

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 100;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: .92rem; font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  max-width: calc(100% - 32px);
}

/* ============ Breakpoints ============ */
@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .fields { grid-template-columns: repeat(2, 1fr); }
  .result-grid { grid-template-columns: repeat(3, 1fr); }
  .btn-primary { flex: 0 1 auto; min-width: 140px; }
  .btn-ghost { flex: 0 1 auto; }
  .calc { padding: 24px; }
  .ad-top { min-height: 90px; }
}

@media (min-width: 768px) {
  :root { --header-h: 64px; }
  .header-inner { flex-direction: row; align-items: center; justify-content: space-between; padding-top: 12px; padding-bottom: 12px; }
  .site-nav { margin: 0; padding: 0; }
  .hero { padding: 44px 0 28px; }
  .footer-grid { grid-template-columns: 1.6fr 1fr 1fr; }
  .footer-bottom { flex-direction: row; justify-content: space-between; }
}

@media (min-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .tiles { grid-template-columns: repeat(6, 1fr); }
  .tiles a { flex-direction: column; align-items: flex-start; }
  .sidebar { position: sticky; top: calc(var(--header-h) + 16px); }
  .ad-side { min-height: 600px; }
}

/* ============ Ads hidden until AdSense loader is enabled ============ */
.no-ads .ad { display: none; }

/* ============ Nav state ============ */
.site-nav a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }

/* ============ Calculator guide links + guides block ============ */
.calc-guide { margin-top: 12px; font-size: .9rem; color: var(--muted); }
.guides {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 16px;
}
.guides h2 { font-size: 1.3rem; }
.guides > p { margin-top: 6px; color: var(--muted); }
.guide-list { margin: 14px 0; padding-left: 1.2em; display: grid; gap: 8px; }
.more-link { font-weight: 600; text-decoration: none; }
.more-link:hover { text-decoration: underline; }

/* ============ Content pages (about, contact, policy, blog) ============ */
a.btn { text-decoration: none; }
.page { padding: 24px 0 48px; }
.page-narrow { max-width: 760px; }
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--brand); }
.page h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); letter-spacing: -.02em; }
.page-intro { margin-top: 12px; color: var(--muted); font-size: 1.05rem; }
.article-meta { margin-top: 10px; color: var(--muted); font-size: .9rem; }

.prose { margin-top: 24px; font-size: 1.05rem; line-height: 1.75; }
.prose > * + * { margin-top: 1em; }
.prose h2 { font-size: 1.4rem; letter-spacing: -.01em; margin-top: 1.8em; }
.prose h3 { font-size: 1.12rem; margin-top: 1.5em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: .4em; }
.prose a { text-underline-offset: 2px; }
.prose strong { font-weight: 650; }
.prose .table-scroll { margin-top: 1em; }
.prose table { width: 100%; border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; }
.prose th, .prose td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.prose th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.prose td.num, .prose th.num { text-align: right; }

.example {
  background: var(--brand-soft);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 16px 18px;
}
.example > * + * { margin-top: .6em; }
.example-label {
  font-size: .75rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--brand);
}

.cta {
  margin-top: 40px; padding: 22px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.cta-title { font-size: 1.2rem; font-weight: 700; }
.cta p + p { margin-top: 6px; color: var(--muted); }
.cta .btn { margin-top: 14px; }
.cta-links { display: flex; flex-wrap: wrap; gap: 8px; }

.related { margin-top: 32px; }
.related-title { font-weight: 700; font-size: 1rem; }
.related ul { margin: 10px 0 0; padding-left: 1.2em; display: grid; gap: 6px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 16px;
}

/* Blog list */
.post-list { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 14px; }
.post-list li {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px;
  transition: border-color .15s;
}
.post-list li:hover { border-color: var(--brand); }
.post-list h2 { font-size: 1.15rem; line-height: 1.3; }
.post-list h2 a { color: var(--text); text-decoration: none; }
.post-list h2 a:hover { color: var(--brand); }
.post-list time { display: block; margin-top: 4px; font-size: .82rem; color: var(--muted); }
.post-list p { margin-top: 6px; color: var(--muted); font-size: .95rem; }

/* Contact form */
.contact-form { display: grid; gap: 16px; margin-top: 24px; }
.input-wrap textarea {
  flex: 1; width: 100%; min-height: 150px; resize: vertical;
  border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1rem; padding: 11px 12px; outline: none;
}
.form-note { font-size: .85rem; color: var(--muted); }
.form-status { font-weight: 500; }
.form-status:empty { display: none; }
.form-status.ok { color: var(--positive); }
.form-status.error { color: var(--negative); }
.contact-form .btn-primary { flex: none; justify-self: start; min-width: 160px; }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

/* 404 */
.notfound { text-align: center; padding: 56px 0 64px; }
.notfound .big { font-size: clamp(4rem, 18vw, 7rem); font-weight: 800; line-height: 1; color: var(--brand); letter-spacing: -.04em; }
.notfound h1 { margin-top: 12px; }
.notfound .page-intro { margin-left: auto; margin-right: auto; max-width: 48ch; }
.notfound .cta-links { justify-content: center; margin-top: 24px; }
.notfound .tiles { max-width: 760px; margin-left: auto; margin-right: auto; text-align: left; }

@media (min-width: 560px) {
  .guides, .card { padding: 24px; }
  .post-list li { padding: 20px 22px; }
}
@media (min-width: 768px) {
  .page { padding: 40px 0 64px; }
}
