/* Học Mà Chơi — kids theme: bright, big touch targets, rounded, playful */
:root {
  --bg: #fff8ec;
  --bg-2: #ffeecf;
  --ink: #2b2350;
  --ink-soft: #6b6390;
  --card: #ffffff;
  --brand: #5b7cff;
  --brand-ink: #ffffff;
  --good: #34c759;
  --bad: #ff6b6b;
  --star: #ffb703;
  --shadow: 0 8px 0 rgba(0,0,0,.08), 0 12px 24px rgba(0,0,0,.10);
  --radius: 26px;
  --tap: 72px;
  --font: "SF Pro Rounded", "Segoe UI Rounded", "Nunito", "Baloo 2", system-ui,
          -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg), var(--bg-2));
  -webkit-text-size-adjust: 100%;
}
body {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; }
img, svg { -webkit-user-drag: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(255,248,236,.9); backdrop-filter: blur(8px);
}
.topbar-center { flex: 1; text-align: center; }
.topbar-title { font-weight: 800; font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 48px; height: 48px; border: none; border-radius: 16px;
  background: #fff; box-shadow: var(--shadow); font-size: 30px; line-height: 1;
  color: var(--ink); font-weight: 800;
}
.star-count {
  font-weight: 800; font-size: 18px; background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap;
}
.lang-btn {
  min-width: 52px; height: 48px; border: none; border-radius: 16px;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 18px;
  box-shadow: var(--shadow);
}

