/* =====================================================================
   YuhTahn Bé Vui Học — CSS toàn cục (bổ sung cho Tailwind CDN)
   ===================================================================== */

/* ---------- Chặn zoom, chạm, bôi đen, bounce ---------- */
html,
body,
button,
a,
[role='button'] {
  touch-action: manipulation; /* tắt double-tap zoom */
}
html,
body {
  overscroll-behavior: none; /* chặn kéo giãn / bounce trang */
}
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Ô nhập vẫn cho chọn chữ; font >= 16px để iOS không tự zoom khi focus */
input,
select,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  font-size: max(16px, 1rem);
}
/* Vùng chơi game: chạm liên tục, không cuộn/zoom */
.play-area {
  touch-action: none;
}

/* ---------- Nền & font ---------- */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
html {
  background: #fef3c7;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 800;
  color: #1e293b;
  background: radial-gradient(circle at 20% 10%, #fde68a 0, transparent 40%), radial-gradient(circle at 80% 90%, #fbcfe8 0, transparent 45%), #fef3c7;
  background-attachment: fixed;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
#app {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Bố cục màn hình ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.screen-center {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--safe-bottom));
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
.card {
  background: #fff;
  border-radius: 28px;
  padding: 20px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.06), 0 10px 30px rgba(0, 0, 0, 0.08);
}
.title-rainbow {
  background: linear-gradient(90deg, #f43f5e, #f59e0b, #22c55e, #3b82f6, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Nút (tối thiểu 64px) ---------- */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
  min-height: 64px;
  border-radius: 999px;
  font-size: 1.35rem;
  font-weight: 900;
  padding: 0 24px;
  transition: transform 0.1s;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(180deg, #a78bfa, #7c3aed);
  color: #fff;
  box-shadow: 0 6px 0 #5b21b6;
}
.btn-secondary {
  background: #fff;
  color: #5b21b6;
  box-shadow: 0 6px 0 #ddd6fe;
  border: 3px solid #ddd6fe;
}
.btn-danger {
  background: #fff1f2;
  color: #be123c;
  border: 3px solid #fecdd3;
  box-shadow: 0 6px 0 #fecdd3;
}
.btn-ghost {
  background: transparent;
  color: #64748b;
}
.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
  transform: translateY(4px);
  box-shadow: none;
}
button:disabled {
  cursor: default;
}
.btn-primary:disabled {
  opacity: 0.7;
}
.icon-btn {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 1.8rem;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
}
.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- Form ---------- */
.field-label {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  color: #475569;
}
.input {
  width: 100%;
  min-height: 60px;
  border-radius: 18px;
  border: 3px solid #e2e8f0;
  padding: 0 16px;
  font-weight: 800;
  outline: none;
  background: #f8fafc;
}
.input:focus {
  border-color: #a78bfa;
  background: #fff;
}
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  font-size: 1.4rem;
}
.msg-error {
  color: #be123c;
  background: #fff1f2;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 1.05rem;
}
.choice-btn,
.avatar-btn {
  min-height: 64px;
  border-radius: 18px;
  background: #f1f5f9;
  border: 3px solid transparent;
  font-size: 1.6rem;
  font-weight: 900;
}
.avatar-btn {
  font-size: 2.2rem;
}
.choice-btn.selected,
.avatar-btn.selected {
  background: #ede9fe;
  border-color: #7c3aed;
  transform: scale(1.05);
}
.toggle-row,
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 18px;
  background: #f8fafc;
  font-size: 1.2rem;
}
.switch {
  width: 64px;
  height: 36px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.switch.on {
  background: #22c55e;
}
.switch.on::after {
  transform: translateX(28px);
}

/* ---------- Chọn bé ---------- */
.child-card {
  min-height: 190px;
  border-radius: 28px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 8px;
  box-shadow: 0 8px 0 #e9d5ff, 0 10px 24px rgba(0, 0, 0, 0.06);
  transition: transform 0.1s;
}
.child-card:active {
  transform: scale(0.95);
}
.child-card-add {
  background: rgba(255, 255, 255, 0.6);
  border: 4px dashed #c4b5fd;
  box-shadow: none;
}

/* ---------- Bản đồ ---------- */
.map-topbar {
  justify-content: space-between;
}
.child-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 0 14px 0 8px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
}
.star-total {
  font-size: 1.6rem;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fde047, #f59e0b);
  color: #78350f;
  box-shadow: 0 4px 0 #d97706;
}
.map-hint {
  text-align: center;
  font-size: 0.9rem;
  color: #64748b;
  padding: 6px 12px;
}
.map-section {
  position: relative;
  overflow: hidden;
}
.map-path {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.section-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 420px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 24px;
  color: #fff;
  z-index: 3;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
}
.deco {
  position: absolute;
  font-size: 2.2rem;
  opacity: 0.55;
  z-index: 1;
  animation: float 4s ease-in-out infinite;
  pointer-events: none;
}
.map-node {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.node-circle {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  background: var(--c);
  border: 5px solid #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
}
.map-node.locked .node-circle {
  background: #cbd5e1;
  font-size: 1.6rem;
}
.map-node.perfect .node-circle {
  background: linear-gradient(180deg, #fde047, #f59e0b);
  color: #78350f;
}
.map-node.current .node-circle {
  animation: bounce 1.1s ease-in-out infinite, glow 1.6s ease-in-out infinite;
}
.map-node:active .node-circle {
  transform: scale(0.92);
}
.node-stars {
  margin-top: 4px;
  font-size: 1rem;
  letter-spacing: 1px;
  color: #f59e0b;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.5;
}
.node-stars .dim {
  color: #cbd5e1;
}
.node-more {
  position: absolute;
  top: -10px;
  right: -22px;
  font-size: 0.8rem;
  background: #fff;
  color: #b45309;
  border: 2px solid #fcd34d;
  border-radius: 999px;
  padding: 0 6px;
  animation: wiggle 2.4s ease-in-out infinite;
}
.map-end {
  padding-bottom: calc(32px + var(--safe-bottom));
}

/* ---------- Màn chơi ---------- */
.game-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.game-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + var(--safe-top)) 12px 4px;
}
.progress-track {
  flex: 1;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.game-title {
  text-align: center;
  font-size: 0.95rem;
  color: #475569;
}
.game-prompt {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
  padding: 4px 16px 8px;
  min-height: 2.5em;
}
.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  gap: 16px;
  padding: 0 16px;
}
.q-visual {
  width: 100%;
  max-width: 520px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 32px;
  padding: 16px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.06);
}
.emoji-group {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 2px 4px;
  justify-content: center;
  line-height: 1.1;
}
.em-lg {
  font-size: 3rem;
}
.em-md {
  font-size: 2.2rem;
}
.em-sm {
  font-size: 1.5rem;
}
.emoji-group .gone {
  opacity: 0.25;
  position: relative;
  filter: grayscale(1);
}
.emoji-group .gone::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  background: #ef4444;
  transform: rotate(-30deg);
  border-radius: 2px;
}
.math-pics {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.math-pics .em-lg {
  font-size: 2.3rem;
}
.op {
  font-size: 2.4rem;
  color: #7c3aed;
}
.equation {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 2px;
}
.big-emoji {
  font-size: 7rem;
  line-height: 1;
}
.listen-icon {
  font-size: 5rem;
  animation: wiggle 2s ease-in-out infinite;
}
.seq-row {
  display: flex;
  gap: 10px;
}
.seq-tile {
  width: 64px;
  height: 72px;
  border-radius: 18px;
  background: #fff;
  border: 4px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
}
.seq-hole {
  border-style: dashed;
  border-color: #a78bfa;
  color: #a78bfa;
}

/* Nút đáp án */
.opt-btn {
  min-height: 96px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 8px 0 #c7d2fe;
  border: 4px solid #e0e7ff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.opt-btn:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #c7d2fe;
}
.opt-num {
  font-size: 3.2rem;
  font-weight: 900;
  color: #4338ca;
}
.opt-letter {
  font-size: 3.4rem;
  font-weight: 900;
  color: #c2410c;
}
.opt-emoji {
  font-size: 3.6rem;
}
.opt-correct {
  background: #dcfce7;
  border-color: #22c55e;
  box-shadow: 0 8px 0 #86efac;
  animation: pop 0.4s ease;
}
.opt-wrong {
  opacity: 0.45;
}

/* Ghép chữ */
.word-slots {
  display: flex;
  gap: 10px;
}
.word-slot {
  width: 64px;
  height: 76px;
  border-radius: 18px;
  border: 4px dashed #fdba74;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 900;
  color: #c2410c;
}
.word-slot.filled {
  border-style: solid;
  background: #fff;
}
.tile-btn {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  background: #fff;
  border: 4px solid #fed7aa;
  box-shadow: 0 6px 0 #fdba74;
  font-size: 2.4rem;
  font-weight: 900;
  color: #c2410c;
}
.tile-used {
  visibility: hidden;
}

/* Lật thẻ */
.flip-grid {
  display: grid;
  gap: 10px;
  width: 100%;
  margin: 0 auto;
}
.flip-card {
  aspect-ratio: 3 / 4;
  min-height: 72px;
  perspective: 600px;
}
.flip-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner {
  transform: rotateY(180deg);
}
.flip-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(2.4rem, 13vw, 4rem);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
}
.flip-back {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  color: #fff;
  font-size: clamp(1.6rem, 8vw, 2.4rem);
}
.flip-front {
  background: #fff;
  transform: rotateY(180deg);
}
.flip-card.matched .flip-front {
  background: #dcfce7;
  box-shadow: 0 5px 0 #86efac;
}

