/* ============================================================================
   Design system.
   ============================================================================
   Rewritten 2026-11-03 after Felix's note: 「你和原站完全没法比 UI……这也是重点」.
   He was right. The first version was a readable technical document — clear prose,
   a working tool, no product. What was missing, measured against the site we are
   modelling:

     · a real header (mark, search, category nav, CTA) instead of a text brand
     · a THREE-COLUMN layout: contents / content + floating tool card / sidebar
     · the tool as a sticky card with its own sections, not an inline form
     · results written as SENTENCES with the label bolded, not a label/value grid
     · a chart
     · a table of contents built from the page's own headings
     · typography with hierarchy — a large display H1, generous spacing

   Everything below is hand-written CSS. No framework, no build step, no
   dependency — the whole site is ~4 KB of CSS and that is a feature, not a
   limitation: it cannot break because someone else shipped a major version.
   ========================================================================= */

:root {
  /* Brand. One accent, used sparingly — for links, the active nav item, the
     unit selector inside inputs, and the primary result. */
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff4ff;

  --ink: #16181d;
  --ink-2: #3d434d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;

  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --card: #ffffff;

  /* The interest segment in every chart. Warm, to read against the brand blue
     as "the part that is not your money". */
  --interest: #f97316;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lift: 0 2px 4px rgba(16, 24, 40, .05), 0 12px 32px rgba(16, 24, 40, .09);

  --max: 1280px;
  --content: 46rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* The soft wash behind the header, which is what makes the top of the page read
   as a product rather than a document. */
.page-wash {
  background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 42%, var(--bg) 100%);
  border-bottom: 1px solid var(--line);
}

/* ---------------------------------------------------------------- header -- */

.site-header { max-width: var(--max); margin: 0 auto; padding: 0 1.25rem; }

.header-top {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .85rem 0;
}

.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand-mark { width: 28px; height: 28px; flex: none; display: block; }
.brand em { font-style: normal; color: var(--brand); }

.header-search {
  flex: 1 1 auto; max-width: 34rem;
  display: flex; align-items: center; gap: .5rem;
  background: #fff; border: 1px solid var(--line-strong);
  border-radius: 999px; padding: .5rem 1rem;
  color: var(--muted); font-size: .95rem;
}
.header-search input {
  border: 0; outline: 0; font: inherit; flex: 1; background: transparent; color: var(--ink);
}
.header-search svg { flex: none; }

.header-links { display: flex; align-items: center; gap: 1.1rem; font-size: .95rem; }
.header-links a { color: var(--ink-2); text-decoration: none; }
.header-links a:hover { color: var(--brand); }

/* Category nav. On a page whose subject is finance, Finance is marked — the
   same orientation cue the original site gives. */
