/* ── 全局重置 & 变量 ─────────────────────────────────────── */
:root {
  --bg: #FAF6EF;
  --surface: #FFFFFF;
  --surface2: #F3EDE3;
  --primary: #D4845A;
  --primary-dark: #B5633C;
  --primary-light: #F5D6C4;
  --accent: #6BA38A;
  --accent-light: #C3E0D5;
  --danger: #D95F5F;
  --danger-light: #FADADA;
  --text: #2C2416;
  --text2: #6B5D4F;
  --text3: #9B8E82;
  --border: #E0D5C8;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ── 页面层 ─────────────────────────────────────────────── */
.page {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 24px;
}
.page.active { display: flex; }

/* ── 顶栏 ───────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}
.topbar .back-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  line-height: 1;
}
.topbar .back-btn:active { background: var(--surface2); }

/* ── 卡片 ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

/* ── 按钮系列 ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  font-size: 1.1rem;
  padding: 16px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-accent {
  background: var(--accent);
  color: #fff;
  width: 100%;
  font-size: 1.05rem;
  padding: 14px;
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text2);
}
.btn-ghost-sm {
  background: var(--surface2);
  color: var(--text2);
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-row {
  display: flex;
  gap: 10px;
}
.btn-row .btn { flex: 1; }

/* ── 首页 ───────────────────────────────────────────────── */
.home-hero {
  text-align: center;
  padding: 32px 0 20px;
}
.home-hero .emoji { font-size: 3.5rem; }
.home-hero h1 { font-size: 1.6rem; font-weight: 800; margin: 8px 0 4px; }
.home-hero p { color: var(--text2); font-size: 0.95rem; }

.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.stat-card:active { transform: scale(0.97); }
.stat-card .num {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}
.stat-card .label {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 2px;
}

/* ── 书本/课次选择 ───────────────────────────────────────── */
.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text2);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.select-all-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.unit-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}
.unit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.unit-item.checked {
  background: var(--primary-light);
}
.unit-item input[type=checkbox] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}
.unit-item .unit-label {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 500;
}
.unit-item .unit-count {
  font-size: 0.8rem;
  color: var(--text3);
}

.selected-count {
  text-align: center;
  padding: 10px;
  font-size: 0.9rem;
  color: var(--text2);
  font-weight: 500;
}
.selected-count span {
  color: var(--primary);
  font-weight: 700;
  font-size: 1.1rem;
}

/* 自定义词表折叠 */
.custom-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}
.custom-toggle .toggle-icon {
  font-size: 0.85rem;
  color: var(--text3);
  transition: transform 0.2s;
}
.custom-toggle.open .toggle-icon { transform: rotate(180deg); }

.custom-body {
  display: none;
  margin-top: 10px;
}
.custom-body.open { display: block; }

.custom-textarea {
  width: 100%;
  min-height: 100px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 1rem;
  font-family: var(--font);
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
.custom-textarea:focus { outline: none; border-color: var(--primary); }
.custom-hint { font-size: 0.8rem; color: var(--text3); margin-top: 6px; }
.custom-active-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 8px;
}

/* ── 播放设置 ───────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.setting-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.setting-item label {
  font-size: 0.8rem;
  color: var(--text2);
  font-weight: 600;
}
.setting-item select, .setting-item input[type=range] {
  width: 100%;
  font-family: var(--font);
  font-size: 0.95rem;
}
.setting-item select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239B8E82' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.range-row input[type=range] {
  flex: 1;
  accent-color: var(--primary);
}
.range-val {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 32px;
  text-align: right;
}
.shuffle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 4px;
}
.shuffle-row label {
  font-size: 0.9rem;
  color: var(--text2);
  cursor: pointer;
}
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.2s;
  cursor: pointer;
}
.toggle-switch .slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .slider { background: var(--primary); }
.toggle-switch input:checked + .slider::before { transform: translateX(20px); }

/* ── 播放界面 ───────────────────────────────────────────── */
.play-page {
  justify-content: space-between;
}

.play-progress {
  text-align: center;
  padding: 20px 0 10px;
}
.play-progress .prog-nums {
  font-size: 1rem;
  color: var(--text2);
  margin-bottom: 6px;
}
.progress-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
}

.play-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px 0;
}
.current-word {
  font-size: 3rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.05em;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
}
.word-status {
  font-size: 0.95rem;
  color: var(--text3);
  height: 24px;
}
.play-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
}
.play-indicator .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.play-indicator .dot.active { background: var(--primary); }
.play-indicator .dot.done { background: var(--accent); }

.play-controls {
  padding: 16px 0 24px;
}
.ctrl-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.ctrl-btn {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:active { transform: scale(0.92); }
.ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.ctrl-btn.large {
  width: 72px; height: 72px;
  font-size: 1.8rem;
  background: var(--primary);
  color: #fff;
}
.ctrl-btn.large:disabled { background: var(--border); }

.pause-status {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text3);
  min-height: 20px;
}

/* ── 听写隐藏区域（替代 current-word 在播放时的位置） ─── */
.word-hidden-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 80px;
}
.word-hidden-icon {
  font-size: 2.8rem;
  opacity: 0.55;
}
.word-hidden-tip {
  font-size: 1rem;
  color: var(--text3);
  font-weight: 500;
}

/* 家长偷看时显示的词（同 current-word 样式） */
.current-word-peek {
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: 0.05em;
  text-align: center;
  min-height: 80px;
  align-items: center;
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 8px 24px;
}

/* ── 家长看词按钮区 ────────────────────────────────────── */
.peek-btn-row {
  display: flex;
  justify-content: flex-start;
  margin-top: 16px;
  padding-left: 2px;
}
.peek-btn {
  background: transparent;
  color: var(--text3);
  border: none;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.7rem;
  opacity: 0.5;
  font-family: var(--font);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, color 0.12s, opacity 0.12s;
}
.peek-btn.peeking {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  opacity: 1;
}

/* ── 对答案 ─────────────────────────────────────────────── */
.answer-intro {
  text-align: center;
  padding: 16px 0;
}
.answer-intro h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.answer-intro p { font-size: 0.9rem; color: var(--text2); }

.answer-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text3);
  margin-bottom: 10px;
}

.word-answer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.word-answer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.word-answer-item .aw { font-size: 1.3rem; font-weight: 700; }
.word-answer-item .mark-icon { font-size: 1.6rem; }

.word-answer-item.correct {
  border-color: var(--accent);
  background: #f0faf5;
}
.word-answer-item.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
}

.answer-summary {
  margin-top: 6px;
  text-align: center;
  font-size: 1rem;
  color: var(--text2);
  padding: 10px;
}
.answer-summary .big-score {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
}

/* ── 错题本 ─────────────────────────────────────────────── */
.mistake-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mistake-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.mistake-item .mw { font-size: 1.15rem; font-weight: 600; }
.mistake-item .merr {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: 2px;
}
.mistake-del {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text3);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.mistake-del:active { background: var(--danger-light); color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* ── Toast ──────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 20px) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(44,36,22,0.88);
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
  max-width: 90vw;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── 工具类 ─────────────────────────────────────────────── */
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mb8 { margin-bottom: 8px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; color: var(--text2); }

/* ── 滚动条 ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── 响应式 ─────────────────────────────────────────────── */
@media (min-width: 480px) {
  .page { padding: 0 20px 32px; }
}
