/* ── 全局变量 ─────────────────────────────────────────── */
:root {
  --primary: #5C6BC0;
  --primary-light: #7986CB;
  --primary-dark: #3949AB;
  --accent: #FF7043;
  --accent-light: #FF8A65;
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --surface2: #F0F1F8;
  --text: #212121;
  --text2: #616161;
  --text3: #9E9E9E;
  --success: #4CAF50;
  --error: #F44336;
  --warning: #FF9800;
  --border: #E0E0E0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.12);
}

/* ── 基础重置 ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  overflow-x: hidden;
}

/* ── 布局框架 ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
}
.header select {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.bottom-nav {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  z-index: 100;
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px;
  color: var(--text3);
  font-size: 10px;
  transition: color 0.2s;
}
.bottom-nav button .nav-icon { font-size: 22px; }
.bottom-nav button:hover, .bottom-nav button.active { color: var(--primary); }

/* ── 页面切换 ─────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── 主页 ─────────────────────────────────────────────── */
.home-hero {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
  color: white;
  padding: 28px 20px 36px;
  text-align: center;
}
.home-hero h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.home-hero p { font-size: 13px; opacity: 0.85; }

.progress-ring-wrap {
  margin: 20px auto 0;
  width: 110px;
  height: 110px;
  position: relative;
}
.progress-ring-wrap svg { transform: rotate(-90deg); }
.progress-ring-circle { transition: stroke-dashoffset 0.6s ease; }
.progress-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px;
  background: var(--surface);
  margin: 0 0 12px;
}
.stat-card {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
  text-align: center;
}
.stat-card .sc-num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-card .sc-label { font-size: 11px; color: var(--text3); margin-top: 2px; }

.due-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 20px;
  margin: 8px auto 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  padding: 8px 16px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px 16px;
}
/* 第5张卡（奇数最后一个）独占整行 */
.mode-grid .mode-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}
.mode-card {
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}
.mode-card:active { transform: scale(0.96); }
.mode-card .mc-icon { font-size: 32px; display: block; margin-bottom: 8px; }
.mode-card .mc-name { font-size: 15px; font-weight: 600; color: var(--text); }
.mode-card .mc-desc { font-size: 12px; color: var(--text3); margin-top: 3px; }

.action-row {
  display: flex;
  gap: 10px;
  padding: 0 16px 20px;
}
.btn-outline {
  flex: 1;
  padding: 12px;
  border: 1.5px solid var(--primary);
  background: none;
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-outline:active { background: var(--surface2); }
.btn-primary {
  flex: 1;
  padding: 12px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--primary-dark); }

/* ── 单词列表页 ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.page-header h3 { font-size: 17px; font-weight: 700; flex: 1; }
.btn-back {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--primary);
  padding: 4px;
}
.word-list-items { padding: 8px 16px 20px; }
.word-list-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.wli-left { flex: 0 0 auto; }
.wli-word { font-size: 17px; font-weight: 600; display: block; }
.wli-phonetic { font-size: 12px; color: var(--text3); font-style: italic; }
.wli-right { flex: 1; text-align: right; }
.wli-meaning { font-size: 13px; color: var(--text2); display: block; }
.wli-level { font-size: 12px; color: var(--warning); display: block; margin-top: 2px; }

/* ── 学习通用结构 ────────────────────────────────────────── */
.study-header {
  background: var(--surface);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.study-header .progress-text { font-size: 13px; color: var(--text3); flex: 1; text-align: right; }
.progress-bar-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 2px;
  transition: width 0.3s ease;
}
.study-body { padding: 20px 16px; }

