:root {
  --ink: #2d2a4a;
  --ink-soft: #6b6890;
  --card: #ffffff;
  --sky-top: #bfe9ff;
  --sky-bottom: #fff6e5;
  --good: #3cc46b;
  --bad: #ff5a5a;
  --gold: #ffc531;
  --accent: #ff8a5b;
  --accent-soft: #ffe3d6;
  --radius: 28px;
  --shadow: 0 6px 0 rgba(45, 42, 74, 0.12), 0 14px 30px rgba(45, 42, 74, 0.10);
  font-family: "Baloo 2", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, #e3f6ff 40%, var(--sky-bottom) 100%) fixed;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; }

/* ---------- Bầu trời ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.cloud {
  position: absolute; background: #fff; border-radius: 100px; opacity: .85;
  width: 180px; height: 56px; animation: drift linear infinite;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; top: -40px; left: 28px; }
.cloud::after { width: 100px; height: 100px; top: -54px; left: 70px; }
.c1 { top: 12%; animation-duration: 70s; left: -200px; }
.c2 { top: 34%; animation-duration: 95s; animation-delay: -40s; transform: scale(.7); left: -200px; }
.c3 { top: 62%; animation-duration: 120s; animation-delay: -80s; transform: scale(.55); left: -200px; opacity: .6; }
@keyframes drift { from { translate: 0 0; } to { translate: calc(100vw + 400px) 0; } }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(16px, 4vw, 36px);
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(10px);
  border-bottom: 3px solid rgba(255, 255, 255, .9);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-size: 26px; font-weight: 700; margin-right: auto; }
.brand img { width: 46px; height: 46px; object-fit: contain; }
.brand-emoji { font-size: 38px; }
.brand b { color: #14b8a6; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px; border: none; font-size: 24px;
  background: #fff; box-shadow: 0 4px 0 #d9d6ea; transition: transform .1s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9d6ea; }
.star-pill {
  display: flex; align-items: center; gap: 6px; font-size: 24px; font-weight: 800;
  background: #fff8db; padding: 4px 16px 4px 10px; border-radius: 99px;
  box-shadow: inset 0 -3px 0 #ffe08a;
}
.star-pill.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.3) rotate(-6deg); } }

main {
  position: relative; z-index: 1;
  max-width: 1100px; margin: 0 auto;
  padding: 20px clamp(16px, 4vw, 36px) 60px;
}

/* ---------- Cati nói ---------- */
.hello { display: flex; align-items: flex-end; gap: 10px; margin: 6px 0 22px; }
.hello .owl { width: clamp(96px, 18vw, 150px); flex: none; animation: bob 3s ease-in-out infinite; }
.hello .owl.emoji { font-size: 90px; line-height: 1; text-align: center; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-2deg); } }
.bubble {
  position: relative; background: #fff; border-radius: 26px; padding: 14px 20px;
  font-size: clamp(18px, 2.6vw, 24px); font-weight: 600; box-shadow: var(--shadow); margin-bottom: 30px;
}
.bubble::before {
  content: ""; position: absolute; left: -12px; bottom: 18px; border: 12px solid transparent;
  border-right-color: #fff; border-left: 0;
}
.bubble small { display: block; font-size: .72em; color: var(--ink-soft); font-weight: 500; }

h1.title { font-size: clamp(30px, 5vw, 44px); margin: 0 0 4px; line-height: 1.1; }
p.sub { margin: 0 0 18px; color: var(--ink-soft); font-size: 19px; }

