/* =========================================================
   Bé Vui Học Toán — giao diện chung
   Phong cách: Claymorphism (khối mềm, bo tròn, bóng đổ dày)
   Font: Baloo 2 (hỗ trợ tiếng Việt)
   ========================================================= */

:root {
  color-scheme: light;

  /* Màu chính (design-system/toan-tu-duy/MASTER.md) */
  --primary: #2563EB;
  --primary-strong: #1E40AF;
  --on-primary: #FFFFFF;
  --secondary: #F59E0B;
  --secondary-strong: #B45309;
  --on-secondary: #0F172A;
  --accent: #DB2777;
  --accent-strong: #9D174D;
  --on-accent: #FFFFFF;
  --violet: #7C3AED;
  --violet-strong: #5B21B6;

  --success: #15803D;
  --success-soft: #DCFCE7;
  --success-line: #86EFAC;
  --warn: #B45309;
  --warn-soft: #FEF3C7;
  --warn-line: #FCD34D;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --danger-line: #FCA5A5;

  --bg: #EFF6FF;
  --fg: #0F172A;
  --card: #FFFFFF;
  --muted: #F1F5FD;
  --muted-fg: #475569;
  --border: #DBE6FB;
  --border-strong: #BFD3F7;
  --ring: #2563EB;

  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius: 18px;
  --radius-sm: 12px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: 'Baloo 2', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
  color: var(--fg);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 8% 12%, rgba(245, 158, 11, .16) 0 90px, transparent 91px),
    radial-gradient(circle at 92% 18%, rgba(219, 39, 119, .12) 0 70px, transparent 71px),
    radial-gradient(circle at 85% 88%, rgba(37, 99, 235, .12) 0 120px, transparent 121px),
    radial-gradient(circle at 10% 92%, rgba(124, 58, 237, .10) 0 80px, transparent 81px);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.15; margin: 0; font-weight: 800; }
p { margin: 0; }
a { color: var(--primary); }
[hidden] { display: none !important; }

:focus-visible {
  outline: 4px solid var(--ring);
  outline-offset: 3px;
  border-radius: 12px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon { display: inline-block; width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }
[data-icon] { display: inline-flex; }

/* ---------- Bố cục ---------- */
.app {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-7);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.screen { display: flex; flex-direction: column; gap: var(--space-5); flex: 1; }

/* ---------- Thẻ đất sét ---------- */
.card {
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 0 var(--border-strong), 0 18px 36px rgba(37, 99, 235, .10);
  padding: var(--space-5);
}

/* ---------- Thanh trên cùng ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.topbar-title {
  flex: 1;
  font-size: clamp(1.4rem, 4.5vw, 2rem);
  color: var(--primary-strong);
}

.icon-btn {
  width: 60px; height: 60px;
  display: inline-grid; place-items: center;
  font-size: 28px;
  color: var(--primary-strong);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--border-strong);
  cursor: pointer;
  text-decoration: none;
  transition: transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out), background-color 150ms;
  flex: none;
}
.icon-btn:hover { background: var(--muted); }
.icon-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-strong); }
.icon-btn[aria-pressed="false"] { color: var(--muted-fg); }

/* ---------- Nút bấm ---------- */
.btn {
  --btn-bg: var(--card);
  --btn-fg: var(--fg);
  --btn-shadow: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  padding: 10px 28px;
  font: 800 1.3rem/1.1 var(--font);
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 3px solid rgba(15, 23, 42, .06);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--btn-shadow), inset 0 -4px 0 rgba(0, 0, 0, .08);
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out), filter 150ms;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--btn-shadow), inset 0 -2px 0 rgba(0, 0, 0, .08); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn .icon { font-size: 1.3em; }

.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-shadow: var(--primary-strong); }
.btn-yellow  { --btn-bg: var(--secondary); --btn-fg: var(--on-secondary); --btn-shadow: var(--secondary-strong); }
.btn-pink    { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-shadow: var(--accent-strong); }
.btn-green   { --btn-bg: #16A34A; --btn-fg: #fff; --btn-shadow: #166534; }
.btn-white   { --btn-bg: var(--card); --btn-fg: var(--primary-strong); --btn-shadow: var(--border-strong); border-color: var(--border); }
.btn-danger  { --btn-bg: var(--card); --btn-fg: var(--danger); --btn-shadow: var(--danger-line); border-color: var(--danger-soft); }
.btn-xl { min-height: 76px; font-size: 1.7rem; padding: 12px 40px; border-radius: 26px; }
.btn-sm { min-height: 48px; font-size: 1.05rem; padding: 6px 18px; border-radius: 16px; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-4); justify-content: center; }

