/* Tiny Quick Tools: the category standard, played straight.
   Quiet neutral ground, hairlines, ink, one cobalt accent. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --ink: #0e1116;
  --ink-2: #454b56;
  --ink-3: #646c7a;
  --line: #e2e5ea;
  --line-input: #8a919c;
  --accent: #2346c4;
  --accent-soft: rgb(35 70 196 / 0.14);
  --ring: rgb(35 70 196 / 0.3);
  --danger: #b42318;
  --danger-ring: rgb(180 35 24 / 0.22);
  --btn: #0e1116;
  --btn-ink: #ffffff;
  --btn-hover: #2b313b;
  --seg-on: #ffffff;
  --shadow-1: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.04);
  --shadow-seg: 0 1px 2px rgb(16 24 40 / 0.12), 0 0 0 1px rgb(16 24 40 / 0.06);
  /* chart series (validated: lightness, chroma, CVD, contrast) */
  --series-invested: #1baf7a;
  --series-interest: #2346c4;

  --font: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 6px;
  --r-s: 4px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #16181d;
    --surface-2: #1f2228;
    --ink: #eef0f3;
    --ink-2: #b9bfc9;
    --ink-3: #8f97a4;
    --line: #272b32;
    --line-input: #6a717e;
    --accent: #8ea7ff;
    --accent-soft: rgb(142 167 255 / 0.16);
    --ring: rgb(142 167 255 / 0.35);
    --danger: #ff8f80;
    --danger-ring: rgb(255 143 128 / 0.3);
    --btn: #eef0f3;
    --btn-ink: #0e1116;
    --btn-hover: #ffffff;
    --seg-on: #2b2f37;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-seg: 0 1px 2px rgb(0 0 0 / 0.5), 0 0 0 1px rgb(255 255 255 / 0.06);
    --series-invested: #199e70;
    --series-interest: #5b7ff0;
    color-scheme: dark;
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-input) transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, p, ol, ul, figure, fieldset { margin: 0; }
ol, ul { padding: 0; }
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select { font: inherit; color: inherit; }
svg { flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 16px; top: -48px; z-index: 10;
  background: var(--btn); color: var(--btn-ink); padding: 10px 14px;
  border-radius: var(--r-s); font-weight: 600; text-decoration: none;
}
.skip:focus { top: 8px; }

.wrap { width: 100%; max-width: 736px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 24px; } }

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

.site-header { border-bottom: 1px solid var(--line); background: var(--bg); }
.site-header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 16px; }
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  color: var(--ink); text-decoration: none; font-size: 15px; font-weight: 650; letter-spacing: -0.01em;
}
.brand-mark rect { fill: var(--ink); }
.brand-mark path { stroke: var(--bg); stroke-width: 1.8; stroke-linecap: round; fill: none; }
.brand-mark circle { fill: var(--bg); }
.langs { display: flex; gap: 2px; }
.langs a {
  font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink-3);
  text-decoration: none; padding: 6px 8px; border-radius: var(--r-s); min-width: 34px; text-align: center;
}
.langs a:hover { color: var(--ink); }
.langs a[aria-current] { color: var(--ink); background: var(--surface-2); }

/* ---------- page head ---------- */

.page { padding-top: 16px; }
.crumbs ol { display: flex; flex-wrap: wrap; list-style: none; font-size: 13px; color: var(--ink-3); }
.crumbs li + li::before { content: "/"; margin: 0 8px; color: var(--line-input); }
.crumbs a { color: var(--ink-3); text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ink-2); }

.page-title {
  margin: 12px 0 6px;
  font-size: 30px;
  line-height: 1.15; font-weight: 650; letter-spacing: -0.022em;
  text-wrap: balance;
}
.lede { font-size: 15px; color: var(--ink-2); max-width: 60ch; margin-bottom: 20px; }
.page-title + .tool { margin-top: 16px; }

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

.tool {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  padding: 16px;
}
@media (min-width: 640px) { .tool { padding: 24px; } }

.modes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  padding: 3px; background: var(--surface-2); border-radius: var(--r);
  margin-bottom: 20px;
}
@media (min-width: 600px) { .modes { grid-template-columns: repeat(4, auto); } }
.modes a {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 40px; padding: 6px 4px; border-radius: var(--r-s);
  font-size: 15px; font-weight: 550; line-height: 1.25; color: var(--ink-2); text-decoration: none;
  transition: color 120ms, background-color 120ms;
}
.modes a:hover { color: var(--ink); }
.modes a[aria-current] { background: var(--seg-on); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-seg); }

