:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #1a1d26;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --primary: #4f6ef7;
  --primary-weak: #eef1ff;
  --border: #e5e7eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.dark {
  --bg: #0f1115;
  --bg-card: #1a1d24;
  --bg-elevated: #23262f;
  --text: #e8eaed;
  --text-secondary: #9aa0ab;
  --text-muted: #6b7280;
  --primary: #6b84ff;
  --primary-weak: #232a45;
  --border: #2c313c;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.5);
}

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

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* 顶部栏 */
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; border: none; background: transparent;
  color: var(--text); font-size: 22px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:active { background: var(--border); }
.hidden { visibility: hidden; }

/* 主视图 */
.view { flex: 1; overflow-y: auto; padding: 16px 14px 90px; }

/* 底部导航 */
.tabbar {
  display: flex; flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--text-muted);
  padding: 8px 0 6px; font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--primary); }

/* 卡片 */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.card-desc { font-size: 13px; color: var(--text-secondary); margin: 0; }

/* 按钮 */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff;
}
.btn:active { opacity: .85; }
.btn.secondary { background: var(--primary-weak); color: var(--primary); }
.btn.outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.small { padding: 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 单词卡片 */
.word-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
  user-select: none; transition: border-color .15s, background .15s;
}
.word-card:active { background: var(--primary-weak); }
.word-card .w-head { display: flex; align-items: center; justify-content: space-between; }
.word-card .w-word { font-size: 20px; font-weight: 700; letter-spacing: .3px; }
.word-card .w-sound { font-size: 18px; color: var(--primary); opacity: .8; }
.word-card .w-detail { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.word-card.open .w-detail { display: block; }
.w-phonetic { color: var(--text-secondary); font-size: 14px; margin-bottom: 4px; }
.w-pos { color: var(--primary); font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.w-trans { font-size: 15px; color: var(--text); }
.w-def { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.w-example { font-size: 13px; color: var(--text-muted); margin-top: 6px; font-style: italic; }

/* 标记按钮组 */
.mark-row { display: flex; gap: 8px; margin-top: 12px; }
.mark-btn {
  flex: 1; padding: 12px 0; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.mark-btn.know { background: #e7f6ec; color: var(--success); }
.mark-btn.fuzzy { background: #fdf3e0; color: var(--warning); }
.mark-btn.unknown { background: #fdeaea; color: var(--danger); }
.mark-btn:active { opacity: .8; }
.mark-btn.done { outline: 3px solid currentColor; }

/* 进度条 */
.progress-wrap { margin: 12px 0; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }

/* 列表项 */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-size: 15px; font-weight: 500; }
.list-item .li-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.list-item .li-right { font-size: 13px; color: var(--text-muted); flex-shrink: 0; margin-left: 10px; }

/* 徽章 */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--primary-weak); color: var(--primary); }

/* 网格 */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-box .num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-box .label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* 测试选项 */
.quiz-option {
  display: block; width: 100%; padding: 14px 16px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card);
  font-size: 16px; cursor: pointer; text-align: left; color: var(--text);
}
.quiz-option:active { background: var(--primary-weak); }
.quiz-option.correct { border-color: var(--success); background: #e7f6ec; color: var(--success); }
.quiz-option.wrong { border-color: var(--danger); background: #fdeaea; color: var(--danger); }
.quiz-word { font-size: 26px; font-weight: 700; text-align: center; margin: 20px 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.82); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 1000;
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--bg-elevated); border-radius: 16px; padding: 20px;
  width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* 分段选择 */
.seg { display: flex; background: var(--border); border-radius: 10px; padding: 3px; margin: 10px 0; }
.seg-item { flex: 1; text-align: center; padding: 9px 0; border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--text-secondary); border: none; background: transparent; }
.seg-item.active { background: var(--bg-card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

/* 输入框 */
.input, select.input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; background: var(--bg-card); color: var(--text);
}
textarea.input { min-height: 80px; resize: vertical; font-family: inherit; }

/* 页面过渡 */
.page-title { font-size: 18px; font-weight: 700; margin: 4px 0 12px; }
.section-gap { height: 8px; }
.muted { color: var(--text-muted); }
.center { text-align: center; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
