/* ===== MathKids — Cartoon UI v2 ===== */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&display=swap');

:root {
  --clr-bg: #fef9f0;
  --clr-primary: #ff6b6b;
  --clr-primary-dark: #ee5a24;
  --clr-secondary: #4ecdc4;
  --clr-accent: #ffe66d;
  --clr-purple: #a29bfe;
  --clr-green: #55efc4;
  --clr-text: #2d3436;
  --clr-text-light: #636e72;
  --clr-white: #ffffff;
  --clr-card-bg: #ffffff;
  --clr-card-shadow: rgba(0,0,0,0.12);

  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;

  --numpad-key-size: 72px;
  --numpad-gap: 14px;

  --font: 'Nunito', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--clr-bg);
  background-image:
    radial-gradient(circle at 10% 20%, #fff0f0 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, #f0f8ff 0%, transparent 50%);
  min-height: 100vh;
  color: var(--clr-text);
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== SCREENS ===== */
.init-screen,
.select-screen,
.play-screen,
.result-screen,
.update-required-screen {
  width: 100%;
  max-width: 480px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: screen-fade-in 0.3s ease;
}

/* ===== SELECT SCREEN ===== */
.select-screen {
  text-align: center;
}

.current-level {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--clr-text-light);
  background: var(--clr-purple);
  color: white;
  padding: 10px 24px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
/* ===== PLAY SCREEN ===== */
.question-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.question-text {
  font-size: clamp(2.8rem, 12vw, 4.5rem);
  font-weight: 900;
  color: var(--clr-text);
  text-align: center;
  line-height: 1.1;
  letter-spacing: -1px;
  text-shadow: 3px 3px 0px rgba(0,0,0,0.06);
}

/* ===== SCAFFOLD VISUAL (Step 47, LinhHon 4.3) ===== */
.scaffold-visual {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  margin: 8px 0;
}

.scaffold-item.scaffold-unknown {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  height: 50px;
  border: 2px dashed #9ca3af;
  border-radius: 6px;
  font-size: 1.6rem;
  color: #6b7280;
}

.scaffold-visual.pictorial-faded {
  opacity: 0.5;
}

/* ===== STORY CONTEXT (Step 48, LinhHon 5.2) ===== */
.story-context {
  font-size: 1.25rem;
  line-height: 1.5;
  text-align: center;
  color: var(--clr-text);
  background: rgba(0,0,0,0.04);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 8px auto;
  max-width: 520px;
}

/* ===== THEME PICKER (Step 50, LinhHon 13.1) ===== */
.theme-picker { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.theme-option { font-size: 1rem; padding: 8px 14px; border-radius: 999px; border: 2px solid #d1d5db; background: #fff; cursor: pointer; }
.theme-option[aria-pressed="true"] { border-color: #2563eb; background: #eff6ff; }

.question-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* 🔴 v2.2 — Thanh chấm trong-session (LinhHon §3.8.2): chấm tròn sáng/mờ, không số. */
.progress-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}
.progress-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e5e0e0;           /* mờ/rỗng — chưa tới */
  border: 2px solid #d0c8d0;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.progress-dot.is-lit {
  background: var(--clr-green);  /* sáng/đầy = đã trả lời */
  border-color: #2ecc9a;
}

/* 🔴 v2.2 — nút Tạm dừng (nhẹ, an toàn, không cạnh tranh với Trả lời). */
#btn-pause {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--clr-text-light);
  background: #f3f0f7;
  border: 2px solid #e0d8ea;
  border-radius: 999px;
  padding: 6px 18px;
  cursor: pointer;
  margin-top: 4px;
}

/* 🔴 v2.2 (LinhHon §3.8.3) — thứ bậc nút Trả lời/Gợi ý (đồng nhất choice lẫn numpad):
   "Trả lời" là hành động CHÍNH (to, nổi bật, dưới cùng); "Cần gợi ý" là PHỤ (nhỏ, nhạt, trên). */
#btn-hint {
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-purple);
  background: #f6f2ff;
  border: 2px solid #e2d8ff;
  border-radius: 999px;
  padding: 8px 20px;
  cursor: pointer;
  min-width: 120px;
}
#btn-submit {
  font-size: 1.5rem;
  font-weight: 900;
  color: #ffffff;
  background: var(--clr-primary);
  border: none;
  border-radius: 999px;
  padding: 16px 40px;
  cursor: pointer;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 5px 0 var(--clr-primary-dark);
}
#btn-submit:disabled {
  background: #e0d8e0;
  color: #aaa;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.7;
}

