/* ===========================
   哼哼背单词 · 网页版
   =========================== */

@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700;800&family=Nunito:wght@500;600;700;800&display=swap");

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --surface-3: #eef6f1;
  --text: #18202c;
  --text-2: #5e6a78;
  --text-3: #98a2b3;
  --accent: #2f7cf6;
  --accent-2: #10a37f;
  --success: #24a148;
  --danger: #dc2626;
  --warning: #e48a16;
  --border: rgba(30, 41, 59, 0.12);
  --shadow: 0 6px 18px rgba(26, 37, 61, 0.06), 0 1px 4px rgba(26, 37, 61, 0.05);
  --shadow-lg: 0 18px 42px rgba(26, 37, 61, 0.11), 0 4px 12px rgba(26, 37, 61, 0.07);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC",
    "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --font-rounded: "Nunito", "Noto Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
  --touch-target: 44px;
  --touch-gap: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    linear-gradient(180deg, rgba(238, 246, 241, 0.85), rgba(246, 248, 251, 0.92) 36%, #f6f8fb),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  user-select: text;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  touch-action: auto;
}

#app {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 14px 0 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

.touch-target {
  min-height: var(--touch-target);
}

/* ============= 顶部 ============= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 6px 4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-rounded);
  font-weight: 800;
  font-size: 19px;
  color: #152238;
}
.logo {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #dff7ec, #eef4ff);
  box-shadow: inset 0 0 0 1px rgba(16, 163, 127, 0.14);
  font-size: 20px;
}
.streak {
  font-size: 13px;
  color: #8a4b04;
  background: #fff3d8;
  padding: 6px 11px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(228, 138, 22, 0.16);
}

/* ============= 学习入口 ============= */
.study-controls {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "book"
    "units"
    "difficulty"
    "challenge";
  gap: 10px;
  align-items: stretch;
}
.study-controls.chinese-book {
  grid-template-areas:
    "book"
    "units"
    "challenge";
}

/* ============= 词库选择 ============= */
.book-picker {
  grid-area: book;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: visible;
  border: 1px solid var(--border);
}
.book-picker-toggle {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  min-height: 42px;
}
.caret { color: var(--text-3); transition: transform 0.2s; }
.book-picker[aria-expanded="false"] .caret { transform: rotate(-90deg); }
.book-picker-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 8px;
  overflow: visible;
}
.book-picker-body[hidden] { display: none; }
.book-picker-body .book-item {
  padding: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  min-height: var(--touch-target);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.book-picker-body .book-item:hover {
  background: #fbfdff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(30, 41, 59, 0.06);
}
.book-picker-body .book-item.active {
  background: linear-gradient(180deg, rgba(47, 124, 246, 0.1), rgba(16, 163, 127, 0.08));
  color: var(--accent);
  font-weight: 500;
  border-color: rgba(47, 124, 246, 0.5);
}
.book-cover {
  width: 42px;
  aspect-ratio: 0.72;
  object-fit: cover;
  flex: 0 0 auto;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  box-shadow: 0 3px 10px rgba(26, 37, 61, 0.12);
}
.book-info {
  min-width: 0;
  flex: 1;
}
.book-title {
  font-family: var(--font-rounded);
  font-size: 14px;
  line-height: 1.25;
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-picker-body .book-item .book-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-3);
}
.book-check {
  width: 22px;
  flex: 0 0 auto;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}

/* ============= 随机挑战 ============= */
.challenge-panel {
  grid-area: challenge;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: linear-gradient(160deg, #ffffff, #f3fbf7);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.challenge-copy {
  min-width: 0;
}
.challenge-title {
  font-family: var(--font-rounded);
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}
.challenge-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-2);
}
.challenge-btn {
  min-width: 76px;
  min-height: 38px;
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  font-family: var(--font-rounded);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  flex: 0 0 auto;
}
.challenge-btn:hover {
  filter: brightness(0.98);
  box-shadow: 0 6px 14px rgba(47, 124, 246, 0.18);
}

