/* ============ 基础 ============ */
:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #16211b;
  --muted: #6b7a72;
  --border: #e2e8e0;
  --primary: #17624f;
  --primary-soft: #dcf3e6;
  --on-primary: #ffffff;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --good: #15803d;
  --good-soft: #e3f4e7;
  --shadow: 0 10px 30px rgba(22, 33, 27, .08), 0 2px 6px rgba(22, 33, 27, .05);
  --radius: 20px;
  --tap: 56px;
}

[data-theme="dark"] {
  --bg: #0f1713;
  --surface: #17211b;
  --surface-2: #1e2a23;
  --text: #e8f0ea;
  --muted: #93a39a;
  --border: #2a3830;
  --primary: #34d399;
  --primary-soft: #12352a;
  --on-primary: #052e1c;
  --danger: #f87171;
  --danger-soft: #3a1d1c;
  --warn: #fbbf24;
  --warn-soft: #3a2c12;
  --good: #4ade80;
  --good-soft: #14331f;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* 关键：作者样式里的 display 会覆盖浏览器默认的 [hidden]，这里统一兜底 */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, ol, ul { margin: 0; }
h1 { font-size: 1.7rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1.15rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: .92em;
}

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

/* ============ 顶栏 ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-color: var(--border); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand img { border-radius: 9px; }

.topnav { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; }
.nav-btn {
  border: 0;
  background: transparent;
  padding: 9px 18px;
  border-radius: 11px;
  font-size: .95rem;
  color: var(--muted);
  font-weight: 600;
}
.nav-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 20px calc(96px + env(safe-area-inset-bottom));
}

.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.date-line { color: var(--muted); font-size: .92rem; margin: 4px 2px 12px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px 0 16px;
}
.section-head h1 { flex: 1; }

/* ============ 今日 ============ */
.hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 26px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.ring {
  --p: 0;
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid;
  place-items: center;
  flex: none;
}
.ring-inner {
  width: 122px;
  height: 122px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1.2;
}
.ring-inner strong { font-size: 2rem; letter-spacing: -.03em; }
.ring-inner span { font-size: .75rem; color: var(--muted); }

.hero-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hero-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .95rem; }
.hero-row b { margin-left: auto; color: var(--text); font-size: 1.05rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.new { background: var(--primary); }
.dot.review { background: var(--warn); }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}
.stat-strip.four { grid-template-columns: repeat(4, 1fr); }
.stat-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 12px;
  text-align: center;
}
.stat-cell b { display: block; font-size: 1.5rem; letter-spacing: -.02em; }
.stat-cell span { color: var(--muted); font-size: .8rem; }

/* ============ 面板 ============ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 1rem; }
.link {
  border: 0;
  background: none;
  color: var(--primary);
  font-size: .88rem;
  font-weight: 600;
  padding: 4px 0;
}

.steps { padding-left: 20px; color: var(--muted); display: grid; gap: 8px; font-size: .93rem; }
.steps b { color: var(--text); }

/* ============ 按钮 ============ */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 46px;
  padding: 0 18px;
  border-radius: 13px;
  font-weight: 600;
  font-size: .95rem;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #d8b4ae; border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.big { min-height: var(--tap); font-size: 1.02rem; width: 100%; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.icon-btn {
  width: 42px; height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 1rem;
}

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ============ 输入 ============ */
.input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 14px;
  outline: none;
}
.input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.field:last-child { border-bottom: 0; }
.field > span { color: var(--text); font-size: .95rem; }
.field input[type="number"], .field select {
  width: 190px;
  flex: none;
}
.field input[type="text"] { width: 240px; }
.field input[type="checkbox"] {
  width: 26px; height: 26px; min-height: 0;
  accent-color: var(--primary);
}

/* ============ 词库 ============ */
.toolbar { display: grid; gap: 10px; margin-bottom: 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .85rem;
  min-height: 0;
}
.chip.active { background: var(--primary-soft); border-color: transparent; color: var(--primary); font-weight: 600; }