/* ── 闪卡 ─────────────────────────────────────────────── */
.flashcard-wrap {
  perspective: 1000px;
  height: 280px;
  margin: 0 auto 20px;
  cursor: pointer;
  user-select: none;
}
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.flashcard.flipped { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backface-visibility: hidden;
}
.card-front {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}
.card-back {
  background: var(--surface);
  color: var(--text);
  transform: rotateY(180deg);
  border: 2px solid var(--border);
}
.fc-word { font-size: 36px; font-weight: 700; margin-bottom: 8px; }
.fc-phonetic { font-size: 15px; opacity: 0.85; margin-bottom: 8px; }
.fc-flip-hint { font-size: 12px; opacity: 0.7; margin-top: 12px; }
.fc-back-meaning { font-size: 18px; font-weight: 600; color: var(--primary); margin-bottom: 8px; text-align: center; }
.fc-back-example { font-size: 13px; color: var(--text2); text-align: center; font-style: italic; }
.fc-level { font-size: 13px; color: var(--text3); margin-top: 8px; }
.fc-top-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  color: var(--text3);
}
.btn-icon:active { opacity: 0.7; }
.fc-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.btn-know {
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-unknown {
  background: var(--error);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ── 选择题 ────────────────────────────────────────────── */
.ch-word-card {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
  color: white;
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.ch-word { font-size: 34px; font-weight: 700; }
.ch-phonetic { font-size: 14px; opacity: 0.8; margin-top: 4px; }
.ch-speak-btn {
  margin-top: 10px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 20px;
  color: white;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
}
.choices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.choice-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}
.choice-btn:active { background: var(--surface2); }
.choice-btn.selected { background: #E8EAF6; border-color: var(--primary); color: var(--primary); font-weight: 600; }
.choice-btn.correct { background: #E8F5E9; border-color: var(--success); color: #2E7D32; }
.choice-btn.wrong { background: #FFEBEE; border-color: var(--error); color: #C62828; }

/* ── 拼写 / 听写 ─────────────────────────────────────────── */
.spell-card, .dictation-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.sp-meaning, .dt-meaning { font-size: 18px; font-weight: 600; color: var(--primary); margin-bottom: 8px; }
.sp-example, .dt-example { font-size: 13px; color: var(--text2); font-style: italic; }
.dt-controls { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.btn-play {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 30px;
  padding: 10px 24px;
  font-size: 14px;
  cursor: pointer;
}
.input-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.spell-input, .dictation-input {
  flex: 1;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
}
.spell-input:focus, .dictation-input:focus { border-color: var(--primary); }
.btn-submit {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
}
.sp-result, .dt-result {
  font-size: 16px;
  font-weight: 600;
  padding: 8px 0;
  min-height: 32px;
}
.sp-result.correct, .dt-result.correct { color: var(--success); }
.sp-result.wrong, .dt-result.wrong { color: var(--error); }
.sp-hint-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}
.dt-revealed {
  font-size: 14px;
  color: var(--text2);
  padding: 6px 0;
  min-height: 24px;
}
.btn-next {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

/* ── 完成页 ─────────────────────────────────────────────── */
.end-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 24px;
  text-align: center;
}
.end-icon { font-size: 72px; margin-bottom: 16px; }
.end-page h2 { font-size: 24px; font-weight: 700; color: var(--primary); }
.end-page p { color: var(--text2); margin-top: 6px; font-size: 15px; }
.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
  width: 100%;
}
.end-stat { background: var(--surface2); border-radius: var(--radius-sm); padding: 16px 8px; }
.end-stat .es-num { font-size: 26px; font-weight: 700; color: var(--primary); }
.end-stat .es-label { font-size: 12px; color: var(--text3); margin-top: 2px; }
.end-btns { display: flex; gap: 12px; width: 100%; }

/* ── 统计页 ─────────────────────────────────────────────── */
.stats-body { padding: 16px; }
.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.stat-bar-label { width: 32px; font-size: 12px; color: var(--text2); text-align: right; flex-shrink: 0; }
.stat-bar-track {
  flex: 1;
  height: 16px;
  background: var(--surface2);
  border-radius: 8px;
  overflow: hidden;
}
.stat-bar-fill { height: 100%; border-radius: 8px; transition: width 0.6s ease; }
.stat-bar-count { width: 60px; font-size: 11px; color: var(--text3); flex-shrink: 0; }

/* ── 导入页 ─────────────────────────────────────────────── */
.import-body { padding: 16px; }
.import-tip {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 12px;
  line-height: 1.6;
}
.import-tip code { background: var(--surface); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.import-textarea {
  width: 100%;
  height: 200px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: monospace;
  resize: vertical;
  outline: none;
  color: var(--text);
  background: var(--surface);
  margin-bottom: 12px;
}
.import-textarea:focus { border-color: var(--primary); }
.import-btns { display: flex; gap: 10px; }

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: white;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.info { background: var(--primary); }

/* ── 认证页 ─────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 48px;
  background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary-light) 100%);
}
.auth-logo { font-size: 56px; margin-bottom: 8px; }
.auth-title { font-size: 28px; font-weight: 800; color: white; margin-bottom: 4px; }
.auth-sub { font-size: 14px; color: rgba(255,255,255,0.75); margin-bottom: 28px; }

.auth-tabs {
  display: flex;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
  width: 100%;
  max-width: 340px;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 9px;
  background: none;
  color: rgba(255,255,255,0.7);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.auth-tab.active {
  background: white;
  color: var(--primary-dark);
}

.auth-form {
  width: 100%;
  max-width: 340px;
}
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input::placeholder { color: rgba(255,255,255,0.45); }
.form-group input:focus { border-color: rgba(255,255,255,0.8); }
.pwd-row { position: relative; }
.pwd-row input { padding-right: 44px; }
.btn-eye {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.7;
  padding: 4px;
}
.auth-error {
  font-size: 13px;
  color: #FFD54F;
  min-height: 20px;
  margin-bottom: 10px;
  text-align: center;
}
.btn-auth-submit {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: white;
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-auth-submit:disabled { opacity: 0.6; }
.btn-auth-submit:active { opacity: 0.85; }

/* ── 用户头像按钮 ─────────────────────────────────────────── */
.btn-avatar {
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── 用户菜单弹层 ─────────────────────────────────────────── */
.menu-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
}
.user-menu {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 201;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
.user-menu-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
}
.user-avatar-lg { font-size: 36px; }
.user-email { font-size: 14px; color: var(--text2); word-break: break-all; }
.menu-divider { border: none; border-top: 1px solid var(--border); margin: 0 0 12px; }
.menu-item {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.menu-item:active { background: var(--surface2); }
.menu-cancel { color: var(--text3); margin-top: 4px; text-align: center; }

/* ── 确认按钮宽度修正 ─────────────────────────────────────── */
.btn-block { width: 100%; margin-bottom: 8px; }

/* ── 加载遮罩 ─────────────────────────────────────────────── */
.loading-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 300;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--text2); }
