:root {
  --pink: #ff6b9d;
  --pink-dark: #e84d83;
  --yellow: #ffd23f;
  --blue: #4ecdc4;
  --purple: #a06cd5;
  --ink: #2d2a4a;
  --paper: #fff8f3;
  --card: #ffffff;
  --green: #38c172;
  --red: #ef5b6b;
  --shadow: 0 10px 0 rgba(45, 42, 74, 0.12);
  font-size: clamp(16px, 2.4vw, 22px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  background: radial-gradient(circle at 20% 10%, #fff2f7 0%, var(--paper) 45%, #f0fbfa 100%);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.1rem 2.5rem;
}

/* ---------- Screens ---------- */
.screen { display: none; animation: fade .35s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Home ---------- */
.home-header { text-align: center; margin: 1.2rem 0 1.6rem; }
.logo { font-size: 2.6rem; line-height: 1.1; color: var(--pink-dark); text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(255,107,157,.25); }
.logo .beat { display: inline-block; color: var(--pink); animation: beat 1.3s ease-in-out infinite; }
@keyframes beat { 0%,100%{ transform: scale(1);} 15%{ transform: scale(1.25);} 30%{ transform: scale(1);} }
.tagline { margin-top: .5rem; color: var(--purple); font-size: 1rem; }

.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.8rem; }
.mode-card {
  border: none; border-radius: 26px; padding: 1.4rem 1rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  color: #fff; font-family: inherit; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.mode-card:active { transform: translateY(6px); box-shadow: 0 4px 0 rgba(45,42,74,.12); }
.mode-card.practice { background: linear-gradient(160deg, var(--blue), #3bb3ab); }
.mode-card.quiz { background: linear-gradient(160deg, var(--purple), #8a4fc7); }
.mode-emoji { font-size: 2.6rem; }
.mode-title { font-size: 1.4rem; font-weight: 700; }
.mode-sub { font-size: .82rem; opacity: .92; }

.pick-title { text-align: center; color: var(--ink); margin-bottom: .9rem; font-size: 1.2rem; }
.deck-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; }
.deck-btn {
  border: 3px solid #fff; border-radius: 20px; background: var(--card); cursor: pointer;
  padding: .85rem .6rem; font-family: inherit; color: var(--ink); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .15rem; align-items: center;
  transition: transform .12s ease, box-shadow .12s ease, background .2s;
}
.deck-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(45,42,74,.12); }
.deck-btn .deck-name { font-weight: 700; font-size: 1.05rem; }
.deck-btn .deck-words { font-size: .72rem; color: var(--purple); }
.deck-btn.special { background: linear-gradient(160deg, #fff3c4, #ffe08a); }
.deck-btn.all { background: linear-gradient(160deg, #ffd9e6, #ffc2d6); }
.deck-btn .deck-badge { font-size: 1.4rem; }

.how-to { text-align: center; margin-top: 1.6rem; color: var(--ink); font-size: .9rem; }
.legend-dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; background: var(--ink); vertical-align: middle; }
.legend-heart { color: var(--pink); font-size: 1.1rem; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: .7rem; margin: .4rem 0 1.4rem; }
.icon-btn {
  border: none; background: #fff; border-radius: 16px; padding: .55rem .9rem; cursor: pointer;
  font-family: inherit; font-size: 1rem; color: var(--ink); box-shadow: 0 4px 0 rgba(45,42,74,.12);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(45,42,74,.12); }
.progress { flex: 1; height: 16px; background: #fff; border-radius: 20px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(45,42,74,.12); }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), var(--pink)); border-radius: 20px; transition: width .35s ease; }
.score-pill { background: #fff; border-radius: 16px; padding: .5rem .85rem; font-weight: 700; box-shadow: 0 4px 0 rgba(45,42,74,.12); white-space: nowrap; }

/* ---------- Flashcard ---------- */
.card-stage { perspective: 1000px; margin-bottom: 1.4rem; }
.flashcard {
  position: relative; background: var(--card); border-radius: 32px; min-height: 46vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: var(--shadow); border: 6px solid #fff; cursor: pointer; padding: 1.5rem;
  transition: transform .12s ease;
}
.flashcard:active { transform: scale(.99); }
.flashcard.pop { animation: pop .3s ease; }
@keyframes pop { 0%{transform:scale(.96);} 50%{transform:scale(1.03);} 100%{transform:scale(1);} }

.word-display { display: flex; flex-wrap: wrap; justify-content: center; gap: .05em; font-size: clamp(3rem, 16vw, 6rem); font-weight: 700; line-height: 1.5; }
.letter { position: relative; display: inline-block; padding: 0 .02em; }
.letter.heart { color: var(--pink-dark); }
.letter.heart::after {
  content: "♥"; position: absolute; left: 50%; bottom: -.34em; transform: translateX(-50%);
  font-size: .32em; color: var(--pink); line-height: 1;
}
.card-hint { margin-top: 1.6rem; color: var(--purple); font-size: .9rem; text-align: center; }

.star-btn {
  position: absolute; top: .8rem; right: 1rem; border: none; background: none; cursor: pointer;
  font-size: 2rem; color: var(--yellow); line-height: 1; filter: drop-shadow(0 2px 0 rgba(45,42,74,.15));
}
.star-btn.on { animation: starpop .4s ease; }
@keyframes starpop { 0%{transform:scale(1);} 50%{transform:scale(1.4) rotate(15deg);} 100%{transform:scale(1);} }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.round-btn {
  width: 62px; height: 62px; border-radius: 50%; border: none; background: #fff; cursor: pointer;
  font-size: 2rem; color: var(--ink); box-shadow: var(--shadow); font-family: inherit;
}
.round-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(45,42,74,.12); }
.round-btn:disabled { opacity: .35; }
.say-btn {
  border: none; border-radius: 22px; background: linear-gradient(160deg, var(--pink), var(--pink-dark));
  color: #fff; font-family: inherit; font-size: 1.3rem; font-weight: 700; padding: .9rem 1.6rem;
  cursor: pointer; box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: .5rem;
}
.say-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(45,42,74,.12); }
.say-emoji { font-size: 1.3rem; }
.counter { text-align: center; margin-top: 1rem; color: var(--purple); font-size: .95rem; }

/* ---------- Quiz ---------- */
.quiz-body { text-align: center; }
.quiz-prompt { font-size: 1.3rem; margin: 1rem 0 1.2rem; color: var(--ink); }
.big-say { font-size: 1.5rem; padding: 1.1rem 2rem; margin-bottom: 1.8rem; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.opt-btn {
  border: 4px solid #fff; border-radius: 22px; background: var(--card); cursor: pointer;
  font-family: inherit; font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: 700; color: var(--ink);
  padding: 1.1rem .6rem; box-shadow: var(--shadow); transition: transform .1s, background .2s, border-color .2s;
}
.opt-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(45,42,74,.12); }
.opt-btn.correct { background: var(--green); color: #fff; border-color: var(--green); animation: pop .3s; }
.opt-btn.wrong { background: var(--red); color: #fff; border-color: var(--red); animation: shake .4s; }
.opt-btn:disabled { cursor: default; }
@keyframes shake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-8px);} 40%{transform:translateX(8px);} 60%{transform:translateX(-6px);} 80%{transform:translateX(6px);} }
.quiz-feedback { margin-top: 1.4rem; font-size: 1.6rem; min-height: 2rem; font-weight: 700; }
.quiz-feedback.good { color: var(--green); }
.quiz-feedback.bad { color: var(--red); }

/* ---------- Results ---------- */
#results { display: none; }
#results.active { display: flex; min-height: 70vh; align-items: center; justify-content: center; }
.results-card { background: #fff; border-radius: 32px; padding: 2.2rem 1.8rem; text-align: center; box-shadow: var(--shadow); border: 6px solid #fff; width: 100%; }
.results-emoji { font-size: 4.5rem; animation: beat 1.3s ease-in-out infinite; }
#results-title { color: var(--pink-dark); font-size: 1.9rem; margin: .6rem 0; }
.results-score { font-size: 1.3rem; color: var(--ink); margin-bottom: .8rem; }
.results-stars { font-size: 2.2rem; margin-bottom: 1.6rem; letter-spacing: .1em; }
.results-actions { display: flex; flex-direction: column; gap: .7rem; }
.primary-btn { border: none; border-radius: 22px; background: linear-gradient(160deg, var(--blue), #3bb3ab); color: #fff; font-family: inherit; font-size: 1.3rem; font-weight: 700; padding: 1rem; cursor: pointer; box-shadow: var(--shadow); }
.primary-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(45,42,74,.12); }
.ghost-btn { border: 3px solid var(--purple); background: #fff; color: var(--purple); border-radius: 22px; font-family: inherit; font-size: 1.1rem; font-weight: 700; padding: .8rem; cursor: pointer; }

/* ---------- Confetti ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti-piece { position: absolute; width: 12px; height: 12px; top: -20px; will-change: transform; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 360px) {
  .mode-cards { grid-template-columns: 1fr; }
}