.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field { min-width: 0; }
.field label, .choice legend { display: block; font-size: 15px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.control { position: relative; }
.control input {
  display: block; width: 100%; height: 52px; padding: 0 14px;
  font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  background: var(--surface); border: 1px solid var(--line-input); border-radius: var(--r-s);
  caret-color: var(--accent); appearance: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.control.has-suffix input { padding-right: 36px; }
.control input:hover { border-color: var(--ink-3); }
.control input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.suffix {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 17px; font-weight: 500; color: var(--ink-3); pointer-events: none;
}
.control.has-prefix input { padding-left: 46px; }
.prefix {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 15px; font-weight: 550; color: var(--ink-3); pointer-events: none;
}
/* input with a joined unit select: one control, two parts */
.control.has-unit { display: flex; }
.control.has-unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; min-width: 0; flex: 1 1 auto; }
.control.has-unit.has-suffix .suffix { right: calc(var(--unit-w) + 14px); }
.control.has-unit { --unit-w: 104px; }
.control select {
  flex: none; width: var(--unit-w); height: 52px; margin-left: -1px; padding: 0 28px 0 12px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23646c7a' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line-input); border-radius: 0 var(--r-s) var(--r-s) 0;
  font-size: 15px; font-weight: 550; appearance: none; cursor: pointer;
}
.control select:hover { border-color: var(--ink-3); }
.control select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); position: relative; }
.has-error .control input { border-color: var(--danger); }
.has-error .control input:focus { box-shadow: 0 0 0 3px var(--danger-ring); }
.field-error { margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--danger); }
.field-hint { margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--ink-3); }
.field.is-wide { grid-column: 1 / -1; }

.choice { border: 0; padding: 0; margin-top: 16px; min-width: 0; }
.choice legend { padding: 0; }
.choice-options { display: flex; gap: 24px; }
.choice-options label { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; min-height: 32px; }
.choice-options input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.btn-primary {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 52px; margin-top: 16px; padding: 0 28px;
  background: var(--btn); color: var(--btn-ink); border: 0; border-radius: var(--r-s);
  font-size: 17px; font-weight: 600; letter-spacing: -0.005em; cursor: pointer;
  transition: background-color 120ms, transform 80ms;
}
.btn-primary:hover { background: var(--btn-hover); }
.btn-primary:active { transform: translateY(1px); }
@media (min-width: 600px) { .btn-primary { width: auto; min-width: 200px; } }
.tool-form.htmx-request .btn-primary { cursor: progress; opacity: 0.72; }

/* ---------- result ---------- */

