:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2fb;
  --text: #16203a;
  --muted: #6b7793;
  --line: #e2e7f2;
  --brand: #2f5bea;
  --brand-soft: #e8edff;
  --good: #17a673;
  --good-soft: #e4f7f0;
  --bad: #ef5b5b;
  --bad-soft: #fdeceb;
  --warn: #b5761c;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(22, 32, 58, 0.08);
  --topbar-h: 54px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1424;
    --surface: #182036;
    --surface-2: #202a45;
    --text: #eaeefb;
    --muted: #9aa6c5;
    --line: #2a3554;
    --brand: #6d8dff;
    --brand-soft: #232f52;
    --good: #34c48f;
    --good-soft: #17392f;
    --bad: #ff7b7b;
    --bad-soft: #3c2226;
    --warn: #e0a84c;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-title { font-size: 17px; font-weight: 650; margin: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-left: auto; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--brand);
  font-size: 26px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
}

.view {
  padding: 14px 14px 24px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 60vh;
}

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a span { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: .04em;
  margin: 18px 2px 8px;
}
.section-title .count {
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; }
.tiny { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; font-weight: 600; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn.block { display: block; width: 100%; }
.btn[disabled] { opacity: .5; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.pill.done { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.doing { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.pill.due { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
textarea { min-height: 180px; resize: vertical; line-height: 1.5; font-size: 14px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- 学习卡片 ---------- */
.study-wrap { display: flex; flex-direction: column; gap: 12px; }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress > i { display: block; height: 100%; background: var(--brand); transition: width .2s ease; }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 22px 18px;
  min-height: 46vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.flashcard .word { font-size: 34px; font-weight: 700; letter-spacing: .01em; word-break: break-word; }
.flashcard .zh-main { font-size: 24px; font-weight: 600; line-height: 1.4; }
.flashcard .phonetic { color: var(--muted); font-size: 16px; }
.answer-block { border-top: 1px dashed var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.answer-meaning { font-size: 18px; }
.answer-word { font-size: 26px; font-weight: 700; }
.example { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.example .ex-zh { color: var(--muted); margin-top: 4px; font-size: 13px; }
.footer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.footer-actions .btn { padding: 16px; font-size: 17px; }
.footer-actions.single { grid-template-columns: 1fr; }

.speak-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--brand);
  cursor: pointer;
}

.spell-input {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  letter-spacing: .02em;
  padding: 14px 14px;
}
.spell-input::placeholder { font-size: 15px; letter-spacing: 0; }
.study-actions { display: flex; flex-direction: column; gap: 10px; }

.word-line { padding: 9px 2px; border-bottom: 1px solid var(--line); }
.word-line:last-child { border-bottom: none; }
.word-line .en { font-weight: 650; }
.word-line .ex { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.group-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  cursor: pointer;
}
.group-item .name { font-weight: 620; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20, 26, 45, .92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  max-width: 86vw;
  text-align: center;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 26px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.notice { border-radius: 12px; padding: 10px 12px; font-size: 13px; background: var(--bad-soft); color: var(--bad); margin-bottom: 10px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.notice.ok { background: var(--good-soft); color: var(--good); }

.dup-line { border-left: 3px solid var(--warn); padding-left: 8px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }
.checkline input { width: auto; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
details summary { cursor: pointer; color: var(--brand); font-size: 13px; }