/* ---------- Viên thông tin ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 52px;
  padding: 6px 18px;
  font-weight: 700; font-size: 1.2rem;
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--border-strong);
  font-variant-numeric: tabular-nums;
}
.pill .icon { color: var(--primary); font-size: 1.3em; }

/* ---------- Thanh tiến độ ---------- */
.progress {
  height: 16px;
  background: var(--muted);
  border: 3px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
  border-radius: 999px;
  transition: width 300ms var(--ease-out);
}
.progress.green > span { background: linear-gradient(90deg, #4ADE80, #16A34A); }

/* =========================================================
   TRANG CHỦ
   ========================================================= */
.hero {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding-top: var(--space-5);
}
.mascot { width: 132px; height: 132px; }
.mascot svg { width: 100%; height: 100%; overflow: visible; }
.mascot .eye-lid { transform-origin: center; transform-box: fill-box; animation: blink 5s infinite; }
.mascot { animation: bob 3.2s ease-in-out infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(0); } 96% { transform: scaleY(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.hero h1 {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  color: var(--primary-strong);
  letter-spacing: -.5px;
}
.hero h1 .hl { color: var(--accent); }
.greet { font-size: clamp(1.15rem, 3.6vw, 1.45rem); color: var(--muted-fg); font-weight: 600; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
  margin-top: var(--space-4);
}

.menu-card {
  --c: var(--primary);
  --c-strong: var(--primary-strong);
  --c-soft: #DBEAFE;
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-6) var(--space-5) var(--space-5);
  text-align: center;
  text-decoration: none;
  color: var(--fg);
  background: var(--card);
  border: 4px solid var(--c-soft);
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 0 var(--c-strong), 0 22px 40px rgba(15, 23, 42, .10);
  cursor: pointer;
  transition: transform 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.menu-card:hover { transform: translateY(-4px); box-shadow: 0 14px 0 var(--c-strong), 0 26px 44px rgba(15, 23, 42, .14); }
.menu-card:active { transform: translateY(8px); box-shadow: 0 2px 0 var(--c-strong), 0 8px 16px rgba(15, 23, 42, .10); }
.menu-card.is-pink { --c: var(--accent); --c-strong: var(--accent-strong); --c-soft: #FCE7F3; }
.menu-card.is-violet { --c: var(--violet); --c-strong: var(--violet-strong); --c-soft: #EDE9FE; }

.menu-art {
  width: 100%;
  max-width: 260px;
  height: 130px;
  display: grid; place-items: center;
  background: var(--c-soft);
  border-radius: var(--radius-lg);
}
.menu-art svg { width: 88%; height: 88%; }
.menu-title { font-size: 2rem; font-weight: 800; color: var(--c-strong); line-height: 1.1; }
.menu-sub { font-size: 1.1rem; color: var(--muted-fg); font-weight: 600; }
.menu-go {
  margin-top: var(--space-2);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 26px;
  font-size: 1.3rem; font-weight: 800;
  color: #fff;
  background: var(--c);
  border-radius: 999px;
}

.home-footer {
  margin-top: auto;
  padding-top: var(--space-6);
  display: flex; justify-content: center; gap: var(--space-4); flex-wrap: wrap;
}

/* =========================================================
   TÍNH NHANH
   ========================================================= */
.start-card { display: flex; flex-direction: column; align-items: center; gap: var(--space-5); text-align: center; }
.start-card h2 { font-size: clamp(1.8rem, 6vw, 2.6rem); color: var(--primary-strong); }
.lead { font-size: 1.25rem; color: var(--muted-fg); font-weight: 600; }

.mastery-mini { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: var(--space-2); font-weight: 700; font-size: 1.15rem; }
.mastery-mini b { color: var(--success); font-size: 1.4rem; }

.choice-group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.choice-group legend { font-weight: 800; font-size: 1.2rem; margin-bottom: var(--space-3); padding: 0; }
.seg { display: flex; gap: var(--space-3); flex-wrap: wrap; justify-content: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  min-width: 96px; min-height: 64px;
  display: inline-grid; place-items: center;
  padding: 6px 18px;
  font-size: 1.6rem; font-weight: 800;
  color: var(--primary-strong);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--border-strong);
  cursor: pointer;
  transition: transform 150ms var(--ease-out), box-shadow 150ms, background-color 150ms, color 150ms;
}
.seg label small { display: block; font-size: .85rem; font-weight: 600; color: inherit; opacity: .8; line-height: 1; }
.seg input:checked + label { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 5px 0 var(--primary-strong); }
.seg input:focus-visible + label { outline: 4px solid var(--ring); outline-offset: 3px; }
.seg label:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-strong); }

.play-status { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.play-status .spacer { flex: 1; }

.question-card {
  display: grid; place-items: center;
  padding: var(--space-5) var(--space-4);
  min-height: 190px;
  transition: background-color 200ms, border-color 200ms;
}
.question {
  display: flex; align-items: center; justify-content: center; gap: .25em;
  font-size: clamp(3.6rem, 15vw, 7rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.question .op { color: var(--accent); }
.question .eq { color: var(--muted-fg); }
.ans-slot {
  min-width: 1.4em;
  padding: 0 .12em;
  text-align: center;
  color: var(--primary);
  background: var(--muted);
  border: 4px dashed var(--border-strong);
  border-radius: 22px;
}
.question-card.is-correct { background: var(--success-soft); border-color: var(--success-line); }
.question-card.is-correct .ans-slot { color: var(--success); border-style: solid; border-color: var(--success-line); background: #fff; }
.question-card.is-wrong { background: var(--warn-soft); border-color: var(--warn-line); }
.question-card.is-wrong .ans-slot { color: var(--success); border-style: solid; border-color: var(--success-line); background: #fff; }
.question-card.pop .question { animation: pop 260ms var(--ease-spring); }
.question-card.is-wrong .question { animation: shake 420ms ease-in-out; }

@keyframes pop { from { transform: scale(.85); opacity: .3; } to { transform: scale(1); opacity: 1; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); } 40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(6px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
@media (min-width: 640px) { .keypad { grid-template-columns: repeat(6, 1fr); gap: var(--space-4); } }

.key {
  --k: var(--primary);
  min-height: 78px;
  display: grid; place-items: center;
  font: 800 clamp(2.2rem, 8vw, 3rem)/1 var(--font);
  color: var(--k);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--k), 0 10px 18px rgba(15, 23, 42, .08);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out), background-color 150ms;
}
.key:hover { background: var(--muted); }
.key:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--k); }
.key:disabled { cursor: default; }
.key.key-correct { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.key.key-wrong { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.key.key-hint { background: var(--success-soft); border-color: #16A34A; color: var(--success); animation: pulse 700ms ease-in-out 2; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* Lớp phủ tạm dừng */
.overlay {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid; place-items: center;
  padding: var(--space-4);
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(4px);
}
.overlay .card { width: min(440px, 100%); text-align: center; display: flex; flex-direction: column; gap: var(--space-4); align-items: stretch; }
.overlay h2 { font-size: 2rem; color: var(--primary-strong); }

/* Kết quả */
.result-hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.result-hero h2 { font-size: clamp(2rem, 7vw, 3rem); color: var(--accent); }
.result-hero .big { font-size: 1.4rem; font-weight: 700; }
.result-hero .compare { font-size: 1.15rem; color: var(--success); font-weight: 700; }
.stars { display: flex; gap: 6px; font-size: 64px; }
.stars .icon { width: 64px; height: 64px; }
.stars .on { color: var(--secondary); filter: drop-shadow(0 4px 0 var(--secondary-strong)); }
.stars .off { color: var(--border-strong); }
.stars .on:nth-child(1) { animation: starIn 400ms var(--ease-spring) 100ms both; }
.stars .on:nth-child(2) { animation: starIn 400ms var(--ease-spring) 300ms both; }
.stars .on:nth-child(3) { animation: starIn 400ms var(--ease-spring) 500ms both; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
}
.stat {
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--border-strong);
  padding: var(--space-4);
  text-align: center;
}
.stat .label { font-size: 1rem; color: var(--muted-fg); font-weight: 600; }
.stat .value { font-size: 1.9rem; font-weight: 800; color: var(--primary-strong); font-variant-numeric: tabular-nums; line-height: 1.2; }

.panel-title { font-size: 1.4rem; color: var(--primary-strong); display: flex; align-items: center; gap: 10px; }
.hint { color: var(--muted-fg); font-size: 1rem; }

.group { margin-top: var(--space-5); }
.group h4 { margin: 0 0 var(--space-3); font-size: 1.15rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 30px; padding: 0 10px;
  border-radius: 999px; font-size: 1rem; font-weight: 800;
}
.lv-fast .badge, .badge.lv-fast { background: var(--success-soft); color: var(--success); }
.lv-ok .badge, .badge.lv-ok { background: var(--warn-soft); color: var(--warn); }
.lv-weak .badge, .badge.lv-weak { background: var(--danger-soft); color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; flex-direction: column;
  padding: 6px 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--muted);
  line-height: 1.2;
}
.chip b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.chip small { font-size: .9rem; color: var(--muted-fg); font-weight: 600; }
.chip.lv-fast { background: var(--success-soft); border-color: var(--success-line); }
.chip.lv-ok { background: var(--warn-soft); border-color: var(--warn-line); }
.chip.lv-weak { background: var(--danger-soft); border-color: var(--danger-line); }
.chip .wrong { color: var(--danger); }
.empty-note { color: var(--muted-fg); font-style: italic; }

/* Thông báo nhỏ */
.toast {
  position: fixed;
  left: 50%; top: 18px;
  z-index: 60;
  transform: translate(-50%, -140%);
  padding: 12px 26px;
  font-size: 1.3rem; font-weight: 800;
  color: #fff;
  background: var(--violet);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--violet-strong), 0 12px 30px rgba(15, 23, 42, .2);
  transition: transform 300ms var(--ease-spring);
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden; text-overflow: ellipsis;
}
.toast.show { transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* =========================================================
   TOÁN TƯ DUY
   ========================================================= */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-5);
}
.game-card {
  --c: var(--primary); --c-strong: var(--primary-strong); --c-soft: #DBEAFE;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-5) var(--space-4) var(--space-4);
  font-family: var(--font);
  color: var(--fg);
  text-align: center;
  background: var(--card);
  border: 4px solid var(--c-soft);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 0 var(--c-strong);
  cursor: pointer;
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}
.game-card:hover { transform: translateY(-3px); box-shadow: 0 11px 0 var(--c-strong); }
.game-card:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--c-strong); }
.game-card .preview {
  width: 100%; min-height: 84px;
  display: grid; place-items: center;
  padding: 8px;
  font-size: 2rem; letter-spacing: 2px; line-height: 1.2;
  background: var(--c-soft);
  border-radius: var(--radius);
}
.game-card .g-title { font-size: 1.5rem; font-weight: 800; color: var(--c-strong); line-height: 1.1; }
.game-card .g-desc { font-size: 1rem; color: var(--muted-fg); font-weight: 600; }
.game-card .g-stars { display: flex; gap: 2px; font-size: 22px; }
.game-card .g-stars .on { color: var(--secondary); }
.game-card .g-stars .off { color: var(--border-strong); }

.c-blue   { --c: #2563EB; --c-strong: #1E40AF; --c-soft: #DBEAFE; }
.c-pink   { --c: #DB2777; --c-strong: #9D174D; --c-soft: #FCE7F3; }
.c-yellow { --c: #D97706; --c-strong: #92400E; --c-soft: #FEF3C7; }
.c-green  { --c: #16A34A; --c-strong: #166534; --c-soft: #DCFCE7; }
.c-violet { --c: #7C3AED; --c-strong: #5B21B6; --c-soft: #EDE9FE; }
.c-teal   { --c: #0D9488; --c-strong: #115E59; --c-soft: #CCFBF1; }

.dots { display: flex; gap: 8px; flex-wrap: wrap; }
.dots span {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--border-strong);
}
.dots span.done { background: var(--success-line); border-color: #16A34A; }
.dots span.miss { background: var(--warn-line); border-color: var(--secondary-strong); }
.dots span.now { background: var(--secondary); border-color: var(--secondary-strong); transform: scale(1.2); }

.prompt {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  text-align: center;
  font-size: clamp(1.6rem, 5.5vw, 2.4rem);
  font-weight: 800;
  color: var(--primary-strong);
}
.prompt em { font-style: normal; color: var(--accent); text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 6px; }

.stage {
  min-height: 170px;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
}
.stage-emoji { font-size: clamp(2.4rem, 9vw, 3.6rem); line-height: 1; }
.slot-q {
  width: clamp(64px, 16vw, 92px); height: clamp(64px, 16vw, 92px);
  display: grid; place-items: center;
  font-size: clamp(2.2rem, 8vw, 3.2rem); font-weight: 800;
  color: var(--accent);
  background: #FCE7F3;
  border: 4px dashed var(--accent);
  border-radius: 22px;
}
.slot-q.filled { border-style: solid; background: var(--success-soft); border-color: #16A34A; color: inherit; }

.num-bubble {
  width: clamp(60px, 15vw, 88px); height: clamp(60px, 15vw, 88px);
  display: grid; place-items: center;
  font-size: clamp(2rem, 7vw, 3rem); font-weight: 800;
  color: var(--primary-strong);
  background: #DBEAFE;
  border: 3px solid var(--border-strong);
  border-radius: 50%;
}

.choices {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: var(--space-4);
}
.choice {
  min-width: 110px; min-height: 104px;
  display: grid; place-items: center;
  padding: 10px 18px;
  font: 800 clamp(2.4rem, 9vw, 3.4rem)/1 var(--font);
  color: var(--primary-strong);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 26px;
  box-shadow: 0 7px 0 var(--border-strong), 0 12px 20px rgba(15, 23, 42, .08);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out), background-color 150ms, opacity 200ms;
}
.choice:hover { background: var(--muted); }
.choice:active { transform: translateY(6px); box-shadow: 0 1px 0 var(--border-strong); }
.choice.is-right { background: var(--success-soft); border-color: #16A34A; box-shadow: 0 7px 0 #16A34A; }
.choice.is-wrong { background: var(--danger-soft); border-color: var(--danger-line); opacity: .55; animation: shake 420ms ease-in-out; }
.choice:disabled { cursor: default; }

.choices.panels { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.choice.panel {
  min-height: 200px;
  padding: var(--space-4);
  align-content: center;
}
.panel-items { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4px; max-width: 100%; }
.panel-items span { line-height: 1.1; }

/* Khung 10 ô (ten-frame) & xúc xắc */
.tenframe {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 6px; padding: 8px;
  background: #1E40AF;
  border-radius: 16px;
  width: min(380px, 100%);
}
.tenframe span { aspect-ratio: 1; background: #fff; border-radius: 10px; display: grid; place-items: center; }
.tenframe span i, .dice span i {
  width: 72%; height: 72%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FDA4AF, #DB2777 70%);
}
.dice {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  width: min(220px, 70vw); aspect-ratio: 1; padding: 16px;
  background: #fff;
  border: 4px solid var(--border-strong);
  border-radius: 28px;
  box-shadow: 0 6px 0 var(--border-strong);
}
.dice span { display: grid; place-items: center; }
.cover {
  width: min(380px, 100%); min-height: 150px;
  display: grid; place-items: center;
  font-size: 4rem; font-weight: 800; color: #fff;
  background: repeating-linear-gradient(45deg, var(--violet), var(--violet) 18px, #8B5CF6 18px, #8B5CF6 36px);
  border-radius: 24px;
}

/* Ngôi nhà số */
.house { display: flex; flex-direction: column; align-items: center; width: min(320px, 90%); }
.house .roof {
  width: 100%; height: 120px;
  display: grid; place-items: end center;
  padding-bottom: 10px;
  font-size: 3.2rem; font-weight: 800; color: #fff;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.house .rooms {
  width: 86%;
  display: grid; grid-template-columns: 1fr 1fr;
  border: 4px solid var(--accent-strong);
  border-top: 0;
  background: #fff;
  border-radius: 0 0 18px 18px;
  overflow: hidden;
}
.house .room {
  min-height: 110px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 3rem; font-weight: 800;
  color: var(--primary-strong);
  padding: 8px;
}
.house .room + .room { border-left: 4px solid var(--accent-strong); }
.house .room .mini { font-size: 1rem; letter-spacing: 1px; line-height: 1; color: var(--accent); }
.house .room .slot-q { width: 76px; height: 76px; }

.round-result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-4); }
.round-result h2 { font-size: clamp(2rem, 7vw, 3rem); color: var(--accent); }

/* =========================================================
   GÓC BỐ MẸ
   ========================================================= */
.gate { max-width: 460px; margin: var(--space-6) auto 0; text-align: center; display: flex; flex-direction: column; gap: var(--space-4); }
.gate h2 { font-size: 1.8rem; color: var(--primary-strong); }
.gate .q { font-size: 2.2rem; font-weight: 800; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field label { font-weight: 700; }
.field .help { font-size: .95rem; color: var(--muted-fg); }
.input {
  min-height: 56px;
  padding: 8px 16px;
  font: 700 1.3rem var(--font);
  color: var(--fg);
  background: #fff;
  border: 3px solid var(--border-strong);
  border-radius: 16px;
  width: 100%;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37, 99, 235, .25); }
.field-error { color: var(--danger); font-weight: 700; min-height: 1.5em; }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; font-weight: 700; cursor: pointer; }
.check input { width: 28px; height: 28px; accent-color: var(--primary); cursor: pointer; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.section-head h2 { font-size: 1.6rem; color: var(--primary-strong); display: flex; align-items: center; gap: 10px; }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: 1rem; font-weight: 600; margin-bottom: var(--space-4); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 26px; height: 26px; border-radius: 8px; display: inline-grid; place-items: center; font-style: normal; font-size: .9rem; font-weight: 800; border: 2px solid; }

.grids { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-5); }
.grid-wrap h3 { font-size: 1.25rem; margin-bottom: var(--space-2); }
.grid-wrap .axis { font-size: .9rem; color: var(--muted-fg); margin-bottom: var(--space-2); }
.fact-table { border-collapse: separate; border-spacing: 3px; width: 100%; table-layout: fixed; }
.fact-table th { font-size: .9rem; font-weight: 800; color: var(--muted-fg); padding: 2px 0; }
.fact-table th.corner { color: var(--accent); font-size: 1.1rem; }
.fact-table td { padding: 0; }
.cell {
  width: 100%; aspect-ratio: 1;
  min-height: 26px;
  display: grid; place-items: center;
  padding: 0;
  font: 800 .85rem var(--font);
  border: 2px solid;
  border-radius: 7px;
  cursor: pointer;
}
.cell.lv-none { background: #F8FAFC; border-color: #E2E8F0; color: #94A3B8; }
.cell.lv-fast, .legend i.lv-fast { background: #BBF7D0; border-color: #16A34A; color: #14532D; }
.cell.lv-ok,   .legend i.lv-ok   { background: #FDE68A; border-color: #D97706; color: #78350F; }
.cell.lv-weak, .legend i.lv-weak { background: #FECACA; border-color: #DC2626; color: #7F1D1D; }
.legend i.lv-none { background: #F8FAFC; border-color: #CBD5E1; color: #94A3B8; }
.cell.sel { outline: 3px solid var(--primary); outline-offset: 1px; }

.fact-detail { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); background: var(--muted); border-radius: var(--radius); min-height: 56px; font-weight: 600; }

.table-scroll { overflow-x: auto; }
.hist { width: 100%; border-collapse: collapse; font-size: 1rem; }
.hist th, .hist td { padding: 10px 8px; text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
.hist th { color: var(--muted-fg); font-size: .9rem; }
.hist td.num { font-variant-numeric: tabular-nums; }
.bar { display: inline-block; height: 12px; border-radius: 6px; background: var(--primary); vertical-align: middle; margin-left: 8px; min-width: 4px; }

.logic-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); }
.logic-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px; background: var(--muted); border-radius: var(--radius); font-weight: 700; }
.logic-item .g-stars .on { color: var(--secondary); }
.logic-item .g-stars .off { color: var(--border-strong); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); }

.tips details {
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  background: #fff;
}
.tips details + details { margin-top: var(--space-3); }
.tips summary { font-weight: 800; font-size: 1.15rem; cursor: pointer; color: var(--primary-strong); min-height: 36px; display: flex; align-items: center; }
.tips ul { margin: var(--space-2) 0 0; padding-left: 1.3em; }
.tips li + li { margin-top: 6px; }

/* =========================================================
   HỒ SƠ TỪNG BÉ
   ========================================================= */
/* màu lấy từ lớp .c-blue / .c-pink ... gắn kèm */
.avatar {
  width: 96px; height: 96px;
  display: inline-grid; place-items: center;
  flex: none;
  font-size: 56px; line-height: 1;
  background: var(--c-soft);
  border: 4px solid var(--c-strong);
  border-radius: 50%;
}
.avatar-sm { width: 40px; height: 40px; font-size: 24px; border-width: 3px; }
.avatar-md { width: 64px; height: 64px; font-size: 38px; }
.avatar-lg { width: 128px; height: 128px; font-size: 76px; border-width: 5px; }

.who-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 60px;
  padding: 6px 16px 6px 8px;
  font: 800 1.15rem var(--font);
  color: var(--fg);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--border-strong);
  cursor: pointer;
  text-decoration: none;
  max-width: 46vw;
  transition: transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.who-chip:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-strong); }
.who-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; text-align: left; }
.who-text small { font-size: .85rem; font-weight: 700; color: var(--muted-fg); }
.who-chip.who-big {
  margin-top: var(--space-3);
  min-height: 84px;
  padding: 8px 10px 8px 10px;
  gap: 12px;
  font-size: 1.5rem;
  max-width: calc(100vw - 32px);
  border-color: var(--border-strong);
  box-shadow: 0 6px 0 var(--border-strong), 0 14px 26px rgba(37, 99, 235, .12);
}
.who-switch {
  display: inline-flex; align-items: center;
  min-height: 48px;
  padding: 4px 18px;
  font-size: 1.1rem; font-weight: 800;
  color: #fff;
  background: var(--primary);
  border-radius: 999px;
  white-space: nowrap;
}

.profile-card.add-card {
  color: var(--primary-strong);
  border: 4px dashed var(--border-strong);
  box-shadow: none;
  background: transparent;
  text-decoration: none;
  justify-content: center;
}
.profile-card.add-card .plus {
  width: 128px; height: 128px;
  display: grid; place-items: center;
  font-size: 72px; font-weight: 800; line-height: 1;
  border-radius: 50%;
  background: var(--muted);
}
.profile-card.add-card:hover, .profile-card.add-card:active { box-shadow: none; }
@media (max-width: 480px) { .profile-card.add-card .plus { width: 96px; height: 96px; font-size: 56px; } }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Màn hình "Ai đang học?" */
.picker {
  position: fixed; inset: 0;
  z-index: 40;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-4);
  background: var(--bg);
}
.picker h1 { font-size: clamp(2rem, 7vw, 3.2rem); color: var(--primary-strong); text-align: center; }
.picker-grid {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: var(--space-5);
  max-width: 900px;
}
.profile-card {
  width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  font: 800 1.6rem/1.1 var(--font);
  color: var(--c-strong);
  background: var(--card);
  border: 4px solid var(--c-soft);
  border-radius: var(--radius-xl);
  box-shadow: 0 9px 0 var(--c-strong);
  cursor: pointer;
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}
.profile-card:hover { transform: translateY(-3px); box-shadow: 0 12px 0 var(--c-strong); }
.profile-card:active { transform: translateY(7px); box-shadow: 0 2px 0 var(--c-strong); }
.profile-card .p-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) {
  .profile-card { width: 150px; font-size: 1.3rem; }
  .profile-card .avatar-lg { width: 96px; height: 96px; font-size: 56px; }
}

/* Chọn bé trong Góc bố mẹ */
.kid-tabs { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.kid-tabs .label { font-weight: 800; margin-right: 4px; }
.kid-tab {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: 6px 18px 6px 8px;
  font: 800 1.1rem var(--font);
  color: var(--fg);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--border-strong);
  cursor: pointer;
}
.kid-tab[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-strong); }

.compare-table td .avatar-sm { vertical-align: middle; margin-right: 6px; }
.trend-up { color: var(--success); font-weight: 800; }
.trend-down { color: var(--danger); font-weight: 800; }
.trend-flat { color: var(--muted-fg); font-weight: 700; }

.profile-list { display: flex; flex-direction: column; gap: var(--space-4); }
.profile-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--muted);
  border-radius: var(--radius-lg);
  align-items: start;
}
.profile-row .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); }
.profile-row .actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--space-3); }
.pick-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pick-row button {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  font-size: 28px;
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  padding: 0;
}
.pick-row button[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .3); }
.pick-row .swatch { width: 30px; height: 30px; border-radius: 50%; background: var(--c); }
@media (max-width: 480px) {
  .profile-row { grid-template-columns: 1fr; }
  .topbar .who-chip { padding: 6px; min-height: 54px; }
  .topbar .who-name { display: none; }
}

