:root {
  --bg: #FFF4D6; --card: #FFFFFF; --ink: #3B2A2A; --ink2: #7A6558;
  --star: #FFD166; --starLine: #F2B84B; --pink: #FFB5A7; --mint: #B5EAD7; --line: #E8DCC4; --face: #FFE9D6;
  --ok: #5FBF8F; --ng: #F08A7A;
  --r: 24px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Arial Rounded MT Bold", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  min-height: 100vh; min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
.screen { display: none; max-width: 820px; margin: 0 auto; padding: 16px 16px 40px; }
.screen.on { display: block; }
.hidden { display: none !important; }

/* 共用元件 */
.card { background: var(--card); border: 3px solid var(--line); border-radius: var(--r); padding: 16px; }
.btn { background: var(--star); border: 3px solid var(--starLine); border-radius: 999px; padding: 14px 26px; font-size: 22px; font-weight: 700; }
.btn:active { transform: scale(.96); }
.btn.pink { background: var(--pink); border-color: #F29A89; }
.btn.mint { background: var(--mint); border-color: #8FD6BD; }
.btn.white { background: #fff; border-color: var(--line); }
.btn.small { font-size: 16px; padding: 8px 16px; }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
h1, h2, h3 { margin: 0 0 8px; }
.muted { color: var(--ink2); }
.chip { display: inline-block; white-space: nowrap; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--face); }
.lv1 { background: var(--pink); } .lv2 { background: var(--star); } .lv3 { background: var(--mint); } .lv4 { background: var(--starLine); color: #fff; }

/* 頂列 */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.iconbtn { width: 52px; height: 52px; border-radius: 50%; background: #fff; border: 3px solid var(--line); display: grid; place-items: center; }
.iconbtn svg { width: 26px; height: 26px; }

/* 首頁 */
.hero { display: flex; align-items: center; gap: 12px; }
.hero .meh { width: 170px; flex: none; }
.hero .meh img, .hero .meh svg { width: 100%; height: auto; display: block; }
.bubble { position: relative; background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 12px 16px; font-size: 20px; font-weight: 700; }
.bubble::before { content: ""; position: absolute; left: -12px; top: 50%; margin-top: -9px; border: 9px solid transparent; border-right-color: var(--line); border-left: 0; }
.home-actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.home-actions .btn.go { flex: 1 1 220px; font-size: 28px; padding: 18px; }

/* 集點卡 */
.stampcard { background: #fff; border: 3px dashed var(--starLine); border-radius: var(--r); padding: 14px; }
.stampcard .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 700; }
.slots { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.slot { aspect-ratio: 1; border-radius: 50%; background: var(--bg); border: 3px solid var(--line); display: grid; place-items: center; }
.slot svg { width: 78%; height: 78%; }
.slot.pop svg { animation: pop .45s ease-out; }
@keyframes pop { 0% { transform: scale(.2); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
.mini-card { display: flex; gap: 3px; background: #fff; border: 3px solid var(--line); border-radius: 999px; padding: 6px 10px; }
.mini-card .slot { width: 20px; border-width: 2px; }

/* 字卡清單 */
.wordlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.worditem { background: #fff; border: 3px solid var(--line); border-radius: 18px; padding: 10px 12px; text-align: left; }
.worditem b { display: block; font-size: 18px; }
.worditem .zh { color: var(--ink2); font-size: 15px; }
.worditem .dots { margin-top: 6px; display: flex; gap: 4px; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--line); }
.dot.on { background: var(--starLine); border-color: var(--starLine); }

/* 練習 */
.q-card { text-align: center; }
.q-meh { width: 120px; margin: 0 auto; }
.q-meh svg, .q-meh img { width: 100%; height: auto; display: block; }
.q-task { font-size: 22px; font-weight: 700; margin: 6px 0 12px; }
.q-prompt { font-size: 34px; font-weight: 700; margin: 8px 0; letter-spacing: .02em; word-break: break-word; }
.q-prompt .blank { display: inline-block; min-width: .9em; border-bottom: 4px solid var(--starLine); margin: 0 3px; color: var(--ink); }
.steps { display: flex; justify-content: center; gap: 8px; margin: 6px 0 10px; }
.step { padding: 4px 12px; border-radius: 999px; background: var(--bg); font-weight: 700; font-size: 15px; }
.step.now { background: var(--star); }
.step.done { background: var(--mint); }
.bigrow { display: flex; justify-content: center; align-items: flex-end; gap: 18px; margin: 10px 0; flex-wrap: wrap; }
.curword .blank { border-bottom-color: var(--ink); }
.roundbtn { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; border: 4px solid; }
.roundbtn svg { width: 44px; height: 44px; }
.roundbtn.speak { background: var(--mint); border-color: #8FD6BD; }
.roundbtn.mic { background: var(--pink); border-color: #F29A89; width: 120px; height: 120px; }
.roundbtn.mic svg { width: 56px; height: 56px; }
.roundbtn.mic.listening { animation: pulse 1s ease-in-out infinite; background: var(--star); border-color: var(--starLine); }
@keyframes pulse { 50% { transform: scale(1.08); } }
.roundlabel { text-align: center; font-weight: 700; margin-top: 4px; font-size: 16px; }
.heard { min-height: 30px; font-size: 20px; color: var(--ink2); margin: 6px 0; }
.heard.bad { color: #C95B4A; }
.tapswitch { background: none; text-decoration: underline; color: var(--ink2); font-size: 17px; padding: 8px; }

/* 點字母卡 */
.slotsline { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 10px 0 14px; }
.wordslots { display: flex; gap: 5px; }
.lslot { width: 44px; height: 54px; border-radius: 12px; background: var(--bg); border: 3px dashed var(--starLine); display: grid; place-items: center; font-size: 30px; font-weight: 700; }
.lslot.filled { background: #fff; border-style: solid; }
.lfixed { width: 26px; height: 54px; display: grid; place-items: center; font-size: 30px; font-weight: 700; }
.filled-in { color: #E08E3C; }
.wgap { display: inline-block; width: .7em; }
.likeicon { width: 64px; margin: 0 auto 6px; }
.likeicon svg { width: 100%; height: auto; display: block; }
.lslot.cur { border-color: var(--ink); }
.tiles { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.tile { width: 62px; height: 62px; border-radius: 16px; background: var(--star); border: 3px solid var(--starLine); font-size: 32px; font-weight: 700; }
.tile.used { visibility: hidden; }
.tile:active { transform: scale(.92); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.choice { background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 18px 10px; font-size: 26px; font-weight: 700; }
.choice.en { font-size: 22px; }
.choice:active { background: var(--face); }

/* 結果與解鎖 */
.overlay { position: fixed; inset: 0; background: rgba(255, 244, 214, .96); display: grid; place-items: center; z-index: 50; padding: 16px; }
.result { text-align: center; max-width: 520px; width: 100%; }
.result .meh { width: 210px; margin: 0 auto; }
.result .meh svg, .result .meh img { width: 100%; height: auto; }
.result h2 { font-size: 34px; }
.result .ans { font-size: 26px; font-weight: 700; margin: 8px 0; }
.result .lvmsg { display: inline-block; margin: 6px 0 14px; padding: 6px 16px; border-radius: 999px; background: var(--mint); font-weight: 700; font-size: 20px; }
.result .lvmsg.down { background: var(--face); }
.flystar { position: fixed; width: 54px; height: 54px; z-index: 80; pointer-events: none; }
.rain { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.rain svg { position: absolute; top: -60px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }
.unlock .sticker-big { width: 240px; height: 240px; margin: 8px auto; background: #fff; border: 4px solid var(--star); border-radius: 36px; display: grid; place-items: center; animation: pop .6s ease-out; }
.unlock .sticker-big img, .unlock .sticker-big svg { width: 90%; height: auto; max-height: 90%; }

/* 貼紙牆 */
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.stk { background: #fff; border: 3px solid var(--star); border-radius: 22px; padding: 8px; text-align: center; aspect-ratio: 1 / 1.1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.stk img, .stk svg { width: 100%; height: auto; max-height: 78%; object-fit: contain; }
.stk b { font-size: 15px; margin-top: 2px; }
.stk.locked { background: var(--face); border: 3px dashed var(--line); color: var(--ink2); font-weight: 700; }
.stk.locked .q { font-size: 44px; color: var(--starLine); }

/* 家長頁 */
.parent table { width: 100%; border-collapse: collapse; font-size: 16px; }
.parent th, .parent td { text-align: left; padding: 8px 6px; border-bottom: 2px solid var(--bg); }
.dist { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.dist div { border-radius: 18px; padding: 12px; text-align: center; }
.dist b { display: block; font-size: 32px; }
.distbar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: var(--bg); }
.parent section { margin-bottom: 14px; }
.syncline { font-size: 15px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.switch input { width: 26px; height: 26px; }

/* 家庭代碼 */
.family-box { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.family-box input { width: 100%; font: inherit; font-size: 24px; padding: 12px 16px; border-radius: 18px; border: 3px solid var(--line); background: #fff; color: var(--ink); text-align: center; margin: 12px 0; -webkit-user-select: text; user-select: text; }

@media (max-width: 520px) {
  .hero .meh { width: 120px; }
  .bubble { font-size: 17px; }
  .q-prompt { font-size: 26px; }
  .lslot { width: 36px; height: 46px; font-size: 24px; }
  .lfixed { width: 18px; height: 46px; font-size: 24px; }
  .tile { width: 54px; height: 54px; font-size: 28px; }
  .dist { grid-template-columns: repeat(2, 1fr); }
  .slots { grid-template-columns: repeat(5, 1fr); max-width: 320px; margin: 0 auto; }
  .wordlist { grid-template-columns: repeat(2, 1fr); }
}
