:root {
  --sky-top: #8fd0f0;
  --sky-bot: #cdeeff;
  --grass: #6aa84f;
  --grass-dark: #4e7d39;
  --dirt: #8b5a2b;
  --ink: #2b2118;
  --panel: #fffdf6;
  --gold: #ffd75e;
  --red: #e05a4f;
  --green: #5aa84f;
  --blue: #4a90d9;
  --line: #2b2118;
  --shadow: 4px 4px 0 rgba(43, 33, 24, .22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, .85) 0 6%, transparent 6.5%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 52%, #eaf8ff 100%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 14px calc(30px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(143, 208, 240, .98), rgba(143, 208, 240, .82) 70%, transparent);
}

.icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 3px 3px 0 rgba(43, 33, 24, .25);
  font-size: 1.15rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform .08s;
}
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(43, 33, 24, .25); }
#btnBack { visibility: hidden; }

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 0 rgba(43, 33, 24, .25));
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.16rem;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: .72rem;
  opacity: .7;
  letter-spacing: .5px;
}

/* ---------------- 屏幕切换 ---------------- */
.screen { display: none; }
.screen.active { display: block; animation: pop .26s ease-out; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- 首页 ---------------- */
.hero-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf6, #fff3cf);
  box-shadow: var(--shadow);
}

.hero-emoji {
  font-size: 2.6rem;
  line-height: 1;
  filter: drop-shadow(2px 3px 0 rgba(43, 33, 24, .2));
}

.hero-copy h2 {
  margin: 0 0 4px;
  font-size: 1.14rem;
}
.hero-copy p {
  margin: 0;
  font-size: .78rem;
  opacity: .72;
}

/* 册次切换 */
.book-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.book-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 4px 5px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 246, .66);
  box-shadow: 2px 2px 0 rgba(43, 33, 24, .14);
  transition: transform .08s, background .12s, box-shadow .12s;
}
.book-tab b {
  font-size: .95rem;
  line-height: 1.15;
}
.book-tab small {
  font-size: .62rem;
  font-weight: 600;
  opacity: .58;
}
.book-tab.on {
  background: linear-gradient(180deg, #ffe9a8, #ffd75e);
  box-shadow: 3px 3px 0 rgba(43, 33, 24, .22);
}
.book-tab:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(43, 33, 24, .18); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 4px;
}

.stat {
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 3px 3px 0 rgba(43, 33, 24, .18);
  padding: 10px 6px 8px;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 1.5rem;
  line-height: 1.1;
  color: #2f6d2a;
}
.stat span {
  display: block;
  margin-top: 2px;
  font-size: .72rem;
  opacity: .68;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 2px 10px;
}
.section-head h3 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: .5px;
}
.section-head span {
  font-size: .72rem;
  opacity: .62;
}

/* 混合复习：本册 / 三册混合 */
.review-head { align-items: center; }
.scope-switch {
  display: inline-flex;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 246, .72);
  overflow: hidden;
  flex: none;
}
.scope-btn {
  border: 0;
  background: transparent;
  padding: 4px 9px;
  font-size: .68rem;
  font-weight: 800;
  line-height: 1.5;
  color: #6b5a41;
  white-space: nowrap;
}
.scope-btn + .scope-btn { border-left: 2px solid var(--line); }
.scope-btn.on { background: #ffd75e; color: var(--ink); }

.unit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.unit-card {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: transform .1s, box-shadow .1s;
}
.unit-card:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 rgba(43, 33, 24, .22);
}

.unit-card.review {
  background:
    linear-gradient(135deg, rgba(255, 215, 94, .28), transparent 55%),
    var(--panel);
}

.unit-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.unit-book {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .5px;
  color: #7a5a1e;
  background: #ffeab0;
  border: 2px solid #d9b45c;
  border-radius: 999px;
  padding: 2px 8px;
}

.unit-stars {
  font-size: .9rem;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #9a7413, -1px 1px 0 #9a7413;
}

