* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  color-scheme: light;
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --text-2: #86868B;
  --primary: #007AFF;
  --success: #34C759;
  --error: #FF3B30;
  --divider: #E5E5EA;
  --r-card: 16px;
  --r-btn: 14px;
  --r-input: 12px;
  --r-tag: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.04);
  --tabbar-h: 56px;
}
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body { overflow-x: hidden; }

.view { display: none; }
.view.active { display: block; }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--r-btn); padding: 14px 18px;
  font-size: 16px; font-weight: 600; cursor: pointer; line-height: 1;
  transition: opacity .15s ease, transform .05s ease;
  min-height: 48px;
}
.btn:active { opacity: .7; transform: scale(.99); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary[disabled] { opacity: .4; pointer-events: none; }
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-logout { background: #fff; color: var(--error); border: 1px solid var(--divider); }

.icon-btn {
  background: none; border: none; color: var(--primary); font-size: 28px;
  width: 44px; height: 44px; cursor: pointer; line-height: 44px;
  border-radius: 12px; transition: opacity .15s;
}
.icon-btn:active { opacity: .6; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  background: var(--card); border-radius: var(--r-card); padding: 36px 28px 30px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center;
}
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.login-sub { font-size: 14px; color: var(--text-2); margin-bottom: 28px; }
.login-input {
  width: 100%; border: 1px solid var(--divider); border-radius: var(--r-input);
  padding: 14px 16px; font-size: 16px; margin-bottom: 16px; text-align: center;
  background: var(--card); color: var(--text);
}
.login-input:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--error); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 页面容器 ---------- */
.page { max-width: 560px; margin: 0 auto; padding: 16px 16px 28px; }
.page-header { display: flex; align-items: center; gap: 8px; padding: 8px 0 16px; }
.page-header h1 { font-size: 22px; font-weight: 700; }

/* ---------- 首页 ---------- */
.home-header { display: flex; align-items: flex-end; justify-content: space-between; padding: 20px 0 18px; }
.greeting { font-size: 14px; color: var(--text-2); margin-bottom: 4px; }
.home-title { font-size: 24px; font-weight: 700; }
.home-date { font-size: 13px; color: var(--text-2); }

.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px;
}
.stat-cell {
  background: var(--card); border-radius: var(--r-card); padding: 16px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: var(--shadow);
}
.stat-num { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-2); }

