/* ——— The Finvest Personal Finance Guide ——— */

:root {
  --blue: #2945e3;          /* Finvest royal blue */
  --blue-deep: #1d33b8;
  --blue-soft: rgba(41, 69, 227, 0.08);
  --sky: #38a3f5;           /* accent for italic highlight words */
  --card: #eef3fc;          /* soft blue panel */
  --paper: #ffffff;
  --ink: #11151f;
  --ink-soft: #4a5163;
  --ink-faint: #8a90a3;
  --line: #e4e8f3;
  --red: #e5484d;
  --red-soft: rgba(229, 72, 77, 0.09);
  --green: #18a05c;
  --green-soft: rgba(24, 160, 92, 0.10);
  --code-bg: #131a2e;
  --code-ink: #dde4f5;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
  --content-w: 740px;
  --sidebar-w: 296px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ——— progress bar ——— */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: var(--blue); z-index: 60; transition: width .1s linear;
}

/* ——— layout ——— */
#layout { display: flex; min-height: 100vh; }

/* ——— sidebar ——— */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 28px 22px 40px;
}
#sidebar .brand {
  display: block; text-decoration: none; color: var(--ink);
  font-family: var(--serif); font-weight: 600; font-size: 21px;
  line-height: 1.2; margin-bottom: 3px;
}
#sidebar .brand .fv { color: var(--blue); }
#sidebar .brand-sub {
  font-size: 11px; color: var(--ink-faint); letter-spacing: .05em;
  text-transform: uppercase; margin-bottom: 24px; font-weight: 600;
}
#sidebar .part {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); margin: 20px 0 7px; font-weight: 700;
}
#sidebar a.ch {
  display: flex; gap: 9px; align-items: baseline;
  padding: 5px 9px; margin: 0 -9px; border-radius: 8px;
  text-decoration: none; color: var(--ink-soft);
  font-size: 13px; line-height: 1.35;
}
#sidebar a.ch .n {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint);
  flex: 0 0 20px; text-align: right;
}
#sidebar a.ch:hover { background: var(--card); color: var(--ink); }
#sidebar a.ch.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
#sidebar a.ch.active .n { color: var(--blue); }

/* ——— mobile top bar ——— */
#topbar {
  display: none; position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  align-items: center; justify-content: space-between;
}
#topbar .t { font-family: var(--serif); font-weight: 600; font-size: 17px; }
#topbar .t .fv { color: var(--blue); }
#menu-btn {
  font-family: var(--sans); font-size: 13px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; padding: 7px 13px; cursor: pointer;
  color: var(--ink-soft);
}

/* ——— main column ——— */
#main { flex: 1; min-width: 0; }
#content {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 52px 36px 80px;
}

/* ——— typography ——— */
#content h1 {
  font-family: var(--serif); font-size: 42px; line-height: 1.1;
  font-weight: 600; letter-spacing: -0.01em; margin: 6px 0 10px;
}
#content h2 {
  font-family: var(--serif); font-size: 27px; font-weight: 600;
  line-height: 1.25; margin: 44px 0 14px;
}
#content h3 { font-size: 19px; font-weight: 650; margin: 32px 0 10px; }
#content h4 { font-size: 16px; font-weight: 650; margin: 0 0 6px; }
#content p { margin: 0 0 17px; }
#content a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 2.5px; }
#content strong { font-weight: 650; }
#content em { font-style: italic; }
#content ul, #content ol { padding-left: 24px; margin: 0 0 17px; }
#content li { margin-bottom: 7px; }
#content hr { border: 0; border-top: 1px solid var(--line); margin: 38px 0; }

.ch-kicker {
  font-size: 11.5px; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--blue); margin-bottom: 4px;
}
.ch-meta {
  font-size: 13px; color: var(--ink-faint);
  margin-bottom: 34px; padding-bottom: 20px; border-bottom: 1px solid var(--line);
}