/* =========================================================
   SAO THƯỞNG & KHO QUÀ
   ========================================================= */
.star-ico { color: var(--secondary); filter: drop-shadow(0 2px 0 var(--secondary-strong)); }

/* Thưởng sao ở màn hình kết quả */
.star-award {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  width: 100%; max-width: 520px;
  margin-top: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--warn-soft);
  border: 3px solid var(--warn-line);
  border-radius: var(--radius-lg);
}
.star-award .plus {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: clamp(2.2rem, 8vw, 3rem); font-weight: 800; line-height: 1;
  color: var(--secondary-strong);
  animation: pop 500ms var(--ease-spring) 600ms both;
}
.star-award .plus .icon { width: 1em; height: 1em; }
.star-award .total { font-weight: 700; font-size: 1.15rem; }
.star-award .goal { width: 100%; display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--muted-fg); text-align: center; }
.star-award.no-award { background: var(--muted); border-color: var(--border); }

/* Số sao lớn ở Kho quà */
.wallet {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  text-align: center;
}
.wallet .amount {
  display: inline-flex; align-items: center; gap: 12px;
  font-size: clamp(3rem, 12vw, 4.6rem); font-weight: 800; line-height: 1;
  color: var(--secondary-strong);
  font-variant-numeric: tabular-nums;
}
.wallet .amount .icon { width: .9em; height: .9em; }
.wallet .sub { color: var(--muted-fg); font-weight: 600; font-size: 1.1rem; }