.unit-name {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
  word-break: break-word;
}

.unit-zh {
  font-size: .8rem;
  opacity: .7;
  line-height: 1.35;
}

.foot {
  margin: 30px 0 6px;
  text-align: center;
  font-size: .7rem;
  opacity: .5;
}

/* ---------------- 游戏中 ---------------- */
.play-head {
  margin-bottom: 14px;
}

.progress {
  height: 16px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
  box-shadow: 2px 2px 0 rgba(43, 33, 24, .16);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7fd36a, #4aedd9);
  transition: width .28s ease-out;
}

.play-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: .8rem;
  font-weight: 700;
  opacity: .75;
  padding: 0 4px;
}

.q-hint {
  text-align: center;
  font-size: .82rem;
  font-weight: 700;
  opacity: .72;
  margin: 4px 0 14px;
}

.prompt-card {
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 18px;
}
.prompt-card.small {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.prompt-card .emoji {
  font-size: 4rem;
  line-height: 1.05;
  filter: drop-shadow(2px 4px 0 rgba(43, 33, 24, .14));
}
.prompt-card.small .emoji { font-size: 1.7rem; }

.prompt-card .zh {
  margin-top: 6px;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 1px;
}
.prompt-card.small .zh { margin: 0; }

.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.choice {
  min-height: 68px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 8px;
  transition: transform .08s, background .15s;
  word-break: break-word;
}
.choice:active { transform: translate(2px, 2px); }
.choice.right {
  background: #d9f5cf;
  border-color: var(--green);
  color: #2f6d2a;
}
.choice.wrong {
  background: #ffe0dc;
  border-color: var(--red);
  color: #a7281d;
  animation: shake .32s;
}
.choice.dim { opacity: .45; }

@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* 听音 */
.big-speaker {
  display: block;
  width: 132px;
  height: 132px;
  margin: 6px auto 6px;
  border: 4px solid var(--line);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff, #ffe9a8 70%);
  box-shadow: 5px 6px 0 rgba(43, 33, 24, .22);
  font-size: 3.6rem;
  line-height: 1;
  transition: transform .1s;
}
.big-speaker:active { transform: scale(.94); }

.listen-tip {
  text-align: center;
  font-size: .78rem;
  opacity: .6;
  margin: 2px 0 18px;
}

.speak-line {
  display: block;
  margin: 16px auto 0;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: 2px 2px 0 rgba(43, 33, 24, .18);
  padding: 8px 18px;
  font-size: .86rem;
  font-weight: 800;
}
.speak-line:active { transform: translate(2px, 2px); }

/* 补字母 */
.slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 18px;
}

.slot {
  width: 44px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 1.5rem;
  font-weight: 900;
  text-transform: lowercase;
}
.slot.fixed {
  background: #eef4e9;
  border-color: #8a9a80;
  color: #4c5a44;
}
.slot.blank {
  border-style: dashed;
  background: #fffbe8;
  color: #b08a2e;
}
.slot.blank.filled {
  border-style: solid;
  border-color: var(--green);
  background: #e6f7df;
  color: #2f6d2a;
}
.slot.blank.bad { animation: shake .32s; border-color: var(--red); }

.letters {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
}
.letter {
  min-height: 56px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 3px 3px 0 rgba(43, 33, 24, .2);
  font-size: 1.35rem;
  font-weight: 900;
  text-transform: uppercase;
}
.letter:active { transform: translate(2px, 2px); }
.letter.wrong {
  background: #ffe0dc;
  border-color: var(--red);
  color: #a7281d;
  opacity: .65;
}
.letter.used { opacity: .35; }

/* 看词打字 */
.copy-card { padding-bottom: 14px; }

.copy-word {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 8px;
  margin-top: 14px;
}

/* 短语按单词分组，换行不会把单词拆开 */
.cl-word {
  display: inline-flex;
  gap: 5px;
}

