/* 听书「悬浮球」（透明玻璃质感）：
   离开听书页后，朗读由它接管 —— 音符转圈 = 正在朗读，停住 = 已暂停。
   出现在主导航的各个页面上（books / index / chart / archive / incense / profile），
   听书页自己不放（那页本身就是播放器）。

   结构：
     .books-listen-ball           定位容器（可拖动，left/top 由 JS 写）
       .books-listen-ball-shell   透明玻璃长条
         .books-listen-ball-cover 音符（转圈动画，点它进听书页）
         .books-listen-ball-toggle 播放 / 暂停（圆沟槽 + 沟槽里走一圈进度环）
           .books-listen-ball-ring   SVG 进度环（groove 底槽 + bar 进度）
         .books-listen-ball-close  叉号（关掉悬浮球并停止朗读）

   尺寸（用户一路要求「再小一点 / 再细一点」）：
     收起态 34×34（左端圆头、右端直角 = 胶囊从中间劈开，贴左边时镜像）
     展开态 高 34（长条变细），四角 9px 小圆弧
   ========================================================================== */

.books-listen-ball {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 380;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  /* 松手吸附 / 展开收起导致的位移，走一段动画；拖动中立刻关掉 */
  transition: left 200ms cubic-bezier(0.22, 0.61, 0.36, 1),
              top 200ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.books-listen-ball.is-dragging {
  transition: none;
}

/* 还没落位：先别露脸，也不要位移过渡。
   容器 CSS 是 top:0;left:0 —— 少了这条，换页时球会先在左上角亮一下再"跳"到边上去。 */
.books-listen-ball[data-placed='false'] {
  visibility: hidden;
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .books-listen-ball {
    transition: none;
  }
}

.books-listen-ball[hidden] {
  display: none !important;
}

.books-listen-ball-shell {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  /* 展开态是「四角圆弧的长条」，不是全圆胶囊 */
  border-radius: 9px;
  /* 玻璃质感：尽量透 + 背景模糊 + 内高光（用户要的就是「那种透明的」） */
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 16px rgba(33, 36, 31, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(16px) saturate(165%);
  -webkit-backdrop-filter: blur(16px) saturate(165%);
  cursor: grab;
}

/* ---- 收起态：像「胶囊从中间劈开」—— 圆头永远朝着屏幕内侧，直角贴着屏幕边。 ----
   贴右边 → 左端圆头 / 右端直角；贴左边 → 镜像过来。 ---- */
.books-listen-ball[data-state='collapsed'] .books-listen-ball-shell {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border-radius: 17px 0 0 17px;
}

.books-listen-ball[data-state='collapsed'][data-side='left'] .books-listen-ball-shell {
  border-radius: 0 17px 17px 0;
}

/* 拖动中一旦离开左右两边（跑到屏幕中间了）就变回正圆，
   松手吸回边上再变回半胶囊 —— 这是「可以拖但又只许停边上」的可视反馈。 */
.books-listen-ball[data-state='collapsed'][data-offedge='true'] .books-listen-ball-shell {
  border-radius: 50%;
}

.books-listen-ball[data-state='collapsed'] .books-listen-ball-body {
  display: none;
}

.books-listen-ball-body {
  display: flex;
  align-items: center;
  gap: 2px;
  animation: books-listen-ball-body-in 180ms ease;
}

@keyframes books-listen-ball-body-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .books-listen-ball-body {
    animation: none;
  }
}

.books-listen-ball[data-playing='false'] .books-listen-ball-shell {
  animation: none;
}

.books-listen-ball.is-dragging .books-listen-ball-shell {
  cursor: grabbing;
  box-shadow: 0 12px 26px rgba(33, 36, 31, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

/* ---- 音符（朗读中转圈，停住 = 暂停） ---- */
.books-listen-ball-cover {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.books-listen-ball-note {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  /* 跟随主体外观的主题色（本站只有 --accent-rgb，没有 --accent 变量） */
  color: rgb(var(--accent-rgb, 185, 65, 50));
  animation: books-listen-ball-spin 7s linear infinite;
}

.books-listen-ball-note svg {
  width: 17px;
  height: 17px;
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.6));
}

.books-listen-ball-note[data-tone='jade'] {
  color: #2e8b6f;
}

.books-listen-ball-note[data-tone='gold'] {
  color: #b17824;
}

.books-listen-ball-note[data-tone='ink'] {
  color: #243748;
}

.books-listen-ball[data-playing='false'] .books-listen-ball-note {
  animation-play-state: paused;
}

@keyframes books-listen-ball-spin {
  to { transform: rotate(360deg); }
}

/* ---- 播放 / 暂停：圆沟槽 + 沟槽里的一圈进度环 ---- */
.books-listen-ball-toggle {
  position: relative;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  /* 沟槽 = 比玻璃长条深一档（一层很淡的暗色 + 内阴影压出凹陷） */
  background: rgba(35, 38, 31, 0.09);
  box-shadow:
    inset 0 1px 2px rgba(33, 36, 31, 0.20),
    inset 0 -1px 0 rgba(255, 255, 255, 0.5);
  color: var(--ink, #23261f);
  cursor: pointer;
}

/* 进度环：贴在沟槽内侧，起点在 12 点方向 */
.books-listen-ball-ring {
  position: absolute;
  inset: 0;
  width: 26px;
  height: 26px;
  transform: rotate(-90deg);
  pointer-events: none;
  overflow: visible;
}

.books-listen-ball-ring-groove,
.books-listen-ball-ring-bar {
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.books-listen-ball-ring-groove {
  stroke: rgba(35, 38, 31, 0.14);
}

.books-listen-ball-ring-bar {
  stroke: rgb(var(--accent-rgb, 185, 65, 50));
  transition: stroke-dashoffset 320ms linear;
}

.books-listen-ball-toggle-face {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.books-listen-ball-toggle-face svg {
  width: 12px;
  height: 12px;
}

.books-listen-ball-icon-pause {
  display: none;
}

.books-listen-ball[data-playing='true'] .books-listen-ball-icon-pause {
  display: block;
}

.books-listen-ball[data-playing='true'] .books-listen-ball-icon-play {
  display: none;
}

/* ---- 书名（点它 = 进听书页） ---- */
.books-listen-ball-title {
  max-width: 104px;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--ink, #23261f);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

/* ---- 叉号 ---- */
.books-listen-ball-close {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(35, 38, 31, 0.55);
  cursor: pointer;
}

.books-listen-ball-close svg {
  width: 12px;
  height: 12px;
}

.books-listen-ball-close:hover,
.books-listen-ball-toggle:hover {
  background: rgba(35, 38, 31, 0.12);
}

@media (prefers-reduced-motion: reduce) {
  .books-listen-ball-note {
    animation: none;
  }
}