/* ——— key takeaways (blockquote) ——— */
#content blockquote {
  margin: 32px 0; padding: 20px 26px;
  background: var(--blue-soft);
  border-left: 3px solid var(--blue);
  border-radius: 0 14px 14px 0;
  font-size: 15.5px;
}
#content blockquote p { margin-bottom: 9px; }
#content blockquote p:last-child, #content blockquote ul:last-child { margin-bottom: 0; }

/* ——— tables ——— */
#content table {
  width: 100%; border-collapse: collapse; margin: 24px 0;
  font-size: 14px; line-height: 1.55;
}
#content th {
  text-align: left; font-weight: 650; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft);
  border-bottom: 2px solid var(--blue); padding: 8px 12px 8px 0;
}
#content td { border-bottom: 1px solid var(--line); padding: 9px 12px 9px 0; vertical-align: top; }

/* ——— code ——— */
#content code {
  font-family: var(--mono); font-size: .85em;
  background: var(--card); border-radius: 5px; padding: 2px 6px;
}
#content pre {
  background: var(--code-bg); color: var(--code-ink);
  border-radius: 12px; padding: 18px 22px; overflow-x: auto;
  margin: 24px 0; font-size: 13.5px; line-height: 1.55;
}
#content pre code { background: none; padding: 0; font-size: inherit; color: inherit; }

/* ——— math ——— */
.katex-display { margin: 24px 0 !important; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.katex { font-size: 1.05em; }
span.math-display { display: block; text-align: center; }

/* ——— Finvest components ——— */

/* eyebrow labels */
.eyebrow {
  font-size: 10.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; margin-bottom: 8px; color: var(--blue);
}
.eyebrow.green { color: var(--green); }
.eyebrow.red { color: var(--red); }
.eyebrow.gray { color: var(--ink-faint); }
.eyebrow.blue { color: var(--blue); }

/* soft blue cards */
.card {
  background: var(--card); border-radius: 16px;
  padding: 22px 24px; margin: 22px 0;
}
.card p { margin-bottom: 10px; font-size: 15px; color: var(--ink-soft); }
.card p:last-child { margin-bottom: 0; }
.card h4 { color: var(--ink); }
.card ul { margin: 0; padding-left: 20px; }
.card li { font-size: 14.5px; color: var(--ink-soft); margin-bottom: 8px; }
.card.checklist li { list-style: none; position: relative; padding-left: 8px; }
.card.checklist ul { padding-left: 18px; }
.card.checklist li::before {
  content: "✓"; position: absolute; left: -16px; color: var(--blue);
  font-weight: 700;
}

/* big stat displays */
.statgrid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 26px 0;
}
.stat {
  background: var(--card); border-radius: 16px; padding: 22px 24px;
}
.statgrid .stat { margin: 0; }
.stat .num {
  font-family: var(--serif); font-weight: 600; font-size: 52px;
  line-height: 1.05; letter-spacing: -0.01em; margin: 4px 0 8px;
  color: var(--blue);
}
.stat.bad .num { color: var(--red); }
.stat.good .num { color: var(--green); }
.stat p { font-size: 13.5px; color: var(--ink-soft); margin: 0; line-height: 1.55; }
.stat > .num + p strong, .stat p strong { color: var(--ink); }
div.stat { margin: 26px 0; }

/* decision rule */
.rule {
  margin: 28px 0; padding: 18px 24px 18px 22px;
  background: #fff; border: 1.5px solid var(--blue); border-radius: 14px;
  position: relative;
}
.rule::before {
  content: "Decision rule";
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--blue); margin-bottom: 6px;
}
.rule p { margin: 0; font-size: 15.5px; font-weight: 500; color: var(--ink); }
.rule p + p { margin-top: 8px; }

/* persona boxes */
.persona {
  margin: 26px 0; padding: 20px 24px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 1px 4px rgba(17, 21, 31, .05);
  position: relative;
}
.persona::before {
  content: attr(data-name);
  display: inline-block; font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: var(--blue);
  border-radius: 999px; padding: 4px 12px; margin-bottom: 10px;
}
.persona p { margin: 0 0 10px; font-size: 15px; color: var(--ink-soft); }
.persona p:last-child { margin-bottom: 0; }
.persona strong { color: var(--ink); }

