/* Unlocking the Mortgage Code — site styles
   Concept: Canadian bank paperwork. Cheque-paper green, ledger ink, statement forms. */

:root {
  --paper: #f4f7f3;          /* page: pale cheque paper */
  --sheet: #ffffff;          /* forms and cards */
  --tint: #e3ede5;           /* security-paper green */
  --rule: #c3d1c7;           /* ledger lines */
  --ink: #17243a;            /* body text, navy ledger ink */
  --ink-soft: #4a586b;       /* secondary text */
  --teal: #1d5c73;           /* links and actions */
  --teal-deep: #134557;
  --stamp: #a3231b;          /* stamps and warnings, used sparingly */
  --gold: #8a6a12;           /* decoder notes */
  --gold-tint: #f6efd8;

  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;

  --measure: 68ch;
  --radius-form: 3px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-variant-numeric: lining-nums;
}

img { max-width: 100%; height: auto; }

a { color: var(--teal); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--teal-deep); text-decoration-thickness: 2px; }

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

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: #fff; padding: 0.5rem 1rem; z-index: 10;
  font-family: var(--sans);
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------- Header ---------- */

.site-header {
  background: var(--sheet);
  border-bottom: 1px solid var(--rule);
}
.site-header .inner {
  max-width: 72rem; margin: 0 auto; padding: 0.9rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 2rem;
  justify-content: space-between;
}
.brand {
  font-family: var(--sans); font-weight: 800; font-size: 1.05rem;
  color: var(--ink); text-decoration: none; letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 0.55rem;
}
.brand-mark {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 2px solid var(--ink); font-size: 0.95rem; line-height: 1;
}
.brand small { display: block; font-weight: 500; font-size: 0.78rem; color: var(--ink-soft); letter-spacing: 0; }

.site-nav ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem;
  font-family: var(--sans); font-size: 0.95rem; font-weight: 600;
}
.site-nav a { color: var(--ink); text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.site-nav a:hover { border-bottom-color: var(--rule); }
.site-nav a[aria-current="page"] { border-bottom-color: var(--teal); color: var(--teal-deep); }

/* ---------- Layout ---------- */

main { display: block; }

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }

.page-head { padding: 3rem 0 1.5rem; }
.page-head .wrap > * { max-width: var(--measure); }

.crumbs {
  font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft);
  margin: 0 0 1rem;
}
.crumbs a { color: var(--ink-soft); }

h1, h2, h3, h4 { font-family: var(--sans); line-height: 1.2; letter-spacing: -0.015em; color: var(--ink); }
h1 { font-size: clamp(2rem, 4.5vw, 3rem); font-weight: 800; margin: 0 0 1rem; }
h2 { font-size: clamp(1.45rem, 2.6vw, 1.85rem); font-weight: 750; margin: 2.75rem 0 0.75rem; }
h3 { font-size: 1.2rem; font-weight: 700; margin: 2rem 0 0.5rem; }

.lede { font-size: 1.28rem; line-height: 1.55; color: var(--ink); margin: 0 0 1rem; }

.meta {
  font-family: var(--sans); font-size: 0.88rem; color: var(--ink-soft);
  margin: 0;
}

.prose { max-width: var(--measure); padding-bottom: 3rem; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1rem; }
.prose li { margin-bottom: 0.4rem; }
.prose li::marker { color: var(--ink-soft); }
.prose strong { font-weight: 650; }
.prose h2:first-child { margin-top: 0; }

