/* ============================================================
   features.css — Stats, Badges, Friend Battle, Challenge
   Loads LAST. Tokens only. "Calm Scholar" + kid-friendly.
   ============================================================ */

/* ── Stats screen shell ─────────────────────────────────── */
.stats-screen {
  padding: var(--sp-4) var(--sp-4) calc(var(--nav-h) + var(--sp-6));
  max-width: 640px;
  margin: 0 auto;
}
.stats-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.stats-tab {
  flex: 1;
  padding: 9px;
  border: none;
  background: none;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  font-family: inherit;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.stats-tab:active { transform: scale(0.96); }
.stats-tab.active { background: var(--primary-soft); color: var(--primary); }
.stats-view { padding-top: var(--sp-4); }

.section-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin: var(--sp-5) 0 var(--sp-3);
}

/* ── Overview: hero ─────────────────────────────────────── */
.stats-hero {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
}
.streak-card {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent), var(--warning));
  color: #fff;
  box-shadow: var(--sh-md);
}
.streak-card .material-symbols-rounded { font-size: 2.4rem; font-variation-settings: 'FILL' 1; }
.streak-num { font-size: var(--fs-3xl); font-weight: var(--fw-extra); line-height: 1; }
.streak-lbl { font-size: var(--fs-sm); opacity: 0.92; }

.stat-bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-3) var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  text-align: center;
}
.stat-bubble .material-symbols-rounded { font-size: 1.4rem; color: var(--primary); font-variation-settings: 'FILL' 1; }
.stat-bubble-val { font-size: var(--fs-lg); font-weight: var(--fw-bold); color: var(--text); }
.stat-bubble-lbl { font-size: var(--fs-xs); color: var(--text-3); }

/* ── Overview: mastery ──────────────────────────────────── */
.mastery-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.mastery-row:last-child { border-bottom: none; }
.mastery-icon { font-size: 1.5rem; color: var(--m-color, var(--primary)); font-variation-settings: 'FILL' 1; flex-shrink: 0; }
.mastery-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.mastery-top { display: flex; justify-content: space-between; font-size: var(--fs-sm); }
.mastery-name { color: var(--text); font-weight: var(--fw-semibold); }
.mastery-frac { color: var(--text-3); }
.mastery-bar { height: 8px; background: var(--surface-sunken); border-radius: var(--r-full); overflow: hidden; }
.mastery-fill { height: 100%; background: var(--m-color, var(--primary)); border-radius: var(--r-full); transition: width var(--dur-slow) var(--ease-out); }

/* ── Overview: history ──────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-item > .material-symbols-rounded { font-size: 1.3rem; font-variation-settings: 'FILL' 1; }
.history-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.history-mode { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.history-date { font-size: var(--fs-xs); color: var(--text-3); }
.history-score { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--primary); }
.history-acc { font-size: var(--fs-xs); color: var(--text-3); min-width: 38px; text-align: right; }

/* ── Badges ─────────────────────────────────────────────── */
.badges-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
  box-shadow: var(--sh-sm);
}
.badges-summary-top {
  display: flex; justify-content: space-between;
  font-size: var(--fs-base); font-weight: var(--fw-semibold);
  color: var(--text); margin-bottom: var(--sp-2);
}
.badges-count { color: var(--primary); font-weight: var(--fw-bold); }
.badges-summary-bar { height: 8px; background: var(--surface-sunken); border-radius: var(--r-full); overflow: hidden; }
.badges-summary-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: var(--r-full); transition: width var(--dur-slow) var(--ease-out); }

.badges-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}
@media (min-width: 520px) { .badges-grid { grid-template-columns: repeat(3, 1fr); } }

.badge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: var(--sp-4) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  position: relative;
}
.badge-medal {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--badge-color, var(--primary));
  box-shadow: var(--sh-md);
}
.badge-medal .material-symbols-rounded { font-size: 1.7rem; color: #fff; font-variation-settings: 'FILL' 1; }
.badge-name { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text); }
.badge-desc { font-size: var(--fs-xs); color: var(--text-3); line-height: var(--lh-snug); }

