:root {
  --bg: #f4f8ff;
  --card: #ffffff;
  --ink: #2b3550;
  --muted: #6b7591;
  --line: #dfe6f3;
  --primary: #ff8a3d;
  --primary-ink: #ffffff;
  --accent: #4aa3ff;
  --good: #2bb673;
  --bad: #ff5a5f;
  --gold: #f5b400;
  --radius: 18px;
  --f0: #ff9aa2; --f1: #ffc48a; --f2: #ffe680; --f3: #a8e6a1;
  --f4: #8fd8f0; --f5: #b7b4ff; --f6: #e3a8f0; --f7: #ffb3d1; --f8: #d6dbe6;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 18px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
kbd { display: inline-block; padding: 1px 7px; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px; background: #fff; font-size: .85em; }
.hidden { display: none !important; }
.small { font-size: 15px; color: var(--muted); }

#app { min-height: 100vh; }
.bg-sky { background: linear-gradient(#bfe6ff, #f4f8ff 70%); }

/* 頂部 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 18px; background: #fff; border-bottom: 2px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 22px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 16px; white-space: nowrap; }
button.chip:hover { border-color: var(--accent); }
.chip.gold { background: #fff6d6; border-color: #f7dc7a; font-weight: 700; }
.progress { flex: 1; min-width: 160px; max-width: 420px; height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width .2s; }

/* 共用 */
.center-page { max-width: 760px; margin: 0 auto; padding: 32px 16px; text-align: center; }
.logo { font-size: 44px; margin: 10px 0 0; }
.sub { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 4px 0 var(--line); padding: 20px; border: 2px solid var(--line); }
.btn { border: none; border-radius: 14px; padding: 12px 22px; font-size: 18px; font-weight: 700; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: #eef3fb; }
.btn.danger { background: #ffe4e4; color: #c62828; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.row.left { justify-content: flex-start; }
.link-btn { margin-top: 28px; background: none; border: none; color: var(--muted); text-decoration: underline; }
.note { background: #fff8e1; border: 2px solid #ffe08a; border-radius: 14px; padding: 10px 14px; margin: 0 0 12px; }
.note.small { background: none; border: none; }
.toggle { display: inline-flex; align-items: center; gap: 8px; margin: 4px 16px 12px 0; font-size: 16px; }
.toggle input { width: 20px; height: 20px; }

.form { text-align: left; display: grid; gap: 14px; }
.form label, .form .label { display: grid; gap: 6px; font-weight: 700; }
.form input, .form select, .form textarea { border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; font-weight: 400; background: #fff; }
.form.inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-top: 12px; }
.form.inline label { font-size: 15px; }
.form.inline label.toggle { display: inline-flex; font-weight: 400; }

/* 選孩子 */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-top: 24px; }
.profile-card { background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 18px 10px; display: grid; justify-items: center; gap: 4px; box-shadow: 0 4px 0 var(--line); }
.profile-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.profile-card small { color: var(--muted); }
.profile-card.add { border-style: dashed; color: var(--muted); }
.plus { font-size: 54px; line-height: 70px; }
.pet-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pet-opt { border: 3px solid var(--line); background: #fff; border-radius: 14px; padding: 8px 4px; display: grid; justify-items: center; font-size: 15px; }
.pet-opt span { font-size: 40px; }
.pet-opt.on { border-color: var(--primary); background: #fff2e8; }

/* 寵物 */
.pet { position: relative; width: var(--s); height: var(--s); display: inline-grid; place-items: center; margin: 0 auto; }
.pet-body { font-size: var(--s); line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.pet-hat { position: absolute; top: calc(var(--s) * -0.32); left: 50%; transform: translateX(-50%); font-size: calc(var(--s) * .45); z-index: 2; animation: bob 2.4s ease-in-out infinite; }
.pet-face { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); font-size: calc(var(--s) * .38); z-index: 2; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }

/* 家 */
.home { max-width: 1100px; margin: 0 auto; padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.room { position: relative; border-radius: var(--radius); min-height: 330px; display: grid; place-items: center; padding: 70px 20px 20px; overflow: hidden; border: 3px solid #fff; box-shadow: 0 4px 0 var(--line); }
.deco { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 34px; letter-spacing: 40px; text-align: center; opacity: .9; }
.bubble { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 88%; background: #fff; border-radius: 16px; padding: 8px 14px; font-size: 17px; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.bubble::after { content: ""; position: absolute; bottom: -10px; left: 50%; border: 6px solid transparent; border-top: 6px solid #fff; transform: translateX(-50%); }
.pet-btn { background: none; border: none; position: relative; padding: 0; }
.pet-btn.hop .pet { animation: hop .5s; }
@keyframes hop { 30% { transform: translateY(-30px) scale(1.05); } 60% { transform: translateY(0) scale(.97); } }
.heart { position: absolute; top: 0; left: 60%; font-size: 30px; animation: rise .9s forwards; pointer-events: none; }
@keyframes rise { to { transform: translateY(-60px); opacity: 0; } }
.pet-name { background: rgba(255,255,255,.85); border-radius: 999px; padding: 4px 16px; font-weight: 700; z-index: 1; margin-bottom: 30px; }
.pet-name small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.status { display: grid; gap: 12px; align-content: start; }
.bar { display: grid; gap: 4px; font-size: 16px; }
.bar-track { height: 16px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .4s; }
.b-food .bar-fill { background: #ff9f43; }
.b-mood .bar-fill { background: #ff6b9a; }
.b-grow .bar-fill { background: #2bb673; }
.warn { color: #c62828; margin: 0; }
.cats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cat-tile { background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: left; display: grid; grid-template-columns: 56px 1fr; grid-template-rows: auto auto auto; column-gap: 12px; box-shadow: 0 4px 0 var(--line); }
.cat-tile:hover { border-color: var(--primary); transform: translateY(-2px); }
.cat-icon { grid-row: 1 / 4; font-size: 40px; width: 56px; height: 56px; display: grid; place-items: center; background: #f0f6ff; border-radius: 14px; font-weight: 700; color: #3867d6; }
.cat-tile b { font-size: 20px; }
.cat-tile small { color: var(--muted); font-size: 14px; }
.cat-stars { font-size: 14px; color: #b07d00; margin-top: 4px; }

/* 課程列表 */
.lessons, .badges, .parent, .shop { max-width: 1000px; margin: 0 auto; padding: 18px; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.lesson { position: relative; background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 18px 14px 12px; display: grid; gap: 4px; justify-items: center; text-align: center; box-shadow: 0 4px 0 var(--line); }
.lesson:hover { border-color: var(--accent); }
.lesson.rec { border-color: var(--primary); background: #fff7f0; }
.lesson .tag { position: absolute; top: -12px; background: var(--primary); color: #fff; font-size: 13px; padding: 2px 10px; border-radius: 999px; }
.lesson .num { width: 36px; height: 36px; border-radius: 50%; background: #eaf2ff; display: grid; place-items: center; font-weight: 700; color: #3867d6; }
.lesson small { color: var(--muted); font-size: 13px; }
.stars i { font-style: normal; font-size: 22px; color: #dde2ec; }
.stars i.on { color: var(--gold); }

/* 練習 */
.practice-page { background: #f7faff; }
.practice { max-width: 1000px; margin: 0 auto; padding: 14px 18px 24px; display: grid; gap: 14px; justify-items: center; }
.tip { margin: 0; color: var(--muted); text-align: center; }
.stage { width: 100%; min-height: 190px; display: grid; place-items: center; background: #fff; border-radius: var(--radius); border: 3px solid var(--line); padding: 20px; }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.drill { display: flex; gap: 8px; flex-wrap: nowrap; justify-content: center; align-items: center; }
.dk { min-width: 54px; height: 64px; padding: 0 6px; display: grid; place-items: center; font-size: 34px; font-weight: 700; border-radius: 12px; background: #f1f4fa; color: #8a93ab; font-family: ui-monospace, "Noto Sans TC", monospace; }
.dk.sp { font-size: 16px; }
.dk.done { background: #e3f7ec; color: var(--good); }
.dk.now { background: var(--primary); color: #fff; transform: scale(1.35); margin: 0 14px; box-shadow: 0 6px 0 #d96a22; }
.word-card, .sent-card { text-align: center; }
.emoji { font-size: 90px; line-height: 1.1; }
.word { font-size: 64px; font-weight: 700; letter-spacing: 4px; font-family: ui-monospace, "Noto Sans TC", monospace; }
.word span, .sent span { color: #b3bbcc; }
.word span.done, .sent span.done { color: var(--good); }
.word span.now, .sent span.now { color: var(--ink); border-bottom: 5px solid var(--primary); }
.sent { font-size: 40px; font-weight: 700; line-height: 1.6; font-family: ui-monospace, "Noto Sans TC", monospace; }
.sent span.space.now { background: #ffe2cc; border-radius: 4px; }
.next-up { color: var(--muted); font-size: 18px; margin-top: 8px; min-height: 1.2em; }
.zy-card { display: flex; gap: 26px; justify-content: center; }
.zy-char { display: grid; justify-items: center; gap: 6px; padding: 10px 14px; border-radius: 16px; border: 3px solid transparent; }
.zy-char.now { border-color: var(--primary); background: #fff7f0; }
.zy-char.done .han { color: var(--good); }
.han { font-size: 72px; font-weight: 700; }
.zy-syms { display: flex; gap: 4px; font-size: 32px; }
.zy-syms span { color: #b3bbcc; min-width: 30px; text-align: center; }
.zy-syms span.done { color: var(--good); }
.zy-syms span.now { color: #fff; background: var(--primary); border-radius: 8px; }
.finger { min-height: 1.4em; font-size: 18px; }
.fc { padding: 1px 8px; border-radius: 8px; }
.fc.f0 { background: var(--f0); } .fc.f1 { background: var(--f1); } .fc.f2 { background: var(--f2); } .fc.f3 { background: var(--f3); }
.fc.f4 { background: var(--f4); } .fc.f5 { background: var(--f5); } .fc.f6 { background: var(--f6); } .fc.f7 { background: var(--f7); } .fc.f8 { background: var(--f8); }
.ime-warn { background: #ffe9e9; color: #b71c1c; border-radius: 12px; padding: 8px 14px; }

/* 螢幕鍵盤 */
.kb { display: grid; gap: 6px; padding: 12px; background: #e9eef7; border-radius: 16px; user-select: none; }
.kb-row { display: flex; gap: 6px; justify-content: center; }
.kb-row:nth-child(2) { padding-left: 28px; }
.kb-row:nth-child(3) { padding-left: 46px; }
.key { width: 52px; height: 52px; border-radius: 10px; display: grid; place-items: center; position: relative; font-weight: 700; font-size: 18px; box-shadow: 0 3px 0 rgba(0,0,0,.15); opacity: .55; transition: opacity .1s, transform .1s; }
.key.f0 { background: var(--f0); } .key.f1 { background: var(--f1); } .key.f2 { background: var(--f2); } .key.f3 { background: var(--f3); }
.key.f4 { background: var(--f4); } .key.f5 { background: var(--f5); } .key.f6 { background: var(--f6); } .key.f7 { background: var(--f7); } .key.f8 { background: var(--f8); }
.key.k-ShiftLeft, .key.k-ShiftRight { width: 84px; font-size: 14px; }
.key.k-Space { width: 340px; font-size: 15px; }
.key.homekey::after { content: ""; position: absolute; bottom: 7px; width: 12px; height: 3px; border-radius: 2px; background: rgba(0,0,0,.45); }
.key .zy-s { position: absolute; right: 4px; bottom: 2px; font-size: 11px; font-weight: 400; opacity: .7; }
.kb-zy .key .zy { font-size: 22px; }
.kb-zy .key .en { position: absolute; left: 4px; top: 1px; font-size: 11px; font-weight: 400; opacity: .7; }
.key.next { opacity: 1; outline: 4px solid var(--ink); transform: scale(1.12); z-index: 1; animation: pulse 1s infinite; }
.key.shift-next { opacity: 1; outline: 3px dashed var(--ink); }
.key.hit { animation: hit .25s; }
.key.wrong { animation: wrongk .35s; }
@keyframes pulse { 50% { outline-color: var(--primary); } }
@keyframes hit { 50% { background: var(--good); transform: scale(.92); } }
@keyframes wrongk { 0%, 60% { background: var(--bad); opacity: 1; } }

/* 中文 */
.stage.zh { min-height: 150px; }
.zh-target { font-size: 44px; line-height: 2; text-align: center; letter-spacing: 2px; }
.zh-target span, .zh-target ruby { color: #b3bbcc; }
.zh-target .done { color: var(--good); }
.zh-target .wrong { color: #fff; background: var(--bad); border-radius: 6px; }
.zh-target .now { color: var(--ink); border-bottom: 5px solid var(--primary); }
.zh-target .skip:not(.done) { color: #cfd5e2; }
.zh-target rt { font-size: 15px; color: var(--muted); letter-spacing: 0; }
.zh-input { width: 100%; max-width: 760px; font-size: 34px; padding: 14px 18px; border-radius: 16px; border: 3px solid var(--accent); resize: none; text-align: center; background: #fff; }
.zh-input:focus { outline: 4px solid #cfe6ff; }

/* 結果 */
.result h1 { font-size: 28px; margin-top: 0; }
.big-stars i { font-style: normal; font-size: 64px; color: #dde2ec; display: inline-block; }
.big-stars i.on { color: var(--gold); animation: pop .5s backwards; }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0 8px; }
.stats-row div { background: #f4f7fd; border-radius: 14px; padding: 10px; display: grid; }
.stats-row b { font-size: 32px; }
.stats-row small { color: var(--muted); font-size: 14px; }
.gold { color: #c99300; }
.hl { margin: 6px 0; font-weight: 700; color: #3867d6; }
.new-badges { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }

/* 商店 */
.shop-pet { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center; margin-bottom: 16px; padding-top: 40px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 3px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 18px; }
.tab.on { border-color: var(--primary); background: #fff2e8; font-weight: 700; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.shop-item { background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 14px 10px; display: grid; justify-items: center; gap: 4px; box-shadow: 0 4px 0 var(--line); }
.shop-item:hover { border-color: var(--primary); }
.shop-item.equipped { border-color: var(--good); background: #ecfbf3; }
.shop-item.poor { opacity: .6; }
.si { font-size: 52px; }
.shop-item small { color: var(--muted); font-size: 14px; min-height: 1.2em; }
.price { font-weight: 700; color: #b07d00; font-size: 15px; }

/* 徽章 */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.badge { background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; justify-items: center; text-align: center; gap: 4px; filter: grayscale(1); opacity: .5; }
.badge.on { filter: none; opacity: 1; border-color: #f7dc7a; background: #fffbea; }
.badge i { font-style: normal; font-size: 44px; font-weight: 700; color: #3867d6; }
.badge small { color: var(--muted); font-size: 14px; }
.new-badges .badge { padding: 8px 12px; display: inline-grid; }

/* 家長區 */
.parent { display: grid; gap: 18px; }
.parent h3 { margin-top: 0; }
.kid { border-top: 2px solid var(--line); padding: 10px 0; }
.kid summary { cursor: pointer; font-size: 17px; }
.kid-stats { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 10px 0; font-size: 15px; }
.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist th, .hist td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.custom-list { padding-left: 18px; }
.custom-list li { margin: 6px 0; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 30px); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; opacity: 0; transition: .3s; z-index: 99; font-size: 17px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 800px) {
  .home { grid-template-columns: 1fr; }
  .key { width: 36px; height: 40px; font-size: 14px; }
  .key.k-Space { width: 220px; }
  .key.k-ShiftLeft, .key.k-ShiftRight { width: 56px; }
  .kb-row:nth-child(2) { padding-left: 16px; }
  .kb-row:nth-child(3) { padding-left: 26px; }
  .dk { min-width: 40px; height: 50px; font-size: 26px; }
  .word { font-size: 44px; }
  .sent { font-size: 26px; }
  .zh-target { font-size: 32px; }
}
