:root {
  --ink: #2B2D42;
  --pink: #FF5E7E;
  --pink-dark: #C93D5C;
  --yellow: #FFC93C;
  --green: #2ECC71;
  --green-dark: #1E9E55;
  --blue: #1FB5C9;
  --blue-dark: #168797;
  --purple: #7B61FF;
  --purple-dark: #5A43D6;
  --radius: 24px;
  --font: 'Baloo Bhaijaan 2', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* Portrait app shell: header + one content area sized to the screen, so nothing hides below the fold. */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 18%, #FFE08A 0 60px, transparent 61px),
    radial-gradient(circle at 92% 12%, #FFB3C7 0 42px, transparent 43px),
    radial-gradient(circle at 88% 88%, #B5F5C8 0 80px, transparent 81px),
    radial-gradient(circle at 4% 92%, #C9B8FF 0 55px, transparent 56px),
    linear-gradient(160deg, #FFF4D6, #D6F0FF);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
}

button:focus-visible {
  outline: 4px solid var(--purple);
  outline-offset: 3px;
}

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

.center { text-align: center; }

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .07), 0 14px 30px rgba(0, 0, 0, .08);
  padding: 20px;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px 6px;
}

.topbar h1 {
  margin: 0;
  min-width: 0;
  font-size: clamp(1rem, 4.8vw, 1.8rem);
  font-weight: 800;
  color: var(--purple);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 3px 3px 0 #fff;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .12);
  transition: transform .1s, box-shadow .1s;
}

.icon-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.icon-btn.hidden { visibility: hidden; }

main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 2px 12px calc(14px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

/* ---------- Scroll hint ---------- */

.scroll-hint {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-left: -27px;
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  font-size: 1.7rem;
  font-weight: 800;
  box-shadow: 0 5px 0 var(--pink-dark), 0 10px 24px rgba(0, 0, 0, .22);
}

.scroll-hint.show { display: flex; animation: hint-bounce 1.1s ease-in-out infinite; }
.sheet .scroll-hint { position: absolute; bottom: 86px; }

@keyframes hint-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(9px); }
}

/* ---------- Bottom sheet (hints) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(43, 45, 66, .32);
  animation: fade-in .25s ease-out;
}

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  max-height: 80dvh;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: #fff;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .2);
  animation: slide-up .4s cubic-bezier(.3, 1.3, .6, 1);
}

.sheet-body { width: 100%; min-height: 0; overflow-y: auto; text-align: center; }
.sheet .big-btn { flex: none; margin-top: 12px; }
.sheet .oops { margin-bottom: 10px; }

.hint-box {
  padding: 12px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--c, var(--purple)) 9%, #fff);
  border: 3px dashed color-mix(in srgb, var(--c, var(--purple)) 45%, #fff);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Landscape blocker ---------- */

#rotate { display: none; }

@media (orientation: landscape) and (max-height: 500px) {
  #rotate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(160deg, #FFF4D6, #D6F0FF);
    font-size: 1.4rem;
    text-align: center;
  }
  .rotate-phone { font-size: 4rem; animation: turn 1.6s ease-in-out infinite; }
}

@keyframes turn {
  0%, 30% { transform: rotate(-90deg); }
  60%, 100% { transform: rotate(0); }
}

/* ---------- Listen button ---------- */

.listen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  margin-inline-start: 4px;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--yellow);
  font-size: 1.15rem;
  box-shadow: 0 3px 0 #D9A400;
}

.listen-btn.playing { animation: pulse .8s ease-in-out infinite; background: var(--green); box-shadow: 0 3px 0 var(--green-dark); }

/* ---------- Home ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.table-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 6px 4px 6px;
  border-radius: var(--radius);
  background: var(--c);
  color: #fff;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--c) 65%, #000);
  transition: transform .12s, box-shadow .12s;
}

.table-card:hover { transform: translateY(-4px) rotate(-1.5deg); }
.table-card:active { transform: translateY(5px); box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 65%, #000); }

.card-emoji { font-size: 1.2rem; line-height: 1.2; }
.card-num { font-size: clamp(1.9rem, 6.5vh, 2.8rem); font-weight: 800; line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, .15); }
.card-label { display: none; }
.table-card .stars { font-size: .8rem; }

.stars { display: inline-flex; gap: 2px; font-size: 1.15rem; }
.star { filter: grayscale(1); opacity: .35; }
.star.on { filter: none; opacity: 1; }

.mixed-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 12px;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #FF5E7E, #FFC93C, #2ECC71, #1FB5C9, #7B61FF);
  color: #fff;
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .2);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .18);
  transition: transform .12s;
}

.mixed-card:hover { transform: translateY(-3px) scale(1.01); }
.mixed-card .star:not(.on) { filter: grayscale(1) brightness(2); opacity: .6; }

/* ---------- Mascot ---------- */