.badge-card.earned { border-color: var(--badge-color, var(--primary)); }
.badge-card.locked { opacity: 0.9; }
.badge-card.locked .badge-medal { background: var(--surface-sunken); box-shadow: none; }
.badge-card.locked .badge-medal .material-symbols-rounded { color: var(--text-3); }
.badge-card.locked .badge-name { color: var(--text-2); }

.badge-progress { width: 100%; height: 5px; background: var(--surface-sunken); border-radius: var(--r-full); overflow: hidden; margin-top: 2px; }
.badge-progress-fill { height: 100%; background: var(--badge-color, var(--primary)); border-radius: var(--r-full); transition: width var(--dur-slow) var(--ease-out); }
.badge-progress-txt { font-size: var(--fs-xs); color: var(--text-3); }

/* ── Battles view ───────────────────────────────────────── */
.battle-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.battle-stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--sp-3) var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
}
.battle-stat-num { font-size: var(--fs-xl); font-weight: var(--fw-extra); color: var(--text); }
.battle-stat-lbl { font-size: var(--fs-xs); color: var(--text-3); }

.battle-winrate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.battle-winrate-top {
  display: flex; justify-content: space-between;
  font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  color: var(--text); margin-bottom: var(--sp-2);
}
.battle-winrate-bar { height: 10px; background: var(--surface-sunken); border-radius: var(--r-full); overflow: hidden; }
.battle-winrate-fill { height: 100%; background: linear-gradient(90deg, var(--success), var(--primary)); border-radius: var(--r-full); transition: width var(--dur-slow) var(--ease-out); }

.battle-cta { margin-top: var(--sp-2); }

/* ── Friend-battle RESULT banner (result screen) ────────── */
.battle-result-banner {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  font-weight: var(--fw-bold);
  box-shadow: var(--sh-md);
}
.battle-result-banner .material-symbols-rounded { font-size: 2rem; font-variation-settings: 'FILL' 1; flex-shrink: 0; }
.battle-result-text { display: flex; flex-direction: column; }
.battle-result-text strong { font-size: var(--fs-lg); }
.battle-result-text span { font-size: var(--fs-sm); opacity: 0.9; font-weight: var(--fw-medium); }
.battle-won { background: linear-gradient(135deg, var(--success), var(--primary)); color: #fff; }
.battle-tied { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.battle-tied .material-symbols-rounded { color: var(--primary); }
.battle-lost { background: var(--surface-alt); color: var(--text-2); border: 1px solid var(--border); }
.battle-lost .material-symbols-rounded { color: var(--text-3); }

/* ── Badges-earned strip (result screen) ────────────────── */
.badges-earned {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--sh-sm);
}
.badges-earned-hd {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); font-weight: var(--fw-bold);
  color: var(--text); margin-bottom: var(--sp-3);
}
.badges-earned-hd .material-symbols-rounded { color: var(--accent); font-variation-settings: 'FILL' 1; }
.badges-earned-list { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: center; }
.badge-mini { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 76px; }
.badge-mini .material-symbols-rounded {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--badge-color, var(--primary));
  color: #fff;
  font-size: 1.6rem;
  font-variation-settings: 'FILL' 1;
  box-shadow: var(--sh-sm);
}
.badge-mini-name { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text); text-align: center; line-height: var(--lh-tight); }

/* ── Challenge intro (quiz.js) ──────────────────────────── */
.challenge-hero {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) 0 var(--sp-4);
  text-align: center;
}
.challenge-icon {
  font-size: 3rem; color: var(--primary); font-variation-settings: 'FILL' 1;
  animation: feat-bounce 1.6s var(--ease-spring) infinite;
}
.challenge-sub { font-size: var(--fs-base); color: var(--text-2); }
.challenge-facts {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: var(--sp-2); margin: var(--sp-4) 0;
}
.challenge-fact {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  color: var(--text-2);
  box-shadow: var(--sh-sm);
}
.challenge-fact .material-symbols-rounded { font-size: 1rem; color: var(--primary); }
.challenge-fact.challenge-target { border-color: var(--accent); color: var(--accent); }
.challenge-fact.challenge-target .material-symbols-rounded { color: var(--accent); }

@keyframes feat-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  .challenge-icon { animation: none; }
}