.cl {
  width: 38px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  text-transform: lowercase;
  transition: background .12s, border-color .12s;
}
.cl.filled {
  background: #d9f5cf;
  border-color: var(--green);
  color: #2f6d2a;
}
.cl.next {
  border-color: #d99a00;
  background: #fff2b8;
  animation: key-bob 1.1s ease-in-out infinite;
}
.cl.bad {
  border-color: var(--red);
  background: #ffe0dc;
  animation: shake .32s;
}

@keyframes key-bob {
  50% { transform: translateY(-3px); }
}

.os-kb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 16px 0 4px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 42px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 2px 2px 0 rgba(43, 33, 24, .18);
  font-size: .95rem;
  font-weight: 900;
  text-transform: uppercase;
  line-height: 1;
}
.key:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}
/* 屏幕键盘可点击，不位移，只做发光呼吸，避免抖动影响点按 */
.key.next {
  background: var(--gold);
  border-color: #b8860b;
  animation: key-glow 1.1s ease-in-out infinite;
}

@keyframes key-glow {
  50% { background: #ffe9a0; box-shadow: 0 0 0 3px rgba(255, 205, 60, .55); }
}
.key.wide {
  max-width: 66px;
  flex: 1.6;
  font-size: .72rem;
  text-transform: none;
}

.copy-tools {
  text-align: center;
}

.primary {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 14px 18px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffe480, var(--gold));
  box-shadow: var(--shadow);
  font-size: 1.08rem;
  font-weight: 900;
  letter-spacing: 1px;
}
.primary:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 rgba(43, 33, 24, .22); }

.ghost {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px 18px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: .96rem;
  font-weight: 800;
}
.ghost:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 rgba(43, 33, 24, .22); }

/* 配对 */
.match-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.mcard {
  min-height: 82px;
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.25;
  word-break: break-word;
  transition: transform .1s, background .15s, opacity .2s;
}
.mcard.en {
  background: #e8f4ff;
  color: #1d4f80;
}
.mcard.zh {
  background: #fff8e2;
  color: #6d4a10;
}
.mcard.sel {
  border-color: #d99a00;
  background: #fff2b8;
  transform: translateY(-3px);
  box-shadow: 4px 7px 0 rgba(43, 33, 24, .22);
}
.mcard.right {
  background: #d9f5cf !important;
  border-color: var(--green) !important;
  color: #2f6d2a !important;
  opacity: .8;
}
.mcard.wrong {
  background: #ffe0dc !important;
  border-color: var(--red) !important;
  animation: shake .32s;
}

.match-tip {
  margin: 14px 0 0;
  text-align: center;
  font-size: .75rem;
  opacity: .55;
}

