:root {
  --paper: #f6f3ec;
  --ink: #1b1a17;
  --muted: #615c53;
  --rule: #d6d0c2;
  --accent: #8f2a1c;
  /* Chart series (validated for colorblind separation and contrast on --paper) */
  --s-contrib: #3d6fb0;
  --s-growth: #a33a26;
  --s-real: #b08425;
  --measure: 700px;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  color-scheme: light;
}

/* Dark theme: light is the default; dark applies only when the reader
   picks it with the header switch (stored as data-theme on <html>). */
:root[data-theme="dark"] {
  --paper: #171613;
  --ink: #e6e1d6;
  --muted: #9c968a;
  --rule: #34312b;
  --accent: #d9826b;
  --s-contrib: #5585c8;
  --s-growth: #b03c2a;
  --s-real: #b08c27;
  color-scheme: dark;
}

/* Theme switch: styled like the other small-caps nav links */
.theme-toggle {
  margin-left: 18px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-variant: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
}
.theme-toggle:hover { color: var(--accent); text-decoration-color: currentColor; }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

* { 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: 19px;
  line-height: 1.6;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 20px;
}

.label {
  font-variant: all-small-caps;
  letter-spacing: 0.08em;
  font-size: 1.05em;
  color: var(--muted);
}

/* Masthead */
.masthead { padding: 56px 0 0; }
.masthead-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}
.masthead nav a {
  margin-left: 18px;
  text-decoration: none;
}
.wordmark {
  display: block;
  font-size: clamp(40px, 8vw, 68px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.025em;
  text-decoration: none;
  margin: 28px 0 18px;
}
.wordmark:hover { color: inherit; }
.dateline {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 6px 0;
}

/* Small header used on guide pages */
.bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 22px 0 10px;
  border-bottom: 1px solid var(--ink);
}
.bar .home {
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.bar nav a { margin-left: 18px; text-decoration: none; }

/* Intro */
.intro {
  font-size: 23px;
  line-height: 1.5;
  margin: 40px 0 8px;
}
.intro em { color: var(--accent); font-style: italic; }

h2.label {
  font-size: 1.15em;
  font-weight: 600;
  margin: 64px 0 4px;
  color: var(--ink);
}

/* Contents */
.contents { margin: 0; padding: 0; }
.subject {
  border-top: 1px solid var(--rule);
  padding: 18px 0 20px;
}
.subject:first-child { border-top: 1px solid var(--ink); }
.subject-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.numeral {
  color: var(--accent);
  font-weight: 600;
  min-width: 2.2em;
}
.subject h3 {
  margin: 0;
  font-size: 1em;
  font-weight: 600;
}
.subject .scope {
  margin: 2px 0 0 calc(2.2em + 12px);
  color: var(--muted);
  font-style: italic;
  font-size: 0.92em;
}
.entries {
  list-style: none;
  margin: 10px 0 0 calc(2.2em + 12px);
  padding: 0;
}
.entries li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}
.entries .leader {
  flex: 1;
  border-bottom: 1px dotted var(--muted);
  transform: translateY(-5px);
  min-width: 24px;
}
.entries .when {
  color: var(--muted);
  font-size: 0.85em;
  white-space: nowrap;
}
.entries .pending { color: var(--muted); }

/* Subscribe */
.subscribe p { margin: 8px 0 18px; }
.subscribe form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.subscribe input {
  flex: 1 1 260px;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink);
  padding: 6px 0;
  border-radius: 0;
}
.subscribe input::placeholder { color: var(--muted); font-style: italic; }
.subscribe input:focus { outline: none; border-bottom-color: var(--accent); }
.subscribe button {
  font: inherit;
  font-variant: all-small-caps;
  letter-spacing: 0.08em;
  font-weight: 600;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  padding: 7px 18px 9px;
  cursor: pointer;
}
.subscribe button:hover { background: var(--accent); }

/* Footer */
footer {
  margin-top: 80px;
  padding: 14px 0 56px;
  border-top: 1px solid var(--ink);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.85em;
  color: var(--muted);
}

/* Article */
.numbered { counter-reset: section; }
.article .kicker { margin: 44px 0 0; }
.article h1 {
  font-size: clamp(34px, 6vw, 50px);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 8px 0 16px;
}
.article .lede {
  font-size: 23px;
  line-height: 1.45;
  font-style: italic;
  margin: 0 0 14px;
}
.article .byline {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 6px 0;
  margin-bottom: 36px;
}
.article h2 {
  font-size: 1.3em;
  font-weight: 600;
  line-height: 1.25;
  margin: 48px 0 8px;
}
.numbered h2:not(.unnumbered) { counter-increment: section; }
.numbered h2:not(.unnumbered)::before {
  content: counter(section) ".";
  color: var(--accent);
  margin-right: 0.5em;
}
.kicker a { text-decoration: none; }
.sources { font-size: 0.9em; padding-left: 1.2em; }
.sources a { word-break: break-word; }
.follow p { margin-top: 8px; }
.article h3 {
  font-size: 1em;
  font-weight: 600;
  font-style: italic;
  margin: 26px 0 4px;
}
.article p { margin: 0 0 16px; }
.article li { margin-bottom: 8px; }
.note {
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 14px 0;
  margin: 32px 0;
}
.note .label { display: block; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.note p { margin: 0; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding-left: 32px; position: relative; }
.checklist li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.38em;
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--ink);
}
.disclaimer {
  font-size: 0.85em;
  font-style: italic;
  color: var(--muted);
  margin-top: 48px;
}

