/* ===== 基础 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4f8; --card: #fff; --text: #1a202c; --muted: #718096;
  --primary: #5a67d8; --primary-hover: #4c51bf;
  --success: #38a169; --danger: #e53e3e; --warning: #d69e2e;
  --border: #e2e8f0; --hover-bg: #edf2f7;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.08), 0 4px 10px rgba(0,0,0,.05);
  --radius: 16px; --radius-sm: 10px;
}

/* 暗色模式 */
[data-theme="dark"] {
  --bg: #0f1419; --card: #1a1f2e; --text: #e2e8f0; --muted: #8892a8;
  --primary: #7c8cf0; --primary-hover: #93a0f3;
  --success: #48bb78; --danger: #fc8181; --warning: #ecc94b;
  --border: #2d3748; --hover-bg: #252d3f;
  --shadow: 0 2px 8px rgba(0,0,0,.25); --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  display: flex; justify-content: center; padding: 12px;
}

.container {
  width: 100%; max-width: 640px; height: calc(100vh - 24px);
  display: flex; flex-direction: column; gap: 8px;
}

/* ===== 头部 ===== */
header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
header h1 { font-size: 1.2rem; font-weight: 700; white-space: nowrap; }

.theme-toggle {
  background: var(--card); border: 2px solid var(--border);
  border-radius: 50%; width: 36px; height: 36px;
  font-size: 1rem; cursor: pointer; transition: all .3s;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--primary); transform: rotate(15deg); }

/* ===== Tab 导航 ===== */
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 7px 14px; border: 1.5px solid var(--border); background: var(--card);
  border-radius: 999px; font-size: .82rem; cursor: pointer;
  transition: all .25s cubic-bezier(.4,0,.2,1);
  font-family: inherit; color: var(--muted);
}
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.tab-panel { display: none; flex-direction: column; flex: 1; gap: 8px; overflow: hidden; }
.tab-panel.active { display: flex; }