.batch-list { display: grid; gap: 10px; }
.batch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.batch-main { flex: 1; min-width: 0; }
.batch-main b { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch-main span { color: var(--muted); font-size: .8rem; }
.batch-bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 7px; }
.batch-bar i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

.word-list { display: grid; }
.word-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.6fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px 2px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
}
.word-row:last-child { border-bottom: 0; }
.word-row .w { font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; }
.word-row .m { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: .72rem;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.new { background: var(--primary-soft); color: var(--primary); }
.badge.learning { background: var(--warn-soft); color: var(--warn); }
.badge.mastered { background: var(--good-soft); color: var(--good); }

.empty { color: var(--muted); text-align: center; padding: 26px 10px; }

/* ============ 导入 ============ */
.drop {
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
  padding: 34px 18px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--muted);
}
.drop strong { color: var(--text); font-size: 1.02rem; }
.drop span { font-size: .85rem; }
.drop.drag { border-color: var(--primary); background: var(--primary-soft); }

.paste-box { margin-top: 12px; }
.paste-box summary { cursor: pointer; color: var(--muted); font-size: .88rem; padding: 6px 0; }
.paste-box textarea { margin: 8px 0; }

.table-wrap {
  max-height: 46vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.preview { width: 100%; border-collapse: collapse; font-size: .9rem; }
.preview th {
  position: sticky; top: 0;
  background: var(--surface-2);
  text-align: left;
  padding: 9px 12px;
  font-size: .78rem;
  color: var(--muted);
  z-index: 1;
}
.preview td { padding: 7px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
.preview .w { font-weight: 600; white-space: nowrap; }
.preview input {
  width: 100%;
  min-height: 36px;
  padding: 5px 9px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
}
.preview input:focus { background: var(--surface-2); border-color: var(--border); }
.preview .src { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.preview .src.miss { color: var(--warn); }

.progress-line { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0; }
.progress-line > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* ============ 统计 ============ */
.dist { display: grid; gap: 12px; }
.dist-row { display: grid; grid-template-columns: 72px 1fr 52px; align-items: center; gap: 12px; font-size: .88rem; }
.dist-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.dist-track i { display: block; height: 100%; border-radius: 99px; }
.dist-row b { text-align: right; font-weight: 600; }

.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 14px);
  gap: 4px;
  width: max-content;
}
.heatmap i { width: 14px; height: 14px; border-radius: 4px; background: var(--surface-2); }
.heatmap i.lv1, .heatmap-legend .lv1 { background: color-mix(in srgb, var(--primary) 22%, var(--surface-2)); }
.heatmap i.lv2, .heatmap-legend .lv2 { background: color-mix(in srgb, var(--primary) 45%, var(--surface-2)); }
.heatmap i.lv3, .heatmap-legend .lv3 { background: color-mix(in srgb, var(--primary) 70%, var(--surface-2)); }
.heatmap i.lv4, .heatmap-legend .lv4 { background: var(--primary); }
.heatmap-legend { display: flex; align-items: center; gap: 5px; justify-content: flex-end; color: var(--muted); font-size: .75rem; margin-top: 8px; }
.heatmap-legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; height: 130px; }
.bar-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bar-col .bar { width: 100%; max-width: 34px; background: var(--primary); border-radius: 6px 6px 3px 3px; min-height: 3px; opacity: .85; }
.bar-col .bar.empty { background: var(--surface-2); }
.bar-col span { font-size: .7rem; color: var(--muted); }
.bar-col b { font-size: .72rem; }

/* ============ 学习界面 ============ */
.study {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 18px calc(14px + env(safe-area-inset-bottom));
}
.study[hidden] { display: none; }

.study-top { display: flex; align-items: center; gap: 14px; }
.progress-track { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .25s ease; }
.study-count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; min-width: 54px; text-align: right; }

.study-body {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 18px 0;
}