.mascot-row {
  --avatar: clamp(62px, 11vh, 100px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 2px 0 12px;
}

.mascot-row.large { --avatar: clamp(70px, 13vh, 120px); }

.avatar {
  width: var(--avatar);
  height: var(--avatar);
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 5px solid #fff;
  box-shadow: 0 0 0 5px var(--c, var(--purple)), 0 10px 20px rgba(0, 0, 0, .15);
  user-select: none;
}

.mascot-row.large .avatar { animation: float 3s ease-in-out infinite; }

.bubble {
  position: relative;
  max-width: 440px;
  padding: 8px 14px;
  border-radius: 20px;
  background: #fff;
  font-size: clamp(.98rem, 4vw, 1.3rem);
  font-weight: 800;
  line-height: 1.45;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .07);
}

.bubble::before {
  content: '';
  position: absolute;
  top: 50%;
  inset-inline-start: -9px;
  width: 20px;
  height: 20px;
  background: #fff;
  transform: translateY(-50%) rotate(45deg);
  border-radius: 3px;
}

.jump { animation: jump .7s cubic-bezier(.3, 1.5, .6, 1); }
.nod { animation: nod .8s ease-in-out; }

/* ---------- Equation & arrays ---------- */

.equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35em;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.3;
}

.equation .op { color: var(--pink); }
.equation .ans { color: color-mix(in srgb, var(--c, var(--purple)) 75%, #000); min-width: 1.2em; text-align: center; }

.array {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: var(--s);
}

.arr-row {
  display: flex;
  gap: 1px;
  padding: 0 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--c, var(--purple)) 16%, #fff);
}

.arr-row span { line-height: 1.2; }

.array-caption {
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
}

/* ---------- Review ---------- */

.review h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.3rem, 5.5vw, 1.9rem);
}

.review-talk {
  margin: 0 0 8px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  opacity: .75;
}

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }

.fact-row {
  padding: 0 6px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .07);
  transition: transform .12s, border-color .12s;
}

.fact-row:nth-child(4n+1), .fact-row:nth-child(4n+4) { background: color-mix(in srgb, var(--c) 12%, #fff); }
.fact-row.selected { border-color: var(--c); transform: scale(1.03); }
.fact-row .equation { font-size: clamp(1.15rem, 4.6vw, 1.5rem); }

.review .visual {
  height: clamp(150px, 27vh, 240px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-top: 8px solid var(--c);
}

/* ---------- Buttons ---------- */

.big-btn {
  margin-top: 14px;
  padding: 10px 30px;
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-size: clamp(1.15rem, 4.6vw, 1.5rem);
  font-weight: 800;
  box-shadow: 0 7px 0 var(--pink-dark);
  transition: transform .1s, box-shadow .1s;
}

.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-dark); }
.big-btn.alt { background: var(--blue); box-shadow: 0 7px 0 var(--blue-dark); }
.big-btn.alt2 { background: var(--purple); box-shadow: 0 7px 0 var(--purple-dark); }

/* ---------- Quiz ---------- */

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.dots { display: flex; flex-wrap: wrap; gap: 5px; }

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .1);
  transition: transform .2s;
}

.dot.now { background: var(--yellow); transform: scale(1.3); }
.dot.ok { background: var(--green); }
.dot.miss { background: #FFB199; }

.streak {
  padding: 2px 12px;
  border-radius: 999px;
  background: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .08);
}

