/* ============ 基础 ============ */
:root {
  --bg1: #8fd3ff;
  --bg2: #c8f7dc;
  --card: #ffffff;
  --ink: #2b2d42;
  --muted: #6c757d;
  --primary: #ff7a00;
  --primary-dark: #e06500;
  --good: #2bb673;
  --bad: #ef476f;
  --warn: #ffb703;
  --blue: #4361ee;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 10px 24px rgba(30, 60, 90, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; }
h2, h3 { margin: .3em 0 .6em; }
p { line-height: 1.6; }

#app { max-width: 1180px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 28px; }
.screen { animation: fadeIn .25s ease; }

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 100; }

#toast {
  position: fixed; left: 50%; top: 22px; transform: translate(-50%, -120px);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 18px; transition: transform .3s ease; z-index: 120; max-width: 90vw; text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.narrow { max-width: 680px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 56px; padding: 0 24px; border-radius: 18px; font-size: 20px; font-weight: 700;
  background: #eef2f7; box-shadow: 0 4px 0 #cfd6df; transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #cfd6df; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); }
.btn-primary:active { box-shadow: 0 1px 0 var(--primary-dark); }
.btn-danger { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #c22d50; }
.btn-ghost { background: #f4f6fa; box-shadow: none; font-size: 18px; min-height: 48px; }
.btn-big { width: 100%; min-height: 68px; font-size: 24px; margin-top: 14px; }
.row-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.link-btn { display: block; margin: 12px auto 0; color: var(--blue); font-size: 16px; text-decoration: underline; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, .85);
  padding: 8px 14px; border-radius: 999px; font-size: 18px; white-space: nowrap; box-shadow: 0 3px 0 rgba(0, 0, 0, .06);
}
.chip-btn { min-height: 44px; }

/* ============ 顶栏 ============ */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.btn-back {
  min-height: 50px; padding: 0 18px; border-radius: 16px; font-size: 20px; font-weight: 700;
  background: rgba(255, 255, 255, .9); box-shadow: 0 3px 0 rgba(0, 0, 0, .08);
}
.topbar-title { flex: 1; font-size: 24px; font-weight: 800; text-align: center; }

/* ============ 首次进入 ============ */
.onboard { max-width: 760px; margin: 0 auto; text-align: center; }
.title-big { font-size: 46px; font-weight: 900; margin-top: 10px; color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, .15); }
.subtitle { font-size: 20px; margin-top: 4px; }
.onboard .card { text-align: left; }
.name-input {
  width: 100%; font-size: 26px; padding: 14px 18px; border-radius: 16px; border: 3px solid #dfe6ee;
  outline: none; font-family: inherit; -webkit-user-select: text; user-select: text;
}
.name-input:focus { border-color: var(--primary); }
.pet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.pet-choice {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px;
  border-radius: 18px; background: #f4f6fa; border: 3px solid transparent; font-size: 17px;
}
.pet-choice-emoji { font-size: 52px; line-height: 1.1; }
.pet-choice.selected { border-color: var(--primary); background: #fff3e6; transform: scale(1.05); }

/* ============ 首页 ============ */
.home-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.hello { font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .15); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.home-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }

.pet-card { text-align: center; position: relative; }
.speech {
  display: block; width: fit-content; margin-left: auto; margin-right: auto; background: #fff8e1; border: 2px solid #ffe08a; padding: 8px 14px;
  border-radius: 16px; font-size: 17px; position: relative; margin-bottom: 4px;
}
.speech::after {
  content: ""; position: absolute; left: 50%; bottom: -10px; margin-left: -8px;
  border: 8px solid transparent; border-top-color: #ffe08a; border-bottom: 0;
}
.pet { position: relative; display: inline-flex; align-items: center; justify-content: center; margin: 6px auto; line-height: 1; cursor: pointer; }
.pet-card .pet { display: flex; }
.pet-acc { position: absolute; top: -4%; left: 50%; transform: translateX(-50%) rotate(-8deg); }
.pet-name { font-size: 20px; font-weight: 800; margin-bottom: 8px; }

.bar { height: 16px; background: #edf1f6; border-radius: 999px; overflow: hidden; flex: 1; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #ffd166, var(--primary)); border-radius: 999px; transition: width .4s; }

.task {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; margin-bottom: 10px;
  border-radius: 16px; background: #f4f6fa; font-size: 19px; text-align: left; min-height: 60px;
}
.task.done { background: #e6f8ef; color: #1b7f50; }
.task-icon { font-size: 28px; }
.task-text { flex: 1; }
.task-num { font-weight: 800; }

.diag-banner {
  width: 100%; padding: 16px; border-radius: 16px; background: #fff3e6; border: 3px dashed var(--primary);
  font-size: 19px; font-weight: 700; margin-bottom: 14px; color: var(--primary-dark);
}
.islands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.island {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; min-height: 160px; border-radius: 24px; color: #fff; padding: 12px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .15); transition: transform .1s;
}
.island:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.island-icon { font-size: 56px; line-height: 1.1; }
.island-name { font-size: 22px; font-weight: 900; }
.island-desc { font-size: 15px; opacity: .92; }
.isl-green { background: linear-gradient(160deg, #57cc99, #2a9d8f); }
.isl-orange { background: linear-gradient(160deg, #ffb347, #ff7a00); }
.isl-purple { background: linear-gradient(160deg, #b388ff, #7b2cbf); }
.isl-blue { background: linear-gradient(160deg, #64b5f6, #1e63c4); }
.isl-pink { background: linear-gradient(160deg, #ff8fab, #e5517a); }
.isl-dark { background: linear-gradient(160deg, #5c677d, #33415c); }
.island.locked { filter: grayscale(.85); opacity: .6; }
.badge-rec, .badge-count {
  position: absolute; top: -8px; right: -6px; background: var(--bad); color: #fff; font-weight: 800;
  padding: 4px 12px; border-radius: 999px; font-size: 15px; box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
  animation: pulse 1.4s infinite;
}

.mode-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.btn-mode { min-width: 130px; min-height: 72px; font-size: 22px; background: #fff3e6; box-shadow: 0 4px 0 #ffd3a6; }

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 50, .45); display: flex; align-items: center;
  justify-content: center; z-index: 90; padding: 16px;
}
.modal { width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; margin: 0; }
.modal-btns { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.modal-btns .btn { flex: 1; min-width: 130px; }
.big-score { font-size: 64px; font-weight: 900; color: var(--primary); }
.big-score small { font-size: 24px; }
.big-stars { font-size: 60px; color: #ffb703; letter-spacing: 6px; }
.big-emoji { font-size: 22px; }
.big-emoji::first-line { font-size: 60px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.result-grid.four { grid-template-columns: repeat(4, 1fr); margin: 0; }
.result-grid div { background: #f4f6fa; border-radius: 16px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; }
.result-grid b { font-size: 30px; }
.result-grid span { font-size: 15px; color: var(--muted); }

/* ============ 答题布局（题目 + 键盘） ============ */
.play-area { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
.play-main { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.play-pad { position: sticky; top: 16px; }

.dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: rgba(255, 255, 255, .8); }
.dot.cur { background: var(--primary); transform: scale(1.25); }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }

.question { font-size: 58px; font-weight: 900; letter-spacing: 2px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.answer-box {
  display: inline-block; min-width: 140px; padding: 4px 18px; border-radius: 18px; background: #fff;
  border: 4px solid #dfe6ee; color: var(--blue);
}
.answer-box.ok { border-color: var(--good); color: var(--good); }
.answer-box.reveal { border-color: var(--bad); color: var(--bad); }
.feedback { min-height: 32px; font-size: 22px; font-weight: 700; }
.feedback.good { color: var(--good); }
.feedback.soft { color: #b5562a; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: rgba(255, 255, 255, .6); padding: 14px; border-radius: 26px; }
.key {
  height: 80px; border-radius: 20px; background: #fff; font-size: 36px; font-weight: 800;
  box-shadow: 0 5px 0 #cfd6df; transition: transform .06s;
}
.key:active { transform: translateY(4px); box-shadow: 0 1px 0 #cfd6df; background: #fff3e6; }
.key-del { background: #ffe5ea; color: var(--bad); }
.key-enter { grid-column: 1 / -1; background: var(--good); color: #fff; box-shadow: 0 5px 0 #1b8a55; font-size: 28px; }
.keypad.compact .key { height: 72px; }

/* ============ 诊断结果 ============ */
.diag-row { display: grid; grid-template-columns: 110px 1fr 150px; gap: 12px; align-items: center; margin: 12px 0; font-size: 18px; }
.diag-tag { font-weight: 700; font-size: 16px; }
.lvl-good { color: var(--good); }
.lvl-mid { color: #d68c00; }
.lvl-bad { color: var(--bad); }
.bar-fill.lvl-good { background: var(--good); }
.bar-fill.lvl-mid { background: var(--warn); }
.bar-fill.lvl-bad { background: var(--bad); }
.recommend { text-align: center; font-size: 22px; background: #fff3e6; border-radius: 16px; padding: 14px; margin: 16px 0 8px; }

/* ============ 口诀泡泡 ============ */
.bubble-hud { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.time-bar { height: 22px; }
.time-fill { background: linear-gradient(90deg, #57cc99, #2a9d8f); transition: none; }
.time-fill.hurry { background: linear-gradient(90deg, #ff8fab, var(--bad)); }
.bubble-stage {
  position: relative; height: calc(100vh - 170px); min-height: 460px; border-radius: 28px; overflow: hidden;
  background: linear-gradient(180deg, #bfe9ff 0%, #6ec6ff 60%, #3a8ee6 100%); box-shadow: var(--shadow);
}
.bubble-q {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: #fff; padding: 10px 34px; border-radius: 22px; font-size: 48px; font-weight: 900;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .12); white-space: nowrap;
}
.combo { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); z-index: 5; font-size: 26px; font-weight: 900; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .25); opacity: 0; }
.combo.flash { animation: floatUp 1s ease forwards; }
.bubble-tip { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 5; font-size: 22px; font-weight: 800; color: #fff; background: rgba(239, 71, 111, .9); padding: 6px 18px; border-radius: 999px; white-space: nowrap; }
.bubble-tip:empty { display: none; }
.bubble-field { position: absolute; inset: 0; }
.bubble {
  position: absolute; left: 0; top: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #1d3557; will-change: transform; cursor: pointer;
  background: radial-gradient(circle at 30% 28%, rgba(255, 255, 255, .95) 0 12%, rgba(255, 255, 255, .55) 22%, var(--bc) 70%);
  border: 3px solid rgba(255, 255, 255, .85); box-shadow: inset -6px -8px 16px rgba(0, 0, 0, .08), 0 6px 14px rgba(0, 0, 0, .12);
}
.b1 { --bc: #ffd6e0; } .b2 { --bc: #d0f4de; } .b3 { --bc: #fff1b6; } .b4 { --bc: #e4d9ff; }
.bubble.popped { animation: pop .25s ease forwards; pointer-events: none; }
.bubble.wrong-pop { --bc: #ff9aa9; animation: wrongPop .5s ease forwards; pointer-events: none; }

/* ============ 竖式工地 ============ */
.level-list { display: flex; flex-direction: column; gap: 12px; }
.level-card {
  display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-radius: 20px; background: #fff3e6;
  box-shadow: 0 4px 0 #ffd3a6; text-align: left; min-height: 84px;
}
.level-card.locked { background: #eef1f5; box-shadow: 0 4px 0 #d8dde4; opacity: .7; }
.level-num { width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 26px; font-weight: 900; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.level-card.locked .level-num { background: #b8c0cc; }
.level-info { flex: 1; display: flex; flex-direction: column; font-size: 21px; }
.level-info small { color: var(--muted); font-size: 15px; }
.level-stars { font-size: 28px; color: #ffb703; letter-spacing: 2px; }

.vtitle { font-size: 34px; font-weight: 900; }
.vcard { padding: 22px 32px; margin: 0; }
.vgrid { --cell: 64px; display: inline-flex; flex-direction: column; align-items: flex-end; }
.vrow { display: grid; grid-template-columns: repeat(var(--cols), var(--cell)); }
.vcell {
  height: var(--cell); display: flex; align-items: center; justify-content: center; font-size: 44px;
  font-weight: 800; font-variant-numeric: tabular-nums; border-radius: 12px; margin: 2px; transition: background .15s;
}
.vrow-carry .vcell { height: 26px; font-size: 20px; color: var(--bad); align-items: flex-end; }
.vcell.sign { color: var(--muted); }
.vcell.slot { border: 2px dashed #d5dce5; }
.vcell.src { background: #fff1b6; }
.vrow-carry .vcell.src { background: #ffd6e0; }
.vcell.target { border: 3px solid var(--primary); background: #fff3e6; animation: pulse 1.1s infinite; }
.vcell.target::after { content: "?"; color: #ffb366; }
.vcell.filled { border: none; }
.vcell.ok { color: var(--blue); animation: pop-in .25s ease; }
.vcell.auto { color: #e07a00; animation: pop-in .25s ease; }
.vcell.carry-in { animation: pop-in .3s ease; }
.vline { height: 4px; background: var(--ink); border-radius: 2px; width: 100%; margin: 4px 0; }
.guide { font-size: 22px; font-weight: 800; color: var(--primary-dark); min-height: 30px; max-width: 640px; }
.vmsg { font-size: 21px; font-weight: 700; min-height: 30px; }
.vmsg.bad { color: var(--bad); }
.vmsg.good { color: var(--good); }
.vhint { font-size: 20px; color: #6a4c93; min-height: 28px; max-width: 640px; width: 100%; }

.area-row, .area-col { display: flex; gap: 6px; margin: 14px 0; min-height: 110px; }
.area-col { flex-direction: column; min-height: 220px; }
.area-block { border-radius: 14px; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; font-size: 18px; min-width: 70px; text-align: center; }
.area-block b { font-size: 22px; }
.ab0 { background: #2a9d8f; } .ab1 { background: #ff7a00; } .ab2 { background: #7b2cbf; } .ab3 { background: #1e63c4; }

/* ============ 错题怪兽 ============ */
.monster-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0; }
.monster-stats div { background: #f4f6fa; border-radius: 16px; padding: 10px; display: flex; flex-direction: column; align-items: center; }
.monster-stats b { font-size: 32px; }
.monster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.monster-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px; background: #f1ecff; border-radius: 18px; min-height: 110px; }
.monster-card.resting { background: #f4f6fa; opacity: .75; }
.monster-emoji { font-size: 48px; }
.monster-big { font-size: 130px; line-height: 1.1; animation: bob 2s ease-in-out infinite; }
.monster-big.hit { animation: hit .5s ease; }
.monster-big.laugh { animation: laugh .6s ease 2; }
.monster-hp { font-size: 30px; }

/* ============ 成绩单 ============ */
.heat { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; max-width: 620px; margin: 10px auto; }
.heat-cell { aspect-ratio: 1; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; }
.heat-cell.head { background: none; color: var(--muted); }
.lv0 { background: #edf1f6; color: #9aa5b1; }
.lv1 { background: #ffb3c1; }
.lv2 { background: #ffe08a; }
.lv3 { background: #8ee4af; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; font-size: 15px; margin: 8px 0; }
.legend i { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: -3px; margin-right: 4px; }
.days { display: flex; gap: 12px; justify-content: space-around; align-items: flex-end; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; max-width: 70px; }
.day-bar { height: 140px; width: 100%; max-width: 40px; display: flex; flex-direction: column; justify-content: flex-end; background: #f4f6fa; border-radius: 10px; overflow: hidden; }
.day-right { background: #8ee4af; }
.day-wrong { background: #ffb3c1; }
.mistake-list { display: flex; flex-direction: column; gap: 8px; }
.mistake-item { display: flex; justify-content: space-between; padding: 10px 14px; background: #f4f6fa; border-radius: 12px; font-size: 18px; }

/* ============ 动画 ============ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { to { scale: 1.6; opacity: 0; } }
@keyframes wrongPop { 0% { opacity: 1; } 30% { filter: brightness(1.2); } 100% { opacity: 0; } }
@keyframes pop-in { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.2); } 100% { transform: scale(1); opacity: 1; } }
@keyframes floatUp { 0% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -40px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-30px) rotate(-6deg); } }
@keyframes hit { 0% { transform: scale(1); filter: none; } 30% { transform: scale(.8) rotate(-12deg); filter: brightness(2); } 100% { transform: scale(1); } }
@keyframes laugh { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-10deg) scale(1.1); } 75% { transform: rotate(10deg) scale(1.1); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
.bob { animation: bob 2.4s ease-in-out infinite; }
.jump { animation: jump .5s ease; }
.shake { animation: shake .4s ease; }
.pop-in { animation: pop-in .3s ease; }
.wiggle { animation: wiggle .5s ease-in-out infinite; }

/* ============ 竖屏 / 小屏 ============ */
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
  .play-area { grid-template-columns: 1fr; }
  .play-pad { position: static; max-width: 460px; width: 100%; margin: 0 auto; }
  .question { font-size: 46px; }
}
@media (max-width: 600px) {
  .islands { grid-template-columns: repeat(2, 1fr); }
  .pet-grid { grid-template-columns: repeat(4, 1fr); }
  .pet-choice-emoji { font-size: 40px; }
  .hello { font-size: 24px; }
  .result-grid.four { grid-template-columns: repeat(2, 1fr); }
  .diag-row { grid-template-columns: 90px 1fr; }
  .diag-tag { grid-column: 2; }
  .vgrid { --cell: 46px; }
  .vcell { font-size: 32px; }
  .vcard { padding: 16px; }
  .bubble-q { font-size: 36px; }
  .key { height: 64px; font-size: 30px; }
}