/* ---------------- 反馈条 ---------------- */
.feedback {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 24px);
  width: min(92vw, 520px);
  padding: 12px 16px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 4px 5px 0 rgba(43, 33, 24, .25);
  font-size: .92rem;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 40;
}
.feedback.show { opacity: 1; transform: translate(-50%, 0); }
.feedback.ok { background: #e4f8db; border-color: var(--green); color: #2f6d2a; }
.feedback.no { background: #fff0dc; border-color: #d99a00; color: #7a5310; }
.feedback b { font-size: 1.05rem; }

/* ---------------- 结算 ---------------- */
.result-card {
  border: 3px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #fffdf6, #fff3cf);
  box-shadow: var(--shadow);
  padding: 22px 18px 18px;
  text-align: center;
  margin-top: 8px;
}

.stars {
  font-size: 2.7rem;
  letter-spacing: 8px;
  line-height: 1;
  color: #d8d2c2;
  text-shadow: 2px 2px 0 rgba(43, 33, 24, .18);
}
.stars .star.on {
  color: var(--gold);
  text-shadow: 2px 2px 0 #a97d12, -2px 2px 0 #a97d12;
  animation: star-pop .45s backwards;
}
.stars .star:nth-child(2) { animation-delay: .12s; }
.stars .star:nth-child(3) { animation-delay: .24s; }

@keyframes star-pop {
  0% { transform: scale(.2) rotate(-30deg); opacity: 0; }
  70% { transform: scale(1.25) rotate(6deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-card h2 {
  margin: 12px 0 4px;
  font-size: 1.3rem;
}

.res-acc {
  margin: 0 0 6px;
  font-size: .9rem;
  font-weight: 700;
  opacity: .75;
}

.res-missed {
  margin-top: 14px;
  text-align: left;
}
.res-missed .rm-title {
  font-size: .8rem;
  font-weight: 800;
  opacity: .6;
  margin: 0 0 8px;
  text-align: center;
}
.res-missed .rm-empty {
  text-align: center;
  font-size: .9rem;
  font-weight: 700;
  color: #2f6d2a;
  background: #e4f8db;
  border: 2px dashed #8fc47e;
  border-radius: 12px;
  padding: 12px;
}
.word-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid #e2d9c3;
  border-radius: 12px;
  background: #fff;
  margin-bottom: 8px;
}
.word-row .we { font-size: 1.05rem; font-weight: 900; }
.word-row .wz { font-size: .82rem; opacity: .65; margin-left: auto; }
.word-row .mini-speak {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff8dc;
  font-size: .95rem;
  display: grid;
  place-items: center;
}

.result-actions { margin-top: 18px; }

/* ---------------- 玩法弹层 ---------------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(24, 20, 14, .48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .18s;
}
.sheet-mask.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 0 rgba(43, 33, 24, .18);
  animation: slide-up .22s ease-out;
}
@keyframes slide-up {
  from { transform: translateY(40px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-grip {
  width: 46px;
  height: 6px;
  border-radius: 4px;
  background: #d9d2c0;
  margin: 2px auto 10px;
}

.sheet h3 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  text-align: center;
}

.sheet-modes {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 3px 3px 0 rgba(43, 33, 24, .18);
  transition: transform .08s;
}
.mode-btn:active { transform: translate(2px, 2px); }
.mode-btn .mi {
  font-size: 1.7rem;
  line-height: 1;
  flex: 0 0 auto;
}
.mode-btn .mt { display: flex; flex-direction: column; gap: 2px; }
.mode-btn .mt b { font-size: 1rem; }
.mode-btn .mt small { font-size: .74rem; opacity: .62; font-weight: 500; }

.sheet-cancel {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #efe9db;
  font-size: .92rem;
  font-weight: 800;
}

/* ---------------- 大屏 ---------------- */
@media (min-width: 560px) {
  .unit-grid { grid-template-columns: 1fr 1fr; }
  .choices { gap: 14px; }
  .choice { min-height: 76px; font-size: 1.45rem; }
  .match-grid { grid-template-columns: repeat(4, 1fr); }
  .mcard { min-height: 96px; }
  .slot { width: 50px; height: 60px; font-size: 1.7rem; }
  .sheet-mask { align-items: center; }
  .sheet { border-radius: 22px; }
  .sheet-modes { display: grid; grid-template-columns: 1fr 1fr; }
  .mode-btn { height: 100%; }
  .sheet-cancel { width: 220px; margin-left: auto; margin-right: auto; }
}

@media (max-width: 360px) {
  .choice { font-size: 1.12rem; min-height: 60px; }
  .slot { width: 38px; height: 48px; font-size: 1.3rem; }
  .letters { gap: 7px; }
  .letter { min-height: 50px; font-size: 1.2rem; }
  .mcard { min-height: 74px; font-size: .92rem; }
}

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

/* ---------- 全屏按钮 ---------- */
[data-fullscreen] { touch-action: manipulation; }
[data-fullscreen] .fs-enter,
[data-fullscreen] .fs-exit {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
[data-fullscreen] .fs-exit { display: none; }
[data-fullscreen].is-fs .fs-enter { display: none; }
[data-fullscreen].is-fs .fs-exit { display: block; }
