/* ===== 设计系统 ===== */
:root {
  --primary: #8b5cf6;
  --primary-soft: #ede9fe;
  --pink: #ec4899;
  --pink-soft: #fce7f3;
  --bg: #faf8ff;
  --card: #ffffff;
  --text: #2e2a3b;
  --muted: #8b86a0;
  --ok: #22c55e;
  --ok-soft: #dcfce7;
  --bad: #ef4444;
  --bad-soft: #fee2e2;
  --warn: #f59e0b;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(90, 70, 160, .08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 560px;
  margin: 0 auto;
  padding-top: 56px;
  padding-bottom: calc(64px + var(--safe-bottom));
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }

/* ===== 顶栏 ===== */
#topbar {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; height: 56px; z-index: 50;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid #eee8fb;
}
.streak {
  font-weight: 700; color: #ea580c; background: #fff7ed;
  border-radius: 999px; padding: 5px 10px; font-size: 14px; white-space: nowrap;
}
.streak span { margin-left: 2px; }
.title-chip { flex: 1; min-width: 0; }
.title-chip span { display: block; font-size: 13px; font-weight: 600; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-bar { height: 6px; background: var(--primary-soft); border-radius: 999px; margin-top: 3px; overflow: hidden; }
.xp-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--pink)); border-radius: 999px; transition: width .5s; }
.icon-btn { font-size: 20px; padding: 8px; border-radius: 12px; }
.icon-btn:active { background: var(--primary-soft); }

/* ===== 底部 Tab ===== */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 50;
  display: flex; background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px);
  border-top: 1px solid #eee8fb; padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; padding: 8px 0 6px; font-size: 20px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted);
}
.tab span { font-size: 11px; }
.tab.active { color: var(--primary); }
.tab .dot {
  position: absolute; top: 6px; right: calc(50% - 18px); width: 8px; height: 8px;
  background: var(--pink); border-radius: 50%;
}

/* ===== 视图通用 ===== */
.view { padding: 16px 14px 24px; animation: fadeIn .25s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
h2.page-title { font-size: 20px; margin-bottom: 14px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 12px 20px; border-radius: 14px;
  font-size: 16px; font-weight: 600; transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary), #a78bfa); color: #fff; box-shadow: 0 4px 14px rgba(139, 92, 246, .35); }
.btn-pink { background: linear-gradient(135deg, var(--pink), #f472b6); color: #fff; box-shadow: 0 4px 14px rgba(236, 72, 153, .3); }
.btn-ghost { background: var(--primary-soft); color: var(--primary); }
.btn-block { width: 100%; }
.btn[disabled] { filter: grayscale(1) opacity(.5); pointer-events: none; }

/* ===== 关卡地图 ===== */
.chapter { margin-bottom: 18px; }
.chapter-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: linear-gradient(135deg, var(--primary-soft), var(--pink-soft));
  border-radius: var(--radius); cursor: pointer; user-select: none;
}
.chapter-head .ch-icon { font-size: 24px; }
.chapter-head .ch-title { flex: 1; font-weight: 700; font-size: 15px; }
.chapter-head .ch-prog { font-size: 12px; color: var(--muted); }
.chapter-head .ch-arrow { transition: transform .2s; color: var(--muted); }
.chapter.open .ch-arrow { transform: rotate(90deg); }
.chapter-body { padding: 10px 4px 0; display: none; }
.chapter.open .chapter-body { display: block; }

.level-row { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 14px; cursor: pointer; }
.level-row:active { background: var(--primary-soft); }
.level-row.locked { opacity: .45; cursor: not-allowed; }
.level-num {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; background: var(--primary-soft);
}
.level-row.cleared .level-num { background: linear-gradient(135deg, var(--primary), var(--pink)); }
.level-info { flex: 1; min-width: 0; }
.level-info .lv-title { font-size: 14px; font-weight: 600; }
.level-info .lv-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stars { letter-spacing: 2px; font-size: 14px; white-space: nowrap; }
.stars .off { opacity: .2; filter: grayscale(1); }

.badge-shelf { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 6px; }
.badge-slot {
  aspect-ratio: 1; border-radius: 14px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 22px; position: relative;
}
.badge-slot small { font-size: 9px; color: var(--muted); max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.badge-slot.locked { filter: grayscale(1); opacity: .35; }

/* ===== 答题（闯关/错题重练） ===== */
.quiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.quiz-head .q-progress { flex: 1; height: 8px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; }
.quiz-head .q-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--pink)); transition: width .3s; }
.quiz-head .q-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.close-x { font-size: 18px; color: var(--muted); padding: 6px; }

