/* ============================================================
   LexiRoots - Gamification Visual Elements
   XP, Hearts, Streaks, Levels, Leaderboard, Challenges
   Class names match JS templates exactly (flat hyphens)
   ============================================================ */


/* =========================
   XP BAR
   ========================= */
.xp-bar-container {
  margin-bottom: var(--space-4);
}

.xp-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.xp-bar-level {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
}

.xp-bar-xp {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.xp-bar {
  position: relative;
  width: 100%;
  height: 8px;
  background: var(--color-surface-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  min-width: 0;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light), var(--color-accent));
  transition: width 0.5s var(--ease-out);
  position: relative;
}

.xp-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 100%
  );
  animation: xpShimmer 2.5s ease-in-out infinite;
}

@keyframes xpShimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}


/* =========================
   HEARTS DISPLAY
   ========================= */
.hearts-badge {
  display: flex;
  align-items: center;
  gap: 3px;
}

.heart {
  font-size: var(--text-lg);
  line-height: 1;
  transition: transform var(--duration-fast) var(--ease-bounce);
}

.heart-full {
  /* Emoji handles the visual; add subtle glow */
  filter: drop-shadow(0 1px 2px rgba(231, 76, 60, 0.3));
}

.heart-empty {
  opacity: 0.3;
  filter: grayscale(0.5);
}


/* =========================
   STREAK
   ========================= */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-warning);
}

.streak-icon {
  font-size: var(--text-lg);
  line-height: 1;
  animation: flameGlow 2s ease-in-out infinite;
}

@keyframes flameGlow {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(253, 203, 110, 0.3));
    transform: scale(1);
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(253, 203, 110, 0.5));
    transform: scale(1.1);
  }
}


/* =========================
   XP FLOAT ANIMATION
   ========================= */
.xp-float {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  font-size: var(--text-xl);
  font-weight: var(--font-black);
  color: var(--color-primary-light);
  text-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
  opacity: 1;
  transition: none;
}

.xp-float-animate {
  animation: xpFloatUp 1.2s var(--ease-out) forwards;
}

@keyframes xpFloatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(0.6);
  }
  20% {
    opacity: 1;
    transform: translateY(-12px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-70px) scale(0.8);
  }
}


/* =========================
   LEVEL UP
   ========================= */
.modal-level-up {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-up-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-6);
  position: relative;
  overflow: hidden;
}

.level-up-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.level-up-particles::before,
.level-up-particles::after {
  content: '';
  position: absolute;
  border-radius: var(--radius-full);
  animation: particleDrift 3s ease-in-out infinite;
}

.level-up-particles::before {
  width: 6px;
  height: 6px;
  background: var(--color-primary-light);
  top: 20%;
  left: 15%;
  animation-delay: 0s;
}

.level-up-particles::after {
  width: 8px;
  height: 8px;
  background: var(--color-accent);
  top: 30%;
  right: 20%;
  animation-delay: 1s;
}

@keyframes particleDrift {
  0%, 100% {
    opacity: 0.4;
    transform: translateY(0) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-20px) scale(1.5);
  }
}

.level-up-icon {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: var(--space-4);
  animation: bounceIn 0.6s var(--ease-bounce) 0.2s both;
}

.level-up-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-black);
  color: var(--color-text);
  margin-bottom: var(--space-2);
  animation: fadeInUp var(--duration-slow) var(--ease-out) 0.4s both;
}

.level-up-number {
  font-size: 5rem;
  font-weight: var(--font-black);
  line-height: 1;
  margin-bottom: var(--space-3);
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: levelNumPop 0.8s var(--ease-bounce) 0.5s both;
}

@keyframes levelNumPop {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-15deg);
  }
  60% {
    transform: scale(1.1) rotate(3deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.level-up-subtitle {
  font-size: var(--text-md);
  color: var(--color-text-muted);
  animation: fadeInUp var(--duration-slow) var(--ease-out) 0.6s both;
}


/* =========================
   ACHIEVEMENT TOAST
   ========================= */
.achievement-toast {
  position: fixed;
  top: calc(var(--top-bar-height) + var(--safe-area-top) + var(--space-4));
  left: var(--space-4);
  right: var(--space-4);
  max-width: 400px;
  margin: 0 auto;
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: linear-gradient(135deg, var(--color-surface), var(--color-surface-light));
  border: 1.5px solid rgba(108, 92, 231, 0.3);
  border-radius: var(--radius-lg);
  box-shadow:
    var(--shadow-lg),
    0 0 30px rgba(108, 92, 231, 0.15);
  transform: translateY(-120%);
  animation: achievementSlideIn 0.6s var(--ease-bounce) forwards;
}

.achievement-toast-show {
  transform: translateY(0);
}

.achievement-toast-icon {
  font-size: var(--text-3xl);
  line-height: 1;
  flex-shrink: 0;
  animation: badgePop 0.5s var(--ease-bounce) 0.3s both;
}

.achievement-toast-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 2px;
}

.achievement-toast-title {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.achievement-toast-name {
  font-size: var(--text-md);
  font-weight: var(--font-bold);
  color: var(--color-text);
}

@keyframes achievementSlideIn {
  0% {
    transform: translateY(-120%);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes achievementSlideOut {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-120%);
    opacity: 0;
  }
}

@keyframes badgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}


/* =========================
   ACHIEVEMENT CARDS (Profile)
   ========================= */
.achievement-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  transition:
    transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) ease,
    border-color var(--duration-base) ease;
}