/* ============= 单元 ============= */
.units {
  grid-area: units;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px;
  scrollbar-width: none;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  position: relative;
  margin-left: 14px;
  border-left: 3px solid rgba(16, 163, 127, 0.46);
}
.units::before {
  content: "";
  position: absolute;
  left: -15px;
  top: -10px;
  width: 14px;
  height: 28px;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 8px;
}
.units::-webkit-scrollbar { display: none; }
.unit-chip {
  flex-shrink: 0;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-2);
  transition: all 0.15s;
  font-family: var(--font);
  min-height: 38px;
  min-width: 78px;
}
.unit-chip.active {
  background: var(--accent-2);
  color: white;
  border-color: var(--accent-2);
  font-weight: 700;
  box-shadow: 0 5px 12px rgba(16, 163, 127, 0.22);
}
.unit-chip:hover:not(.active) {
  background: #f4fbf8;
  color: var(--text);
  border-color: rgba(16, 163, 127, 0.26);
}

/* ============= 难度 ============= */
.difficulty-panel {
  grid-area: difficulty;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border);
  border-left: 3px solid rgba(47, 124, 246, 0.44);
  border-radius: 8px;
  box-shadow: var(--shadow);
  position: relative;
  margin-left: 14px;
}
.difficulty-panel::before {
  content: "";
  position: absolute;
  left: -15px;
  top: -10px;
  width: 14px;
  height: 28px;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 8px;
}
.difficulty-label {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-2);
}
.difficulty-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  flex: 1;
}
.difficulty-option {
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-2);
  font-family: var(--font-rounded);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.difficulty-option.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 5px 12px rgba(47, 124, 246, 0.2);
}
.difficulty-option:hover:not(.active) {
  background: #f5f9ff;
  color: var(--text);
  border-color: rgba(47, 124, 246, 0.28);
}

/* ============= 模式 tab ============= */
.mode-tabs {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}
.mode-tab {
  flex: 1;
  padding: 8px 0;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  font-family: var(--font);
  min-height: var(--touch-target);
}
.mode-tab.active {
  background: var(--accent);
  color: white;
}

/* ============= 主舞台 ============= */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(250, 253, 255, 0.98)),
    var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(30, 41, 59, 0.08);
  box-shadow: var(--shadow-lg);
  min-height: 280px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  position: relative;
  cursor: pointer;
  transition: transform 0.15s;
}
.card:active { transform: scale(0.99); }
.card.answer-good {
  animation: card-good 0.5s ease;
}
.card.answer-try {
  animation: card-try 0.42s ease;
}

.big-word {
  font-size: 38px;
  font-family: var(--font-rounded);
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
  word-break: break-word;
  color: #14213d;
}
.big-word.listen-word {
  line-height: 1;
}
.replay-sound {
  width: 88px;
  height: 88px;
  border: 1.5px solid rgba(47, 124, 246, 0.22);
  border-radius: 999px;
  background: linear-gradient(145deg, #ffffff, #eef6ff);
  box-shadow: 0 12px 28px rgba(47, 124, 246, 0.14), inset 0 0 0 6px rgba(47, 124, 246, 0.05);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.replay-sound:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 124, 246, 0.4);
  box-shadow: 0 14px 32px rgba(47, 124, 246, 0.18), inset 0 0 0 6px rgba(47, 124, 246, 0.07);
}
.replay-sound:active {
  transform: scale(0.97);
}
.phonetic {
  font-size: 16px;
  color: var(--text-2);
  font-family: "Lucida Sans Unicode", "Arial Unicode MS", monospace;
  min-height: 20px;
}
.meaning {
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  color: var(--text);
}
.example {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  font-style: italic;
  margin-top: 4px;
}

