/* ═══════════ 主题变量 ═══════════ */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1a2233;
  --text-dim: #6b7791;
  --line: #e5e9f2;
  --primary: #2f6df6;
  --primary-soft: #eaf1ff;
  --ok: #17a673;
  --ok-soft: #e6f7f1;
  --bad: #f0664a;
  --bad-soft: #feeceb;
  --warn: #f5a524;
  --warn-soft: #fff6e5;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 8px 28px rgba(20, 30, 60, .07);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #171c25;
    --surface-2: #1d2431;
    --text: #e8ecf4;
    --text-dim: #8b96ab;
    --line: #262e3d;
    --primary: #5b8cff;
    --primary-soft: #1a2540;
    --ok: #35c48d;
    --ok-soft: #122a24;
    --bad: #ff7a5e;
    --bad-soft: #2e1a18;
    --warn: #f5b544;
    --warn-soft: #2b2312;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ═══════════ 顶栏 ═══════════ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 12px 0 10px;
}

/* 顶栏内容与下方卡片对齐在同一列 */
.topbar-inner { max-width: 480px; margin: 0 auto; padding: 0 12px; }

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  color: #fff; font-weight: 700; font-size: 20px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(47, 109, 246, .3);
}

.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.brand .sub { margin: 0; font-size: 12px; color: var(--text-dim); }
.brand .sub b { color: var(--primary); }

/* 分段胶囊式导航 */
.tabs {
  display: flex; gap: 2px; margin-top: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px;
}

.tab {
  flex: 1; justify-content: center;
  border: 0; background: none; cursor: pointer;
  padding: 7px 8px;
  font-size: 14px; font-weight: 600; color: var(--text-dim);
  border-radius: 9px;
  display: flex; align-items: center; gap: 6px;
  transition: color .15s, background .15s, box-shadow .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface); color: var(--primary);
  box-shadow: 0 1px 4px rgba(20, 30, 60, .08);
}

.badge {
  background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; display: none;
  align-items: center; justify-content: center;
}
.badge.show { display: inline-flex; }
.badge.warn { background: var(--warn); }

/* ═══════════ 布局 ═══════════ */
/* 锁死为手机宽度的一列，电脑上打开也是这个宽度 */
main {
  max-width: 480px; margin: 0 auto; padding: 14px 12px 50px;
  /* 全面屏 PWA：底部手势条不挡按钮 */
  padding-bottom: calc(50px + constant(safe-area-inset-bottom));
  padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px));
}
.view { display: none; }
.view.active { display: block; }

/* ═══════════ 学习页 ═══════════ */
.studybar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 2px; }
.field > span { font-size: 11px; color: var(--text-dim); font-weight: 600; }
.field select {
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 9px; padding: 6px 8px; font-size: 13px; cursor: pointer;
  outline: none;
}
.field select:focus { border-color: var(--primary); }

.progress-wrap { flex: 1; min-width: 160px; }
.progress {
  height: 7px; border-radius: 99px; background: var(--line); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), #7aa2ff);
  transition: width .3s ease;
}
.progress-text { font-size: 11px; color: var(--text-dim); margin-top: 5px; text-align: right; }

/* ── 卡片 ── */
.card-stage { perspective: 1400px; }

.card {
  /* 顶部渐变细条用分层背景（不能用 overflow:hidden，会把 preserve-3d 压扁、翻卡失效） */
  background:
    linear-gradient(90deg, var(--primary), #7aa2ff 55%, var(--warn)) top / 100% 3px no-repeat,
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 18px 18px;
  min-height: 340px;
  display: grid;                    /* 两面叠放同一格，高度 = 两面最大值 */
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3, .9, .4, 1);
}
.card.flipped { transform: rotateY(180deg); }
/* 换新卡时瞬间归位，不用过渡（翻回过程中会露出新词背面的答案） */
.card.no-anim { transition: none; }