.streak.hot { background: #FFE08A; animation: pulse 1s ease-in-out infinite; }

.question {
  padding: 10px 14px;
  text-align: center;
  border-top: 10px solid var(--c);
}

.q-label { margin: 0; font-size: 1rem; font-weight: 700; opacity: .65; }
.question .equation { font-size: clamp(2.4rem, 8vh, 4.6rem); }

.qmark {
  display: inline-block;
  color: var(--pink);
  animation: wobble 1.6s ease-in-out infinite;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.choice {
  min-height: clamp(54px, 9vh, 84px);
  padding: 4px 6px;
  border: 4px solid var(--c);
  border-radius: 20px;
  background: #fff;
  font-size: clamp(1.7rem, 7vw, 2.5rem);
  font-weight: 800;
  box-shadow: 0 7px 0 color-mix(in srgb, var(--c) 60%, #000);
  transition: transform .1s, box-shadow .1s, opacity .2s;
}

.choice:hover:not(:disabled) { transform: translateY(-3px); }
.choice:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 60%, #000); }
.choice:disabled { cursor: default; }

.choice.right {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  box-shadow: 0 7px 0 var(--green-dark);
  animation: bounce .6s;
}

.choice.wrong {
  border-color: #FF8A6B;
  background: #FFE1D9;
  animation: wiggle .5s;
}

.choice.faded { opacity: .4; }

.feedback {
  margin-top: 10px;
  text-align: center;
}

.streak-msg { font-size: 1.3rem; font-weight: 800; color: #E8590C; }

.oops { margin-bottom: 14px; font-size: clamp(1.2rem, 4.6vw, 1.6rem); font-weight: 700; }
.oops b { font-size: 1.4em; color: var(--green-dark); }

.hint-visual { width: fit-content; max-width: 100%; margin: 0 auto; }

/* ---------- Setup ---------- */

.setup { max-width: 640px; margin: 0 auto; }

.setup-talk {
  margin: 4px 0 16px;
  text-align: center;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  color: var(--purple);
}

.setup-card h3 { margin: 0 0 10px; font-size: 1.4rem; }

.avatar-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.avatar-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  border: 5px solid #E6E1F5;
  border-radius: var(--radius);
  background: #fff;
  font-size: 1.4rem;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .08);
  transition: transform .12s, border-color .12s;
}

.avatar-choice img { width: 100%; max-width: min(150px, 18vh); aspect-ratio: 1; border-radius: 50%; object-fit: cover; }
.avatar-choice:hover { transform: translateY(-3px); }
.avatar-choice.selected { border-color: var(--green); background: #EFFFF5; }
.avatar-choice.selected b::after { content: ' ✅'; }

.name-input {
  width: 100%;
  padding: 12px 18px;
  border: 4px solid #E6E1F5;
  border-radius: 18px;
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  outline: none;
}

.name-input:focus { border-color: var(--purple); }

.big-btn:disabled { opacity: .45; cursor: default; transform: none; }

.link-btn {
  margin-top: 18px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--purple-dark);
}

/* ---------- Result ---------- */

.result {
  max-width: 560px;
  margin: 8px auto 0;
  text-align: center;
}

.result-avatar {
  width: min(170px, 24vh);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
  border: 6px solid #fff;
  box-shadow: 0 0 0 6px var(--yellow), 0 12px 24px rgba(0, 0, 0, .15);
  animation: float 2.5s ease-in-out infinite;
}
.result h2 { margin: 8px 0 0; font-size: clamp(1.3rem, 5.5vw, 2rem); }
.score { margin: 4px 0; font-size: 1.2rem; font-weight: 700; }
.stars-big .stars { font-size: clamp(2.2rem, 6vh, 3rem); gap: 8px; }

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-actions .big-btn { width: min(100%, 340px); margin-top: 10px; }

/* ---------- Animations ---------- */

.pop-in { animation: pop-in .45s cubic-bezier(.3, 1.6, .6, 1) backwards; animation-delay: var(--d, 0ms); }
.bounce { display: inline-block; animation: bounce .6s; }

@keyframes pop-in {
  from { transform: scale(.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.2); }
  60% { transform: scale(.94); }
  100% { transform: scale(1); }
}

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes jump {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-22px) scale(1.12) rotate(-6deg); }
  65% { transform: translateY(0) scale(.96) rotate(4deg); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes nod {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-7deg); }
  50% { transform: rotate(6deg); }
  75% { transform: rotate(-3deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

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