/* choice 模式 */
.choice { width: 100%; }
.choice-prompt {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
  color: var(--text-2);
}
.choice-prompt .target {
  color: var(--accent);
  font-weight: 600;
}
.choice-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.choice-option {
  padding: 16px 8px;
  background: #ffffff;
  border: 1.5px solid rgba(30, 41, 59, 0.1);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
  font-family: var(--font);
  min-height: 64px;
  min-width: 120px;
  box-shadow: 0 5px 14px rgba(26, 37, 61, 0.05);
}
.choice-option:hover {
  background: #f7fbff;
  border-color: rgba(47, 124, 246, 0.28);
  transform: translateY(-1px);
}
.choice-option.correct {
  background: rgba(36, 161, 72, 0.12);
  border-color: var(--success);
  color: var(--success);
  box-shadow: 0 8px 18px rgba(36, 161, 72, 0.12);
}
.choice-option.wrong {
  background: rgba(220, 38, 38, 0.11);
  border-color: var(--danger);
  color: var(--danger);
}
.choice-option:disabled { cursor: default; }

/* ============= 进度 ============= */
.progress { padding: 0 4px; }
.progress-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.accuracy { color: var(--success); font-weight: 700; }
.progress-bar {
  height: 6px;
  background: rgba(30, 41, 59, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.3s ease;
}

/* ============= 操作按钮 ============= */
.actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
.btn {
  flex: 1;
  padding: 13px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  -webkit-appearance: none;
  min-height: var(--touch-target);
}
.btn:active { transform: scale(0.97); opacity: 0.9; }
.btn-primary { background: var(--accent); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: var(--surface); color: var(--text-2); box-shadow: var(--shadow); }
.hidden { display: none !important; }

/* ============= 拼写输入 ============= */
.spell-input {
  display: flex;
  gap: 8px;
}
.spell-input input {
  flex: 1;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  min-height: var(--touch-target);
}
.spell-input input:focus {
  border-color: var(--accent);
}
.spell-input input.shake { animation: shake 0.4s; border-color: var(--danger); }
.spell-input input.correct-flash { border-color: var(--success); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ============= 反馈 ============= */
.feedback {
  min-height: 24px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  justify-content: center;
}
.feedback.success { color: var(--success); }
.feedback.danger { color: var(--danger); }
.feedback-card {
  width: min(640px, 100%);
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 20px rgba(26, 37, 61, 0.06);
  animation: feedback-pop 0.24s ease;
}
.feedback-card.is-good {
  border-color: rgba(36, 161, 72, 0.22);
  background: linear-gradient(180deg, rgba(239, 253, 244, 0.98), rgba(255, 255, 255, 0.96));
}
.feedback-card.is-try {
  border-color: rgba(228, 138, 22, 0.28);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.98), rgba(255, 255, 255, 0.96));
}
.feedback-mark {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-rounded);
  font-size: 20px;
  font-weight: 900;
}
.is-good .feedback-mark {
  color: #ffffff;
  background: var(--success);
}
.is-try .feedback-mark {
  color: #ffffff;
  background: var(--warning);
}
.feedback-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text);
  font-size: 15px;
  line-height: 1.3;
}
.feedback-detail,
.feedback-note {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
}
.feedback-detail strong {
  color: var(--text);
  font-weight: 850;
}
.feedback-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  color: #8a4b04;
  background: #fff3d8;
  box-shadow: inset 0 0 0 1px rgba(228, 138, 22, 0.16);
  font-size: 12px;
  font-weight: 850;
}