.entries { display: flex; flex-direction: column; gap: 12px; }
.entry {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border: none; border-radius: var(--r-card); padding: 16px; cursor: pointer;
  box-shadow: var(--shadow); text-align: left; transition: opacity .15s;
  min-height: 68px;
}
.entry:active { opacity: .7; }
.entry-primary { background: var(--primary); color: #fff; }
.entry-primary .entry-text small { color: rgba(255,255,255,.85); }
.entry-icon {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #F0F7FF; color: var(--primary);
}
.entry-primary .entry-icon { background: rgba(255,255,255,.18); color: #fff; }
.entry-icon svg { width: 24px; height: 24px; }
.entry-text { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.entry-text b { font-size: 16px; font-weight: 600; }
.entry-text small { font-size: 12px; color: var(--text-2); }
.entry-arrow { font-size: 22px; color: #C7C7CC; }

.encourage { text-align: center; color: var(--text-2); font-size: 13px; padding: 26px 0 8px; }

/* ---------- 刷题页 ---------- */
.quiz-page {
  display: flex; flex-direction: column;
  height: 100vh;
  height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom));
  padding: 0 16px;
}
.quiz-topbar {
  display: flex; align-items: center; gap: 4px; padding: 10px 0 12px;
  border-bottom: 1px solid var(--divider); flex-shrink: 0;
}
.quiz-topbar .icon-btn { margin-left: -8px; }
.quiz-mode { font-size: 17px; font-weight: 600; flex: 1; }
.quiz-count { font-size: 13px; color: var(--text-2); }

.quiz-scroll { flex: 1; overflow-y: auto; padding: 16px 0 20px; -webkit-overflow-scrolling: touch; }

.question-card { padding: 18px; }
.q-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.tag {
  background: #EAF3FF; color: var(--primary); font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--r-tag); flex-shrink: 0;
}
.q-chapter { font-size: 12px; color: var(--text-2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-btn {
  background: none; border: none; font-size: 26px; color: #C7C7CC; cursor: pointer;
  width: 44px; height: 44px; line-height: 44px; flex-shrink: 0; transition: color .15s;
}
.fav-btn.on { color: #FFCC00; }
.q-content { font-size: 18px; line-height: 1.7; margin-bottom: 18px; white-space: pre-wrap; word-break: break-word; }

.q-options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; background: var(--card);
  border: 1.5px solid var(--divider); border-radius: 12px; padding: 14px;
  cursor: pointer; font-size: 15px; line-height: 1.5; transition: border-color .12s, background .12s;
  min-height: 44px;
}
.opt:active { opacity: .8; }
.opt.sel { border-color: var(--primary); background: #F0F7FF; }
.opt input { display: none; }
.opt .letter {
  width: 26px; height: 26px; border-radius: 8px; background: #F2F2F7;
  color: var(--text); font-weight: 600; font-size: 14px; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;
}
.opt.sel .letter { background: var(--primary); color: #fff; }
.opt .txt { flex: 1; word-break: break-word; }
.opt.correct { border-color: var(--success); background: #F0FFF4; }
.opt.correct .letter { background: var(--success); color: #fff; }
.opt.wrong { border-color: var(--error); background: #FFF0F0; }
.opt.wrong .letter { background: var(--error); color: #fff; }
.opt.judge { justify-content: center; font-size: 16px; font-weight: 600; }
.tip { font-size: 12px; color: var(--text-2); margin-top: 10px; text-align: center; }

.text-input {
  width: 100%; border: 1.5px solid var(--divider); border-radius: var(--r-input);
  padding: 14px; font-size: 16px; background: #fff; color: var(--text);
  font-family: inherit; line-height: 1.6; resize: vertical;
}
.text-input:focus { outline: none; border-color: var(--primary); }
.text-input.area { min-height: 140px; }

.q-result { margin-top: 18px; }
.verdict { font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.verdict.ok { color: var(--success); }
.verdict.no { color: var(--error); }
.answer-line { font-size: 15px; margin-bottom: 12px; }
.answer-line b { color: var(--success); }
.explain {
  background: #F9F9FB; border-radius: 12px; padding: 14px; font-size: 14px;
  line-height: 1.7; color: #3A3A3C; white-space: pre-wrap; word-break: break-word;
}
.selfmark { margin-top: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.selfmark-label { font-size: 14px; color: var(--text-2); }
.btn.mark { padding: 11px 22px; font-size: 15px; }
.btn.ok-btn { background: var(--success); color: #fff; }
.btn.no-btn { background: var(--error); color: #fff; }

.quiz-bottom {
  flex-shrink: 0; padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--divider);
}
.bottom-row { display: flex; gap: 10px; }
.bottom-row #prev-btn { flex: 0 0 auto; padding-left: 20px; padding-right: 20px; }
.bottom-row #submit-btn { flex: 1; }

/* ---------- 章节/题型选择 ---------- */
.chapter-list, .type-list { display: flex; flex-direction: column; gap: 12px; }
.chapter-item { padding: 16px; }
.ch-info { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.ch-info b { font-size: 15px; }
.ch-info small { color: var(--text-2); font-size: 12px; }
.ch-bar { height: 5px; border-radius: 3px; background: var(--divider); overflow: hidden; }
.ch-bar i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.ch-actions { display: flex; gap: 10px; }
.ch-actions .btn { flex: 1; }
.btn-sm { min-height: 40px; padding: 10px; font-size: 14px; }
.type-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px; cursor: pointer;
}
.type-item:active { opacity: .7; }
.type-name { font-size: 16px; font-weight: 600; }
.type-count { font-size: 13px; color: var(--text-2); }

/* ---------- 加载/错误 ---------- */
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 0; color: var(--text-2); }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--divider);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { text-align: center; padding: 40px 0; color: var(--text-2); }
.error-box p { margin-bottom: 14px; }

/* ---------- 卡片/子页面 ---------- */
.card { background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); }
.sub-card { padding: 24px; text-align: center; margin-bottom: 16px; }
.sub-title { font-size: 14px; color: var(--text-2); margin-bottom: 8px; }
.sub-num { font-size: 44px; font-weight: 700; margin-bottom: 8px; }
.sub-desc { font-size: 13px; color: var(--text-2); }
.empty { text-align: center; padding: 40px 0; color: var(--text-2); }
.empty-icon {
  width: 64px; height: 64px; border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  margin: 0 auto 14px; color: var(--success); box-shadow: var(--shadow);
}
.empty p { font-size: 14px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff;
  border-top: 1px solid var(--divider); display: flex; z-index: 100;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar.hidden { display: none; }
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0 6px; color: var(--text-2); min-height: 52px;
}
.tab-icon svg { width: 24px; height: 24px; }
.tab-label { font-size: 10px; }
.tab.active { color: var(--primary); }

/* 页面底部预留 tabbar 空间 */
body.with-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* 淡入过渡 */
.view.active { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