.q-type-tag {
  display: inline-block; font-size: 11px; font-weight: 600; color: var(--primary);
  background: var(--primary-soft); padding: 3px 10px; border-radius: 999px; margin-bottom: 10px;
}
.q-text { font-size: 17px; font-weight: 600; line-height: 1.55; margin-bottom: 16px; }

.opt-list { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 10px; text-align: left;
  min-height: 52px; padding: 12px 14px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 15px; line-height: 1.45; border: 2px solid transparent;
  transition: border-color .15s, background .15s;
}
.opt .opt-key {
  width: 26px; height: 26px; flex: none; border-radius: 8px; background: var(--primary-soft);
  color: var(--primary); font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.opt.dim { opacity: .55; }
@keyframes shake {
  0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); } 75% { transform: translateX(-4px); }
}

.judge-btns { display: flex; gap: 12px; }
.judge-btns .opt { flex: 1; justify-content: center; font-size: 17px; font-weight: 700; min-height: 64px; }

.blank-row { display: flex; gap: 10px; }
.blank-row input {
  flex: 1; min-height: 52px; padding: 0 14px; font-size: 16px;
  border: 2px solid #e4dcfa; border-radius: 14px; outline: none; background: var(--card);
}
.blank-row input:focus { border-color: var(--primary); }
.blank-row .btn { flex: none; padding: 12px 18px; }
.blank-result { margin-top: 10px; font-size: 14px; font-weight: 600; }
.blank-result.ok { color: var(--ok); }
.blank-result.bad { color: var(--bad); }