@keyframes feedback-pop {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes card-good {
  0% { box-shadow: var(--shadow-lg); }
  45% { box-shadow: 0 18px 42px rgba(36, 161, 72, 0.16), 0 0 0 4px rgba(36, 161, 72, 0.1); }
  100% { box-shadow: var(--shadow-lg); }
}

@keyframes card-try {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.next-question-btn {
  justify-self: center;
  min-width: 140px;
  min-height: 42px;
  padding: 0 22px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  font-family: var(--font-rounded);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(47, 124, 246, 0.18);
}
.next-question-btn[hidden] {
  display: none !important;
}

.touch-debug .touch-target,
.touch-debug .tap-ripple,
.touch-debug .book-item,
.touch-debug .unit-chip,
.touch-debug .choice-option,
.touch-debug .mode-tab,
.touch-debug .btn,
.touch-debug .link-btn,
.touch-debug .modal-close {
  outline: 2px solid rgba(255, 69, 58, 0.7);
  outline-offset: -1px;
}
.touch-debug-panel {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 101;
  background: rgba(0, 0, 0, 0.82);
  color: #ffffff;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
}
.touch-debug-head {
  font-weight: 600;
  margin-bottom: 4px;
  color: #ffd60a;
}
#touchDebugInfo { color: #f5f5f7; }

.touch-instruction {
  margin: -4px 0 6px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
}
.tap-ripple {
  position: relative;
  overflow: hidden;
}
.tap-ripple::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(47, 124, 246, 0.12);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
.tap-ripple:active::after {
  opacity: 1;
}

/* ============= 底部 ============= */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 6px 4px;
  font-size: 13px;
  color: var(--text-3);
}
.link-btn {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 10px;
  font-family: var(--font);
  min-height: 38px;
  min-width: var(--touch-target);
}
.link-btn:hover {
  color: var(--accent);
  border-color: rgba(47, 124, 246, 0.24);
  background: #ffffff;
}
.version { font-size: 11px; color: var(--text-3); }

/* ============= 弹窗 ============= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s;
}
.modal[hidden] {
  display: none !important;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid rgba(30, 41, 59, 0.1);
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-rounded);
  font-weight: 800;
  font-size: 16px;
}
.modal-close {
  background: #f8fafc;
  border: none;
  font-size: 24px;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  -webkit-appearance: none;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.word-stats-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
  background: #f8fbfd;
}
.word-stats {
  min-width: 640px;
}
.word-stats-row {
  display: grid;
  grid-template-columns: 1.9fr 1.2fr 0.7fr 0.7fr 0.7fr 0.9fr;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  align-items: center;
}
.word-stats-head {
  position: sticky;
  top: 0;
  background: #eef6f1;
  font-weight: 800;
  color: #244034;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.word-stats-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.72);
}
.word-stats-row span,
.word-stats-head span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.word-stats-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-3);
}
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-2); }
.stat-value {
  font-family: var(--font-rounded);
  font-weight: 800;
  color: var(--text);
}

@media (pointer: coarse) {
  :root {
    --touch-target: 46px;
  }
  .choice-options { gap: var(--touch-gap); }
  .actions { gap: 14px; }
  .card { min-height: 320px; }
  .book-picker-toggle { min-height: 44px; }
  .unit-chip { min-height: 42px; }
  .difficulty-option { min-height: 42px; }
  .challenge-btn { min-height: 42px; }
}

@media (min-width: 768px) {
  :root {
    --touch-target: 44px;
  }
  #app {
    width: min(1360px, calc(100% - 40px));
    padding: 16px 0 28px;
    gap: 18px;
  }
  .topbar { padding: 18px 8px 8px; }
  .brand { font-size: 20px; }
  .logo { font-size: 26px; }
  .streak { font-size: 14px; padding: 6px 12px; }
  .study-controls {
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-areas:
      "book challenge"
      "units challenge"
      "difficulty challenge";
    align-items: stretch;
    gap: 12px;
  }
  .study-controls.chinese-book {
    grid-template-areas:
      "book challenge"
      "units challenge";
  }
  .book-picker,
  .challenge-panel {
    min-height: 0;
  }
  .book-picker-toggle { padding: 10px 12px; font-size: 15px; min-height: 40px; }
  .book-picker-body {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    max-height: none;
    overflow: visible;
  }
  .book-picker-body .book-item { padding: 7px 8px; }
  .book-cover { width: 40px; }
  .book-title { font-size: 13px; }
  .book-picker-body .book-item .book-meta { font-size: 11px; }
  .units {
    align-content: start;
    flex-wrap: wrap;
    overflow: visible;
    max-height: none;
    margin-left: 24px;
  }
  .units::before {
    left: -25px;
    width: 24px;
  }
  .unit-chip {
    font-size: 12px;
    padding: 6px 12px;
    min-height: 34px;
    min-width: 84px;
  }
  .difficulty-panel {
    margin-left: 24px;
  }
  .difficulty-panel::before {
    left: -25px;
    width: 24px;
  }
  .difficulty-options {
    display: flex;
    flex-wrap: wrap;
  }
  .difficulty-option {
    min-height: 34px;
    min-width: 112px;
    padding: 0 12px;
  }
  .challenge-panel {
    align-items: stretch;
    flex-direction: column;
    justify-content: center;
  }
  .challenge-btn {
    width: 100%;
    min-height: 36px;
  }
  .mode-tab { padding: 12px 0; font-size: 16px; }
  .card {
    min-height: 360px;
    padding: 42px 36px;
    gap: 16px;
  }
  .big-word { font-size: 52px; }
  .phonetic { font-size: 19px; }
  .meaning { font-size: 26px; }
  .example { font-size: 16px; }
  .choice-prompt { font-size: 20px; margin-bottom: 16px; }
  .choice-option { font-size: 17px; padding: 18px 12px; min-height: 70px; }
  .progress-text { font-size: 14px; }
  .btn { font-size: 18px; padding: 15px 16px; border-radius: 12px; }
  .spell-input { gap: 12px; }
  .spell-input input { font-size: 18px; padding: 14px 16px; }
  .feedback { font-size: 16px; min-height: 28px; }
  .footer { padding: 10px 4px 8px; font-size: 14px; }
  .link-btn { font-size: 14px; }
  .version { font-size: 12px; }
  .modal-card { max-width: 560px; }
  .modal-head { padding: 18px 22px; font-size: 18px; }
  .modal-close { font-size: 28px; }
  .modal-body { padding: 22px 22px 24px; font-size: 16px; }
}

@media (orientation: landscape) and (min-width: 768px) and (min-height: 480px) {
  :root {
    --touch-target: 40px;
  }
  #app {
    width: min(1480px, calc(100% - 32px));
    height: 100svh;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "controls"
      "card"
      "footer";
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
    overflow: hidden;
  }
  .topbar { grid-area: top; }
  .study-controls { grid-area: controls; }
  .stage { grid-area: card; min-width: 0; min-height: 0; }
  .footer { grid-area: footer; }

  .topbar { padding: 4px 4px 0; }
  .brand { font-size: 18px; }
  .logo {
    width: 30px;
    height: 30px;
    font-size: 20px;
    border-radius: 8px;
  }
  .streak { font-size: 13px; padding: 5px 10px; }
  .study-controls {
    grid-template-columns: minmax(420px, 1.15fr) minmax(320px, 0.85fr) 210px;
    grid-template-areas:
      "book units challenge"
      "book difficulty challenge";
    gap: 8px;
  }
  .study-controls.chinese-book {
    grid-template-areas:
      "book units challenge";
  }
  .book-picker-toggle {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
  }
  .book-picker-body {
    gap: 6px;
    padding: 6px;
  }
  .book-picker-body .book-item {
    min-height: 46px;
    padding: 5px 7px;
    gap: 7px;
  }
  .book-cover { width: 32px; border-radius: 5px; }
  .book-title { font-size: 12px; }
  .book-picker-body .book-item .book-meta { font-size: 10px; }
  .book-check { width: 14px; }
  .units,
  .difficulty-panel {
    margin-left: 12px;
    padding: 6px;
    gap: 5px;
    box-shadow: 0 4px 12px rgba(26, 37, 61, 0.05);
  }
  .units::before,
  .difficulty-panel::before {
    left: -13px;
    width: 12px;
    top: -8px;
    height: 22px;
  }
  .units {
    align-content: center;
    flex-wrap: wrap;
  }
  .unit-chip {
    min-height: 30px;
    min-width: 66px;
    padding: 4px 9px;
    font-size: 11px;
  }
  .difficulty-panel {
    gap: 8px;
  }
  .difficulty-label { font-size: 11px; }
  .difficulty-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
  .difficulty-option {
    min-height: 30px;
    min-width: 0;
    padding: 0 8px;
    font-size: 11px;
  }
  .challenge-panel {
    padding: 8px;
    gap: 8px;
  }
  .challenge-title { font-size: 14px; }
  .challenge-meta { font-size: 10px; }
  .challenge-btn {
    min-height: 32px;
    font-size: 13px;
  }
  .stage {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
    gap: 6px;
  }

  .card {
    min-height: 0;
    height: 100%;
    padding: 20px 24px;
    gap: 8px;
    border-radius: 12px;
  }
  .big-word { font-size: 42px; line-height: 1.08; }
  .phonetic {
    font-size: 15px;
    min-height: 18px;
  }
  .choice-prompt {
    font-size: 16px;
    margin-bottom: 8px;
  }
  .choice-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .choice-option {
    min-height: 54px;
    font-size: 15px;
    padding: 10px 8px;
    border-radius: 8px;
  }
  .replay-sound {
    width: 70px;
    height: 70px;
    font-size: 34px;
  }
  .progress {
    margin: 0;
  }
  .progress-text {
    font-size: 12px;
    margin-bottom: 4px;
  }
  .progress-bar { height: 7px; }
  .feedback {
    min-height: 20px;
    font-size: 14px;
  }
  .footer {
    padding: 0 4px;
    font-size: 12px;
    min-height: 28px;
  }
  .link-btn {
    font-size: 12px;
    min-height: 28px;
    padding: 3px 6px;
  }
  .btn { font-size: 17px; }
  .spell-input input { font-size: 17px; }
}

@media (min-width: 1200px) {
  #app {
    width: min(1480px, calc(100% - 48px));
    display: grid;
    grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "controls controls"
      "card card"
      "progress progress"
      "footer footer";
    align-items: start;
    column-gap: 18px;
    padding-top: 14px;
  }
  .topbar { grid-area: top; }
  .study-controls { grid-area: controls; }
  .stage { grid-area: card; min-width: 0; }
  .progress { grid-area: progress; align-self: end; }
  .footer { grid-area: footer; }
  .stage, .study-controls, .progress { margin-bottom: 0; }
  .card { min-height: 460px; }
  .feedback { font-size: 17px; }
  .book-picker-body {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (min-width: 1200px) and (min-height: 480px) {
  #app {
    width: min(1480px, calc(100% - 32px));
    height: 100svh;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "controls"
      "card"
      "footer";
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
    overflow: hidden;
  }
  .study-controls {
    grid-template-columns: minmax(420px, 1.15fr) minmax(320px, 0.85fr) 210px;
    grid-template-areas:
      "book units challenge"
      "book difficulty challenge";
    gap: 8px;
  }
  .study-controls.chinese-book {
    grid-template-areas:
      "book units challenge";
  }
  .stage {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
    gap: 6px;
    min-height: 0;
  }
  .card {
    min-height: 0;
    height: 100%;
  }
}

@media (orientation: landscape) and (min-width: 768px) and (max-width: 1050px) and (min-height: 480px) {
  #app {
    width: calc(100% - 20px);
    gap: 6px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .study-controls {
    grid-template-columns: minmax(300px, 1fr) minmax(230px, 0.9fr) 150px;
    gap: 6px;
  }
  .book-picker-body {
    gap: 5px;
    padding: 5px;
  }
  .book-picker-body .book-item {
    padding: 4px 5px;
    gap: 5px;
  }
  .book-cover { width: 27px; }
  .book-title { font-size: 11px; }
  .book-picker-body .book-item .book-meta { display: none; }
  .unit-chip {
    min-width: 58px;
    padding: 3px 7px;
  }
  .challenge-panel { padding: 6px; }
  .challenge-meta { display: none; }
  .card {
    padding: 16px 18px;
  }
  .big-word { font-size: 36px; }
  .choice-option {
    min-height: 48px;
    font-size: 14px;
    padding: 8px 6px;
  }
}

@media (orientation: landscape) and (min-width: 1200px) and (min-height: 480px) {
  #app {
    width: min(1760px, calc(100% - 28px));
    height: 100svh;
    min-height: 0;
    display: grid;
    grid-template-columns: clamp(360px, 25vw, 480px) minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "controls card"
      "footer footer";
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 10px 14px;
    padding-top: 8px;
    padding-bottom: 8px;
    overflow: hidden;
  }

  .topbar {
    grid-area: top;
    padding: 2px 4px 0;
  }

  .study-controls {
    grid-area: controls;
    min-height: 0;
    align-self: stretch;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "book"
      "units"
      "difficulty"
      "challenge";
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 8px;
    overflow: hidden;
  }

  .study-controls.chinese-book {
    grid-template-areas:
      "book"
      "units"
      "challenge";
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .book-picker {
    min-height: 0;
  }

  .book-picker-toggle {
    min-height: 32px;
    padding: 6px 10px;
  }

  .book-picker-body {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px;
  }

  .book-picker-body .book-item {
    min-height: 42px;
    padding: 5px 7px;
  }

  .book-cover {
    width: 30px;
  }

  .units,
  .difficulty-panel {
    margin-left: 0;
    padding: 8px;
  }

  .units::before,
  .difficulty-panel::before {
    display: none;
  }

  .units {
    min-height: 0;
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
    flex-wrap: wrap;
    border-left-width: 1px;
  }

  .unit-chip {
    min-width: calc(50% - 4px);
    min-height: 32px;
    padding: 4px 8px;
    border-radius: 9px;
  }

  .difficulty-panel {
    border-left-width: 1px;
  }

  .difficulty-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .difficulty-option {
    min-width: 0;
  }

  .challenge-panel {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
  }

  .challenge-btn {
    width: auto;
    min-width: 92px;
  }

  .stage {
    grid-area: card;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto;
    gap: 8px;
  }

  .card {
    min-height: 0;
    height: 100%;
    padding: 28px 34px;
  }

  .choice-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .choice-option {
    min-height: 66px;
    font-size: 18px;
  }

  .big-word {
    font-size: 54px;
  }

  .phonetic {
    font-size: 18px;
  }

  .choice-prompt {
    font-size: 19px;
    margin-bottom: 12px;
  }

  .progress {
    grid-area: auto;
    margin: 0;
  }

  .feedback {
    min-height: 22px;
  }

  .footer {
    grid-area: footer;
    min-height: 26px;
    padding: 0 4px;
  }
}

@media (orientation: landscape) and (min-width: 1700px) and (min-height: 480px) {
  .book-picker-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .unit-chip {
    min-width: calc(33.333% - 5px);
  }

  .choice-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (min-width: 1200px) and (min-height: 480px) {
  body.is-chinese-book .difficulty-panel {
    display: none !important;
  }

  #app {
    width: min(1900px, calc(100% - 24px));
    grid-template-columns: clamp(560px, 34vw, 700px) minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "controls card"
      "footer footer";
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 10px 16px;
  }

  .study-controls {
    grid-template-columns: 1fr;
    grid-template-areas:
      "book"
      "units"
      "difficulty"
      "challenge";
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  .study-controls.chinese-book,
  body.is-chinese-book .study-controls {
    grid-template-areas:
      "book"
      "units"
      "challenge";
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .book-picker-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
  }

  .book-picker-body .book-item {
    min-width: 0;
    min-height: 58px;
    padding: 7px 8px;
    gap: 9px;
  }

  .book-cover {
    width: 42px;
  }

  .book-title {
    font-size: 13px;
    white-space: nowrap;
  }

  .book-picker-body .book-item .book-meta {
    display: block;
    font-size: 11px;
    line-height: 1.25;
  }

  .book-check {
    width: 16px;
  }

  .units {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-content: stretch;
    gap: 6px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .unit-chip {
    width: 100%;
    min-width: 0;
    min-height: 36px;
    justify-content: flex-start;
    text-align: left;
    border-radius: 10px;
    padding: 7px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .challenge-panel {
    min-height: 64px;
  }

  .stage {
    align-self: stretch;
    min-height: 0;
    height: 100%;
    grid-template-rows: minmax(0, 1fr) auto auto;
  }

  .card {
    min-height: 0;
    height: 100%;
    padding: 34px 40px;
  }

  .big-word {
    font-size: 64px;
  }

  .choice-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .choice-option {
    min-height: 76px;
    font-size: 20px;
  }
}

@media (orientation: landscape) and (min-width: 1760px) and (min-height: 480px) {
  #app {
    grid-template-columns: clamp(640px, 35vw, 760px) minmax(0, 1fr);
  }

  .choice-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .choice-option {
    min-height: 70px;
  }
}
