:root {
  --purple: #7c5cff;
  --purple-dark: #5b3ff0;
  --pink: #ff5c9e;
  --orange: #ff9e42;
  --yellow: #ffce4a;
  --green: #3ecf8e;
  --blue: #4ac9ff;
  --ink: #2c2a4a;
  --muted: #7a7897;
  --bg-card: #ffffff;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(76, 60, 150, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #f4f1ff 0%, #fdf2f8 50%, #fff9ec 100%);
  background-attachment: fixed;
}

h1, h2, h3, .brand-emoji, .btn, .tab-btn, .topbar-brand {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
}

.hidden { display: none !important; }

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.muted { color: var(--muted); font-size: 0.95rem; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  box-shadow: 0 6px 16px rgba(124, 92, 255, 0.4);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(124, 92, 255, 0.55); }

.btn-ghost {
  background: rgba(124, 92, 255, 0.1);
  color: var(--purple-dark);
}
.btn-ghost:hover { background: rgba(124, 92, 255, 0.18); }

.btn-secondary {
  background: white;
  color: var(--purple-dark);
  border: 2px solid var(--purple);
}

/* ===== Auth View ===== */
#view-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand-emoji { font-size: 3rem; }
.brand h1 { font-size: 2.1rem; margin: 8px 0 4px; color: var(--purple-dark); }
.tagline { color: var(--muted); margin: 0; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; background: #f4f2ff; padding: 6px; border-radius: 999px; }
.tab-btn {
  flex: 1; border: none; background: transparent; padding: 10px; border-radius: 999px;
  font-weight: 700; cursor: pointer; color: var(--muted); font-size: 0.95rem;
}
.tab-btn.active { background: white; color: var(--purple-dark); box-shadow: 0 2px 8px rgba(124,92,255,0.25); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 0.9rem; color: var(--ink); }
.auth-form input {
  border: 2px solid #e8e5fb; border-radius: 12px; padding: 12px 14px; font-size: 1rem;
  font-family: inherit; outline: none; transition: border-color 0.15s;
}
.auth-form input:focus { border-color: var(--purple); }
.form-error { color: #e2437a; font-weight: 700; font-size: 0.88rem; min-height: 1.2em; margin: 0; }

/* ===== Mascot Picker ===== */
.mascot-picker-wrap { max-width: 720px; margin: 0 auto; padding: 48px 20px 60px; text-align: center; }
.mascot-picker-wrap h1 { font-size: 1.8rem; color: var(--purple-dark); margin-bottom: 6px; }
.mascot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; margin: 28px 0; }
.mascot-option {
  background: white; border: 3px solid #eee9ff; border-radius: 18px; padding: 16px 10px; cursor: pointer;
  transition: transform 0.12s, border-color 0.12s; text-align: center;
}
.mascot-option:hover { transform: translateY(-3px); border-color: var(--purple); }
.mascot-option.selected { border-color: var(--purple); background: #f6f4ff; }
.mascot-option .mascot-avatar-lg { width: 84px; height: 84px; margin: 0 auto 10px; }
.mascot-option .mascot-avatar-lg svg { width: 100%; height: 100%; }
.mascot-option .mascot-name { font-weight: 800; font-size: 0.95rem; }
.mascot-option .mascot-tagline { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.mascot-option .mascot-preview-btn {
  margin-top: 8px; border: 2px solid #eee9ff; background: white; border-radius: 999px;
  padding: 5px 12px; font-size: 0.75rem; font-weight: 700; color: var(--purple-dark); cursor: pointer;
}
.mascot-option .mascot-preview-btn:hover { border-color: var(--purple); }
.mascot-option .mascot-preview-btn.speaking { background: var(--purple); color: white; border-color: var(--purple); }

.voice-picker-row {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px;
  font-size: 0.85rem; font-weight: 700; color: var(--ink);
}
.voice-picker-row select {
  border: 2px solid #e8e5fb; border-radius: 10px; padding: 6px 10px; font-family: inherit; font-size: 0.85rem;
}

.mascot-mini-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #eee9ff; padding: 0; cursor: pointer;
  background: white; overflow: hidden; flex-shrink: 0;
}
.mascot-mini-btn:hover { border-color: var(--purple); }
.mascot-mini-btn svg { width: 100%; height: 100%; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: white; box-shadow: 0 2px 10px rgba(76,60,150,0.08);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap; gap: 12px;
}
.topbar-brand { font-weight: 800; font-size: 1.2rem; color: var(--purple-dark); }
.topbar-user { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user-name { font-weight: 700; }

.level-pill {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #593500; font-weight: 800; padding: 6px 14px; border-radius: 999px; font-size: 0.85rem;
}

.xp-bar-wrap { display: flex; align-items: center; gap: 8px; }
.xp-bar-track { width: 140px; height: 10px; background: #eee9ff; border-radius: 999px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--purple), var(--pink)); width: 0%; transition: width 0.4s ease; }
.xp-bar-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; white-space: nowrap; }

.journey-title { font-weight: 800; font-size: 1.1rem; color: var(--purple-dark); text-align: center; flex: 1; }

/* ===== Dashboard ===== */
.dashboard-main {
  max-width: 960px; margin: 0 auto; padding: 28px 20px 60px;
  display: grid; gap: 22px;
}
.ask-card h2, .badges-card h2, .topics-card h2 { margin: 0 0 6px; font-size: 1.4rem; }
.ask-form { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.ask-form input {
  flex: 1; min-width: 220px; border: 2px solid #e8e5fb; border-radius: 12px;
  padding: 14px 16px; font-size: 1.05rem; font-family: inherit; outline: none;
}
.ask-form input:focus { border-color: var(--purple); }

.ask-suggestions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; }
.suggestion-chip {
  background: #f4f2ff; border: none; padding: 8px 16px; border-radius: 999px;
  font-weight: 700; cursor: pointer; color: var(--purple-dark); font-size: 0.9rem;
}
.suggestion-chip:hover { background: #e8e3ff; }

.badges-grid { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.badge-item {
  background: linear-gradient(135deg, #fff7e0, #ffe9d6); border-radius: 16px;
  padding: 14px 18px; text-align: center; min-width: 110px;
}
.badge-item .badge-emoji { font-size: 1.8rem; }
.badge-item .badge-label { font-weight: 800; font-size: 0.8rem; margin-top: 4px; color: #8a5a1f; }

.topic-filters { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chip {
  border: 2px solid #ecebfc;
  background: #faf9ff;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover { border-color: var(--purple); }
.filter-chip.active { background: var(--purple); border-color: var(--purple); color: #fff; }
.topics-groups { margin-top: 18px; display: flex; flex-direction: column; gap: 22px; }
.topic-subject-group h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topic-subject-group .subject-count { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.topics-empty { color: var(--muted); padding: 8px 0; }
.topics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 16px; }
.topic-tile {
  border: 2px solid #eee9ff; border-radius: 16px; padding: 16px; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s; text-align: left; background: white;
}
.topic-tile:hover { transform: translateY(-3px); box-shadow: 0 8px 18px rgba(124,92,255,0.18); border-color: var(--purple); }
.topic-tile .topic-emoji { font-size: 1.8rem; }
.topic-tile .topic-title { font-weight: 800; margin: 8px 0 4px; font-size: 1rem; }
.topic-tile .topic-subject { font-size: 0.78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.topic-tile .topic-grade { position: absolute; top: 10px; right: 12px; font-size: 0.7rem; font-weight: 800; color: var(--purple-dark); background: #ede9ff; padding: 2px 8px; border-radius: 999px; }
.topic-tile { position: relative; }
.topic-tile .topic-progress-bar { margin-top: 10px; height: 6px; background: #f0edff; border-radius: 999px; overflow: hidden; }
.topic-tile .topic-progress-fill { height: 100%; background: var(--green); }

/* ===== Journey View ===== */
.journey-main { max-width: 760px; margin: 0 auto; padding: 28px 20px 80px; }

.journey-map { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 28px; flex-wrap: wrap; }
.map-node {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.9rem; background: #eee9ff; color: var(--muted); border: 3px solid #eee9ff;
  flex-shrink: 0;
}
.map-node.done { background: var(--green); color: white; border-color: var(--green); }
.map-node.current { background: white; color: var(--purple-dark); border-color: var(--purple); box-shadow: 0 0 0 5px rgba(124,92,255,0.15); }
.map-connector { width: 24px; height: 4px; background: #eee9ff; border-radius: 2px; }
.map-connector.done { background: var(--green); }

.step-card { text-align: left; }
.step-title { font-size: 1.5rem; margin: 10px 0 4px; }
.step-count { color: var(--muted); font-weight: 700; font-size: 0.85rem; margin-bottom: 14px; }

.step-illustration { width: 100%; max-width: 420px; margin: 0 auto 16px; border-radius: 16px; overflow: hidden; }
.step-illustration svg { width: 100%; height: auto; display: block; }

.mascot-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; }
.mascot-row .mascot-avatar { width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; }
.mascot-row .mascot-avatar svg { width: 100%; height: 100%; }
.mascot-row .read-aloud-btn {
  border: 2px solid #e8e5fb; background: white; border-radius: 999px; padding: 8px 16px;
  font-weight: 700; font-size: 0.85rem; cursor: pointer; color: var(--purple-dark);
  display: flex; align-items: center; gap: 6px;
}
.mascot-row .read-aloud-btn:hover { border-color: var(--purple); }
.mascot-row .read-aloud-btn.speaking { background: var(--purple); color: white; border-color: var(--purple); }
.step-explanation { font-size: 1.08rem; line-height: 1.6; margin: 16px 0; }

.fun-fact-box {
  background: linear-gradient(135deg, #eafaf1, #e5f6ff); border-radius: 14px; padding: 14px 18px;
  font-size: 0.95rem; margin: 18px 0; display: flex; gap: 10px; align-items: flex-start;
}
.fun-fact-box .ff-emoji { font-size: 1.3rem; }

.quiz-box { margin-top: 22px; padding-top: 20px; border-top: 2px dashed #eee9ff; }
.quiz-question { font-weight: 800; font-size: 1.05rem; margin-bottom: 14px; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  text-align: left; border: 2px solid #e8e5fb; border-radius: 12px; padding: 12px 16px;
  background: white; cursor: pointer; font-family: inherit; font-size: 0.98rem; font-weight: 600;
  transition: border-color 0.12s, background 0.12s;
}
.quiz-option:hover { border-color: var(--purple); }
.quiz-option.correct { border-color: var(--green); background: #eafaf1; }
.quiz-option.incorrect { border-color: #e2437a; background: #fdecf1; }
.quiz-option:disabled { cursor: default; }

.quiz-feedback { margin-top: 14px; font-weight: 700; min-height: 1.2em; }
.quiz-feedback.correct { color: #1f9d63; }
.quiz-feedback.incorrect { color: #e2437a; }

.step-actions { margin-top: 22px; display: flex; justify-content: flex-end; }

/* ===== Celebration Overlay ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(44, 42, 74, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.celebration-card { text-align: center; max-width: 380px; }
.celebration-emoji { font-size: 2.6rem; margin-bottom: 6px; }
.celebration-card h2 { margin: 0 0 10px; color: var(--purple-dark); }
.celebration-card p { margin: 6px 0; font-weight: 700; }
.celebration-card .btn { margin-top: 18px; }

@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .xp-bar-track { width: 90px; }
  .dashboard-main, .journey-main { padding-left: 14px; padding-right: 14px; }
}