.cat-nav {
  display: flex; gap: 1.35rem; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid transparent;
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav a {
  padding: .6rem 0; font-size: .93rem; color: var(--ink-2);
  text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.cat-nav a:hover { color: var(--brand); }
.cat-nav a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------------------------------------------------------------- layout -- */

.shell {
  max-width: var(--max); margin: 0 auto; padding: 2rem 1.25rem 4rem;
  display: grid; gap: 2.5rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1040px) {
  .shell { grid-template-columns: 15rem minmax(0, 1fr) 20rem; align-items: start; }
  .shell.no-toc { grid-template-columns: minmax(0, 1fr) 20rem; }
}
@media (min-width: 1400px) {
  .shell { grid-template-columns: 16rem minmax(0, 1fr) 22rem; }
}

.col-main { min-width: 0; max-width: var(--content); }

/* ------------------------------------------------------------- contents -- */

.toc { position: sticky; top: 1.5rem; font-size: .9rem; display: none; }
@media (min-width: 1040px) { .toc { display: block; } }
.toc h2 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 .7rem; font-weight: 700;
}
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc li { margin: 0; }
.toc a {
  display: block; padding: .32rem 0 .32rem .8rem; margin-left: -2px;
  color: var(--ink-2); text-decoration: none; border-left: 2px solid transparent;
  line-height: 1.4;
}
.toc a:hover { color: var(--brand); border-left-color: var(--brand); }

/* ------------------------------------------------------------ titleblock -- */

.meta-line { font-size: .82rem; color: var(--muted); margin: 0 0 .5rem; }
h1 {
  font-size: clamp(1.85rem, 4.2vw, 2.6rem); line-height: 1.14;
  letter-spacing: -.025em; font-weight: 800; margin: 0 0 1rem; max-width: 20ch;
}
.byline {
  display: flex; flex-wrap: wrap; gap: .4rem 1.5rem;
  font-size: .86rem; color: var(--muted); margin: 0 0 1.75rem;
  padding-bottom: 1.25rem; border-bottom: 1px solid var(--line);
}
.byline b { color: var(--ink-2); font-weight: 600; }

/* ------------------------------------------------------------------ tool -- */

.tool {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 0 2rem;
  overflow: hidden;
}
/* On wide screens the tool becomes the floating right-hand card. It is the same
   markup in both cases — only the placement changes, so there is one code path
   and no risk of the mobile and desktop tools drifting apart. */
@media (min-width: 1040px) {
  .tool {
    grid-column: 3; grid-row: 1 / span 20;
    position: sticky; top: 1.5rem; margin: 0;
    box-shadow: var(--shadow-lift);
    max-height: calc(100vh - 3rem); overflow-y: auto;
  }
}

.tool-section { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.tool-section:last-child { border-bottom: 0; }
.tool-section > h2 {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin: 0 0 .9rem;
}
/* The results block sits at the top of the card and stays there while the
   inputs scroll under it — the answer is what the visitor came for, so it is
   the one thing that must never be scrolled out of view. */
.tool-results { position: sticky; top: 0; background: var(--card); z-index: 2; border-bottom: 1px solid var(--line); }
@media (max-width: 1039px) { .tool-results { position: static; } }

.inputs { display: grid; gap: 1rem; }

.field { display: grid; gap: .35rem; }
.field label {
  font-size: .88rem; font-weight: 600; color: var(--ink-2);
  display: flex; align-items: center; gap: .3rem;
}
.field-row {
  display: flex; align-items: stretch;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
}
.field-row:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field-row input, .field-row select {
  font: inherit; border: 0; outline: 0; background: transparent;
  padding: .62rem .8rem; width: 100%; min-width: 0; color: var(--ink);
}
.field-row input {
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.02rem;
  text-align: right; padding-right: .4rem;
}
.field-row select { text-align: left; cursor: pointer; font-size: .95rem; }
.field-unit {
  display: flex; align-items: center; padding: 0 .8rem 0 .1rem;
  color: var(--brand); font-weight: 600; font-size: .92rem; white-space: nowrap;
}
.field-help { font-size: .79rem; color: var(--muted); line-height: 1.45; margin: 0; }

/* Results as SENTENCES. This is the single biggest readability change over the
   label/value grid the first version used: "The final balance is $18,193.97"
   reads as an answer, where "Final balance | $18,193.97" reads as a table row. */
.results { display: grid; gap: .55rem; }
.results p { margin: 0; font-size: .98rem; line-height: 1.5; color: var(--ink-2); }
.results b { color: var(--ink); font-weight: 600; }
.results .headline {
  font-size: 1.5rem; font-weight: 800; color: var(--brand);
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.2;
  display: block; margin-top: .1rem;
}
.tool-note { font-size: .76rem; color: var(--muted); margin: .9rem 0 0; }

/* ----------------------------------------------------------------- chart -- */

.chart { margin: 0; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: .35rem 1.1rem;
  font-size: .78rem; color: var(--muted); margin-top: .6rem;
}
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* ---------------------------------------------------------------- content -- */

main section { margin: 0 0 2rem; }
h2 {
  font-size: 1.4rem; line-height: 1.3; letter-spacing: -.015em;
  font-weight: 700; margin: 2.5rem 0 .75rem;
}
h3 { font-size: 1.08rem; font-weight: 700; margin: 1.6rem 0 .4rem; }
p { margin: .7rem 0; color: var(--ink-2); }
a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-dark); }

.lede { font-size: 1.09rem; color: var(--ink-2); }

/* The formula block — set apart, monospaced, with its symbol table. */
.formula {
  background: var(--brand-soft); border: 1px solid #dbe6fe;
  border-radius: var(--radius); padding: 1.25rem 1.4rem; margin: 1.5rem 0;
}
.formula h2 { margin-top: 0; font-size: 1.05rem; }
.formula-expr { overflow-x: auto; margin: .5rem 0 0; }
.formula-expr code {
  font-family: var(--mono); font-size: .96rem; white-space: nowrap;
  background: #fff; padding: .55rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid #dbe6fe; display: inline-block; color: var(--ink);
}
.legend { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .9rem 0 0; }
.legend dt { font-family: var(--mono); font-weight: 700; font-size: .92rem; }
.legend dd { margin: 0; color: var(--ink-2); font-size: .93rem; }