/* 判定反馈：绿/红脉冲（配合 judge() 的 250ms 延迟翻面） */
.card.flash-ok  { animation: flashOk  .28s ease; }
.card.flash-bad { animation: flashBad .28s ease; }
@keyframes flashOk {
  0%   { border-color: var(--ok);  box-shadow: 0 0 0 4px var(--ok-soft),  var(--shadow); }
  100% { border-color: var(--line); box-shadow: var(--shadow); }
}
@keyframes flashBad {
  0%   { border-color: var(--bad);  box-shadow: 0 0 0 4px var(--bad-soft),  var(--shadow); }
  100% { border-color: var(--line); box-shadow: var(--shadow); }
}

.face {
  grid-area: 1 / 1;
  display: flex; flex-direction: column;
  min-height: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.front {
  transform: rotateY(0deg);        /* 显式变换，防 iOS 合成层闪烁 */
  justify-content: center;         /* 背面撑高时正面内容居中不显空 */
  background: radial-gradient(120% 65% at 50% -10%, var(--primary-soft), transparent 62%);
  border-radius: calc(var(--radius) - 1px);
}
.face.front .actions { margin-top: 28px; }
.face.back { transform: rotateY(180deg); }

.face.front.active { animation: pop .22s ease; }

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(.995); }
  to   { opacity: 1; transform: none; }
}

.word-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.word {
  margin: 0; font-size: 36px; font-weight: 800; letter-spacing: -.5px;
  font-family: "Segoe UI", system-ui, sans-serif;
  word-break: break-word;
}
.word.small { font-size: 28px; }

.speak {
  border: 0; background: var(--primary-soft); color: var(--primary);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  font-size: 15px; flex: none; transition: transform .12s, background .15s;
}
.speak:hover { transform: scale(1.08); }
.speak:active { transform: scale(.94); }

.tag {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--line);
}
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.phonetic {
  margin: 6px 0 0; color: var(--text-dim);
  font-size: 16px; font-family: "Segoe UI", system-ui, sans-serif;
}

.ask { margin: 26px 0 0; color: var(--text-dim); font-size: 14px; }

.actions { display: flex; gap: 12px; margin-top: auto; padding-top: 26px; }
.actions-next { margin-top: 24px; padding-top: 0; }

.btn {
  flex: 1; border: 1px solid transparent; border-radius: 13px;
  padding: 14px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, filter .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn .k {
  font-size: 11px; font-weight: 700; opacity: .55;
  border: 1px solid currentColor; border-radius: 5px;
  padding: 0 5px; line-height: 16px;
}

.btn-wrong { background: var(--bad-soft); color: var(--bad); }
.btn-wrong:hover { filter: brightness(.96); }

.btn-right { background: var(--ok-soft); color: var(--ok); }
.btn-right:hover { filter: brightness(.96); }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(47,109,246,.28); }
.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost { background: var(--surface-2); border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-ghost.danger:hover { color: var(--bad); border-color: var(--bad); }

.btn-small { flex: none; padding: 7px 12px; font-size: 13px; border-radius: 9px; }

/* 手机上没有物理键盘，默认隐藏；接鼠标/键盘的设备才显示 */
.kbd-hint { display: none; font-size: 11px; color: var(--text-dim); text-align: center; margin: 12px 0 0; opacity: .8; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; } }
.kbd-hint b { color: var(--text); font-weight: 700; }

/* ── 释义与内容块 ── */
.meaning {
  margin: 14px 0 0; font-size: 17px; font-weight: 600; line-height: 1.7;
  padding-bottom: 14px; border-bottom: 1px dashed var(--line);
}

.block { margin-top: 16px; }

.block h4 {
  margin: 0 0 7px; font-size: 12px; font-weight: 700; letter-spacing: .4px;
  color: var(--text-dim); display: flex; align-items: center; gap: 6px;
}
.block h4::before {
  content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--primary);
}

.block p { margin: 0 0 6px; font-size: 14.5px; line-height: 1.85; }
.block p:last-child { margin-bottom: 0; }

.block.mnemonic {
  background: var(--warn-soft);
  border-radius: 13px; padding: 14px 15px;
}
.block.mnemonic h4 { color: var(--warn); }
.block.mnemonic h4::before { background: var(--warn); }
.block.mnemonic p { font-size: 14.5px; }

