/* Moon Math 3 — styles.css
 * Giao diện tươi sáng, bo tròn, nhiều hiệu ứng. Mobile-first (điện thoại & iPad).
 */

/* ============ Nền tảng ============ */
:root {
  /* Màu cố định (không đổi theo theme) */
  --ink: #1f2937;
  --ink-soft: #6b7280;
  --card: #ffffff;
  --ok: #22c55e;
  --ok-dark: #16a34a;
  --no: #ef4444;
  --no-dark: #dc2626;
  --shadow: 0 10px 30px rgba(30, 20, 80, .18);
  --radius: 22px;
  font-size: 16px;

  /* === Biến THEME (mặc định: Rừng non). themes.js sẽ ghi đè khi Moon đổi màu === */
  --bg: linear-gradient(160deg, #15803d, #22c55e 60%, #4ade80);
  --headtext: #ffffff;          /* chữ trên nền màu */
  --head-shadow: rgba(0,0,0,.12);
  --chrome-bg: rgba(255,255,255,.2);   /* nút tròn trên nền (back, âm thanh) */
  --chrome-fg: #ffffff;
  --track: rgba(255,255,255,.28);      /* nền thanh tiến độ, badge */
  --primary: #16a34a;
  --primary2: #22c55e;          /* cặp gradient nút/chip */
  --primary-dark: #15803d;
  --ring: rgba(22,163,74,.4);
  --progress: linear-gradient(90deg, #fde047, #4ade80);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  font-family: 'Baloo 2', 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }

/* Vệt sáng trang trí ở nền */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(40% 30% at 10% 10%, rgba(255,255,255,.18), transparent 60%),
    radial-gradient(35% 25% at 90% 0%, rgba(255,255,255,.14), transparent 60%);
  pointer-events: none; z-index: 0;
}

/* ============ Bố cục màn hình ============ */
#app { position: relative; z-index: 1; }
.mm-screen {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.mm-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 14px;
}

/* ============ Trang chủ ============ */
.mm-home-header { text-align: center; color: var(--headtext); padding: 18px 6px 6px; position: relative; }
.mm-logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.mm-logo-emoji { font-size: 2.4rem; animation: floaty 3s ease-in-out infinite; }
.mm-logo-title { font-size: 2rem; font-weight: 800; margin: 0; text-shadow: 0 3px 0 var(--head-shadow); }

/* Nút mở bảng chọn màu (góc phải header) */
.mm-theme-btn {
  position: absolute; top: 12px; right: 0;
  border: none; background: var(--chrome-bg); color: var(--chrome-fg);
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.3rem;
  display: grid; place-items: center; transition: transform .1s ease;
}
.mm-theme-btn:active { transform: scale(.9); }
.mm-home-sub { margin: 6px 0 0; opacity: .95; font-weight: 600; }

.mm-home-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (max-width: 380px) { .mm-home-grid { grid-template-columns: 1fr; } }

.mm-topic-card {
  position: relative;
  border: none;
  text-align: left;
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  min-height: 150px;
  display: flex; flex-direction: column; gap: 4px;
  background: linear-gradient(150deg, var(--from), var(--to));
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  overflow: hidden;
}
.mm-topic-card::after {
  content: ''; position: absolute; right: -30px; top: -30px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.18);
}
.mm-topic-card:active { transform: scale(.96); }
@media (hover: hover) { .mm-topic-card:hover { transform: translateY(-4px); filter: saturate(1.1); } }
.mm-topic-card-emoji { font-size: 2.6rem; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0,0,0,.2)); }
.mm-topic-card-title { font-size: 1.25rem; font-weight: 800; margin-top: 6px; }
.mm-topic-card-tag { font-size: .82rem; font-weight: 600; opacity: .95; line-height: 1.25; flex: 1; }
.mm-topic-card-go { font-size: .85rem; font-weight: 700; margin-top: 4px; opacity: .95; }

.mm-soon {
  background: var(--track);
  border: 2px dashed var(--chrome-fg);
  box-shadow: none; color: var(--headtext);
}
.mm-soon .mm-topic-card-tag { opacity: .9; }