/* ---------- Lưới chủ đề ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.topic-card {
  position: relative; border: none; text-align: left; padding: 16px 18px 18px;
  border-radius: var(--radius); background: var(--card);
  box-shadow: 0 8px 0 var(--c), 0 16px 30px rgba(45, 42, 74, .12);
  transition: transform .15s, box-shadow .15s; overflow: hidden;
}
.topic-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 62%; background: var(--soft); border-radius: 0 0 50% 50% / 0 0 26px 26px; }
.topic-card:hover { transform: translateY(-4px) rotate(-.6deg); }
.topic-card:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--c), 0 6px 12px rgba(45, 42, 74, .1); }
.topic-card .pic { position: relative; height: 150px; display: grid; place-items: center; }
.topic-card .pic img { max-height: 150px; max-width: 100%; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0,0,0,.12)); }
.topic-card .pic .big-emoji { font-size: 96px; }
.topic-card h3 { position: relative; margin: 10px 0 0; font-size: 28px; line-height: 1; color: var(--c); }
.topic-card .vi { position: relative; font-size: 18px; color: var(--ink-soft); font-weight: 600; }
.topic-card .meter { position: relative; margin-top: 10px; height: 12px; border-radius: 99px; background: #f0eef8; overflow: hidden; }
.topic-card .meter i { display: block; height: 100%; background: var(--c); border-radius: 99px; }
.topic-card .stars { position: absolute; top: 12px; right: 14px; font-size: 20px; letter-spacing: -2px; z-index: 1; }

/* ---------- Trang chủ đề ---------- */
.topic-head { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.topic-head .pic { width: 110px; height: 110px; border-radius: 30px; background: var(--soft); display: grid; place-items: center; box-shadow: inset 0 -6px 0 rgba(0,0,0,.05); }
.topic-head .pic img { width: 92px; height: 92px; object-fit: contain; }
.topic-head .pic .big-emoji { font-size: 64px; }
.topic-head h1 { margin: 0; font-size: clamp(34px, 6vw, 50px); line-height: 1; color: var(--c); }
.topic-head .vi { font-size: 22px; color: var(--ink-soft); font-weight: 600; }

.act-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.act {
  display: flex; align-items: center; gap: 14px; text-align: left; border: none;
  padding: 18px; border-radius: 24px; background: #fff; box-shadow: 0 6px 0 var(--ac), 0 12px 24px rgba(45,42,74,.1);
  transition: transform .12s;
}
.act:hover { transform: translateY(-3px); }
.act:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ac); }
.act .ico { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; font-size: 36px; background: var(--acs); flex: none; }
.act b { display: block; font-size: 23px; line-height: 1.1; }
.act span { color: var(--ink-soft); font-size: 16px; font-weight: 500; line-height: 1.2; display: block; }
.act .best { font-size: 16px; margin-top: 2px; }

