:root {
  --bg: #f4f8ff;
  --panel: #ffffff;
  --ink: #2b3a55;
  --muted: #7c8aa5;
  --brand: #ff8a3d;
  --brand2: #4d8bff;
  --green: #36c08a;
  --red: #ff5d6c;
  --yellow: #ffcc4d;
  --line: #e6ecf7;
  --shadow: 0 6px 20px rgba(77, 139, 255, .12);
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, #f4f8ff 100%);
  color: var(--ink);
  min-height: 100vh;
}
.app { max-width: 760px; margin: 0 auto; padding: 14px 14px 90px; }

/* 顶部栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px 14px;
}
.logo { font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.logo .star { font-size: 22px; }
.score-badge {
  background: var(--yellow); color: #6b4a00; font-weight: 800;
  padding: 6px 12px; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 6px;
}

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 760px; margin: 0 auto;
  background: var(--panel); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 8px 4px;
  box-shadow: 0 -4px 18px rgba(0,0,0,.06); z-index: 20;
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 10px; border-radius: 12px; cursor: pointer; font-weight: 700;
}
.tabbar button .ic { font-size: 20px; }
.tabbar button.active { color: var(--brand); background: #fff3ea; }

/* 卡片/通用 */
.card {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--line);
}
h2.section { font-size: 18px; margin: 4px 2px 12px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; font-size: 15px; font-weight: 800;
  cursor: pointer; transition: transform .08s ease; color: #fff;
}
.btn:active { transform: scale(.96); }
.btn.brand { background: var(--brand); }
.btn.blue { background: var(--brand2); }
.btn.ghost { background: #eef3ff; color: var(--brand2); }
.btn.green { background: var(--green); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 关卡/主题网格 */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--panel); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  border: 1px solid var(--line); cursor: pointer; transition: transform .1s ease;
}
.tile:active { transform: scale(.97); }
.tile .emoji { font-size: 34px; }
.tile .tname { font-weight: 800; margin-top: 6px; }
.tile .tmeta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.progress { height: 8px; background: #eef3ff; border-radius: 999px; margin-top: 10px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }

/* 单词卡（翻转） */
.wordcard-wrap { perspective: 1000px; margin: 6px 0 16px; }
.wordcard {
  width: 100%; min-height: 230px; position: relative; cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s; border-radius: var(--radius);
}
.wordcard.flip { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.face.front { background: linear-gradient(160deg, #fff7ef, #ffe9d6); }
.face.back { background: linear-gradient(160deg, #eef6ff, #e2eeff); transform: rotateY(180deg); }
.face .big-emoji { font-size: 72px; }
.face .word { font-size: 30px; font-weight: 900; margin-top: 8px; letter-spacing: .5px; }
.face .pos { color: var(--muted); font-size: 13px; }
.face .zh { font-size: 20px; font-weight: 800; margin-top: 6px; }
.face .example { font-size: 14px; color: var(--ink); margin-top: 10px; text-align: center; }
.face .exzh { font-size: 12px; color: var(--muted); }
.speak-btn {
  position: absolute; bottom: 10px; right: 10px; border: 0; background: var(--brand2);
  color: #fff; width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* 选项 */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.opt {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 14px 10px;
  font-size: 16px; font-weight: 700; cursor: pointer; text-align: center;
}
.opt.correct { border-color: var(--green); background: #e8faf2; }
.opt.wrong { border-color: var(--red); background: #ffeef0; }
.opt:disabled { cursor: default; }
.repeat-dev { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; }
.repeat-dev .opt { padding: 8px 10px; border-radius: 10px; font-size: 14px; font-weight: 600; flex: 1; text-align: left; }

/* 跟读评分后的「对比纠正」弹层：反复听示范音与自己的录音 */
.cmp-mask { position: fixed; inset: 0; background: rgba(20,30,55,.5); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
.cmp-box { background: #fff; border-radius: 18px; padding: 16px; width: 100%; max-width: 420px; box-shadow: 0 18px 48px rgba(20,30,55,.28); }
.cmp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cmp-word { text-align: center; font-size: 28px; font-weight: 800; line-height: 1.2; word-break: break-word; }
.cmp-zh { text-align: center; margin-top: 2px; font-size: 14px; }
.cmp-score { text-align: center; font-size: 13px; margin: 8px 0 2px; }
.cmp-btns { display: flex; gap: 10px; margin-top: 12px; }
.cmp-btns .btn { flex: 1; }
.cmp-tip { font-size: 12.5px; line-height: 1.6; margin-top: 12px; }

/* 连线 */
.match-grid { display: flex; gap: 18px; justify-content: space-between; }
.match-col { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.match-item {
  border: 2px solid var(--line); border-radius: 12px; padding: 10px; text-align: center;
  font-weight: 800; cursor: pointer; background: #fff; user-select: none;
}
.match-item.sel { border-color: var(--brand); background: #fff3ea; }
.match-item.done { opacity: .4; border-color: var(--green); }
.match-line { font-size: 22px; text-align: center; color: var(--muted); }

/* 排序成句 */
.jumble { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  border: 2px solid var(--brand2); background: #eef3ff; color: var(--brand2);
  border-radius: 12px; padding: 10px 12px; font-weight: 800; cursor: pointer;
}
.chip.used { opacity: .3; }
.sentence-box {
  min-height: 48px; border: 2px dashed var(--line); border-radius: 12px; padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px;
}
.sentence-box .chip { border-color: var(--green); background: #e8faf2; color: var(--green); }

/* 反馈 */
.feedback {
  margin-top: 12px; padding: 12px; border-radius: 14px; font-weight: 700; font-size: 14px;
  display: none;
}
.feedback.show { display: block; }
.feedback.ok { background: #e8faf2; color: #1c7a55; }
.feedback.no { background: #ffeef0; color: #b3323f; }

/* 生词本 */
.wordrow {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid var(--line);
}
.wordrow .w { font-weight: 800; flex: 1; }
.wordrow .zh { color: var(--muted); font-size: 13px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 800; }
.tag.hard { background: #ffe7e9; color: #c23b46; }
.tag.fuzzy { background: #fff3d6; color: #9a7400; }
.tag.known { background: #e3f7ee; color: #1c7a55; }
.mini { border: 0; background: #eef3ff; color: var(--brand2); border-radius: 10px; padding: 6px 10px; font-weight: 800; cursor: pointer; }

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

/* 雷达/统计 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #f6f9ff; border-radius: 14px; padding: 12px; text-align: center; }
.stat .num { font-size: 24px; font-weight: 900; color: var(--brand2); }
.stat .lab { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 对话 */
.dlg-line { padding: 10px; border-radius: 14px; margin-bottom: 10px; background: #f6f9ff; }
.dlg-line.me { background: #fff3ea; }
.dlg-line .sp { font-weight: 800; font-size: 13px; color: var(--brand); }
.dlg-line .en { font-size: 17px; font-weight: 700; margin: 2px 0; }
.dlg-line .zh { font-size: 13px; color: var(--muted); }
.dlg-line .play { float: right; border: 0; background: var(--brand2); color: #fff; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; }

/* 动画 */
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.pop { animation: pop .25s ease; }
@keyframes floatUp { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }
.floatstar { position: fixed; font-size: 24px; pointer-events: none; animation: floatUp .9s ease forwards; z-index: 50; }

/* 设置面板 */
.overlay { position: fixed; inset: 0; background: rgba(20,30,55,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 60; }
.sheet {
  background: var(--panel); width: 100%; max-width: 760px; border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  max-height: 86vh; overflow-y: auto; animation: pop .25s ease;
}
.companion-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 8px; }
.companion-chip {
  border: 2px solid var(--line); border-radius: 14px; padding: 10px 4px; text-align: center;
  font-size: 30px; cursor: pointer; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.companion-chip span { font-size: 12px; color: var(--muted); font-weight: 700; }
.companion-chip.sel { border-color: var(--brand); background: #fff3ea; }
.upload-btn {
  display: inline-block; margin-top: 12px; background: var(--brand2); color: #fff; font-weight: 800;
  padding: 10px 14px; border-radius: 12px; cursor: pointer;
}
input[type=range] { accent-color: var(--brand); }

/* 伙伴气泡 */
.buddy-toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 55;
  background: #fff; border: 2px solid var(--brand); border-radius: 999px; padding: 8px 14px 8px 8px;
  display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); font-weight: 800; font-size: 14px;
  animation: pop .25s ease;
}

/* 测评 */
.q-num { color: var(--brand); font-weight: 900; }
.test-hero { text-align: center; padding: 8px 0 4px; }
.test-hero .big { font-size: 40px; }
.chart-box { display: flex; gap: 8px; align-items: flex-end; height: 140px; justify-content: center; padding: 10px 0; }
.bar { width: 38px; background: var(--brand2); border-radius: 8px 8px 0 0; position: relative; }
.bar span { position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; }
.bar i { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-weight: 900; color: var(--ink); font-style: normal; }

/* 错因分布条 */
.reason-bars { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.rbar { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.rl { width: 76px; color: var(--muted); flex: none; }
.rt { background: linear-gradient(90deg, #ffb454, #ff7a59); color: #fff; font-weight: 800;
  border-radius: 8px; padding: 4px 10px; min-width: 28px; text-align: center; transition: width .4s ease; }

/* 词库总览 */
.lib-tbl { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.lib-row { display: grid; grid-template-columns: 28px 1fr 44px 1fr 26px 30px; align-items: center; gap: 6px; padding: 6px 4px; border-radius: 8px; background: #fff; }
.lib-row:nth-child(odd) { background: #fbfdff; }
.lib-row .e { font-size: 18px; text-align: center; }
.lib-row .w { font-weight: 800; color: var(--ink); text-transform: lowercase; }
.lib-row .p { color: #9aa7b8; font-size: 12px; }
.lib-row .z { color: var(--muted); }
.lib-row .f { text-align: center; }
.lib-row .spk { font-size: 14px; padding: 4px 6px; }

/* 云端同步指示灯 */
.sync-badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #eef3f8; color: #5b6b7e; white-space: nowrap; }

/* 设置开关 */
.switch { width: 48px; height: 28px; border-radius: 999px; border: none; background: #cfd8e3; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch.on { background: var(--brand); }
.switch span { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on span { left: 23px; }

/* 阅读短文 */
.passage { white-space: pre-wrap; background: #f6f9fc; border-left: 3px solid var(--brand); border-radius: 8px; padding: 10px 12px; font-size: 15px; line-height: 1.7; color: var(--ink); margin: 6px 0; }

/* 跟读评测 */
.repeat-word { font-size: 34px; font-weight: 800; color: var(--ink); text-align: center; margin: 14px 0 4px; letter-spacing: .5px; }
.repeat-zh { text-align: center; color: var(--muted); margin-bottom: 10px; }
.repeat-btns { display: flex; gap: 10px; }
.repeat-btns .btn { flex: 1; }
.repeat-status { text-align: center; min-height: 18px; margin: 10px 0; }
.repeat-result { margin-top: 6px; }
.soe-scores { display: flex; gap: 8px; margin: 10px 0; }
.soe-score { flex: 1; background: #f6f9fc; border-radius: 10px; padding: 10px 6px; text-align: center; }
.soe-score span { display: block; font-size: 12px; color: var(--muted); }
.soe-score b { font-size: 22px; color: var(--brand); }
.soe-score .stars { color: #f5b50a; font-size: 13px; letter-spacing: 1px; }
.soe-words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.soe-w { padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.soe-w.ok { background: #e3f7ea; color: #1f9d55; }
.soe-w.mid { background: #fff4e0; color: #d98a00; }
.soe-w.bad { background: #fde4e4; color: #d23b3b; }
