:root {
  --ink: #2b2350;
  --paper: #fff3d1;
  --card: #ffffff;
  --pink: #ff4f8b;
  --pink-ink: #d62f6b;
  --blue: #2f80ff;
  --blue-ink: #1f5fd1;
  --orange: #ff9f1c;
  --teal: #1fc7b6;
  --purple: #8b5cf6;
  --green: #2dc76d;
  --yellow: #ffd23f;
  --miss: #ddd8e8;
  --spring: linear(0, 0.45 15%, 1.08 35%, 0.97 55%, 1.01 75%, 1);
  --font: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui,
    sans-serif;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-size: 1.125rem;
  line-height: 1.4;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle, rgb(255 79 139 / 0.16) 0.3rem, transparent 0.34rem),
    radial-gradient(circle, rgb(47 128 255 / 0.14) 0.3rem, transparent 0.34rem);
  background-size: 3rem 3rem;
  background-position: 0 0, 1.5rem 1.5rem;
}

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

:where(button):focus-visible {
  outline: 0.25rem solid var(--ink);
  outline-offset: 0.25rem;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 1rem;
  width: 100%;
  max-width: 34rem;
  min-height: 100dvh;
  margin-inline: auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

/* Scoreboard */

.scoreboard {
  display: grid;
  gap: 0.75rem;
}

.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.mode {
  min-height: 2.75rem;
  padding: 0.1rem 0.5rem 0.25rem;
  border: 0.1875rem solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 0.25rem 0 var(--ink);
  color: var(--purple);
  font: inherit;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    translate 120ms ease-out,
    box-shadow 120ms ease-out,
    background-color 150ms ease-out,
    color 150ms ease-out;
}

@media (hover: hover) {
  .mode:hover {
    background: #f3edff;
  }
}

.mode:active {
  translate: 0 0.2rem;
  box-shadow: 0 0.05rem 0 var(--ink);
}

.mode[aria-pressed='true'] {
  background: var(--purple);
  color: var(--card);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
}

.stat {
  display: grid;
  justify-items: center;
  padding: 0.4rem 0.5rem 0.5rem;
  border: 0.1875rem solid var(--ink);
  border-radius: 1rem;
  box-shadow: 0 0.25rem 0 var(--ink);
}

.stat-answered {
  background: var(--yellow);
}

.stat-streak {
  background: var(--pink);
}

.stat-best {
  background: var(--teal);
}

.stat dt {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.stat dd {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat dd.is-bumped {
  @media (prefers-reduced-motion: no-preference) {
    animation: bump 400ms var(--spring);
  }
}

@keyframes bump {
  40% {
    scale: 1.35;
  }
}

.dots {
  display: flex;
  justify-content: center;
  gap: clamp(0.25rem, 1.5vw, 0.5rem);
  margin: 0;
  padding: 0;
  list-style: none;
}

.dots li {
  --dot: var(--pink);

  width: clamp(1rem, 6vw, 1.5rem);
  aspect-ratio: 1;
  border: 0.1875rem solid var(--ink);
  border-radius: 50%;
  background: var(--card);
  transition: background-color 200ms ease-out;
}

.dots li:nth-child(2) { --dot: #ff7a45; }
.dots li:nth-child(3) { --dot: var(--orange); }
.dots li:nth-child(4) { --dot: var(--yellow); }
.dots li:nth-child(5) { --dot: #9be15d; }
.dots li:nth-child(6) { --dot: var(--green); }
.dots li:nth-child(7) { --dot: var(--teal); }
.dots li:nth-child(8) { --dot: var(--blue); }
.dots li:nth-child(9) { --dot: var(--purple); }
.dots li:nth-child(10) { --dot: #d65cf6; }

.dots li.is-filled {
  background: var(--dot);

  @media (prefers-reduced-motion: no-preference) {
    animation: bump 400ms var(--spring);
  }
}

/* Card */

.play {
  display: grid;
  align-content: center;
  gap: clamp(1.25rem, 5vh, 2.5rem);
  padding-block-end: 1rem;
}

.noscript {
  margin: 0;
  text-align: center;
}

.card {
  container-type: inline-size;
  padding: clamp(2rem, 9vh, 4rem) 1rem;
  border: 0.25rem solid var(--ink);
  border-radius: 2rem;
  background: var(--card);
  box-shadow: 0 0.5rem 0 var(--ink);
  text-align: center;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  transition:
    translate 450ms ease-out,
    rotate 450ms ease-out,
    border-color 150ms ease-out;
  transition-timing-function: var(--spring), var(--spring), ease-out;

  @media (prefers-reduced-motion: reduce) {
    transition-duration: 150ms, 150ms, 150ms;
    transition-timing-function: ease-out;
  }
}

.card.is-dragging {
  cursor: grabbing;
  transition: none;
}

.card.is-correct {
  border-color: var(--green);
}

.card.is-wrong {
  border-color: var(--pink-ink);
}

.problem {
  margin: 0;
  font-size: clamp(2rem, 11vw, 5.5rem);
  font-size: clamp(2rem, 14cqi, 5.5rem);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.problem .operand:nth-child(4n + 1) {
  color: var(--pink-ink);
}

.problem .operand:nth-child(4n + 3) {
  color: var(--blue-ink);
}

.problem .operator {
  color: var(--purple);
  margin-inline: 0.12em;
}

.problem .equals {
  margin-inline: 0.12em;
}

.problem .slot {
  display: inline-block;
  min-width: 1.4em;
  color: var(--orange);
}

.card.is-correct .slot,
.card.is-wrong .slot {
  color: var(--green);
}

/* Answer buttons */

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 5.5rem;
  padding: 0.5rem 1.25rem;
  border: 0.25rem solid var(--ink);
  border-radius: 1.5rem;
  color: var(--ink);
  font: inherit;
  font-size: clamp(2.25rem, 10vw, 3rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0.4rem 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    translate 120ms ease-out,
    box-shadow 120ms ease-out,
    scale 200ms ease-out,
    background-color 150ms ease-out,
    opacity 150ms ease-out;
}

.choice-left {
  background: var(--orange);
}

.choice-right {
  background: var(--teal);
}

.choice .arrow {
  font-size: 0.6em;
}

@media (hover: hover) {
  .choice:hover {
    box-shadow: 0 0.5rem 0 var(--ink);
    translate: 0 -0.1rem;
  }
}

.choice:active,
.choice.is-pressed {
  box-shadow: 0 0.1rem 0 var(--ink);
  translate: 0 0.3rem;
}

.choice.is-leaning {
  box-shadow: 0 0.4rem 0 var(--ink), 0 0 0 0.3rem var(--yellow);

  @media (prefers-reduced-motion: no-preference) {
    scale: 1.06;
  }
}

.choice.is-answer {
  background: var(--green);
}

.choice.is-miss {
  background: var(--miss);
  opacity: 0.75;
}

.choice.is-miss .value {
  text-decoration: line-through 0.12em;
}

/* Celebration */

.party {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: clip;
  pointer-events: none;
}

.cheer {
  display: grid;
  justify-items: center;
  margin: 0;
  padding: 1.25rem 2rem 1.5rem;
  border: 0.25rem solid var(--ink);
  border-radius: 2rem;
  background: var(--card);
  box-shadow: 0 0.5rem 0 var(--ink);
  text-align: center;
}

.cheer[hidden] {
  display: none;
}

.cheer-count {
  color: var(--pink-ink);
  font-size: clamp(4.5rem, 25vw, 7rem);
  font-weight: 700;
  line-height: 1;
}

.cheer-words {
  font-size: clamp(1.75rem, 8vw, 2.5rem);
  font-weight: 700;
  line-height: 1.1;
}

.piece {
  position: absolute;
  top: 50%;
  left: 50%;
  font-weight: 700;
  line-height: 1;
  -webkit-text-stroke: 0.04em var(--ink);
}
