 		if started.get()
 			renderScores localScores
 
-renderButton = (buffer) !->
+renderButton = (finalReached, count, buffer) !->
+	animationDone = Obs.create finalReached.peek()
+	buttonText = Obs.create (if finalReached.peek() then "WINNER" else "Click")
+
 	buffering = Obs.create false
 	Dom.div !->
-		Dom.style _userSelect: 'none', textAlign: 'center', maxWidth: '700px', borderRadius: '10px', boxShadow: '0 0 10px #aaa', border: '4px solid '+Plugin.colors().highlight, padding: '10px 16px'
+		Dom.style
+			transition: 'border 6s ease'
+			_userSelect: 'none'
+			textAlign: 'center'
+			maxWidth: '700px'
+			borderRadius: '10px'
+			boxShadow: '0 0 10px #aaa'
+			padding: '10px 16px'
+		Obs.observe !->
+			Dom.style border: "4px solid #{if finalReached.get() then '#ffd700' else Plugin.colors().highlight}"
+
 		Dom.div !->
-			Dom.style textTransform: 'uppercase', fontWeight: 'bold', fontSize: '500%', color: Plugin.colors().highlight
-			Dom.text "Click"
-
-		Dom.onTap !->
-			buffering.set true
-			buffer.incr()
+			Dom.style
+				textTransform: 'uppercase'
+				fontWeight: 'bold'
+				fontSize: '500%'
+				transition: 'color 6s ease'
+			Obs.observe !->
+				Dom.style color: (if finalReached.get() then '#ffd700' else Plugin.colors().highlight)
+
+			Obs.observe !-> Dom.text buttonText.get()
+
+		Obs.observe !->
+			if not finalReached.get()
+				Dom.onTap !->
+					if count?.get() is (FINALNUMBER - 1)
+						finalReached.set true
+						Server.sync 'incr', 1
+					else
+						buffering.set true
+						buffer.incr()
+
+		buttonEl = Dom.get()
+		unless finalReached.peek()
+				Obs.observe !->
+					return unless finalReached.get() and not animationDone.get()
+					buttonEl.style transition: 'border 6s ease, transform 5s ease'
+
+					rotY = Obs.create 0
+					scl = Obs.create 1
+					Obs.observe !->
+						buttonEl.style transform: "rotateY(#{rotY.get()}deg) scale(#{scl.get()})"
+					spinning = Obs.create true
+					Obs.observe !->
+						if spinning.get()
+							Obs.interval 500, !->
+								rotY.set (rotY.get() + 360)
+							Obs.onTime 5000, !->
+								spinning.set false
+						else
+							buttonEl.style transition: 'border 6s ease, transform 1s ease, opacity 1s ease'
+							scl.set 10
+							buttonEl.style opacity: 0
+							Obs.onTime 1000, !->
+								scl.set 1
+								buttonEl.style opacity: 1
+								buttonText.set "WINNER"
+								Obs.onTime 1000, !->
+									animationDone.set true
 
 	Obs.observe !->
 		return unless buffering.get()

		oldScore = Db.shared.get('counters', App.userId()) ? 0
		newScore = oldScore + buffer.get()
		return if newScore is 0
		localScores.set 'counters', App.userId(), newScore
		started.set true

	Ui.card !->
		renderButton buffer
		renderMagic localScores
		renderFunny()


Plugin = require 'plugin'

BUFFER_TIME = 1000
FINALNUMBER = 1000000

exports.render = ->
	# create local copy of the scores
	localScores = Obs.create {}
	copied = {}
	started = Obs.create false
	finalReached = Obs.create (Db.shared.peek 'counters', App.userId() >= FINALNUMBER)
	Obs.observe !->
		Db.shared.iterate 'counters', (v) !->
			# just copy once!