.two-col {
  display: grid; gap: 2.5rem;
  grid-template-columns: minmax(0, 1fr);
  padding-bottom: 2rem;
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; border: 1px solid var(--rule); background: var(--sheet); }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { background: var(--tint); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* ---------- Callouts ---------- */

.decoder {
  background: var(--gold-tint);
  border-left: 4px solid var(--gold);
  padding: 1rem 1.2rem; margin: 1.5rem 0;
  font-size: 1.02rem;
}
.decoder > :last-child { margin-bottom: 0; }
.decoder-title { font-family: var(--sans); font-weight: 750; color: var(--gold); margin: 0 0 0.3rem; font-size: 0.95rem; }

.warning {
  border-left: 4px solid var(--stamp);
  background: #fbeeed;
  padding: 1rem 1.2rem; margin: 1.5rem 0;
}
.warning > :last-child { margin-bottom: 0; }

.example {
  background: var(--sheet); border: 1px solid var(--rule);
  padding: 1.1rem 1.25rem; margin: 1.5rem 0;
}
.example > :last-child { margin-bottom: 0; }
.example-title { font-family: var(--sans); font-weight: 750; margin: 0 0 0.4rem; font-size: 1rem; }

.formula {
  font-family: var(--sans); font-variant-numeric: tabular-nums;
  background: var(--sheet); border: 1px dashed var(--rule);
  padding: 0.8rem 1rem; margin: 1.2rem 0; overflow-x: auto;
  font-size: 1rem; white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-block; font-family: var(--sans); font-weight: 700; font-size: 1rem;
  background: var(--teal); color: #fff; text-decoration: none;
  padding: 0.75rem 1.25rem; border: 2px solid var(--teal); border-radius: var(--radius-form);
  cursor: pointer;
}
.btn:hover { background: var(--teal-deep); border-color: var(--teal-deep); color: #fff; }
.btn-quiet { background: transparent; color: var(--teal); }
.btn-quiet:hover { background: var(--tint); color: var(--teal-deep); }

/* ---------- The statement form (calculators) ---------- */

.statement {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-form);
  box-shadow: 0 1px 0 var(--rule), 0 14px 30px -22px rgba(23, 36, 58, 0.45);
  margin: 0 0 2.5rem;
  overflow: hidden;
}
.statement-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.25rem 1rem;
  padding: 0.9rem 1.25rem;
  font-family: var(--sans);
  background-color: var(--tint);
  /* security-paper weave */
  background-image:
    repeating-linear-gradient(45deg, rgba(29, 92, 115, 0.07) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(-45deg, rgba(29, 92, 115, 0.07) 0 1px, transparent 1px 7px);
  border-bottom: 1px solid var(--rule);
}
.statement-head h2 { margin: 0; font-size: 1.15rem; }
.form-no { font-size: 0.82rem; color: var(--ink-soft); font-weight: 600; }

.statement-body {
  display: grid; gap: 0;
  grid-template-columns: minmax(0, 1fr);
}
.fields { padding: 1.25rem; display: grid; gap: 1rem; align-content: start; }
.results { padding: 1.25rem; border-top: 1px dashed var(--rule); background: #fbfcfa; }

.field label { display: block; font-family: var(--sans); font-weight: 650; font-size: 0.95rem; margin-bottom: 0.3rem; }
.field .hint { display: block; font-family: var(--sans); font-size: 0.82rem; color: var(--ink-soft); margin-top: 0.25rem; line-height: 1.4; }
.input-row { display: flex; align-items: stretch; border: 1px solid var(--rule); border-radius: var(--radius-form); background: #fff; }
.input-row:focus-within { outline: 3px solid var(--teal); outline-offset: 1px; }
.input-row .unit { font-family: var(--sans); color: var(--ink-soft); padding: 0.55rem 0.7rem; background: var(--paper); display: grid; place-items: center; }
.input-row input, .input-row select, .field select {
  flex: 1; min-width: 0; border: 0; background: transparent;
  font-family: var(--sans); font-size: 1.05rem; color: var(--ink);
  padding: 0.55rem 0.7rem; font-variant-numeric: tabular-nums;
}
.field select { border: 1px solid var(--rule); border-radius: var(--radius-form); background: #fff; width: 100%; }
.input-row input:focus, .input-row select:focus { outline: none; }
.field select:focus { outline: 3px solid var(--teal); outline-offset: 1px; }

.radio-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; font-family: var(--sans); font-size: 0.95rem; }
.radio-row label { font-weight: 500; display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }

.ledger { margin: 0; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.ledger div {
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  padding: 0.5rem 0; border-bottom: 1px solid var(--rule);
}
.ledger dt { color: var(--ink-soft); font-size: 0.95rem; }
.ledger dd { margin: 0; font-weight: 700; font-size: 1.05rem; text-align: right; }
.ledger .total dt { color: var(--ink); font-weight: 700; }
.ledger .total dd { font-size: 1.6rem; font-weight: 800; color: var(--teal-deep); }
.ledger .good dd { color: #1f6b3a; }
.ledger .bad dd { color: var(--stamp); }

.fine { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); margin: 0.8rem 0 0; line-height: 1.45; }
.calc-note { font-family: var(--sans); font-size: 0.9rem; margin: 0.9rem 0 0; padding: 0.6rem 0.8rem; background: var(--tint); border-radius: var(--radius-form); }
.calc-note:empty { display: none; }
.calc-note.alert { background: #fbeeed; color: var(--stamp); }

.compare {
  display: grid; gap: 0.75rem; grid-template-columns: minmax(0, 1fr);
  padding: 1.25rem; border-top: 1px solid var(--rule);
  font-family: var(--sans);
}
.compare-card { border: 1px solid var(--rule); border-radius: var(--radius-form); padding: 0.9rem 1rem; background: #fff; }
.compare-card h3 { margin: 0 0 0.15rem; font-size: 1rem; }
.compare-card .amt { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; margin: 0.2rem 0; }
.compare-card p { margin: 0; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.45; }
.compare-card.winner { border: 2px solid var(--teal); position: relative; }
.compare-card .tag { font-size: 0.8rem; font-weight: 700; color: var(--teal-deep); }

.stamp {
  display: inline-block; font-family: var(--sans); font-weight: 800;
  color: var(--stamp); border: 3px double var(--stamp); border-radius: 4px;
  padding: 0.1rem 0.6rem; transform: rotate(-4deg); letter-spacing: 0.06em;
}

/* ---------- Home ---------- */

.hero { padding: 3.25rem 0 2rem; border-bottom: 1px solid var(--rule); background: var(--sheet); }
.hero .wrap { display: grid; gap: 2rem; grid-template-columns: minmax(0, 1fr); align-items: center; }
.hero h1 { font-size: clamp(2.2rem, 5.5vw, 3.6rem); max-width: 16ch; }
.hero .lede { max-width: 54ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

.mini-statement { font-family: var(--sans); }
.mini-statement .statement { margin: 0; }
.mini-statement .ledger { padding: 0.5rem 1.25rem 1.1rem; }

.section { padding: 3rem 0 1rem; }
.section > .wrap > h2:first-child { margin-top: 0; }
.section-intro { max-width: var(--measure); margin: 0 0 1.5rem; }

.tool-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; grid-template-columns: minmax(0, 1fr); border-top: 2px solid var(--ink); }
.tool-list li { border-bottom: 1px solid var(--rule); }
.tool-list a {
  display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: 0.25rem 1rem;
  padding: 1.1rem 0.25rem; text-decoration: none; color: var(--ink);
}
.tool-list a:hover { background: var(--sheet); }
.tool-list .code { font-family: var(--sans); font-weight: 700; font-size: 0.85rem; color: var(--ink-soft); padding-top: 0.2rem; }
.tool-list .t { font-family: var(--sans); font-weight: 750; font-size: 1.15rem; color: var(--teal-deep); }
.tool-list .d { grid-column: 2; font-size: 1rem; color: var(--ink-soft); line-height: 1.5; }

.guide-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.5rem 2.5rem; grid-template-columns: minmax(0, 1fr); }
.guide-list li { border-top: 1px solid var(--rule); padding-top: 1rem; }
.guide-list a.title { font-family: var(--sans); font-weight: 750; font-size: 1.15rem; text-decoration: none; color: var(--ink); }
.guide-list a.title:hover { color: var(--teal); text-decoration: underline; }
.guide-list p { margin: 0.35rem 0 0; font-size: 1rem; color: var(--ink-soft); line-height: 1.5; }

.book-band { background: var(--ink); color: #eef3f0; padding: 2.5rem 0; margin-top: 3rem; }
.book-band h2 { color: #fff; margin-top: 0; }
.book-band p { max-width: var(--measure); }
.book-band .btn { background: #fff; color: var(--ink); border-color: #fff; }
.book-band .btn:hover { background: var(--tint); }

/* ---------- Related / next steps ---------- */

.related { border-top: 2px solid var(--ink); padding-top: 1rem; margin-top: 2.5rem; }
.related h2 { margin-top: 0; font-size: 1.2rem; }
.related ul { padding-left: 1.1rem; }

.author-box {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.25rem;
  border: 1px solid var(--rule); background: var(--sheet); padding: 1rem 1.2rem; margin: 2.5rem 0 0;
  font-size: 1rem;
}
.author-box strong { font-family: var(--sans); }

/* ---------- Worksheets & signup ---------- */

.sheet-list { list-style: none; padding: 0; margin: 0 0 1.5rem; border-top: 2px solid var(--ink); }
.sheet-list li { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); gap: 0.2rem 1rem; padding: 0.9rem 0; border-bottom: 1px solid var(--rule); }
.sheet-list .code { font-family: var(--sans); font-weight: 750; color: var(--ink-soft); }
.sheet-list a { font-family: var(--sans); font-weight: 700; }
.sheet-list p { grid-column: 2; margin: 0; font-size: 1rem; color: var(--ink-soft); line-height: 1.5; }

.signup .fields { gap: 0.9rem; }
.signup input[type="text"], .signup input[type="email"] {
  width: 100%; font-family: var(--sans); font-size: 1.05rem; padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule); border-radius: var(--radius-form); background: #fff; color: var(--ink);
}
.consent { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.6rem; align-items: start; font-family: var(--sans); font-size: 0.92rem; line-height: 1.45; }
.consent input { margin-top: 0.2rem; width: 1.1rem; height: 1.1rem; }
.consent-fine { font-family: var(--sans); font-size: 0.82rem; color: var(--ink-soft); line-height: 1.5; margin: 0; }
.form-status { font-family: var(--sans); font-size: 0.95rem; margin: 0; }
.form-status.ok { color: #1f6b3a; font-weight: 650; }
.form-status.err { color: var(--stamp); font-weight: 650; }

/* ---------- Footer ---------- */

.site-footer { background: var(--sheet); border-top: 1px solid var(--rule); margin-top: 3rem; font-family: var(--sans); font-size: 0.9rem; color: var(--ink-soft); }
.site-footer .inner { max-width: 72rem; margin: 0 auto; padding: 2rem 1rem 2.5rem; display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); }
.site-footer h2 { font-size: 0.95rem; margin: 0 0 0.5rem; color: var(--ink); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--teal); }
.site-footer .legal { grid-column: 1 / -1; border-top: 1px solid var(--rule); padding-top: 1rem; line-height: 1.55; }
.site-footer .legal p { margin: 0 0 0.5rem; max-width: 90ch; }

/* ---------- Breakpoints ---------- */

@media (min-width: 720px) {
  .statement-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .results { border-top: 0; border-left: 1px dashed var(--rule); }
  .compare { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .compare.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-footer .inner { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .author-box { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 960px) {
  .hero .wrap { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
  .two-col { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); align-items: start; }
  .two-col > .statement { position: sticky; top: 1.5rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .stamp-in { animation: stamp-in 380ms cubic-bezier(.2,.9,.3,1.3) both; }
  @keyframes stamp-in { from { opacity: 0; transform: rotate(-4deg) scale(1.6); } to { opacity: 1; transform: rotate(-4deg) scale(1); } }
}

@media print {
  .site-header, .site-footer, .book-band, .hero-actions { display: none; }
  body { background: #fff; }
}

/* Book band sits flush against the footer on the home page */
main:has(> .book-band:last-child) + .site-footer { margin-top: 0; }
