:root {
  --bg1: #fff0f6;
  --bg2: #ffe3ef;
  --card: rgba(255, 255, 255, 0.85);
  --ink: #6b2c4a;
  --muted: #b07a93;
  --pink: #ff6fa5;
  --pink-deep: #e84e8a;
  --pink-soft: #ffd1e3;
  --lilac: #e9d5ff;
  --mint: #c8f7dc;
  --mint-ink: #1f7a4d;
  --peach: #ffe1d6;
  --peach-ink: #b4533a;
  --shadow: 0 10px 30px rgba(232, 78, 138, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 50%, #f6e8ff);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.screen { display: none; animation: pop-in 0.4s ease; }
.screen.active { display: block; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- hero ---------- */
.hero { text-align: center; margin-bottom: 20px; }
.tooth-mascot {
  font-size: 64px;
  display: inline-block;
  animation: bob 2.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(232, 78, 138, 0.25));
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-8px) rotate(4deg); }
}
h1 { font-size: 2.2rem; margin: 6px 0 4px; font-weight: 700; }
.script { font-family: "Pacifico", cursive; color: var(--pink-deep); font-weight: 400; }
.sub { color: var(--muted); margin: 0; font-size: 1.05rem; line-height: 1.5; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  backdrop-filter: blur(6px);
  border: 2px solid #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 8px; margin-bottom: 18px; }
.stat span { display: block; font-size: 1.7rem; font-weight: 700; color: var(--pink-deep); }
.stat small { color: var(--muted); font-size: 0.82rem; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  border: none;
  cursor: pointer;
  border-radius: 18px;
  padding: 14px 18px;
  font-size: 1.1rem;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s;
  width: 100%;
}
.btn small { display: block; font-weight: 400; font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  color: #fff;
  box-shadow: 0 8px 20px rgba(232, 78, 138, 0.35);
}
.btn-soft { background: #fff; color: var(--pink-deep); border: 2px solid var(--pink-soft); }

.big-buttons { display: grid; gap: 12px; margin-bottom: 26px; }

.btn-icon {
  font-size: 1.4rem;
  background: #fff;
  border: 2px solid var(--pink-soft);
  border-radius: 14px;
  width: 46px; height: 46px;
  cursor: pointer;
  flex-shrink: 0;
}
.link {
  font: inherit;
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 6px;
}

/* ---------- topics ---------- */
.section-title { font-size: 1.25rem; margin: 0 0 12px; text-align: center; }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.topic {
  font: inherit;
  text-align: left;
  cursor: pointer;
  border: 2px solid #fff;
  border-radius: 20px;
  padding: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.topic:hover { transform: translateY(-3px) rotate(-0.5deg); }
.topic .t-emoji { font-size: 1.6rem; }
.topic .t-name { font-weight: 600; font-size: 1.05rem; margin: 4px 0 8px; display: block; }
.topic .t-info { font-size: 0.8rem; color: var(--muted); }
.mini-bar { height: 8px; background: rgba(255,255,255,0.8); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.mini-bar div { height: 100%; background: linear-gradient(90deg, var(--pink), var(--pink-deep)); border-radius: 99px; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.quiz-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pill {
  align-self: flex-start;
  background: var(--pink-soft);
  color: var(--pink-deep);
  border-radius: 99px;
  padding: 3px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.muted { color: var(--muted); font-size: 0.85rem; }
.session-hearts {
  background: #fff;
  border-radius: 14px;
  padding: 8px 12px;
  font-weight: 700;
  color: var(--pink-deep);
  border: 2px solid var(--pink-soft);
  white-space: nowrap;
}
.session-hearts.bump { animation: bump 0.4s ease; }
@keyframes bump { 50% { transform: scale(1.25); } }

.progress { height: 10px; background: rgba(255,255,255,0.7); border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #ffb3d1, var(--pink-deep)); border-radius: 99px; transition: width 0.4s ease; }

.question { font-size: 1.25rem; font-weight: 600; line-height: 1.45; margin: 0 0 18px; }
.options { display: grid; gap: 10px; }
.option {
  font: inherit;
  text-align: left;
  font-size: 1.02rem;
  background: #fff;
  border: 2px solid var(--pink-soft);
  border-radius: 16px;
  padding: 13px 16px;
  cursor: pointer;
  color: var(--ink);
  display: flex; gap: 12px; align-items: center;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.option:hover:not(:disabled) { border-color: var(--pink); transform: translateX(3px); }
.option:disabled { cursor: default; }
.option .letter {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--pink-soft);
  color: var(--pink-deep);
  font-weight: 700;
  font-size: 0.9rem;
}
.option.correct { background: var(--mint); border-color: #6fd9a0; color: var(--mint-ink); }
.option.correct .letter { background: #6fd9a0; color: #fff; }
.option.wrong { background: var(--peach); border-color: #ffb199; color: var(--peach-ink); animation: wiggle 0.4s ease; }
.option.wrong .letter { background: #ffb199; color: #fff; }
.option.faded { opacity: 0.55; }
@keyframes wiggle {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.feedback {
  margin-top: 16px;
  border-radius: 18px;
  padding: 14px 16px;
  line-height: 1.5;
  animation: pop-in 0.35s ease;
}
.feedback.good { background: linear-gradient(135deg, #fff0f7, #ffe0ee); border: 2px dashed var(--pink); }
.feedback.oops { background: linear-gradient(135deg, #fff8f0, #f6ecff); border: 2px dashed #d8b4fe; }
.feedback .f-title { font-weight: 700; font-size: 1.15rem; display: block; margin-bottom: 4px; }
.feedback .f-expl { margin-top: 8px; font-size: 0.95rem; color: var(--ink); opacity: 0.85; }
#nextBtn { margin-top: 16px; }

.hidden { display: none !important; }

/* ---------- done ---------- */
.done-card { text-align: center; }
.done-emoji { font-size: 72px; animation: bob 2.6s ease-in-out infinite; }
.done-card h2 { margin: 6px 0; font-size: 1.6rem; }
.big-score { font-size: 2.6rem; font-weight: 700; color: var(--pink-deep); margin: 8px 0; }
.done-card .big-buttons { margin: 22px 0 0; }

.footer-note { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 30px; }

/* ---------- floating background hearts ---------- */
.floaties { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.floaty {
  position: absolute;
  bottom: -40px;
  opacity: 0.35;
  animation: float-up linear infinite;
}
@keyframes float-up {
  to { transform: translateY(-115vh) rotate(25deg); }
}

/* ---------- celebration burst ---------- */
.burst {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  font-size: 24px;
  animation: burst 1.1s ease-out forwards;
}
@keyframes burst {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(var(--rot)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .floaties { display: none; }
}

@media (max-width: 420px) {
  h1 { font-size: 1.8rem; }
  .question { font-size: 1.12rem; }
  .card { padding: 16px; }
}

/* =====================================================
   ✨ extra love & animations ✨
   ===================================================== */
html { background: var(--bg1); }

/* soft breathing gradient behind everything */
body::before {
  content: "";
  position: fixed; inset: -20%;
  z-index: 0; pointer-events: none;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,182,214,0.55), transparent 40%),
    radial-gradient(circle at 80% 30%, rgba(233,213,255,0.55), transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(255,214,230,0.6), transparent 45%);
  animation: aurora 18s ease-in-out infinite alternate;
}
@keyframes aurora {
  0% { transform: translate(0,0) rotate(0deg) scale(1); }
  50% { transform: translate(3%, -2%) rotate(8deg) scale(1.05); }
  100% { transform: translate(-3%, 2%) rotate(-6deg) scale(1); }
}

/* bouncy wavy name */
.script .ch { display: inline-block; animation: wave 2.4s ease-in-out infinite; }
@keyframes wave {
  0%, 60%, 100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-9px) rotate(-6deg); }
}
.heartbeat { display: inline-block; animation: heartbeat 1.3s ease-in-out infinite; }
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.25); }
  30% { transform: scale(1); }
  45% { transform: scale(1.18); }
}

/* mascot: blushing cheeks + sparkles + click to boop */
.mascot-wrap { position: relative; display: inline-block; cursor: pointer; }
.mascot-wrap .blush {
  position: absolute; top: 58%; width: 12px; height: 7px; border-radius: 50%;
  background: #ff8fb8; opacity: 0.7; filter: blur(1px);
  animation: blush 2.6s ease-in-out infinite;
}
.mascot-wrap .blush.l { left: 14px; }
.mascot-wrap .blush.r { right: 14px; }
@keyframes blush { 50% { opacity: 0.35; transform: scale(0.85); } }
.mascot-wrap .spark {
  position: absolute; font-size: 16px; animation: twinkle 2s ease-in-out infinite;
}
.mascot-wrap .spark.s1 { top: 0; left: -14px; }
.mascot-wrap .spark.s2 { top: 8px; right: -16px; animation-delay: .7s; }
.mascot-wrap .spark.s3 { bottom: 4px; left: -6px; animation-delay: 1.3s; }
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(0.3) rotate(0); }
  50% { opacity: 1; transform: scale(1) rotate(90deg); }
}
.tooth-mascot.boop { animation: boop 0.6s ease; }
@keyframes boop {
  30% { transform: scale(1.25, 0.8); }
  60% { transform: scale(0.9, 1.15) translateY(-10px); }
}

/* staggered entrance for lists */
.stagger > * { opacity: 0; animation: rise 0.55s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

/* shimmering primary buttons */
.btn-primary { position: relative; overflow: hidden; }
.btn-primary::after {
  content: ""; position: absolute; top: 0; left: -60%;
  width: 40%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,0.55), transparent);
  transform: skewX(-20deg);
  animation: shimmer 3.2s ease-in-out infinite;
}
@keyframes shimmer { 0%, 60% { left: -60%; } 100% { left: 130%; } }

/* topic cards float gently */
.topic { animation: rise 0.55s cubic-bezier(.2,1.4,.4,1) backwards; }
.topic .t-emoji { display: inline-block; transition: transform .3s; }
.topic:hover .t-emoji { transform: scale(1.3) rotate(-12deg); }

/* stat numbers pop */
.stat span { animation: rise .6s cubic-bezier(.2,1.4,.4,1) backwards; }
.stat:nth-child(2) span { animation-delay: .1s; }
.stat:nth-child(3) span { animation-delay: .2s; }

/* progress bar heart rider */
.progress { overflow: visible; position: relative; }
.progress-bar { position: relative; }
.progress-bar::after {
  content: "💗"; position: absolute; right: -10px; top: 50%;
  transform: translateY(-50%); font-size: 18px;
  animation: heartbeat 1.3s ease-in-out infinite;
}

/* question card slides in */
.question-card.enter { animation: card-in .5s cubic-bezier(.2,1.3,.4,1); }
@keyframes card-in {
  from { opacity: 0; transform: translateX(40px) rotate(2deg); }
  to { opacity: 1; transform: none; }
}
.question-card.leave { animation: card-out .28s ease-in forwards; }
@keyframes card-out { to { opacity: 0; transform: translateX(-40px) rotate(-2deg); } }

.option.correct { animation: jelly .6s ease; }
@keyframes jelly {
  30% { transform: scale(1.06, 0.94); }
  50% { transform: scale(0.97, 1.03); }
  70% { transform: scale(1.02, 0.98); }
}

/* big love overlay when right */
.love-pop {
  position: fixed; left: 50%; top: 42%; z-index: 60; pointer-events: none;
  font-size: 110px; transform: translate(-50%, -50%) scale(0);
  animation: love-pop 1s cubic-bezier(.2,1.6,.4,1) forwards;
  filter: drop-shadow(0 10px 20px rgba(232,78,138,.4));
}
@keyframes love-pop {
  0% { transform: translate(-50%, -50%) scale(0) rotate(-20deg); opacity: 1; }
  45% { transform: translate(-50%, -50%) scale(1.15) rotate(6deg); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(.9); opacity: 0; }
}

/* gentle hug when wrong */
.question-card.hug { animation: hug .7s ease; }
@keyframes hug {
  30% { transform: scale(0.97); box-shadow: 0 0 0 10px rgba(216,180,254,.35), var(--shadow); }
  60% { transform: scale(1.01); }
}
.feedback.oops .f-title::before {
  content: "🧸 "; display: inline-block; animation: rock 1.6s ease-in-out infinite;
}
@keyframes rock { 50% { transform: rotate(-14deg); } }

/* floating background items sway */
.floaty { animation-name: float-up, sway; animation-timing-function: linear, ease-in-out; animation-iteration-count: infinite, infinite; }
@keyframes sway { 50% { margin-left: 30px; } }

/* click sparkle trail */
.tap-heart {
  position: fixed; pointer-events: none; z-index: 70; font-size: 18px;
  animation: tap 0.9s ease-out forwards;
}
@keyframes tap {
  from { opacity: 1; transform: translate(-50%, -50%) scale(.5); }
  to { opacity: 0; transform: translate(-50%, -160%) scale(1.3); }
}

/* falling confetti on results */
.rain {
  position: fixed; top: -40px; z-index: 55; pointer-events: none;
  animation: rain linear forwards;
}
@keyframes rain {
  to { transform: translateY(110vh) rotate(540deg); }
}
.big-score { animation: heartbeat 1.6s ease-in-out infinite; display: inline-block; }

/* ---------- question source + official-exam extras ---------- */
.source-filter { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0 0 18px; }
.source-filter button {
  font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer;
  border: 2px solid var(--pink-soft); background: #fff; color: var(--pink-deep);
  border-radius: 999px; padding: 7px 14px; transition: transform .15s, background .15s;
}
.source-filter button:hover { transform: translateY(-2px); }
.source-filter button[aria-pressed="true"] { background: var(--pink); border-color: var(--pink); color: #fff; box-shadow: var(--shadow); }
.q-source { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.q-source:empty { display: none; }
.q-source .tag { font-size: 0.78rem; font-weight: 600; border-radius: 999px; padding: 3px 10px; background: var(--pink-soft); color: var(--pink-deep); }
.q-source .tag.new { background: var(--lilac); color: #7a3fb0; }
.q-source .tag.rep { background: var(--peach); color: var(--peach-ink); }
.q-source .tag.sub { background: #fff; color: var(--muted); border: 1.5px solid var(--pink-soft); }
.feedback .f-note { margin-top: 10px; padding: 8px 12px; border-radius: 14px; background: #fff7e6; border: 2px dashed #ffc46b; font-size: 0.9rem; color: #8a5300; }
.feedback .f-ref { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }

/* ---------- encouragement modes: cute (default) / calm / focus ---------- */
.mode-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 14px; }
.mode-switch button {
  font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer; line-height: 1.2;
  border: 2px solid var(--pink-soft); background: #fff; color: var(--ink);
  border-radius: 16px; padding: 9px 6px; display: grid; gap: 2px; justify-items: center;
  transition: transform .15s, background .15s, border-color .15s;
}
.mode-switch button small { font-weight: 500; font-size: 0.72rem; color: var(--muted); }
.mode-switch button:hover { transform: translateY(-2px); }
.mode-switch button[aria-pressed="true"] { border-color: var(--pink); background: var(--pink-soft); }
.mode-toggle { font-size: 1.1rem; }

/* calm + focus: no floating hearts, no bouncing / jelly / wiggle */
body.mode-calm .floaties, body.mode-focus .floaties { display: none; }
body.mode-calm .tooth-mascot, body.mode-focus .tooth-mascot { animation: none; }
body.mode-calm .option.correct, body.mode-focus .option.correct,
body.mode-calm .option.wrong, body.mode-focus .option.wrong { animation: none; }
body.mode-calm .burst, body.mode-focus .burst { display: none; }

/* focus: plain, exam-like feedback */
body.mode-focus .feedback .f-title::before, body.mode-focus .feedback .f-title::after { content: none !important; }
body.mode-focus .feedback.good, body.mode-focus .feedback.oops { background: #fff; border-style: solid; border-width: 2px; }
body.mode-focus .feedback.good { border-color: #6fd9a0; }
body.mode-focus .feedback.oops { border-color: #ffb199; }
body.mode-focus .screen { animation: none; }
body.mode-calm .tap-heart, body.mode-focus .tap-heart,
body.mode-calm .rain, body.mode-focus .rain { display: none; }
body.mode-calm .question-card.hug, body.mode-focus .question-card.hug,
body.mode-calm .big-score, body.mode-focus .big-score { animation: none; }