.mm-home-footer { text-align: center; color: var(--headtext); opacity: .92; font-weight: 600; margin-top: 20px; font-size: .9rem; }

/* ============ Thanh trên cùng ============ */
.mm-topbar {
  display: flex; align-items: center; gap: 10px;
  color: var(--headtext);
}
.mm-back, .mm-sound {
  border: none; background: var(--chrome-bg); color: var(--chrome-fg);
  width: 44px; height: 44px; border-radius: 50%;
  font-size: 1.5rem; font-weight: 800; line-height: 1;
  display: grid; place-items: center;
  transition: transform .1s ease, background .1s ease;
}
.mm-back:active, .mm-sound:active { transform: scale(.9); }
.mm-topbar-title { flex: 1; text-align: center; font-size: 1.15rem; font-weight: 800; text-shadow: 0 2px 0 var(--head-shadow); }

/* ============ Màn chọn tuỳ chọn ============ */
.mm-topic-hero {
  width: 84px; height: 84px; border-radius: 24px;
  display: grid; place-items: center; margin: 0 auto;
  box-shadow: var(--shadow);
  animation: pop .4s ease;
}
.mm-topic-hero-emoji { font-size: 2.8rem; filter: drop-shadow(0 3px 3px rgba(0,0,0,.2)); }
.mm-topic-tagline { text-align: center; color: var(--ink-soft); font-weight: 600; margin: 12px 0 18px; }

.mm-opt-group { margin-bottom: 16px; }
.mm-opt-label { font-weight: 700; margin-bottom: 8px; color: var(--ink); }
.mm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mm-chip {
  border: 2px solid #e5e7eb; background: #f9fafb; color: var(--ink);
  padding: 9px 14px; border-radius: 999px; font-weight: 700; font-size: .95rem;
  transition: transform .1s ease, background .1s ease, border-color .1s ease, color .1s ease;
}
.mm-chip:active { transform: scale(.94); }
.mm-chip[data-active="true"] {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 14px var(--ring);
}

