:root {
  --ink: #3b2a5a;
  --ink-soft: #7a6a99;
  --card: #ffffff;
  --ok: #4cd07d;
  --bad: #ff6b6b;
  --accent: #8b5cf6;
  --shadow: 0 8px 0 rgba(59, 42, 90, .15);
  --font: 'Baloo 2', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: #cdeeff linear-gradient(180deg, #bfe8ff 0%, #e8f7ff 45%, #fff4d9 100%) fixed;
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.icon-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: #fff; font-size: 30px;
  box-shadow: var(--shadow);
  transition: transform .1s;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(59,42,90,.15); }
.stars {
  background: #fff; border-radius: 40px; padding: 6px 22px;
  font-size: 30px; font-weight: 800; box-shadow: var(--shadow);
}
.stars.bump { animation: pop .4s; }

/* ---------- screens ---------- */
#app {
  max-width: 1000px; margin: 0 auto; padding: 0 16px 140px;
  text-align: center;
}
.title {
  font-size: clamp(3rem, 10vw, 5.5rem); margin: 0; line-height: 1;
  letter-spacing: 2px;
}
.title span { display: inline-block; animation: float 2.4s ease-in-out infinite; }
.subtitle { font-size: 1.6rem; margin: 6px 0 22px; color: var(--ink-soft); font-weight: 700; }