/* ===== 通用 ===== */
.top-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }
.lib-bar { display: flex; gap: 6px; align-items: center; }
.date-bar { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.date-select {
  padding: 6px 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .78rem; background: var(--card); cursor: pointer; outline: none;
  max-width: 140px;
}
.date-select:focus { border-color: var(--primary); }

.lib-select {
  padding: 8px 10px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .85rem; background: var(--card); cursor: pointer; outline: none;
  min-width: 140px;
}
.lib-select:focus { border-color: var(--primary); }

.date-label { font-weight: 600; font-size: .9rem; min-width: 90px; text-align: center; }

/* ===== 按钮 ===== */
.btn {
  padding: 10px 18px; border: none; border-radius: var(--radius-sm);
  font-size: .82rem; font-weight: 600; cursor: pointer;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  font-family: inherit; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-green { background: var(--success); color: #fff; }
.btn-green:hover { background: #2f855a; }
.btn-outline { background: var(--card); color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-outline.active { background: var(--primary); color: #fff; }
.btn-danger { background: var(--card); color: var(--danger); border: 1px solid var(--danger); font-size: .8rem; padding: 8px 10px; }
.btn-danger:hover { background: #fed7d7; }
.btn-sm { padding: 6px 10px; font-size: .78rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-quit { background: var(--card); color: var(--muted); border: 1px solid var(--border); }
.btn-quit:hover { background: #fed7d7; color: var(--danger); border-color: var(--danger); }
.btn-review { background: var(--warning); color: #fff; }
.btn-review:hover { background: #b7791f; }
.btn-warning { background: var(--warning); color: #1a202c; font-weight: 700; }
.btn-warning:hover { background: #d69e2e; transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn.loading {
  pointer-events: none; opacity: .7;
  animation: btnPulse 1.2s ease-in-out infinite;
}
@keyframes btnPulse {
  0%, 100% { opacity: .7; }
  50% { opacity: .4; }
}

/* ===== 输入区 ===== */
.input-area { display: flex; flex-direction: column; gap: 6px; }
.word-input {
  width: 100%; padding: 12px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit; resize: vertical; outline: none; line-height: 1.6;
}
.word-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(90,103,216,.15); }
.input-actions { display: flex; justify-content: space-between; align-items: center; }
.input-hint { font-size: .75rem; color: var(--muted); }

.add-status {
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: .85rem; text-align: center;
}
.add-status.success { background: #c6f6d5; color: #276749; }
.add-status.error { background: #fed7d7; color: #9b2c2c; }
.add-status.hidden { display: none; }

/* ===== 搜索 ===== */
.search-wrap { display: flex; gap: 8px; align-items: center; }
.search-input {
  flex: 1; padding: 9px 12px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .85rem; outline: none; font-family: inherit;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(90,103,216,.15); }
.day-count { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ===== 学习统计 ===== */
.stats-bar {
  display: flex; gap: 8px; padding: 4px 0 8px; flex-wrap: wrap;
}
.stats-bar.hidden { display: none; }
.stat-item {
  font-size: .76rem; color: var(--muted); background: var(--card);
  padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border);
  white-space: nowrap;
}

/* ===== 单词列表 ===== */
.word-list {
  flex: 1; overflow-y: auto; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); min-height: 80px;
}
.empty-hint {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); font-size: .95rem; padding: 30px 20px; text-align: center;
}

.word-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  transition: background .2s ease;
}
.word-item:last-child { border-bottom: none; }
.word-item:hover { background: var(--hover-bg); }
.word-item .eng { font-weight: 600; color: var(--primary); font-size: .9rem; min-width: 100px; }
.word-item .chn { color: var(--text); font-size: .85rem; flex: 1; }
.word-item .item-speaker {
  width: 28px; height: 28px; border: none; background: var(--bg); border-radius: 50%;
  font-size: .8rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: .2s;
}
.word-item .item-speaker:hover { background: var(--primary); color: #fff; }
.word-item .item-del {
  width: 24px; height: 24px; border: none; background: transparent; border-radius: 50%;
  font-size: .85rem; cursor: pointer; color: var(--muted); transition: .2s;
}
.word-item .item-del:hover { background: #fed7d7; color: var(--danger); }

/* 汇总模式 */
.date-group { padding: 0; }
.date-group-header {
  padding: 10px 14px; background: var(--bg); font-weight: 700; font-size: .85rem;
  color: var(--primary); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 1;
}
.date-group-header .count { font-size: .75rem; color: var(--muted); font-weight: 400; }
.summary-total { padding: 10px 14px; font-size: .85rem; color: var(--muted); text-align: center; border-bottom: 1px solid var(--border); }

/* ===== 练习设置 ===== */
.practice-setup {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.practice-setup h3 { font-size: 1rem; }
.setup-row { display: flex; align-items: center; gap: 10px; }
.setup-row label { font-size: .85rem; font-weight: 600; min-width: 40px; }
.setup-select {
  flex: 1; padding: 8px 10px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .85rem; background: var(--card); cursor: pointer; outline: none;
}
.mode-switch { display: flex; gap: 12px; }
.mode-option { font-size: .85rem; cursor: pointer; display: flex; align-items: center; gap: 4px; }

/* ===== 练习区 ===== */
.practice-area { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.practice-area.hidden { display: none; }

.prac-header { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; }
.prac-progress { color: var(--primary); }
.prac-score { color: var(--muted); }

.prac-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 36px 24px; display: flex; flex-direction: column; align-items: center; gap: 14px;
  flex: 1; justify-content: center;
  animation: cardIn .35s cubic-bezier(.4,0,.2,1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.prac-prompt { font-size: 1.6rem; font-weight: 700; color: var(--text); text-align: center; }

.speaker-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 3px solid var(--border);
  background: var(--bg); font-size: 1.2rem; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.speaker-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.speaker-btn.speaking { background: var(--primary); color: #fff; border-color: var(--primary); animation: pulse .8s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(90,103,216,.4); }
  50% { box-shadow: 0 0 0 14px rgba(90,103,216,0); }
}

.prac-answer {
  width: 100%; max-width: 320px; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1.1rem; text-align: center; outline: none;
  font-family: inherit;
}
.prac-answer:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(90,103,216,.15); }
.prac-answer.correct { border-color: var(--success); background: #f0fff4; }
.prac-answer.wrong { border-color: var(--danger); background: #fff5f5; }

.prac-chinese {
  font-size: .9rem; color: var(--muted); text-align: center;
}

/* ===== 影印字母提示 ===== */
.letter-hint {
  display: flex; gap: 4px; justify-content: center; flex-wrap: wrap;
}
.letter-box {
  width: 32px; height: 38px; border: 2px solid var(--border); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; font-family: 'Courier New', monospace;
  transition: all .15s; background: var(--hover-bg); color: var(--muted);
  text-transform: lowercase;
}
.letter-box.match { background: #c6f6d5; border-color: #38a169; color: #276749; }
.letter-box.wrong { background: #fed7d7; border-color: #e53e3e; color: #9b2c2c; }
.letter-box.current { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(90,103,216,.2); }

.prac-feedback {
  font-size: 1rem; font-weight: 600; text-align: center; padding: 8px 16px; border-radius: var(--radius-sm);
}
.prac-feedback.correct { color: var(--success); background: #f0fff4; }
.prac-feedback.wrong { color: var(--danger); background: #fff5f5; }
.prac-feedback.hidden { display: none; }

.prac-sentence {
  background: var(--hover-bg); border-radius: var(--radius-sm); padding: 12px 14px;
  max-width: 400px; text-align: center;
}
.prac-sentence.hidden { display: none; }
.sentence-en { font-size: .85rem; color: var(--text); font-style: italic; margin-bottom: 4px; }
.sentence-cn { font-size: .8rem; color: var(--muted); }
.sentence-speaker {
  width: 26px; height: 26px; border: none; background: var(--bg);
  border-radius: 50%; font-size: .75rem; cursor: pointer; transition: .2s;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); vertical-align: middle; margin-bottom: 4px; flex-shrink: 0;
}
.sentence-speaker:hover { background: var(--primary); color: #fff; }
.sentence-speaker.speaking { background: var(--primary); color: #fff; animation: pulse .8s infinite; }
.prac-image {
  max-width: 200px; max-height: 150px; border-radius: var(--radius-sm);
  object-fit: cover; margin: 0 auto;
}
.prac-image.hidden { display: none; }

.prac-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.hidden { display: none !important; }

/* ===== 练习结果 ===== */
.practice-result {
  background: var(--card); border-radius: var(--radius); padding: 32px 20px;
  box-shadow: var(--shadow); text-align: center; display: flex;
  flex-direction: column; align-items: center; gap: 16px;
}
.result-stats { font-size: 1.1rem; line-height: 1.8; }

/* ===== 复习 ===== */
.review-count { font-size: .8rem; color: var(--muted); }
.review-list {
  flex: 1; overflow-y: auto; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); min-height: 80px;
}

.review-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
}
.review-item:last-child { border-bottom: none; }
.review-item .eng { font-weight: 600; color: var(--primary); font-size: .9rem; }
.review-item .chn { color: var(--text); font-size: .85rem; }
.review-item .review-date-badge {
  font-size: .7rem; color: var(--muted); background: var(--bg);
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
  margin-left: auto;
}
.review-item .item-speaker {
  width: 28px; height: 28px; border: none; background: var(--bg); border-radius: 50%;
  font-size: .8rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: .2s;
}
.review-item .item-speaker:hover { background: var(--primary); color: #fff; }
.review-item .item-master {
  padding: 5px 10px; border: 1px solid var(--success); background: var(--card); color: var(--success);
  border-radius: 15px; font-size: .75rem; cursor: pointer; transition: .2s; font-family: inherit;
}
.review-item .item-sentence {
  width: 28px; height: 28px; border: none; background: var(--bg); border-radius: 50%;
  font-size: .85rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: .2s;
}
.review-item .item-sentence:hover { background: var(--warning); color: #fff; }
.review-item .item-master:hover { background: var(--success); color: #fff; }
.review-sentence {
  padding: 8px 14px 8px 24px; background: var(--hover-bg); border-bottom: 1px solid var(--border);
  font-size: .82rem;
}
.review-sentence.hidden { display: none; }
.review-sentence .sentence-en { font-style: italic; color: var(--text); margin-bottom: 2px; }
.review-sentence .sentence-cn { color: var(--muted); }

/* ===== 新建词库弹窗 ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; justify-content: center; align-items: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  max-width: 400px; width: 100%; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { font-size: 1rem; }
.modal-input {
  padding: 10px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit; outline: none;
}
.modal-input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== 响应式 ===== */
@media (max-width: 640px) {
  body { padding: 0; }
  .container { height: 100vh; gap: 6px; border-radius: 0; }

  /* 头部缩小 */
  header { padding: 8px; gap: 4px; }
  header h1 { font-size: 1rem; }
  .tab { padding: 8px 10px; font-size: .75rem; }

  /* 顶部栏竖排 */
  .top-bar { flex-direction: column; gap: 6px; padding: 0 8px; }
  .date-bar { justify-content: center; }
  .lib-select { min-width: 0; flex: 1; font-size: .82rem; padding: 10px 8px; }
  .date-select { font-size: .75rem; max-width: none; flex: 1; }

  /* 输入区全宽 */
  .input-area { padding: 0 8px; }
  .word-input { font-size: 1rem; padding: 14px 12px; }
  .input-actions { flex-direction: column; align-items: stretch; gap: 6px; }
  .input-hint { text-align: center; }

  /* 搜索 */
  .search-wrap { padding: 0 8px; }
  .search-input { font-size: 1rem; padding: 12px; }

  /* 单词列表占满 */
  .word-list { border-radius: 0; }
  .word-item { padding: 14px 12px; gap: 8px; }
  .word-item .eng { font-size: .95rem; min-width: 80px; }
  .word-item .chn { font-size: .9rem; }
  .word-item .item-speaker,
  .word-item .item-del { width: 36px; height: 36px; font-size: 1rem; }

  /* 练习设置 */
  .practice-setup { padding: 16px 12px; border-radius: 0; gap: 12px; }
  .setup-row { flex-wrap: wrap; }
  .mode-switch { flex-direction: column; gap: 6px; }
  .mode-option { font-size: .9rem; padding: 8px 0; }

  /* 练习卡片 */
  .prac-card { padding: 20px 14px; border-radius: 0; }
  .prac-prompt { font-size: 1.3rem; }
  .prac-answer { max-width: 100%; font-size: 1.2rem; padding: 14px; }
  .letter-box { width: 28px; height: 34px; font-size: 1rem; }
  .prac-sentence { max-width: 100%; }
  .prac-actions { width: 100%; }
  .prac-actions .btn { flex: 1; padding: 12px; font-size: .9rem; }

  /* 练习结果 */
  .practice-result { border-radius: 0; padding: 24px 16px; }

  /* 复习 */
  .review-list { border-radius: 0; }
  .review-item { flex-wrap: wrap; padding: 14px 12px; gap: 6px; }
  .review-item .eng { font-size: .95rem; }
  .review-item .chn { font-size: .9rem; }
  .review-item .review-date-badge { font-size: .7rem; }
  .review-item .item-speaker,
  .review-item .item-sentence { width: 34px; height: 34px; font-size: .9rem; }
  .review-item .item-master { padding: 8px 12px; font-size: .8rem; }

  /* 防止 iOS 缩放 */
  input[type="text"], input[type="search"], textarea { font-size: 16px !important; }
}