/* ============ Nút ============ */
.mm-btn {
  border: none; border-radius: 16px; font-weight: 800;
  padding: 14px 20px; font-size: 1.05rem;
  transition: transform .1s ease, box-shadow .1s ease, filter .1s ease;
}
.mm-btn:active { transform: translateY(2px) scale(.99); }
.mm-btn-big { width: 100%; margin-top: 8px; font-size: 1.15rem; padding: 16px; }
.mm-btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: #fff; box-shadow: 0 8px 18px var(--ring); }
.mm-btn-primary[disabled] { filter: grayscale(.6) opacity(.6); box-shadow: none; }
.mm-btn-ghost { background: #f3f4f6; color: var(--ink); }
.mm-btn-next { background: linear-gradient(135deg, var(--ok), var(--ok-dark)); color: #fff; box-shadow: 0 8px 18px rgba(34,197,94,.35); width: 100%; margin-top: 0; }

/* ============ Thanh tiến độ ============ */
.mm-progress-wrap { margin-top: 14px; color: #fff; }
.mm-progress { height: 14px; background: var(--track); border-radius: 999px; overflow: hidden; }
.mm-progress-fill { height: 100%; background: var(--progress); border-radius: 999px; transition: width .35s cubic-bezier(.4,1.4,.5,1); }
.mm-progress-text { display: flex; justify-content: space-between; font-weight: 700; font-size: .88rem; margin-top: 6px; }
.mm-progress-correct { background: var(--track); padding: 1px 10px; border-radius: 999px; }

/* ============ Thẻ câu hỏi ============ */
/* Màn làm bài co giãn theo chiều cao màn hình để mọi thứ gọn trong 1 khung hình */
.mm-quiz-screen { display: flex; flex-direction: column; }
.mm-quiz-screen .mm-q-card { flex: 1 1 auto; display: flex; flex-direction: column; }
.mm-q-card { text-align: center; position: relative; padding-top: 30px; padding-bottom: 0; }
.mm-q-mascot {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  font-size: 3rem; filter: drop-shadow(0 4px 4px rgba(0,0,0,.15));
  animation: floaty 2.6s ease-in-out infinite;
}
.mm-q-prompt {
  font-size: 2.4rem; font-weight: 800; color: var(--ink);
  margin: 6px 0 14px; letter-spacing: .5px;
}

/* --- Trắc nghiệm --- */
.mm-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mm-choice {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid #e5e7eb; background: #fff; color: var(--ink);
  border-radius: 16px; padding: 16px 14px; font-size: 1.4rem; font-weight: 800;
  transition: transform .1s ease, border-color .1s ease, background .1s ease;
}
.mm-choice:active { transform: scale(.96); }
.mm-choice-key {
  background: color-mix(in srgb, var(--primary) 14%, #fff); color: var(--primary-dark);
  width: 30px; height: 30px; border-radius: 9px; font-size: .95rem;
  display: grid; place-items: center; flex: 0 0 auto;
}
.mm-choice-val { flex: 1; text-align: center; }
.mm-choice.is-correct { border-color: var(--ok); background: #dcfce7; animation: pop .3s ease; }
.mm-choice.is-correct .mm-choice-key { background: var(--ok); color: #fff; }
.mm-choice.is-wrong { border-color: var(--no); background: #fee2e2; }
.mm-choice.is-wrong .mm-choice-key { background: var(--no); color: #fff; }
.mm-choice[disabled] { opacity: 1; cursor: default; }

/* --- Điền số --- */
.mm-fill-wrap { display: flex; justify-content: center; margin-bottom: 10px; }
.mm-fill-display {
  min-width: 120px; padding: 2px 18px 4px;
  font-size: 2.1rem; font-weight: 800; color: var(--ink-soft);
  border-bottom: 5px solid color-mix(in srgb, var(--primary) 45%, #fff); text-align: center;
  transition: color .1s ease, border-color .1s ease;
}
.mm-fill-display.has-val { color: var(--primary-dark); }
.mm-fill-display.is-correct { color: var(--ok-dark); border-color: var(--ok); animation: pop .3s ease; }
.mm-fill-display.is-wrong { color: var(--no-dark); border-color: var(--no); }

.mm-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 300px; margin: 0 auto; }
.mm-key {
  border: none; background: #f3f4f6; color: var(--ink);
  border-radius: 14px; padding: 11px 0; font-size: 1.4rem; font-weight: 800;
  box-shadow: 0 3px 0 #d1d5db; transition: transform .06s ease, box-shadow .06s ease, background .1s ease;
}
.mm-key:active { transform: translateY(3px); box-shadow: 0 0 0 #d1d5db; }
.mm-key-fn { background: color-mix(in srgb, var(--primary) 14%, #fff); color: var(--primary-dark); box-shadow: 0 3px 0 color-mix(in srgb, var(--primary) 35%, #fff); }
.mm-btn-check { max-width: 300px; margin: 0 auto; display: block; }

/* ============ Vùng hành động (sticky đáy thẻ) + phản hồi ============ */
/* Nút Kiểm tra / Câu tiếp theo luôn nằm trong vùng này -> luôn nhìn thấy,
   không bị bàn phím số che, không cần cuộn. */
.mm-action {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--card);
  margin-top: 14px;
  padding-top: 10px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  border-radius: 0 0 var(--radius) var(--radius);
}
.mm-fill-mode .mm-action { margin-top: auto; } /* đẩy xuống đáy thẻ ở dạng điền số */

.mm-feedback { font-weight: 800; font-size: 1.05rem; text-align: center; margin-bottom: 8px; animation: fadeIn .2s ease; }
.mm-feedback.ok { color: var(--ok-dark); }
.mm-feedback.no { color: var(--no-dark); }

/* ============ Kết quả ============ */
.mm-result-card { text-align: center; }
.mm-result-face { font-size: 4.5rem; animation: pop .5s ease; }
.mm-result-title { font-size: 1.6rem; font-weight: 800; margin: 6px 0 4px; }
.mm-stars { display: flex; justify-content: center; gap: 8px; margin: 10px 0; }
.mm-star { font-size: 3rem; line-height: 1; }
.mm-star.on { color: #fbbf24; text-shadow: 0 2px 0 #d97706; animation: starPop .5s cubic-bezier(.3,1.6,.5,1) backwards; }
.mm-star.off { color: #e5e7eb; }
.mm-result-score { margin: 10px 0 18px; display: flex; flex-direction: column; }
.mm-score-big { font-size: 2.6rem; font-weight: 800; color: var(--primary-dark); }
.mm-score-sub { color: var(--ink-soft); font-weight: 600; }
.mm-result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ============ Confetti canvas ============ */
.mm-confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9999; }

/* ============ Hiệu ứng động ============ */
.mm-fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes floaty { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -8px); } }
.mm-logo-emoji { animation-name: floatySimple; }
@keyframes floatySimple { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes starPop { 0% { transform: scale(0) rotate(-40deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.mm-shake { animation: shake .45s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

/* Tôn trọng người dùng tắt hiệu ứng chuyển động */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============ Bảng chọn màu (theme picker) ============ */
.mm-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; animation: fadeIn .2s ease;
}
@media (min-width: 560px) { .mm-modal-overlay { align-items: center; } }
.mm-modal {
  width: 100%; max-width: 460px; background: var(--card);
  border-radius: 24px; padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  animation: slideUp .28s cubic-bezier(.3,1.2,.5,1);
  max-height: 88dvh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.mm-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.mm-modal-title { font-size: 1.3rem; font-weight: 800; margin: 0; }
.mm-modal-close {
  border: none; background: #f3f4f6; color: var(--ink);
  width: 38px; height: 38px; border-radius: 50%; font-size: 1.3rem; line-height: 1;
  display: grid; place-items: center;
}
.mm-modal-close:active { transform: scale(.9); }

.mm-swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mm-swatch {
  border: 3px solid transparent; border-radius: 18px; padding: 0;
  background: #fff; overflow: hidden; text-align: left; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  transition: transform .1s ease, border-color .1s ease;
}
.mm-swatch:active { transform: scale(.96); }
.mm-swatch[data-active="true"] { border-color: var(--ink); }
.mm-swatch-preview { height: 62px; position: relative; }
.mm-swatch-check {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: var(--ok-dark); font-weight: 800;
  display: none; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.mm-swatch[data-active="true"] .mm-swatch-check { display: grid; }
.mm-swatch-label { display: block; padding: 9px 12px; font-weight: 800; font-size: .95rem; color: var(--ink); }
.mm-swatch-label small { display: block; font-weight: 600; color: var(--ink-soft); font-size: .75rem; }

/* ============ Đặt tính cột dọc (loại câu 'column') ============ */
.mm-col-caption { color: var(--ink-soft); font-weight: 700; margin: 2px 0 8px; }
.mm-column { display: inline-block; margin: 4px auto 2px; text-align: right; }
.mm-col-row { display: grid; gap: 8px; justify-content: end; }
.mm-col-cell {
  width: 46px; height: 56px; display: grid; place-items: center;
  font-size: 2rem; font-weight: 800; color: var(--ink);
}
.mm-col-op { color: var(--primary-dark); }
.mm-col-line { height: 4px; background: var(--ink); border-radius: 4px; margin: 6px 0 8px; }
.mm-col-box {
  width: 46px; height: 56px; border-radius: 12px;
  border: 3px solid color-mix(in srgb, var(--primary) 35%, #fff);
  background: #f9fafb; color: var(--primary-dark);
  font-size: 2rem; font-weight: 800; display: grid; place-items: center;
  transition: border-color .1s ease, background .1s ease, transform .1s ease;
}
.mm-col-box.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, #fff); transform: translateY(-2px); }
.mm-col-box.is-correct { border-color: var(--ok); background: #dcfce7; color: var(--ok-dark); }
.mm-col-box.is-wrong { border-color: var(--no); background: #fee2e2; color: var(--no-dark); }
.mm-col-empty { width: 46px; height: 56px; }
@media (max-width: 380px) {
  .mm-col-cell, .mm-col-box, .mm-col-empty { width: 40px; height: 50px; font-size: 1.7rem; }
}

/* iPad / màn rộng: phóng to nhẹ cho dễ nhìn */
@media (min-width: 700px) {
  :root { font-size: 18px; }
  .mm-q-prompt { font-size: 2.8rem; }
}