/* Count-up MM:SS elapsed — cosmetic cho phụ huynh, không gây áp lực tốc độ cho trẻ. */
.session-timer {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--clr-text-light);
  background: #ffffff;
  border: 2px solid #e8e0ff;
  border-radius: 999px;
  padding: 4px 16px;
  letter-spacing: 0.5px;
}

/* Phản hồi đúng/sai trên thẻ lựa chọn. */
.choice-card.is-correct {
  border-color: var(--clr-green);
  background: #e6fff4;
}
.choice-card.is-wrong {
  border-color: #ffd6d6;
  background: #fff0f0;
}

/* ===== CHOICE CARDS (Tầng 1) ===== */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  margin: 8px 0;
  padding: 0 8px;
}

.choice-card {
  background: var(--clr-card-bg);
  border: 3px solid #e8e0ff;
  border-radius: var(--radius-xl);
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--clr-text);
  min-height: 88px;
  padding: 20px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  box-shadow: 0 4px 0px #e8e0ff, 0 6px 16px var(--clr-card-shadow);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.choice-card:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: var(--clr-purple);
  background: #f8f6ff;
}

.choice-card:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 0px #e8e0ff, 0 3px 8px var(--clr-card-shadow);
}

.choice-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.choice-card.is-selected {
  border-color: var(--clr-secondary);
  background: #f0fffd;
  box-shadow: 0 4px 0px #38b2a9, 0 6px 16px var(--clr-card-shadow);
  transform: translateY(-2px);
}

/* ===== NUMPAD (Tầng 2–3) ===== */
.numpad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.numpad-display {
  width: 100%;
  max-width: 280px;
  min-height: 64px;
  background: white;
  border: 3px solid #e8e0ff;
  border-radius: var(--radius-lg);
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-text);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.06);
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--numpad-key-size));
  gap: var(--numpad-gap);
}

.numpad-key {
  width: var(--numpad-key-size);
  height: var(--numpad-key-size);
  background: white;
  border: 3px solid #e8e0ff;
  border-radius: var(--radius-lg);
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--clr-text);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
  box-shadow: 0 4px 0px #e8e0ff;
  font-family: var(--font);
}

.numpad-key:hover:not(:disabled) {
  background: #f8f6ff;
  transform: translateY(-2px);
}

.numpad-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0px #e8e0ff;
}

.numpad-key:disabled { opacity: 0.4; cursor: not-allowed; }

.numpad-key.key-delete {
  background: #fff0f0;
  border-color: #ffd6d6;
  box-shadow: 0 4px 0px #ffd6d6;
  font-size: 1rem;
}

.numpad-key.key-confirm {
  background: var(--clr-secondary);
  border-color: #38b2a9;
  box-shadow: 0 4px 0px #38b2a9;
  color: white;
  font-size: 0.9rem;
}

.numpad-key.key-confirm:hover:not(:disabled) {
  background: #3dd6cc;
}
/* ===== BUTTONS ===== */
button {
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#btn-start {
  background: var(--clr-primary);
  color: white;
  font-size: 1.3rem;
  padding: 16px 48px;
  border-radius: 999px;
  box-shadow: 0 6px 0px var(--clr-primary-dark), 0 8px 20px rgba(255,107,107,0.35);
  letter-spacing: 0.5px;
}

#btn-start:hover {
  transform: translateY(-3px);
  box-shadow: 0 9px 0px var(--clr-primary-dark), 0 12px 24px rgba(255,107,107,0.4);
}