.result { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.result-empty { font-size: 15px; color: var(--ink-3); }
.result.is-error { display: none; }
.result-lead { display: grid; }
.result-lead > p { grid-area: 1 / 1; font-size: 15px; color: var(--ink-2); }
.lead-stale { visibility: hidden; }

.figure-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; margin-top: 2px; }
.figure {
  display: block; min-width: 0; overflow-wrap: anywhere;
  font-size: clamp(56px, 48px + 2vw, 64px); line-height: 1.04; font-weight: 650;
  letter-spacing: -0.035em; font-variant-numeric: tabular-nums;
  transition: color 160ms;
}
/* long figures (money) shrink fluidly instead of breaking mid-number */
.figure.is-long { font-size: clamp(36px, 10.5vw, 56px); overflow-wrap: normal; white-space: nowrap; }
.figure.is-fresh { animation: settle 360ms var(--ease-out); }
@keyframes settle {
  from { opacity: 0.35; transform: translateY(6px); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

.btn-copy {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 36px; padding: 0 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line-input); border-radius: var(--r-s);
  font-size: 15px; font-weight: 550; cursor: pointer;
  transition: background-color 120ms, color 120ms, border-color 120ms;
}
.btn-copy:hover { background: var(--surface-2); }
.btn-copy svg { fill: none; stroke: currentColor; stroke-width: 1.4; }
.btn-copy.is-copied { color: var(--accent); border-color: var(--accent); }

.result-note { margin-top: 4px; font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.steps-title { margin: 22px 0 6px; font-size: 15px; font-weight: 600; }
.steps { list-style: none; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.steps li {
  display: grid; grid-template-columns: 1fr auto minmax(5ch, auto); gap: 12px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px;
}
.step-expr { color: var(--ink-2); overflow-wrap: anywhere; }
.step-eq { color: var(--ink-3); }
.step-val { text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.steps-note { margin-top: 8px; font-size: 13px; color: var(--ink-3); }

/* stale: inputs edited after a result; nothing moves */
.result.is-stale .lead-current { visibility: hidden; }
.result.is-stale .lead-stale { visibility: visible; color: var(--ink); font-weight: 550; }
.result.is-stale .figure {
  color: var(--ink-3);
  text-decoration: line-through; text-decoration-thickness: 3px; text-decoration-color: var(--line-input);
}
.result.is-stale .result-note { color: var(--ink-3); }
.result.is-stale .step-expr, .result.is-stale .step-val { color: var(--ink-3); }
.result.is-stale .btn-copy { visibility: hidden; }

/* ---------- ads (only when ADS_ENABLED and the tool allows) ---------- */

.ad-slot {
  position: relative; margin-top: 24px; min-height: 280px;
  border: 1px dashed var(--line); border-radius: var(--r);
}
.ad-label { position: absolute; top: 6px; left: 10px; font-size: 13px; color: var(--ink-3); }

/* ---------- explainer ---------- */

.explainer { margin-top: 56px; max-width: 68ch; color: var(--ink-2); }
.explainer h2 { margin: 40px 0 12px; font-size: 22px; line-height: 1.25; font-weight: 650; letter-spacing: -0.015em; color: var(--ink); text-wrap: balance; }
.explainer h2:first-child { margin-top: 0; }
.explainer h3 { margin: 24px 0 6px; font-size: 17px; line-height: 1.35; font-weight: 600; color: var(--ink); }
.explainer p, .explainer ul, .explainer ol { margin: 0 0 14px; font-size: 17px; line-height: 1.6; }
.explainer ul, .explainer ol { padding-left: 1.3em; }
.explainer li { margin-bottom: 4px; }
.explainer strong { color: var(--ink); font-weight: 600; }
.explainer code {
  font: 600 0.94em/1 var(--font); font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--ink); padding: 1px 4px; border-radius: var(--r-s);
  white-space: nowrap;
}
.explainer .updated, .updated { margin-top: 24px; font-size: 13px; color: var(--ink-3); }

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

.related { margin-top: 48px; }
.related h2, .home-group h2 { font-size: 17px; font-weight: 650; margin-bottom: 12px; }
.related ul, .home-list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; }
.related a, .home-list a {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-s);
  color: var(--ink); font-size: 15px; font-weight: 550; text-decoration: none;
}
.related a:hover, .home-list a:hover { border-color: var(--line-input); }
.home-group { margin-top: 32px; }

/* form actions: the primary button plus a quiet secondary link */
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; margin-top: 16px; }
.form-actions .btn-primary { margin-top: 0; }
.link-quiet { font-size: 15px; color: var(--ink-2); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.link-quiet:hover { color: var(--ink); text-decoration: underline; }

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

.chart { margin: 28px 0 0; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 16px; margin-bottom: 10px; }
.chart-title { font-size: 15px; font-weight: 600; }
.legend { display: flex; gap: 16px; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 2px; }
.swatch-invested { background: var(--series-invested); }
.swatch-interest { background: var(--series-interest); }
/* data layer stretches to the frame; labels sit on a percentage overlay so
   text keeps its real size at every width */
.chart-frame { position: relative; height: 240px; }
@media (min-width: 640px) { .chart-frame { height: 300px; } }
.chart-frame svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-data { touch-action: pan-y; }
.chart .grid, .chart .axis, .chart .crosshair { vector-effect: non-scaling-stroke; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-input); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font: 12px var(--font); font-variant-numeric: tabular-nums; }
.chart .tick-y { text-anchor: start; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.chart .area-invested { fill: var(--series-invested); fill-opacity: 0.22; }
.chart .area-interest { fill: var(--series-interest); fill-opacity: 0.16; }
.chart .line-invested, .chart .line-total { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .line-invested { stroke: var(--series-invested); }
.chart .line-total { stroke: var(--series-interest); }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-caption { margin-top: 2px; text-align: center; font-size: 13px; color: var(--ink-3); }
.chart-tip {
  position: absolute; top: 0; z-index: 2; min-width: 168px; padding: 8px 10px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line-input); border-radius: var(--r-s); box-shadow: var(--shadow-1);
  font-size: 13px; line-height: 1.45; font-variant-numeric: tabular-nums;
}
.chart-tip strong { display: block; font-weight: 600; margin-bottom: 2px; }
.chart-tip span { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); }
.chart-tip b { color: var(--ink); font-weight: 600; }
.result.is-stale .chart { opacity: 0.45; }

