/*
 * Background music player: "导航栏小蝶" — a small butterfly button in the navbar
 * (built by js/bgm.js). Tapping it opens a panel with the title, play / pause,
 * volume and a small level meter. The home page has no navbar, so there the
 * button floats in the top-right corner with the same look.
 */

/* ---------- placement ---------- */
.top-navbar.has-bgm {
  justify-content: flex-start;
}

.top-navbar.has-bgm > .top-brand {
  margin-right: auto;
}

/* the navbar's own 32px gap is too wide for this small button: sit 12px from the
   nav links (desktop) and 10px from the menu button (phones) */
.top-navbar .top-bgm {
  margin-left: -20px;
}

@media (max-width: 1050px) {
  .top-navbar .top-bgm {
    margin-left: 0;
    margin-right: -22px;
  }
}

.top-bgm {
  position: relative;
  flex: none;
}

.top-bgm.is-floating {
  position: fixed;
  top: calc(24px + env(safe-area-inset-top, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
  z-index: 60;
  view-transition-name: top-bgm;
  animation: topBgmIn var(--dur-l, 420ms) var(--ease-out, cubic-bezier(.22, 1, .36, 1)) both .25s;
}

@media (max-width: 760px) {
  .top-bgm.is-floating {
    top: calc(18px + env(safe-area-inset-top, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
  }
}

@keyframes topBgmIn {
  from { opacity: 0; transform: translateY(-6px) scale(.9); }
  to   { opacity: 1; transform: none; }
}

/* ---------- butterfly button ---------- */
.top-bgm-btn {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  padding: 8px;
  border: 1px solid rgba(171, 131, 235, .22);
  border-radius: 14px;
  background: rgba(20, 10, 34, .72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition:
    transform var(--dur-s, 180ms) var(--ease-out, ease),
    background-color var(--dur-m, 260ms) var(--ease-out, ease),
    border-color var(--dur-m, 260ms) var(--ease-out, ease),
    box-shadow var(--dur-l, 420ms) var(--ease-out, ease);
}

@media (hover: hover) {
  .top-bgm-btn:hover {
    background: rgba(185, 132, 255, .18);
    border-color: rgba(216, 180, 255, .4);
  }
}

.top-bgm-btn:active {
  transform: scale(.93);
}

.top-bgm.is-playing .top-bgm-btn {
  border-color: rgba(216, 180, 255, .45);
  box-shadow: 0 0 18px rgba(185, 132, 255, .35);
}

/* volume 0: a slash across the button */
.top-bgm-btn::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .85);
  transform: translate(-50%, -50%) rotate(-40deg) scaleX(0);
  transition: transform var(--dur-m, 260ms) var(--ease-out, ease);
}

.top-bgm.is-silent .top-bgm-btn::after {
  transform: translate(-50%, -50%) rotate(-40deg) scaleX(1);
}

/* ---------- butterfly (same wing technique as the travel map) ---------- */
.top-bgm-butterfly {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  perspective: 140px;
  pointer-events: none;
}

.top-bgm-butterfly img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.top-bgm-butterfly .wing-l {
  clip-path: polygon(0 0, 51% 0, 51% 100%, 0 100%);
  transform-origin: 51% 53%;
}

.top-bgm-butterfly .wing-r {
  clip-path: polygon(49% 0, 100% 0, 100% 100%, 49% 100%);
  transform-origin: 49% 53%;
}

.top-bgm-butterfly .body {
  clip-path: polygon(44% 0, 56% 0, 56% 100%, 44% 100%);
  z-index: 2;
}

.top-bgm.is-playing .top-bgm-butterfly .wing-l {
  animation: topBgmFlapL .55s ease-in-out infinite alternate;
}

.top-bgm.is-playing .top-bgm-butterfly .wing-r {
  animation: topBgmFlapR .55s ease-in-out infinite alternate;
}

@keyframes topBgmFlapL { to { transform: rotateY(52deg); } }
@keyframes topBgmFlapR { to { transform: rotateY(-52deg); } }

/* ---------- panel ---------- */
.top-bgm-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 5;
  width: 220px;
  padding: 14px;
  border: 1px solid rgba(216, 180, 255, .25);
  border-radius: 16px;
  background: rgba(16, 9, 28, .96);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  transform-origin: top right;
  transform: translateY(-6px) scale(.88);
  opacity: 0;
  visibility: hidden;
  transition:
    transform var(--dur-m, 260ms) var(--ease-out, ease),
    opacity var(--dur-s, 180ms) var(--ease-out, ease),
    visibility 0s linear var(--dur-m, 260ms);
}

.top-bgm.is-open .top-bgm-panel {
  transform: none;
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

/* little pointer toward the button */
.top-bgm-panel::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 16px;
  width: 10px;
  height: 10px;
  border-top: 1px solid rgba(216, 180, 255, .25);
  border-left: 1px solid rgba(216, 180, 255, .25);
  background: rgba(16, 9, 28, .96);
  transform: rotate(45deg);
}

.top-bgm-title {
  color: #f3eaff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

.top-bgm-sub {
  margin-top: 2px;
  color: rgba(226, 206, 255, .55);
  font-size: 10px;
  letter-spacing: .14em;
}

.top-bgm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.top-bgm-play {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #9257ff, #ae60ff);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(135, 76, 237, .35);
  transition: transform var(--dur-s, 180ms) var(--ease-out, ease);
}

@media (hover: hover) {
  .top-bgm-play:hover { transform: scale(1.06); }
}

.top-bgm-play:active { transform: scale(.92); }

.top-bgm-play svg {
  width: 16px;
  height: 16px;
}

.top-bgm-volume {
  flex: 1;
  min-width: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-y;
}

.top-bgm-volume::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 9px;
  background: linear-gradient(90deg, #d8b4ff var(--pct, 10%), rgba(216, 180, 255, .2) var(--pct, 10%));
}

.top-bgm-volume::-moz-range-track {
  height: 3px;
  border-radius: 9px;
  background: rgba(216, 180, 255, .2);
}

.top-bgm-volume::-moz-range-progress {
  height: 3px;
  border-radius: 9px;
  background: #d8b4ff;
}

.top-bgm-volume::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(185, 132, 255, .45), 0 0 14px rgba(185, 132, 255, .7);
  -webkit-appearance: none;
  transition: transform var(--dur-s, 180ms) var(--ease-out, ease);
}

.top-bgm-volume::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(185, 132, 255, .45);
}

.top-bgm-volume:active::-webkit-slider-thumb { transform: scale(1.2); }

.top-bgm-pct {
  flex: none;
  min-width: 30px;
  color: rgba(226, 206, 255, .7);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* level meter */
.top-bgm-eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  margin-left: auto;
}

.top-bgm-eq i {
  width: 2px;
  height: 3px;
  border-radius: 2px;
  background: #d8b4ff;
}

.top-bgm.is-playing .top-bgm-eq i {
  animation: topBgmEq .8s ease-in-out infinite alternate;
}

.top-bgm-eq i:nth-child(2) { animation-delay: .2s; }
.top-bgm-eq i:nth-child(3) { animation-delay: .4s; }

@keyframes topBgmEq { to { height: 12px; } }

.top-bgm-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .top-bgm.is-floating,
  .top-bgm.is-playing .top-bgm-butterfly img,
  .top-bgm.is-playing .top-bgm-eq i {
    animation: none !important;
  }
}

@media print {
  .top-bgm { display: none; }
}
