/* Aly & Mimi — the music toggle (music agent).
   A hand-drawn harp in one sage line on a small translucent paper disc,
   bottom-right, clear of the safe area. Sound-waves breathe while it plays;
   a fine strike draws across when muted. Colours and motion from tokens.css. */

.am-music {
  position: fixed;
  right: max(14px, calc(env(safe-area-inset-right, 0px) + 10px));
  bottom: max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  z-index: 80;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--sage, #757d5e);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.94);
  transition:
    opacity var(--dur-slow, 900ms) var(--ease-out, ease-out),
    transform var(--dur-slow, 900ms) var(--ease-out, ease-out),
    visibility 0s linear var(--dur-slow, 900ms);
}

.am-music.is-shown {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

/* the paper disc: pale, a little translucent, a hairline pressed edge */
.am-music::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: rgba(248, 237, 228, 0.82);
  background:
    radial-gradient(circle at 36% 30%,
      color-mix(in srgb, var(--paper-light, #f8ede4) 94%, transparent) 0%,
      color-mix(in srgb, var(--paper, #f2d6ce) 80%, transparent) 78%);
  box-shadow:
    inset 0 0 0 0.75px color-mix(in srgb, var(--sage, #757d5e) 42%, transparent),
    inset 0 1px 1px rgba(255, 255, 255, 0.55),
    0 3px 10px -3px color-mix(in srgb, var(--sage-deep, #5f6749) 40%, transparent),
    0 1px 2px color-mix(in srgb, var(--sage-deep, #5f6749) 16%, transparent);
  -webkit-backdrop-filter: blur(6px) saturate(1.05);
  backdrop-filter: blur(6px) saturate(1.05);
  transition: transform var(--dur-quick, 320ms) var(--ease-out, ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .am-music:hover::before { transform: scale(1.05); }
}
.am-music:active::before { transform: scale(0.93); }

.am-music__icon {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  margin: 7px;
  overflow: visible;
}

.am-music__harp { transition: opacity var(--dur-base, 620ms) var(--ease-out, ease-out); }
.am-music[data-state="off"] .am-music__harp { opacity: 0.66; }

/* sound-waves: breathe gently while playing, fold away when muted */
.am-music__wave {
  transform-box: fill-box;
  transform-origin: 0% 50%;
  opacity: 0;
  transform: scaleY(0.6) translateX(-1px);
  transition:
    opacity var(--dur-base, 620ms) var(--ease-out, ease-out),
    transform var(--dur-base, 620ms) var(--ease-out, ease-out);
}
.am-music[data-state="on"] .am-music__wave { opacity: 0.85; transform: none; }
.am-music[data-state="on"] .am-music__wave--1 { animation: am-music-breathe 3.4s var(--ease-in-out, ease-in-out) 0.9s infinite alternate; }
.am-music[data-state="on"] .am-music__wave--2 { animation: am-music-breathe 3.4s var(--ease-in-out, ease-in-out) 1.6s infinite alternate; }

@keyframes am-music-breathe {
  from { opacity: 0.85; transform: none; }
  to   { opacity: 0.3;  transform: translateX(0.8px) scaleY(0.88); }
}

/* the strike: a single fine line that draws itself across when muted */
.am-music__strike {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition:
    stroke-dashoffset var(--dur-base, 620ms) var(--ease-out, ease-out),
    opacity var(--dur-quick, 320ms) var(--ease-out, ease-out);
}
.am-music[data-state="off"] .am-music__strike { stroke-dashoffset: 0; opacity: 0.9; }

/* focus: a fine sage ring drawn around the disc, same hand as the icon */
.am-music:focus { outline: none; }
.am-music:focus-visible::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1.25px solid var(--sage, #757d5e);
  opacity: 0.8;
}

/* phones: docked top-right, above the card's own paper band, where nothing
   interactive ever sits still — clear of the calendar/maps pills, the footer
   line, the swipe cue and the reply form with the keyboard up (QC round 2) */
@media (max-width: 640px) {
  .am-music {
    top: max(4px, calc(env(safe-area-inset-top, 0px) + 4px));
    bottom: auto;
    right: max(8px, calc(env(safe-area-inset-right, 0px) + 8px));
    transform: translateY(-8px) scale(0.94);
  }
  .am-music.is-shown { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .am-music,
  .am-music::before,
  .am-music__wave,
  .am-music__strike { transition-duration: 1ms; }
  .am-music[data-state="on"] .am-music__wave { animation: none; }
}

@media print {
  .am-music { display: none; }
}
