/* Background music control: a small music button in the top-left corner that opens
   a soft pill with play/pause, mute and the bunny volume slider. */
.music-audio { display: none; }
.music {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 40;
  display: flex;
  align-items: center;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}
.music.is-unavailable { display: none; }
/* step aside while she's reading a note, a memory card or a zoomed picture */
.music { transition: opacity .25s ease, visibility 0s; }
body:has(.note-overlay, .memory-overlay, .photo-zoom) .music { opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility 0s .25s; }

.music-toggle {
  position: relative;
  z-index: 2;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 9px;
  border-radius: 50%;
  border: 2.5px solid var(--cocoa);
  background: rgba(255, 246, 248, .92);
  color: var(--cocoa);
  box-shadow: 0 6px 14px -8px rgba(122, 75, 71, .5);
  cursor: pointer;
  transition: transform .2s var(--ease-bounce), background .2s;
}
.music-toggle svg { display: block; width: 100%; height: 100%; }
.music-toggle:hover { transform: scale(1.06); }
.music-toggle:focus-visible { outline: 3px solid var(--candy); outline-offset: 3px; }
.music.is-playing:not(.is-muted) .music-toggle svg { animation: music-bob 1.6s ease-in-out infinite; }
.music.is-muted .music-toggle { color: var(--cocoa-soft); }
.music.is-muted .music-toggle::after {   /* a small strike when muted */
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 2.5px;
  border-radius: 2px;
  background: var(--rouge);
  rotate: -40deg;
}
@keyframes music-bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-1.5px) rotate(-6deg); } }

/* the pill that slides out from the button */
.music-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  margin-left: -20px;
  padding: 0 14px 0 26px;
  border-radius: 999px;
  border: 2.5px solid var(--cocoa);
  background: #FFF6F8;
  box-shadow: 0 6px 14px -8px rgba(122, 75, 71, .5);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-12px) scaleX(.85);
  transform-origin: left center;
  transition: opacity .2s ease, transform .3s var(--ease-soft), visibility 0s .3s;
}
.music.is-open .music-panel {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .2s ease, transform .3s var(--ease-soft), visibility 0s;
}
.music-btn {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 6px;
  border-radius: 50%;
  border: 2px solid var(--cocoa);
  background: var(--blush);
  color: var(--cocoa);
  cursor: pointer;
}
.music-btn svg { display: block; width: 100%; height: 100%; }
.music-btn:hover { background: var(--pastel); }
.music-btn:focus-visible { outline: 3px solid var(--candy); outline-offset: 2px; }

/* the bunny slider */
.bunny-slider {
  position: relative;
  flex: none;
  width: 118px;
  height: 36px;
  margin-left: 6px;
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.bunny-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 9px;
  translate: 0 -50%;
  border-radius: 99px;
  background: var(--blush);
  border: 2px solid var(--cocoa);
  overflow: hidden;
}
.bunny-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--cherry), var(--rouge));
}
.bunny-thumb {
  position: absolute;
  top: 50%;
  width: 30px;
  height: 30px;
  translate: -50% -58%;
  pointer-events: none;
  transition: scale .2s var(--ease-bounce);
  filter: drop-shadow(0 2px 2px rgba(122, 75, 71, .25));
}
.bunny-thumb svg { display: block; width: 100%; height: 100%; overflow: visible; }
/* ears droop when it's quiet and perk up as it gets louder */
.bunny-ear-l, .bunny-ear-r { transform-box: fill-box; transform-origin: 50% 95%; transition: transform .25s var(--ease-soft); }
.bunny-ear-l { transform: rotate(calc(-42deg + var(--perk, .5) * 34deg)); }
.bunny-ear-r { transform: rotate(calc(42deg - var(--perk, .5) * 34deg)); }
.bunny-eyes-shut { display: none; }
.bunny-slider.is-silent .bunny-eyes-open { display: none; }
.bunny-slider.is-silent .bunny-eyes-shut { display: inline; }
.bunny-slider.is-dragging .bunny-thumb, .bunny-slider:hover .bunny-thumb { scale: 1.12; }
.bunny-slider:focus-visible .bunny-track { outline: 3px solid var(--candy); outline-offset: 3px; }

/* if the browser blocked the music, a gentle nudge to start it */
.music-hint {
  position: absolute;
  left: 48px;
  top: 50%;
  margin: 0;
  padding: 6px 11px;
  translate: 0 -50%;
  border-radius: 999px;
  background: #FFF6F8;
  border: 2px solid var(--cocoa);
  font: 800 12px/1 var(--font-sans);
  color: var(--cocoa);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .3s ease;
}
.music.is-blocked:not(.is-open) .music-hint { opacity: 1; visibility: visible; }
.music.is-blocked .music-toggle { animation: music-nudge 1.8s ease-in-out infinite; }
@keyframes music-nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(251, 111, 146, .5); } 50% { box-shadow: 0 0 0 7px rgba(251, 111, 146, 0); } }

@media (prefers-reduced-motion: reduce) {
  .music-toggle svg, .music.is-blocked .music-toggle { animation: none !important; }
  .music-panel, .bunny-ear-l, .bunny-ear-r, .bunny-thumb { transition: none; }
}
