:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --focus: #2a78d6;
  --alert: #d03b3b;

  /* One colour per place a pound of salary can go, the same in every chart. */
  --c-takehome: #008300;
  --c-tax: #e87ba4;
  --c-ni: #2a78d6;
  --c-loan: #eb6834;
  --c-pension: #1baf7a;
  --c-car: #eda100;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --focus: #3987e5;
    --alert: #e66767;

    --c-tax: #d55181;
    --c-ni: #3987e5;
    --c-loan: #d95926;
    --c-pension: #199e70;
    --c-car: #c98500;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, p, ul, dl, dd, figure {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Page frame */

.masthead,
.layout,
.footnotes {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  padding-top: 32px;
  padding-bottom: 24px;
}

.masthead h1 {
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.masthead p {
  max-width: 62ch;
  margin-top: 6px;
  color: var(--ink-2);
}

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

@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  .masthead,
  .layout,
  .footnotes {
    padding-left: 16px;
    padding-right: 16px;
  }
}

.footnotes {
  padding-top: 32px;
  padding-bottom: 48px;
  color: var(--ink-2);
  font-size: 13px;
}

.footnotes h2 {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 14px;
}

.footnotes ul,
.notes {
  max-width: 80ch;
  padding-left: 18px;
  list-style: disc;
}

.footnotes li + li,
.notes li + li {
  margin-top: 4px;
}

/* Form */

.inputs,
.cars,
.results {
  display: grid;
  gap: 16px;
  min-width: 0;
}

fieldset {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

legend {
  float: left; /* lets the legend sit inside the grid rather than on the border */
  grid-column: 1 / -1;
  padding: 0;
  font-weight: 600;
}

.field,
.check {
  grid-column: 1 / -1;
}

.field.half {
  grid-column: span 1;
}

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* inputs must shrink to the column */
  gap: 4px;
  align-content: start;
}

.field > span:first-child {
  color: var(--ink-2);
  font-size: 13px;
}

input,
select,
button {
  font: inherit;
  color: inherit;
}

.field > input,
.field > select,
.input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--page);
}

.field > input,
.field > select {
  padding: 0 10px;
}

.input {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}

.input i {
  flex: none;
  color: var(--muted);
  font-style: normal;
}

.input input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0;
  border: 0;
  outline: 0;
  background: none;
}

.input:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.check input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--focus);
}

.check small {
  display: block;
  color: var(--ink-2);
  font-size: 13px;
}

/* CO2 and range do not affect an electric car's tax. */
.car:has(select[name="fuel"] option[value="electric"]:checked) .combustion {
  display: none;
}

.car:has(select[name="fuel"] option[value="electric"]:checked) .price {
  grid-column: 1 / -1;
}

.field small {
  color: var(--muted);
}

.button,
.remove {
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 600;
}

.remove {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 3px 10px;
  color: var(--ink-2);
  font-size: 13px;
}

.button:hover,
.remove:hover {
  border-color: var(--ink-2);
  color: var(--ink);
}

/* Results */

/* Hold the last render while a recalculation is in flight. */
.results.htmx-request {
  opacity: 0.6;
  transition: opacity 150ms 200ms;
}

.panel,
.card,
.notice {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.panel h2,
.card h2 {
  font-size: 16px;
  line-height: 1.3;
}

.panel-sub,
.chart figcaption p {
  margin-top: 2px;
  color: var(--ink-2);
  font-size: 13px;
}

.notice {
  border-color: var(--alert);
}

.notice ul {
  margin-top: 6px;
  padding-left: 18px;
  list-style: disc;
}

.notes {
  color: var(--ink-2);
  font-size: 13px;
}

/* Car cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.card header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}

.card h2 {
  overflow-wrap: anywhere;
}

.badge {
  flex: none;
  padding: 1px 8px;
  border: 1px solid var(--axis);
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
}

.meta,
.stat-sub,
.caption,
.car-note {
  color: var(--ink-2);
  font-size: 13px;
}

.stat {
  margin-top: 14px;
  color: var(--ink-2);
}

.stat b {
  margin-right: 2px;
  color: var(--ink);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.car-note {
  margin-top: 10px;
}

.sums {
  margin-top: 16px;
  font-variant-numeric: tabular-nums;
}

.sums div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-top: 1px solid var(--grid);
}

.sums dt {
  color: var(--ink-2);
}

.sums .total {
  border-top-color: var(--axis);
  font-weight: 600;
}

.sums .total dt {
  color: var(--ink);
}

/* Cost-by-tax-year columns */

.columns {
  display: flex;
  margin-top: 18px;
}

.col {
  flex: 1;
  min-width: 0;
  text-align: center;
  border-radius: 4px;
}

.col-plot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 96px;
  border-bottom: 1px solid var(--axis);
}

.col-value {
  padding-bottom: 3px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.col-bar {
  width: min(24px, 60%);
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}

.col-x {
  display: block;
  padding-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.caption {
  margin-top: 6px;
}

/* Stacked bar charts */

.c-takehome { background: var(--c-takehome); }
.c-tax { background: var(--c-tax); }
.c-ni { background: var(--c-ni); }
.c-loan { background: var(--c-loan); }
.c-pension { background: var(--c-pension); }
.c-car { background: var(--c-car); }

.seg,
.col-bar,
.legend i {
  forced-color-adjust: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 14px;
  color: var(--ink-2);
  font-size: 13px;
}

.legend li {
  display: flex;
  gap: 6px;
  align-items: center;
}

.legend i {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.bars {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.bar-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 12px;
  margin-bottom: 4px;
  font-size: 13px;
}

.bar-note {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.track {
  border-left: 1px solid var(--axis);
}

.stack {
  display: flex;
  gap: 2px;
  height: 20px;
}

.seg {
  flex: 0 0 0;
  min-width: 1px;
}

.seg:last-child {
  border-radius: 0 4px 4px 0;
}

.seg:hover,
.seg:focus-visible,
.col:hover .col-bar,
.col:focus-visible .col-bar {
  filter: brightness(1.15);
}

.axis {
  position: relative;
  height: 18px;
  border-top: 1px solid var(--grid);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.axis span {
  position: absolute;
  top: 3px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.axis span:first-child {
  transform: none;
}

.axis span:last-child {
  transform: translateX(-100%);
}

/* Tables */

.scroll {
  margin-top: 12px;
  overflow-x: auto;
}

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

th,
td {
  padding: 7px 0 7px 16px;
  border-top: 1px solid var(--grid);
  text-align: right;
  white-space: nowrap;
}

thead th {
  border-top: 0;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 400;
  vertical-align: bottom;
  white-space: normal;
}

th:first-child {
  padding-left: 0;
  text-align: left;
}

tbody th {
  color: var(--ink-2);
  font-weight: 400;
}

tr.strong th,
tr.strong td {
  border-top-color: var(--axis);
  color: var(--ink);
  font-weight: 600;
}

sup {
  color: var(--muted);
}

.employer {
  margin-top: 12px;
}

/* Chart tooltip */

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
  font-size: 13px;
  pointer-events: none;
}

.tooltip b {
  display: block;
  font-variant-numeric: tabular-nums;
}

.tooltip span {
  color: var(--ink-2);
}
