:root {
  --bg: #fff8f0;
  --card: #fff;
  --primary: #ff8a5b;
  --primary-d: #ff6b3d;
  --pink: #ffb3ba;
  --mint: #b5ead7;
  --yellow: #ffe39d;
  --blue: #b8e0f6;
  --purple: #d7b9ff;
  --text: #3d2c2c;
  --muted: #7a6a6a;
  --shadow: 0 6px 18px rgba(255, 138, 91, 0.18);
  --radius: 22px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Comic Sans MS', 'Be Vietnam Pro', 'Nunito', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(circle at 10% 20%, var(--yellow) 0, transparent 30%),
    radial-gradient(circle at 90% 10%, var(--mint) 0, transparent 32%),
    radial-gradient(circle at 80% 90%, var(--pink) 0, transparent 30%),
    var(--bg);
  background-attachment: fixed;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

header.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 12px;
}
.brand {
  font-size: 28px;
  font-weight: bold;
  color: var(--primary-d);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand .mascot { font-size: 36px; }
.topbar .nav-links { display: flex; gap: 10px; }

h1 { font-size: 36px; margin: 12px 0 6px; }
h2 { font-size: 24px; margin: 18px 0 10px; }
p { line-height: 1.55; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s, background 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--primary-d); }
.btn:active { transform: scale(0.97); }
.btn.big { font-size: 22px; padding: 16px 32px; }
.btn.ghost {
  background: transparent;
  color: var(--primary-d);
  border: 2px solid var(--primary);
}
.btn.ghost:hover { background: var(--primary); color: #fff; }
.btn.danger { background: #ff5b6b; }
.btn.danger:hover { background: #e44a59; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: var(--radius-sm);
  border: 2px solid #f3d8c8;
  background: #fffdfb;
  font-family: inherit;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
}
label { display: block; margin: 8px 0 6px; font-weight: bold; color: var(--muted); }

.grid {
  display: grid; gap: 16px;
}
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

/* Home */
.hero {
  text-align: center;
  padding: 40px 20px 20px;
}
.hero .mascot { font-size: 88px; display: block; margin-bottom: 12px; }
.hero h1 { font-size: 48px; color: var(--primary-d); margin: 0 0 8px; }
.hero .sub { font-size: 20px; color: var(--muted); }

.profile-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
  border: 3px solid transparent;
}
.profile-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.profile-card .avatar { font-size: 72px; line-height: 1; }
.profile-card .name { font-size: 22px; font-weight: bold; margin-top: 8px; }
.profile-card .level { font-size: 14px; color: var(--muted); }

/* Letters grid (mầm non) */
.letter-tile {
  background: linear-gradient(135deg, #fff, #fff8f0);
  border-radius: 22px;
  padding: 20px 12px 14px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.15s;
  user-select: none;
  border: 3px solid transparent;
  position: relative;
}
.letter-tile:hover { transform: scale(1.06) translateY(-2px); border-color: var(--primary); }
.letter-tile:active { transform: scale(0.98); }
.letter-tile .char {
  font-size: 64px; font-weight: bold; color: var(--primary-d); line-height: 1;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}
.letter-tile .ex { font-size: 16px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.letter-tile .emoji { font-size: 56px; line-height: 1; margin-top: 8px; }

/* W-F: Lesson progress bar */
.lesson-progress {
  display: flex; align-items: center; gap: 10px;
  background: #fff8f0; border-radius: 999px; padding: 8px 14px; margin: 12px 0;
}
.lesson-progress .bar {
  flex: 1; height: 14px; background: #f3d8c8; border-radius: 999px; overflow: hidden;
}
.lesson-progress .bar .fill {
  height: 100%; background: linear-gradient(90deg, var(--mint), var(--primary));
  border-radius: 999px; transition: width 0.4s ease;
}
.lesson-progress .count { font-weight: 700; color: var(--primary-d); font-size: 14px; white-space: nowrap; }

/* W-F: Reward overlay polish */
.reward-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; gap: 18px; padding: 20px;
}
.reward-overlay .big-emoji { font-size: 120px; animation: pop 0.5s ease-out; }
.reward-overlay .msg {
  background: #fff; padding: 18px 26px; border-radius: 22px;
  font-size: 22px; font-weight: 700; color: var(--primary-d); text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3); max-width: 90vw;
}

/* Topic chips */
.topic-chip {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.topic-chip:hover { transform: translateY(-3px); }
.topic-chip .emoji { font-size: 54px; }
.topic-chip .title { font-size: 20px; font-weight: bold; }

/* Word card (lớp 1) */
.word-card {
  text-align: center;
  padding: 28px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.word-card .emoji { font-size: 100px; display: block; }
.word-card .word {
  font-size: 64px; font-weight: bold;
  color: var(--primary-d);
  margin: 10px 0;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}
.steps {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  font-size: 28px; margin: 16px 0;
}
.step {
  background: #fff3e6;
  border-radius: 14px;
  padding: 8px 18px;
  opacity: 0.35;
  transition: opacity 0.25s, transform 0.25s, background 0.25s;
}
.step.active {
  opacity: 1;
  background: var(--yellow);
  transform: scale(1.18);
}
.step.final {
  background: var(--mint);
  color: var(--primary-d);
  font-weight: bold;
}

.toolbar {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
  margin-top: 18px;
}
.toolbar .btn { min-width: 130px; }

.stars { font-size: 32px; letter-spacing: 4px; }
.star-on { color: #ffc83a; }
.star-off { color: #e5d5c5; }

.banner {
  background: #fff3cd;
  border-left: 6px solid #ffc107;
  padding: 12px 16px;
  border-radius: 10px;
  margin: 12px 0;
  color: #5b4a00;
}
.banner.err {
  background: #ffe1e3;
  border-left-color: #ff5b6b;
  color: #6b1d23;
}
.banner.ok {
  background: #d6f5e3;
  border-left-color: #2ecc71;
  color: #1d5b3a;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--muted); }

table {
  width: 100%; border-collapse: collapse; margin-top: 10px;
}
th, td {
  padding: 10px 12px; border-bottom: 1px solid #f3d8c8; text-align: left;
}
th { background: #fff3e6; color: var(--primary-d); }

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-width: 90vw;
}
dialog::backdrop { background: rgba(0,0,0,0.4); }

/* Animations */
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.pop { animation: pop 0.35s ease-out; }

@keyframes wiggle {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}
.wiggle { animation: wiggle 0.5s ease-in-out; }

.reward-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; z-index: 999;
}
.reward-overlay .big-emoji { font-size: 160px; animation: pop 0.5s ease-out; }
.reward-overlay .msg { font-size: 28px; color: var(--primary-d); font-weight: bold; text-align: center; max-width: 90vw; }

/* Mascot */
.mascot { vertical-align: middle; line-height: 0; }
.mascot-svg { width: 100%; height: 100%; }
.mascot-state-idle .mascot-svg { animation: mascot-breathe 3s ease-in-out infinite; }
.mascot-state-happy .mascot-svg { animation: mascot-bounce 0.5s ease-out 2; }
.mascot-state-wiggle .mascot-svg { animation: mascot-wiggle 0.5s ease-in-out; }
.mascot-state-sad .mascot-svg { transform: rotate(-5deg); filter: saturate(0.5); }

@keyframes mascot-breathe {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
@keyframes mascot-bounce {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
@keyframes mascot-wiggle {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

/* Subject chip */
.subject-chip {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
  border: 3px solid transparent;
}
.subject-chip:hover { transform: translateY(-4px); border-color: var(--primary); }
.subject-chip .subject-name { font-size: 24px; font-weight: bold; margin-top: 8px; color: var(--primary-d); }
.subject-chip .subject-meta { font-size: 14px; color: var(--muted); }

/* Skill tree path */
.skill-path { position: relative; padding: 30px 0; }
.skill-node {
  position: relative;
  width: 90px; height: 90px;
  margin: 16px auto;
  border-radius: 50%;
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
  border: 4px solid var(--primary);
}
.skill-node.locked { background: #f0e8e0; border-color: #d4c4b4; cursor: not-allowed; opacity: 0.55; }
.skill-node.done { border-color: #2ecc71; }
.skill-node:not(.locked):hover { transform: scale(1.07); }
.skill-node .stars { font-size: 16px; }
.skill-node .icon { font-size: 36px; }
.skill-node-title { text-align: center; font-size: 14px; color: var(--text); max-width: 140px; margin: 0 auto; }

/* Math tile / shape tile */
.count-emoji { font-size: 64px; }
.compare-num { font-size: 80px; font-weight: bold; color: var(--primary-d); }

/* KPI tiles (admin stats) */
.kpi-grid { gap: 12px; }
.kpi {
  background: linear-gradient(135deg, var(--yellow), var(--mint));
  border-radius: 14px; padding: 14px; text-align: center;
}
.kpi .v { font-size: 28px; font-weight: bold; color: var(--primary-d); }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi.warn { background: linear-gradient(135deg, #ffe1e3, #fff3cd); }
.kpi.info { background: linear-gradient(135deg, var(--blue), var(--purple)); }
.kpi.ok   { background: linear-gradient(135deg, var(--mint), var(--yellow)); }

/* CMS layout (admin) */
.cms-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 480px; }
@media (max-width: 860px) { .cms-layout { grid-template-columns: 1fr; } }
.cms-tree {
  background: #fff8f0; border-radius: 14px; padding: 10px;
  max-height: 600px; overflow: auto; font-size: 14px;
  border: 1px solid #f3d8c8;
}
.cms-tree details { margin: 2px 0; }
.cms-tree summary { cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.cms-tree summary:hover { background: #fff3e6; }
.cms-tree .cms-item {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 8px;
  cursor: pointer;
}
.cms-tree .cms-item:hover { background: #ffe7d3; }
.cms-tree .cms-item.selected { background: var(--primary); color: #fff; }
.cms-tree .cms-add {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--mint); color: #1d5b3a; font-weight: bold;
  cursor: pointer; font-size: 12px;
}
.cms-tree .cms-add:hover { background: #98ddc0; }
.cms-editor {
  background: var(--card); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow);
}
.cms-editor h3 { margin-top: 0; }
.cms-editor textarea {
  width: 100%; min-height: 240px; font-family: 'Courier New', monospace; font-size: 13px;
  border-radius: 8px; border: 2px solid #f3d8c8; padding: 10px; resize: vertical;
}
.cms-editor .row { gap: 8px; }

/* V-B: child profile form (avatar picker + segmented gender + camera dialog) */
.add-child .field { margin-top: 12px; }
.add-child .field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.add-child input[type=text], .add-child select {
  width: 100%; max-width: 320px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid #f3d8c8; background: #fff; font-size: 16px;
}
.add-child input[type=text]:focus, .add-child select:focus { outline: none; border-color: var(--primary); }
.seg { display: inline-flex; gap: 0; background: #fff3e6; border-radius: 14px; padding: 4px; border: 2px solid #f3d8c8; }
.seg-opt { cursor: pointer; padding: 8px 18px; border-radius: 10px; font-weight: 600; color: var(--muted); user-select: none; }
.seg-opt input { display: none; }
.seg-opt:has(input:checked) { background: var(--primary); color: #fff; box-shadow: var(--shadow); }
.avatar-picker {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(64px, 72px));
  max-width: 460px;
}
.avatar-picker-hint { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.avatar-picker .avt {
  position: relative; aspect-ratio: 1/1; border-radius: 14px;
  border: 3px solid transparent; cursor: pointer; overflow: hidden;
  background: #fff; transition: transform 0.12s ease, border-color 0.12s ease;
  max-width: 72px;
}
.avatar-picker .avt:hover { transform: translateY(-2px); }
.avatar-picker .avt img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-picker .avt input { position: absolute; opacity: 0; width: 0; height: 0; }
.avatar-picker .avt:has(input:checked) { border-color: var(--primary); box-shadow: var(--shadow); }
.avatar-picker .avt.custom {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #ffe7d3, #ffd5e1);
  font-size: 11px; line-height: 1.15; color: var(--primary-d); font-weight: 700; text-align: center;
  padding: 4px;
}
.cam-dialog { border: none; border-radius: 18px; padding: 18px; box-shadow: var(--shadow); max-width: 420px; }
.cam-dialog::backdrop { background: rgba(0,0,0,0.4); }
.profile-card .avatar img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }

/* W-C: admin tables — horizontal scroll + truncate long cells */
.card { overflow: visible; }
.t-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 10px 0; border-radius: 12px; }
.t-wrap table { width: 100%; min-width: 640px; margin: 0; }
.t-wrap th, .t-wrap td { white-space: nowrap; }
.t-wrap td.wrap { white-space: normal; }
.t-wrap td.meta { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.t-wrap td.meta.open { white-space: normal; word-break: break-all; max-width: none; }
.t-wrap td code { font-size: 12px; background: #fff8f0; padding: 2px 6px; border-radius: 4px; }

/* Sticky header */
.t-wrap table thead th { position: sticky; top: 0; z-index: 1; }

/* W-D: Mobile responsive — phones (≤640px) and small tablets (≤860px) */
@media (max-width: 860px) {
  .container { padding: 16px 14px 60px; }
  h1 { font-size: 28px; }
  h2 { font-size: 22px; }
  .card { padding: 18px 16px; border-radius: 18px; }
}
@media (max-width: 640px) {
  html, body { font-size: 15px; }
  .container { padding: 12px 10px 80px; }
  header.topbar { flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
  .brand { font-size: 22px; }
  .brand .mascot { font-size: 26px; }
  .topbar .nav-links { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .topbar .nav-links .btn { padding: 8px 14px; font-size: 14px; }
  .card { padding: 14px 12px; border-radius: 16px; }
  h1 { font-size: 24px; }
  h2 { font-size: 19px; }
  h3 { font-size: 16px; }
  .btn { padding: 11px 18px; font-size: 16px; }
  .btn.big { font-size: 18px; padding: 13px 24px; }
  .row { flex-wrap: wrap; gap: 8px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; gap: 10px; }
  /* Hero — index */
  .hero-grid { grid-template-columns: 1fr !important; gap: 20px; }
  .hero-illustration { max-height: 220px; }
  /* Subject + feature cards */
  .subject-card, .feat-card { padding: 16px; }
  /* Auth tabs full-width */
  .auth-tabs { width: 100%; }
  /* CMS — collapse to single column */
  .cms-layout { grid-template-columns: 1fr !important; }
  .cms-tree { max-height: 320px; }
  /* Inputs */
  input[type=text], input[type=password], input[type=number], input[type=email], select, textarea {
    font-size: 16px; /* >= 16 prevents iOS zoom */
  }
  /* Tables sticky header off on mobile (smaller height) */
  .t-wrap { max-height: 60vh; }
  /* Avatar picker → smaller cells on phone */
  .avatar-picker { grid-template-columns: repeat(auto-fill, minmax(56px, 64px)); }
  .avatar-picker .avt { max-width: 64px; }
  /* Camera dialog full-width */
  .cam-dialog { max-width: 95vw; padding: 14px; }
  /* Feedback button */
  .feedback-fab { right: 12px !important; bottom: 12px !important; padding: 10px 14px !important; font-size: 14px !important; }
  /* Lesson page (W-F kid UI) */
  .lesson-letter { font-size: 56px !important; }
}
@media (max-width: 380px) {
  .brand { font-size: 18px; }
  h1 { font-size: 20px; }
  .btn { padding: 10px 14px; font-size: 14px; }
}

/* X-B: Hiệu ứng phù hợp tuổi — animations + reduced-motion safe. */
@keyframes mascot-blink {
  0%, 92%, 98%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}
@keyframes mascot-wave {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}
@keyframes mascot-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-12px) scale(1.05); }
  60% { transform: translateY(-12px) scale(1.05) rotate(8deg); }
}
@keyframes mascot-think {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(6deg); }
}
@keyframes mascot-encourage {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.mascot { display: inline-block; transition: transform 0.3s; }
.mascot-state-idle .m-eye { animation: mascot-blink 4s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.mascot-state-wave { animation: mascot-wave 0.8s ease-in-out 2; }
.mascot-state-celebrate, .mascot-state-happy { animation: mascot-jump 0.6s ease-out 2; }
.mascot-state-think { animation: mascot-think 1.6s ease-in-out infinite; }
.mascot-state-encourage, .mascot-state-sad { animation: mascot-encourage 0.4s ease-in-out 3; }

@keyframes bg-soft-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
body.bg-motion {
  background: linear-gradient(135deg, #fff5e6 0%, #ffe9d6 25%, #ffe4f3 50%, #e6f4ff 75%, #fff5e6 100%);
  background-size: 200% 200%;
  animation: bg-soft-shift 18s ease-in-out infinite;
}

@keyframes correct-pulse {
  0% { box-shadow: 0 0 0 0 rgba(127, 201, 169, 0.6); }
  50% { box-shadow: 0 0 0 12px rgba(127, 201, 169, 0); }
  100% { box-shadow: 0 0 0 0 rgba(127, 201, 169, 0); }
}
.correct-feedback { animation: correct-pulse 0.5s ease-out; }

@keyframes gentle-shake {
  0%, 100% { transform: translateX(0); }
  25%, 75% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
}
.wrong-feedback { animation: gentle-shake 0.35s ease-in-out; }

@keyframes star-burst {
  0% { opacity: 1; transform: translate(0,0) scale(0.4) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--dx, 60px), var(--dy, -60px)) scale(1) rotate(180deg); }
}
.star-burst {
  position: absolute; pointer-events: none;
  font-size: 28px; line-height: 1;
  animation: star-burst 0.9s ease-out forwards;
}

.skeleton {
  background: linear-gradient(90deg, #f0e7da 25%, #f7efe1 50%, #f0e7da 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  body.bg-motion { animation: none; background: #fff5e6; }
  .mascot-state-idle .m-eye,
  .mascot-state-wave,
  .mascot-state-celebrate, .mascot-state-happy,
  .mascot-state-think,
  .mascot-state-encourage, .mascot-state-sad,
  .correct-feedback, .wrong-feedback,
  .star-burst, .skeleton, .reveal-pulse { animation: none !important; }
}

/* X-C: Lesson sticky action bar (thumb zone) — Đọc / Hint / Tiếp. */
.lesson-action-bar {
  position: sticky;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  padding: 10px;
  margin: 14px -16px -16px;
  border-top: 2px solid #f3d8c8;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.05);
  border-radius: 0 0 18px 18px;
}
.lesson-action-bar .btn {
  padding: 14px 8px;
  min-height: 56px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
.lesson-action-bar .btn:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes revealPulse {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.15); }
  60% { transform: scale(0.95); }
}
.reveal-pulse { animation: revealPulse 0.8s ease-out; }

@media (max-width: 640px) {
  .lesson-action-bar .btn { padding: 12px 4px; min-height: 52px; font-size: 14px; }
  .lesson-action-bar { margin: 12px -12px -12px; }
}

/* X-E: Admin tab navigation. */
.admin-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  background: #fff; padding: 8px;
  border-radius: 14px; box-shadow: var(--shadow);
  margin-bottom: 16px;
  position: sticky; top: 0; z-index: 50;
}
.admin-tab {
  flex: 0 1 auto;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  transition: background 0.15s, color 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.admin-tab:hover { background: #fff3e6; }
.admin-tab.active { background: var(--primary); color: #fff; }
.admin-tab .tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px;
  background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700;
}
.admin-panel[hidden] { display: none !important; }

@media (max-width: 640px) {
  .admin-tabs { gap: 4px; padding: 6px; }
  .admin-tab { padding: 8px 10px; font-size: 13px; }
}

/* X-D: Admin chart containers — fix Chart.js maintainAspectRatio:false growing
   canvas vô hạn vì parent div không có height cố định. */
.chart-card { background: #fff; border-radius: 12px; padding: 14px; box-shadow: var(--shadow-sm, 0 1px 4px rgba(0,0,0,0.06)); }
.chart-card h3 { margin: 0 0 8px; }
.chart-box { position: relative; height: 240px; width: 100%; }
.chart-box canvas { max-height: 100%; }
@media (max-width: 640px) {
  .chart-box { height: 200px; }
}

/* F0: child-info avatar + name (topbar) */
.child-info { display: inline-flex; align-items: center; gap: 8px; }
.child-info .avatar-mini {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; background: #fde8d4;
  border: 2px solid var(--brand-2, #ffb366);
}
.child-info .child-name { font-weight: 600; color: var(--ink, #333); }

/* F4: Settings modal cho trang Học */
.settings-dlg {
  border: none; border-radius: 18px; padding: 0;
  background: #fff; box-shadow: 0 12px 36px rgba(0,0,0,0.25);
  width: min(440px, 92vw);
}
.settings-dlg::backdrop { background: rgba(0,0,0,0.35); }
.settings-form { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.settings-form h3 { margin: 0 0 4px; color: var(--brand, #f97316); }
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-row label { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.settings-row select,
.settings-row input[type=range] { width: 100%; }
.settings-row .badge {
  background: #fde8d4; color: #f97316; padding: 2px 8px;
  border-radius: 999px; font-weight: 700; font-size: 12px;
  margin-left: auto;
}
.settings-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }

/* A2: ảnh từ thư viện Pixabay (cache server) + fallback emoji */
.word-img {
  display: inline-flex; align-items: center; justify-content: center;
  position: relative; border-radius: 16px; overflow: hidden;
  background: linear-gradient(135deg, #fff5e8, #ffe5d0);
  box-shadow: 0 4px 14px rgba(255, 138, 91, 0.18);
  transition: transform .25s ease;
}
.word-img:hover { transform: scale(1.05) rotate(-2deg); }
.word-img img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: opacity .35s ease;
}
.word-img-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

/* ============================================================
   A3 + B1 + B2 + B4 + B6: animations + UI polish
   ============================================================ */

/* B4: living background — floating bubbles */
body.bg-motion::before,
body.bg-motion::after {
  content: '';
  position: fixed;
  pointer-events: none;
  z-index: 0;
  border-radius: 50%;
  filter: blur(3px);
  opacity: 0.55;
}
body.bg-motion::before {
  width: 220px; height: 220px;
  background: radial-gradient(circle at 30% 30%, #ffd8a8 0%, #ffba87 50%, transparent 70%);
  top: -60px; left: -60px;
  animation: float-a 18s ease-in-out infinite;
}
body.bg-motion::after {
  width: 260px; height: 260px;
  background: radial-gradient(circle at 70% 70%, #b8e0f6 0%, #87c5e8 50%, transparent 70%);
  bottom: -80px; right: -80px;
  animation: float-b 22s ease-in-out infinite;
}
@keyframes float-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40vw, 20vh) scale(1.15); }
  66% { transform: translate(70vw, 60vh) scale(0.9); }
}
@keyframes float-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-60vw, -50vh) scale(1.2); }
}
.container { position: relative; z-index: 1; }

/* B2: topbar slide-down on load */
.topbar.slide-down {
  animation: slide-down .55s cubic-bezier(.4, 1.6, .6, 1) both;
}
@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* B2: button ripple + active feedback */
.btn { position: relative; overflow: hidden; }
.btn::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, transparent 70%);
  opacity: 0; transition: opacity .25s;
}
.btn:hover:not(:disabled)::after { opacity: 1; }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn { transition: transform .12s, box-shadow .2s; }

/* A3: subject chips → richer cards */
.subject-chip {
  background: linear-gradient(140deg, #fff5e8 0%, #ffe5d0 100%);
  border: 3px solid transparent;
  border-radius: 22px;
  padding: 28px 18px 22px;
  position: relative;
  overflow: hidden;
  transition: transform .35s cubic-bezier(.4, 1.6, .6, 1), box-shadow .3s, border-color .25s;
}
.subject-chip::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.6) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform .8s;
}
.subject-chip:hover {
  transform: translateY(-8px) rotate(-1deg);
  box-shadow: 0 16px 36px rgba(255, 138, 91, 0.3);
  border-color: var(--primary);
}
.subject-chip:hover::before { transform: translateX(100%); }
.subject-chip .subject-name { font-size: 26px; margin-top: 14px; }

/* B1: mascot wave on load + click feedback */
.mascot-wave { animation: wave 1.2s ease-in-out 2; transform-origin: 70% 80%; }
@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}
.mascot-bubble {
  position: relative;
  display: inline-block;
  padding: 10px 18px;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 6px 16px rgba(0,0,0,.1);
  font-weight: 700;
  color: var(--primary-d);
  animation: bubble-in .5s cubic-bezier(.4,1.6,.6,1) both;
  margin-bottom: 14px;
}
.mascot-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px; left: 50%;
  margin-left: -10px;
  border: 10px solid transparent;
  border-top-color: #fff;
}
@keyframes bubble-in {
  from { transform: scale(.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* A3: skill node — bobbing + glowing for unlocked */
.skill-node:not(.locked):not(.done) {
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.skill-node.done {
  background: linear-gradient(135deg, #d6f5e1, #b5ead7);
  animation: done-pulse 2s ease-in-out infinite;
}
@keyframes done-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, .4); }
  50%      { box-shadow: 0 0 0 14px rgba(46, 204, 113, 0); }
}
.skill-node.locked {
  animation: lock-idle 4s ease-in-out infinite;
}
@keyframes lock-idle {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(2px); }
}
.skill-node.locked.shake {
  animation: shake-no .4s ease-in-out;
}
@keyframes shake-no {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

/* A3: skill-node-title small bounce on hover */
.skill-node:not(.locked):hover .icon { animation: pop-icon .35s; }
@keyframes pop-icon {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* B2: modal pop animation */
dialog[open] {
  animation: modal-pop .35s cubic-bezier(.4, 1.6, .6, 1);
}
@keyframes modal-pop {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
dialog::backdrop { animation: fade-in .25s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* B6: skeleton + loading mascot bounce */
.loading-mascot {
  display: inline-block;
  font-size: 48px;
  animation: load-bounce .8s ease-in-out infinite;
}
@keyframes load-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-12px) scale(1.05); }
}
.skeleton {
  background: linear-gradient(90deg, #fde8d4 25%, #ffe5d0 50%, #fde8d4 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  border-radius: 12px;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* B3: combo / streak indicator */
.combo-flame {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 999px;
  background: linear-gradient(90deg, #ff7e5f, #feb47b);
  color: #fff; font-weight: 800;
  animation: flame-pulse .6s ease-in-out;
}
@keyframes flame-pulse {
  0% { transform: scale(.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* B5: card flip 3D (for skill reveals) */
.card-flip { perspective: 1000px; }
.card-flip-inner {
  position: relative; transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.4,1.6,.6,1);
}
.card-flip.flipped .card-flip-inner { transform: rotateY(180deg); }
.card-flip-front, .card-flip-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
}
.card-flip-back { transform: rotateY(180deg); }

/* B3: typewriter praise */
.typewriter {
  overflow: hidden; white-space: nowrap;
  display: inline-block;
  animation: type 1.6s steps(30, end);
}
@keyframes type { from { width: 0; } to { width: 100%; } }

/* B5: memory match glow */
.matched {
  background: linear-gradient(135deg, #b5ead7, #87e8a9) !important;
  animation: glow 1.2s ease-in-out;
}
@keyframes glow {
  0% { box-shadow: 0 0 0 0 rgba(46,204,113,.6); }
  50% { box-shadow: 0 0 20px 8px rgba(46,204,113,.5); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}

/* B2: fade-in for new main views */
#main > * {
  animation: fade-up .35s ease both;
}
@keyframes fade-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Reduced motion: kill heavy anims */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
