/* 英语积累本 —— 移动优先 */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #8a90a0;
  --line: #e6e8ee;
  --accent: #4f6ef7;
  --accent-soft: #eef1fe;
  --green: #2eb872;
  --green-soft: #e8f8f0;
  --orange: #f2994a;
  --orange-soft: #fef3e7;
  --red: #eb5757;
  --red-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ===== 布局 ===== */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(244, 245, 247, .92);
  backdrop-filter: blur(10px);
}
.app-title { font-weight: 700; font-size: 17px; }
.streak-chip {
  background: var(--card); border-radius: 999px; padding: 4px 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
#main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(84px + env(safe-area-inset-bottom));
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 4px 0;
}
.tab .tab-icon { font-size: 20px; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ===== 通用组件 ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.btn {
  border: none; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; padding: 10px 16px;
  font-family: inherit; transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--accent-soft); color: var(--accent); }
.btn-plain { background: #f0f1f5; color: var(--ink); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-block { width: 100%; display: block; }
.btn-sm { font-size: 13px; padding: 6px 12px; border-radius: 8px; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; font-family: inherit;
  background: #fff; color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
label.field { display: block; margin-bottom: 12px; }
label.field .field-name { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  border-radius: 999px; padding: 2px 8px; vertical-align: middle;
}
.badge-new { background: var(--accent-soft); color: var(--accent); }
.badge-review { background: var(--green-soft); color: var(--green); }
.badge-mastered { background: #f3e8ff; color: #9333ea; }
.badge-warn { background: var(--orange-soft); color: var(--orange); }

/* 空态 */
.empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty .empty-icon { font-size: 44px; margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ===== 登录 ===== */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo { font-size: 56px; margin-bottom: 8px; }
.login-box h1 { font-size: 22px; margin-bottom: 4px; }
.login-box .muted { margin-bottom: 20px; }
.login-box input { margin-bottom: 12px; text-align: center; }
.login-error { color: var(--red); font-size: 14px; margin-top: 10px; }

/* ===== Toast ===== */
#toastWrap {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 90vw;
}
.toast {
  background: #2a2f3d; color: #fff; font-size: 14px;
  padding: 9px 18px; border-radius: 999px; box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ===== 弹层 ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 90; background: rgba(20, 24, 40, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
  animation: modal-in .22s ease;
}
@keyframes modal-in { from { transform: translateY(40px); opacity: .5; } }
.modal h3 { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
@media (min-width: 640px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 18px; }
}

/* ===== 面板通用 ===== */
.panel h2 { font-size: 19px; margin: 10px 2px 12px; }
.panel-sub { color: var(--muted); font-size: 13px; margin: -8px 2px 12px; }

/* ===== 句子库 ===== */
.gen-hint { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.lib-toolbar { margin-bottom: 10px; }
.tag-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tag-chip {
  border: none; background: var(--card); color: var(--muted); cursor: pointer;
  border-radius: 999px; padding: 5px 13px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.tag-chip.on { background: var(--accent); color: #fff; }
.sentence-item { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; }
.sentence-main { flex: 1; min-width: 0; cursor: pointer; }
.detail-dialogue { margin-bottom: 14px; }
.sentence-text { font-weight: 600; font-size: 16px; }
.sentence-trans { font-size: 14px; margin: 2px 0 8px; }
.sentence-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.sentence-ops { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.lib-io { display: flex; gap: 10px; justify-content: center; margin: 18px 0 6px; }

/* ===== 今日学习 ===== */
.study-progress {
  position: relative; height: 26px; background: var(--card); border-radius: 999px;
  margin: 12px 0 14px; overflow: hidden; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.study-progress-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent-soft); transition: width .3s;
}
.study-progress span { position: relative; }
.study-card { padding: 20px 18px; }
.study-listening { text-align: center; padding: 36px 18px; }
.listen-icon { font-size: 54px; margin-bottom: 10px; }
.listen-ops { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.study-target { font-size: 19px; font-weight: 700; margin-top: 4px; }
.study-target mark, .line-en mark { background: #fff3bf; border-radius: 4px; padding: 0 3px; }
.study-trans { color: var(--muted); margin-top: 4px; }
.study-note { font-size: 13px; color: var(--muted); margin-top: 8px; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.study-hr { border: none; border-top: 1px dashed var(--line); margin: 16px 0 12px; }

.dialogue-scene { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 12px; }
.dialogue-lines { display: flex; flex-direction: column; gap: 10px; }
.dialogue-line {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px 10px; border-radius: 10px; transition: background .2s;
}
.dialogue-line.playing { background: var(--accent-soft); }
.speaker-tag {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff;
}
.speaker-a .speaker-tag { background: var(--accent); }
.speaker-b .speaker-tag { background: var(--green); }
.line-body { flex: 1; min-width: 0; }
.line-en { font-size: 15.5px; font-weight: 500; }
.line-zh { font-size: 13px; margin-top: 1px; }
.line-play { border: none; background: none; cursor: pointer; font-size: 16px; opacity: .55; padding: 2px; }
.line-play:hover { opacity: 1; }

/* 每日目标 */
.goal-row { display: flex; gap: 10px; margin: 10px 0 4px; }
.goal-chip {
  flex: 1; background: var(--card); border-radius: 12px; padding: 8px 12px;
  box-shadow: var(--shadow); font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.goal-chip b { margin-left: auto; color: var(--ink); }
.goal-chip.done b { color: var(--green); }
.goal-bar { width: 100%; height: 5px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.goal-bar div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.goal-chip.done .goal-bar div { background: var(--green); }

/* 听懂/听不懂 */
.listen-judge { display: flex; gap: 10px; }
.listen-judge .btn { flex: 1; padding: 14px 0; font-size: 15px; }
.listen-ok { background: var(--green-soft); color: var(--green); }
.listen-fail { background: var(--orange-soft); color: var(--orange); }
.fail-banner {
  background: var(--orange-soft); color: var(--orange); font-size: 13.5px; font-weight: 600;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; text-align: center;
}
.badge-fail { background: var(--red-soft); color: var(--red); }

/* 用法列表 */
.usage-list { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.usage-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.usage-item { padding: 7px 0; }
.usage-name { font-size: 13px; font-weight: 700; color: var(--accent); }
.usage-en { font-size: 15px; margin-top: 2px; }
.usage-zh { font-size: 13px; }

.grade-row { display: flex; gap: 10px; margin-top: 14px; }
.grade-btn { flex: 1; padding: 14px 0; font-size: 15px; }
.grade-forgot { background: var(--red-soft); color: var(--red); }
.grade-fuzzy { background: var(--orange-soft); color: var(--orange); }
.grade-know { background: var(--green-soft); color: var(--green); }

/* ===== 设置 ===== */
.setting-title { font-weight: 700; margin-bottom: 12px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; gap: 12px;
}
.setting-name { font-size: 14.5px; }
.seg { display: flex; background: #f0f1f5; border-radius: 10px; padding: 3px; }
.seg-btn {
  border: none; background: none; cursor: pointer; border-radius: 8px;
  padding: 6px 16px; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.seg-btn.on { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.key-row { padding: 10px 0; border-bottom: 1px dashed var(--line); margin-bottom: 6px; }
.key-info { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14.5px; }
.key-ops { display: flex; gap: 8px; }
.key-ops input { flex: 1; min-width: 0; }
.key-mask {
  background: var(--bg) !important; color: var(--muted) !important;
  font-family: ui-monospace, Menlo, monospace; letter-spacing: .5px; cursor: default;
}

/* 生成进度横幅 */
.gen-progress {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 80; background: var(--card); border-radius: 12px;
  box-shadow: 0 4px 20px rgba(20, 24, 40, .18);
  padding: 12px 16px; overflow: hidden;
  font-size: 13.5px; font-weight: 600;
  max-width: 616px; margin: 0 auto;
}
.gen-progress-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent-soft); transition: width .4s;
}
.gen-progress span { position: relative; }

/* ===== 统计 ===== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stage-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.stage-name { width: 36px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.stage-bar-wrap { flex: 1; height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.stage-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.stage-bar-mastered { background: var(--green); }
.stage-count { width: 30px; text-align: right; font-size: 13px; font-weight: 700; }
@media (max-width: 420px) { .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; } }