#btn-start:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0px var(--clr-primary-dark);
}

#btn-submit {
  background: var(--clr-accent);
  color: var(--clr-text);
  font-size: 1.1rem;
  padding: 14px 36px;
  border-radius: 999px;
  box-shadow: 0 5px 0px #e6c800, 0 7px 16px rgba(255,230,109,0.4);
}

#btn-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 7px 0px #e6c800, 0 10px 20px rgba(255,230,109,0.45);
}

#btn-submit:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 3px 0px #e6c800;
}

#btn-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

#btn-hint {
  background: transparent;
  color: var(--clr-text-light);
  font-size: 0.95rem;
  padding: 8px 20px;
  border-radius: 999px;
  border: 2px dashed #ccc;
  font-weight: 700;
}

#btn-hint:hover:not(:disabled) {
  border-color: var(--clr-purple);
  color: var(--clr-purple);
  background: #f8f6ff;
}

/* ===== HINT / PART-WHOLE ===== */
.hint-text {
  background: #fffbea;
  border: 2px solid var(--clr-accent);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: badge-pop 0.25s ease;
}

.part-whole {
  font-size: 1.5rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pw-whole {
  background: var(--clr-primary);
  color: white;
  padding: 6px 18px;
  border-radius: var(--radius-md);
  font-size: 1.6rem;
}

.pw-part {
  background: var(--clr-secondary);
  color: white;
  padding: 6px 18px;
  border-radius: var(--radius-md);
  font-size: 1.4rem;
}

.pw-missing {
  background: var(--clr-accent);
  color: var(--clr-text);
  border: 3px dashed #e6c800;
}

.pw-parts {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== ANSWER REVEAL ===== */
.answer-text {
  background: #f0fff8;
  border: 2px solid var(--clr-green);
  border-radius: var(--radius-lg);
  padding: 14px 24px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #00b894;
  text-align: center;
  width: 100%;
  max-width: 360px;
  animation: badge-pop 0.25s ease;
}

/* ===== REST STATION ===== */
.rest-station {
  text-align: center;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.rest-text {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--clr-purple);
  animation: rest-breathe 2s ease-in-out infinite;
}

/* ===== RESULT SCREEN ===== */
.result-screen {
  text-align: center;
}
/* ===== ANIMATIONS ===== */
@keyframes screen-fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes badge-pop {
  0%   { transform: scale(0.85); opacity: 0; }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}

@keyframes rest-breathe {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.06); }
}

@keyframes correct-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-8px); }
  75%       { transform: translateX(8px); }
}

.is-correct, .choice-card.is-correct { animation: correct-pulse 0.35s ease; }
.is-wrong, .choice-card.is-wrong { animation: wrong-shake 0.35s ease; }

/* ===== SUBITIZE OVERLAY ===== */
.subitize-overlay {
  border-radius: var(--radius-xl);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  --numpad-key-size: 80px;
  --numpad-gap: 16px;

  .choice-card { font-size: 2.8rem; padding: 24px 10px; }
  .question-text { font-size: 5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== AUXILIARY — cover classes emitted by JS but not in main cartoon CSS ===== */
.init-title {
  font-size: 2rem; font-weight: 900; color: var(--clr-primary); text-align: center;
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 5px solid #e8e0ff;
  border-top-color: var(--clr-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.init-screen-error, .error-message {
  color: var(--clr-primary); font-weight: 800; text-align: center; padding: 16px;
}
.retry-button {
  background: var(--clr-primary); color: white;
  padding: 12px 32px; border-radius: 999px;
  font-size: 1rem; font-weight: 800;
  box-shadow: 0 4px 0px var(--clr-primary-dark);
}
.self-correction-badge {
  background: var(--clr-green); color: var(--clr-text);
  padding: 8px 20px; border-radius: 999px;
  font-size: 0.95rem; font-weight: 800;
  animation: badge-pop 0.25s ease;
}
.fever-active { background: linear-gradient(135deg, #fff3cd, #ffe66d); }
.fever-streak { color: var(--clr-primary); font-weight: 900; }