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

* {
  margin: 0;
  padding: 0;
}

body {
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

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

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

p {
  text-wrap: pretty;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
}

ul,
ol {
  list-style: none;
}

a {
  color: currentColor;
}

:root {
  --font-family: "IBM Plex Sans Condensed", sans-serif;

  --font-size-sm: 0.8rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.563rem;
  --font-size-2xl: 1.953rem;
  --font-size-3xl: 2.441rem;
  --font-size-4xl: 3.052rem;
  --font-size-5xl: 3.815rem;

  --font-weight-bold: 700;
  --font-weight-normal: 400;

  --color-background: #f8f5eb;
  --color-background-alt: #eee4cc;
  --color-body: #15130f;
  --color-heading: #c13d49;
  --color-animal-protein: #c13d49;
  --color-plant-protein: #771d3b;
  --color-fat: #df9234;
  --color-carbohydrates: #ecc141;
  --color-size-legend-stroke: #c2beb9;
}

body {
  font-family: var(--font-family);
  font-weight: var(--font-weight-normal);
  font-size: var(--font-size-md);
  line-height: 1.4;
  color: var(--color-body);
  background-color: var(--color-background);
}

h1,
h2 {
  font-weight: var(--font-weight-bold);
  line-height: 1;
  color: var(--color-heading);
  text-transform: uppercase;
}

h1 {
  font-size: var(--font-size-3xl);
  margin-block-end: 0.75em;
}

h1 + p {
  font-size: var(--font-size-lg);
}

h2 {
  font-size: var(--font-size-lg);
  margin-block-end: 0.75em;
}

p + p {
  margin-block-start: 1em;
}

main,
header,
footer {
  width: min(100% - 4rem, 90rem);
  margin: 4rem auto;
  position: relative;
}

.small-multiples,
header,
footer {
  --width: 20rem;
  --gap: 2rem;
  display: grid;
  grid-gap: var(--gap);
  grid-template-columns: repeat(auto-fill, min(100%, var(--width)));
  justify-content: center;
}

.color-legend {
  display: grid;
  grid-template-areas:
    ". top ."
    "left swatches right"
    ". bottom .";
  grid-template-columns: repeat(3, auto);
  grid-template-rows: repeat(3, auto);
  align-items: center;
  justify-items: center;
  gap: 0.5em;
  width: min-content;
}

.color-legend [data-area="top"] {
  grid-area: top;
  text-align: center;
}

.color-legend [data-area="right"] {
  grid-area: right;
  text-align: left;
  width: min-content;
  justify-self: left;
}

.color-legend [data-area="bottom"] {
  grid-area: bottom;
  text-align: center;
}

.color-legend [data-area="left"] {
  grid-area: left;
  text-align: right;
  width: min-content;
  justify-self: right;
}

.color-legend [data-area="swatches"] {
  grid-area: swatches;
  max-width: revert;
}

.color-legend .swatch {
  stroke: var(--color-background);
}

.size-legend .tick__rect {
  fill: none;
  stroke: var(--color-size-legend-stroke);
}

.chart {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 0.5em;
  padding: 1em;
  border-radius: 1em;
  background-color: var(--color-background);
  border: 1px solid transparent;
  transform: background-color 0.1s, border-color 0.1s;
}

.chart.active {
  background-color: var(--color-background-alt);
  border-color: currentColor;
}

.chart .chart__title {
  font-weight: var(--font-weight-bold);
}

.chart .chart__rect {
  stroke: var(--color-background);
}

.chart.active .chart__rect {
  stroke: var(--color-body);
}

.panel {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(100% - 4rem, 20rem);
  background-color: var(--color-background-alt);
  border-radius: 1rem;
  padding: 1rem;
  border: 1px solid currentColor;
  box-shadow: 0px 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.panel input {
  width: 100%;
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--color-background);
}

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  background-color: var(--color-background-alt);
  padding: 1em;
  border-radius: 1em;
  border: 1px solid currentColor;
  box-shadow: 0px 10px 15px -3px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: opacity 0.1s, visibility 0.1s;
}

.tooltip.visible {
  opacity: 0.95;
  visibility: visible;
}

.tooltip table {
  border-collapse: collapse;
}

.tooltip th,
.tooltip td {
  padding: 0.25em 0.5em;
  text-align: right;
}

.tooltip th {
  font-weight: var(--font-weight-bold);
}

.tooltip td {
  white-space: nowrap;
}

.tooltip .swatch {
  font-weight: var(--font-weight-normal);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.tooltip .swatch__swatch {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  transform: rotate(45deg);
}

.tooltip [data-compare="above"]::after {
  content: "↑";
}

.tooltip [data-compare="below"]::after {
  content: "↓";
}
