:root {
  --pink: #ff8fab;
  --purple: #a78bfa;
  --blue: #60a5fa;
  --yellow: #fbbf24;
  --green: #4ade80;
  --ink: #4a4458;
  --paper: #fffaf3;
  --theme-color: #a78bfa;
  --theme-bg: #f2edfb;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Verdana, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #fff6e9 0%, #eef6ff 50%, #f6ecff 100%);
  overflow-x: hidden;
}

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

.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}
.screen.active { display: flex; }

/* ---------- Header ---------- */
.app-header {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.score-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.06);
  font-weight: 700;
  font-size: 1rem;
}
.score-pill .star-icon { color: var(--yellow); }

/* ---------- Title screen ---------- */
#screen-title { justify-content: center; text-align: center; }
.title-robi-img {
  width: 190px;
  height: 190px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 10px 0 rgba(0,0,0,0.08);
  margin-bottom: 8px;
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.game-title {
  font-size: 2.3rem;
  font-weight: 900;
  margin: 8px 0 0;
  color: var(--purple);
  text-shadow: 2px 2px 0 #fff;
}
.game-subtitle {
  font-size: 1.05rem;
  color: #7a7189;
  margin: 6px 0 22px;
}

.mode-picker {
  display: flex;
  gap: 12px;
  margin-bottom: 26px;
}
.mode-btn {
  background: #fff;
  border-radius: 18px;
  padding: 14px 18px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  font-weight: 700;
  min-width: 150px;
  border: 3px solid transparent;
  transition: transform .1s;
}
.mode-btn small { display:block; font-weight: 500; color: #8a8296; margin-top: 4px; font-size: .78rem; }
.mode-btn.selected { border-color: var(--purple); background: #f4effe; transform: translateY(-2px); }
.mode-btn:active { transform: translateY(2px); }

.big-btn {
  background: linear-gradient(180deg, var(--purple), #8b6ee0);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
  padding: 18px 46px;
  border-radius: 24px;
  box-shadow: 0 6px 0 #6d4fc4;
  transition: transform .1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #6d4fc4; }

/* ---------- Entry / auth screen ---------- */
#screen-entry { text-align: center; }
.title-robi-img.small { width: 110px; height: 110px; margin-bottom: 4px; }
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #9891a3;
  font-size: .82rem;
  margin: 24px 0 16px;
  max-width: 340px;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #ddd6ea; }
.auth-box {
  background: #fff;
  border-radius: 22px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.06);
}
.auth-copy { font-size: .88rem; color: #7a7189; margin: 0 0 12px; }
.auth-input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid #e6e0f2;
  font-size: 1rem;
  margin-bottom: 12px;
  font-family: inherit;
}
.auth-input:focus { outline: none; border-color: var(--purple); }
.small-btn { font-size: 1rem; padding: 13px 20px; width: 100%; box-sizing: border-box; }
.auth-status { min-height: 20px; font-size: .85rem; font-weight: 700; color: var(--purple); margin: 10px 0 0; }
.text-link { color: #8a8296; font-weight: 700; text-decoration: underline; padding: 10px; margin-top: 16px; }

/* ---------- Kid picker screen ---------- */
.kid-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 560px;
  margin-bottom: 22px;
}
.kid-card {
  background: #fff;
  border-radius: 20px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}
.kid-card .kid-avatar { font-size: 2.6rem; }
.kid-card .kid-name { font-weight: 800; margin-top: 6px; }
.kid-card .kid-stars { color: var(--yellow); font-size: .9rem; margin-top: 4px; }
.add-kid-box {
  background: #fff;
  border-radius: 22px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.06);
}
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; }
.avatar-option {
  font-size: 1.7rem;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: #f4effe;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid transparent;
}
.avatar-option.selected { border-color: var(--purple); background: #e8def9; }

.tier-badge-row { display: flex; justify-content: center; margin-bottom: 14px; }
.tier-badge {
  background: linear-gradient(180deg, var(--yellow), #f5a623);
  color: #6b4a00;
  font-weight: 800;
  font-size: .8rem;
  padding: 6px 16px;
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
  letter-spacing: .02em;
}
.upgrade-btn { margin-top: 10px; background: linear-gradient(180deg, var(--yellow), #f5a623); box-shadow: 0 5px 0 #c9861a; }
.cap-note { font-size: .82rem; color: #8a6b1f; text-align: center; margin: 10px 0 0; font-weight: 600; }

/* ---------- Select screen ---------- */
.section-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
  margin: 6px 0 4px;
  text-align: center;
}
.section-subtitle { color: #8a8296; margin-bottom: 20px; text-align: center; }

#friend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 720px;
}
.friend-card {
  background: var(--bg, #fff);
  border-radius: 22px;
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 5px 0 rgba(0,0,0,0.08);
  border: 3px solid transparent;
  position: relative;
}
.friend-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  transition: transform .12s;
}
.friend-card-btn:active { transform: translateY(3px); }
.print-mini-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 0 rgba(0,0,0,0.1);
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.print-mini-btn:active { transform: translateY(2px); }
.friend-img-wrap {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
  margin-bottom: 8px;
}
.friend-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.friend-name { font-weight: 800; font-size: 1.15rem; color: var(--accent, var(--ink)); }
.friend-theme { font-size: .78rem; color: #746b83; text-align: center; margin: 2px 0 8px; }
.friend-theme .dot { opacity: .5; }
.friend-stars { color: var(--yellow); letter-spacing: 2px; font-size: .95rem; }

.extra-modes-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 720px;
  margin-top: 20px;
}
.extra-mode-btn {
  background: #fff;
  border-radius: 20px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  border: 3px solid transparent;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  transition: transform .12s;
}
.extra-mode-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.08); }
.extra-mode-icon { font-size: 1.8rem; }
.extra-mode-label { font-weight: 800; font-size: .92rem; text-align: left; line-height: 1.3; flex: 1; }
.extra-mode-label small { font-weight: 600; color: #8a8296; }
.extra-mode-lock {
  display: none;
  font-size: .72rem;
  font-weight: 800;
  color: #8a6b1f;
  background: #fff3d0;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.extra-mode-btn.locked .extra-mode-lock { display: inline-block; }
.extra-mode-btn.locked { opacity: .82; }

/* ---------- Lesson screen ---------- */
#screen-lesson { background: var(--theme-bg); }
.lesson-header {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.lesson-header img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; }
.lesson-header .lesson-friend-name { font-weight: 800; color: var(--theme-color); flex: 1; }
.timer-pill { color: #c0392b; font-variant-numeric: tabular-nums; }

.progress-track {
  width: 100%;
  max-width: 640px;
  height: 14px;
  background: #fff;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
  margin-bottom: 22px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #22c55e);
  transition: width .4s ease;
}

#lesson-stage {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.learn-card, .challenge-card {
  background: #fff;
  border-radius: 28px;
  padding: 34px 24px 26px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 8px 0 rgba(0,0,0,0.06);
  animation: pop-in .3s ease;
}
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.vocab-swatch { width: 130px; height: 130px; border-radius: 50%; box-shadow: 0 6px 14px rgba(0,0,0,0.15); }
.vocab-shape { font-size: 8rem; color: var(--theme-color); line-height: 1; }
.vocab-emoji { font-size: 7rem; line-height: 1; }
.vocab-number { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.num-digit { font-size: 5rem; font-weight: 900; color: var(--theme-color); line-height: 1; }
.num-dots { display: flex; flex-wrap: wrap; gap: 6px; max-width: 160px; justify-content: center; }
.num-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--theme-color); }

.word-pair { text-align: center; margin: 20px 0 18px; }
.word-en { font-size: 1.6rem; font-weight: 800; color: var(--ink); text-transform: capitalize; }
.word-es { font-size: 1.15rem; font-weight: 600; color: var(--theme-color); font-style: italic; margin-top: 2px; }

.hear-btn {
  background: var(--theme-color);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.hear-btn:active { transform: translateY(3px); box-shadow: none; }

.robi-bubble {
  min-height: 24px;
  margin-top: 16px;
  font-weight: 700;
  color: #7a5c00;
  background: #fff8e0;
  padding: 10px 16px;
  border-radius: 16px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .25s, transform .25s;
  text-align: center;
}
.robi-bubble.show { opacity: 1; transform: translateY(0); }

.next-btn {
  margin-top: 22px;
  background: linear-gradient(180deg, var(--theme-color), var(--theme-color));
  filter: brightness(1);
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 14px 30px;
  border-radius: 20px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  width: 100%;
  max-width: 420px;
}
.next-btn:disabled { opacity: .45; box-shadow: none; }
.next-btn:not(:disabled):active { transform: translateY(3px); box-shadow: none; }

.challenge-prompt { font-size: 1.2rem; font-weight: 700; text-align: center; margin-bottom: 20px; }
.hear-btn-small { margin-top: 18px; font-size: .82rem; padding: 9px 16px; opacity: .9; }
.challenge-options { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.option-btn {
  background: var(--theme-bg);
  border-radius: 20px;
  padding: 16px;
  width: 110px;
  height: 110px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  border: 3px solid transparent;
}
.option-btn .vocab-emoji { font-size: 3.2rem; }
.option-btn .vocab-shape { font-size: 3.5rem; }
.option-btn .vocab-swatch { width: 60px; height: 60px; }
.option-btn .vocab-number .num-digit { font-size: 2.2rem; }
.option-btn .vocab-number .num-dots { max-width: 90px; }
.option-btn .num-dot { width: 10px; height: 10px; }
.option-btn:active { transform: translateY(3px); }
.option-btn.correct { border-color: var(--green); background: #eafff1; }
.option-btn.wrong { border-color: #f87171; animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- Results screen ---------- */
#screen-results { justify-content: center; text-align: center; }
.results-medal { font-size: 4rem; }
.results-friend-img { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 4px solid #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15); margin: 6px 0 14px; }
.results-score-label { color: #8a8296; font-weight: 600; }
.results-score { font-size: 2.6rem; font-weight: 900; color: var(--purple); }
#results-stars { font-size: 1.6rem; color: var(--yellow); letter-spacing: 4px; margin: 6px 0 16px; }
.results-message { max-width: 380px; margin: 0 auto 22px; color: #6b6277; font-weight: 600; }
.results-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.secondary-btn {
  background: #fff;
  color: var(--purple);
  font-weight: 800;
  padding: 14px 24px;
  border-radius: 20px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}
.secondary-btn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- FX ---------- */
.sparkle {
  position: fixed;
  font-size: 1.4rem;
  pointer-events: none;
  animation: sparkle-float .9s ease-out forwards;
  z-index: 999;
}
@keyframes sparkle-float {
  0% { opacity: 1; transform: translate(0,0) scale(0.6) rotate(0deg); }
  100% { opacity: 0; transform: translate(calc((var(--x, 0)) * 1px), -60px) scale(1.3) rotate(90deg); }
}
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 16px;
  z-index: 998;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
  border-radius: 2px;
}
@keyframes confetti-fall {
  to { transform: translate(calc(var(--drift, 0) * 120px), 105vh) rotate(400deg); opacity: 0.9; }
}

/* ---------- Upgrade / pricing screen ---------- */
#screen-upgrade { text-align: center; }
.upgrade-status { min-height: 20px; font-size: .85rem; font-weight: 700; color: #c0392b; max-width: 460px; margin: 0 0 8px; }
.tier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 960px;
  margin-top: 10px;
  align-items: stretch;
}
.tier-card {
  background: #fff;
  border-radius: 24px;
  padding: 24px 18px 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 6px 0 rgba(0,0,0,0.08);
  border: 3px solid transparent;
  position: relative;
  text-align: left;
}
.tier-card.featured { border-color: var(--purple); }
.tier-card.current { border-color: var(--green); background: #f2fff6; }
.tier-ribbon {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.tier-card-name { font-weight: 800; font-size: 1.15rem; }
.tier-card-price { font-size: 2rem; font-weight: 900; color: var(--purple); margin: 4px 0 14px; }
.tier-card-price small { font-size: .95rem; font-weight: 700; color: #8a8296; }
.tier-perks { list-style: none; margin: 0 0 18px; padding: 0; flex: 1; }
.tier-perks li { font-size: .88rem; color: #5c5468; margin-bottom: 10px; padding-left: 20px; position: relative; }
.tier-perks li::before { content: '✓'; position: absolute; left: 0; color: var(--green); font-weight: 900; }
.tier-btn {
  background: linear-gradient(180deg, var(--purple), #8b6ee0);
  color: #fff;
  font-weight: 800;
  font-size: .95rem;
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 4px 0 #6d4fc4;
  text-align: center;
}
.tier-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.tier-btn:disabled { background: #e6e0f2; color: #a79cc0; box-shadow: none; cursor: default; }
.tier-card.current .tier-btn { background: var(--green); color: #fff; box-shadow: none; }
.upgrade-footnote { font-size: .78rem; color: #9891a3; max-width: 480px; margin: 22px auto 0; }

@media (max-width: 420px) {
  .game-title { font-size: 1.8rem; }
  .vocab-emoji { font-size: 5.5rem; }
  .vocab-shape { font-size: 6rem; }
  .learn-card { padding: 26px 16px 20px; }
}

/* ---------- Equations (Nano's math bonus words) ---------- */
.vocab-equation { font-size: 2.6rem; font-weight: 900; color: var(--theme-color); letter-spacing: .02em; }

/* ---------- Language picker (title / kid-picker / classroom) ---------- */
.picker-label { font-size: .85rem; color: #8a8296; margin: 0 0 8px; text-align: center; }
.mini-label { font-size: .8rem; color: #8a8296; margin: 4px 0 6px; text-align: center; font-weight: 700; }
.lang-picker { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; }
.lang-option {
  background: #fff;
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: .92rem;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
  border: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lang-option.selected { border-color: var(--purple); background: #f4effe; }
.lang-option:active { transform: translateY(2px); }

.footer-link { display: block; font-size: .78rem; margin-top: 18px; }

/* ---------- Sign-in teacher checkbox ---------- */
.teacher-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: #5c5468;
  font-weight: 600;
  margin: 4px 0 14px;
  text-align: left;
}
.teacher-checkbox-row input { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Kid / student card language tag ---------- */
.kid-lang { font-size: .72rem; color: #8a8296; margin-top: 2px; font-weight: 600; }

/* ---------- Classroom screen ---------- */
.classroom-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 18px;
}
.small-secondary { padding: 10px 16px; font-size: .85rem; }
.classroom-grid { max-width: 720px; }
.classroom-card-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.small-link { font-size: .75rem; margin: 0; padding: 4px; }
.add-student-box { max-width: 380px; }

/* ---------- Presentation / projector mode ---------- */
body.presentation-mode { background: #fff; }
body.presentation-mode .friend-name { font-size: 1.4rem; }
body.presentation-mode .friend-theme { font-size: .95rem; }
body.presentation-mode .friend-img-wrap { width: 130px; height: 130px; }
body.presentation-mode #friend-grid { max-width: 960px; gap: 24px; }
body.presentation-mode .section-title { font-size: 2.1rem; }
body.presentation-mode .print-mini-btn { width: 40px; height: 40px; font-size: 1.2rem; }
#btn-presentation-mode.active { background: var(--purple); color: #fff; }

/* ---------- Printable flashcards ---------- */
.print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 960px;
}
.print-card {
  background: #fff;
  border: 2px solid #e6e0f2;
  border-radius: 16px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.print-card-icon { transform: scale(.45); margin: -30px 0; }
.print-card-en { font-weight: 800; margin-top: 4px; text-transform: capitalize; }
.print-card-secondary { font-style: italic; color: #746b83; font-size: .9rem; }
.print-card-friend { font-size: .72rem; color: #a79cc0; margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }

@media print {
  body { background: #fff !important; }
  .screen { display: none !important; }
  .screen.active { display: flex !important; }
  .no-print { display: none !important; }
  .print-grid { max-width: 100%; }
  .print-card { break-inside: avoid; box-shadow: none; }
}

/* ---------- Legal screen ---------- */
.legal-content {
  width: 100%;
  max-width: 640px;
  text-align: left;
  background: #fff;
  border-radius: 22px;
  padding: 22px 24px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.06);
}
.legal-content h2 { color: var(--purple); margin: 18px 0 8px; }
.legal-content h2:first-child { margin-top: 0; }
.legal-content ul { padding-left: 20px; margin: 0 0 8px; }
.legal-content li { margin-bottom: 10px; font-size: .92rem; line-height: 1.45; color: #4a4458; }
.legal-note { font-size: .82rem; color: #8a8296; font-style: italic; margin-bottom: 14px; }
.legal-note code { background: #f4effe; padding: 2px 6px; border-radius: 6px; }
