:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --border: #e2e1dd;
  --border-strong: #cfcec9;
  --text: #1a1a18;
  --text-2: #5c5b56;
  --text-3: #8a8883;
  --accent: #1f6f5c;
  --accent-soft: #e8f2ef;
  --warn: #a8641b;
  --warn-soft: #fdf3e7;
  --bad: #9d3427;
  --bad-soft: #fbecea;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1e1f23;
    --surface-2: #24252a;
    --border: #32343a;
    --border-strong: #43454d;
    --text: #ececea;
    --text-2: #a8a8a4;
    --text-3: #7c7c79;
    --accent: #5fbfa3;
    --accent-soft: #1c332d;
    --warn: #d99a4e;
    --warn-soft: #33281a;
    --bad: #d97a6c;
    --bad-soft: #33201d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1140px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

header.page { margin-bottom: 28px; }

header.page h1 {
  margin: 0 0 6px;
  font-size: 27px;
  letter-spacing: -0.02em;
  font-weight: 640;
}

header.page p {
  margin: 0;
  color: var(--text-2);
  max-width: 64ch;
}

header.page p.tagline-note {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

/* Grid and flex items default to min-width:auto, which lets the nowrap tables
   inside .scroll force the whole page wider than the viewport. */
.layout > *,
.panel,
.scroll { min-width: 0; }

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.panel.inputs {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.panel + .panel { margin-top: 18px; }

.panel h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.panel .sub {
  margin: 0 0 16px;
  color: var(--text-2);
  font-size: 13.5px;
}

/* ------------------------------------------------------------------- faq */

.panel.faq { margin-top: 18px; }

.faq details {
  border-top: 1px solid var(--border);
  padding: 13px 0;
}

.faq details:first-of-type { border-top: 0; padding-top: 2px; }
.faq details:last-of-type { padding-bottom: 0; }

.faq summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14.5px;
  list-style: none;
}

.faq summary::-webkit-details-marker { display: none; }

.faq summary::before {
  content: "+";
  display: inline-block;
  width: 16px;
  color: var(--accent);
  font-weight: 700;
}

.faq details[open] summary::before { content: "–"; }

.faq p {
  margin: 8px 0 0 16px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------------------------------------------------------------- forms */

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

fieldset legend {
  padding: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

label.field {
  display: block;
  margin-bottom: 11px;
  font-size: 13px;
  color: var(--text-2);
}

label.field span { display: block; margin-bottom: 4px; }

input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

label.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}

label.check input { margin: 3px 0 0; flex: none; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Which LTV band the current deposit/price actually falls into — derived
   from the plan, not a click target, so it's a plain highlight rather than
   a `.here`-style selected state. */
label.field.rate-row-active span { color: var(--accent); font-weight: 650; }
label.field.rate-row-active input { border-color: var(--accent); background: var(--accent-soft); }

details.advanced summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 6px 0;
}

button.primary {
  width: 100%;
  padding: 10px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

button.primary:hover { filter: brightness(1.08); }

/* ---------------------------------------------------------------- cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
}

.stat .k {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 620;
}

.stat .v {
  font-size: 23px;
  font-weight: 620;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.stat .n { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

/* ---------------------------------------------------------------- routes */

.routes { display: grid; gap: 12px; }

.route {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
}

/* "best" (cheapest) is marked by its border and the "saves £X" pill only —
   the strong fill belongs to "selected" (the route actually being costed),
   so the two don't compete for the same visual weight when they differ. */
.route.best { border-color: var(--accent); }

.route.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.route-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.route-head h3 { margin: 0; font-size: 15px; font-weight: 620; }

.route-cost {
  font-size: 21px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.route p.desc { margin: 5px 0 8px; font-size: 13.5px; color: var(--text-2); }

.route .saving {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 8px;
}

@media (prefers-color-scheme: dark) {
  .route.selected .saving { background: rgba(0,0,0,.25); }
}

.route ul { margin: 6px 0 0; padding-left: 17px; font-size: 12.5px; color: var(--text-2); }
.route ul li { margin-bottom: 3px; }

.tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text-2);
  vertical-align: middle;
}

.tag.current { background: var(--text-2); color: var(--surface); }

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

.chart-wrap { margin: 0 0 16px; }

svg.chart { width: 100%; height: auto; display: block; overflow: visible; }

svg.chart .chart-grid { stroke: var(--border); stroke-width: 1; }
svg.chart .chart-axis-line { stroke: var(--border-strong); stroke-width: 1; }

svg.chart .chart-axis {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  fill: var(--text-3);
}

svg.chart .chart-axis-title {
  font-size: 10.5px;
  font-weight: 620;
  letter-spacing: 0.02em;
  fill: var(--text-2);
}

svg.chart .chart-gap { fill: var(--warn-soft); opacity: 0.8; }

svg.chart .chart-gap-swatch { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1; }

svg.chart .chart-line-ref {
  fill: none;
  stroke: var(--warn);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

svg.chart .chart-zone-label {
  font-size: 9.5px;
  font-style: italic;
  fill: var(--text-3);
}

svg.chart .chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

svg.chart .chart-kink {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 1.5;
}

svg.chart .chart-marker {
  stroke: var(--text-3);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

svg.chart .chart-dot {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}

svg.chart .chart-line-interest { stroke: var(--warn); }
svg.chart .chart-dot-interest { fill: var(--warn); }

svg.chart .chart-allowance-line { stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 3 3; }

svg.chart .chart-allowance-label {
  font-size: 9.5px;
  font-weight: 650;
  fill: var(--bad);
}

svg.chart .chart-hit {
  fill: transparent;
  touch-action: none;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
}

.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; }

.chart-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
}

.chart-swatch-interest { background: var(--warn); }
.chart-swatch-allowance { background: var(--bad); }

.chart-caption .chart-reset {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

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

.scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

thead th {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 620;
  border-bottom: 1px solid var(--border-strong);
}

table.tight th, table.tight td { padding: 8px 7px; font-size: 13px; }

tbody tr.here { background: var(--accent-soft); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }

td.pos { color: var(--accent); }
td.neg { color: var(--bad); }

/* ---------------------------------------------------------------- notes */

.note {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}

.note.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.note.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.note.good { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.note ul { margin: 6px 0 0; padding-left: 18px; }

footer.disclaimer {
  margin-top: 26px;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.6;
}

.support {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-3);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.support:hover {
  background: var(--surface-2);
  color: var(--text-2);
}

.support img {
  width: 56px;
  height: 56px;
  border-radius: 4px;
  flex: none;
  /* The QR itself has no background — fixed white regardless of theme,
     since a transparent background loses all contrast against a dark
     page and makes it unscannable. */
  background: #fff;
  padding: 4px;
}

.support strong { color: var(--text-2); font-weight: 620; }
.support:hover strong { color: var(--accent); }

.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

.err {
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  color: var(--bad);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* --------------------------------------------------------------- responsive
   Must stay at the end of the file: a media query adds no specificity, so
   these only win if they come after the base rules they override — the
   stacked layout below only un-stickies the input panel because this block
   comes after the unconditional `.panel.inputs { position: sticky }` rule
   above; the same block used to sit near the top of the file and silently
   lost that fight, which is why the input panel used to cover the results
   on a narrow screen even though this rule looked correct in isolation. */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel.inputs {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
}

@media (max-width: 520px) {
  .wrap { padding: 22px 14px 60px; }
  .panel { padding: 15px; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  header.page h1 { font-size: 23px; }
  .stat .v { font-size: 20px; }
  .route-cost { font-size: 19px; }
  .route-head { gap: 4px; }
  th, td, table.tight th, table.tight td { padding: 7px 8px; }
}
