/* 详情页故事朗读 — 单行播放条 + 明确播放态 */
.story-tts {
  --stts-accent: #ff522b;
  --stts-accent-rgb: 255, 82, 43;
  --stts-ink: #1f2937;
  --stts-muted: #6b7280;
  --stts-line: rgba(17, 24, 39, .09);
  --stts-bg: #f3f4f6;
  --stts-bg-play: #fff4f1;
  margin: 0 0 .75rem;
  max-width: 100%;
}

.story-tts *,
.story-tts *::before,
.story-tts *::after {
  box-sizing: border-box;
}

.story-tts button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  font: inherit;
  line-height: 1;
  vertical-align: middle;
  box-shadow: none !important;
  outline: none;
  text-decoration: none;
  float: none;
  width: auto;
  max-width: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.story-tts button:focus-visible {
  outline: 2px solid rgba(var(--stts-accent-rgb), .45);
  outline-offset: 2px;
}

.story-tts [hidden] {
  display: none !important;
}

/* —— 入口 —— */
.story-tts-entry {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
}

.story-tts-start {
  gap: .4rem;
  min-height: 2rem;
  padding: .32rem .9rem .32rem .72rem;
  border: 0;
  border-radius: 999px;
  background: var(--stts-accent);
  color: #fff;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .02em;
  transition: filter .15s ease, transform .15s ease;
}

.story-tts-start:hover { filter: brightness(1.05); }
.story-tts-start:active { transform: scale(.98); }

.story-tts-start.is-disabled,
.story-tts-start:disabled {
  background: #d1d5db;
  color: #fff;
  cursor: not-allowed;
  filter: none !important;
  transform: none !important;
  opacity: .72;
  box-shadow: none !important;
}

.story-tts-start.is-disabled:hover,
.story-tts-start:disabled:hover {
  filter: none;
}

.story-tts-start .tts-label-short {
  display: none;
}

.story-tts.is-view-en .story-tts-start:not(.is-disabled):not(:disabled) {
  background: #2563eb;
}

.story-tts-start-ico {
  display: inline-flex;
  width: 1.1rem;
  height: 1.1rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
}

.story-tts-caret {
  width: 0;
  height: 0;
  margin-left: .1rem;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid rgba(255, 255, 255, .9);
}

.story-tts-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 9.5rem;
  padding: .3rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--stts-line);
  box-shadow: 0 10px 28px -14px rgba(17, 24, 39, .45);
}

.story-tts-menu-item {
  width: 100%;
  justify-content: flex-start !important;
  min-height: 2rem;
  padding: 0 .7rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--stts-ink);
  font-size: .8125rem;
  font-weight: 650;
}

.story-tts-menu-item:hover {
  background: rgba(var(--stts-accent-rgb), .08);
  color: var(--stts-accent);
}

.story-tts-lang-tag {
  flex: 0 0 auto;
  font-size: .625rem;
  font-weight: 700;
  color: var(--stts-accent);
  background: rgba(var(--stts-accent-rgb), .1);
  border-radius: 999px;
  padding: .2rem .4rem;
  line-height: 1;
  white-space: nowrap;
}

/* —— 面板 —— */
.story-tts-panel {
  width: 100%;
  border: 1px solid var(--stts-line);
  border-radius: 10px;
  background: var(--stts-bg);
  overflow: hidden;
  transition: background .2s ease, border-color .2s ease;
}

.story-tts.is-playing .story-tts-panel {
  background: var(--stts-bg-play);
  border-color: rgba(var(--stts-accent-rgb), .22);
}

.story-tts-loading,
.story-tts-player {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: .55rem;
  min-height: 2.35rem;
  height: 2.35rem;
  padding: 0 .55rem 0 .45rem;
}

.story-tts-loading {
  color: var(--stts-muted);
  font-size: .75rem;
  font-weight: 600;
}

.story-tts-loading-copy {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
}

.story-tts-spin {
  flex: 0 0 auto;
  width: .72rem;
  height: .72rem;
  border: 2px solid rgba(var(--stts-accent-rgb), .2);
  border-top-color: var(--stts-accent);
  border-radius: 50%;
  animation: story-tts-spin .7s linear infinite;
}

/* 合成中右侧小波形 */
.story-tts-eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  margin-left: auto;
}

.story-tts-eq i {
  display: block;
  width: 2px;
  height: 40%;
  border-radius: 1px;
  background: rgba(var(--stts-accent-rgb), .55);
  animation: story-tts-eq .9s ease-in-out infinite;
}

.story-tts-eq i:nth-child(1) { animation-delay: 0s; height: 45%; }
.story-tts-eq i:nth-child(2) { animation-delay: .12s; height: 80%; }
.story-tts-eq i:nth-child(3) { animation-delay: .24s; height: 55%; }
.story-tts-eq i:nth-child(4) { animation-delay: .36s; height: 70%; }

/* —— 播放按钮：用 class 切换图标，不用 SVG hidden —— */
.story-tts-play {
  position: relative;
  flex: 0 0 auto;
  align-self: center;
  width: 1.7rem;
  height: 1.7rem;
  min-width: 1.7rem;
  max-width: 1.7rem;
  min-height: 1.7rem;
  max-height: 1.7rem;
  border: 0;
  border-radius: 50% !important;
  background: var(--stts-accent);
  color: #fff;
  padding: 0 !important;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}

.story-tts-play:hover {
  filter: brightness(1.04);
}

.story-tts-play:active {
  transform: scale(.94);
}

