/* The marble jar: a kudos counter. A clear glass jar with a rolled rim stands on the white page on its own soft
   shadow, full of cat's eye marbles drawn by the script, a kraft paper tag tied round its neck with twine; under it a
   round minus and a dark Give kudos pill, 58 pixels tall. The light comes from the top left. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1d2126;           /* the main button, and the words */
  --hairline: #e3ded5;      /* the edge of the minus button */
  --spent: #ece8e1;         /* the main button when the jar is full */
  --shadow: #2f2a22;        /* the shadows on the page under the jar */
  --caustic: #fff4d6;       /* the light the glass gathers into its own shadow */
  --glass: #dcebe7;         /* the jar's glass, a faint green */
  --glass-deep: #afc8c2;    /* the glass where it is thick */
  --glass-edge: #577c76;    /* the glass seen edge-on, at the sides */
  --glint: #ffffff;         /* reflections on the glass */
  --kraft: #dcc49c;         /* the paper tag */
  --kraft-dark: #c2a676;    /* its edges */
  --kraft-light: #ead8b6;   /* the ring round its hole */
  --tag-ink: #3a2c1c;       /* the number on the tag */
  --twine: #a57f55;         /* the string */
  --twine-dark: #7c5a36;    /* the string, in the shade */
  --twine-light: #dcc49f;   /* the string's twist, catching the light */
  --tomato: #c8372b;        /* the vanes of the first kind of marble, deep in the middle... */
  --tomato-light: #ff9156;  /* ...and bright at the tips */
  --cobalt: #1c4fc6;        /* the second kind */
  --cobalt-light: #61b4ff;  /* its tips */
  --jade: #0c8259;          /* the third kind */
  --jade-light: #5ed59b;    /* its tips */
  --marigold: #d08a00;      /* the fourth kind */
  --marigold-light: #ffd447; /* its tips */
  --violet: #6a3cc7;        /* the fifth kind */
  --violet-light: #b89aff;  /* its tips */
  --rose: #c0265e;          /* the sixth kind */
  --rose-light: #ff8fbb;    /* its tips */
  --focus: #2f6bff;         /* focus rings */
}

* {
  box-sizing: border-box;
}

/* quick taps on the buttons never become a double tap that zooms the page */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Bricolage Grotesque Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ---------------------------------------------------------------- the jar */
.kj {
  width: min(360px, 100%);
}

/* every measure inside follows the jar's width: a unit of the drawing is --u */
.kj__scene {
  --u: calc(100cqw / 340);
  position: relative;
  aspect-ratio: 340 / 396;
  border-radius: 28px;
  container-type: inline-size;
  cursor: grab;
  outline: none;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
}

.kj__scene.is-dragging {
  cursor: grabbing;
}

.kj__scene[data-still] {
  cursor: default;
}

/* the focus of the keys: a ring round the jar, over everything in it */
.kj__scene::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 2.5px var(--focus);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.kj__scene:focus-visible::after {
  opacity: 1;
}

.kj__layer,
.kj__move {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.kj__layer {
  overflow: visible;
}

.kj__move {
  will-change: transform;
}

/* a marble comes in from above the jar: the top of the canvas fades it in, so it never appears out of nowhere */
.kj__marbles {
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 13%);
  mask-image: linear-gradient(180deg, transparent 0, #000 13%);
}

/* the thick glass at the sides: what is behind it looks a little soft, as through a lens */
.kj__edge {
  position: absolute;
  -webkit-backdrop-filter: blur(1.1px) saturate(1.15);
  backdrop-filter: blur(1.1px) saturate(1.15);
}

/* ---------------------------------------------------------------- the tag */
.kj__tag {
  position: absolute;
  width: calc(var(--u) * 64);
  transform-origin: 50% 0;
  transform: translateX(-50%);
  filter: drop-shadow(calc(var(--u) * 1.5) calc(var(--u) * 3) calc(var(--u) * 2.5) rgba(60, 40, 15, 0.28));
  will-change: transform;
}

.kj__string {
  display: block;
  width: 100%;
  height: calc(var(--u) * 26);
  overflow: visible;
}

.kj__string-back,
.kj__string-front {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.1;
}

.kj__string-back {
  stroke: var(--twine-dark);
}

.kj__string-front {
  stroke: var(--twine);
}

.kj__card {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  height: calc(var(--u) * 84);
  margin-top: calc(var(--u) * -8);
  padding-top: calc(var(--u) * 19);
  color: var(--tag-ink);
  clip-path: polygon(24% 0, 76% 0, 100% 14%, 100% 100%, 0 100%, 0 14%);
  /* kraft paper: a soft light from the top left, darker edges, and the fibres, as two kinds of noise drawn by SVG */
  background:
    radial-gradient(120% 70% at 25% 12%, rgba(255, 250, 238, 0.5), rgba(255, 250, 238, 0) 60%),
    linear-gradient(90deg, rgba(120, 90, 50, 0.16), rgba(120, 90, 50, 0) 12%, rgba(120, 90, 50, 0) 88%, rgba(120, 90, 50, 0.18)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.36 0 0 0 0 0.25 0 0 0 0 0.12 0.9 0 0 0 -0.3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23f)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04 0.35' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 0.97 0 0 0 0 0.9 0 0 0.7 0 -0.36'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23g)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--kraft) 0%, var(--kraft-dark) 140%);
  background-size: auto, auto, calc(var(--u) * 70), calc(var(--u) * 80), auto;
}

