/* 字课 · 听写 */
:root {
  --paper: #FFF8EE;
  --card: #FFFFFF;
  --ink: #2A2320;
  --ink-2: #6B615A;
  --ink-3: #A1968C;
  --line: #F0E3D0;
  --line-2: #F7EDDE;
  --brand: #D8452F;
  --brand-dark: #B93521;
  --brand-soft: #FCEAE4;
  --green: #2E7D64;
  --green-soft: #E7F3EE;
  --gold: #F2A93B;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "FandolKai", serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --shadow: 0 12px 32px rgba(126, 84, 40, .09);
  --shadow-sm: 0 4px 14px rgba(126, 84, 40, .07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  margin: 0; color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(circle at 1px 1px, rgba(191, 160, 120, .16) 1px, transparent 0) 0 0 / 22px 22px,
    var(--paper);
  min-height: 100vh; min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.loading { text-align: center; color: var(--ink-3); padding: 30vh 20px 0; }
.kai { font-family: var(--kai); }

/* ---------------------------------------------------------------- 顶栏 */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto; padding: 16px 16px 4px; min-height: 64px;
}
.top .title { font-weight: 700; font-size: 18px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: .02em; }
.brand em { font-style: normal; font-weight: 600; color: var(--brand); font-size: 15px; background: var(--brand-soft); padding: 1px 9px; border-radius: 999px; }
.brand-tile {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-family: var(--kai); font-size: 22px; font-weight: 400;
  box-shadow: 0 4px 12px rgba(216, 69, 47, .28);
}
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); font-size: 15px; font-weight: 600; box-shadow: var(--shadow-sm);
}
.pill span { color: var(--brand); font-size: 13px; }
.pill.back { font-weight: 500; color: var(--ink-2); }

/* ---------------------------------------------------------------- 通用 */
.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 64px; }
.eyebrow {
  display: inline-block; font-size: 13px; letter-spacing: .14em; color: var(--brand);
  background: var(--brand-soft); padding: 3px 11px; border-radius: 999px; font-weight: 600;
}
.lede { color: var(--ink-2); font-size: 16px; margin: 8px 0 20px; }
.meta { color: var(--ink-3); font-size: 15px; margin: 6px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 600; padding: 12px 22px; border-radius: 15px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink); transition: transform .12s, background .15s, border-color .15s;
  text-align: center; line-height: 1.3;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 8px 20px rgba(216, 69, 47, .26); }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.big { font-size: 19px; padding: 17px 28px; border-radius: 18px; width: 100%; }
