/* ====== 全局重置与基础 ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f6ef7;
  --primary-hover: #3b5de7;
  --success: #52c41a;
  --success-hover: #45a818;
  --danger: #ff4d4f;
  --warning: #faad14;
  --text: #2c3e50;
  --text-secondary: #7f8c8d;
  --text-muted: #bdc3c7;
  --bg: #f5f7fa;
  --bg-white: #ffffff;
  --border: #e8ecf1;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ====== 导航栏 ====== */
#navbar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#navUser { color: var(--text-secondary); font-size: 14px; }

/* ====== 页面容器 ====== */
.page { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }
.page.hidden { display: none; }

/* ====== 按钮 ====== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 20px; border-radius: var(--radius); border: 1px solid transparent;
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s;
  text-decoration: none; line-height: 1.5;
}
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 36px; font-size: 16px; border-radius: var(--radius-lg); }
.btn-block { display: flex; width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ====== 表单 ====== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--text); }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"] {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text); background: var(--bg-white); transition: border-color 0.2s;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,0.1); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ====== 弹窗/Modal ====== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg-white); border-radius: var(--radius-lg);
  padding: 28px 32px; max-width: 440px; width: 90%;
  box-shadow: var(--shadow-lg);
}
.modal-box p { margin-bottom: 16px; font-size: 15px; color: var(--text); }
.modal-box h3 { margin-bottom: 20px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-upload { max-width: 520px; }

/* ====== Toast ====== */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 28px;
  border-radius: var(--radius); font-size: 14px; z-index: 2000;
  box-shadow: var(--shadow-lg); transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: var(--text); }