/* the punched hole with its paper ring, and the string going through it */
.kj__hole {
  position: absolute;
  left: 50%;
  top: calc(var(--u) * 2.5);
  width: calc(var(--u) * 11);
  height: calc(var(--u) * 11);
  margin-left: calc(var(--u) * -5.5);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70, 60, 45, 0.55) 0 30%, var(--kraft-light) 33% 66%, rgba(120, 90, 50, 0.3) 70%, rgba(120, 90, 50, 0) 76%);
}

.kj__kicker {
  margin-right: -0.2em;
  font-size: calc(var(--u) * 8.4);
  font-weight: 650;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.62;
}

/* the number: a slot for each digit, and the digits roll through it */
.kj__count {
  display: flex;
  justify-content: center;
  height: 1.08em;
  margin-top: calc(var(--u) * 1);
  font-size: calc(var(--u) * 34);
  font-weight: 720;
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kj__slot {
  position: relative;
  width: 0.58em;
  height: 100%;
  overflow: hidden;
}

.kj__digit {
  position: absolute;
  inset: 0;
  text-align: center;
}

.kj__for {
  max-width: 92%;
  margin-top: calc(var(--u) * 2);
  overflow: hidden;
  font-size: calc(var(--u) * 9.5);
  font-weight: 520;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0.7;
}

/* ---------------------------------------------------------------- the buttons */
.kj__actions {
  display: flex;
  gap: 10px;
  padding-top: 14px;
}

.kj__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  outline: none;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.kj__btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.kj__btn--less {
  flex: none;
  width: 58px;
  padding: 0;
  border: 1.5px solid var(--hairline);
  background: var(--page);
  color: var(--ink);
}

.kj__btn--more {
  flex: 1;
  gap: 8px;
  padding: 0 22px;
  border: 0;
  background: var(--ink);
  color: var(--page);
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 6px 14px -8px rgba(29, 33, 38, 0.7);
}

@media (hover: hover) and (pointer: fine) {
  .kj__btn--less:not([aria-disabled='true']):hover {
    background: color-mix(in srgb, var(--hairline) 35%, var(--page));
  }

  .kj__btn--more:not([aria-disabled='true']):hover {
    background: color-mix(in srgb, var(--ink), #ffffff 9%);
  }
}

.kj__btn:active,
.kj__btn.is-held {
  transform: translateY(1px) scale(0.985);
}

.kj__btn:focus-visible {
  box-shadow: 0 0 0 3px var(--page), 0 0 0 5.5px var(--focus);
}

.kj__btn[aria-disabled='true'] {
  cursor: default;
  transform: none;
}

.kj__btn--less[aria-disabled='true'] {
  color: color-mix(in srgb, var(--ink) 30%, var(--page));
}

.kj__btn--more[aria-disabled='true'] {
  background: var(--spent);
  color: color-mix(in srgb, var(--ink) 62%, var(--page));
  box-shadow: none;
}

.kj__plus {
  transition: opacity 0.2s, width 0.2s;
}

.kj__btn--more[aria-disabled='true'] .kj__plus {
  width: 0;
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .kj__btn,
  .kj__btn:active,
  .kj__btn.is-held {
    transform: none;
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
  }
}
