:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #64625d; /* 5.6:1 on --page, WCAG AA for small text */
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #1f68bf; /* 5.5:1 on white: AA for small text */
  --good: #006300;
  --bad: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }

.site-header { padding: 28px 0 8px; }
.site-header h1 { margin: 0; font-size: clamp(1.7rem, 5vw, 2.4rem); letter-spacing: -0.02em; }
.site-header h1 span { color: var(--accent); }
.lede { margin: 6px 0 0; color: var(--text-2); max-width: 46em; }

section { margin: 28px 0; }
h2 { font-size: 1.2rem; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
h3 { font-size: 1rem; margin: 0 0 4px; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 0.85rem;
}
.sub { margin: 0 0 12px; color: var(--text-2); font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.8rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.empty { color: var(--text-2); text-align: center; padding: 28px 16px; }

.btn {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid transparent;
}
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-2); min-width: 0; }
.field input, .field select {
  font: inherit; font-size: 1rem; color: var(--text); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; width: 100%; min-width: 0;
}
.field select:disabled { opacity: 0.5; }
fieldset { border: 0; padding: 0; margin: 0; }
.field-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; grid-column: 1 / -1; }
.field-group legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; color: var(--text); }

.params { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.params .wide { grid-column: 1 / -1; }
@media (min-width: 760px) {
  .params { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .field-group { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .params .wide { grid-column: span 4; }
}

.vehicle-grid { display: grid; gap: 16px; }
@media (min-width: 760px) { .vehicle-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); } }
.vehicle { border-top: 4px solid var(--vc, var(--accent)); margin-bottom: 0; }
.vehicle-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.vehicle-head h3 { flex: 1; margin: 0; font-size: 1rem; }
.badge { width: 12px; height: 12px; border-radius: 3px; background: var(--vc); flex: none; }
.selects, .vehicle-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.vehicle-inputs { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.spec { margin: 10px 0 0; font-size: 0.9rem; color: var(--text-2); }
.spec b { color: var(--text); }
.status:empty { display: none; }
.status { margin: 8px 0 0; }
#add-vehicle { margin-top: 12px; }

.verdict {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 16px;
}
.verdict .big { font-size: clamp(1.3rem, 4vw, 1.8rem); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.verdict p { margin: 6px 0 0; color: var(--text-2); }

.ranking { list-style: none; margin: 14px 0 0; padding: 12px 0 0; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.ranking li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.ranking .rank-name { flex: 1 1 12em; min-width: 0; }
.tiles { display: grid; gap: 12px; margin-bottom: 16px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--vc); border-radius: var(--radius); padding: 14px 16px; }
.tile h3 { display: flex; gap: 8px; align-items: center; }
.tile .kind { font-size: 0.75rem; color: var(--text-2); border: 1px solid var(--border); border-radius: 99px; padding: 1px 8px; font-weight: 500; }
.tile .hero { font-size: 1.8rem; font-weight: 700; margin: 6px 0 0; }
.tile .hero-sub { color: var(--text-2); font-size: 0.85rem; margin: 0 0 10px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 0; }
.stats div { min-width: 0; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; }
.cheapest-tag { color: var(--good); font-size: 0.8rem; font-weight: 600; }

.insights, .actions, .sources ul, .method { margin: 8px 0 0; padding-left: 20px; }
.insights li, .actions li { margin: 8px 0; }
.insights b { font-weight: 700; }

.chart-box { position: relative; width: 100%; overflow: hidden; }
.chart { display: block; max-width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick, .chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-dot, .chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.chart .direct-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .marker { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker-label { fill: var(--text-2); font-size: 11px; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .bar.active { opacity: 0.8; }
.chart .bar-value { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .group-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 0 0 8px; padding: 0; font-size: 0.85rem; color: var(--text-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: baseline; }
.chart-tip {
  display: none; position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 0.8rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
}

.table-toggle { margin-top: 8px; font-size: 0.85rem; }
.table-toggle summary { cursor: pointer; color: var(--accent); }
.data-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.table-toggle > div { overflow-x: auto; }

.share-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sources li { margin: 6px 0; font-size: 0.9rem; }
.sources details { margin-top: 12px; }
.sources summary { cursor: pointer; font-weight: 600; }
.method li { margin: 6px 0; font-size: 0.9rem; color: var(--text-2); }
.footer { color: var(--muted); font-size: 0.8rem; padding-bottom: 32px; }

.pay-method { grid-column: 1 / -1; border: 0; padding: 0; margin: 2px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pay-method legend { font-size: 0.85rem; color: var(--text-2); padding: 0; margin-bottom: 4px; width: 100%; }
.seg { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--page); color: var(--text); font-size: 0.95rem; cursor: pointer; flex: 1 1 8em; justify-content: center; }
.seg input { accent-color: var(--accent); margin: 0; }
.seg:has(input:checked) { border-color: var(--vc, var(--accent)); background: var(--surface-2); font-weight: 600; }
.seg:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.finance-fields { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.finance-fields[hidden] { display: none; }
.finance-fields .field input { background: var(--surface); }
.loan-summary { grid-column: 1 / -1; margin: 0; font-size: 0.9rem; color: var(--text-2); }
.loan-summary:empty { display: none; }
.loan-summary b { color: var(--text); }
.loan-summary .warn { color: var(--bad); }

.baseline { max-width: 26em; margin-bottom: 12px; }
.monthly-headline { margin: 0 0 12px; display: grid; gap: 8px; }
.monthly-headline p { margin: 0; font-size: 1.05rem; }
.monthly-headline .delta { font-weight: 700; white-space: nowrap; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.data-table.monthly { min-width: 100%; }
.data-table.monthly th, .data-table.monthly td { padding: 7px 8px; white-space: nowrap; }
.data-table.monthly thead th { vertical-align: bottom; font-weight: 600; color: var(--text); white-space: normal; min-width: 6.5em; }
.data-table.monthly thead th:first-child { min-width: 9em; }
.data-table.monthly th[scope=row] { text-align: left; font-weight: 400; color: var(--text-2); white-space: normal; }
.data-table.monthly tr.net th, .data-table.monthly tr.net td { font-weight: 700; color: var(--text); border-top: 2px solid var(--axis); font-size: 1.05rem; }
.data-table.monthly tr.vs th, .data-table.monthly tr.vs td { font-weight: 600; color: var(--text); }
.data-table.monthly tr.sub-head th { text-align: left; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding-top: 14px; border-bottom: 0; }
.data-table.monthly .baseline-col { background: var(--surface-2); }
.data-table.monthly .swatch { margin-right: 4px; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--good); }
.hero-month { margin: -6px 0 10px; color: var(--text); font-weight: 600; }

/* Keep the row labels visible while a wide table scrolls sideways (five cars on a phone). */
.data-table.monthly tr > :first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.data-table.monthly thead th { min-width: 5.5em; }
.data-table.monthly thead th:first-child { min-width: 7.5em; }
@media (max-width: 600px) {
  .data-table.monthly { font-size: 0.85rem; }
  .data-table.monthly th, .data-table.monthly td { padding: 6px 6px; }
  .data-table.monthly th[scope=row] { min-width: 7.5em; max-width: 8.5em; }
}

.fuel-sweep { max-width: 22em; margin-bottom: 12px; }
#chart-gas:empty { display: none; }
.chart-note { color: var(--text-2); margin: 4px 0 0; }

/* ---------- validation ---------- */
input[aria-invalid="true"] { border-color: var(--bad); outline: 2px solid var(--bad); outline-offset: 1px; }

/* ---------- export: half-page summary ---------- */
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.report-wrap { margin: 24px 0; }
.report-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.report-bar h2 { margin: 0 auto 0 0; font-size: 1.1rem; }
/* On screen the sheet is shown at print size (7.7in wide) so what you see is what prints. */
.report-sheet {
  box-sizing: border-box; width: 100%; max-width: 7.7in; padding: 0.18in 0.22in;
  background: #fff; color: #111; border: 1px solid #d4d4d0; border-radius: 6px;
  font: 8.2pt/1.25 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  overflow-x: auto;
}
.report-sheet .rp-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1.5px solid #111; padding-bottom: 2px; margin-bottom: 3px; }
.report-sheet h2 { font-size: 11pt; margin: 0; }
.report-sheet .rp-head span { font-size: 7.5pt; color: #444; }
.report-sheet p { margin: 2px 0; }
.report-sheet .rp-assume { font-size: 7.4pt; color: #222; }
.rp-table { width: 100%; border-collapse: collapse; margin: 3px 0; font-variant-numeric: tabular-nums; }
.rp-table th, .rp-table td { padding: 1px 4px; border-bottom: 0.5px solid #ddd; text-align: right; white-space: nowrap; }
.rp-table th[scope="row"] { text-align: left; font-weight: 500; color: #222; }
.rp-table thead th { font-weight: 700; border-bottom: 1px solid #111; white-space: normal; vertical-align: bottom; }
.rp-table tr.strong th, .rp-table tr.strong td { font-weight: 700; border-top: 1px solid #111; background: #f1f1ee; }
.cols-4 .rp-table { font-size: 7.4pt; }
.rp-find { margin: 3px 0; padding-left: 12px; }
.rp-find li { margin: 1px 0; }
.report-sheet .rp-notes, .report-sheet .rp-src { font-size: 6.8pt; color: #444; }

@media print {
  @page { size: letter portrait; margin: 0.4in; }
  html, body { background: #fff !important; color: #111 !important; margin: 0 !important; padding: 0 !important; }
  body.rp-print > :not(main), body.rp-print main > :not(#report), .no-print { display: none !important; }
  body.rp-print main.wrap { max-width: none !important; padding: 0 !important; margin: 0 !important; }
  body.rp-print #report { display: block !important; margin: 0; }
  /* Half of a US Letter page: 11in / 2 minus the 0.4in top margin = 5.1in max. */
  .report-sheet { max-width: none; width: 7.7in; max-height: 5.05in; overflow: hidden; border: 0; border-bottom: 0.5px dashed #999; border-radius: 0; padding: 0 0 0.05in; }
}

/* WCAG 2.2 target size on touch screens */
@media (pointer: coarse) { .btn.small, button.remove, .icon-btn { min-height: 32px; min-width: 32px; } }

/* ---- today's dollars, ranges, explainers ---- */
.mode-group .seg-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.range-line { margin: .35rem 0; }
.mode-tag { display: inline-block; font-size: .8rem; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2, #eef2f7); color: var(--text-2, #555); margin: .25rem 0; }
.hero-range { margin: .1rem 0 .2rem; font-size: .9rem; color: var(--text-2, #555); }
details.how { margin-top: .6rem; font-size: .88rem; }
details.how > summary { cursor: pointer; color: var(--accent, #1a5fb4); }
details.how .how-sec { margin: .5rem 0 .7rem; }
details.how h4 { margin: .3rem 0 .15rem; font-size: .9rem; }
details.how .how-val { font-weight: 400; color: var(--text-2, #555); }
details.how .how-lines { margin: 0; padding-left: 1.1rem; }
details.how .how-lines li { margin: .1rem 0; font-variant-numeric: tabular-nums; }
details.how .how-src { font-size: .8rem; margin: .2rem 0 0; }
details.charge-adj { grid-column: 1 / -1; margin-top: .4rem; }
details.charge-adj > summary { cursor: pointer; }
.field.inline { display: inline-flex; align-items: center; gap: .4rem; }
.field.inline input { width: 4.5rem; }
table.dep td { font-variant-numeric: tabular-nums; }
.rp-headline { font-weight: 700; }
.report-sheet .rp-notes, .report-sheet .rp-src, .report-sheet .rp-assume { margin: 2px 0; line-height: 1.25; }

/* Navigation, used-car inputs, reliability breakout (CALC lane) */
.site-nav { display: flex; gap: 16px; margin: 4px 0 0; font-size: 0.95rem; }
.site-nav a { color: var(--accent); padding: 4px 0; }
.site-nav a[aria-current="page"] { color: inherit; font-weight: 600; text-decoration: none; }
.condition-row { display: flex; gap: 12px; align-items: center; border: 0; padding: 0; margin: 0 0 8px; }
.used-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 8px; }
.used-fields[hidden] { display: none; }
.used-note { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted, #555); margin: 0; }
.cond-line { font-size: 0.8rem; color: var(--muted, #555); margin: 2px 0; }
.cond-line.low { color: #9a3412; }
.rel-car + .rel-car { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.rel-car > h4 { margin: 0 0 4px; }
.rel-card h3 { font-size: 1rem; margin: 4px 0; }
.rel-card h3 small { font-weight: 400; color: var(--muted, #555); }
.rel-card .table-wrap { overflow-x: auto; }
.rel-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.rel-table th, .rel-table td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.rel-live, .rel-vin { font-size: 0.85rem; margin: 6px 0; }
@media print { #reliability { display: none; } }