/* ——— figures ——— */
figure.fig {
  margin: 32px 0; padding: 22px 22px 16px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 1px 4px rgba(17, 21, 31, .04);
}
figure.fig svg { width: 100%; height: auto; display: block; }
figure.fig figcaption {
  font-size: 13px; color: var(--ink-soft);
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  line-height: 1.5;
}

/* SVG palette — the only colors chapter figures may use */
.fg-grid  { stroke: #e9edf7; stroke-width: 1; }
.fg-axis  { stroke: #aab1c5; stroke-width: 1.4; fill: none; }
.fg-tick  { fill: #8a90a3; font-family: var(--sans); }
.fg-label { fill: #4a5163; font-family: var(--sans); font-weight: 600; }
.fg-title { fill: #11151f; font-family: var(--sans); font-weight: 600; }
.fg-annot { fill: #4a5163; font-family: var(--serif); font-style: italic; }
.fg-arrow { stroke: #8a90a3; stroke-width: 1.2; fill: none; }
.fg-l1 { stroke: var(--blue); stroke-width: 2.6; fill: none; stroke-linecap: round; }
.fg-l2 { stroke: var(--sky); stroke-width: 2.4; fill: none; stroke-linecap: round; }
.fg-l3 { stroke: var(--green); stroke-width: 2.2; fill: none; stroke-linecap: round; }
.fg-a1 { fill: rgba(41, 69, 227, .12); stroke: none; }
.fg-a2 { fill: rgba(229, 72, 77, .12); stroke: none; }
.fg-a3 { fill: rgba(56, 163, 245, .18); stroke: none; }
.fg-d1 { fill: var(--blue); }
.fg-d2 { fill: var(--red); }
.fg-ref { stroke: #aab1c5; stroke-width: 1.3; stroke-dasharray: 5 5; fill: none; }
text.fg-l1, text.fg-l2, text.fg-l3 { stroke: none; font-family: var(--sans); font-weight: 600; }
text.fg-l1 { fill: var(--blue); } text.fg-l2 { fill: var(--sky); } text.fg-l3 { fill: var(--green); }

/* ——— interactive calculators ——— */
.widget {
  margin: 32px 0; padding: 24px;
  background: #fff; border: 1.5px solid var(--blue); border-radius: 16px;
  box-shadow: 0 2px 10px rgba(41, 69, 227, .07);
}
.widget .w-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; color: var(--ink); }
.widget .w-title::before { content: "✦ "; color: var(--blue); }
.widget .w-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.widget .w-controls { display: flex; flex-wrap: wrap; gap: 16px 26px; margin-bottom: 14px; }
.widget .w-ctl { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1; }
.widget .w-ctl.wide { flex: 1 1 100%; }
.widget .w-ctl.grow2 { flex: 2 1 300px; }
.widget .w-ctl label { font-size: 12px; color: var(--ink-soft); display: flex; justify-content: space-between; gap: 8px; }
.widget .w-ctl label b { font-family: var(--mono); font-weight: 600; color: var(--blue); white-space: nowrap; }
.widget input[type=range] { accent-color: var(--blue); width: 100%; }
.widget .w-seg {
  display: flex; flex-wrap: wrap; width: 100%;
  border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
}
.widget .w-seg button {
  font-family: var(--sans); font-size: 12.5px; padding: 8px 10px; border: 0;
  background: #fff; color: var(--ink-soft); cursor: pointer; font-weight: 600;
  flex: 1 1 auto; white-space: nowrap; line-height: 1.2;
}
.widget .w-seg button.on { background: var(--blue); color: #fff; }
.widget .w-read {
  display: flex; flex-wrap: wrap; gap: 10px 26px; margin-top: 14px;
  padding-top: 14px; border-top: 1px solid var(--line);
}
.widget .w-stat { font-size: 12px; color: var(--ink-soft); }
.widget .w-stat b { display: block; font-family: var(--serif); font-size: 22px; color: var(--ink); font-weight: 600; }
.widget .w-stat b.pos { color: var(--green); }
.widget .w-stat b.neg { color: var(--red); }
.widget .w-stat b.blu { color: var(--blue); }
.widget svg { width: 100%; height: auto; display: block; }
.widget .w-note { font-size: 11.5px; color: var(--ink-faint); margin-top: 10px; }

/* ——— cover page ——— */
#cover-hero {
  background: var(--blue);
  border-radius: 20px;
  padding: 64px 52px;
  margin: 26px 0 32px;
  color: #fff;
}
#cover-hero .fv-mark {
  font-family: var(--serif); font-weight: 700; font-size: 22px; margin-bottom: 40px;
}
#cover-hero h1 {
  font-family: var(--serif); font-size: 52px; line-height: 1.08;
  font-weight: 600; letter-spacing: -0.01em; margin: 0 0 18px; color: #fff;
}
#cover-hero h1 em { font-style: italic; color: #7cc4f8; }
#cover-hero .cover-sub {
  font-size: 18px; line-height: 1.6; color: rgba(255, 255, 255, .85);
  max-width: 540px; margin-bottom: 30px;
}
#cover-hero .cover-cta {
  display: inline-block; font-size: 15px; font-weight: 650;
  background: #fff; color: var(--blue); text-decoration: none;
  padding: 13px 26px; border-radius: 10px;
}
#cover-hero .cover-cta:hover { background: #eaf2ff; }
#cover-hero .cover-note { font-size: 12.5px; color: rgba(255,255,255,.6); margin-top: 16px; }
.cover-disclaimer {
  font-size: 12px; color: var(--ink-faint); margin: 0 4px 44px; line-height: 1.5;
  padding: 0 4px;
}
.toc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 10px 0 50px; }
.toc-part-label {
  grid-column: 1 / -1; font-size: 11px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 700;
  margin-top: 16px;
}
.toc-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px;
  text-decoration: none; color: var(--ink); background: #fff; display: block;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.toc-card:hover {
  border-color: var(--blue); transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(41, 69, 227, .08);
}
.toc-card .tc-n { font-family: var(--mono); font-size: 11px; color: var(--blue); font-weight: 600; }
.toc-card .tc-t { font-family: var(--serif); font-weight: 600; font-size: 17px; line-height: 1.25; margin: 4px 0 5px; }
.toc-card .tc-d { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; }

/* ——— prev / next footer nav ——— */
#chnav {
  display: flex; gap: 14px; margin-top: 60px; padding-top: 28px;
  border-top: 1px solid var(--line);
}
#chnav a {
  flex: 1; border: 1px solid var(--line); border-radius: 14px;
  padding: 15px 18px; text-decoration: none; color: var(--ink); background: #fff;
}
#chnav a:hover { border-color: var(--blue); }
#chnav a.next { text-align: right; }
#chnav .dir { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); font-weight: 700; }
#chnav .ttl { font-family: var(--serif); font-weight: 600; font-size: 16px; margin-top: 3px; }
#chnav a.next .ttl { color: var(--blue); }

footer.site {
  max-width: var(--content-w); margin: 0 auto; padding: 0 36px 48px;
  font-size: 12px; color: var(--ink-faint); line-height: 1.6;
}
footer.site a { color: var(--blue); }

/* ——— responsive ——— */
@media (max-width: 980px) {
  #sidebar {
    position: fixed; left: 0; top: 0; z-index: 70; height: 100vh;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.12); background: #fff;
  }
  #sidebar.open { transform: translateX(0); }
  #topbar { display: flex; }
  #content { padding: 30px 20px 64px; }
  #content h1 { font-size: 32px; }
  #cover-hero { padding: 42px 28px; }
  #cover-hero h1 { font-size: 36px; }
  .toc-grid { grid-template-columns: 1fr; }
  .statgrid { grid-template-columns: 1fr; }
  body { font-size: 16px; }
}
#scrim {
  display: none; position: fixed; inset: 0; background: rgba(17, 21, 31, .35); z-index: 65;
}
#scrim.show { display: block; }
