.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 80px;
  height: 78px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 500;
  visibility: hidden;
}

.back-to-top.visible {
  visibility: visible;
}

.back-to-top:hover img {
  scale: 1.15;
}

/* Flower */
.back-to-top img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(0);
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.3));
  transition: scale 0.25s ease;
}

/* Stem */
.back-to-top::before {
  content: '';
  position: absolute;
  bottom: -45px;
  left: 50%;
  width: 3.5px;
  height: 0;
  transform: translateX(-50%);
  background: linear-gradient(to top, #6b8c42, #8fa86e);
  border-radius: 3px;
  box-shadow: 1px 1px 4px rgba(46, 29, 16, 0.25);
  z-index: -1;
}

/* Enter animations */
@keyframes stem-grow {
  0% { height: 0; opacity: 0; }
  15% { opacity: 1; }
  100% { height: 80px; opacity: 1; }
}

@keyframes bloom {
  0% { transform: scale(0) rotate(-30deg); }
  60% { transform: scale(1.1) rotate(5deg); }
  80% { transform: scale(0.95) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.back-to-top.visible::before {
  animation: stem-grow 0.6s ease-out forwards;
}

.back-to-top.visible img {
  animation: bloom 0.5s ease-out 0.45s forwards;
}

/* Exit animations — MUST come after .visible rules to win by cascade */
@keyframes wilt {
  0% { transform: scale(1) rotate(0deg); }
  40% { transform: scale(1.05) rotate(3deg); }
  100% { transform: scale(0) rotate(30deg); }
}

@keyframes stem-shrink {
  0% { height: 80px; opacity: 1; }
  85% { opacity: 1; }
  100% { height: 0; opacity: 0; }
}

.back-to-top.hiding {
  visibility: visible;
}

.back-to-top.hiding img {
  animation: wilt 0.25s ease-in both;
}

.back-to-top.hiding::before {
  animation: stem-shrink 0.2s ease-in 0.15s both;
}

@media (min-width: 1300px) {
  .back-to-top {
    right: calc((87vw - 1120px) / 4);
  }
}
