body {
  --bg: #ffd166;
  background: var(--bg);
  transition: background-color 0.6s;
}

/* top band: home button on the left, level progress in the middle, picture "box lid" on the right */
#hud {
  position: fixed;
  inset: 0 0 auto 0;
  height: calc(max(8px, env(safe-area-inset-top)) + 64px);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 8px;
  pointer-events: none;
}

#progress {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.6);
}

#dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

#dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(20, 33, 61, 0.2);
}

#dots i.done {
  background: #118ab2;
}

#dots i.now {
  width: 18px;
  height: 18px;
  background: #ef476f;
  box-shadow: 0 0 0 3px #fff;
}

#stars {
  display: flex;
  gap: 2px;
  font-size: 24px;
}

#stars b {
  font-weight: normal;
  transition: filter 0.3s, opacity 0.3s;
}

#stars b.off {
  filter: grayscale(1);
  opacity: 0.35;
}

#box {
  position: fixed;
  z-index: 40;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

#box[hidden] {
  display: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#board {
  position: absolute;
  z-index: 0;
}

#board.done {
  z-index: 50;
}

#board canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#hintc {
  opacity: 0;
}

#hintc.on {
  animation: glow 1s ease-in-out infinite;
}

#whole {
  opacity: 0;
  transition: opacity 0.8s;
}

#whole.show {
  opacity: 1;
}

.piece {
  position: absolute;
  left: 0;
  top: 0;
  touch-action: none;
  will-change: transform;
  filter: drop-shadow(0 0.6vmin 0.5vmin rgba(0, 0, 0, 0.28));
  animation: pop 0.4s backwards;
}

.piece.lift {
  filter: drop-shadow(0 2vmin 1.6vmin rgba(0, 0, 0, 0.3));
  scale: 1.05;
}

.piece.snap {
  transition: transform 0.22s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.piece.locked {
  filter: none;
  animation: none;
}

.piece.hint {
  animation: wiggle 0.9s ease-in-out infinite;
}

#bravo {
  position: fixed;
  z-index: 60;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: none;
  justify-content: center;
  pointer-events: none;
  color: #fff;
  font-size: min(9vmin, 64px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0.6vmin 0.6vmin 0 #ef476f, -0.6vmin -0.6vmin 0 #118ab2;
}

#bravo.show {
  display: flex;
  animation: twist 1s infinite cubic-bezier(0.31, 0.44, 0.44, 1.65);
}

.star {
  position: fixed;
  z-index: 70;
  top: -10vh;
  font-size: 8vmin;
  pointer-events: none;
  animation: falling 2.6s linear forwards;
}

/* level up: the new grid builds itself, wordless */
#up,
#rest {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  background: rgba(20, 33, 61, 0.6);
}

#up.show,
#rest.show {
  display: grid;
}

.mini {
  display: grid;
  gap: 1.2vmin;
  width: min(50vmin, 360px);
  aspect-ratio: 1;
  padding: 2vmin;
  border-radius: 4vmin;
  background: #fff;
}

.mini i {
  border-radius: 1.2vmin;
  background: #8ac926;
  animation: happy 0.5s backwards calc(var(--i) * 0.08s);
}

/* eye rest after a few puzzles: look far away for 20 seconds, then the buttons appear */
#rest .card {
  display: grid;
  justify-items: center;
  gap: 4vmin;
  width: min(80vmin, 520px);
  padding: 6vmin;
  border-radius: 6vmin;
  background: #fff;
}

#rest .big {
  font-size: 18vmin;
  line-height: 1;
}

#rest .bar {
  width: 100%;
  height: 3vmin;
  border-radius: 2vmin;
  background: rgba(20, 33, 61, 0.12);
  overflow: hidden;
}

#rest .bar i {
  display: block;
  width: 0;
  height: 100%;
  background: #06d6a0;
}

#rest .buttons {
  display: none;
  gap: 6vmin;
}

#rest.ready .buttons {
  display: flex;
  animation: happy 0.5s;
}

#rest .buttons > * {
  width: 20vmin;
  height: 20vmin;
  max-width: 120px;
  max-height: 120px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 0;
  background: #8ac926;
  box-shadow: 0 1vmin 0 rgba(0, 0, 0, 0.18);
  font-size: min(10vmin, 60px);
  text-decoration: none;
}

#rest .bye {
  background: #8ecae6;
}

@keyframes fill {
  to { width: 100%; }
}

@keyframes pop {
  from { scale: 0; }
}

@keyframes glow {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@keyframes happy {
  0% { transform: scale(0.6); }
  50% { transform: scale(1.2) rotate(-6deg); }
  100% { transform: scale(1); }
}

@keyframes wiggle {
  0%, 100% { rotate: 0deg; scale: 1; }
  25% { rotate: -6deg; scale: 1.08; }
  75% { rotate: 6deg; scale: 1.08; }
}

@keyframes twist {
  0%, 100% { transform: rotate(0); }
  25%, 75% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

@keyframes falling {
  to { top: 110vh; transform: rotate(360deg); }
}