.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--space-5);
}
.reward-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  background: var(--card);
  border: 4px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 0 var(--border-strong);
}
.reward-card.ready { border-color: var(--warn-line); box-shadow: 0 8px 0 var(--secondary-strong); }
.reward-card .r-icon {
  width: 110px; height: 110px;
  display: grid; place-items: center;
  font-size: 64px; line-height: 1;
  background: var(--muted);
  border-radius: 50%;
}
.reward-card.ready .r-icon { background: var(--warn-soft); animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-8deg); } 90% { transform: rotate(8deg); } 95% { transform: rotate(-4deg); } }
.reward-card .r-name { font-size: 1.5rem; font-weight: 800; color: var(--primary-strong); line-height: 1.15; }
.reward-card .r-cost { display: inline-flex; align-items: center; gap: 6px; font-size: 1.3rem; font-weight: 800; color: var(--secondary-strong); }
.reward-card .progress { width: 100%; }
.reward-card .r-left { font-weight: 600; color: var(--muted-fg); }

.redeem-list { display: flex; flex-direction: column; gap: var(--space-3); }
.redeem-item {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--muted);
  border-radius: var(--radius);
  font-weight: 700;
}
.redeem-item .ri-icon { font-size: 2rem; line-height: 1; }
.redeem-item .ri-main { flex: 1; min-width: 160px; }
.redeem-item .ri-main small { display: block; font-weight: 600; color: var(--muted-fg); }
.status {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 2px 14px;
  border-radius: 999px;
  font-size: .95rem; font-weight: 800;
}
.status.wait { background: var(--warn-soft); color: var(--warn); }
.status.done { background: var(--success-soft); color: var(--success); }