.order-pool, .order-picked { display: flex; flex-direction: column; gap: 8px; }
.order-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow);
  font-size: 15px; line-height: 1.4; border: 2px solid transparent;
}
.order-item .ord-n {
  width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.order-item.picked { border-color: var(--primary); background: #fbfaff; }
.order-item.right { border-color: var(--ok); background: var(--ok-soft); }
.order-item.wrong { border-color: var(--bad); background: var(--bad-soft); }
.order-hint { font-size: 12px; color: var(--muted); margin: 10px 0; }

.explain {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  background: #fffbEB; border: 1px solid #fde68a; color: #785006;
  animation: fadeIn .25s;
}
.explain b { color: #92400e; }
.explain.right-bg { background: var(--ok-soft); border-color: #bbf7d0; }
.explain.right-bg b { color: #15803d; }
.next-row { margin-top: 14px; }

/* ===== 结算页 ===== */
.result-hero { text-align: center; padding: 26px 10px 10px; }
.result-hero .big-emoji { font-size: 64px; animation: pop .5s; }
@keyframes pop { 0% { transform: scale(.2); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.result-hero h2 { font-size: 24px; margin: 10px 0 4px; }
.result-hero .acc { color: var(--muted); font-size: 15px; }
.result-stars { font-size: 40px; letter-spacing: 8px; margin: 14px 0; }
.result-stars i { display: inline-block; animation: starPop .4s backwards; }
.result-stars i:nth-child(2) { animation-delay: .25s; }
.result-stars i:nth-child(3) { animation-delay: .5s; }
@keyframes starPop { 0% { transform: scale(0) rotate(-90deg); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.xp-gain { display: inline-block; background: var(--pink-soft); color: var(--pink); font-weight: 700; padding: 6px 16px; border-radius: 999px; font-size: 15px; margin-bottom: 16px; }
.result-wrong { text-align: left; margin: 6px 0 14px; }
.result-wrong .rw-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.result-wrong .rw-item { font-size: 13px; padding: 8px 10px; background: var(--bad-soft); border-radius: 10px; margin-bottom: 6px; line-height: 1.5; }
.result-btns { display: flex; flex-direction: column; gap: 10px; }

/* ===== 复习 ===== */
.review-summary { display: flex; gap: 10px; margin-bottom: 14px; }
.review-summary .rs-item {
  flex: 1; text-align: center; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 6px;
}
.rs-item .rs-n { font-size: 22px; font-weight: 800; color: var(--primary); }
.rs-item small { color: var(--muted); font-size: 12px; }

.flip-card { perspective: 1000px; margin-bottom: 16px; }
.flip-inner { position: relative; transition: transform .45s; transform-style: preserve-3d; }
.flip-card.flipped .flip-inner { transform: rotateX(180deg); }
.flip-face {
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 18px; min-height: 220px;
  display: flex; flex-direction: column; justify-content: center;
}
.flip-back { position: absolute; inset: 0; transform: rotateX(180deg); overflow-y: auto; }
.flip-face .fc-q { font-size: 17px; font-weight: 600; line-height: 1.6; }
.flip-face .fc-a { font-size: 16px; line-height: 1.6; }
.flip-face .fc-a .ans-main { font-weight: 700; color: var(--primary); font-size: 18px; margin-bottom: 8px; }
.flip-face .fc-explain { margin-top: 12px; font-size: 13px; color: var(--muted); line-height: 1.6; border-top: 1px dashed #eee; padding-top: 10px; }
.rate-btns { display: flex; gap: 10px; }
.rate-btns .btn { flex: 1; min-height: 52px; font-size: 15px; }
.rate-forgot { background: var(--bad-soft); color: var(--bad); }
.rate-fuzzy { background: #fef3c7; color: #b45309; }
.rate-remember { background: var(--ok-soft); color: #15803d; }

.review-done { text-align: center; padding: 30px 10px; }
.review-done .big-emoji { font-size: 64px; animation: pop .5s; }

/* ===== 错题本 ===== */
.mist-group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 2px 8px; }
.mist-item { display: flex; align-items: center; gap: 10px; }
.mist-item .mi-q { flex: 1; font-size: 14px; line-height: 1.5; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mist-item .mi-times { font-size: 11px; color: var(--bad); background: var(--bad-soft); border-radius: 999px; padding: 3px 8px; white-space: nowrap; }
.empty-tip { text-align: center; color: var(--muted); padding: 50px 20px; font-size: 14px; line-height: 1.8; }
.empty-tip .big { font-size: 48px; display: block; margin-bottom: 10px; }

/* ===== 设置 ===== */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.set-row .set-label { font-size: 15px; font-weight: 600; }
.set-row .set-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.set-row select {
  min-height: 40px; border-radius: 10px; border: 2px solid #e4dcfa; padding: 0 10px;
  font-size: 14px; background: var(--card); color: var(--text); outline: none;
}
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute; inset: 0; background: #ddd6f3; border-radius: 999px; transition: .2s;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { left: 23px; }
.danger-zone .btn { background: var(--bad-soft); color: var(--bad); }

/* ===== 弹层/提示 ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  background: rgba(46, 42, 59, .92); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; z-index: 100; max-width: 86%;
  text-align: center; animation: fadeIn .2s;
}
.modal {
  position: fixed; inset: 0; background: rgba(30, 20, 50, .5); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fadeIn .2s;
}
.modal-card {
  background: var(--card); border-radius: 20px; padding: 26px 22px; width: 100%; max-width: 340px;
  text-align: center; animation: pop .35s;
}
.modal-card .m-icon { font-size: 52px; }
.modal-card h3 { font-size: 19px; margin: 8px 0 4px; }
.modal-card p { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 16px; }
.modal-card .btn { width: 100%; }

/* ===== 彩带 ===== */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti i {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: .6; }
}

/* ===== 口令门 ===== */
.gate {
  position: fixed; inset: 0; z-index: 200; background: linear-gradient(160deg, #ede9fe, #fce7f3);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate-card { text-align: center; width: 100%; max-width: 320px; }
.gate-icon { font-size: 56px; animation: pop .5s; }
.gate-card h2 { color: var(--primary); margin: 8px 0 4px; }
.gate-tip { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.gate-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 26px; }
.gate-dots i {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary); background: transparent;
  transition: background .15s;
}
.gate-dots i.on { background: var(--primary); }
.gate-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.gate-keys button {
  height: 60px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow);
  font-size: 22px; font-weight: 700; color: var(--text);
}
.gate-keys button:active { background: var(--primary-soft); transform: scale(.96); }
.gate-err { color: var(--bad); font-size: 13px; margin-top: 14px; animation: shake .35s; }

/* ===== 桌面端微调 ===== */
@media (min-width: 560px) {
  body { border-left: 1px solid #f0ebfc; border-right: 1px solid #f0ebfc; }
}
