/* ---------- Design tokens ---------- */
:root {
  --sky-top: #BEE3F8;
  --sky-bottom: #FFF6E0;
  --grass: #8BC97C;
  --grass-dark: #6BA95C;
  --accent-coral: #FF8C6B;
  --accent-coral-dark: #F06B47;
  --accent-sun: #FFC857;
  --flower-pink: #FF6FA5;
  --ink: #2B3A4A;
  --ink-soft: #5A6B7A;
  --white: #FFFFFF;
  --danger: #E85D5D;
  --radius: 20px;
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
}

button { font-family: var(--font-body); cursor: pointer; }
input { font-family: var(--font-body); }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.view { display: none; flex: 1; flex-direction: column; }
.view.active { display: flex; }
.view-center { align-items: center; justify-content: center; padding: 24px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
}
.topbar-user {
  font-weight: 700;
  background: var(--white);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.btn-back {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 1rem;
}

.content { padding: 8px 24px 40px; flex: 1; }

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
  margin: 8px 0 20px;
}

/* ---------- Cards / login ---------- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 12px 30px rgba(43, 58, 74, 0.12);
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.brand-flower { font-size: 2.6rem; display: block; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 6px 0 2px;
}
.brand-sub { color: var(--ink-soft); margin: 0 0 24px; font-size: 0.95rem; }

#loginForm { display: flex; flex-direction: column; gap: 14px; }
#loginForm label { text-align: left; font-weight: 700; font-size: 0.9rem; color: var(--ink-soft); }
#loginForm input {
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid #E4EEF5;
  font-size: 1.05rem;
  outline: none;
}
#loginForm input:focus { border-color: var(--accent-coral); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-weight: 800;
  font-size: 1rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent-coral); color: var(--white); box-shadow: 0 6px 16px rgba(255,140,107,0.4); }
.btn-primary:hover { background: var(--accent-coral-dark); }
.btn-secondary { background: #EAF4EC; color: var(--grass-dark); }

/* ---------- Topic grid ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.topic-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 22px;
  text-align: left;
  box-shadow: 0 8px 20px rgba(43,58,74,0.08);
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.topic-card:hover { transform: translateY(-4px); }
.topic-card .icon { font-size: 2rem; }
.topic-card h3 { font-family: var(--font-display); margin: 10px 0 4px; font-size: 1.15rem; }
.topic-card p { margin: 0; color: var(--ink-soft); font-size: 0.88rem; }

/* ---------- Level list ---------- */
.level-list { display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
.level-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--white);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 6px 16px rgba(43,58,74,0.08);
  border: none;
  text-align: left;
  cursor: pointer;
}
.level-row.locked { opacity: 0.55; cursor: not-allowed; }
.level-badge {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent-sun);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
  flex-shrink: 0;
}
.level-row.locked .level-badge { background: #DDE4EA; }
.level-info { flex: 1; }
.level-info .name { font-weight: 800; }
.level-info .meta { color: var(--ink-soft); font-size: 0.85rem; }
.level-row .status { font-size: 1.3rem; }

/* ---------- Play view ---------- */
.view-play { position: relative; }
.sky {
  position: relative;
  flex: 1;
  height: min(52vh, 460px);
  min-height: 320px;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: radial-gradient(circle at 80% 15%, #FFFdf0 0%, transparent 40%);
}
.btn-quit {
  position: absolute; top: 16px; left: 16px;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.85);
  font-size: 1.3rem; color: var(--ink-soft); line-height: 1;
  z-index: 5;
}
.timer-sun {
  position: absolute; top: 16px; right: 16px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent-sun);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.3rem;
  color: var(--ink);
  box-shadow: 0 0 0 6px rgba(255,200,87,0.25);
  z-index: 5;
}
.timer-sun.urgent { background: var(--danger); color: white; box-shadow: 0 0 0 6px rgba(232,93,93,0.25); }

.progress-track {
  position: absolute; top: 16px; left: 66px; transform: none;
  background: rgba(255,255,255,0.85);
  padding: 6px 16px; border-radius: 999px;
  font-weight: 800; font-size: 0.85rem; color: var(--ink-soft);
  z-index: 5;
}

.bubble-zone {
  position: relative;
  width: 100%;
  height: 100%;
}
.bubble {
  position: absolute;
  left: 50%;
  top: 16px; /* JS overwrites this each item and animates it precisely */
  transform: translateX(-50%);
  background: var(--white);
  border-radius: 50%;
  width: clamp(180px, 16vw, 260px);
  height: clamp(180px, 16vw, 260px);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  box-shadow: 0 10px 24px rgba(43,58,74,0.15), inset 0 -8px 16px rgba(190,227,248,0.4);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  text-align: center;
  padding: 12px;
  word-break: break-word;
}
.btn-replay {
  margin-top: 8px;
  border: none; background: #F1F6FA; border-radius: 999px;
  padding: 4px 10px; font-size: 1rem;
}

/* ---------- Garden / answer area ---------- */
.garden {
  background: linear-gradient(180deg, var(--grass) 0%, var(--grass-dark) 100%);
  padding: 18px 24px 28px;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -8px 24px rgba(43,58,74,0.15);
}
.flower-slots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.flower-slot {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.flower-slot.filled { background: transparent; }

.answer-form {
  display: flex;
  gap: 10px;
  max-width: 480px;
  margin: 0 auto;
}
.answer-form input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 999px;
  border: none;
  font-size: 1.1rem;
  outline: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.answer-form input.wrong-hint { box-shadow: 0 0 0 3px var(--danger); }

.feedback {
  text-align: center;
  min-height: 24px;
  margin-top: 10px;
  font-weight: 800;
  color: var(--white);
}
.feedback-line.success { font-size: 1.05rem; }

.feedback-wrong {
  background: rgba(0,0,0,0.18);
  border-radius: 14px;
  padding: 10px 18px;
  margin-top: 2px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}
.feedback-row {
  font-size: 0.95rem;
  margin: 3px 0;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.feedback-label { color: rgba(255,255,255,0.75); font-weight: 700; }
.feedback-typed { text-decoration: line-through; color: #FFD9D0; font-weight: 800; }
.feedback-correct { color: var(--white); font-weight: 800; }
.feedback-countdown {
  margin-top: 8px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
  font-style: italic;
}
#feedbackCountdownNum { font-weight: 800; font-style: normal; }

/* ---------- Result view ---------- */
.result-card { max-width: 420px; }
.result-flowers { font-size: 2.2rem; margin: 12px 0; letter-spacing: 4px; }
.result-percent { font-family: var(--font-display); font-size: 2rem; color: var(--accent-coral-dark); }
.result-message { color: var(--ink-soft); margin: 12px 0 20px; }
.result-actions { display: flex; gap: 12px; justify-content: center; }

/* ---------- Confetti ---------- */
.confetti-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.2; }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .content { padding: 8px 16px 32px; }
  .card { padding: 28px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .confetti-piece { animation-duration: 0.01s !important; }
}
