:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --ink: #1f2733;
  --ink-soft: #5b6573;
  --ink-faint: #9aa4b2;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --primary-ink: #4338ca;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --warn: #d97706;
  --warn-soft: #fdf0dc;
  --bad: #dc2626;
  --bad-soft: #fdeaea;
  --line: #e6eaf1;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --radius: 16px;
  --radius-sm: 10px;
}

/* ---------- 暗色主题 ---------- */
[data-theme="dark"] {
  --bg: #0f141b;
  --surface: #1a212b;
  --surface-2: #232c39;
  --ink: #e7ecf3;
  --ink-soft: #a7b0bd;
  --ink-faint: #6b7585;
  --primary: #818cf8;
  --primary-soft: #2a2f50;
  --primary-ink: #c7d0ff;
  --ok: #34d399;
  --ok-soft: #142a22;
  --warn: #fbbf24;
  --warn-soft: #2e2510;
  --bad: #f87171;
  --bad-soft: #2e1717;
  --line: #2a3340;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}
[data-theme="dark"] .topbar { background: rgba(26,33,43,.78); }
[data-theme="dark"] .sidebar { background: var(--surface); border-right-color: var(--line); }
[data-theme="dark"] .flip-back { background: linear-gradient(160deg, #232c39, #2a2f50); }
[data-theme="dark"] .hero { box-shadow: 0 12px 30px rgba(0,0,0,.4); }

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

#app { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px;
  box-shadow: 0 6px 16px rgba(79,70,229,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; }
.brand-text span { font-size: 11px; color: var(--ink-faint); letter-spacing: .5px; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  color: var(--ink-soft); text-decoration: none; font-weight: 600; font-size: 14.5px;
  cursor: pointer; transition: all .15s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-ink); }
.nav-ico { font-size: 17px; }

.sidebar-foot { padding-top: 16px; border-top: 1px solid var(--line); }
.data-btns { display: flex; flex-direction: column; gap: 8px; }
.data-btns .btn { width: 100%; }

/* ---------- 主区域 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 72px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.7);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 21px; font-weight: 750; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right {
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.streak-pill {
  background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 13.5px;
  padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(217,119,6,.18);
  box-shadow: 0 2px 8px rgba(217,119,6,.10); white-space: nowrap; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px; cursor: default; user-select: none;
}
.streak-pill .short { display: none; }
.streak-pill .fire { font-size: 15px; }

/* ---------- 账户区 & 同步状态 ---------- */
.account { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.sync-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #9aa4b2; flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(154,164,178,.15);
}
.sync-dot.syncing { background: #d97706; animation: syncPulse 1s ease-in-out infinite; }
.sync-dot.synced { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.sync-dot.error { background: #dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,.18); }
.sync-dot.local { background: #9aa4b2; }
@keyframes syncPulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.account-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-family: inherit; color: var(--ink); transition: all .15s ease;
}
.account-pill:hover { border-color: var(--primary); }
.account-pill .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.account-pill .acc-email { font-size: 13px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-pill .acc-caret { font-size: 10px; color: var(--ink-faint); }
.account-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 180px; z-index: 50;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 14px 34px rgba(16,24,40,.18); padding: 8px; overflow: hidden;
}
.account-menu .acc-info { font-size: 12px; color: var(--ink-faint); padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.acc-item {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border: none; background: transparent;
  border-radius: 9px; cursor: pointer; font-family: inherit; font-size: 13.5px; color: var(--ink);
}
.acc-item:hover { background: var(--surface-2); }
.acc-item.danger { color: var(--bad); }

/* ---------- 登录/注册弹窗 ---------- */
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 700; color: var(--ink-soft);
}
.auth-tab.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.auth-msg { font-size: 13px; min-height: 18px; margin-top: 10px; }
.auth-msg.bad { color: var(--bad); }
.auth-hint { font-size: 12px; color: var(--ink-faint); margin-top: 14px; line-height: 1.5; }
.view { padding: 28px 32px 48px; max-width: 1080px; width: 100%; }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px 18px; border-radius: 11px; border: none; cursor: pointer;
  font-weight: 700; font-size: 14px; font-family: inherit; transition: all .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(79,70,229,.28); }
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); color: var(--ink-soft); }
.btn-ghost:hover { background: #e6eaf1; }
.btn-ghost.danger { color: var(--bad); }
.btn-ghost.danger:hover { background: var(--bad-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

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

/* ---------- 仪表盘 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px; }
.stat {
  padding: 20px 22px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat .stat-label { color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.stat .stat-num { font-size: 34px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.stat .stat-sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.stat.accent .stat-num { color: var(--primary); }
.stat.ok .stat-num { color: var(--ok); }

.hero {
  background: linear-gradient(120deg, #4f46e5, #7c3aed);
  color: #fff; border-radius: 20px; padding: 30px 32px; margin-bottom: 26px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  box-shadow: 0 12px 30px rgba(79,70,229,.3);
}
.hero h2 { font-size: 22px; font-weight: 800; }
.hero p { opacity: .9; margin-top: 6px; font-size: 14px; }
.hero .btn-primary { background: #fff; color: var(--primary-ink); box-shadow: none; }
.hero .btn-primary:hover { background: #f0eeff; }

.section-title { font-size: 16px; font-weight: 750; margin: 4px 0 14px; }

/* 牌组小卡 */
.deck-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.deck-chip {
  padding: 16px 18px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); cursor: pointer; transition: all .15s ease;
  border-left: 4px solid var(--primary);
}
.deck-chip:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(16,24,40,.1); }
.deck-chip .dc-name { font-weight: 750; font-size: 15px; }
.deck-chip .dc-meta { font-size: 12.5px; color: var(--ink-faint); margin-top: 4px; }
.deck-chip .dc-due { color: var(--bad); font-weight: 700; }

/* ---------- 卡片库 ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }

.deck-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.deck-card {
  padding: 20px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); position: relative;
}
.deck-card .dc-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.deck-dot { width: 14px; height: 14px; border-radius: 5px; flex-shrink: 0; }
.deck-card h3 { font-size: 16px; font-weight: 750; }
.deck-card .dc-count { font-size: 13px; color: var(--ink-soft); }
.deck-card .dc-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0 14px; }
.deck-card .dc-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.deck-card .dc-actions { display: flex; gap: 8px; }
.deck-card .dc-actions .btn { flex: 1; padding: 8px; font-size: 13px; }

/* 牌组详情（卡片列表） */
.back-link { color: var(--ink-soft); font-weight: 600; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; margin-bottom: 16px; }
.back-link:hover { color: var(--primary); }
.card-row {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); margin-bottom: 10px;
}
.card-row .cr-side { flex: 1; min-width: 0; }
.card-row .cr-front { font-weight: 700; }
.card-row .cr-back { color: var(--ink-soft); font-size: 13.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row .cr-state { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; flex-shrink: 0; }
.state-new { background: var(--surface-2); color: var(--ink-soft); }
.state-learning { background: var(--warn-soft); color: var(--warn); }
.state-mastered { background: var(--ok-soft); color: var(--ok); }
.card-row .cr-del { color: var(--ink-faint); cursor: pointer; padding: 6px; border-radius: 8px; }
.card-row .cr-del:hover { background: var(--bad-soft); color: var(--bad); }
.card-row .cr-star { color: var(--ink-faint); cursor: pointer; padding: 6px; border-radius: 8px; font-size: 15px; transition: transform .12s ease; }
.card-row .cr-star:hover { background: var(--warn-soft); transform: scale(1.15); }
.card-row .cr-star.on { color: var(--warn); }
.card-row .cr-edit { color: var(--ink-faint); cursor: pointer; padding: 6px; border-radius: 8px; }
.card-row .cr-edit:hover { background: var(--primary-soft); color: var(--primary); }
.card-row .cr-img { margin-right: 6px; filter: saturate(0.9); }
.card-row .cr-mistake { font-size: 13px; font-weight: 700; color: var(--bad); padding: 4px 10px; border-radius: 999px; background: var(--bad-soft); flex-shrink: 0; }

/* 图片卡片字段 */
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn.danger, .btn-sm.danger { color: var(--bad); }
.btn.danger:hover, .btn-sm.danger:hover { background: var(--bad-soft); }
.img-field { margin-top: 4px; }
.img-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.img-preview { margin-top: 8px; }
.img-preview img { max-height: 140px; max-width: 100%; border-radius: 10px; display: block; border: 1px solid var(--line); }
.flip-img { max-height: 220px; max-width: 100%; border-radius: 12px; margin-bottom: 12px; object-fit: contain; background: #fff; border: 1px solid var(--line); }

.weak-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.weak-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.weak-row .wr-main { flex: 1; min-width: 0; }
.weak-row .wr-name { font-weight: 700; font-size: 14.5px; }
.weak-row .wr-sub { font-size: 12.5px; color: var(--ink-faint); }

.empty {
  text-align: center; padding: 56px 20px; color: var(--ink-faint);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .emo { font-size: 40px; }

/* ---------- 学习模式 ---------- */
.study-wrap { max-width: 680px; margin: 0 auto; }
.study-progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 22px; }
.study-progress > span { display: block; height: 100%; background: var(--primary); transition: width .3s ease; }
.study-meta { text-align: center; color: var(--ink-faint); font-size: 13px; margin-bottom: 14px; }

.flip-card {
  perspective: 1400px; height: 320px; margin-bottom: 22px; cursor: pointer;
}
.flip-inner {
  position: relative; width: 100%; height: 100%; transition: transform .55s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center; border: 1px solid var(--line); box-shadow: var(--shadow);
}
.flip-front { background: var(--surface); }
.flip-back { background: linear-gradient(160deg, #fbfaff, #eef0ff); transform: rotateY(180deg); }
.flip-tag { font-size: 12px; font-weight: 700; color: var(--ink-faint); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 14px; }
.flip-text { font-size: 26px; font-weight: 750; }
.flip-hint { position: absolute; bottom: 18px; font-size: 12.5px; color: var(--ink-faint); }

.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.rate-btn {
  padding: 14px 8px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 700; font-size: 14px; color: var(--ink); transition: all .15s ease;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-family: inherit;
}
.rate-btn .r-emo { font-size: 20px; }
.rate-btn small { font-size: 11px; color: var(--ink-faint); font-weight: 600; }
.rate-btn:hover { transform: translateY(-2px); border-color: var(--primary); }
.rate-btn.q1 { color: var(--bad); } .rate-btn.q1:hover { background: var(--bad-soft); }
.rate-btn.q3 { color: var(--warn); } .rate-btn.q3:hover { background: var(--warn-soft); }
.rate-btn.q4 { color: #2563eb; } .rate-btn.q4:hover { background: #e8f0fe; }
.rate-btn.q5 { color: var(--ok); } .rate-btn.q5:hover { background: var(--ok-soft); }

.session-summary { text-align: center; padding: 40px 20px; }
.session-summary .big { font-size: 48px; font-weight: 800; color: var(--primary); }
.summary-stats { display: flex; justify-content: center; gap: 32px; margin: 22px 0 28px; }
.summary-stats div span { display: block; font-size: 26px; font-weight: 800; }
.summary-stats div small { color: var(--ink-faint); }

/* ---------- 统计 ---------- */
.chart-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 18px; }
.chart-card { padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.chart-card h3 { font-size: 15px; font-weight: 750; margin-bottom: 16px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--ink-soft); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }

/* 记忆保持率曲线 */
.retention-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.retention-head .ret-num { font-size: 22px; font-weight: 800; color: var(--primary); }
.retention-head .ret-num.dim { color: var(--ink-soft); font-size: 18px; }
.retention-head small { display: block; font-size: 11.5px; color: var(--ink-faint); }
.ret-badge { min-width: 46px; text-align: center; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; flex-shrink: 0; }
.ret-badge.ok { color: var(--ok); background: var(--ok-soft); }
.ret-badge.warn { color: var(--warn); background: var(--warn-soft); }
.ret-badge.bad { color: var(--bad); background: var(--bad-soft); }
.ret-badge.na { color: var(--ink-faint); background: var(--surface-2); }

/* ---------- 模态框 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16,24,40,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 18px; padding: 26px; width: 100%; max-width: 440px;
  box-shadow: 0 24px 60px rgba(16,24,40,.25);
}
.modal h3 { font-size: 18px; font-weight: 750; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--ink); background: var(--surface-2);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.field input::placeholder,
.field textarea::placeholder { color: var(--ink-faint); opacity: 0.85; }
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
[data-theme="dark"] .field input::placeholder,
[data-theme="dark"] .field textarea::placeholder { color: var(--ink-soft); opacity: 0.95; }
[data-theme="dark"] .field input,
[data-theme="dark"] .field textarea { background: #151b23; border-color: #2f3a49; }
[data-theme="dark"] .field input:focus,
[data-theme="dark"] .field textarea:focus { background: #1a212b; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 76px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

.color-row { display: flex; gap: 8px; }
.color-dot { width: 28px; height: 28px; border-radius: 8px; cursor: pointer; border: 3px solid transparent; }
.color-dot.sel { border-color: var(--ink); }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 11px; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 80; animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 880px) {
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .view { padding: 20px 18px 40px; }
  .topbar { padding: 0 18px; }
  .topbar-right { gap: 8px; }
  .topbar h1 { font-size: 18px; }
  .streak-pill { padding: 6px 10px; font-size: 12px; }
  .rate-btn { padding: 12px 4px; font-size: 13px; }
  .rate-btn small { display: none; }
  .rate-btn .r-key { top: 4px; left: 5px; }
  .flip-card { height: 280px; }
  .flip-text { font-size: 22px; }
  .study-meta { font-size: 12px; }
}

@media (max-width: 560px) {
  .topbar { height: 64px; }
  .topbar h1 { font-size: 16px; max-width: 140px; }
  .streak-pill .full { display: none; }
  .streak-pill .short { display: inline; }
  .account-pill .acc-email { display: none; }
  .account-pill { padding: 5px; }
}

/* 主题切换按钮 */
.theme-toggle {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); cursor: pointer; font-size: 17px;
  display: grid; place-items: center; transition: all .15s ease; flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--primary); transform: translateY(-1px); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); cursor: pointer; font-size: 17px;
  display: grid; place-items: center; transition: all .15s ease; flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--primary); transform: translateY(-1px); }

/* 朗读按钮 */
.speak-btn {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  cursor: pointer; font-size: 16px; display: grid; place-items: center; transition: all .15s ease; z-index: 2;
}
.speak-btn:hover { border-color: var(--primary); color: var(--primary); }
.speak-btn.speaking { color: var(--primary); border-color: var(--primary); }
.audio-play { right: 58px; }

/* 录音字段（卡片弹窗） */
.audio-field { margin-top: 4px; }
.audio-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.audio-preview { margin-top: 8px; }
.audio-preview audio { width: 100%; max-width: 320px; }

/* 复习日历热力图 */
.heatmap-wrap { overflow-x: auto; padding-bottom: 6px; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 4px; }
.heat-cell { width: 15px; height: 15px; border-radius: 3px; background: var(--surface-2); }
.heat-cell.l1 { background: #c7d2fe; }
.heat-cell.l2 { background: #a5b4fc; }
.heat-cell.l3 { background: #818cf8; }
.heat-cell.l4 { background: #4f46e5; }
[data-theme="dark"] .heat-cell { background: #222b38; }
[data-theme="dark"] .heat-cell.l1 { background: #34406e; }
[data-theme="dark"] .heat-cell.l2 { background: #4f5fa8; }
[data-theme="dark"] .heat-cell.l3 { background: #7c8cf0; }
[data-theme="dark"] .heat-cell.l4 { background: #a5b4fc; }
.heat-legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-faint); margin-top: 10px; justify-content: flex-end; }
.heat-legend .heat-cell { width: 12px; height: 12px; }

/* 牌组搜索与筛选 */
.deck-filter { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.deck-filter input {
  flex: 1; min-width: 200px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 11px;
  font-size: 14px; font-family: inherit; color: var(--ink); background: var(--surface-2);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.deck-filter input::placeholder { color: var(--ink-faint); opacity: 0.85; }
.deck-filter input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft); }
[data-theme="dark"] .deck-filter input { background: #151b23; border-color: #2f3a49; }
[data-theme="dark"] .deck-filter input::placeholder { color: var(--ink-soft); opacity: 0.95; }
[data-theme="dark"] .deck-filter input:focus { background: #1a212b; border-color: var(--primary); }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); cursor: pointer; font-size: 13px; font-weight: 600; font-family: inherit; transition: all .15s ease;
}
.filter-chip:hover { border-color: var(--primary); }
.filter-chip.on { background: var(--primary-soft); color: var(--primary-ink); border-color: var(--primary); }

/* ---------- 图表文字（明暗自适应） ---------- */
.donut-pct { fill: var(--ink); }
.donut-sub { fill: var(--ink-faint); }

/* ---------- 学习页退出条 ---------- */
.study-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.study-exit {
  flex-shrink: 0; background: var(--surface-2); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 14px;
  font-weight: 700; font-size: 13px; cursor: pointer; font-family: inherit; transition: all .15s ease;
}
.study-exit:hover { color: var(--primary); border-color: var(--primary); }
.study-exit.undo { color: var(--warn); }
.study-exit.undo:hover { color: var(--warn); border-color: var(--warn); }
.study-meta { flex: 1; text-align: center; color: var(--ink-faint); font-size: 13px; }

/* ---------- 评级按钮键位提示 ---------- */
.rate-btn { position: relative; }
.rate-btn .r-key {
  position: absolute; top: 6px; left: 8px; font-size: 10px; font-weight: 800;
  color: var(--ink-faint); background: var(--surface-2); border-radius: 6px; padding: 1px 5px;
}

/* ---------- 结束页 / 数据管理 ---------- */
.summary-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.data-card .data-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.data-card .data-actions .btn { flex: 1; min-width: 120px; }

/* ---------- 填空卡（Cloze） ---------- */
.cloze {
  display: inline-block; min-width: 52px; text-align: center;
  border-bottom: 2px dashed var(--primary); color: transparent; user-select: none;
  margin: 0 2px;
}
.cloze.revealed { color: var(--primary); font-weight: 600; border-bottom: none; }
.cr-type {
  font-size: 11px; background: var(--primary-soft); color: var(--primary-ink);
  padding: 1px 6px; border-radius: 6px; margin-right: 6px; font-weight: 600;
}
.ret-mini { font-size: 12.5px; color: var(--ink-faint); margin-top: 10px; }
.ret-mini b { color: var(--ink); }

/* ---------- Cloze 填空卡输入自测 ---------- */
.cloze-input {
  width: 92px; text-align: center; font: inherit; font-weight: 600;
  border: none; border-bottom: 2px solid var(--primary); background: transparent;
  color: var(--ink); padding: 2px 4px; margin: 0 2px; border-radius: 0;
}
.cloze-input::placeholder { color: var(--ink-faint); opacity: 0.85; }
.cloze-input:focus { outline: none; border-bottom-color: var(--primary-ink); background: var(--primary-soft); border-radius: 4px 4px 0 0; }
[data-theme="dark"] .cloze-input::placeholder { color: var(--ink-soft); opacity: 0.95; }
[data-theme="dark"] .cloze-input { background: rgba(129,140,248,.08); }
[data-theme="dark"] .cloze-input:focus { background: var(--primary-soft); }
.cloze-input.cloze-ok { border-bottom-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.cloze-input.cloze-bad { border-bottom-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.cloze-check {
  margin-top: 16px; padding: 8px 18px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink-soft); font-weight: 700; font-size: 13.5px;
  cursor: pointer; font-family: inherit; transition: all .15s ease;
}
.cloze-check:hover { border-color: var(--primary); color: var(--primary); }
.cloze-feedback { margin-top: 12px; font-size: 14px; }
.cloze-checked-line { font-weight: 600; line-height: 2; }
.cloze.revealed.ok { color: var(--ok); }
.cloze.revealed.bad { color: var(--bad); }
.cloze-verdict { margin-top: 8px; font-weight: 700; font-size: 13.5px; }
.cloze-verdict.ok { color: var(--ok); }
.cloze-verdict.bad { color: var(--bad); }

/* ---------- 本地快照安全网 ---------- */
.snap-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.snap-head { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.snap-head small { font-weight: 400; color: var(--ink-faint); }
.snap-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px dashed var(--line);
}
.snap-time { font-size: 12.5px; color: var(--ink-soft); }
.snap-empty { font-size: 12.5px; color: var(--ink-faint); margin: 0; }

/* ---------- 卡片弹窗提示 ---------- */
.field-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--ink-faint); }
.field-hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* ---------- 模板牌组 / 空状态欢迎 ---------- */
.welcome-decks {
  text-align: center; padding: 56px 20px; color: var(--ink-soft);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.welcome-decks .welcome-emo { font-size: 44px; }
.welcome-decks h2 { font-size: 20px; font-weight: 750; margin: 10px 0 6px; color: var(--ink); }
.welcome-decks p { font-size: 14px; color: var(--ink-faint); margin-bottom: 18px; }
.welcome-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.welcome-mini {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.welcome-mini span { color: var(--ink-soft); font-weight: 600; font-size: 14px; }

/* 模板弹窗列表 */
.tpl-list { display: flex; flex-direction: column; gap: 10px; }
.tpl-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface-2);
  transition: all .15s ease;
}
.tpl-row:hover { border-color: var(--primary); }
.tpl-row input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.tpl-dot { width: 14px; height: 14px; border-radius: 5px; flex-shrink: 0; }
.tpl-main { display: flex; flex-direction: column; }
.tpl-name { font-weight: 700; font-size: 14.5px; }
.tpl-badge { display: inline-block; font-size: 11px; line-height: 1; padding: 2px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); margin-left: 7px; font-weight: 600; vertical-align: middle; }
.tpl-sub { font-size: 12.5px; color: var(--ink-faint); }

/* ---------- 移动端底部导航栏 ---------- */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 8px 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.08); z-index: 40;
}
@media (min-width: 881px) { .mobile-nav { display: none !important; } }
@media (max-width: 880px) { .mobile-nav { display: flex; } }
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 20px; border-radius: 12px; border: none; background: transparent;
  cursor: pointer; font-family: inherit; color: var(--ink-soft); transition: all .15s ease;
}
.mobile-nav-item:hover { background: var(--surface-2); }
.mobile-nav-item.active { color: var(--primary); background: var(--primary-soft); }
.mobile-nav-item .mnav-ico { font-size: 18px; }
.mobile-nav-item .mnav-text { font-size: 11px; font-weight: 700; }

/* ---------- 学习页移动端优化 ---------- */
@media (max-width: 880px) {
  .study-wrap { padding-bottom: 80px; }
  .flip-card { height: 260px; }
  .flip-text { font-size: 20px; }
  .rate-btn { padding: 10px 4px; font-size: 12px; }
  .rate-btn .r-key { font-size: 9px; padding: 0 4px; }
}

/* ---------- 手势翻卡效果 ---------- */
.flip-card.gesture-left .flip-inner { transform: rotateY(180deg); }
.flip-card.gesture-right .flip-inner { transform: rotateY(0deg); }
.flip-card.swipe-left { animation: swipeLeft 0.3s ease-out; }
.flip-card.swipe-right { animation: swipeRight 0.3s ease-out; }
@keyframes swipeLeft {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); opacity: 0; }
}
@keyframes swipeRight {
  0% { transform: translateX(0); }
  100% { transform: translateX(100%); opacity: 0; }
}

/* 小程序入口条 */
.mp-entry {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: #1a6b5a;
  color: #fff;
  border-radius: 50px;
  padding: 10px 20px;
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(26,107,90,0.3);
  cursor: pointer;
  max-width: 90vw;
}
.mp-entry-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mp-icon {
  font-size: 18px;
}
.mp-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  margin-left: 8px;
  cursor: pointer;
  opacity: 0.7;
}
.mp-close:hover {
  opacity: 1;
}
