:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --border: #dde3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --soft: #eef2ff;
  --shadow: 0 10px 30px rgba(20, 33, 61, 0.08);
  --btn-sec-bg: #e7edfb;
  --btn-sec-text: #1e3a8a;
  --btn-sec-hover: #d9e3fb;
  --input-bg: #ffffff;
  --header-bg: linear-gradient(135deg, #111827, #1e3a8a);
  --header-text: #cbd5e1;
  --floating-shadow: 0 8px 24px rgba(0,0,0,0.15);
  --surface: var(--surface);  --surface: var(--surface);
  --surface-dim: #f1f5f9;
  --surface-alt: #e2e8f0;
  --danger-surface: #fee2e2;
  --danger-surface-hover: #fecaca;
  --danger-text: #991b1b;
  --success-surface: #dcfce7;
  --success-text: #166534;
  --warning-surface: #fefce8;
  --warning-surface-alt: #fef9c3;
  --warning-border: #fde68a;
  --warning-text: #854d0e;
  --warning-input-bg: #fffbeb;
  --warning-accent: #eab308;
  --primary-surface: #dbeafe;
  --primary-surface-hover: #bfdbfe;
  --primary-text: #1e3a8a;
  --primary-light-text: #3730a3;
  --text-dim: #64748b;
  --text-mid: #475569;
  --text-strong: #334155;
  --record-bg: #16a34a;
  --sentence-card: linear-gradient(180deg, #eff6ff, #ffffff);
  --diff-correct-bg: #dcfce7;
  --diff-correct-border: #86efac;
  --diff-yours-bg: #dbeafe;
  --diff-yours-border: #93c5fd;
  --diff-wrong-bg: #fef2f2;
  --diff-wrong-border: #fca5a5;
  --input-focus-ring: rgba(37, 99, 235, 0.12);
  --transcript-summary-bg: #f1f5f9;
  --transcript-summary-hover: #e2e8f0;
  --voice-msg-bg: #f1f5f9;

  --player-bg: #0f172a;
}

* {
  box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --soft: #1e3a8a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --btn-sec-bg: #1e3a8a;
  --btn-sec-text: #bfdbfe;
  --btn-sec-hover: #1e40af;
  --input-bg: #0f172a;
  --header-bg: linear-gradient(135deg, #020617, #172554);
  --header-text: #94a3b8;
  --floating-shadow: 0 8px 24px rgba(0,0,0,0.5);
  --surface: #0f172a;
  --surface-dim: #1e293b;
  --surface-alt: #334155;
  --danger-surface: #450a0a;
  --danger-surface-hover: #7f1d1d;
  --danger-text: #fca5a5;
  --success-surface: #052e16;
  --success-text: #86efac;
  --warning-surface: #451a03;
  --warning-surface-alt: #713f12;
  --warning-border: #92400e;
  --warning-text: #fef08a;
  --warning-input-bg: #1a120e;
  --warning-accent: #ca8a04;
  --primary-surface: #1e3a8a;
  --primary-surface-hover: #1e40af;
  --primary-text: #93c5fd;
  --primary-light-text: #c7d2fe;
  --text-dim: #94a3b8;
  --text-mid: #cbd5e1;
  --text-strong: #e2e8f0;
  --record-bg: #15803d;
  --sentence-card: linear-gradient(180deg, #1e293b, #0f172a);
  --diff-correct-bg: #064e3b;
  --diff-correct-border: #15803d;
  --diff-yours-bg: #172554;
  --diff-yours-border: #1d4ed8;
  --diff-wrong-bg: #450a0a;
  --diff-wrong-border: #7f1d1d;
  --input-focus-ring: rgba(59, 130, 246, 0.2);
  --transcript-summary-bg: #1e293b;
  --transcript-summary-hover: #334155;
  --voice-msg-bg: #1e293b;
}


body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.import-label {
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: 0.15s ease;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
.import-label:hover {
  background: var(--primary-dark);
}

button.secondary,
.import-label {
  background: var(--btn-sec-bg);
  color: var(--primary-text);
}

button.secondary:hover,
.import-label:hover {
  background: var(--btn-sec-hover);
}

button.danger {
  background: var(--danger-surface);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger-surface-hover);
  color: var(--danger-dark);
}

button.record {
  background: var(--record-bg);
}

button.record.recording {
  background: var(--danger);
}

input,
textarea,
select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(16px, 3vw, 26px) clamp(14px, 4vw, 30px);
  background: var(--header-bg);
  color: white;
}

.app-header h1 {
  margin: 0 0 8px;
  font-size: 30px;
}

.app-header p {
  margin: 0;
  color: var(--header-text);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding: clamp(10px, 2vw, 18px);
  max-width: 1500px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: clamp(12px, 2vw, 18px);
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.url-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.url-row input {
  flex: 1;
  min-width: min(220px, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--player-bg);
  border-radius: 16px;
  overflow: hidden;
  margin: 14px 0;
}

#player,
#player iframe {
  width: 100%;
  height: 100%;
}

.player-controls,
.transcript-actions,
.nav-row,
.record-row,
.review-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.hint,
.parse-summary,
.feedback {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  line-height: 1.6;
}

.practice-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pill {
  background: var(--soft);
  color: var(--primary-light-text);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.sentence-card {
  background: var(--sentence-card);
  border: 1px solid #dbeafe;
  border-radius: 18px;
  padding: 18px;
  min-height: 150px;
}

.time-range {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
}

.target-text {
  font-size: 25px;
  line-height: 1.45;
  font-weight: 750;
}

.record-row {
  margin-top: 16px;
}

#recordStatus {
  color: var(--muted);
}

#recordingPlayback {
  width: 100%;
  margin-top: 12px;
  display: none;
}

.recognized-box {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.recognized-box label {
  color: var(--muted);
  font-weight: 650;
}

.recognized-box textarea {
  min-height: 92px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.score-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  background: white;
}

.score-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.score-card strong {
  font-size: 28px;
}

.sentence-list,
.review-list {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.sentence-list.empty,
.review-list.empty {
  color: var(--muted);
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 14px;
}

.sentence-item,
.review-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  background: white;
}

.sentence-item:hover,
.review-item:hover {
  background: var(--surface);
}

.sentence-item.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.sentence-item .meta,
.review-item .meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.sentence-item .text,
.review-item .text {
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-dim);
  color: var(--text-strong);
  margin-left: 4px;
}

.badge.low {
  background: var(--danger-surface);
  color: var(--danger-text);
}

.badge.good {
  background: var(--success-surface);
  color: var(--success-text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stats-grid div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.stats-grid strong {
  font-size: 26px;
}

.app-footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 10px 18px 30px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .layout.view-browse .list-panel,
  .layout:not(.view-practice) .list-panel,
  .layout.view-browse .practice-panel,
  .layout:not(.view-practice) .practice-panel,
  .layout.view-browse .review-panel,
  .layout:not(.view-practice) .review-panel,
  .layout.view-browse .stats-panel,
  .layout:not(.view-practice) .stats-panel,
  .layout.view-notes .sticky-col1,
  .layout.view-notes .notes-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .url-row {
    flex-direction: column;
  }

  .score-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .app-header {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions label,
  .header-actions button {
    flex: 1 1 180px;
  }
}

@media (max-width: 560px) {
  body {
    min-width: 320px;
  }

  .score-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .target-text {
    font-size: 21px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .header-actions label,
  .header-actions button,
  .header-actions select {
    width: 100%;
  }

  .player-controls,
  .nav-row,
  .record-row,
  .transcript-actions,
  .caption-fetch-row,
  .note-actions-row,
  .notes-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  button,
  .import-label {
    width: 100%;
  }
}

/* ─── v2.1 — Loop & Dictation ──────────────────────────────────────────── */

.loop-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  flex-wrap: wrap;
}

.loop-btn {
  background: var(--surface-dim);
  color: var(--text-mid);
  border: 2px solid var(--border);
  padding: 8px 14px;
  font-weight: 600;
}

.loop-btn.active {
  background: var(--primary-surface);
  border-color: var(--primary);
  color: var(--primary);
}

.loop-btn.playing {
  background: #2563eb;
  border-color: var(--primary-dark);
  color: white;
  animation: pulse-loop 1.2s ease-in-out infinite;
}

@keyframes pulse-loop {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(37,99,235,0); }
}

.loop-count-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.loop-count-selector select {
  padding: 6px 8px;
  min-width: 60px;
}

.loop-indicator {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

.dictation-btn.active {
  background: var(--warning-surface-alt);
  border: 2px solid #eab308;
  color: var(--warning-text);
}

.dictation-area {
  margin-top: 14px;
  padding: 14px;
  background: var(--warning-surface);
  border: 1px solid var(--warning-border);
  border-radius: 14px;
  display: grid;
  gap: 10px;
}

.dictation-area label {
  font-weight: 650;
  color: var(--warning-text);
}

.dictation-area textarea {
  min-height: 80px;
  border-color: var(--warning-border);
  background: var(--warning-input-bg);
}

.dictation-area textarea:focus {
  border-color: var(--warning-accent);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.dictation-actions {
  display: flex;
  gap: 10px;
}

.dictation-actions button {
  font-size: 14px;
}

.dictation-compare {
  margin-top: 10px;
  padding: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid;
  gap: 8px;
}

.dictation-compare-item {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.correct-text {
  background: var(--success-surface);
  border: 1px solid var(--diff-correct-border);
}

.correct-text::before {
  content: "✅ 原文: ";
  font-weight: 650;
  color: var(--success-text);
}

.your-text {
  background: var(--primary-surface);
  border: 1px solid var(--diff-yours-border);
}

.your-text::before {
  content: "✍️ 你的听写: ";
  font-weight: 650;
  color: #1e40af;
}

.diff-text {
  background: var(--diff-wrong-bg);
  border: 1px solid var(--diff-wrong-border);
}

.diff-text::before {
  content: "🔍 差异: ";
  font-weight: 650;
  color: var(--danger-text);
}

.dictation-word {
  display: inline;
  padding: 1px 3px;
  border-radius: 4px;
}

.dictation-word.correct {
  color: var(--success-text);
}

.dictation-word.wrong {
  background: var(--danger-surface-hover);
  color: var(--danger-text);
  text-decoration: line-through;
}

.dictation-word.missing {
  background: var(--warning-surface-alt);
  color: var(--warning-text);
  font-style: italic;
}

.dictation-word.extra {
  background: var(--danger-surface-hover);
  color: var(--danger-text);
}

/* ─── End v2.1 ──────────────────────────────────────────────────────────── */

/* ─── v2.2 — Layout & Transcript Upload ──────────────────────────────────── */

.transcript-source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.upload-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--btn-sec-bg);
  color: var(--primary-text);
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 650;
  font-size: 14px;
  transition: 0.15s ease;
}

.upload-label:hover {
  background: var(--btn-sec-hover);
}

.file-name {
  font-size: 13px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── v2.3 — Scoring Mode ────────────────────────────────────────────────── */

.scoring-mode-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.scoring-mode-label select {
  padding: 6px 8px;
  font-size: 13px;
  min-width: 120px;
}

/* ─── End v2.3 ──────────────────────────────────────────────────────────── */

/* ─── End v2.2 ──────────────────────────────────────────────────────────── */

/* ─── v2.0 New UI Elements ─────────────────────────────────────────── */

/* ─── v4.0 — New Grid Layout: Sticky + Collapsible Transcript ──────── */

/* Explicit grid placement — Browse mode keeps media + sentence side by side */
.layout.view-browse .sticky-col1,
.layout:not(.view-practice) .sticky-col1 {
  grid-column: 1;
  grid-row: 1;
}

.layout.view-browse .list-panel,
.layout:not(.view-practice) .list-panel {
  grid-column: 2;
  grid-row: 1;
}

.layout.view-browse .practice-panel,
.layout:not(.view-practice) .practice-panel {
  grid-column: 1;
  grid-row: 2;
}

.layout.view-browse .review-panel,
.layout:not(.view-practice) .review-panel {
  grid-column: 2;
  grid-row: 2;
}

.layout.view-browse .stats-panel,
.layout:not(.view-practice) .stats-panel {
  grid-column: 2;
  grid-row: 3;
}

/* Notes mode: player left, notes right */
.layout.view-notes {
  max-width: 1500px;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 1fr);
  gap: 14px;
  align-items: start;
}

.layout.view-notes .sticky-col1 {
  grid-column: 1;
  grid-row: 1 / span 3;
}

.layout.view-notes .notes-panel {
  grid-column: 2;
  grid-row: 1 / span 3;
  min-height: min(760px, calc(100vh - 140px));
}

/* Practice mode: mini player strip top, Sentences left, Practice right */
.layout.view-practice {
  max-width: 1500px;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.2fr);
  gap: 14px;
  align-items: start;
}

/* ── Floating player window (不受 grid 约束) ── */
.layout.view-practice .sticky-col1 {
  position: fixed;
  z-index: 100;
  width: 300px;
  min-width: 220px;
  min-height: 100px;
  resize: both;
  overflow: auto;
  padding: 10px;
  cursor: grab;
  user-select: none;
  touch-action: none;

  /* 卡片样式 */
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  background: var(--panel);
  border-radius: 14px;

  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto;
  gap: 4px;

  /* 默认位置：右下角 */
  right: 24px;
  bottom: 24px;
  left: auto;
  top: auto;
}

/* 缩放把手指示器 (右下角小三角) */
.layout.view-practice .sticky-col1::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 12px 12px;
  border-color: transparent transparent var(--muted) transparent;
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}

/* Player 占满浮窗宽度 */
.layout.view-practice .player-shell {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  margin: 0;
  border-radius: 10px;
}

/* Podcast 音频条同样 */
.layout.view-practice .audio-player-shell {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  margin: 0;
  min-height: 40px;
  padding: 6px;
  border-radius: 10px;
}

/* 非必要元素不显示 */
.layout.view-practice .sticky-col1 h2,
.layout.view-practice .sticky-col1 .url-row,
.layout.view-practice .sticky-col1 .caption-fetch-row,
.layout.view-practice .sticky-col1 .transcript-collapsible,
.layout.view-practice .sticky-col1 .hint,
.layout.view-practice .sticky-col1 > .transcript-collapsible,
.layout.view-practice .podcast-section,
.layout.view-practice #podcastEpisodeSelect {
  display: none !important;
}

