/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f5ff;
  --card: #ffffff;
  --ink: #2b2b4a;
  --muted: #8a89a8;
  --primary: #5a5bd6;
  --primary-2: #7c6cf0;
  --accent: #f6a821;
  --ok: #2ecc71;
  --line: #ececfc;
  --bubble-ai: #f1f1fb;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 85% -10%, #e7e6ff 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 25%, #e6f6ff 0%, transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; }
a { color: var(--primary); }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 18px;
  background: rgba(244, 245, 255, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(90, 91, 214, 0.08);
}
.brand { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 1.4rem; }
.brand .tag {
  font-size: 0.72rem; font-weight: 600; color: var(--primary);
  background: #e7e5ff; border-radius: 20px; padding: 3px 10px;
}
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.diff { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.diff select {
  font-size: 0.85rem; color: var(--ink); padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  cursor: pointer; outline: none;
}
.diff select:focus { border-color: var(--primary); }

/* 个人中心 */
.profile-block { margin-bottom: 16px; }
.profile-block h3 { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }
.diff-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.profile-block .stats-row { margin-top: 0; }
.howto-details summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.howto-details summary::-webkit-details-marker { display: none; }
.howto-details summary h3 { margin: 0; }
.howto-details[open] summary h3 { color: var(--primary); }
.howto-card { margin-top: 10px; display: flex; flex-direction: column; gap: 9px; }
.howto-line { display: flex; gap: 10px; align-items: flex-start; }
.howto-line .stepnum { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; margin-top: 2px; }
.howto-line p { font-size: 0.85rem; line-height: 1.6; color: #55557a; margin: 0; }


/* ============ 按钮 ============ */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 8px 14px; font-size: 0.9rem; cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(90, 91, 214, 0.15); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border: none;
}
.btn.ghost { background: rgba(255, 255, 255, 0.8); }
.btn.big { padding: 14px 30px; font-size: 1.05rem; border-radius: 16px; }
.btn.small { padding: 6px 12px; font-size: 0.82rem; border-radius: 10px; }
.btn.danger:hover { border-color: #e74c3c; color: #e74c3c; }
.linklike {
  border: none; background: none; color: var(--primary); cursor: pointer;
  font-size: inherit; text-decoration: underline; padding: 0;
}

/* ============ 首页 ============ */
main { max-width: 880px; margin: 0 auto; }
.home { padding: 26px 16px 60px; display: flex; flex-direction: column; gap: 20px; }
.card {
  background: var(--card); border: 1px solid rgba(90, 91, 214, 0.08);
  border-radius: 20px; box-shadow: 0 6px 24px rgba(93, 80, 180, 0.07);
}
.hero { text-align: center; padding: 48px 24px 36px; }
.hero h1 {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 12px;
}
.home-hero-title {
  font-size: clamp(1.8rem, 4.5vw, 2.6rem);
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 12px;
}
.wl-mini { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wl-mini .wl-actions { justify-content: center; }
.hero .sub { color: var(--muted); font-size: 1.05rem; margin-bottom: 28px; }
.hero .sub .hl { color: var(--primary); font-weight: 700; }
.hero-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.banner {
  margin-top: 20px; display: inline-block; font-size: 0.88rem; color: #b45309;
  background: #fef3c7; border: 1px solid #fde68a; border-radius: 12px; padding: 8px 14px;
}
.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
.step { padding: 18px; display: flex; gap: 12px; align-items: flex-start; }
.stepnum {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.step p { font-size: 0.9rem; line-height: 1.55; color: #55557a; }
.stats-row { display: flex; justify-content: space-around; margin-top: 18px; padding: 18px 10px; }
.stat { text-align: center; }
.stat .num { font-size: 1.6rem; font-weight: 800; color: var(--primary); display: block; }
.stat .lbl { font-size: 0.78rem; color: var(--muted); }

/* ============ 游戏页 ============ */
.game { height: calc(100dvh - 58px); display: flex; flex-direction: column; padding: 12px 16px; }
.round-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-radius: 14px; font-size: 0.88rem; flex: none;
}
.round-bar .spacer { flex: 1; }
.chat {
  flex: 1; overflow-y: auto; padding: 14px 2px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.sysnote {
  align-self: center; font-size: 0.8rem; color: var(--muted);
  background: rgba(255, 255, 255, 0.7); border-radius: 20px; padding: 5px 14px;
}
.msg { display: flex; }
.msg.ai { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(88%, 620px); padding: 13px 16px; line-height: 1.65; font-size: 0.97rem;
  white-space: pre-wrap; word-break: break-word;
}
.msg.ai .bubble {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--bubble-ai); border: 1px solid rgba(90, 91, 214, 0.07);
  border-radius: 4px 18px 18px 18px;
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: 18px 18px 4px 18px;
}
.msg .content { flex: 1; min-width: 0; }
.msg.win .bubble { background: #effbf4; border-color: #bfe8cf; animation: pop 0.3s ease; }
.msg.info .bubble { background: #fff8ec; border-color: #fce3b8; }
@keyframes pop { from { transform: scale(0.95); } to { transform: scale(1); } }

/* 可点击单词 */
.w {
  color: #4a4ac9; cursor: pointer;
  text-decoration: underline dotted rgba(90, 91, 214, 0.55);
  text-underline-offset: 3px; border-radius: 4px; padding: 0 1px;
  transition: background 0.15s ease;
}
.w:hover { background: #e3e1ff; }
.msg.user .bubble .w { color: inherit; text-decoration: none; cursor: default; }
.msg.user .bubble .w:hover { background: transparent; }

/* 朗读按钮 */
.speak {
  flex: none; border: none; background: #fff; border-radius: 50%;
  width: 30px; height: 30px; font-size: 14px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); margin-top: 2px;
  transition: transform 0.12s ease;
}
.speak:hover { transform: scale(1.1); }

/* 打字动画 */
.msg.typing .bubble { display: flex; gap: 6px; padding: 16px 20px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #a5a5d8; animation: blink 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ============ 输入区 ============ */
.composer {
  flex: none; padding: 12px 14px 14px;
  background: rgba(255, 255, 255, 0.88); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 4px 18px rgba(93, 80, 180, 0.08);
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  padding: 6px 14px; font-size: 0.85rem; cursor: pointer; color: #55557a;
  transition: all 0.12s ease;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }
.inputrow { display: flex; gap: 10px; }
.inputrow input {
  flex: 1; padding: 12px 16px; font-size: 0.97rem; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 14px; outline: none;
  transition: border-color 0.15s ease;
}
.inputrow input:focus { border-color: var(--primary); }
.inputrow input:disabled { background: #f4f4fb; }
.hintline { margin-top: 8px; font-size: 0.78rem; color: var(--muted); }

/* ============ 弹窗 ============ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 18, 45, 0.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: min(92vw, 480px); max-height: 82vh; overflow-y: auto;
  background: #fff; border-radius: 20px; padding: 24px;
  box-shadow: 0 20px 60px rgba(20, 18, 45, 0.25);
  animation: pop 0.2s ease;
}
.modal-card.wide { width: min(94vw, 660px); }
.modal-card h2 { font-size: 1.15rem; margin-bottom: 10px; }
.modal-card .muted { font-size: 0.85rem; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }
.modal-card input[type=password] {
  width: 100%; padding: 12px 14px; font-size: 0.95rem;
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
}
.modal-card input[type=password]:focus { border-color: var(--primary); }
.msgline { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; margin: 10px 0 4px; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin-bottom: 0; }
.history-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.hist-toolbar { display: flex; align-items: center; gap: 12px; margin-top: 14px; min-height: 22px; }
.hist-all { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); cursor: pointer; user-select: none; }
.hist-all input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.hist-box { display: flex; gap: 10px; align-items: flex-start; }
.hist-box > .history-item { flex: 1; min-width: 0; }
.hist-sel { width: 16px; height: 16px; margin-top: 6px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.hist-box.sel > .history-item { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.history-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: #fafaff; }
.history-item summary { cursor: pointer; font-size: 0.95rem; list-style: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.history-item summary::-webkit-details-marker { display: none; }
.history-item .badge {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 20px;
  background: #f1f0ff; color: var(--primary); font-weight: 600;
}
.history-item .badge.ok { background: #e6f9ef; color: #1a9e54; }
.history-item .badge.err { background: #fdeeee; color: #d64545; }
.history-item .badge.due { background: #fff3e6; color: #d97a06; }
.history-item .badge.wait { background: #eef0f4; color: #8a8fa3; }
.history-item .wrong-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.history-item .meta { margin-left: auto; font-size: 0.75rem; color: var(--muted); }
.history-item .summary {
  margin-top: 8px; font-size: 0.86rem; line-height: 1.6; color: #55557a;
  white-space: pre-wrap; border-top: 1px dashed var(--line); padding-top: 8px;
}
.empty { text-align: center; color: var(--muted); font-size: 0.9rem; padding: 30px 0; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 60; max-width: 88vw;
  background: rgba(30, 28, 60, 0.92); color: #fff;
  padding: 10px 20px; border-radius: 30px; font-size: 0.88rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25); text-align: center;
}

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  .brand .tag { display: none; }
  .howto { grid-template-columns: 1fr; }
  .game { padding: 10px 10px; }
  .bubble { max-width: 94%; font-size: 0.94rem; }
  .hero { padding: 36px 16px 26px; }
}

/* ============ 单词表卡片 ============ */
.wordlist-card { margin-top: 18px; padding: 18px 20px; }
.wl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wl-head .wl-info {
  font-size: 0.82rem; color: var(--primary); background: #eef;
  padding: 3px 12px; border-radius: 20px;
}
.wordlist-card .muted {
  margin: 8px 0 12px; font-size: 0.85rem; color: var(--muted); line-height: 1.6;
}
.wl-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.wordlist-card.dragging { border-color: var(--primary); background: #f6f5ff; }

/* 开关 */
.switch {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.85rem; color: #55557a; cursor: pointer; user-select: none;
}
.switch input { display: none; }
.switch .slider {
  width: 38px; height: 21px; border-radius: 20px; background: #d8d8ee;
  position: relative; transition: background 0.15s ease;
}
.switch .slider::after {
  content: ''; position: absolute; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: left 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { left: 19px; }
.switch:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }

/* ============ 排行榜 ============ */
.lb-summary { display: flex; gap: 10px; margin-top: 14px; }
.lb-stat {
  flex: 1; text-align: center; background: #fafaff;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.lb-stat b { font-size: 1.3rem; color: var(--primary); display: block; }
.lb-stat span { font-size: 0.75rem; color: var(--muted); }
.lb-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fafaff; font-size: 0.9rem;
}
.lb-row .rank { width: 26px; text-align: center; font-weight: 700; color: var(--muted); flex: none; }
.lb-row .rank.medal { font-size: 1.1rem; }
.lb-row .word { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pts { margin-left: auto; color: #b45309; font-weight: 600; flex: none; }
.lb-row .meta { font-size: 0.75rem; color: var(--muted); flex: none; }
@media (max-width: 640px) {
  .lb-row .meta { display: none; }
}

/* 中文翻译标签（词库/排行榜中的中文释义） */
.history-item .cn {
  font-size: 0.78rem; color: #55557a; background: #f0f0fa;
  border-radius: 8px; padding: 1px 8px; font-weight: 600;
}

/* ============ 词汇表弹窗 ============ */
.vocab-block { margin-bottom: 16px; }
.vocab-block h3 { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }
.vocab-block textarea {
  width: 100%; padding: 10px 12px; font-size: 0.92rem; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
  font-family: inherit; resize: vertical; margin-bottom: 10px;
}
.vocab-block textarea:focus { border-color: var(--primary); }
.vocab-manual { display: flex; gap: 8px; flex-wrap: wrap; }
.vocab-manual input {
  flex: 1; min-width: 120px; padding: 9px 12px; font-size: 0.9rem; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
}
.vocab-manual input:focus { border-color: var(--primary); }
.vocab-block .muted { display: block; margin-top: 8px; }

/* ============ 学习天地：书籍卡片 ============ */
.book-list { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; text-align: left; }
.book-card {
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
  background: #fafaff; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.book-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(90, 91, 214, 0.12); }
.book-card.active { border-color: var(--primary); background: #f3f2ff; }
.book-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.book-name { font-size: 1.02rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.book-bar { height: 6px; border-radius: 6px; background: #e8e8f6; overflow: hidden; margin-bottom: 12px; }
.book-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width 0.3s ease; }
.book-actions { display: flex; gap: 8px; flex-wrap: wrap; }


/* 单词头（总结卡片）：单词 + 中文 + 音标 + 播放键 */
.word-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px; padding: 8px 12px;
  background: #f4f4ff; border: 1px solid var(--line); border-radius: 10px;
}
.word-head .word { font-size: 1.15rem; color: var(--primary); font-weight: 700; }
.word-head .cn {
  font-size: 0.8rem; color: #55557a; background: #f0f0fa;
  border-radius: 8px; padding: 1px 8px; font-weight: 600;
}
/* 音标 */
.ipa { font-size: 0.82rem; color: #8a8fa3; letter-spacing: 0.2px; }
.ipa.none { display: none; }
/* 行内小号播放键（词库/错题卡） */
.speak-mini { width: 26px; height: 26px; font-size: 12px; margin-top: 0; }


/* 听力提示（第二次提示）：音标 + 播放按钮 */
.hint-audio { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.hint-audio .ipa-big { font-size: 1.05rem; color: var(--primary); font-weight: 600; letter-spacing: 0.5px; }


/* 排行榜：当前用户高亮 */
.lb-row.me { border-color: var(--primary); background: #f1f0ff; }