/* Nhớ thứ tự */
.seq-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 28px;
}
.seq-slot {
  width: 68px;
  height: 80px;
  border-radius: 18px;
  background: #fff;
  border: 4px solid #ddd6fe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
}
.seq-slot.covered {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  border-color: #7c3aed;
  font-size: 1.8rem;
}
.seq-status {
  font-size: 1.3rem;
  color: #475569;
}
.seq-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  max-width: 460px;
  min-height: 90px;
}
.seq-choice {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  background: #fff;
  border: 4px solid #ddd6fe;
  box-shadow: 0 6px 0 #c4b5fd;
  font-size: 2.8rem;
}

/* ---------- Kết quả ---------- */
.result-stars {
  display: flex;
  gap: 6px;
  margin: 24px 0 16px;
}
.result-star {
  font-size: clamp(2.6rem, 14vw, 4.2rem);
  filter: grayscale(1);
  opacity: 0.25;
}
.result-star.earned {
  filter: none;
  opacity: 0;
  animation: star-fall 0.6s cubic-bezier(0.3, 1.6, 0.6, 1) forwards;
}

/* ---------- Hộp thoại, thông báo, hiệu ứng ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 32px;
  padding: 24px;
  text-align: center;
  max-height: 90dvh;
  overflow-y: auto;
}
.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + var(--safe-top));
  transform: translateX(-50%);
  z-index: 60;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 1.05rem;
  max-width: calc(100% - 32px);
  text-align: center;
  animation: pop 0.3s ease;
}
.confetti-piece {
  position: fixed;
  z-index: 70;
  pointer-events: none;
}
.praise-bubble {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 65;
  transform: translate(-50%, -50%);
  padding: 14px 26px;
  border-radius: 999px;
  font-size: 2rem;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  animation: bubble 1.3s ease forwards;
}
.praise-good {
  background: #fff;
  color: #16a34a;
  box-shadow: 0 8px 0 #bbf7d0;
}
.praise-soft {
  background: #fff;
  color: #d97706;
  box-shadow: 0 8px 0 #fde68a;
  font-size: 1.4rem;
}

/* ---------- Animation ---------- */
.bounce {
  animation: bounce 1.2s ease-in-out infinite;
}
.pop-in {
  animation: pop 0.35s ease both;
}
.shake {
  animation: shake 0.45s ease;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18), 0 0 0 0 rgba(250, 204, 21, 0.8); }
  50% { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18), 0 0 0 12px rgba(250, 204, 21, 0); }
}
@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { translate: 0; }
  20% { translate: -10px; }
  40% { translate: 10px; }
  60% { translate: -6px; }
  80% { translate: 6px; }
}
@keyframes wiggle {
  0%, 100% { rotate: 0deg; }
  25% { rotate: -8deg; }
  75% { rotate: 8deg; }
}
@keyframes float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -8px; }
}
@keyframes star-fall {
  0% { opacity: 0; transform: translateY(-160px) rotate(-180deg) scale(0.4); }
  100% { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}
@keyframes bubble {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  80% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(0.95); }
}
@media (prefers-reduced-motion: reduce) {
  .bounce, .deco, .listen-icon, .node-more, .map-node.current .node-circle {
    animation: none;
  }
}

/* ---------- Tablet / desktop ---------- */
@media (min-width: 768px) {
  .opt-btn { min-height: 120px; }
  .opt-num { font-size: 4rem; }
  .game-prompt { font-size: 1.9rem; }
  .map-body { max-width: 720px; margin: 0 auto; border-radius: 32px; overflow: hidden; }
}