/* 控件已移到 Sentences 面板，浮窗内隐藏 */
.layout.view-practice .sticky-col1 .player-controls,
.layout.view-practice .sticky-col1 .loop-controls,
.layout.view-practice .sticky-col1 .player-status,
.layout.view-practice .sticky-col1 .podcast-status {
  display: none !important;
}

.layout.view-practice .record-row,
.layout.view-practice .nav-row {
  gap: 8px;
}

/* ── Sentences (左列，占满) ── */
.layout.view-practice .list-panel {
  grid-column: 1;
  grid-row: 1 / span 3;
}

.layout.view-practice .sentence-list {
  max-height: calc(100vh - 220px);
  min-height: 400px;
}

/* ── Practice (右列上方) ── */
.layout.view-practice .practice-panel {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 8px;
  max-height: none;
  overflow: visible;
}

/* ── Review + Stats (右列，Practice 下方) ── */
.layout.view-practice .review-panel {
  grid-column: 2;
  grid-row: 2;
}

.layout.view-practice .stats-panel {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 1280px) {
  .layout.view-practice {
    grid-template-columns: minmax(300px, 1fr) minmax(360px, 1.1fr);
  }
  .layout.view-practice .sticky-col1 {
    width: 260px;
  }
}

/* Transcript collapsible inside video/podcast panel */
.transcript-collapsible {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}