.achievement-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.achievement-card.earned {
  border-color: rgba(0, 206, 201, 0.35);
  background: linear-gradient(135deg, var(--color-surface), rgba(0, 206, 201, 0.04));
}

.achievement-card.locked {
  opacity: 0.4;
  filter: grayscale(0.8);
}

.achievement-card.locked:hover {
  transform: none;
  box-shadow: none;
}

.achievement-icon {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}

.achievement-name {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-text);
  margin-bottom: 2px;
}

.achievement-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: var(--leading-tight);
}


/* =========================
   LEADERBOARD
   ========================= */
.leaderboard-screen {
  padding: var(--space-4) 0;
}

.leaderboard-tabs {
  display: flex;
  gap: var(--space-1);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 3px;
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}

.leaderboard-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  user-select: none;
  -webkit-user-select: none;
}

.leaderboard-tab:hover {
  color: var(--color-text);
}

.leaderboard-tab.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  transition:
    transform var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.leaderboard-item:hover {
  background: var(--color-surface-light);
}

.leaderboard-item-me {
  border-color: rgba(108, 92, 231, 0.4);
  background: rgba(108, 92, 231, 0.06);
}

.leaderboard-item-me:hover {
  background: rgba(108, 92, 231, 0.1);
}

/* Top 3 ranks */
.leaderboard-top-1 {
  border-color: rgba(255, 215, 0, 0.3);
  background: rgba(255, 215, 0, 0.04);
}

.leaderboard-top-1 .leaderboard-rank {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #1a1a2e;
  box-shadow: 0 2px 12px rgba(255, 215, 0, 0.3);
}

.leaderboard-top-2 {
  border-color: rgba(192, 192, 192, 0.2);
  background: rgba(192, 192, 192, 0.03);
}

.leaderboard-top-2 .leaderboard-rank {
  background: linear-gradient(135deg, #C0C0C0, #A8A8A8);
  color: #1a1a2e;
  box-shadow: 0 2px 8px rgba(192, 192, 192, 0.2);
}

.leaderboard-top-3 {
  border-color: rgba(205, 127, 50, 0.2);
  background: rgba(205, 127, 50, 0.03);
}

.leaderboard-top-3 .leaderboard-rank {
  background: linear-gradient(135deg, #CD7F32, #B87333);
  color: #1a1a2e;
  box-shadow: 0 2px 8px rgba(205, 127, 50, 0.2);
}

.leaderboard-rank {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-black);
  border-radius: var(--radius-full);
  flex-shrink: 0;
  background: var(--color-surface-light);
  color: var(--color-text-muted);
}

.leaderboard-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-surface-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.leaderboard-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.leaderboard-name {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-level {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.leaderboard-xp {
  font-size: var(--text-md);
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}


/* =========================
   CHALLENGE CARDS
   ========================= */
.challenge-screen {
  padding: var(--space-4) 0;
}

.challenge-create-section,
.challenge-join-section,
.challenge-list-section {
  margin-bottom: var(--space-6);
}

.challenge-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.challenge-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  overflow: hidden;
  position: relative;
  transition:
    transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) ease;
}

.challenge-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.challenge-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.challenge-lesson-name {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-accent);
}

.challenge-card-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-4) 0;
}

.challenge-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
}

.challenge-player-name {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-text);
  margin-bottom: var(--space-1);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.challenge-player-score {
  font-size: var(--text-2xl);
  font-weight: var(--font-black);
  color: var(--color-text);
}

.challenge-vs {
  font-size: var(--text-lg);
  font-weight: var(--font-black);
  color: var(--color-accent-secondary);
  flex-shrink: 0;
  opacity: 0.8;
}

.challenge-result {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  text-align: center;
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.challenge-result.win {
  color: var(--color-success-light);
  background: rgba(0, 184, 148, 0.12);
}

.challenge-result.loss {
  color: var(--color-danger-light);
  background: rgba(214, 48, 49, 0.12);
}

.challenge-result.tie {
  color: var(--color-warning);
  background: rgba(253, 203, 110, 0.12);
}

.challenge-share {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  background: var(--color-surface-light);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}

.challenge-share-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.challenge-share-id {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
  user-select: all;
  -webkit-user-select: all;
  letter-spacing: 0.5px;
}

.challenge-copy-btn {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.challenge-play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all var(--duration-fast) ease;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.challenge-play-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
}

.challenge-play-btn:active {
  transform: translateY(0);
}


/* =========================
   SHARED KEYFRAMES
   ========================= */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}


/* =========================
   REDUCED MOTION
   ========================= */
@media (prefers-reduced-motion: reduce) {
  .xp-bar-fill,
  .xp-bar-fill::after,
  .streak-icon,
  .xp-float,
  .xp-float-animate,
  .level-up-icon,
  .level-up-number,
  .level-up-particles::before,
  .level-up-particles::after,
  .achievement-toast,
  .achievement-toast-icon {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .xp-bar-fill {
    transition: width 0.01ms !important;
  }
}