@media (max-width: 560px) {
  body { font-size: 18px; }
  .masthead { padding-top: 28px; }
  .intro, .article .lede { font-size: 20px; }
  .entries, .subject .scope { margin-left: 0; }
  .entries li { flex-wrap: wrap; }
  .entries .leader { display: none; }
  .entries .when { width: 100%; }
  .bar nav a:first-child { display: none; }
}

/* ---------- Calculator ---------- */
.calc {
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 8px 0 28px;
  margin: 8px 0 24px;
}
.calc h2 { margin-top: 16px; }
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px 28px;
  margin: 12px 0 8px;
}
.field label {
  display: block;
  font-variant: all-small-caps;
  letter-spacing: 0.06em;
  color: var(--muted);
  line-height: 1.3;
}
.field input {
  width: 100%;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  padding: 4px 0;
}
.field input:focus { outline: none; border-bottom: 2px solid var(--accent); margin-bottom: -1px; }
.calc-note { font-size: 0.85em; font-style: italic; color: var(--muted); }

.results { margin: 28px 0 8px; }
.hero { margin: 0 0 16px; }
.hero .label { display: block; }
.hero-num {
  display: block;
  font-size: clamp(40px, 8vw, 60px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 24px;
  margin: 0;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
}
.stats dt { font-variant: all-small-caps; letter-spacing: 0.06em; color: var(--muted); line-height: 1.3; }
.stats dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.chart { margin: 32px 0 0; }
.chart figcaption { color: var(--ink); font-weight: 600; }
.legend {
  list-style: none;
  padding: 0;
  margin: 4px 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  font-size: 0.85em;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 8px; }
.sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; flex: none; }
.sw-contrib { background: var(--s-contrib); }
.sw-growth { background: var(--s-growth); }
.sw-real { height: 0; border-radius: 0; border-top: 2px dashed var(--s-real); }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; overflow: visible; font-family: var(--serif); touch-action: pan-y; }
.chart-wrap .gridline { stroke: var(--rule); stroke-width: 1; }
.chart-wrap .baseline { stroke: var(--muted); stroke-width: 1; }
.chart-wrap .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-wrap .direct { fill: var(--muted); font-size: 13px; }
.chart-wrap .area-contrib { fill: var(--s-contrib); stroke: var(--paper); stroke-width: 2; stroke-linejoin: round; }
.chart-wrap .area-growth { fill: var(--s-growth); }
.chart-wrap .line-real { fill: none; stroke: var(--s-real); stroke-width: 2; stroke-dasharray: 6 4; stroke-linejoin: round; }
.chart-wrap .crosshair { stroke: var(--ink); stroke-width: 1; }
.chart-wrap .dot { stroke: var(--paper); stroke-width: 2; }
.chart-wrap .dot-balance { fill: var(--s-growth); }
.chart-wrap .dot-contrib { fill: var(--s-contrib); }
.chart-wrap .dot-real { fill: var(--s-real); }
.chart-wrap .hit { fill: transparent; cursor: crosshair; }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 8px 12px;
  font-size: 0.8em;
  line-height: 1.5;
  white-space: nowrap;
  z-index: 2;
}
.tip span { display: flex; align-items: center; gap: 6px; }
.tip b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.tip .sw { width: 10px; }

.table-view { margin-top: 16px; }
.table-view summary { cursor: pointer; color: var(--ink); }
.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; margin-top: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85em; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.data-table thead th { position: sticky; top: 0; background: var(--paper); font-weight: 600; border-bottom: 1px solid var(--ink); }
.data-table th[scope="row"] { font-weight: 400; color: var(--muted); }

.compare { border-left: 2px solid var(--accent); padding-left: 16px; }

/* ---------- Home break-even calculator ---------- */
.calc-group { border: 0; padding: 0; margin: 18px 0 0; min-width: 0; }
.calc-group legend { padding: 0; color: var(--ink); font-weight: 600; }
.calc-group .calc-grid { margin-top: 6px; }
.hero-sub { display: block; color: var(--muted); font-size: 0.9em; }
.hero-2 .hero-num { font-size: clamp(30px, 6vw, 42px); }
.stats dd.neg { color: var(--accent); }

.sw-value { background: var(--s-contrib); height: 3px; border-radius: 0; }
.sw-fees { height: 0; border-radius: 0; border-top: 2px dashed var(--s-real); }
.sw-allin { background: var(--s-growth); height: 3px; border-radius: 0; }
.chart-wrap .line-value { fill: none; stroke: var(--s-contrib); stroke-width: 2.5; stroke-linejoin: round; }
.chart-wrap .line-fees { fill: none; stroke: var(--s-real); stroke-width: 2; stroke-dasharray: 6 4; }
.chart-wrap .line-allin { fill: none; stroke: var(--s-growth); stroke-width: 2; stroke-linejoin: round; }
.chart-wrap .dot-value { fill: var(--s-contrib); }
.chart-wrap .dot-fees { fill: var(--s-real); }
.chart-wrap .dot-allin { fill: var(--s-growth); }
.chart-wrap .sell-marker { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-wrap .sell-label { font-style: italic; }

.breakdowns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px 32px;
  margin-top: 28px;
}
.breakdowns h3 { margin: 0 0 4px; font-weight: 600; color: var(--ink); font-style: normal; }
.cost-table th[scope="row"] { text-align: left; color: var(--ink); white-space: normal; }
.cost-table tr.total th, .cost-table tr.total td { font-weight: 600; border-top: 1px solid var(--ink); }
.cost-table tr.sub th, .cost-table tr.sub td { color: var(--muted); font-style: italic; border-bottom: 0; }