.word-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.chip {
  border: none; background: #fff; border-radius: 99px; padding: 6px 16px 6px 8px; font-size: 19px; font-weight: 700;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 3px 0 #e4e1f2;
}
.chip img { width: 34px; height: 34px; object-fit: contain; }
.chip .mini { width: 30px; height: 30px; display: grid; place-items: center; font-size: 22px; }
.chip.done { background: #e8fbef; box-shadow: 0 3px 0 #b8ecc9; }

/* ---------- Hình minh họa chung ---------- */
.vis { width: 100%; height: 100%; display: grid; place-items: center; }
.vis img { width: 100%; height: 100%; object-fit: contain; }
.vis .big-emoji { font-size: min(40vw, 180px); line-height: 1; }
.paint { width: 78%; aspect-ratio: 1; }
.paint path { stroke: rgba(0,0,0,.18); stroke-width: 3; }
.count-grid { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4%; width: 92%; height: 92%; }
.count-grid .it { width: 28%; aspect-ratio: 1; display: grid; place-items: center; animation: pop .4s backwards; }
.count-grid.n1 .it, .count-grid.n2 .it { width: 44%; }
.count-grid.n3 .it, .count-grid.n4 .it { width: 40%; }
.count-grid.many .it { width: 21%; }
.count-grid .it img { width: 100%; height: 100%; object-fit: contain; }
.count-grid .it .e { font-size: clamp(22px, 7vw, 60px); line-height: 1; }
@keyframes pop { from { transform: scale(0); } 70% { transform: scale(1.15); } }

/* ---------- Thẻ học từ ---------- */
.learn { display: grid; justify-items: center; gap: 16px; }
.progress-dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.progress-dots i { width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: inset 0 -2px 0 #ddd; }
.progress-dots i.on { background: var(--c); box-shadow: none; transform: scale(1.25); }
.progress-dots i.seen { background: var(--soft); }
.flash {
  width: min(92vw, 460px); background: #fff; border-radius: 36px; padding: 18px 18px 22px;
  box-shadow: 0 10px 0 var(--c), 0 24px 40px rgba(45,42,74,.15); text-align: center;
  animation: cardIn .45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes cardIn { from { transform: translateY(30px) scale(.9) rotate(-3deg); opacity: 0; } }
.flash .pic { aspect-ratio: 1; border-radius: 26px; background: var(--soft); overflow: hidden; cursor: pointer; display: grid; place-items: center; }
.flash .pic .vis { padding: 6%; }
.flash .pic:active .vis { transform: scale(.96); }
.flash .word { font-size: clamp(48px, 13vw, 76px); font-weight: 800; line-height: 1; margin-top: 14px; color: var(--c); letter-spacing: 1px; cursor: pointer; }
.flash .word .l { display: inline-block; }
.flash .word.spell .l { animation: hop .5s; }
@keyframes hop { 40% { transform: translateY(-14px) scale(1.15); color: var(--ink); } }
.flash .vi { font-size: 24px; color: var(--ink-soft); font-weight: 600; }
.flash .sent { margin-top: 6px; font-size: 19px; background: #f7f6fc; border-radius: 16px; padding: 6px 12px; display: inline-block; cursor: pointer; }
.flash .sent:hover { background: #efedf9; }

.btn-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 22px; padding: 12px 22px; font-size: 22px; font-weight: 800;
  background: #fff; box-shadow: 0 5px 0 #dcd9ec; display: inline-flex; align-items: center; gap: 8px; min-height: 60px;
  transition: transform .1s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #dcd9ec; }
.btn.primary { background: var(--c, var(--accent)); color: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.2); }
.btn.round { width: 72px; height: 72px; padding: 0; justify-content: center; border-radius: 50%; font-size: 32px; }
.btn.big { font-size: 26px; padding: 14px 30px; }
.btn:disabled { opacity: .4; }
.btn .s { font-size: 15px; font-weight: 600; display: block; }

/* ---------- Trò chơi ---------- */
.game-top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.game-top .bar { flex: 1; height: 18px; border-radius: 99px; background: #fff; overflow: hidden; box-shadow: inset 0 -3px 0 #eceaf6; }
.game-top .bar i { display: block; height: 100%; background: var(--c); border-radius: 99px; transition: width .4s; }
.game-top .hearts { font-size: 22px; font-weight: 800; }
.prompt { text-align: center; margin: 4px 0 16px; }
.prompt h2 { font-size: clamp(24px, 4.5vw, 34px); margin: 0; line-height: 1.15; }
.prompt .hint { color: var(--ink-soft); font-size: 18px; }
.speaker {
  width: 120px; height: 120px; border-radius: 50%; border: none; font-size: 56px; background: var(--c); color: #fff;
  box-shadow: 0 8px 0 rgba(0,0,0,.18); margin: 10px auto 4px; display: grid; place-items: center;
}
.speaker.talk { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 8px 0 rgba(0,0,0,.18), 0 0 0 16px rgba(255,255,255,.6); } }
.speaker:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.18); }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 620px; margin: 0 auto; }
@media (min-width: 760px) { .choices { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 920px; } }
.choice {
  border: none; background: #fff; border-radius: 28px; padding: 10px; aspect-ratio: 1;
  box-shadow: 0 6px 0 #dcd9ec, 0 12px 20px rgba(45,42,74,.08); position: relative; transition: transform .12s;
}
.choice .vis { border-radius: 20px; background: var(--soft); padding: 6%; }
.choice:hover { transform: translateY(-3px); }
.choice.right { box-shadow: 0 6px 0 var(--good), 0 0 0 6px var(--good); animation: yay .5s; }
.choice.wrong { box-shadow: 0 6px 0 var(--bad), 0 0 0 6px var(--bad); animation: shake .45s; opacity: .55; }
.choice .tag { position: absolute; left: 50%; bottom: 10px; translate: -50% 0; background: #fff; border-radius: 99px; padding: 0 12px; font-size: 20px; font-weight: 800; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
@keyframes shake { 20%, 60% { transform: translateX(-10px) rotate(-2deg); } 40%, 80% { transform: translateX(10px) rotate(2deg); } }
@keyframes yay { 50% { transform: scale(1.07) rotate(2deg); } }

.word-choices { display: grid; gap: 12px; max-width: 520px; margin: 0 auto; }
.word-choice { border: none; background: #fff; border-radius: 22px; padding: 14px; font-size: 32px; font-weight: 800; box-shadow: 0 6px 0 #dcd9ec; }
.word-choice.right { background: #e8fbef; box-shadow: 0 6px 0 var(--good); animation: yay .5s; }
.word-choice.wrong { background: #ffe8e8; box-shadow: 0 6px 0 var(--bad); animation: shake .45s; }
.see-pic { width: min(64vw, 300px); aspect-ratio: 1; margin: 0 auto 18px; background: #fff; border-radius: 30px; padding: 12px; box-shadow: var(--shadow); }
.see-pic .vis { background: var(--soft); border-radius: 22px; padding: 6%; }

/* Đánh vần */
.slots { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 0 0 22px; }
.slot {
  width: clamp(44px, 11vw, 64px); height: clamp(54px, 13vw, 76px); border-radius: 16px; background: #fff;
  border: 3px dashed #cfcbe6; display: grid; place-items: center; font-size: clamp(30px, 8vw, 44px); font-weight: 800; text-transform: lowercase;
}
.slot.filled { border: 3px solid var(--c); background: var(--soft); animation: pop .3s; }
.slot.gap { border: none; background: transparent; width: 18px; }
.tiles { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; max-width: 620px; margin: 0 auto; }
.tile {
  width: clamp(52px, 13vw, 70px); height: clamp(52px, 13vw, 70px); border: none; border-radius: 18px; font-size: clamp(30px, 8vw, 40px); font-weight: 800;
  background: var(--tc, #fff); box-shadow: 0 6px 0 rgba(0,0,0,.15);
}
.tile:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.tile.used { visibility: hidden; }
.tile.wrong { animation: shake .4s; background: #ffd1d1; }

/* Lật thẻ */
.memory { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; max-width: 640px; margin: 0 auto; perspective: 900px; }
@media (max-width: 520px) { .memory { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.mcard { aspect-ratio: 3/4; border: none; padding: 0; background: none; position: relative; }
.mcard .in { position: absolute; inset: 0; transition: transform .45s; transform-style: preserve-3d; }
.mcard.open .in, .mcard.matched .in { transform: rotateY(180deg); }
.mcard .face { position: absolute; inset: 0; border-radius: 20px; backface-visibility: hidden; display: grid; place-items: center; box-shadow: 0 5px 0 rgba(0,0,0,.12); }
.mcard .back { background: var(--c); background-image: radial-gradient(rgba(255,255,255,.25) 3px, transparent 4px); background-size: 22px 22px; font-size: 40px; }
.mcard .front { background: #fff; transform: rotateY(180deg); padding: 8px; }
.mcard .front .vis { background: var(--soft); border-radius: 14px; padding: 6%; }
.mcard .front .w { font-size: clamp(18px, 4.6vw, 28px); font-weight: 800; color: var(--c); text-align: center; line-height: 1.05; word-break: break-word; }
.mcard.matched .front { box-shadow: 0 0 0 5px var(--good); animation: yay .5s; }

/* Kết quả */
.result { text-align: center; background: #fff; border-radius: 36px; padding: 26px 20px 30px; max-width: 520px; margin: 10px auto; box-shadow: var(--shadow); animation: cardIn .5s cubic-bezier(.2,1.4,.4,1); }
.result img.owl { width: 170px; }
.result .owl.emoji { font-size: 110px; }
.result h2 { font-size: 40px; margin: 4px 0 0; color: var(--c); }
.result .big-stars { font-size: 60px; letter-spacing: 6px; margin: 6px 0; }
.result .big-stars span { display: inline-block; animation: pop .5s backwards; }
.result .big-stars .off { filter: grayscale(1); opacity: .3; }
.result p { font-size: 20px; color: var(--ink-soft); margin: 0 0 18px; }

/* Pháo giấy */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.floating-star { position: fixed; z-index: 60; font-size: 44px; pointer-events: none; animation: flyStar .9s cubic-bezier(.5,-.3,.7,1) forwards; }
@keyframes flyStar { to { left: var(--tx); top: var(--ty); transform: scale(.4); opacity: .3; } }

.parent-note { margin-top: 34px; background: rgba(255,255,255,.7); border-radius: 22px; padding: 14px 18px; font-size: 17px; color: var(--ink-soft); }
.parent-note b { color: var(--ink); }
.reset-link { background: none; border: none; color: var(--ink-soft); text-decoration: underline; font-size: 15px; padding: 0; }

@media (max-width: 520px) {
  .brand { font-size: 21px; }
  .brand img { width: 38px; height: 38px; }
  .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .topic-card { padding: 10px 12px 14px; }
  .topic-card .pic { height: 100px; }
  .topic-card .pic img { max-height: 100px; }
  .topic-card .pic .big-emoji { font-size: 64px; }
  .topic-card h3 { font-size: 22px; }
  .topic-card .vi { font-size: 15px; }
  .choices { gap: 12px; }
  .btn.round { width: 62px; height: 62px; }
}

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