.story-tts.is-playing .story-tts-play {
  box-shadow: 0 0 0 3px rgba(var(--stts-accent-rgb), .18);
}

.story-tts-play .ico-play,
.story-tts-play .ico-pause {
  display: block;
  pointer-events: none;
}

.story-tts-play .ico-pause {
  display: none;
}

.story-tts.is-playing .story-tts-play .ico-play {
  display: none;
}

.story-tts.is-playing .story-tts-play .ico-pause {
  display: block;
}

/* —— 进度条 —— */
.story-tts-seek {
  position: relative;
  flex: 1 1 auto;
  min-width: 3.5rem;
  height: 1.85rem;
  margin: 0 .1rem;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.story-tts-seek-bg,
.story-tts-seek-fill {
  position: absolute;
  left: 0;
  top: 50%;
  height: 3px;
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
  transition: height .12s ease;
}

.story-tts-seek-bg {
  right: 0;
  background: rgba(17, 24, 39, .12);
}

.story-tts-seek-fill {
  width: 0%;
  background: var(--stts-accent);
}

.story-tts-seek-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--stts-accent);
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(17, 24, 39, .16);
  transition: transform .12s ease, width .12s ease, height .12s ease;
}

.story-tts-seek:hover .story-tts-seek-bg,
.story-tts-seek:hover .story-tts-seek-fill,
.story-tts.is-seeking .story-tts-seek-bg,
.story-tts.is-seeking .story-tts-seek-fill {
  height: 4px;
}

.story-tts-seek:hover .story-tts-seek-thumb,
.story-tts.is-seeking .story-tts-seek-thumb {
  width: 13px;
  height: 13px;
}

.story-tts-time {
  flex: 0 0 auto;
  font-size: .6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--stts-muted);
  white-space: nowrap;
  line-height: 1;
  min-width: 4.5rem;
  text-align: right;
  letter-spacing: -.01em;
}

.story-tts-speed,
.story-tts-close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--stts-muted);
  border-radius: 7px;
  padding: 0;
  transition: background .15s ease, color .15s ease;
}

.story-tts-speed {
  min-width: 2rem;
  height: 1.85rem;
  font-size: .6875rem;
  font-weight: 700;
}

.story-tts-speed.is-active {
  color: var(--stts-accent);
  background: rgba(var(--stts-accent-rgb), .1);
}

.story-tts-close {
  width: 1.85rem;
  height: 1.85rem;
}

.story-tts-speed:hover,
.story-tts-close:hover {
  background: rgba(17, 24, 39, .06);
  color: var(--stts-ink);
}

.story-tts-error {
  margin: 0;
  padding: .5rem .65rem;
  color: #b91c1c;
  font-size: .75rem;
  background: rgba(185, 28, 28, .06);
}

@keyframes story-tts-spin {
  to { transform: rotate(360deg); }
}

@keyframes story-tts-eq {
  0%, 100% { transform: scaleY(.45); }
  50% { transform: scaleY(1); }
}

/* —— 暗色 —— */
.nice-dark-mode .story-tts {
  --stts-ink: #f3f4f6;
  --stts-muted: #9ca3af;
  --stts-line: rgba(255, 255, 255, .1);
  --stts-bg: rgba(255, 255, 255, .06);
  --stts-bg-play: rgba(255, 82, 43, .12);
}

.nice-dark-mode .story-tts-seek-bg {
  background: rgba(255, 255, 255, .16);
}

.nice-dark-mode .story-tts-seek-thumb {
  background: #111827;
}

.nice-dark-mode .story-tts-speed:hover,
.nice-dark-mode .story-tts-close:hover {
  background: rgba(255, 255, 255, .08);
}

.nice-dark-mode .story-tts-start.is-disabled,
.nice-dark-mode .story-tts-start:disabled {
  background: rgba(255, 255, 255, .18);
  color: rgba(255, 255, 255, .55);
}

.nice-dark-mode .story-tts-menu-item {
  color: #f3f4f6;
}

/* —— 移动端 —— */
@media (max-width: 575.98px) {
  .story-tts {
    margin-bottom: .65rem;
  }

  .story-tts-start {
    min-height: 2rem;
    padding: .32rem .75rem .32rem .65rem;
    font-size: .75rem;
  }

  .story-tts-start .tts-label-long {
    display: none;
  }

  .story-tts-start .tts-label-short {
    display: inline;
  }

  .story-tts-loading,
  .story-tts-player {
    min-height: 2.65rem;
    height: 2.65rem;
    gap: .4rem;
    padding: 0 .4rem 0 .35rem;
  }

  .story-tts-play {
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    max-width: 2rem;
    min-height: 2rem;
    max-height: 2rem;
  }

  .story-tts-seek {
    height: 2.2rem;
    min-width: 2.5rem;
  }

  .story-tts-seek-bg,
  .story-tts-seek-fill {
    height: 4px;
  }

  .story-tts-seek-thumb {
    width: 14px;
    height: 14px;
  }

  .story-tts-time {
    min-width: 4.2rem;
    font-size: .625rem;
  }

  .story-tts-speed,
  .story-tts-close {
    min-width: 2.15rem;
    width: 2.15rem;
    height: 2.15rem;
  }

  .story-tts-speed {
    font-size: .75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-tts-spin,
  .story-tts-eq i,
  .story-tts-start,
  .story-tts-play,
  .story-tts-panel,
  .story-tts-seek-bg,
  .story-tts-seek-fill,
  .story-tts-seek-thumb {
    animation: none !important;
    transition: none !important;
  }
}
