/* The tick ring chart: a month of spending on a black page. A dial of 120 hairline ticks, a figure in the middle in
   Roboto Flex (a variable typeface: weight 100 to 1000, width 25 to 151, optical size 8 to 144) with tabular digits,
   and a key beside it. One accent, the other categories in greys. */
:root {
  --page: #000000;              /* the page */
  --ink: #f2f0eb;               /* the figure and the chosen category */
  --muted: #8b8a85;             /* the small texts */
  --tick-light: #b9b8b2;        /* the ticks of the largest category, at rest */
  --tick-dark: #3d3c39;         /* the ticks of the smallest category, at rest */
  --tick-dim: #1f1f1d;          /* the ticks of the others while one is chosen */
  --rule: #1c1c1a;              /* the hairline circle inside the ticks, and the rules of the key */
  --accent: #ff5b24;            /* the chosen category */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Roboto Flex Variable', 'Roboto Flex', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.spend {
  --ring: min(380px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: clamp(36px, 6vw, 72px);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- the ring */
.spend__ring {
  position: relative;
  flex: none;
  width: var(--ring);
  aspect-ratio: 1;
}

.spend__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* the reading in the middle */
.read {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  justify-items: center;
  gap: calc(var(--ring) * 0.012);
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
}

.read__label,
.read__note {
  display: grid;
  overflow: hidden;
  font-size: max(12px, calc(var(--ring) * 0.034));
  line-height: 1.25;
  font-variation-settings: 'wdth' 100, 'wght' 440;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

.read__label {
  color: var(--ink);
  font-variation-settings: 'wdth' 112, 'wght' 560;
}

.read__note {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* the words that change are stacked in the same cell, one going out while the next comes in */
.read__label > span,
.read__note > span {
  grid-area: 1 / 1;
  display: block;
  padding: 0.08em 0 0.14em;
}

.read__amount {
  display: flex;
  justify-content: center;
  font-size: calc(var(--ring) * 0.152);
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* every sign has its own fixed box, so a digit that grows heavier or narrower never moves its neighbours */
.ch {
  display: inline-block;
  width: 0.56em;
  text-align: center;
}

.ch--sep {
  width: 0.24em;
}

.ch--cur {
  width: 0.5em;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the key */
.key {
  display: grid;
  width: 220px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.key__item {
  appearance: none;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  width: 100%;
  margin: 0;
  padding: 10px 0 0;
  border: 0;
  background: none;
  color: #c9c7c1;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: color 0.35s ease;
}

.key__name {
  font-size: 15px;
  line-height: 1.2;
  font-variation-settings: 'wdth' var(--wd, 100), 'wght' var(--w, 420);
  white-space: nowrap;
}

.key__share {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-variation-settings: 'wdth' 100, 'wght' 420;
  color: var(--muted);
  transition: color 0.35s ease;
}

/* a hairline under every category, as long as its share next to the largest */
.key__rule {
  grid-column: 1 / -1;
  position: relative;
  height: 1px;
  margin-top: 9px;
  background: var(--rule);
}

.key__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: var(--c, var(--muted));
  transform-origin: 0 50%;
  transition: background-color 0.35s ease;
}

.key__item.is-on {
  color: var(--ink);
}

.key__item.is-on .key__share {
  color: var(--ink);
}

.key__item.is-on .key__fill {
  background: var(--accent);
}

.key.has-on .key__item:not(.is-on) {
  color: #5d5c58;
}

.key.has-on .key__item:not(.is-on) .key__share {
  color: #4a4946;
}

.key__item:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}

@media (max-width: 680px) {
  .spend {
    --ring: min(340px, calc(100vw - 32px));
    flex-direction: column;
    gap: 22px;
  }

  .key {
    width: var(--ring);
    grid-template-columns: 1fr 1fr;
    column-gap: 28px;
  }

  .key__name {
    font-size: 14px;
  }
}