.transcript-summary {
  padding: 12px 16px;
  font-weight: 650;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-dim);
  user-select: none;
  transition: background 0.15s;
}

.transcript-summary:hover {
  background: var(--surface-alt);
}

.transcript-summary::marker {
  color: var(--primary);
  font-size: 1.1em;
}

.transcript-inner {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.transcript-inner textarea {
  min-height: 160px;
  margin-bottom: 10px;
}

.transcript-inner .parse-summary {
  margin-top: 10px;
}

/* Sentence list: max-height for scrollability */
/* Responsive: collapse to single column on mobile */
@media (max-width: 980px) {
  .layout,
  .layout.view-practice,
  .layout.view-notes {
    grid-template-columns: 1fr;
  }

  .sticky-col1,
  .layout.view-practice .practice-panel {
    position: static;
  }

  /* 移动端隐藏浮窗（屏幕太小） */
  .layout.view-practice .sticky-col1 {
    display: none !important;
  }

  .list-panel,
  .practice-panel,
  .review-panel,
  .stats-panel,
  .notes-panel,
  .layout.view-practice .sticky-col1,
  .layout.view-practice .list-panel,
  .layout.view-practice .practice-panel,
  .layout.view-practice .review-panel,
  .layout.view-practice .stats-panel,
  .layout.view-notes .sticky-col1,
  .layout.view-notes .notes-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .layout.view-practice .practice-panel {
    max-height: none;
    overflow: visible;
  }

  .layout.view-practice .sentence-list {
    min-height: auto;
    max-height: 460px;
  }
}

/* ─── End v4.0 ──────────────────────────────────────────────────────────── */

/* ─── v5.2 — Sentence Follow Button ───────────────────────────────────────── */

.sentence-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sentence-panel-head h2 {
  margin: 0;
}

.follow-btn {
  background: var(--surface-dim);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.follow-btn.active {
  background: var(--primary-surface);
  border-color: #3b82f6;
  color: var(--primary-dark);
}

.follow-btn:hover {
  background: var(--surface-alt);
}

.follow-btn.active:hover {
  background: var(--primary-surface-hover);
}

/* ─── End v5.2 ──────────────────────────────────────────────────────────── */

/* ─── v5.3 — Sentence Controls Bar (练习模式) ─────────────────────────── */

.sentence-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sentence-controls .player-controls,
.sentence-controls .loop-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.sentence-controls button,
.sentence-controls select {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.sentence-controls .loop-count-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.sentence-controls .loop-indicator {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

/* v5.3 end */

/* ─── v5.3 — Azure Word-Level Details ─────────────────────────────────────── */

.word-details {
  margin-top: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.word-details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.word-details-header h4 {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.confidence-badge {
  background: var(--primary-surface);
  color: var(--primary-dark);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.wd-recognized {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--surface-dim);
  border-radius: 8px;
}

.wd-recognized em {
  color: var(--text);
  font-style: italic;
}

.wd-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.wd-word {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  background: var(--surface-dim);
  color: var(--text-strong);
  cursor: help;
}

.wd-word sup {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  margin-left: 2px;
}

.wd-word.wd-ok {
  background: var(--warning-surface-alt);
  color: var(--warning-text);
}

.wd-word.wd-ok sup {
  color: #a16207;
}

.wd-word.wd-wrong {
  background: var(--danger-surface);
  color: var(--danger-text);
}

.wd-word.wd-wrong sup {
  color: #dc2626;
}

.wd-word.wd-omit {
  background: var(--diff-wrong-bg);
  color: #7f1d1d;
  text-decoration: line-through;
}

.wd-word.wd-extra {
  background: #e0f2fe;
  color: #075985;
  border: 1px dashed #38bdf8;
}

/* ─── End v5.3 ──────────────────────────────────────────────────────────── */

/* ─── v5.1 — Voice Message Delete Button ──────────────────────────────────── */

.voice-msg-del {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 50%;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: unset;
  font-weight: 400;
}

.voice-msg-del:hover {
  color: var(--danger);
  background: var(--danger-surface);
}

/* ─── End v5.1 ──────────────────────────────────────────────────────────── */

.mode-select {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 15px;
  cursor: pointer;
}

.mode-select option {
  background: #1e293b;
  color: white;
}

.player-status {
  margin: 8px 0 12px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface-dim);
  color: var(--text-mid);
  transition: 0.2s;
}

.player-status.ready {
  background: var(--success-surface);
  color: var(--success-text);
}

.player-status.loading {
  background: var(--warning-surface-alt);
  color: var(--warning-text);
}

.player-status.error {
  background: var(--danger-surface);
  color: var(--danger-text);
}

.caption-fetch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.caption-fetch-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.caption-fetch-row select {
  min-width: 130px;
}

.caption-options-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 6px 0 12px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--surface-dim);
}

.toggle-option,
.caption-segmentation-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  color: var(--text-strong);
  cursor: pointer;
}

.caption-segmentation-label select {
  min-width: 130px;
}

.toggle-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.caption-options-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-spinner.hidden {
  display: none;
}

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

.podcast-section {
  margin-bottom: 16px;
}

.podcast-section h3 {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 8px;
}

.podcast-section input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

.audio-player-shell {
  margin: 12px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 48px;
}

.podcast-status {
  margin: 12px 0;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  font-size: 14px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:disabled:hover {
  background: inherit;
}

button.secondary:disabled:hover {
  background: var(--btn-sec-bg);
}

.podcast-panel select {
  width: 100%;
}

/* ─── v3.0 — Voice Messages (WeChat-style) ────────────────────────────── */

.voice-messages {
  margin-top: 14px;
  padding: 14px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 14px;
  display: block;
}

.voice-msgs-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.voice-msgs-header h4 {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.voice-msgs-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.voice-count {
  background: var(--soft);
  color: var(--primary-light-text);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.voice-msg-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 10px;
}

.voice-msg-tools input,
.voice-msg-tools select {
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 10px;
}

.voice-msg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.layout.view-practice .voice-msg-list {
  max-height: min(42vh, 520px);
}

.voice-msg-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.voice-msg-item:hover {
  background: #f0f4ff;
  border-color: #93c5fd;
}

.voice-msg-item.playing,
.voice-msg-item.selected {
  background: var(--primary-surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.voice-msg-playbtn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.voice-msg-item.playing .voice-msg-playbtn {
  background: var(--record-bg);
  animation: pulse-play 1.2s ease-in-out infinite;
}

@keyframes pulse-play {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(22,163,74,0); }
}

.voice-msg-body {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.voice-msg-top,
.voice-msg-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.voice-msg-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  flex: 1;
  min-width: 48px;
}

.voice-msg-progress {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  border-radius: 999px;
  transition: width 0.1s linear;
}

.voice-msg-item.playing .voice-msg-progress {
  background: linear-gradient(90deg, #22c55e, #16a34a);
}

.voice-msg-dur,
.voice-msg-ts,
.voice-msg-time {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.voice-msg-dur {
  font-weight: 700;
}

.voice-msg-score {
  font-size: 12px;
  font-weight: 700;
  color: var(--success-text);
  background: var(--success-surface);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}

.voice-msg-score.low {
  color: var(--danger-text);
  background: var(--danger-surface);
}

.voice-msg-text {
  font-size: 13px;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.voice-msg-time {
  color: #9ca3af;
}

.voice-msg-empty,
.voice-msg-limit {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: white;
  font-size: 13px;
  line-height: 1.5;
}

/* ─── v3.0 — Practice / Listen Mode Toggle ────────────────────────────── */

.practice-mode-btn {
  background: var(--btn-sec-bg);
  color: var(--primary-text);
  transition: all 0.2s ease;
  min-width: 120px;
}

.practice-mode-btn.listen-mode {
  background: var(--primary-surface);
  color: #1e40af;
  border: 2px solid #3b82f6;
  font-weight: 700;
  animation: pulse-listen 2s ease-in-out infinite;
}

@keyframes pulse-listen {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(59,130,246,0); }
}

/* ─── v3.0 — Project Save/Load ────────────────────────────────────────── */

#saveProjectBtn {
  background: #065f46;
  color: white;
}

#saveProjectBtn:hover {
  background: #047857;
}

/* ─── End v3.0 ──────────────────────────────────────────────────────────── */

/* ─── End v2.0 ──────────────────────────────────────────────────────── */

/* ─── Notes Panel ──────────────────────────────────────────────────── */

.note-input-box {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.note-stamp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-timestamp {
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

#noteTextInput {
  min-height: 160px;
  resize: vertical;
}

.note-mode-tabs,
.note-actions-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.note-mode-tabs button.active {
  background: var(--primary);
  color: white;
}

.note-markdown-preview {
  min-height: 160px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
}

.voice-note-status {
  color: var(--muted);
  font-size: 13px;
}

#voiceNoteBtn.recording {
  background: var(--danger);
  color: white;
}

.note-voice-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-dim);
  border: 1px solid var(--border);
}

.note-voice-message.playing {
  border-color: var(--primary);
  background: var(--primary-surface);
}

.note-voice-play {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  padding: 0;
  flex: 0 0 38px;
}

.note-voice-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  min-width: 74px;
}

.note-voice-wave span {
  width: 5px;
  border-radius: 999px;
  background: var(--primary);
  opacity: 0.72;
}

.note-voice-wave span:nth-child(1) { height: 10px; }
.note-voice-wave span:nth-child(2) { height: 18px; }
.note-voice-wave span:nth-child(3) { height: 26px; }
.note-voice-wave span:nth-child(4) { height: 16px; }
.note-voice-wave span:nth-child(5) { height: 22px; }

.note-voice-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.note-voice-meta strong {
  font-size: 13px;
  color: var(--text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-voice-meta small {
  color: var(--muted);
}

.notes-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.notes-toolbar input {
  flex: 1;
  min-width: 120px;
}

.notes-list {
  display: grid;
  gap: 8px;
  max-height: min(620px, calc(100vh - 430px));
  min-height: 180px;
  overflow: auto;
  padding-right: 4px;
}

.note-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--panel);
}

.note-item .note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.note-item .note-meta strong {
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
}

.note-item .note-meta strong:hover {
  text-decoration: underline;
}

.note-item .note-text {
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.markdown-body {
  white-space: normal;
}

.markdown-body p,
.note-markdown-preview p {
  margin: 0 0 8px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.note-markdown-preview h1,
.note-markdown-preview h2,
.note-markdown-preview h3 {
  margin: 8px 0 6px;
  font-size: 17px;
}

.markdown-body ul,
.note-markdown-preview ul {
  margin: 6px 0 8px 20px;
  padding: 0;
}

.markdown-body code,
.note-markdown-preview code {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-dim);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92em;
}

.note-item .note-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

.note-item .note-actions button {
  padding: 3px 8px;
  font-size: 11px;
}
