/* ===== 背单词助手 全局样式 ===== */
:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #2b3448;
  --muted: #7a8699;
  --primary: #4f7cff;
  --primary-dark: #3a5fd8;
  --accent: #ffb84d;
  --green: #2ecc71;
  --red: #ff6b6b;
  --line: #e6ebf2;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(43, 52, 72, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;   /* 微信/安卓浏览器禁止自动放大字体 */
  text-size-adjust: 100%;
  touch-action: manipulation;        /* 去除双击缩放延迟 */
}

/* 内联 SVG 图标:随字号缩放,全平台可靠(替代 emoji) */
.ic {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  flex-shrink: 0;
  display: inline-block;
}

/* ===== 顶栏 ===== */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: -webkit-sticky;   /* 兼容微信老内核 X5 */
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(43, 52, 72, 0.04);
}

.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;            /* 窄屏自动换行,避免溢出错乱 */
  gap: 6px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 10px;
  min-width: 0;
}

.brand:hover { background: var(--bg); }
.brand .ic { width: 22px; height: 22px; color: var(--primary); }

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.pill {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.pill .ic { width: 14px; height: 14px; }
.pill-streak { background: #fff4e0; color: #c97b1a; }
.pill-due { background: #eaf0ff; color: var(--primary-dark); }
.pill:hover { filter: brightness(0.97); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  padding: 0;
}

.icon-btn .ic { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--bg); }

/* ===== 视图容器 ===== */
.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ===== 首页 ===== */
.hero {
  background: linear-gradient(135deg, #4f7cff, #7a5cff);
  border-radius: var(--radius);
  color: #fff;
  padding: 26px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.hero h1 { font-size: 24px; margin-bottom: 6px; }
.hero p { font-size: 14px; opacity: 0.9; line-height: 1.6; }

.hero-actions { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:active { transform: translateY(1px); }

.btn .ic { width: 17px; height: 17px; }
.btn-lg .ic { width: 19px; height: 19px; }
.card h3 .ic { width: 19px; height: 19px; color: var(--primary); }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(79, 124, 255, 0.35); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-white { background: #fff; color: var(--primary-dark); }
.btn-white:hover { background: #f0f4ff; }

.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); }

.btn-lg { padding: 14px 34px; font-size: 17px; }

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-icon { font-size: 24px; line-height: 1; margin-bottom: 6px; }

/* 周活动柱状图 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card h3 { font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 110px;
}

.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar { width: 70%; max-width: 34px; border-radius: 6px 6px 0 0; background: #d7e2ff; min-height: 4px; }
.bar.has { background: linear-gradient(180deg, #4f7cff, #7a5cff); }
.bar-label { font-size: 11px; color: var(--muted); }
.bar-num { font-size: 11px; font-weight: 700; color: var(--primary); }

/* 词表进度 */
.level-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.level-row:last-child { border-bottom: none; }

.level-name { width: 64px; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.level-bar-wrap { flex: 1; height: 10px; background: #edf1f8; border-radius: 999px; overflow: hidden; }
.level-bar { height: 100%; background: linear-gradient(90deg, #4f7cff, #7a5cff); border-radius: 999px; transition: width 0.3s; }
.level-info { width: 130px; text-align: right; font-size: 12px; color: var(--muted); flex-shrink: 0; }

/* ===== 练习页(全屏听写) ===== */
.practice-wrap {
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);   /* 微信/手机地址栏高度更准确 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
  padding: 24px 16px;
}

.practice-progress {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar-wrap { flex: 1; height: 10px; background: #edf1f8; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #ff8a3d); border-radius: 999px; transition: width 0.25s; }
.progress-text { font-size: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; }

.practice-card {
  width: 100%;
  max-width: 640px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px 26px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.speaker-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #4f7cff, #7a5cff);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(79, 124, 255, 0.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  padding: 0;
}

.speaker-btn .ic { width: 30px; height: 30px; }

.speaker-btn:active { transform: scale(0.94); }
.speaker-btn.speaking { animation: pulse 0.9s infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.sentence-display {
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: 0.5px;
  color: var(--ink);
  max-width: 100%;
  overflow-wrap: break-word;
}

.sentence-display .blank {
  color: var(--primary);
  border-bottom: 3px solid var(--primary);
  padding: 0 4px;
  min-width: 90px;
  display: inline-block;
  text-align: center;
}

.sentence-display .blank .blank-hint {
  color: #9db8ff; /* 提示字母用浅色,区别于完整答案 */
  letter-spacing: 1px;
}

.sentence-display .revealed {
  color: var(--green);
  border-bottom-color: var(--green);
}

.practice-hint { font-size: 14px; color: var(--muted); }

.answer-row {
  width: 100%;
  max-width: 460px;
  display: flex;
  gap: 10px;
}

.answer-input {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  padding: 13px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: #fbfcfe;
  color: var(--ink);
  text-align: center;
}

.answer-input:focus { border-color: var(--primary); background: #fff; }

.answer-submit {
  border: none;
  border-radius: 12px;
  padding: 0 22px;
  font-size: 16px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.answer-submit:hover { background: var(--primary-dark); }

/* 结果反馈 */
.result-box { width: 100%; max-width: 460px; animation: pop 0.2s ease; }

@keyframes pop { from { transform: scale(0.96); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

.result-banner {
  font-size: 20px;
  font-weight: 800;
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.result-correct { background: #e8f9ef; color: #1d9e56; }
.result-wrong { background: #ffecec; color: #d64545; }

.result-word {
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 2px;
}

.result-word button {
  border: none;
  background: none;
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
  color: var(--primary);
  padding: 2px;
}

.result-word button .ic { width: 22px; height: 22px; }

.result-banner .ic { width: 20px; height: 20px; vertical-align: -0.2em; }

.practice-hint .ic { width: 13px; height: 13px; vertical-align: -0.1em; color: var(--accent); }

.result-meaning { font-size: 18px; font-weight: 700; color: var(--primary-dark); margin-bottom: 8px; }
.result-sentence { font-size: 15px; color: var(--muted); line-height: 1.7; }

.self-grade { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.grade-btn {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
}

.grade-btn:hover { border-color: var(--primary); color: var(--primary); }
.grade-btn.selected { border-color: var(--primary); background: #eaf0ff; color: var(--primary-dark); }

.next-btn { margin-top: 12px; }

/* ===== 词表浏览 ===== */
.search-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.search-input {
  flex: 1;
  min-width: 180px;
  font-size: 15px;
  padding: 11px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  outline: none;
}

.search-input:focus { border-color: var(--primary); }

.level-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.level-tab {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
}

.level-tab.active { border-color: var(--primary); color: var(--primary-dark); background: #eaf0ff; }

.word-table { width: 100%; border-collapse: collapse; }

.word-table th, .word-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.word-table th { color: var(--muted); font-size: 13px; font-weight: 600; }

.word-en { font-weight: 700; font-size: 16px; }
.word-en .mini-speak {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--primary);
  vertical-align: middle;
  padding: 2px;
  margin-left: 2px;
}
.word-en .mini-speak .ic { width: 16px; height: 16px; }
.word-cn { color: var(--ink); }
.word-level { font-size: 12px; color: var(--muted); }

/* ===== 设置 ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--line);
  flex-wrap: wrap;
}

.setting-row:last-child { border-bottom: none; }
.setting-label { font-weight: 600; font-size: 15px; }
.setting-desc { font-size: 12px; color: var(--muted); margin-top: 3px; }

.setting-control { display: flex; align-items: center; gap: 8px; }

select, input[type="number"] {
  font-size: 14px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus, input[type="number"]:focus { border-color: var(--primary); }

#set-voice { max-width: 240px; }

.toggle { position: relative; width: 48px; height: 27px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: #d4dbe6;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.15s;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  width: 21px;
  height: 21px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.15s;
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(21px); }

.btn-danger { background: #ffecec; color: #d64545; border: none; }
.btn-danger:hover { background: #ffdcdc; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 100;
  transition: opacity 0.2s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

/* 空状态 */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .emoji { display: block; margin-bottom: 12px; color: var(--muted); }
.empty .emoji .ic { width: 52px; height: 52px; }

.done-emoji { font-size: 56px; line-height: 1; margin-bottom: 10px; color: var(--primary); }

/* ===== 响应式 ===== */
@media (max-width: 560px) {
  .hero h1 { font-size: 20px; }
  .practice-card { padding: 24px 16px; min-height: 280px; }
  .level-info { width: 110px; }
}

/* 窄屏(手机/微信):隐藏品牌文字、压缩顶栏,防止导航换行错乱 */
@media (max-width: 480px) {
  .topbar-inner { padding: 8px 8px; gap: 6px; }
  .brand-text { display: none; }
  .brand { padding: 4px 6px; }
  .icon-btn { width: 34px; height: 34px; }
  .pill { padding: 5px 8px; font-size: 12px; }
  .word-table th:nth-child(3), .word-table td:nth-child(3) { display: none; } /* 手机词表隐藏例句列 */
}

/* 兼容不支持 flex gap 的老内核(微信 X5 等):顶栏用 margin 兜底 */
@supports not (gap: 0.5em) {
  .topbar-right { margin-left: 0; }
  .topbar-inner, .topbar-right, .brand { gap: 0; }
  .topbar-right > * { margin-left: 6px; }
  .brand .ic { margin-right: 7px; }
}