.block.example p { font-family: "Segoe UI", system-ui, sans-serif; }
.block.example .zh { color: var(--text-dim); font-family: inherit; }

/* 划分 chips */
.split { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.split .seg {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 10px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 700; font-size: 14px; color: var(--primary);
}
.split .plus { color: var(--text-dim); align-self: center; font-size: 12px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-list span {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 9px; font-size: 13px;
}

/* ── 统计 ── */
.stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 11px 8px; text-align: center;
}
.stat b { display: block; font-size: 21px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--text-dim); }
.stat.ok b { color: var(--ok); }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

/* ── 完成面板 ── */
.done-panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px 26px; text-align: center;
}
.done-panel.hidden { display: none; }
.done-emoji { font-size: 44px; }
.done-panel h3 { margin: 8px 0 4px; font-size: 20px; }
.done-panel p { color: var(--text-dim); margin: 0; font-size: 14px; }

.hidden { display: none !important; }

/* ═══════════ 列表页 ═══════════ */
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.list-head h2 { margin: 0; font-size: 17px; }
.muted { color: var(--text-dim); font-weight: 400; font-size: 13px; }
.list-tools { display: flex; gap: 8px; align-items: center; }

.list-tools input[type=search] {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 8px 12px; font-size: 13px;
  min-width: 0; flex: 1; outline: none;
}
.list-tools input[type=search]:focus { border-color: var(--primary); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 99px; padding: 5px 13px; font-size: 12.5px;
  cursor: pointer; color: var(--text-dim); transition: all .15s;
}
.chips button:hover { color: var(--text); }
.chips button.on {
  background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
}

.wordlist { display: flex; flex-direction: column; gap: 8px; }

.wl-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 15px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: border-color .15s, transform .12s;
}
.wl-item:hover { border-color: var(--primary); transform: translateX(2px); }

.wl-main { flex: 1; min-width: 0; }
.wl-word {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 700; font-size: 17px;
}
.wl-word .ph { font-weight: 400; font-size: 12px; color: var(--text-dim); margin-left: 7px; }
.wl-meaning {
  font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wl-src {
  display: inline-block; flex: none;
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 7px;
}

.wl-del {
  border: 0; background: none; cursor: pointer; flex: none;
  color: var(--text-dim); font-size: 16px; padding: 4px 6px; border-radius: 7px;
}
.wl-del:hover { color: var(--bad); background: var(--bad-soft); }

.empty {
  text-align: center; color: var(--text-dim); padding: 50px 20px; font-size: 14px;
}

/* ═══════════ 弹窗 ═══════════ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(12, 18, 30, .45);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 600px; width: 100%; max-height: 84vh; overflow-y: auto;
  padding: 24px 24px 20px;
  animation: pop .2s ease;
}
.modal-box .close {
  float: right; border: 0; background: var(--surface-2);
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  color: var(--text-dim); font-size: 16px;
}
.modal-box .close:hover { color: var(--text); }

/* 弹窗里的复习进度一行 */
.review-line {
  margin: 6px 0 0; font-size: 12.5px; color: var(--text-dim);
}

/* 系统开启"减弱动态效果"时：翻卡瞬间切换、去掉装饰动画，功能不受影响 */
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .face.front.active, .card.flash-ok, .card.flash-bad, .modal-box { animation: none; }
}


/* 弹窗里的复习进度一行 */
.review-line {
  margin: 6px 0 0; font-size: 12.5px; color: var(--text-dim);
}

/* 联想记忆生成中的占位 */
.pending {
  color: var(--text-dim); font-size: 13.5px;
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: 10px; padding: 10px 12px; margin: 0;
}

/* 联想记忆来源徽标 */
.src-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 99px;
  border: 1px solid var(--line); margin-bottom: 8px;
}
.src-badge.src-pdf { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.src-badge.src-gen { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.src-badge.src-none { background: var(--surface-2); color: var(--text-dim); }
