/* Tokens are documented in DESIGN.md. Change them there first. */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  --page: #ffffff;
  --ink: #151a21;
  --muted: #56606d;
  --line: #d4dae1;
  --accent: #1d4fb5;
  --save: #0a6f4c;
  --save-tint: #e9f5ef;
  --warn: #6d4600;
  --warn-tint: #fff3d6;

  --t-small: 0.875rem;
  --t-body: 1rem;
  --t-lede: 1.125rem;
  --t-h2: 1.375rem;
  --t-h1: clamp(1.625rem, 1.2rem + 1.6vw, 2.25rem);
  --t-price: 1.75rem;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 6px;
  --control: 44px;
  --ring: 0 0 0 2px var(--page), 0 0 0 5px var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #11151a;
    --ink: #e6eaef;
    --muted: #9ba6b2;
    --line: #2c343d;
    --accent: #90b3ff;
    --save: #5fd3a2;
    --save-tint: #13281f;
    --warn: #ffd98a;
    --warn-tint: #33280c;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 var(--t-body)/1.55 "IBM Plex Sans", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent); color: var(--page); }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

@media (hover: hover) and (pointer: fine) {
  a:hover { text-decoration-thickness: 2px; }
}

:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--ring);
  border-radius: 2px;
}

.wrap {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0 var(--s4);
}

p, li, dd { max-width: 60ch; text-wrap: pretty; }

time, .price, table, input, .summary { font-variant-numeric: tabular-nums; }
time { white-space: nowrap; }

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

/* Header and footer */

.site-header { border-bottom: 1px solid var(--line); }

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  min-height: 52px;
}

.brand {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  padding-block: var(--s3);
}

.site-header nav { display: flex; gap: var(--s4); }
.site-header nav a { padding-block: var(--s3); }

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--t-small);
  padding-block: var(--s5) var(--s6);
}

.footer-title { font-size: var(--t-body); margin: 0 0 var(--s2); color: var(--ink); }

.link-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--s4);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

.link-list a { display: block; padding-block: var(--s2); }

/* Text */

main.wrap { padding-block: var(--s5) var(--s7); }

h1, h2, h3 { font-weight: 600; text-wrap: balance; }
h1 { font-size: var(--t-h1); line-height: 1.15; letter-spacing: -0.015em; margin: 0 0 var(--s3); }
h2 { font-size: var(--t-h2); line-height: 1.25; margin: var(--s7) 0 var(--s3); }
h3 { font-size: var(--t-body); margin: var(--s5) 0 var(--s2); }

.byline { font-size: var(--t-small); color: var(--muted); margin: 0 0 var(--s4); }
.lede { font-size: var(--t-lede); margin: 0 0 var(--s5); }
.muted, .note, .cite { color: var(--muted); }
.sourced li + li { margin-top: var(--s3); }
.sourced .cite { margin-top: var(--s1); }
.note, .cite, .plan { display: block; font-size: var(--t-small); }
.plan { color: var(--ink); }

.fields { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s5); }
.fields dt { font-weight: 600; }
.fields dd { margin: 0; }

@media (max-width: 40rem) {
  .fields { grid-template-columns: 1fr; gap: 0; }
  .fields dd { margin-bottom: var(--s3); }
}

/* Calculator */

.calc h2 { margin-top: var(--s6); }

.calc-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
}

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

@media (min-width: 48rem) {
  .calc-form { grid-template-columns: 2.1fr 1.2fr 0.7fr 0.8fr auto; align-items: end; }
  .field-wide, .field-action { grid-column: auto; }
}

.field label {
  display: block;
  font-size: var(--t-small);
  font-weight: 600;
  margin-bottom: var(--s1);
}

.calc-form select, .calc-form input, .calc-form button {
  width: 100%;
  min-height: var(--control);
  font: inherit;
  font-size: var(--t-body);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--ink);
}

.calc-form select:focus-visible, .calc-form input:focus-visible { border-color: var(--accent); }
.calc-form input[aria-invalid="true"] { border-color: var(--warn); }

.calc-form button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--page);
  font-weight: 600;
  padding-inline: var(--s5);
  cursor: pointer;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

.calc-form button:disabled { opacity: 0.7; cursor: progress; }

@media (hover: hover) and (pointer: fine) {
  .calc-form button:hover { background: color-mix(in srgb, var(--accent) 86%, var(--ink)); }
}

.field-error:empty { display: none; }
.field-error { color: var(--warn); font-weight: 600; margin: var(--s2) 0 0; }

/* Result: the one loud element on the page */

.result { margin-top: var(--s5); }

.verdict {
  font-size: var(--t-h2);
  line-height: 1.3;
  font-weight: 600;
  margin: 0 0 var(--s1);
}

.summary { margin: 0 0 var(--s4); color: var(--muted); }

.faceoff {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.side {
  max-width: none;
  display: grid;
  grid-template-columns: 1fr;
  padding: var(--s4);
  gap: 0;
}

.side + .side { border-top: 1px solid var(--line); }
.side.is-cheaper { background: var(--save-tint); }

.side-name { font-weight: 600; margin-bottom: var(--s1); }

.tag {
  display: inline-block;
  margin-left: var(--s2);
  padding: 0 var(--s2);
  border: 1px solid currentColor;
  border-radius: var(--radius);
  color: var(--save);
  font-size: var(--t-small);
  line-height: 1.6;
}

.side .price {
  display: block;
  font-size: var(--t-price);
  line-height: 1.15;
  font-weight: 600;
  white-space: nowrap;
  grid-row: 2;
}

.side.is-cheaper .price { color: var(--save); }

.bar {
  display: block;
  grid-row: 3;
  height: 6px;
  margin: var(--s2) 0 var(--s2);
  width: var(--share);
  background: var(--muted);
  border-radius: 3px;
  transform-origin: left;
}

.side.is-cheaper .bar { background: var(--save); }

.result.is-fresh .bar { animation: grow 160ms cubic-bezier(0.2, 0.7, 0.2, 1); }

@keyframes grow { from { transform: scaleX(0.4); } }
@keyframes appear { from { opacity: 0.4; } }

/* Reduced motion keeps the cue but drops the movement. */
@media (prefers-reduced-motion: reduce) {
  .result.is-fresh .bar { animation-name: appear; }
}

.stale {
  max-width: none;
  background: var(--warn-tint);
  color: var(--warn);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  font-weight: 600;
  margin: 0 0 var(--s4);
}

/* Tables */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}

table { border-collapse: collapse; width: 100%; font-size: var(--t-small); }
th, td { text-align: left; vertical-align: top; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
thead th { font-weight: 600; color: var(--muted); }
tbody th { font-weight: 600; }
td .price, td strong { font-size: var(--t-body); font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
th .note a { display: inline-block; padding-block: var(--s1); }

/* Under 40rem a table row becomes a labelled block, so nothing scrolls sideways. */
@media (max-width: 40rem) {
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap th, .table-wrap td { display: block; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-wrap tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
  .table-wrap tbody tr:last-child { border-bottom: 0; }
  .table-wrap th, .table-wrap td { padding: var(--s1) 0; border: 0; }
  .table-wrap tr > :first-child { font-weight: 600; font-size: var(--t-body); padding-bottom: var(--s2); }
  .table-wrap td[data-label] { position: relative; padding-left: 8.5rem; }
  .table-wrap td[data-label]::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    width: 7.5rem;
    color: var(--muted);
  }
}
