:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #14181f;
  --ink-2: #5b6472;
  --ink-3: #8b93a1;
  --line: #e5e8f0;
  --brand: #3b5bfd;
  --brand-soft: #eaeeff;
  --ok: #159c6b;
  --ok-soft: #e6f7f0;
  --bad: #e0413f;
  --bad-soft: #fdecec;
  --warn: #b8721a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .05), 0 8px 24px rgba(20, 24, 31, .06);
}

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

/* 有 display 规则的元素会盖掉浏览器默认的 [hidden]，统一钉死 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 4px; }

/* ───── 顶栏 ───── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  font-size: 19px;
  color: var(--ink-2);
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--brand-soft); }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 14px;
  font-weight: 600;
  max-width: 40vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip[hidden] { display: none; }

main {
  padding: 14px 14px calc(env(safe-area-inset-bottom) + 32px);
  max-width: 720px;
  margin: 0 auto;
}
.view[hidden] { display: none; }

/* ───── 今日 ───── */
.today-card {
  background: linear-gradient(135deg, #3b5bfd, #6a4bfd);
  border-radius: var(--radius);
  padding: 16px;
  color: #fff;
  box-shadow: var(--shadow);
}
.today-row { display: flex; }
.today-stat { flex: 1; text-align: center; }
.today-stat b { display: block; font-size: 26px; line-height: 1.2; }
.today-stat span { font-size: 12px; opacity: .82; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 2px 10px;
}
.link-btn { color: var(--brand); font-size: 14px; font-weight: 600; padding: 4px 2px; }

/* ───── 词库列表 ───── */
.deck-list { display: flex; flex-direction: column; gap: 10px; }
.deck {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.deck-title { font-weight: 650; font-size: 16px; }
.deck-head { display: flex; align-items: flex-start; gap: 8px; }
.deck-head .deck-title { flex: 1; min-width: 0; }
.mini-btn {
  flex: 0 0 auto;
  font-size: 13px; font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 5px 12px;
}
.mini-btn:active { filter: brightness(.94); }
.deck-sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.deck-tags { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tag {
  font-size: 12.5px; padding: 3px 9px; border-radius: 999px;
  background: #f1f3f8; color: var(--ink-2);
}
.tag.due { background: #fff3e6; color: var(--warn); font-weight: 600; }
.tag.new { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tag.done { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.deck-actions { display: flex; gap: 8px; margin-top: 12px; }
.deck-actions button { flex: 1; }

.empty { color: var(--ink-3); font-size: 14px; line-height: 1.7; padding: 8px 4px; }

/* ───── 按钮 ───── */
.primary-btn {
  background: var(--brand); color: #fff;
  border-radius: 12px; padding: 11px 16px;
  font-weight: 650; font-size: 15px;
  min-height: 44px;
}
.primary-btn:active { filter: brightness(.94); }
.primary-btn[disabled] { opacity: .45; }
.ghost-btn {
  background: #f1f3f8; color: var(--ink-2);
  border-radius: 12px; padding: 11px 16px;
  font-weight: 600; font-size: 15px; min-height: 44px;
}
.ghost-btn.danger { background: var(--bad-soft); color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row > .ghost-btn, .row > .primary-btn { flex: 0 0 auto; }

/* ───── 面板 / 表单 ───── */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.panel h2 { margin-bottom: 6px; }
.hint { color: var(--ink-3); font-size: 13.5px; margin: 6px 0 10px; line-height: 1.6; }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 12px;
  padding: 12px;
  outline: none;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus { border-color: var(--brand); }
textarea { resize: vertical; line-height: 1.6; font-size: 15px; }
.file-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 12px; padding: 11px 16px; font-weight: 650; font-size: 15px;
  min-height: 44px;
}
.file-info {
  margin-top: 10px; padding: 10px 12px;
  background: var(--ok-soft); color: var(--ok);
  border-radius: 12px; font-size: 13.5px;
}
.log {
  margin-top: 12px; padding: 12px;
  background: #0f172a; color: #cbd5e1;
  border-radius: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.75;
  max-height: 240px; overflow: auto;
  white-space: pre-wrap;
}

/* ───── 预览 ───── */
.preview-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.preview-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex; gap: 10px; align-items: flex-start;
}
.preview-item.off { opacity: .45; }
.preview-item input[type="checkbox"] { margin-top: 4px; width: 18px; height: 18px; flex: 0 0 auto; }
.preview-word { font-weight: 650; }
.preview-ph { color: var(--brand); font-size: 13px; margin-left: 6px; }
.preview-cn { color: var(--ink-2); font-size: 13.5px; }
.preview-en { color: var(--ink-3); font-size: 13px; }
.save-bar { position: sticky; bottom: 0; padding-top: 12px; background: var(--card); }
.save-bar .primary-btn { width: 100%; }

/* ───── 卡片列表 ───── */
.card-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.card-row {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow);
}
.card-row-head { display: flex; align-items: baseline; gap: 8px; }
.card-row-head .w { font-weight: 650; }
.card-row-head .ph { color: var(--brand); font-size: 13px; }
.card-row-head .spk { margin-left: auto; color: var(--brand); font-size: 18px; }
.card-row-body { color: var(--ink-2); font-size: 14px; margin-top: 3px; }
.card-row-ex { color: var(--ink-3); font-size: 13.5px; margin-top: 4px; }

/* ───── 学习 ───── */
.study-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.study-progress {
  flex: 1; height: 6px; background: #e6e9f2; border-radius: 999px; overflow: hidden;
}
.study-progress > div { height: 100%; width: 0; background: var(--brand); transition: width .25s; }
.study-meta { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.study-meta span { margin-left: 8px; }

.quiz {
  background: var(--card); border-radius: 18px; padding: 18px;
  box-shadow: var(--shadow);
}
.quiz-kind { font-size: 12.5px; color: var(--brand); font-weight: 650; letter-spacing: .3px; }
.quiz-prompt { font-size: 22px; font-weight: 650; margin: 12px 0 4px; line-height: 1.45; }
.quiz-prompt.small { font-size: 18px; font-weight: 500; }
.quiz-sub { color: var(--ink-3); font-size: 13.5px; margin-bottom: 14px; }
.quiz-sentence { font-size: 18px; line-height: 1.7; }
.blank { color: var(--brand); font-weight: 700; letter-spacing: 2px; }
.answer-input {
  width: 100%; font-size: 20px; padding: 14px;
  border: 2px solid var(--line); border-radius: 14px; background: #fbfcfe;
}
.answer-input:focus { border-color: var(--brand); }
.quiz-actions { margin-top: 12px; }
.quiz-actions button { width: 100%; }
.opt-list { display: flex; flex-direction: column; gap: 9px; }
.opt {
  text-align: left; padding: 14px;
  background: #f7f8fc; border: 2px solid transparent;
  border-radius: 14px; font-size: 16px; line-height: 1.5;
}
.opt:active { background: var(--brand-soft); }
.opt.right { background: var(--ok-soft); border-color: var(--ok); color: #0d6b4a; font-weight: 600; }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); color: #9c2320; }
.opt[disabled] { opacity: .85; }

.result { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.verdict { font-size: 15px; font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.word-line { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.word-line .w { font-size: 26px; font-weight: 700; }
.word-line .ph { color: var(--brand); font-size: 15px; }
.speak {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 17px;
}
.def { margin-top: 10px; }
.def .cn { font-size: 17px; font-weight: 600; }
.def .en { color: var(--ink-2); font-size: 14.5px; margin-top: 2px; }
.ex { margin-top: 12px; padding: 12px; background: #f7f8fc; border-radius: 12px; }
.ex .en { font-size: 15px; line-height: 1.6; }
.ex .cn { color: var(--ink-3); font-size: 13.5px; margin-top: 4px; }
.family { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); line-height: 1.7; }

.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grade-row button { border-radius: 12px; padding: 13px 4px; font-weight: 650; font-size: 14px; min-height: 50px; }
.g0 { background: var(--bad-soft); color: var(--bad); }
.g1 { background: #fdf3e3; color: var(--warn); }
.g2 { background: var(--brand-soft); color: var(--brand); }
.g3 { background: var(--ok-soft); color: var(--ok); }

.done-card {
  background: var(--card); border-radius: 18px; padding: 28px 18px;
  text-align: center; box-shadow: var(--shadow);
}
.done-card .big { font-size: 40px; }
.done-card h2 { margin: 10px 0 6px; font-size: 20px; }
.done-card p { color: var(--ink-3); font-size: 14px; margin: 0 0 18px; }

/* ───── 设置弹窗 ───── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--card);
  width: 100%; max-width: 620px;
  border-radius: 20px 20px 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 16px; overflow: auto; }
.setting-block { margin-bottom: 24px; }
.setting-block input[type="password"], .setting-block input[type="text"] { margin-bottom: 2px; }
.status { font-size: 13px; color: var(--ink-2); margin-top: 8px; line-height: 1.6; word-break: break-word; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.thinking { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; }
.seg { display: flex; background: #f1f3f8; border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 13.5px; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--brand); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.profile-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.profile-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
}
.profile-row.on { border-color: var(--brand); background: var(--brand-soft); }
.profile-row .nm { flex: 1; font-weight: 600; }
.profile-row .del { color: var(--bad); font-size: 13px; }

/* ───── toast ───── */
.toast {
  position: fixed;
  left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: #0f172a; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 80; max-width: 86vw; text-align: center;
}
.toast[hidden] { display: none; }

@media (min-width: 620px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 20px; max-height: 86vh; }
}

/* ───────── 项目卡 ───────── */

.chip.offline { background: #fdf3e3; color: var(--warn); font-weight: 700; }

.file-note { font-size: 13px; color: var(--ink-2); word-break: break-all; }

.proj-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--ink-2); margin-top: 10px;
}
.proj-status .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--brand);
  flex: 0 0 auto;
}
.proj-status.busy .dot { animation: pulse 1.1s ease-in-out infinite; }
.proj-status.ok .dot { background: var(--ok); }
.proj-status.bad .dot { background: var(--bad); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}

.prog {
  display: flex; height: 8px; border-radius: 999px; overflow: hidden;
  background: #eaecf3; margin-top: 10px;
}
.prog i { display: block; height: 100%; transition: width .3s; }
.prog .m { background: var(--ok); }
.prog .f { background: #6f8cff; }
.prog .l { background: #ffc46b; }

.prog-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 12px; color: var(--ink-3); margin-top: 7px;
}
.prog-legend b { font-weight: 650; color: var(--ink-2); }
.prog-legend i {
  display: inline-block; width: 8px; height: 8px; border-radius: 2px;
  margin-right: 4px; vertical-align: -1px;
}

.prog-legend i.m { background: var(--ok); }
.prog-legend i.f { background: #6f8cff; }
.prog-legend i.l { background: #ffc46b; }
.prog-legend i.n { background: #d9dce6; }

.big-num { font-size: 22px; font-weight: 700; color: var(--ink); }
.big-num small { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }

.deck-actions.col { flex-direction: column; }
