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

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

svg {
  display: block;
  max-width: 100%;
  height: auto;
}

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

ul,
ol {
  list-style: none;
}

a {
  color: currentColor;
}

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

  --font-family: "Roboto Condensed", sans-serif;

  --font-weight-body: 400;
  --font-weight-title: 700;

  --line-height-title: 1;
  --line-height-body: 1.4;

  --color-white: #fff;
  --color-black: #000;
  --color-neutral-50: #fafafa;
  --color-neutral-100: #f5f5f5;
  --color-neutral-200: #eeeeee;
  --color-neutral-300: #e0e0e0;
  --color-neutral-400: #bdbdbd;
  --color-neutral-500: #9e9e9e;
  --color-neutral-600: #757575;
  --color-neutral-700: #616161;
  --color-neutral-800: #424242;
  --color-neutral-900: #212121;

  --color-bg: var(--color-white);
  --color-text: var(--color-neutral-900);
  --color-stroke: var(--color-neutral-300);
}

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

h1 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-title);
  line-height: var(--line-height-title);
}

text {
  font-size: var(--font-size-sm);
  fill: currentColor;
}

main {
  width: min(calc(100% - 2rem), 80rem);
  margin: 4rem auto;
  min-height: calc(100svh - 8rem);
  display: flex;
  gap: 2rem;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

hgroup {
  text-align: center;
}

hgroup p {
  margin-block-start: 0.5em;
}

.segmented {
  --n: 3;

  --color-bg: var(--color-neutral-200);
  --color-selected: var(--color-white);
  --color-hover: var(--color-neutral-50);

  position: relative;
  isolation: isolate;
  border: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  border: 0.25rem solid var(--color-bg);
  border-radius: 9999px;
  background: var(--color-bg);

  legend {
    /* Screen reader only */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  input[type="radio"] {
    position: absolute;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
  }

  label {
    padding: 0.5rem 1.5rem;
    border-radius: 9999px;
    background: transparent;
    user-select: none;
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;

    input:not(:checked) + &:hover,
    input:not(:checked) + input:focus + & {
      background: var(--color-hover);
    }

    input:checked + & {
      anchor-name: --selected;
    }
  }

  &::before {
    content: "";
    position: absolute;
    border-radius: 9999px;
    background: var(--color-selected);
    z-index: -1;

    position-anchor: --selected;
    top: anchor(top);
    right: anchor(right);
    bottom: anchor(bottom);
    left: anchor(left);
    transition-property: top, right, bottom, left;
    transition-duration: 0.3s;
    transition-timing-function: ease-in-out;
  }
}

.chart-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.color-legend {
  width: min(100%, 30rem);

  .swatches {
    --swatch-size: 16px;
    --offset: calc(var(--swatch-size) / 2);
    clip-path: polygon(
      var(--offset) 0,
      calc(100% - var(--offset)) 0,
      100% var(--offset),
      calc(100% - var(--offset)) 16px,
      var(--offset) 16px,
      0 var(--offset)
    );
  }

  .annotations text {
    font-size: var(--font-size-md);
  }

  .axis .tick line {
    stroke: var(--color-bg);
  }
}

.chart {
  position: relative;
  width: 100%;
  display: grid;

  > * {
    grid-area: 1 / 1;
    width: 100%;
  }

  &.is-transitioning {
    pointer-events: none;
  }

  .tick {
    line {
      stroke: var(--color-stroke);
    }
  }

  .highlight {
    position: absolute;
    border: 1.5px solid var(--color-text);
    opacity: 0.5;
    visibility: hidden;

    &.is-visible {
      visibility: visible;
    }
  }
}

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--color-bg);
  background: color(from var(--color-bg) srgb r g b / 0.9);
  padding: 0.25rem 0.75rem;
  width: max-content;
  text-align: center;
  border: 1.5px solid var(--color);
  border-radius: 0.25rem;
  visibility: hidden;
  opacity: 0;
  transition-property: visibility, opacity;
  transition-duration: 0.15s;
  transition-timing-function: ease-in-out;

  &.is-visible {
    visibility: visible;
    opacity: 1;
  }

  .tooltip__title {
    font-size: var(--font-size-sm);
  }

  .tooltip__value {
    font-size: var(--font-size-md);
  }
}
