:root {
  --purple: #5B3EF2;
  --purple-dark: #3F2AB0;
  --pink: #FF4FA0;
  --yellow: #FFC93C;
  --green: #2BD576;
  --red: #FF5A5A;
  --blue: #34C1FF;
  --bg: #F4F1FF;
  --card-bg: #FFFFFF;
  --text: #2A2350;
  --text-soft: #6E6591;
  --radius: 20px;
  --shadow: 0 8px 24px rgba(60, 40, 140, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16112B;
    --card-bg: #221C40;
    --text: #F1EEFF;
    --text-soft: #A79DD6;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px) 16px;
}

.screen { padding-top: 12px; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0 4px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }

.brand { display: flex; align-items: center; gap: 8px; }
.brand-emoji { font-size: 28px; }
.brand h1 { font-size: 22px; margin: 0; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }

.points-banner {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 12px 0;
  box-shadow: var(--shadow);
  text-align: center;
}
.points-value { font-size: 40px; font-weight: 800; line-height: 1; }
.pts-label { font-size: 16px; font-weight: 600; opacity: 0.9; }
.points-sub { margin-top: 6px; font-size: 13px; opacity: 0.85; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.stat-chip {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 4px;
  text-align: center;
}
.stat-num { display: block; font-size: 20px; font-weight: 800; color: var(--purple); }
@media (prefers-color-scheme: dark) { .stat-num { color: #B9A6FF; } }
.stat-name { display: block; font-size: 11px; color: var(--text-soft); margin-top: 2px; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 14px 0;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

.setup-block { margin-bottom: 16px; }
.setup-label { font-weight: 700; font-size: 13px; color: var(--text-soft); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em; }

.tables-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.table-toggle {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--bg);
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
}
.table-toggle.active {
  background: var(--purple);
  color: white;
  border-color: var(--purple-dark);
}

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

.chip-btn {
  border: none;
  background: var(--bg);
  color: var(--purple);
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) { .chip-btn { color: #C6B6FF; } }
.chip-btn.danger { color: var(--red); }

.option-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 2px solid var(--bg);
  background: var(--bg);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.pill.active { background: var(--yellow); border-color: #E0A800; color: #4A3600; }

.big-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 16px;
  font-size: 18px;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  box-shadow: var(--shadow);
  cursor: pointer;
  margin-top: 6px;
}
.big-btn:active { transform: scale(0.98); }
.big-btn.secondary {
  background: var(--card-bg);
  color: var(--purple);
  border: 2px solid var(--purple);
}
@media (prefers-color-scheme: dark) { .big-btn.secondary { color: #C6B6FF; border-color: #C6B6FF; } }

.install-hint {
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
  margin-top: 18px;
}

/* QUIZ */
.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.quiz-progress { font-weight: 700; color: var(--text-soft); }
.quiz-score { font-weight: 800; font-size: 18px; }

.timer-bar-track {
  height: 14px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}
.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  border-radius: 999px;
  transition: width 0.1s linear, background-color 0.3s;
}
.timer-bar-fill.warn { background: linear-gradient(90deg, var(--yellow), var(--red)); }
.timer-bar-fill.danger { background: var(--red); }

.streak-badge {
  text-align: center;
  font-weight: 800;
  color: #B8590A;
  background: #FFE8B8;
  border-radius: 999px;
  padding: 6px 12px;
  width: fit-content;
  margin: 8px auto;
  animation: pop .3s ease;
}
@keyframes pop { from { transform: scale(0.7); opacity: 0;} to { transform: scale(1); opacity: 1;} }

.question-area {
  text-align: center;
  margin: 28px 0;
  position: relative;
}
.question-text {
  font-size: 56px;
  font-weight: 900;
  color: var(--text);
}
.feedback-flash {
  position: absolute;
  top: -6px; left: 0; right: 0;
  font-size: 22px;
  font-weight: 800;
}
.feedback-flash.correct { color: var(--green); }
.feedback-flash.wrong { color: var(--red); }

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.answer-btn {
  padding: 22px 10px;
  font-size: 26px;
  font-weight: 800;
  border-radius: 18px;
  border: none;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.answer-btn:active { transform: scale(0.96); }
.answer-btn.correct { background: var(--green); color: white; }
.answer-btn.wrong { background: var(--red); color: white; }
.answer-btn.disabled { pointer-events: none; opacity: 0.6; }

/* RESULTS */
.results-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 20px;
  text-align: center;
  margin-top: 24px;
}
.results-emoji { font-size: 56px; }
.results-card h2 { margin: 6px 0 2px; }
.results-points-earned {
  font-size: 30px;
  font-weight: 900;
  color: var(--purple);
  margin: 10px 0 18px;
}
@media (prefers-color-scheme: dark) { .results-points-earned { color: #C6B6FF; } }

.results-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.rstat-num { font-size: 18px; font-weight: 800; }
.rstat-label { font-size: 11px; color: var(--text-soft); margin-top: 2px; }

.results-missed {
  text-align: left;
  font-size: 13px;
  color: var(--text-soft);
  margin: 12px 0;
  max-height: 100px;
  overflow-y: auto;
}
.results-missed .miss-row { padding: 3px 0; }

/* REWARDS */
.mini-points { font-weight: 800; }
.rewards-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.reward-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.reward-emoji { font-size: 30px; }
.reward-info { flex: 1; }
.reward-name { font-weight: 700; }
.reward-cost { color: var(--text-soft); font-size: 13px; }
.redeem-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  background: var(--purple);
  color: white;
  cursor: pointer;
}
.redeem-btn:disabled { background: #C9C4E8; cursor: not-allowed; }

.empty-note { color: var(--text-soft); font-size: 14px; text-align: center; padding: 20px 0; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 12, 50, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.modal-emoji { font-size: 48px; }

/* PIN */
.pin-card { text-align: center; margin-top: 20px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 20px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 2px solid var(--purple); display: inline-block; }
.pin-dot.filled { background: var(--purple); }
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}
.pin-key {
  aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}
.pin-key.ghost { visibility: hidden; box-shadow: none; }
.pin-error { color: var(--red); font-weight: 700; margin-top: 14px; }

/* PROFILES */
.profiles-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}
.profile-card {
  background: var(--card-bg);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 10px;
  text-align: center;
  border: none;
  cursor: pointer;
}
.profile-card:active { transform: scale(0.97); }
.profile-card-avatar { font-size: 40px; }
.profile-card-name { font-weight: 800; margin-top: 6px; }
.profile-card-points { color: var(--text-soft); font-size: 12px; margin-top: 2px; }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.avatar-toggle {
  aspect-ratio: 1;
  font-size: 26px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: var(--bg);
  cursor: pointer;
}
.avatar-toggle.active { border-color: var(--purple); background: #E9E3FF; }
@media (prefers-color-scheme: dark) { .avatar-toggle.active { background: #362A6E; } }

.full-width { width: 100%; margin-top: 6px; }

.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  border: none;
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  margin: 4px 0 2px;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
}
.profile-chip-avatar {
  font-size: 20px;
  background: var(--bg);
  border-radius: 50%;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.profile-chip-caret { color: var(--text-soft); font-size: 12px; }

.card-subtitle { color: var(--text-soft); font-size: 12px; margin: -6px 0 10px; }

/* PARENT DASHBOARD */
.pending-list, .manage-rewards-list, .history-list { display: flex; flex-direction: column; gap: 8px; }
.pending-row, .manage-row, .history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}
.pending-row .grow, .manage-row .grow { flex: 1; }
.small-btn {
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  background: var(--green);
  color: white;
}
.small-btn.remove { background: var(--red); }

.add-reward-row { display: flex; gap: 6px; margin-top: 12px; }
.emoji-input { width: 44px; text-align: center; }
.text-input { flex: 1; }
.num-input { width: 60px; }
.add-reward-row input {
  border: 2px solid var(--bg);
  border-radius: 10px;
  padding: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

.history-row { justify-content: space-between; color: var(--text-soft); }

button { font-family: inherit; }