/* ---------- Layout ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 18px 16px 48px; }
.screen { animation: pop .25s ease; }
.screen-title { text-align: center; font-size: 30px; font-weight: 900; margin: 8px 0 20px; }
.screen-title small { display: block; font-size: 17px; font-weight: 700; color: var(--ink-soft); margin-top: 6px; }

/* ---------- Grid of big cards ---------- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); max-width: 640px; margin: 0 auto; }

.tile {
  border: none; border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow); padding: 20px 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform .12s ease; color: var(--ink);
  min-height: 150px; justify-content: center;
}
.tile:active { transform: scale(.95); }
.tile .emoji { font-size: 56px; line-height: 1; }
.tile .label { font-size: 19px; font-weight: 800; }
.tile .sub { font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.tile[data-accent] { border-bottom: 8px solid var(--accent, var(--brand)); }

/* Profile cards */
.profile-card { min-height: 220px; gap: 14px; }
.profile-card .avatar { font-size: 84px; }
.profile-card .age { font-size: 15px; font-weight: 800; color: var(--brand); background: #eef2ff; padding: 4px 12px; border-radius: 999px; }
.profile-card .stars-mini { font-size: 15px; font-weight: 800; color: var(--ink-soft); }

/* ---------- Play area ---------- */
.play { max-width: 760px; margin: 0 auto; }
.prompt {
  text-align: center; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 18px; margin-bottom: 18px;
}
.prompt .p-emoji { font-size: 84px; line-height: 1; }
.prompt .p-flag { width: 150px; height: 100px; border-radius: 12px; box-shadow: var(--shadow); }
.prompt .p-text { font-size: 24px; font-weight: 900; margin-top: 10px; }
.prompt .p-text.sub { font-size: 17px; font-weight: 700; color: var(--ink-soft); margin-top: 4px; }

.listen-btn {
  margin: 4px auto 0; display: inline-flex; align-items: center; gap: 8px;
  border: none; border-radius: 999px; background: var(--brand); color: #fff;
  font-weight: 800; font-size: 18px; padding: 12px 22px; box-shadow: var(--shadow);
}

.choices { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.choice {
  min-height: var(--tap); border: 4px solid transparent; border-radius: var(--radius);
  background: #fff; box-shadow: var(--shadow); padding: 16px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--ink);
  transition: transform .1s ease;
}
.choice:active { transform: scale(.96); }
.choice .c-emoji { font-size: 52px; line-height: 1; }
.choice .c-flag { width: 108px; height: 72px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.choice .c-text { font-size: 18px; font-weight: 800; }
.choice.correct { border-color: var(--good); background: #eafff0; }
.choice.wrong { border-color: var(--bad); background: #fff0f0; animation: shake .3s; }
.choice[disabled] { opacity: .55; }

/* Tap-hear grid */
.tap-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.tap-card {
  border: none; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow);
  padding: 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--ink);
}
.tap-card:active { transform: scale(.94); }
.tap-card.speaking { border: 4px solid var(--brand); }
.tap-card .t-emoji { font-size: 50px; }
.tap-card .t-flag { width: 96px; height: 64px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.tap-card .t-text { font-size: 16px; font-weight: 800; }
.tap-card .t-sub { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

/* Match: two columns */
.match-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.match-col { display: flex; flex-direction: column; gap: 12px; }
.match-item {
  min-height: 66px; border: 4px solid transparent; border-radius: 20px; background: #fff;
  box-shadow: var(--shadow); padding: 10px; display: flex; align-items: center; justify-content: center;
  gap: 8px; color: var(--ink); font-weight: 800; font-size: 18px;
}
.match-item:active { transform: scale(.97); }
.match-item .m-emoji { font-size: 40px; }
.match-item .m-flag { width: 84px; height: 56px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.match-item.selected { border-color: var(--brand); background: #eef2ff; }
.match-item.done { border-color: var(--good); background: #eafff0; opacity: .7; }

/* Progress dots */
.progress { display: flex; gap: 8px; justify-content: center; margin: 6px 0 18px; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #e6ddc7; }
.dot.done { background: var(--good); }
.dot.current { background: var(--brand); transform: scale(1.25); }

/* Finish card */
.finish { text-align: center; padding: 30px 18px; }
.finish .big { font-size: 90px; }
.finish h2 { font-size: 30px; margin: 8px 0; }
.finish .stars-earned { font-size: 26px; font-weight: 900; color: var(--star); }
.primary-btn {
  border: none; border-radius: 999px; background: var(--brand); color: #fff;
  font-weight: 900; font-size: 20px; padding: 16px 34px; box-shadow: var(--shadow); margin: 8px;
}
.ghost-btn {
  border: none; border-radius: 999px; background: #fff; color: var(--ink);
  font-weight: 800; font-size: 18px; padding: 14px 28px; box-shadow: var(--shadow); margin: 8px;
}

/* Age filter chips */
.chips { display: flex; gap: 10px; justify-content: center; margin-bottom: 18px; flex-wrap: wrap; }
.chip {
  border: none; border-radius: 999px; background: #fff; color: var(--ink-soft);
  font-weight: 800; font-size: 16px; padding: 10px 20px; box-shadow: var(--shadow);
}
.chip.active { background: var(--brand); color: #fff; }

/* Celebrate overlay */
.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti { position: absolute; width: 12px; height: 16px; border-radius: 3px; top: -20px; animation: fall 1s ease-in forwards; }

/* Manage profile name row */
.name-row { display:flex; gap:10px; justify-content:center; margin-top:10px; }
.name-row input {
  font-family: inherit; font-size: 18px; font-weight: 700; border: 3px solid #e6ddc7;
  border-radius: 14px; padding: 10px 14px; width: 200px; text-align:center; color: var(--ink);
}

@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }
@keyframes fall { to { transform: translateY(100vh) rotate(540deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition: none !important; }
}

@media (max-width: 420px) {
  .tile .emoji { font-size: 46px; }
  .screen-title { font-size: 25px; }
}

/* ---------- Chuyện Kể (story engine) ---------- */
.story { max-width: 640px; }
.story-art-box {
  background: #0b1026; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); margin: 0 auto 16px; max-width: 560px;
}
.story-art { display: block; width: 100%; height: auto; }
.story-text {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 14px;
}
.story-text p { font-size: 20px; line-height: 1.55; font-weight: 600; margin: 0; color: var(--ink); }
.story-fact { background: #fff7e6; border-left: 8px solid var(--star); }
.fact-badge { display: inline-block; font-weight: 800; color: #a9741a; margin-bottom: 8px; font-size: 15px; }
.story-choices { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.story-choice { flex-direction: row; min-height: 60px; justify-content: center; }
.story-choice .c-text { font-size: 19px; }
.story-why {
  background: #eafff0; border-radius: 18px; padding: 14px 16px;
  font-weight: 700; color: #1c7c3f; font-size: 17px; line-height: 1.5; margin-bottom: 12px;
}
.reveal-hint { color: var(--brand); font-weight: 800; }
.story-nav { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.listen-btn.ghost { background: #fff; color: var(--ink); box-shadow: var(--shadow); padding: 12px 16px; }
.recap-title { font-size: 22px; margin: 0 0 12px; color: var(--ink); }
.recap-list { margin: 0; padding-left: 22px; }
.recap-list li { font-size: 18px; line-height: 1.5; font-weight: 600; margin-bottom: 8px; color: var(--ink); }
