/* ==========================================================================
   theme-zhihu — 音频播放条
   瞬间附件和正文里的 <audio controls> 原来是浏览器原生控件：灰底、不跟深色、
   不跟焦点色，各浏览器长得还不一样。这里换成主题自己的一条。

   播放键、名字与时间一行、进度在下一行。进度分三层：未加载的底轨、已缓冲、
   已播放，缓冲段让读者知道拖到哪里不会卡。外壳 8px 圆角，不描边，深浅色都走
   主题 token。整份文件只在「外观 → 自定义音频播放条」开启时才加载。

   外壳（瞬间的 .audio-item、正文的 figure[data-content-type="audio"]）由 CSS
   先画好，原生控件先藏起来，audio.js 接管后往同一个盒子里填内容，接管前后尺寸
   一致。禁用 JS 时 head.html 的 noscript 把原生控件放回来。
   ========================================================================== */

.audio-item,
.prose figure[data-content-type="audio"] {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 100%;
  height: 56px;
  padding: 0 16px 0 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

/* Halo 给正文的 figure 写了行内 flex-direction:column / align-items:start，
   那会把胶囊压成内容宽度并让控件顶到上沿。行内样式只能用 !important 压过去。 */
.prose figure[data-content-type="audio"] {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
}

.audio-item > audio,
.prose figure[data-content-type="audio"] > audio {
  display: none;
}

.audio-player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

/* ---------- 播放键 ---------- */

.audio-player__play {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-on);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

@media (hover: hover) and (pointer: fine) {
  .audio-player__play:hover { background: var(--accent-hover); }
}

.audio-player__play:active { transform: scale(0.92); }

.audio-player__play svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.audio-player__play[data-state="paused"] svg { margin-left: 1px; }

.audio-player.is-error .audio-player__play {
  background: var(--surface-3);
  color: var(--muted);
  cursor: default;
}

/* ---------- 名字 + 时间一行，进度在下一行 ---------- */

.audio-player__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.audio-player__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  line-height: 1.3;
}

.audio-player__name {
  min-width: 0;
  overflow: hidden;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- 进度 ---------- */

.audio-player__progress {
  position: relative;
  height: 14px;
  cursor: pointer;
  touch-action: none;
}

.audio-player__rail,
.audio-player__buffer,
.audio-player__fill {
  position: absolute;
  top: 50%;
  left: 0;
  height: 4px;
  transform: translateY(-50%);
  border-radius: var(--radius-pill);
  pointer-events: none;
}

.audio-player__rail {
  right: 0;
  background: var(--border-strong);
}

/* 已缓冲：比底轨深一档的中性色，和焦点色的已播段分得开，也不抢戏。 */
.audio-player__buffer {
  width: 0;
  background: color-mix(in srgb, var(--muted) 50%, transparent);
}

.audio-player__fill {
  width: 0;
  background: var(--accent);
}

.audio-player__thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%) scale(0.5);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--surface-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

@media (hover: hover) and (pointer: fine) {
  .audio-player__progress:hover .audio-player__thumb {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.audio-player__progress.dragging .audio-player__thumb,
.audio-player__progress:focus-visible .audio-player__thumb {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.audio-player__progress:focus-visible { outline: none; }

.audio-player__progress:focus-visible .audio-player__thumb {
  box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px rgba(var(--accent-rgb), 0.45);
}

.audio-player.is-error .audio-player__progress { display: none; }

.audio-player__hint {
  display: none;
  align-items: center;
  height: 14px;
  color: var(--muted);
  font-size: 11.5px;
}

.audio-player.is-error .audio-player__hint { display: flex; }

/* ---------- 时间 ---------- */

.audio-player__time {
  flex: none;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.audio-player__time .cur {
  color: var(--text-2);
}

.audio-player.is-error .audio-player__time { display: none; }

/* ---------- 手机 ---------- */

@media (max-width: 768px) {
  .audio-item,
  .prose figure[data-content-type="audio"] {
    height: 52px;
    padding: 0 12px 0 6px;
  }

  .audio-player { gap: 10px; }

  .audio-player__play {
    width: 28px;
    height: 28px;
  }

  .audio-player__play svg {
    width: 13px;
    height: 13px;
  }

  .audio-player__main { gap: 5px; }

  .audio-player__name { font-size: 12.5px; }

  .audio-player__progress,
  .audio-player__hint { height: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .audio-player__play,
  .audio-player__thumb { transition: none; }
}