.card {
  width: min(100%, 720px);
  min-height: min(46vh, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  padding: 40px 28px;
  text-align: center;
  transition: transform .08s ease;
}
.card:active { transform: scale(.995); }
.card-face { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.card-word {
  font-size: clamp(2.6rem, 8vw, 4.8rem);
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.08;
  overflow-wrap: anywhere;
}
.card-phonetic { color: var(--muted); font-size: 1rem; min-height: 0; }
.card-hint { color: var(--muted); font-size: .85rem; margin-top: 10px; }
.card-meaning {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
  font-size: clamp(1.25rem, 3.4vw, 1.7rem);
  line-height: 1.6;
  max-width: 560px;
}
.card-meaning .missing { color: var(--warn); font-size: .95rem; }

.speak-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  width: 46px; height: 46px;
  border-radius: 50%;
  font-size: 1.05rem;
  display: grid; place-items: center;
}

.study-actions { display: grid; gap: 10px; max-width: 720px; width: 100%; margin: 0 auto; }
.btn.reveal { min-height: 58px; font-size: 1.05rem; background: var(--primary); color: var(--on-primary); border-color: transparent; }
.grade-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grade {
  min-height: 66px;
  border-radius: 16px;
  border: 1px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  gap: 2px;
}
.grade small { font-weight: 500; opacity: .55; font-size: .7rem; }
.grade.again { background: var(--danger-soft); color: var(--danger); }
.grade.hard { background: var(--warn-soft); color: var(--warn); }
.grade.good { background: var(--good-soft); color: var(--good); }
.grade:active { transform: scale(.98); }

/* 选择题 */
.mcq { width: min(100%, 720px); display: grid; gap: 18px; justify-items: center; }
.mcq-word {
  font-size: clamp(2.4rem, 7vw, 4rem);
  font-weight: 700;
  letter-spacing: -.03em;
}
.options { display: grid; gap: 10px; width: 100%; }
.option {
  text-align: left;
  padding: 16px 18px;
  min-height: 62px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 1rem;
  line-height: 1.45;
}
.option:active { transform: scale(.995); }
.option.correct { border-color: var(--good); background: var(--good-soft); color: var(--good); font-weight: 600; }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.option:disabled { opacity: 1; }
.mcq-feedback { min-height: 24px; color: var(--muted); font-size: .9rem; }

/* 总结 */
.summary {
  position: absolute;
  inset: 0;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.summary[hidden] { display: none; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
  width: min(100%, 420px);
  text-align: center;
}
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 22px 0 6px; }
.summary-grid b { display: block; font-size: 1.45rem; letter-spacing: -.02em; }
.summary-grid span { color: var(--muted); font-size: .72rem; }

/* ============ 弹层 / Toast ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(10, 20, 15, .45);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 22px;
  padding: 24px;
  width: min(100%, 460px);
  max-height: 84vh;
  max-height: 84dvh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin-bottom: 12px; }
.modal-body { color: var(--muted); font-size: .92rem; }
.modal-body .field { padding: 8px 0; }
.modal-body .field > span { color: var(--text); }
.modal-body input, .modal-body textarea { width: 100%; }
.modal-body textarea { min-height: 84px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #111d17;
  color: #f2f7f3;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: .9rem;
  z-index: 90;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: 80vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* ============ 底部导航 ============ */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 9px 0;
  border-radius: 10px;
  font-size: .82rem;
  font-weight: 600;
}
.tab-btn.active { color: var(--primary); }

/* ============ 响应式 ============ */
@media (min-width: 901px) {
  .tabbar { display: none; }
  main { padding-bottom: 48px; }
  .study { padding: 20px 32px; }
}

@media (max-width: 640px) {
  .topnav { display: none; }
  main { padding-left: 15px; padding-right: 15px; }
  .hero { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 18px; padding: 22px; }
  .hero-side { width: 100%; }
  .hero-row { justify-content: center; }
  .hero-row b { margin-left: 6px; }
  .stat-strip.four { grid-template-columns: repeat(2, 1fr); }
  .field { flex-wrap: wrap; }
  .field input[type="number"], .field select, .field input[type="text"] { width: 100%; }
  .card { min-height: 40vh; padding: 30px 18px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .word-row { grid-template-columns: 1fr auto; }
  .word-row .m { grid-column: 1 / -1; grid-row: 2; }
  .badge { grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