.menu {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.menu-btn {
  background: var(--c); border-radius: 30px; padding: 18px 10px 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 1.45rem; font-weight: 800; line-height: 1.1;
  transition: transform .1s;
  animation: popIn .5s backwards;
}
.menu-btn .mi { font-size: 3.6rem; line-height: 1.2; }
.menu-btn:hover .mi { animation: wiggle .5s; }
.menu-btn:active { transform: translateY(4px) scale(.98); }
.voice-note {
  margin-top: 24px; font-size: 1rem; color: var(--ink-soft);
  background: #fff8; border-radius: 16px; padding: 10px 14px;
}

.prompt {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font-size: clamp(1.5rem, 5vw, 2.3rem); font-weight: 800; margin: 6px 0 18px;
  min-height: 70px;
}
.prompt .hint { color: var(--accent); font-size: 1.3em; }
.speak-btn {
  width: 64px; height: 64px; border-radius: 50%; font-size: 30px; flex: none;
  background: #ffd166; box-shadow: var(--shadow);
}
.speak-btn:active { transform: translateY(4px); }

.progress { display: flex; justify-content: center; gap: 10px; margin: 4px 0 6px; }
.progress i {
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: inset 0 0 0 3px #d9cff0; font-style: normal; font-size: 18px; line-height: 26px;
}
.progress i.on { background: #ffd166; box-shadow: none; animation: pop .4s; }

/* ---------- cards / learning ---------- */
.learn { display: flex; align-items: center; justify-content: center; gap: 12px; }
.nav {
  width: 72px; height: 72px; border-radius: 50%; flex: none;
  background: #fff; font-size: 30px; box-shadow: var(--shadow);
}
.nav:active { transform: translateY(4px); }
.big-card {
  background: var(--card); border-radius: 40px; box-shadow: var(--shadow);
  padding: 18px 20px 22px; width: min(520px, 100%); cursor: pointer;
}
.letter-pair { display: flex; align-items: baseline; justify-content: center; gap: 18px; line-height: 1; }
.letter-pair .L { font-size: clamp(6rem, 24vw, 11rem); font-weight: 800; }
.letter-pair .l { font-size: clamp(4rem, 15vw, 7rem); font-weight: 700; color: var(--ink-soft); }
.pic { font-size: clamp(4rem, 15vw, 7.5rem); line-height: 1.15; display: inline-block; }
.big-card .pic { animation: float 2.6s ease-in-out infinite; }
.word { font-size: clamp(2rem, 7vw, 3.2rem); font-weight: 800; letter-spacing: 4px; }
.word b { color: var(--hl, #ff4d8d); font-size: 1.2em; }

.strip {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin-top: 22px;
}
.strip button {
  width: 50px; height: 50px; border-radius: 14px; background: #fff; font-size: 1.6rem; font-weight: 800;
  box-shadow: 0 4px 0 rgba(59,42,90,.12);
}
.strip button.cur { background: var(--accent); color: #fff; transform: scale(1.12); }

.count-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 90px; margin: 6px 0; }
.count-row button {
  font-size: clamp(2.6rem, 9vw, 4rem); background: none; padding: 2px 4px; line-height: 1.1;
  transition: transform .15s, filter .2s;
  position: relative;
}
.count-row button.counted { filter: drop-shadow(0 0 10px #ffd166); transform: scale(1.12); }
.count-row button[data-n]::after {
  content: attr(data-n); position: absolute; top: -6px; right: -4px;
  background: var(--accent); color: #fff; border-radius: 50%; width: 30px; height: 30px;
  font-size: 18px; line-height: 30px; font-weight: 800;
}
.empty-basket { font-size: 1.6rem; color: var(--ink-soft); font-weight: 700; }

/* ---------- options (quiz) ---------- */
.options { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.opt {
  width: clamp(120px, 27vw, 190px); aspect-ratio: 1; border-radius: 36px;
  background: #fff; box-shadow: var(--shadow);
  font-size: clamp(4.5rem, 15vw, 7.5rem); font-weight: 800; line-height: 1;
  color: var(--c, var(--ink));
  transition: transform .12s, background .2s;
  animation: popIn .4s backwards;
}
.opt:active { transform: translateY(4px) scale(.97); }
.opt.correct { background: var(--ok); color: #fff; animation: pop .5s; }
.opt.dim { opacity: .35; }

/* ---------- matching ---------- */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 28px; max-width: 640px; margin: 0 auto; }
.match .col { display: flex; flex-direction: column; gap: 16px; }
.tile {
  min-height: 120px; border-radius: 30px; background: #fff; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px;
  font-size: clamp(3.5rem, 12vw, 5.5rem); font-weight: 800; line-height: 1;
  transition: transform .12s, background .2s, box-shadow .2s;
  animation: popIn .4s backwards;
}
.tile .pic { font-size: inherit; }
.tile.group { font-size: clamp(2rem, 6vw, 3rem); gap: 2px; align-content: center; }
.tile.sel { box-shadow: 0 0 0 6px var(--accent), var(--shadow); transform: scale(1.04); }
.tile.done { background: var(--pc); color: #fff; animation: pop .45s; cursor: default; }

/* ---------- words ---------- */
.word-pic { font-size: clamp(5rem, 18vw, 8rem); line-height: 1.1; animation: float 2.6s ease-in-out infinite; display: inline-block; }
.slots { display: flex; justify-content: center; gap: 12px; margin: 14px 0 26px; flex-wrap: wrap; }
.slot {
  width: clamp(70px, 18vw, 110px); aspect-ratio: 1; border-radius: 24px;
  border: 5px dashed #c9bdf0; background: #ffffff99;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(3rem, 10vw, 5rem); font-weight: 800; color: #ddd3f5;
}
.slot.next { border-color: var(--accent); animation: pulse 1.2s infinite; }
.slot.filled { border-style: solid; border-color: var(--ok); background: #fff; color: var(--ink); animation: pop .4s; }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.ltile {
  width: clamp(76px, 18vw, 104px); aspect-ratio: 1; border-radius: 24px;
  background: var(--c); color: #fff; box-shadow: var(--shadow);
  font-size: clamp(2.8rem, 9vw, 4rem); font-weight: 800; text-shadow: 0 3px 0 rgba(0,0,0,.15);
  animation: popIn .4s backwards;
}
.ltile:active { transform: translateY(4px); }
.ltile.used { visibility: hidden; }

/* ---------- trace ---------- */
.trace-wrap { display: flex; align-items: center; justify-content: center; gap: 12px; }
.trace-box {
  position: relative; width: min(64vw, 50vh, 460px); aspect-ratio: 1;
  background: #fff; border-radius: 36px; box-shadow: var(--shadow); overflow: hidden;
}
.trace-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.trace-box #draw { touch-action: none; cursor: crosshair; }
.trace-box.win { box-shadow: 0 0 0 8px var(--ok), var(--shadow); }
.seg { display: inline-flex; background: #fff; border-radius: 30px; padding: 5px; box-shadow: var(--shadow); margin-bottom: 10px; }
.seg button { padding: 6px 22px; border-radius: 24px; font-size: 1.4rem; font-weight: 800; background: none; }
.seg button.cur { background: var(--accent); color: #fff; }

/* ---------- generic ---------- */
.row { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.big-btn {
  background: #fff; border-radius: 30px; padding: 12px 28px; font-size: 1.6rem; font-weight: 800;
  box-shadow: var(--shadow);
}
.big-btn.ok { background: var(--ok); color: #fff; }
.big-btn.go { background: var(--accent); color: #fff; animation: pulse 1.2s infinite; }
.big-btn:active { transform: translateY(4px); }

.finish .trophy { font-size: 9rem; animation: bounceIn .8s; }
.finish h2 { font-size: clamp(2.4rem, 8vw, 4rem); margin: 0; }

/* album */
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 14px; }
.sticker {
  aspect-ratio: 1; border-radius: 26px; background: #fff; box-shadow: var(--shadow);
  font-size: 3.4rem; display: flex; align-items: center; justify-content: center;
}
.sticker.locked { background: #ffffff77; color: #cbbfe6; font-size: 2.4rem; box-shadow: inset 0 0 0 4px #ffffffaa; }
.sticker.bounce { animation: wiggle .6s; }
.meter { max-width: 420px; margin: 0 auto 22px; }
.meter .bar { height: 30px; background: #fff; border-radius: 20px; overflow: hidden; box-shadow: inset 0 0 0 3px #e2d9f5; }
.meter .fill { height: 100%; background: linear-gradient(90deg, #ffd166, #ff9f43); border-radius: 20px; transition: width .6s; }
.meter p { font-size: 1.3rem; font-weight: 700; margin: 6px 0; }
.reset { margin-top: 40px; background: none; color: var(--ink-soft); font-size: .95rem; text-decoration: underline; }

/* mascot */
#mascot {
  position: fixed; left: 14px; bottom: 10px; z-index: 20;
  display: flex; align-items: flex-end; gap: 6px; pointer-events: none;
}
#mascot .owl { font-size: 70px; line-height: 1; order: -1; animation: float 3s ease-in-out infinite; }
#bubble {
  background: #fff; border-radius: 22px 22px 22px 4px; padding: 10px 18px;
  font-size: 1.4rem; font-weight: 800; box-shadow: var(--shadow);
  max-width: min(70vw, 420px); margin-bottom: 50px;
  opacity: 0; transform: scale(.6); transform-origin: bottom left; transition: opacity .2s, transform .25s;
}
#bubble.show { opacity: 1; transform: scale(1); }
#mascot.happy .owl { animation: hop .5s 2; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

.fly-star {
  position: fixed; z-index: 40; font-size: 48px; pointer-events: none;
  transition: transform .8s cubic-bezier(.5,-.3,.6,1), opacity .8s;
}

#modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(59, 42, 90, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#modal[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: 40px; padding: 26px 36px; text-align: center; box-shadow: var(--shadow);
  animation: bounceIn .6s;
}
.modal-card .big { font-size: 9rem; line-height: 1.1; animation: spinIn 1s; }
.modal-card h2 { font-size: 2.4rem; margin: 0 0 10px; }

/* anims */
.shake { animation: shake .45s; }
.pop { animation: pop .4s; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes popIn { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bounceIn { 0% { transform: scale(.2); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes spinIn { from { transform: rotate(-360deg) scale(.2); } to { transform: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-14px) rotate(-4deg); } 40% { transform: translateX(12px) rotate(3deg); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-14deg) scale(1.1); } 75% { transform: rotate(14deg) scale(1.1); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes hop { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-24px) rotate(-8deg); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media (max-width: 560px) {
  .nav { width: 54px; height: 54px; font-size: 24px; }
  .learn, .trace-wrap { gap: 6px; }
  #mascot .owl { font-size: 54px; }
  .match { gap: 14px; }
  .tile { min-height: 100px; }
}