/* ====== 认证页面 ====== */
.auth-container {
  min-height: calc(100vh - 120px); display: flex;
  align-items: center; justify-content: center;
}
.auth-card {
  background: var(--bg-white); border-radius: var(--radius-lg);
  padding: 48px 40px; width: 400px; box-shadow: var(--shadow-lg);
}
.auth-title { font-size: 24px; font-weight: 700; text-align: center; color: var(--primary); margin-bottom: 8px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.auth-tab {
  flex: 1; padding: 10px; text-align: center; font-size: 15px; font-weight: 500;
  background: none; border: none; cursor: pointer; color: var(--text-secondary);
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-form.hidden { display: none; }
.auth-form .btn { margin-top: 8px; }

/* ====== 首页 ====== */
.home-container { text-align: center; }
.home-hero { margin: 24px 0 36px; }
.home-hero h1 { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.home-hero p { color: var(--text-secondary); font-size: 15px; }

.section { background: var(--bg-white); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-header h2 { font-size: 18px; font-weight: 600; }

.book-list { text-align: left; }
.book-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 8px; cursor: pointer; transition: all 0.2s;
}
.book-item:hover { border-color: var(--primary); background: rgba(79,110,247,0.03); }
.book-item.selected { border-color: var(--primary); background: rgba(79,110,247,0.06); }
.book-info { flex: 1; }
.book-name { font-weight: 500; font-size: 15px; }
.book-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.book-actions { display: flex; gap: 6px; }
.book-delete { color: var(--danger); background: none; border: none; cursor: pointer; font-size: 13px; padding: 4px 8px; border-radius: 4px; }
.book-delete:hover { background: rgba(255,77,79,0.1); }

.home-actions { display: flex; gap: 16px; justify-content: center; margin-top: 32px; }

/* ====== 学习页面 ====== */
.learn-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.learn-book-name { font-weight: 600; flex: 1; }
.learn-progress { color: var(--text-secondary); font-size: 14px; }

.learn-card-container { display: flex; flex-direction: column; align-items: center; }
.learn-nav { display: flex; gap: 12px; margin-bottom: 24px; }

.word-card {
  background: var(--bg-white); border-radius: var(--radius-lg); padding: 48px;
  width: 100%; max-width: 600px; min-height: 320px; box-shadow: var(--shadow);
  text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.word-card-word { font-size: 36px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.word-card-phonetic { font-size: 16px; color: var(--text-secondary); margin-bottom: 8px; }
.word-card-pos { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; font-style: italic; }
.word-card-definition { font-size: 20px; color: var(--text); margin-bottom: 16px; }
.word-card-example { font-size: 14px; color: var(--text-secondary); max-width: 480px; line-height: 1.8; }

/* 多词性释义 */
.word-card-meanings { text-align: left; width: 100%; max-width: 480px; margin-bottom: 12px; }
.meaning-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.meaning-pos {
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: rgba(79,110,247,0.08); padding: 2px 8px; border-radius: 4px;
  flex-shrink: 0; min-width: 32px; text-align: center;
}
.meaning-def { font-size: 14px; color: var(--text); }
.meaning-def::before { content: '· '; color: var(--text-muted); }
.dict-loading { font-size: 12px; color: var(--text-muted); }

.word-card-actions { display: flex; gap: 12px; margin-top: 24px; }
#btnMark { background: #fff7e6; border-color: #ffd591; color: #d48806; }
#btnMark.marked { background: #fff1f0; border-color: #ffa39e; color: #cf1322; }

/* ====== 检测页面 ====== */
.quiz-container { max-width: 900px; margin: 0 auto; }

.quiz-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.quiz-book-name { font-weight: 600; flex: 1; }
.quiz-timer { font-size: 20px; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; }

.quiz-ready { text-align: center; padding: 60px 20px; }
.quiz-ready h2 { font-size: 22px; margin-bottom: 12px; }
.quiz-ready p { margin-bottom: 10px; color: var(--text-secondary); }
.quiz-ready .btn { margin-top: 16px; }

.quiz-word-display { text-align: center; margin-bottom: 32px; min-height: 80px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.quiz-word-display span:first-child { font-size: 24px; font-weight: 600; color: var(--text); }
.quiz-word-hint { font-size: 14px; color: var(--text-muted); margin-top: 8px; }

.quiz-input-area { display: flex; gap: 12px; max-width: 440px; margin: 0 auto 32px; }
.quiz-input { flex: 1; padding: 12px 16px; border: 2px solid var(--border); border-radius: var(--radius); font-size: 16px; }
.quiz-input:focus { outline: none; border-color: var(--primary); }
.quiz-input.error { border-color: var(--danger); animation: shake 0.4s; }
.quiz-input.correct { border-color: var(--success); }

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

.quiz-progress { text-align: center; }
.quiz-progress-bar { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.quiz-progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; border-radius: 3px; }
#quizProgressText { font-size: 13px; color: var(--text-secondary); }

.quiz-result.hidden { display: none; }
.quiz-result { text-align: center; padding: 40px 20px; }

/* ====== 排行榜 ====== */
.leaderboard-section { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); }
.lb-column { background: var(--bg-white); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.lb-column h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.lb-list { max-height: 480px; overflow-y: auto; }

.lb-item { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid #f5f5f5; font-size: 13px; }
.lb-item:last-child { border-bottom: none; }
.lb-rank { width: 32px; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.lb-rank.gold { color: #faad14; }
.lb-rank.silver { color: #95a5a6; }
.lb-rank.bronze { color: #cd7f32; }
.lb-info { flex: 1; }
.lb-info .lb-name { font-weight: 500; }
.lb-info .lb-detail { font-size: 12px; color: var(--text-secondary); }
.lb-value { font-weight: 600; color: var(--primary); flex-shrink: 0; text-align: right; }

/* ====== 文本样式 ====== */
.text-muted { color: var(--text-muted); text-align: center; padding: 20px; font-size: 14px; }
.text-center { text-align: center; }

/* ====== 消息条 ====== */
.message-bar { padding: 14px 20px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.message-bar.success { background: #f6ffed; border: 1px solid #b7eb8f; color: #389e0d; }
.message-bar.error { background: #fff2f0; border: 1px solid #ffccc7; color: #cf1322; }
.message-bar.info { background: #e6f7ff; border: 1px solid #91d5ff; color: #096dd9; }
.message-bar.warning { background: #fffbe6; border: 1px solid #ffe58f; color: #d48806; }

/* ====== 加载旋转 ====== */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== 上传弹窗 ====== */
.upload-tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.upload-tab {
  flex: 1; padding: 8px 12px; text-align: center; font-size: 13px; font-weight: 500;
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--text-secondary); transition: all 0.2s;
}
.upload-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.upload-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text); resize: vertical; font-family: inherit; line-height: 1.8;
}
.upload-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,0.1); }

/* ====== 响应式微调 ====== */
@media (max-width: 768px) {
  .leaderboard-section { grid-template-columns: 1fr; }
  .auth-card { width: 90%; padding: 32px 24px; }
  .word-card { padding: 32px 24px; }
  .word-card-word { font-size: 28px; }
}