/* Hộp xác nhận của bố mẹ */
.gate-modal { width: min(440px, 100%); display: flex; flex-direction: column; gap: var(--space-3); text-align: center; }
.gate-modal h2 { font-size: 1.7rem; color: var(--primary-strong); }
.gate-modal .gate-q { font-size: 2.2rem; font-weight: 800; }
.gate-art { font-size: 64px; line-height: 1; }

/* Thẻ Kho quà ở trang chủ */
.menu-card.is-gold { --c: #D97706; --c-strong: #92400E; --c-soft: #FEF3C7; }
.menu-stars { display: inline-flex; align-items: center; gap: 6px; font-size: 1.25rem; font-weight: 800; color: var(--secondary-strong); }

/* Góc bố mẹ: quản lý quà */
.reward-edit { display: flex; flex-direction: column; gap: var(--space-3); }
.reward-row {
  display: grid;
  grid-template-columns: auto 1fr 140px auto;
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-3);
  background: var(--muted);
  border-radius: var(--radius);
}
.reward-row .r-icon-btn {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  font-size: 32px;
  background: #fff;
  border: 3px solid var(--border-strong);
  border-radius: 16px;
  cursor: pointer;
}
.reward-row .pick-row { grid-column: 1 / -1; }
@media (max-width: 560px) {
  .reward-row { grid-template-columns: auto 1fr; }
  .reward-row .cost-field, .reward-row .row-actions { grid-column: span 1; }
}
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: end; }
.inline-form .field { flex: 1; min-width: 160px; }
.star-log { font-size: .98rem; }
.star-log .plus { color: var(--success); font-weight: 800; }
.star-log .minus { color: var(--danger); font-weight: 800; }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 480px) {
  body { font-size: 17px; }
  .app { padding: var(--space-3) var(--space-3) var(--space-6); }
  .card { padding: var(--space-4); border-radius: 26px; }
  .icon-btn { width: 54px; height: 54px; font-size: 24px; }
  .key { min-height: 70px; }
  .choice { min-width: 92px; min-height: 92px; }
  .choice.panel { min-height: 170px; }
  .question-card { min-height: 160px; }
}

/* Màn hình thấp (điện thoại xoay ngang) */
@media (max-height: 520px) and (orientation: landscape) {
  .question-card { min-height: 110px; padding: var(--space-3); }
  .question { font-size: 3.2rem; }
  .key { min-height: 56px; font-size: 2rem; }
  .keypad { grid-template-columns: repeat(6, 1fr); }
}

/* ---------- Giảm chuyển động ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .mascot, .mascot .eye-lid { animation: none !important; }
}
