body {
  background: linear-gradient(160deg, #a9d6ff, #3a86ff 70%, #5a189a);
  color: #14213d;
}

.topbar {
  position: fixed;
  z-index: 40;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}

.lvl {
  height: 56px;
  padding: 0 18px;
  border-radius: 28px;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, 0.45);
  font-size: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.lvl.on {
  background: #fff;
  box-shadow: 0 0 0 4px #ffd166, 0 2px 8px rgba(0, 0, 0, 0.25);
}

.stars {
  position: fixed;
  z-index: 40;
  top: max(8px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 24px;
  font-weight: 800;
  gap: 6px;
}

#game {
  position: fixed;
  inset: max(80px, calc(env(safe-area-inset-top) + 72px)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  gap: 2vmin;
}

/* ---------- things to count ---------- */
.things {
  flex: 1;
  width: 100%;
  max-width: 130vmin;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 1.5vmin 2.5vmin;
  padding: 2vmin;
  border-radius: 6vmin;
  background: rgba(255, 255, 255, 0.35);
}

.thing {
  position: relative;
  border: none;
  background: none;
  font-size: var(--s, 15vmin);
  line-height: 1.1;
  padding: 0;
  transition: transform 0.15s;
}

.thing:active {
  transform: scale(0.9);
}

.thing.counted {
  filter: saturate(0.6);
  animation: happy 0.4s;
}

.thing .badge {
  position: absolute;
  right: -0.1em;
  bottom: -0.05em;
  min-width: 1.5em;
  height: 1.5em;
  display: none;
  place-items: center;
  border-radius: 50%;
  border: 0.12em solid #fff;
  background: #3a86ff;
  color: #fff;
  font-size: 0.32em;
  font-weight: 900;
  line-height: 1;
}

.thing.counted .badge {
  display: grid;
}

/* ---------- sums ---------- */
.sum {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5vmin;
  flex-wrap: wrap;
  align-content: center;
}

.group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 38vmin;
  padding: 2vmin;
  border-radius: 5vmin;
  background: rgba(255, 255, 255, 0.4);
  border: 0.8vmin dashed #fff;
  font-size: var(--s, 8vmin);
  line-height: 1.15;
}

.group .x {
  position: relative;
  opacity: 0.35;
}

.group .x::after {
  content: '✖';
  position: absolute;
  inset: 0;
  color: #ef476f;
  font-size: 0.9em;
}

.op, .eq {
  font-size: 12vmin;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0.8vmin 0 rgba(0, 0, 0, 0.25);
}

.eq .q.filled {
  animation: happy 0.6s;
  color: #ffd166;
}

/* ---------- answers ---------- */
.answers {
  display: flex;
  gap: 3vmin;
}

.ans {
  width: 20vmin;
  height: 20vmin;
  border-radius: 50%;
  border: max(6px, 1vmin) solid #fff;
  background: var(--c);
  color: #fff;
  font-size: 12vmin;
  font-weight: 900;
  box-shadow: 0 1.2vmin 0 rgba(0, 0, 0, 0.2);
  text-shadow: 0 0.6vmin 0 rgba(0, 0, 0, 0.2);
}

.ans:active {
  transform: translateY(0.8vmin) scale(0.97);
}

.ans.wrong {
  animation: shake 0.4s;
  opacity: 0.5;
}

.ans.right {
  animation: happy 0.6s;
  border-color: #ffd166;
}

/* ---------- celebration ---------- */
#bravo {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 12vmin;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1vmin 0 rgba(0, 0, 0, 0.3);
  pointer-events: none;
  white-space: nowrap;
}

#bravo.show {
  animation: bravo 1.1s ease-out;
}

.enter {
  animation: pop-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-1.5vmin); }
  75% { transform: translateX(1.5vmin); }
}

@keyframes happy {
  50% { transform: scale(1.15) rotate(-3deg); }
}

@keyframes bravo {
  0% { transform: translate(-50%, -50%) scale(0); }
  25% { transform: translate(-50%, -50%) scale(1.15); }
  70% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
