:root {
  --bg: #f7f2e8;
  --card: #fffdf8;
  --text: #3d4a52;
  --muted: #8a949a;
  --accent: #6aa8a0;
  --accent-dark: #4f8f87;
  --warm: #f2c38a;
  --soft-red: #e9a3a0;
  --green: #8cc49a;
  --blank: #fff4e0;
  --line-top: #9fc3e6;
  --line-mid: #c9b6e4;
  --line-base: #e7a8a8;
  --ghost: #e3dfd6;
  --ink: #4f8f87;
  --ink-soft: rgba(79, 143, 135, .35);
  --start: #5cb26a;
  --demo: #f0a35c;
  --radius: 24px;
  --shadow: 0 4px 0 rgba(0, 0, 0, .07), 0 8px 20px rgba(0, 0, 0, .06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
button:disabled { cursor: default; }
.en { font-family: "Segoe UI", system-ui, sans-serif; }
#app { max-width: 1100px; margin: 0 auto; min-height: 100%; }
.screen { min-height: 100vh; display: flex; flex-direction: column; padding: 0 16px 24px; }

/* top bar */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0; }
.bar-side { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.bar-side.music { justify-content: flex-end; }
.bar-title { font-size: 22px; font-weight: 700; text-align: center; flex: 1; }
.icon-btn { width: 56px; height: 56px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); font-size: 26px; }
.icon-btn:active { transform: translateY(2px); }
.vol-level { min-width: 60px; text-align: center; font-size: 14px; color: var(--accent-dark); letter-spacing: 2px; }
.gear { opacity: .55; width: 44px; height: 44px; font-size: 20px; }
.gear.holding { animation: hold 2s linear forwards; }
@keyframes hold { to { box-shadow: inset 0 0 0 22px var(--warm); } }

/* splash + pet */
.splash { align-items: center; justify-content: center; }
.splash .start { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.splash .play { width: 140px; height: 140px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 64px;
  display: grid; place-items: center; box-shadow: var(--shadow); animation: pulse 1.6s ease-in-out infinite; }
.pet { display: flex; flex-direction: column; align-items: center; }
.pet .cat { font-size: 110px; line-height: 1; cursor: pointer; }
.pet.happy .cat { animation: bounce .9s ease-in-out 3; }
.pet .gifts { font-size: 34px; min-height: 40px; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.hero { display: flex; flex-direction: column; align-items: center; padding: 4px 0 8px; }
.stars-total { font-size: 26px; font-weight: 700; background: var(--card); padding: 6px 20px; border-radius: 99px; box-shadow: var(--shadow); }

/* home: units + lesson tiles */
.unit { background: rgba(255, 255, 255, .5); border-radius: var(--radius); padding: 14px; margin-top: 16px; }
.unit h2 { margin: 0; font-size: 22px; }
.unit h2 .en { font-size: 16px; color: var(--muted); font-weight: 400; }
.unit .pages { color: var(--muted); font-size: 15px; margin: 2px 0 10px; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.lesson-tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 8px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; min-height: 160px; }
.lesson-tile .lt-icon { font-size: 44px; }
.lesson-tile .lt-title { font-weight: 700; font-size: 19px; }
.lesson-tile .lt-sub { color: var(--accent-dark); font-size: 15px; }
.lesson-tile .lt-pages { color: var(--muted); font-size: 14px; }
.lesson-tile .lt-stars { font-size: 13px; min-height: 18px; }
.lesson-tile.locked { opacity: .5; }
.lesson-tile.done { background: #eef6ef; }
.lesson-tile.review { border: 3px dashed var(--warm); }
.next { outline: 4px solid var(--warm); animation: glow 1.6s ease-in-out infinite; }

/* lesson screen */
.lesson-words { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 4px 0 14px; }
.lesson-words span { background: var(--card); padding: 6px 12px; border-radius: 99px; font-size: 18px; box-shadow: var(--shadow); }
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.game-tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 10px; min-height: 190px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.game-tile .gt-icon { font-size: 70px; }
.game-tile .gt-name { font-size: 19px; font-weight: 700; }
.game-tile .gt-stars { font-size: 22px; color: var(--warm); }
.game-tile.locked { opacity: .45; }

/* game common */
.progress { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.progress span { width: 18px; height: 18px; border-radius: 50%; background: var(--ghost); }
.progress span.on { background: var(--accent); }
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pic { font-size: 120px; line-height: 1.1; cursor: pointer; white-space: nowrap; }
.pic.small { font-size: 64px; }
.hear-big { position: relative; background: var(--card); border-radius: 32px; padding: 12px 28px; box-shadow: var(--shadow); }
.hear-big .spk { position: absolute; bottom: 6px; right: 8px; font-size: 30px; }
.word-wrap { display: flex; justify-content: center; color: var(--text); }
.word-svg { height: 140px; max-width: 100%; }

.btn { background: var(--accent); color: #fff; font-size: 30px; border-radius: 22px; padding: 14px 30px; box-shadow: var(--shadow); min-width: 96px; min-height: 76px; }
.btn.soft { background: var(--soft-red); font-size: 18px; min-height: 56px; }
.btn:disabled { opacity: .4; }
.btn:active { transform: translateY(2px); }
.row { display: flex; align-items: center; justify-content: center; }
.row.gap { gap: 14px; margin-top: 14px; }

/* g1 card */
.card { background: var(--card); border-radius: 32px; box-shadow: var(--shadow); padding: 18px 28px 22px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; width: min(560px, 100%); position: relative; }
.card .word-svg { height: 170px; }
.card .next-btn { margin-top: 10px; }
.tag-old { position: absolute; top: 12px; left: 16px; font-size: 28px; }

/* g2 trace */
.trace-wrap { width: 100%; display: flex; flex-direction: column; align-items: center; flex: 1; }
.trace-head { display: flex; gap: 14px; align-items: center; }
canvas.trace { width: 100%; flex: 1; min-height: 320px; max-height: 520px; background: var(--card); border-radius: 28px; box-shadow: var(--shadow); touch-action: none; }
canvas.flash { animation: flash .5s; }

/* g3 choose */
.choose, .missing, .build { display: flex; flex-direction: column; align-items: center; gap: 18px; width: 100%; }
.choices { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.choice { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 6px 18px; min-width: 170px; border: 4px solid transparent; }
.choice .word-svg { height: 110px; }
.choice.right, .target.right, .slots.right { border-color: var(--green); background: #eef8f0; }
.choice.wrong, .tile.wrong { opacity: .35; }

/* g4 missing letter + g5 build */
.target { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 6px 22px; border: 4px solid transparent; }
.target .word-svg { height: 150px; }
.tiles { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.tile { background: #fff6e6; border-radius: 22px; box-shadow: var(--shadow); width: 110px; height: 120px; padding: 0; display: grid; place-items: center; }
.tile .word-svg { height: 100px; }
.tile.used { visibility: hidden; }
.slots { display: flex; gap: 10px; padding: 10px; border-radius: 26px; border: 4px solid transparent; }
.slot { width: 100px; height: 120px; border-radius: 18px; background: var(--card); box-shadow: inset 0 0 0 3px var(--ghost); display: grid; place-items: center; position: relative; }
.slot .word-svg { height: 100px; }
.slot .hint { opacity: .18; }
.slot.filled { box-shadow: inset 0 0 0 3px var(--green); }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(61, 74, 82, .35); display: grid; place-items: center; padding: 16px; z-index: 10; }
.panel { background: var(--card); border-radius: 32px; padding: 24px; box-shadow: var(--shadow); text-align: center; max-width: 520px; width: 100%; }
.big-stars { font-size: 64px; animation: pop .6s ease-out; }
.gift { font-size: 48px; margin-top: 6px; animation: pop .8s ease-out; }
.parent { text-align: left; font-size: 17px; }
.parent h2 { margin-top: 0; }
.parent input { width: 26px; height: 26px; margin-right: 10px; }
.parent label.row { justify-content: flex-start; margin: 14px 0; }

/* motion */
.shake { animation: shake .45s; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@keyframes pulse { 50% { transform: scale(1.07); } }
@keyframes bounce { 50% { transform: translateY(-18px) rotate(-6deg); } }
@keyframes glow { 50% { outline-color: rgba(242, 195, 138, .3); } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
@keyframes flash { 50% { box-shadow: 0 0 0 8px var(--start); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

@media (max-width: 640px) {
  .bar-side { min-width: 0; }
  .bar-title { font-size: 17px; }
  .vol-level { display: none; }
  .pic { font-size: 88px; }
  .word-svg { height: 100px; }
  .choice { min-width: 130px; }
  .choice .word-svg { height: 80px; }
  .tile { width: 84px; height: 96px; }
  .tile .word-svg, .slot .word-svg { height: 78px; }
  .slot { width: 76px; height: 96px; }
}
.bar-pages { display: inline-block; font-size: 15px; font-weight: 400; color: var(--muted); background: var(--card); padding: 2px 10px; border-radius: 99px; }
.vol-level b { font-size: 10px; letter-spacing: 1px; }