/* Worked examples as distinct blocks, so the eye can find them. */
.examples article {
  border-left: 3px solid var(--brand); padding: .1rem 0 .1rem 1.1rem; margin: 1.4rem 0;
}
.examples h3 { margin-top: 0; }

/* ---------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; margin: 1.25rem 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
caption { text-align: left; font-size: .85rem; color: var(--muted); padding: .9rem 1rem 0; }
th, td { padding: .55rem .9rem; border-bottom: 1px solid var(--line); text-align: right; }
thead th {
  border-bottom: 1px solid var(--line-strong); font-size: .74rem;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; background: var(--bg-soft);
}
th[scope="col"]:first-child, tbody th { text-align: left; }
tbody th { font-weight: 600; color: var(--ink-2); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:nth-child(even) { background: #fcfcfd; }
td { font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ------------------------------------------------------------- edge, faq -- */

.edge dl { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: .6rem 1.2rem; margin: 0; }
.edge dt { font-weight: 600; color: var(--ink); font-size: .94rem; }
.edge dd { margin: 0; color: var(--ink-2); font-size: .94rem; }

.faq-item { border-top: 1px solid var(--line); padding-top: .3rem; margin-top: 1.1rem; }
.faq-item h3 { margin-bottom: .3rem; }

/* ---------------------------------------------------------------- related -- */

.related ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
@media (min-width: 720px) { .related ul { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.related li {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .8rem .95rem; background: var(--card);
}
.related li:hover { border-color: var(--brand); }
.related a { font-weight: 600; text-decoration: none; }
.related a:hover { text-decoration: underline; }
.related .why { display: block; color: var(--muted); font-size: .84rem; margin-top: .25rem; line-height: 1.45; }

.sources ul { padding-left: 1.1rem; font-size: .9rem; }
.sources li { margin: .35rem 0; }

/* ---------------------------------------------------------------- footer -- */

.site-footer { border-top: 1px solid var(--line); background: var(--bg-soft); margin-top: 3rem; }
.site-footer .inner {
  max-width: var(--max); margin: 0 auto; padding: 1.75rem 1.25rem;
  color: var(--muted); font-size: .85rem;
}
.site-footer p { margin: 0; color: var(--muted); }

/* ------------------------------------------------------------ index pages -- */

.card-grid { list-style: none; padding: 0; margin: 1.25rem 0; display: grid; gap: .9rem; }
@media (min-width: 720px) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.card-grid li {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; background: var(--card); box-shadow: var(--shadow);
}
.card-grid li:hover { border-color: var(--brand); }
.card-grid a { font-weight: 700; text-decoration: none; font-size: 1.02rem; }
.card-grid a:hover { text-decoration: underline; }
.card-grid .desc { color: var(--muted); font-size: .88rem; margin: .35rem 0 0; line-height: 1.5; }

/* ------------------------------------------------------------ a11y, print -- */

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media print {
  .site-header, .site-footer, .toc, .tool-note, .header-search, .header-links, .cat-nav { display: none; }
  .shell { display: block; padding: 0; max-width: none; }
  .col-main { max-width: none; }
  .tool { border: 1px solid #ccc; box-shadow: none; position: static; margin-bottom: 1.5rem; }
  body { font-size: 10.5pt; }
  a { color: inherit; text-decoration: none; }
  .formula, .table-wrap, .examples article { break-inside: avoid; }
  tr { break-inside: avoid; }
}

/* The "never clears" warning. Amber rather than red: this is a fact about the
   payment, not an error the visitor made, and the line under it tells them what
   to change. */
.tool-warning {
  margin: .2rem 0 0; padding: .6rem .75rem;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius-sm);
  font-size: .86rem; line-height: 1.5; color: #7c2d12;
}

/* The plan-type control sits INSIDE the results block, above the figure it
   changes — see the note in renderTool(). An input that qualifies a number has
   to come before the number, or it is decoration. */
.results-inputs { margin-bottom: .9rem; padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.results-inputs .field-help { font-size: .76rem; }

/* The alternative scenario, stated beside the headline rather than below the
   fold. Sober styling on purpose: this is a qualification, not a callout. */
.companion { margin: .1rem 0 0; font-size: .88rem; color: var(--ink-2); }
.companion b { font-variant-numeric: tabular-nums; }
