/* Math Classes — kid-friendly bilingual UI */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #f59e0b;
  --green: #16a34a;
  --red: #dc2626;
  --bg: #f0f4ff;
  --card: #ffffff;
  --text: #1e1b4b;
  --muted: #6b7280;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
input, textarea { user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
body {
  margin: 0;
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
#site-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--primary); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 2rem; }
.brand-name { font-weight: 800; font-size: 1.25rem; }
.brand-tag { font-size: 0.75rem; opacity: 0.85; }
.header-actions { display: flex; gap: 8px; }
#app { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 24px; margin: 16px 0;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.12);
}
.card.narrow { max-width: 440px; margin: 32px auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
h1 { font-size: 1.6rem; margin: 0.4em 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; color: var(--primary-dark); }

.btn {
  border: none; border-radius: 14px; padding: 12px 20px;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
  background: #e0e7ff; color: var(--primary-dark);
  font-family: inherit; transition: transform 0.08s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { background: #a5b4fc; cursor: not-allowed; }
.btn-big { width: 100%; margin-top: 16px; font-size: 1.2rem; padding: 16px; }
.btn-ghost { background: rgba(255,255,255,0.18); color: #fff; padding: 8px 14px; font-size: 0.95rem; }
.btn-small { padding: 8px 12px; font-size: 0.9rem; }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-row { display: flex; gap: 12px; margin-top: 16px; }
.btn-row .btn { flex: 1; }
.back-btn { margin: 8px 0; background: #e0e7ff; color: var(--primary-dark); }

label { display: block; margin: 14px 0; font-weight: 700; }
input {
  display: block; width: 100%; margin-top: 6px; padding: 14px;
  font-size: 1.1rem; border: 2px solid #c7d2fe; border-radius: 12px;
  font-family: inherit;
}
input:focus { outline: none; border-color: var(--primary); }
.form-error { color: var(--red); font-weight: 700; }

.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tab {
  flex: 1; border: none; border-radius: 14px; padding: 14px;
  font-size: 1.1rem; font-weight: 800; cursor: pointer;
  background: #e0e7ff; color: var(--primary-dark); font-family: inherit;
}
.tab.active { background: var(--primary); color: #fff; }

.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; margin: 16px 0; }
.profile {
  border: 3px solid #e0e7ff; background: #fff; border-radius: var(--radius);
  padding: 16px 8px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-family: inherit;
}
.profile.selected { border-color: var(--primary); background: #eef2ff; }
.profile-avatar { font-size: 2.6rem; }
.profile-name { font-weight: 800; font-size: 1rem; color: var(--text); }

.pin-dots { display: flex; gap: 10px; justify-content: center; margin: 16px 0; }
.dot { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--primary); }
.dot.filled { background: var(--primary); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.key {
  border: none; border-radius: 14px; padding: 18px 0; font-size: 1.6rem; font-weight: 800;
  background: #eef2ff; color: var(--text); cursor: pointer; font-family: inherit;
}
.key:active { transform: scale(0.94); background: #e0e7ff; }
.key-fn { background: #fde68a; }

.welcome { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.big-avatar { font-size: 3rem; }
.topic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 480px) { .topic-grid { grid-template-columns: 1fr; } }
.topic-card {
  border: none; background: var(--card); border-radius: var(--radius);
  padding: 20px; cursor: pointer; text-align: left;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.12);
  display: flex; flex-direction: column; gap: 6px; font-family: inherit; color: var(--text);
}
.topic-card:active { transform: scale(0.97); }
.topic-icon { font-size: 2.4rem; }
.topic-name { font-weight: 800; font-size: 1.15rem; }
.topic-desc { color: var(--muted); font-size: 0.9rem; }
.topic-stats { font-size: 0.85rem; color: var(--primary-dark); font-weight: 700; margin-top: 6px; }

.example { background: #f5f3ff; border-radius: 12px; padding: 14px; margin: 12px 0; }
.example-q { font-weight: 800; font-size: 1.1rem; margin-bottom: 8px; }
.example ol { margin: 8px 0; padding-left: 22px; }
.example li { margin: 4px 0; }
.lesson-sub { color: var(--muted); font-size: 1rem; text-transform: uppercase; letter-spacing: 1px; }

.progress { height: 12px; background: #e0e7ff; border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; }
.problem-prompt { font-size: 1.5rem; line-height: 1.4; white-space: pre-line; }
.answer-display {
  min-height: 64px; border: 3px dashed #c7d2fe; border-radius: 14px;
  font-size: 2rem; font-weight: 800; display: flex; align-items: center; justify-content: center;
  margin: 8px 0;
}
.answer-display.right { border-color: var(--green); color: var(--green); border-style: solid; }
.answer-display.wrong { border-color: var(--red); color: var(--red); border-style: solid; }
.parts { display: flex; gap: 12px; margin: 8px 0; }
.part-field {
  flex: 1; border: 3px solid #e0e7ff; background: #fff; border-radius: 14px;
  padding: 10px; cursor: pointer; font-family: inherit;
}
.part-field .part-label { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.part-val { display: block; min-height: 44px; font-size: 1.8rem; font-weight: 800; border-radius: 8px; }
.part-val.active { background: #eef2ff; }
.part-val.right { color: var(--green); }
.part-val.wrong { color: var(--red); }
.choices { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.choice {
  border: 3px solid #e0e7ff; background: #fff; border-radius: 14px;
  padding: 16px; font-size: 1.4rem; font-weight: 800; cursor: pointer; font-family: inherit; color: var(--text);
}
.choice.right { border-color: var(--green); background: #dcfce7; }
.choice.wrong { border-color: var(--red); background: #fee2e2; }
.feedback { border-radius: 14px; padding: 16px; font-size: 1.2rem; font-weight: 800; margin: 16px 0 0; }
.feedback.good { background: #dcfce7; color: var(--green); }
.feedback.bad { background: #fee2e2; color: var(--red); }

.score-big { font-size: 4rem; font-weight: 800; color: var(--primary); }
.score-big span { font-size: 2rem; color: var(--muted); }
.stars-msg { font-size: 1.25rem; font-weight: 800; }

.grade-card { margin: 16px 0; }
.grade-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.grade-head h2 { margin: 0; }
.topic-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.topic-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topic-row-name { min-width: 170px; font-weight: 700; }
.bar { flex: 1; min-width: 80px; height: 14px; background: #e0e7ff; border-radius: 8px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--green); }
.topic-row-pct { min-width: 44px; text-align: right; font-weight: 800; }
.badge { border-radius: 999px; padding: 6px 12px; font-size: 0.85rem; font-weight: 800; white-space: nowrap; }
.badge-good { background: #dcfce7; color: var(--green); }
.badge-mid { background: #fef3c7; color: #b45309; }
.badge-bad { background: #fee2e2; color: var(--red); }
.badge-none { background: #f3f4f6; color: var(--muted); }

.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.avatar-opt { font-size: 1.8rem; border: 3px solid #e0e7ff; background: #fff; border-radius: 12px; padding: 6px 10px; cursor: pointer; }
.avatar-opt.selected { border-color: var(--primary); background: #eef2ff; }
.kid-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.kid-row .big-avatar { font-size: 2.2rem; }
.kid-actions { margin-left: auto; display: flex; gap: 8px; }
.kid-edit { flex-basis: 100%; }

.spinner {
  width: 40px; height: 40px; border: 5px solid #e0e7ff; border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── racing game ── */
.race-canvas { width: 100%; height: 240px; display: block; margin: 12px 0; touch-action: manipulation; border-radius: 12px; }
.race-canvas.race-tall { height: 340px; }
.race-wrap { position: relative; }
.countdown-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.count-num { font-size: 5rem; font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,.3); animation: countpop .72s ease; }
@keyframes countpop { 0% { transform: scale(.3); opacity: 0; } 35% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.car-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 16px auto; max-width: 340px; }
.car-opt { border: 3px solid #e5e7eb; border-radius: 14px; background: #f8fafc; padding: 8px; cursor: pointer; }
.car-opt.selected { border-color: var(--primary); background: #eef2ff; box-shadow: 0 0 0 3px rgba(79,70,229,.25); }
.car-thumb { width: 84px; height: 110px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.choice-btn { font-size: 1.75rem; font-weight: 800; padding: 20px 8px; border-radius: 16px; border: 3px solid #e0e7ff; background: #fff; color: var(--text); cursor: pointer; min-height: 78px; }
.choice-btn:active { transform: scale(.96); }
.choice-btn.correct { background: var(--green); border-color: var(--green); color: #fff; }
.choice-btn.wrong { background: var(--red); border-color: var(--red); color: #fff; }
.choice-btn.reveal { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.45); }
.choice-btn:disabled { opacity: 1; }
/* snappy taps on phones: no delay, no highlight flash, no text selection.
   touch-action:none on game buttons so the browser never hijacks a tap
   as a page scroll (which cancels the tap and the answer never registers). */
.choice-btn, .car-opt, #race-start {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
/* no text selection anywhere in the race view (long-presses select prompt text) */
#race-qa, .race-wrap, .car-grid {
  user-select: none;
  -webkit-user-select: none;
}
.race-meta { display: flex; align-items: center; gap: 12px; margin: 8px 0 4px; }
.race-meta strong { white-space: nowrap; }
.race-progress { position: relative; flex: 1; height: 12px; background: #e5e7eb; border-radius: 8px; }
.race-progress-fill { height: 100%; background: var(--primary); border-radius: 8px; transition: width .5s; }
.race-flag { position: absolute; right: -8px; top: -10px; }

/* ── v2 additions: difficulty chips, listen button, badges, leaderboard ── */
.diff-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0 4px; flex-wrap: wrap; }
.diff-chip { border: 2px solid #e5e7eb; border-radius: 999px; background: #f8fafc; padding: 8px 16px; font-size: 0.95rem; font-weight: 700; cursor: pointer; }
.diff-chip.selected { border-color: var(--primary); background: #eef2ff; color: var(--primary-dark); }
.listen-btn { border: none; background: none; font-size: 1.3rem; cursor: pointer; vertical-align: middle; margin-left: 6px; padding: 4px 8px; border-radius: 10px; }
.listen-btn:active { background: #eef2ff; }
.stars-line { color: #b45309; font-weight: 800; letter-spacing: 2px; }
.streak-line { font-weight: 700; color: #c2410c; margin: 4px 0 0; }
.streak-line.none { color: var(--muted); font-weight: 600; }
.badges-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.kid-badge { background: #fef9c3; border: 2px solid #fde68a; border-radius: 12px; padding: 6px 10px; font-size: 0.85rem; font-weight: 700; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid #f3f4f6; }
.lb-row:last-child { border-bottom: none; }
.lb-rank { font-size: 1.4rem; width: 2rem; text-align: center; }
.lb-name { flex: 1; font-weight: 700; }
.lb-stats { text-align: right; font-size: 0.85rem; color: var(--muted); }
.lb-stats strong { color: var(--ink); }
.miss-line { font-size: 0.85rem; color: #92400e; background: #fef3c7; border-radius: 8px; padding: 6px 10px; margin-top: 6px; }
.home-actions { display: flex; gap: 10px; justify-content: center; margin: 4px 0 14px; }

/* ── Printable worksheets ── */
.topic-wrap { position: relative; }
.print-btn {
  position: absolute; top: 8px; right: 8px;
  border: 2px solid #e5e7eb; background: #fff; border-radius: 10px;
  font-size: 1.1rem; padding: 6px 9px; cursor: pointer;
}
.print-btn:hover { border-color: var(--primary); }
.print-btn-inline { margin-left: 8px; padding: 4px 8px; font-size: 1rem; }
.ws-toolbar { margin-bottom: 12px; }
.worksheet {
  background: #fff; color: #111; border-radius: 16px;
  padding: 28px 32px; max-width: 800px; margin: 0 auto 24px;
  font-family: Georgia, 'Times New Roman', serif;
}
.ws-brand { font-family: inherit; font-size: 0.9rem; color: #555; margin-bottom: 4px; }
.ws-title { font-size: 1.7rem; margin: 0 0 12px; }
.ws-meta { display: flex; gap: 28px; flex-wrap: wrap; font-size: 1.05rem; margin-bottom: 18px; }
.ws-line { display: inline-block; min-width: 180px; border-bottom: 2px solid #111; }
.ws-line-sm { min-width: 90px; }
.ws-problems { margin: 0; padding-left: 1.6rem; columns: 2; column-gap: 2.5rem; }
.ws-problem { margin-bottom: 14px; page-break-inside: avoid; break-inside: avoid; }
.ws-prompt { font-size: 1.15rem; margin-bottom: 8px; line-height: 1.5; white-space: pre-line; }
.ws-blank { border-bottom: 2px solid #111; height: 1.6rem; max-width: 420px; }
.ws-blank-sm { max-width: 180px; display: inline-block; min-width: 120px; }
.ws-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; max-width: 520px; }
.ws-choice { font-size: 1.05rem; }
.ws-letter { display: inline-block; width: 1.7rem; height: 1.7rem; line-height: 1.7rem;
  text-align: center; border: 2px solid #111; border-radius: 50%; font-weight: 700; margin-right: 6px; }
.ws-parts { display: flex; flex-direction: column; gap: 8px; }
.ws-part { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.ws-key-page { page-break-before: always; margin-top: 24px; }
.ws-key-page h2 { font-size: 1.4rem; }
.ws-key-list { columns: 2; font-size: 1rem; }
.ws-key-list li { margin-bottom: 6px; break-inside: avoid; }

@media print {
  #site-header, .no-print { display: none !important; }
  body { background: #fff !important; }
  #app { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .worksheet { border-radius: 0; padding: 0; margin: 0; max-width: none; }
  .ws-problem { margin-bottom: 10px; }
  .ws-prompt { font-size: 1.02rem; line-height: 1.35; margin-bottom: 6px; }
  .ws-blank { height: 1.3rem; }
  .ws-meta { margin-bottom: 12px; }
  .ws-title { font-size: 1.4rem; margin-bottom: 8px; }
}

/* ── progress features: trophy room / daily challenge / homework / report card ── */
.daily-tag { display: inline-block; background: #fbbf24; color: #451a03; font-weight: 700;
  border-radius: 999px; padding: 2px 12px; margin: 0 0 8px; font-size: 0.9rem; }
.daily-card { border: 2px solid #fbbf24; }
.daily-card.done { border-color: #86efac; background: #f0fdf4; }
.daily-card h3 { margin-top: 0; }
.daily-meta { display: flex; gap: 12px; align-items: center; margin: 8px 0; }
.cal-dots { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.cal-dot { width: 14px; height: 14px; border-radius: 50%; background: #e5e7eb; display: inline-block; }
.cal-dot.on { background: #22c55e; }
.asg-card { border-left: 4px solid #8b5cf6; }
.asg-msg { font-weight: 700; margin-bottom: 6px; }
.asg-note { color: #4b5563; font-style: italic; margin: 4px 0; }
.asg-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 12px 0; }
.stat-tile { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-ic { font-size: 1.4rem; }
.stat-big { font-size: 1.3rem; font-weight: 800; }
.stat-small { font-size: 0.8rem; }
.badges-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0 16px; }
.trophy-badge { background: #fffbeb; border: 1px solid #fcd34d; border-radius: 12px; padding: 10px;
  display: flex; align-items: center; gap: 8px; font-weight: 600; }
.trophy-ic { font-size: 1.6rem; }
.grade-subrow { display: flex; gap: 10px; align-items: center; margin: 6px 0 10px; flex-wrap: wrap; }
.asg-h { margin: 12px 0 6px; }
.asg-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed #e5e7eb; flex-wrap: wrap; }
.asg-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.asg-form label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 2px; }
.asg-form select, .asg-form input { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 8px; }
.rc-table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; font-size: 0.95rem; }
.rc-table th, .rc-table td { border: 1px solid #d1d5db; padding: 6px 8px; text-align: left; }
.rc-table thead th { background: #f3f4f6; }
.rc-stars { color: #f59e0b; letter-spacing: 2px; }
.rc-asg { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed #e5e7eb; }
.rc-asg.done { color: #6b7280; }
.rc-badges { margin: 12px 0; }
@media print {
  .rc-table th, .rc-table td { font-size: 0.85rem; padding: 4px 6px; }
  .stat-tiles { grid-template-columns: repeat(4, 1fr); }
}