.btn.ghost { background: rgba(255, 255, 255, .85); }
.btn.ghost:hover { border-color: #E0C8A8; }
.btn.sm { font-size: 14px; padding: 7px 14px; border-radius: 11px; }
.btn.warnbtn { background: var(--ink); border-color: var(--ink); box-shadow: 0 8px 20px rgba(42, 35, 32, .22); }

.seg { display: inline-flex; background: #F6ECDD; border-radius: 13px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 7px 15px; border-radius: 10px; font-size: 15px;
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.seg button.on { background: #fff; color: var(--ink); font-weight: 700; box-shadow: 0 2px 6px rgba(126, 84, 40, .14); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------------------------------------------------------- 选课本 */
.books h1 { font-size: 28px; margin: 22px 0 0; }
.grade-list { display: grid; gap: 10px; }
.grade {
  display: grid; grid-template-columns: 88px 1fr 1fr; gap: 10px; align-items: center;
  background: #fff; border: 1px solid var(--line-2); border-radius: 18px; padding: 10px 10px 10px 18px; box-shadow: var(--shadow-sm);
}
.g-name { font-weight: 700; }
.g-term {
  border: 1.5px solid var(--line); background: #FFFCF7; border-radius: 13px; padding: 12px 8px; font-size: 16px; font-weight: 600;
}
.g-term:hover { border-color: var(--brand); color: var(--brand); }
.g-term.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------------------------------------------------------------- 首页 */
.hero {
  position: relative; background: #fff; border: 1px solid #FBEFDD; border-radius: 28px;
  box-shadow: var(--shadow); padding: 30px 24px 24px; margin: 26px 0 14px;
}
.hero .mascot { position: absolute; top: -24px; right: 22px; width: 54px; height: 54px; }
.hero h1 { font-size: 34px; line-height: 1.25; margin: 12px 0 0; font-family: var(--kai); font-weight: 400; letter-spacing: .03em; }
.hero h1 small { display: block; font-family: var(--sans); font-size: 15px; color: var(--ink-3); letter-spacing: 0; margin-bottom: 2px; }
.hero .btn { margin-top: 20px; }

.wrongbox {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "head go" "chars go"; gap: 4px 12px; align-items: center;
  background: #2A2320; color: #fff; border-radius: 22px; padding: 16px 18px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.wrongbox:active { transform: scale(.99); }
.wb-head { grid-area: head; display: flex; gap: 10px; align-items: baseline; }
.wb-head span { color: rgba(255, 255, 255, .6); font-size: 14px; }
.wb-chars { grid-area: chars; display: flex; flex-wrap: wrap; gap: 4px; }
.wb-chars i { font-style: normal; font-family: var(--kai); font-size: 22px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; background: rgba(255, 255, 255, .1); }
.wb-chars i.more { background: none; }
.wb-go { grid-area: go; background: var(--brand); padding: 10px 14px; border-radius: 13px; font-weight: 700; font-size: 15px; white-space: nowrap; }

.sec { font-size: 15px; color: var(--ink-3); font-weight: 600; margin: 30px 0 4px; letter-spacing: .06em; }
.unit h3 { font-size: 13px; color: var(--ink-3); font-weight: 500; margin: 16px 4px 6px; }
.unit ul { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: 18px; border: 1px solid var(--line-2); overflow: hidden; }
.unit li + li { border-top: 1px solid var(--line-2); }
.row { display: flex; align-items: center; gap: 10px; padding: 13px 16px; min-height: 54px; }
a.row:hover { background: #FFFBF5; }
a.row:hover .r-name { color: var(--brand); }
.row.now { background: #FFF6EC; box-shadow: inset 3px 0 0 var(--brand); }
.r-pre { font-size: 13px; color: var(--ink-3); width: 58px; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-n { font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.r-st { font-size: 12.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.r-st.ok { color: var(--green); background: var(--green-soft); }
.r-st.bad { color: var(--brand); background: var(--brand-soft); }
.row.off { color: var(--ink-3); }
.row.off .r-name { font-weight: 400; }
.row.off .r-st { color: var(--ink-3); font-weight: 400; padding: 0; }
.foot { color: var(--ink-3); font-size: 13px; margin: 34px 4px 0; line-height: 1.7; }

/* ---------------------------------------------------------------- 准备 */
.ready { text-align: center; padding-top: 22px; }
.ready h1 { font-family: var(--kai); font-weight: 400; font-size: 40px; line-height: 1.25; margin: 12px 0 18px; }
.ready > .seg { margin-bottom: 2px; }
.ready > .seg button { padding: 9px 20px; font-size: 16px; }
.opts {
  background: #fff; border: 1px solid var(--line-2); border-radius: 20px; box-shadow: var(--shadow-sm);
  margin: 26px 0 22px; text-align: left;
}
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px 12px 18px; }
.opt + .opt { border-top: 1px solid var(--line-2); }
.opt > span { color: var(--ink-2); font-size: 15px; }
.warn { background: #FFF1D6; color: #8A5A10; font-size: 14px; border-radius: 14px; padding: 10px 14px; margin: -8px 0 18px; text-align: left; }
.peek { margin-top: 22px; color: var(--ink-3); font-size: 14px; }
.peek summary { cursor: pointer; display: inline-block; padding: 6px 10px; }
.peek p { font-family: var(--kai); font-size: 22px; color: var(--ink); line-height: 1.8; margin-top: 10px; background: #fff; border-radius: 16px; padding: 14px 18px; border: 1px solid var(--line-2); text-align: left; }

/* ---------------------------------------------------------------- 听写中 */
.play { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; padding: 0 16px; }
.ptop { display: flex; align-items: center; gap: 14px; padding: 16px 0 6px; }
.icon {
  width: 42px; height: 42px; flex: none; border-radius: 14px; background: #fff; border: 1px solid var(--line);
  color: var(--ink-2); display: grid; place-items: center; font-size: 14px; box-shadow: var(--shadow-sm);
}
.icon:hover { color: var(--brand); border-color: var(--brand); }
.prog { flex: 1; height: 10px; background: #F3E6D3; border-radius: 99px; overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 99px; transition: width .4s ease; }

.pstage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 10px 0; }
.reader { width: 150px; height: 150px; margin-bottom: 18px; }
.reader .mascot { width: 100%; height: 100%; filter: drop-shadow(0 12px 18px rgba(60, 40, 20, .2)); transform-origin: 50% 100%; animation: float 4s ease-in-out infinite; }
.mascot .pupil { animation: blink 5.2s infinite; transform-origin: center; transform-box: fill-box; }
.mascot .mt { display: none; }
.mascot .mt-idle { display: block; }
.reader.talk .mt-idle, .reader.happy .mt-idle { display: none; }
.reader.talk .mt-talk { display: block; animation: talk .32s ease-in-out infinite alternate; transform-origin: center; transform-box: fill-box; }
.reader.talk .mascot { animation: bob .64s ease-in-out infinite; }
.reader.happy .mt-happy { display: block; }
.reader.happy .mascot { animation: jump .6s ease 2; }
.reader.rest .mascot { animation: none; opacity: .55; }
.hero .mascot { animation: float 4s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(60, 40, 20, .18)); }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes bob { 50% { transform: translateY(-4px) scale(1.03, .97); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes talk { from { transform: scaleY(.35); } to { transform: scaleY(1.15); } }
@keyframes jump { 40% { transform: translateY(-16px) scale(1.06); } }

.pcount { color: var(--ink-3); font-size: 16px; font-variant-numeric: tabular-nums; letter-spacing: .06em; }
.pcount b { color: var(--ink); font-size: 30px; font-weight: 800; margin-right: 2px; }
.pstate { font-size: 24px; font-weight: 700; margin-top: 6px; min-height: 1.5em; }
.pstate.small { font-size: 15px; font-weight: 500; color: var(--ink-3); margin-top: 14px; }
.pend { font-size: 30px; font-weight: 800; }
.bar { width: min(260px, 70vw); height: 8px; border-radius: 99px; background: #F3E6D3; margin-top: 16px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: var(--gold); border-radius: 99px; transform-origin: left; animation: drain linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.pctl { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 0 calc(28px + env(safe-area-inset-bottom)); }
.pctl .btn.ghost { min-width: 88px; }
.pctl .btn.round { width: 112px; height: 112px; border-radius: 50%; font-size: 18px; padding: 0; line-height: 1.25; }
.pctl .btn.wide { flex: 1; max-width: 320px; font-size: 18px; padding: 16px 20px; border-radius: 18px; }

/* 家长读 */
.say-card { background: #fff; border-radius: 28px; box-shadow: var(--shadow); border: 1px solid #FBEFDD; padding: 26px 30px 22px; margin-top: 16px; min-width: min(320px, 100%); }
.sc-word { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.sc-word span { display: flex; flex-direction: column; align-items: center; font-family: var(--kai); font-size: 76px; line-height: 1.1; }
.sc-word .py { font-family: var(--sans); font-size: 18px; color: var(--ink-2); line-height: 1.4; }
.sc-hint { color: var(--ink-2); font-size: 16px; margin-top: 12px; }

/* ---------------------------------------------------------------- 对答案 */
.check { padding-bottom: 130px; }
.check .lede { margin-top: 0; }
.ans { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ans li { background: #fff; border: 1px solid var(--line-2); border-radius: 18px; padding: 10px 10px 12px; position: relative; display: flex; flex-direction: column; align-items: center; box-shadow: var(--shadow-sm); }
.no { position: absolute; top: 8px; left: 11px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tiles { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.tile {
  display: flex; flex-direction: column; align-items: center; border: 2px solid transparent; background: #FFFCF7;
  border-radius: 12px; padding: 2px 4px 4px; min-width: 52px; font-family: var(--kai); font-size: 40px; line-height: 1.1; position: relative;
  transition: background .12s, border-color .12s;
}
.tile .py { font-family: var(--sans); font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.tile:hover { border-color: #EBD9C2; }
.tile.bad { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.tile.bad::after {
  content: "✗"; position: absolute; top: -9px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand); color: #fff; font: 700 12px/20px var(--sans);
}
.hw { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(255, 248, 238, 0), var(--paper) 30%);
}
.dock .btn { display: flex; max-width: 608px; margin: 0 auto; }

/* ---------------------------------------------------------------- 结果 */
.result { text-align: center; padding-top: 30px; }
.result h1 { font-size: 30px; font-weight: 800; margin-top: 10px; }
.seal {
  width: 112px; height: 112px; margin: 10px auto 14px; border: 4px solid var(--brand); border-radius: 50%;
  color: var(--brand); display: grid; place-items: center; font-family: var(--kai); font-size: 36px; letter-spacing: .08em;
  transform: rotate(-9deg); animation: stamp .5s cubic-bezier(.2, .9, .3, 1.4) both;
}
@keyframes stamp {
  0% { transform: rotate(-9deg) scale(2.4); opacity: 0; }
  60% { transform: rotate(-9deg) scale(.92); opacity: 1; }
  100% { transform: rotate(-9deg) scale(1); opacity: .92; }
}
.fix { background: #fff; border: 1px solid #FBEFDD; border-radius: 26px; box-shadow: var(--shadow); padding: 18px; margin: 22px 0 6px; }
.fix-chars { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fc {
  font-family: var(--kai); font-size: 30px; width: 56px; height: 56px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #FFFCF7;
}
.fc.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.fix-pane { display: flex; gap: 20px; align-items: center; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.tzg {
  position: relative; border: 2px solid var(--brand); border-radius: 10px; background: #FFFDF8;
  box-shadow: inset 0 0 0 5px #FFF8EE; display: grid; place-items: center; min-width: 120px; min-height: 120px;
}
.tzg::before, .tzg::after { content: ""; position: absolute; pointer-events: none; border: dashed #EFD8BE; border-width: 0; }
.tzg::before { left: 50%; top: 0; bottom: 0; border-left-width: 1px; }
.tzg::after { top: 50%; left: 0; right: 0; border-top-width: 1px; }
.tzg svg { position: relative; z-index: 1; display: block; }
.tzg .kai { font-size: 100px; padding: 0 20px; }
.fix-info { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; min-width: 150px; }
.fix-info b { font-size: 24px; }
.fix-info span { color: var(--ink-2); }
.fix-btns { display: flex; gap: 8px; margin-top: 10px; }
.fx-msg { color: var(--ink-3); font-size: 13.5px; min-height: 1.5em; margin-top: 4px; max-width: 220px; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 26px; }
.actions .btn { width: 100%; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -14px; width: 9px; height: 15px; background: var(--c, #F2A93B); border-radius: 3px; animation: fall 1.7s ease-in forwards; }
@keyframes fall { 0% { transform: translateY(-20px) rotate(0); opacity: 1; } 100% { transform: translateY(96vh) rotate(460deg); opacity: 0; } }

/* ---------------------------------------------------------------- 窄屏 */
@media (max-width: 420px) {
  .hero h1 { font-size: 30px; }
  .ready h1 { font-size: 34px; }
  .r-pre { width: 50px; }
  .r-n { display: none; }
  .grade { grid-template-columns: 70px 1fr 1fr; padding-left: 14px; }
  .opt { padding-left: 14px; }
  .seg button { padding: 7px 12px; }
  .pctl { gap: 8px; }
  .pctl .btn.ghost { min-width: 76px; padding: 12px 12px; }
  .pctl .btn.round { width: 100px; height: 100px; font-size: 17px; }
  .reader { width: 124px; height: 124px; }
  .sc-word span { font-size: 62px; }
  .ans { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  /* 写字倒计时条要留着，它是在告诉孩子还剩多少时间 */
  *:not(.bar > i), *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