/* ---------- data table ---------- */

.table-block { margin-top: 24px; }
.table-block summary {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; list-style: none;
  font-size: 15px; font-weight: 600; color: var(--ink);
}
.table-block summary::-webkit-details-marker { display: none; }
.table-block summary::before {
  content: ""; width: 7px; height: 7px; margin: 0 3px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 120ms;
}
.table-block[open] summary::before { transform: rotate(45deg); }
.table-block summary:hover { color: var(--accent); }
.table-scroll {
  max-height: 420px; overflow: auto; margin-top: 4px;
  border: 1px solid var(--line); border-radius: var(--r);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table th, .data-table td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); }
.data-table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  font-weight: 600; color: var(--ink); text-align: right;
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table tbody th { font-weight: 550; color: var(--ink-2); }
/* month column stays visible while the table scrolls sideways on phones */
.data-table th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.data-table thead th:first-child { z-index: 2; background: var(--surface-2); }
.data-table td:nth-child(2) { color: var(--ink); font-weight: 600; }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.result.is-stale .data-table td { color: var(--ink-3); }

/* breakdown: key/value lines under the figure (totals emphasised) */
.breakdown { margin-top: 16px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.breakdown > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.breakdown dt { color: var(--ink-2); }
.breakdown dd { margin: 0; font-weight: 600; text-align: right; }
.breakdown .is-em dt, .breakdown .is-em dd { color: var(--ink); font-weight: 650; }
.result.is-stale .breakdown dt, .result.is-stale .breakdown dd { color: var(--ink-3); }

/* estimate notice for health, labor and tax tools */
.disclaimer { margin-top: 16px; font-size: 13px; line-height: 1.5; color: var(--ink-2); max-width: 68ch; }

/* secondary action: the copy-button family, used as a link */
.btn-secondary {
  display: inline-flex; align-items: center; height: 44px; padding: 0 18px; margin-top: 8px;
  background: var(--surface); border: 1px solid var(--line-input); border-radius: var(--r-s);
  color: var(--ink); font-size: 15px; font-weight: 550; text-decoration: none;
  transition: background-color 120ms;
}
.btn-secondary:hover { background: var(--surface-2); }

/* ---------- home search ---------- */

.tool-search { margin: 8px 0 -8px; max-width: 28rem; }
.tool-search label { display: block; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.tool-search input {
  display: block; width: 100%; height: 48px; padding: 0 14px;
  font-size: 17px; background: var(--surface); border: 1px solid var(--line-input); border-radius: var(--r-s);
  caret-color: var(--accent); appearance: none; transition: border-color 120ms, box-shadow 120ms;
}
.tool-search input:hover { border-color: var(--ink-3); }
.tool-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.tool-search input::placeholder { color: var(--ink-3); }
.tool-search .field-hint:empty { visibility: hidden; }
.tool-search .field-hint { min-height: 1.4em; }
.home-group[hidden], .home-list li[hidden] { display: none; }

.explainer-page { margin-top: 24px; }

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

.site-footer { margin-top: 72px; border-top: 1px solid var(--line); }
.site-footer-inner { padding-top: 24px; padding-bottom: 40px; font-size: 13px; color: var(--ink-3); }
.footer-privacy { max-width: 60ch; }
.footer-nav ul { display: flex; flex-wrap: wrap; gap: 4px 20px; list-style: none; margin-top: 12px; }
.footer-nav a { color: var(--ink-2); text-decoration: none; display: inline-flex; min-height: 32px; align-items: center; }
.footer-nav a:hover { color: var(--ink); text-decoration: underline; }
.footer-nav .link-button { min-height: 32px; }
.footer-meta { margin-top: 12px; }
.link-button { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* desktop: keep the answer and its working one readable column */
@media (min-width: 640px) {
  .result-lead, .result-note, .steps-title, .steps, .steps-note, .breakdown { max-width: 24rem; }
  .figure-row { max-width: 24rem; }
  .figure-row:has(.is-long) { max-width: none; justify-content: flex-start; }
}
