:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2330;
  --muted: #8a90a2;
  --line: #e8eaf2;
  --accent: #4f7cff;
  --accent-soft: #eaf0ff;
  --green: #2bbf7a;
  --red: #ff6b6b;
  --amber: #f5a623;
  --radius: 12px;
  --nav-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 14px 18px 8px;
}
.app-header h1 { margin: 0; font-size: 22px; font-weight: 700; }

#app { padding: 6px 14px 20px; max-width: 560px; margin: 0 auto; }

.page.hidden, .hidden { display: none !important; }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
  box-shadow: 0 1px 4px rgba(40,50,90,.06);
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 14px; font-weight: 400; }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ===== 按钮 ===== */
.btn {
  border: none; border-radius: 10px; padding: 12px 16px;
  font-size: 16px; font-weight: 600; cursor: pointer; width: 100%;
  transition: transform .05s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #b9c5ee; cursor: not-allowed; }
.btn-ghost { background: var(--accent-soft); color: var(--accent); }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row .btn { flex: 1; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 12px; flex-wrap: wrap; }
.row-between .btn { width: auto; padding: 10px 22px; }
/* 窄屏（字数提示 + 按钮挤不下时）让按钮单独占一行 */
@media (max-width: 360px) { .row-between .btn { width: 100%; } }

/* ===== 学习计划卡 ===== */
.plan-card { background: #2d3556; color: #fff; }
.plan-stage { font-size: 18px; font-weight: 700; }
.plan-meta { font-size: 14px; opacity: .9; margin: 6px 0 12px; }
.plan-bar { height: 8px; background: rgba(255,255,255,.16); border-radius: 6px; overflow: hidden; }
.plan-bar-fill { height: 100%; background: var(--accent); border-radius: 6px; width: 0%; transition: width .4s; }

/* ===== 打卡卡 ===== */
.streak-card { text-align: center; }
.streak-num { font-size: 40px; font-weight: 800; color: var(--accent); line-height: 1; }
.streak-num small { font-size: 16px; color: var(--muted); margin-left: 4px; font-weight: 600; }
.streak-label { color: var(--muted); font-size: 14px; margin-top: 6px; }
.week-dots { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.week-dots .dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  font-size: 12px; display: flex; align-items: center; justify-content: center;
}
.week-dots .dot.done { background: var(--green); color: #fff; }
.week-dots .dot.today { box-shadow: 0 0 0 2px var(--accent); }

/* ===== 任务清单 ===== */
.task-list { list-style: none; margin: 0; padding: 0; }
.task-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.task-list li:last-child { border-bottom: none; }
.task-check {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line);
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px;
}
.task-check.checked { background: var(--green); border-color: var(--green); }
.task-text { flex: 1; }
.task-text.done { text-decoration: line-through; color: var(--muted); }
.task-go { flex: 0 0 auto; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.today-date { font-weight: 400; }

/* ===== 分段控件 ===== */
.seg { display: flex; background: var(--accent-soft); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg-btn {
  flex: 1; border: none; background: transparent; padding: 9px;
  border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--accent); cursor: pointer;
}
.seg-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ===== 单词卡 ===== */
.flashcard { perspective: 1000px; min-height: 200px; padding: 0; background: transparent; box-shadow: none; }
.flashcard-inner {
  position: relative; width: 100%; min-height: 200px;
  transition: transform .5s; transform-style: preserve-3d; cursor: pointer;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(40,50,90,.06);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.flashcard-back { transform: rotateY(180deg); }
.review-badge { position: absolute; top: 12px; left: 12px; background: var(--amber); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.pronounce-btn { position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border: none; border-radius: 50%; background: var(--accent-soft); font-size: 19px; cursor: pointer; line-height: 1; }
.pronounce-btn:active { transform: scale(.92); }
.word-en { font-size: 32px; font-weight: 800; }
.word-pos { color: var(--muted); margin-top: 6px; font-style: italic; }
.tap-hint { position: absolute; bottom: 14px; color: var(--muted); font-size: 12px; }
.word-cn { font-size: 22px; font-weight: 700; }
.word-ex { color: var(--muted); margin-top: 12px; font-size: 15px; }
.card-progress { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0 2px; }

/* 单词 AI 讲解面板 */
#word-ai { margin-top: 12px; }
.ai-card { background: var(--accent-soft); border-radius: 12px; padding: 14px; }
.ai-sec { font-size: 14px; margin-bottom: 8px; line-height: 1.6; }
.ai-sec b { color: var(--accent); }
.ai-card .sug-list { margin: 4px 0 0; }
.ai-loading { text-align: center; color: var(--muted); }

/* ===== 测试 ===== */
.q-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: 0 2px 10px rgba(40,50,90,.05); }
.q-num { color: var(--muted); font-size: 13px; }
.q-word { font-size: 24px; font-weight: 800; margin: 6px 0 14px; }
.opt {
  display: block; width: 100%; text-align: left; border: 1.5px solid var(--line);
  background: #fff; border-radius: 12px; padding: 13px 14px; margin-bottom: 10px;
  font-size: 15px; cursor: pointer;
}
.opt.correct { border-color: var(--green); background: #eafaf2; }
.opt.wrong { border-color: var(--red); background: #ffeeee; }
.opt:disabled { cursor: default; }
.result-score { font-size: 44px; font-weight: 800; color: var(--accent); text-align: center; }

/* ===== 写作 ===== */
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.ta, .input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 15px; font-family: inherit; background: #fbfcff; color: var(--ink);
}
.ta { resize: vertical; }
.input:read-only { color: var(--muted); background: #f3f4f8; }

.link-btn { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; width: auto; padding: 0; }
.count-low { color: var(--amber) !important; }
.count-ok { color: var(--green) !important; }
.del-btn { background: none; border: none; cursor: pointer; font-size: 15px; width: auto; padding: 0 0 0 10px; }
.hist-right { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
#trend svg { display: block; }

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 2px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.history-list li:last-child { border-bottom: none; }
.history-band { font-weight: 800; color: var(--accent); }

/* ===== 批改结果 ===== */
.overall-band { text-align: center; padding: 8px 0 16px; }
.overall-band .num { font-size: 56px; font-weight: 800; color: var(--accent); line-height: 1; }
.overall-band .lbl { color: var(--muted); font-size: 14px; }
.dim-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.dim-row:last-child { border-bottom: none; }
.dim-head { display: flex; justify-content: space-between; font-weight: 700; }
.dim-band { color: var(--accent); }
.dim-comment { color: var(--muted); font-size: 14px; margin-top: 4px; }
.dim-comment .en { color: var(--ink); display: block; margin-top: 2px; }
.sug-list { margin: 8px 0 0; padding-left: 18px; }
.sug-list li { margin-bottom: 8px; }

/* ===== 进度面板 ===== */
.stats-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.stat { flex: 1 1 28%; text-align: center; background: var(--accent-soft); border-radius: 12px; padding: 16px 6px; }
.stat-num { font-size: 28px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
  display: flex;
}
.nav-btn {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; padding: 6px 0;
}
.nav-btn.active { color: var(--accent); }
.nav-ico { line-height: 0; }
.nav-ico svg { width: 24px; height: 24px; display: block; }

/* ===== 遮罩 ===== */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(20,24,40,.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #fff;
}
.spinner {
  width: 40px; height: 40px; border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
