/* ===== 项目架构A 固定样式 ===== */
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; margin: 0; padding: 20px; color: #333; }
  .top-bar { background: #fff; padding: 16px 20px; border-radius: 12px; margin-bottom: 20px; display: flex; align-items: center; gap: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
  .top-bar h1 { margin: 0; font-size: 24px; }
  .btn-back { background: #4a90e2; color: #fff; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; }
  .card { background: #fff; border-radius: 12px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
  .card h2 { margin-top: 0; font-size: 18px; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 16px; }
  .fold-card { padding: 0; overflow: hidden; }
  .fold-card summary { list-style: none; cursor: pointer; padding: 16px 20px; font-size: 18px; font-weight: 700; user-select: none; }
  .fold-card summary::-webkit-details-marker { display: none; }
  .fold-card summary::after { content: "＋"; float: right; color: #777; font-size: 18px; }
  .fold-card[open] summary::after { content: "－"; }
  .muted-hint { color:#888; font-size:13px; margin: 0 0 10px; line-height: 1.6; }
  .setting-row .rate-label { width:auto; }
  .token-retry-btn { border:0; border-radius:6px; padding:7px 12px; background:#c0392b; color:#fff; cursor:pointer; }
  .token-retry-btn[hidden] { display: none; }
  .jump-hint { color:#c0392b; font-size:12px; font-weight:600; }
  #compareResult { line-height:2; }
  .mode-selection-content { padding: 0 20px 16px; }
  .settings-content { padding: 0 20px 8px; }
  .setting-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
  .setting-row label { width: 60px; font-weight: 500; }
  select, input[type="range"] { padding: 6px 10px; border-radius: 6px; border: 1px solid #ccc; }
  textarea { width: 100%; min-height: 80px; padding: 12px; border-radius: 8px; border: 1px solid #ccc; font-size: 28px; line-height: 1.4; resize: vertical; box-sizing: border-box; }
  
  .play-group { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
  .btn-play { border: none; padding: 14px 32px; border-radius: 24px; font-size: 16px; cursor: pointer; }
  .btn-play-order { background: #7ed321; color: #fff; }
  .btn-play-random { background: #f39c12; color: #fff; }
  
  .nav-group { display: flex; gap: 8px; margin-top: 12px; }
  .btn-nav { font-size: clamp(16px, 1.8vw, 26px); height: 48px; line-height: 1.2; padding: 0 10px; flex: 1; border: none; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
  .btn-prev { background: #e67e22; color: #fff; }
  .btn-play-current { background: #3498db; color: #fff; }
  .btn-next { background: #9013fe; color: #fff; }
  
  .compare-box { display: none; margin-top: 20px; padding: 16px; background: #f8f9fa; border-radius: 8px; border: 1px solid #e9ecef; }
  .compare-box.show { display: block; }
  .score-board { display: flex; gap: 16px; margin-bottom: 16px; font-weight: 600; flex-wrap: wrap; }
  .score-board span { background: #fff; padding: 6px 12px; border-radius: 6px; border: 1px solid #ddd; font-size: 14px; }
  .word { padding: 2px 4px; border-radius: 4px; margin-right: 4px; font-size: 16px; }
  .word.correct { background: #d4edda; color: #155724; }
  .word.wrong { background: #f8d7da; color: #721c24; }
  .word.miss { background: #fff3cd; color: #856404; }
  .word.extra { background: #e0e0e0; color: #9e9e9e; text-decoration: line-through; }

  .letter-miss {
    color: #c0392b;
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    font-weight: 700;
    background: #fff0f0;
    border-radius: 2px;
    padding: 0 1px;
  }
  .letter-extra {
    color: #9e9e9e;
    text-decoration: line-through;
    text-decoration-thickness: 2px;
  }
  .letter-wrong { color: #721c24; background: #f8d7da; }
  
  /* 句子信息展示区 */
  #sentenceInfo { margin-top: 12px; padding: 12px; background: #f0f8ff; border-radius: 8px; font-size: 14px; line-height: 1.7; border-left: 4px solid #4a90e2; }
  #sentenceInfo > div { margin-bottom: 6px; }
  #sentenceInfo > div:last-child { margin-bottom: 0; }
  #sentenceInfo .info-label { font-weight: 700; margin-right: 6px; }
  #infoDifficulty { color: #e67e22; font-weight: bold; }
  
  .answer-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 16px; }
  .answer-heading-row h2 { margin: 0; padding: 0; border: 0; flex: 1 1 auto; }
  #questionCounter { font-weight: bold; font-size: 16px; color: #555; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; }
  .question-counter-label { font-size: 14px; font-weight: 600; color: #777; }
  #questionJumpInput { width: 76px; box-sizing: border-box; padding: 5px 7px; font-size: 16px; font-weight: bold; color: #555; border: 1px solid #bbb; border-radius: 6px; }

  /* ===== 右侧单词本 ===== */
  .app-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
  .main-column { min-width: 0; }
  .wordbook-card { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: hidden; display: flex; flex-direction: column; }
  .wordbook-card h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .wordbook-count { font-size: 12px; color: #777; font-weight: 500; }
  .wordbook-hint { color: #777; font-size: 12px; line-height: 1.5; margin: -4px 0 12px; }
  #wordbookList { overflow-y: auto; min-height: 80px; }
  .wordbook-empty { color: #999; font-size: 13px; text-align: center; padding: 24px 8px; }
  .wordbook-item { display: flex; align-items: flex-start; gap: 8px; padding: 10px 0; border-bottom: 1px solid #eee; }
  .wordbook-item:last-child { border-bottom: 0; }
  .wordbook-word { font-weight: 700; color: #2c3e50; overflow-wrap: anywhere; }
  .wordbook-meta { color: #888; font-size: 11px; margin-top: 3px; }
  .wordbook-phonetic { color: #5367a5; font-size: 13px; margin-top: 5px; }
  .wordbook-meaning { color: #333; font-size: 13px; margin-top: 3px; line-height: 1.5; }
  .wordbook-remove { margin-left: auto; flex: 0 0 auto; border: 0; background: transparent; color: #999; cursor: pointer; font-size: 16px; padding: 0 4px; }
  .wordbook-remove:hover { color: #c0392b; }
  .wordbook-speak { flex: 0 0 auto; border: 0; background: transparent; color: #2585c5; cursor: pointer; font-size: 20px; line-height: 1; padding: 2px 4px; border-radius: 6px; }
  .wordbook-speak:hover { background: #e8f4fc; }
  .wordbook-speak:disabled { opacity: .45; cursor: not-allowed; }
  .wordbook-actions { display: flex; gap: 8px; margin-top: 12px; }
  .wordbook-actions button { flex: 1; border: 1px solid #ddd; background: #f8f9fa; border-radius: 6px; padding: 7px 8px; cursor: pointer; font-size: 12px; }
  .wordbook-actions button:hover { background: #eef4fb; }
  .wordbook-toast { color: #27864b; font-size: 12px; min-height: 18px; margin-top: 6px; }
  /* Responsive layout: desktop, tablet and phone */
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body { min-width: 0; overflow-x: hidden; }
  button, input, select, textarea { font: inherit; }
  button { touch-action: manipulation; }
  .app-layout { width: 100%; max-width: 1800px; margin: 0 auto; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); }
  .main-column, .card, .wordbook-card { min-width: 0; }
  textarea { max-width: 100%; font-size: clamp(18px, 2.2vw, 28px); }
  .wordbook-actions button, .wordbook-speak, .wordbook-remove { min-height: 38px; }
  .btn-play, .btn-nav { min-height: 48px; }
  #compareResult { overflow-wrap: anywhere; word-break: normal; }

  /* Laptop / small desktop */
  @media (max-width: 1100px) {
    body { padding: 14px; }
    .app-layout { grid-template-columns: minmax(0, 1fr) 270px; gap: 14px; }
    .card { padding: 16px; }
    .top-bar { padding: 14px 16px; }
    .top-bar h1 { font-size: clamp(19px, 2.2vw, 24px); }
    .btn-play { padding: 12px 22px; }
  }

  /* Tablet: main exercise first, wordbook below for more writing width */
  @media (max-width: 900px) {
    body { padding: 12px; }
    .app-layout { display: flex; flex-direction: column; gap: 12px; }
    .main-column, .wordbook-card { width: 100%; }
    .wordbook-card { position: static; max-height: none; }
    #wordbookList { max-height: 420px; }
    .top-bar { flex-wrap: wrap; gap: 10px; }
    .top-bar h1 { flex: 1 1 220px; }
    .settings-content { padding: 0 16px 10px; }
    .setting-row { gap: 10px; }
    .setting-row label { width: auto; }
    textarea { font-size: clamp(20px, 3vw, 26px); }
  }

  /* Phone */
  @media (max-width: 600px) {
    body { padding: 8px; }
    .top-bar { padding: 12px; margin-bottom: 12px; border-radius: 10px; }
    .top-bar h1 { font-size: 18px; line-height: 1.3; }
    .btn-back { padding: 9px 11px; font-size: 13px; white-space: nowrap; }
    #statusBar { flex: 1 1 100%; font-size: 13px; overflow-wrap: anywhere; }
    .card { padding: 12px; margin-bottom: 12px; border-radius: 10px; }
    .card h2 { font-size: 16px; padding-bottom: 8px; margin-bottom: 12px; }
    .settings-card summary { padding: 13px 14px; font-size: 16px; }
    .mode-selection-card summary { padding: 13px 14px; font-size: 16px; }
    .mode-selection-content { padding: 0 14px 12px; }
    .settings-content { padding: 0 12px 8px; }
    .setting-row { align-items: center; gap: 8px; }
    .setting-row label { font-size: 14px; }
    .setting-row select { max-width: 100%; min-width: 0; }
    #rateRange { flex: 1 1 120px; min-width: 100px; }
    .play-group { display: grid; grid-template-columns: 1fr; gap: 10px; }
    .btn-play { width: 100%; padding: 13px 14px; font-size: 16px; }
    .nav-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .btn-nav { min-width: 0; height: auto; min-height: 46px; font-size: 15px; padding: 8px 6px; }
    .btn-play-current { grid-column: 1 / -1; grid-row: 1; }
    .btn-prev { grid-column: 1; grid-row: 2; }
    .btn-next { grid-column: 2; grid-row: 2; }
    .answer-heading-row { align-items: flex-start; }
    .answer-heading-row h2 { flex-basis: 100%; }
    #questionCounter { font-size: 15px; }
    #questionJumpInput { width: 72px; min-height: 38px; font-size: 16px; }
    textarea { min-height: 120px; padding: 10px; font-size: 20px; }
    .score-board { gap: 7px; }
    .score-board span { padding: 6px 8px; font-size: 12px; }
    #sentenceInfo { padding: 10px; font-size: 13px; overflow-wrap: anywhere; }
    #compareResult { font-size: 15px; line-height: 2; }
    .word { font-size: 14px; }
    .wordbook-card h2 { align-items: flex-start; }
    .wordbook-count { text-align: right; }
    .wordbook-hint { font-size: 12px; }
    .wordbook-item { gap: 6px; padding: 10px 0; }
    .wordbook-word { font-size: 15px; }
    .wordbook-phonetic, .wordbook-meaning { font-size: 12px; overflow-wrap: anywhere; }
    .wordbook-speak { font-size: 21px; min-width: 38px; }
    .wordbook-remove { min-width: 32px; }
    .wordbook-actions button { min-height: 42px; font-size: 13px; }
  }

  /* Very narrow phones */
  @media (max-width: 360px) {
    body { padding: 5px; }
    .card { padding: 10px; }
    .top-bar { gap: 8px; }
    .top-bar h1 { font-size: 16px; }
    .nav-group { grid-template-columns: 1fr 1fr; }
    .btn-nav { font-size: 13px; }
    .score-board span { font-size: 11px; }
  }


/* ===== 优化补充：键盘可访问性、日志渲染与低动态效果 ===== */
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid #4a90e2;
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== 练习统计与错题复习 ===== */
.stats-card { border: 1px solid #e6edf5; }
.stats-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 12px 0 16px; }
.stat-tile { display: flex; flex-direction: column; gap: 7px; padding: 13px 14px; border-radius: 10px; background: #f3f7fc; border: 1px solid #e4edf7; min-width: 0; }
.stat-label { color: #65758b; font-size: 12px; }
.stat-tile strong { color: #23364d; font-size: 24px; line-height: 1.15; overflow-wrap: anywhere; }
.stat-tile-warn { background: #fff7ed; border-color: #ffdfba; }
.stat-tile-warn strong { color: #c45b12; }
.stats-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stats-actions button { border: 1px solid #d7e0eb; background: #fff; color: #334155; border-radius: 7px; padding: 9px 12px; cursor: pointer; min-height: 38px; }
.stats-actions button:hover { background: #f1f6fb; }
.stats-actions .stats-primary { color: #fff; border-color: #2675c9; background: #2675c9; }
.stats-actions .stats-primary:hover { background: #1e64ad; }
.stats-actions .stats-danger { color: #a93226; }
.review-notice { padding: 10px 12px; border-radius: 8px; background: #eaf4ff; border-left: 4px solid #3488d8; color: #225b91; font-size: 13px; line-height: 1.6; margin-bottom: 14px; }
.mistake-details { border-top: 1px solid #edf0f4; padding-top: 13px; }
.mistake-list-header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; cursor: pointer; list-style: none; }
.mistake-list-header::-webkit-details-marker { display: none; }
.mistake-list-header::before { content: "▶"; color: #64748b; font-size: 11px; margin-right: 2px; transition: transform .15s ease; }
.mistake-details[open] .mistake-list-header::before { transform: rotate(90deg); }
.mistake-list-header strong { flex: 1; }
.mistake-list-header span { color: #8792a2; font-size: 12px; }
.mistake-list { display: grid; gap: 8px; }
.mistake-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; padding: 10px 12px; border: 1px solid #edf0f4; border-radius: 8px; align-items: start; }
.mistake-jump { border: 0; border-radius: 6px; background: #fff0e5; color: #a94c0b; padding: 6px 8px; font-size: 12px; font-weight: 700; cursor: pointer; grid-row: span 2; }
.mistake-jump:hover { background: #ffe1c9; }
.mistake-sentence { font-size: 14px; color: #344256; line-height: 1.5; overflow-wrap: anywhere; }
.mistake-meta { font-size: 12px; color: #7a8797; }
.stats-empty { padding: 18px 12px; text-align: center; color: #8a96a5; background: #fafbfd; border-radius: 8px; font-size: 13px; }
.stats-success { color: #28784a; background: #effaf2; }
.stats-more { text-align: center; color: #778497; font-size: 12px; padding: 8px; }
@media (max-width: 720px) {
  .stats-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-tile strong { font-size: 21px; }
  .stats-actions button { flex: 1 1 calc(50% - 8px); }
  .mistake-list-header { align-items: flex-start; flex-direction: column; gap: 4px; }
}

/* Briefly highlight an existing word when double-clicking it again. */
.wordbook-item-focused {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
  background: rgba(59, 130, 246, 0.12) !important;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

/* Current playback speed, immediately left of the question number. */
.answer-rate-display { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; white-space: nowrap; color: #777; font-size: 14px; }
#answerRateValue { color: #5448d9; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 420px) { .answer-rate-display { margin-right: 4px; font-size: 13px; } }

/* Local Azure audio files. */
.audio-cache-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.audio-cache-heading h2 { margin: 0; padding: 0; border: 0; }
#chooseAudioDirectoryBtn, .resume-audio-btn { border: 1px solid #d9d4ff; border-radius: 7px; background: #f2efff; color: #5448d9; padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; }
#chooseAudioDirectoryBtn:disabled { opacity: .6; cursor: default; }
#chooseAudioDirectoryBtn:focus-visible, .resume-audio-btn:focus-visible { outline: 3px solid #9f96ee; outline-offset: 2px; }
#audioCacheStatus { margin: 12px 0 6px; font-size: 13px; line-height: 1.6; color: #555; overflow-wrap: anywhere; }
.audio-cache-hint { margin: 0; color: #888; font-size: 12px; line-height: 1.6; }
.resume-audio-btn { margin-top: 12px; }
.resume-audio-btn[hidden] { display: none; }

.audio-cache-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.audio-cache-version { color: #888; font-size: 11px; font-weight: 400; white-space: nowrap; }
#verifyAudioDirectoryBtn { border: 1px solid #ddd; border-radius: 7px; background: #fff; color: #555; padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; }
#verifyAudioDirectoryBtn:disabled { opacity: .5; cursor: default; }
#verifyAudioDirectoryBtn:focus-visible { outline: 3px solid #9f96ee; outline-offset: 2px; }
#audioCacheStatus.cache-status-error { color: #b42318; font-weight: 600; }
#audioCacheStatus.cache-status-success { color: #237a3b; }
.audio-cache-last-saved { margin: 8px 0; padding: 8px 10px; background: #f6f8fa; border-radius: 6px; color: #555; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }

[hidden]{display:none!important}.wfd-tools{display:flex;flex-wrap:wrap;gap:10px;margin-bottom:16px}.wfd-tool-toggle{padding:12px 20px;border:1px solid #b5c7d9;border-radius:12px;background:white;color:#24415b;font-size:18px;cursor:pointer}.wfd-tool-toggle[aria-expanded="true"]{background:#e8f0ff;border-color:#4164ce}.main-column>.fold-card h2{padding:16px 20px;margin:0}.btn-submit{background:#16865f;color:white}.nav-group .btn-nav{font-size:clamp(16px,1.5vw,24px)}

/* Match the answer sentence to the writing area at every viewport size. */
#answerInput,#compareResult{font-size:clamp(18px,2.2vw,28px);font-family:inherit}
#compareResult .word{font-size:inherit;display:inline-block;line-height:1.4;margin:4px 4px 4px 0}

#compareResult .word.spelling{background:#f1f5fa;color:#24415b}#compareResult .letter-miss,#compareResult .letter-extra{color:#919ba7;text-decoration:line-through;text-decoration-thickness:2px;background:transparent;padding:0;font-weight:inherit}#compareResult .letter-wrong{color:#bd2036;background:transparent;font-weight:700}#compareResult .spelling-legend{font-size:14px;color:#65778a;line-height:1.6;margin:12px 0}

.wfd-shortcut-hint{font-size:14px;color:#687c91;line-height:1.6;margin:0 0 12px}

/* Compact practice controls share one row at every screen width. */
.nav-group.compact-actions{display:flex;flex-wrap:nowrap;gap:10px;justify-content:flex-start}.nav-group.compact-actions .btn-nav{flex:0 0 44px;width:44px;height:44px;min-height:44px;padding:0;font-size:22px;line-height:1;border-radius:9px;grid-column:auto;grid-row:auto}

.typing-history-block{border-top:1px solid #dce4ee;margin-top:20px;padding-top:16px}.typing-history-label{font-size:15px;color:#657b94;margin-bottom:10px}.typing-history{font-size:28px;line-height:1.8;white-space:pre-wrap;overflow-wrap:anywhere}.typing-deleted{color:#98a1ad;text-decoration:line-through;text-decoration-thickness:2px}.typing-kept{color:#213c58}.typing-word-practice{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-top:12px;font-size:14px;color:#657b94}.typing-word{padding:4px 8px;border-radius:6px;background:#edf3f9}.typing-word.revised{color:#986412;background:#fff3d9}


.wfd-sidebar{min-width:0;display:flex;flex-direction:column;gap:16px}.wfd-sidebar .wordbook-card{position:static;max-height:65vh}.wfd-ai-card{padding:18px!important;overflow-wrap:anywhere}.wfd-ai-card h2{font-size:21px}.wfd-ai-card p{font-size:14px;line-height:1.7}.wfd-ai-actions{display:flex;flex-wrap:wrap;gap:8px}.wfd-ai-actions button{font-size:14px;padding:9px 10px;border:1px solid #b5c7d9;border-radius:8px;background:#edf3ff;color:#24415b;cursor:pointer}.typing-ai-pattern{padding:12px;background:#f3f6fc;border-radius:10px;margin-top:10px}.typing-ai-pattern strong{font-size:16px}@media(max-width:900px){.wfd-sidebar{width:100%}}


.wfd-app-link{display:inline-flex;align-items:center;padding:12px 20px;border:1px solid #b5c7d9;border-radius:12px;background:white;color:#24415b;font-size:18px;text-decoration:none}.wfd-app-link:hover{background:#e8f0ff}


.ask-ai-panel{margin-top:20px;border:1px solid #dce4ed;border-radius:12px;background:white;overflow:hidden}.ask-ai-panel>summary{cursor:pointer;font-size:19px;font-weight:650;background:#f1f4f8;padding:16px 20px}.ask-ai-content{padding:20px}.ask-ai-content>label{display:block;margin-bottom:8px}.ask-ai-content textarea{width:100%;min-height:100px;font:inherit;font-size:20px;line-height:1.7;padding:12px;border:1px solid #b5c7d9;border-radius:10px;resize:vertical}.ask-ai-context{font-size:15px;margin:12px 0}.ask-ai-actions{display:flex;align-items:center;flex-wrap:wrap;gap:12px;margin-top:14px}.ask-ai-actions button{padding:10px 20px;border:1px solid #b5c7d9;border-radius:8px;background:#edf3ff;color:#24415b;font:inherit;cursor:pointer}.ask-ai-actions span{font-size:14px;color:#657b94}.ask-ai-answer{font-size:20px;line-height:1.8;overflow-wrap:anywhere}.ask-ai-answer h3{color:#315db8;font-size:22px}.ask-ai-answer h4{color:#7654ad;font-size:20px}#askAIStatus{color:#657b94;font-size:15px}

