/* ============================================================================
   Gamification — Streaks, XP, Badges
   ============================================================================ */

/* ── Nav-bar streak + XP display ──────────────────────────────────────────── */

.gam-nav {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-right: 0.4rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  color: var(--text-accent);
  user-select: none;
  overflow: hidden;
  max-width: 100%;
}

.gam-streak {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: default;
  position: relative;
  flex-shrink: 0;
}

.gam-streak__flame {
  font-size: 1rem;
  line-height: 1;
}

.gam-streak__count {
  font-weight: 600;
  font-size: 0.85rem;
}

/* Pulse animation when streak at risk */
@keyframes gam-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.gam-streak--at-risk .gam-streak__flame {
  animation: gam-pulse 1.8s ease-in-out infinite;
}

/* XP & level pill */
.gam-xp {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  min-height: var(--touch-min, 2.75rem);
}

.gam-xp__level {
  font-weight: 700;
  color: var(--primary, var(--xp-purple));
}

.gam-xp__amount {
  color: var(--text-muted);
}

/* Level-up glow */
@keyframes gam-levelup-glow {
  0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.6); }
  60% { box-shadow: 0 0 16px 6px rgba(167, 139, 250, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

.gam-xp--levelup {
  animation: gam-levelup-glow 1.2s ease-out;
}

/* ── Badge grid ───────────────────────────────────────────────────────────── */

.gam-badges {
  margin-top: 2rem;
}

.gam-badges__title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--text-main);
}

.gam-badges__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
  gap: 1rem;
}

.gam-badge {
  background: var(--bg-secondary);
  border: 1px solid var(--border-soft);
  border-radius: 0.75rem;
  padding: 1rem;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.gam-badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.gam-badge:focus-visible {
  outline: 2px solid var(--focus-ring, rgba(255, 138, 91, 0.6));
  outline-offset: 2px;
}

.gam-badge--locked {
  opacity: 0.4;
  filter: grayscale(0.6);
}

.gam-badge__icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.4rem;
}

.gam-badge__name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 0.2rem;
}

.gam-badge__desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

.gam-badge__date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  display: block;
}

/* ── Dashboard integration (portal index + dashboard) ─────────────────── */

.gam-dashboard {
  background: var(--bg-secondary);
  border: 1px solid var(--border-soft);
  border-radius: 1rem;
  padding: clamp(1rem, 3vw, 1.5rem);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.gam-dashboard__row {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  align-items: center;
}

.gam-dashboard__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 0;
}

.gam-dashboard__stat-value {
  font-family: 'Fraunces', serif;
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  font-weight: 700;
  color: var(--text-main);
}

.gam-dashboard__stat-label {
  font-size: clamp(0.7rem, 1.5vw, 0.78rem);
  color: var(--text-muted);
}

/* ── XP progress bar to next level ────────────────────────────────────── */

.gam-xp-progress {
  flex: 1;
  min-width: 120px;
}

.gam-xp-progress__bar {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}

.gam-xp-progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary, var(--xp-purple)), var(--primary, var(--xp-purple)));
  border-radius: 4px;
  transition: width 0.4s ease;
}

.gam-xp-progress__text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: block;
}

/* ── Responsive: tablet (768px) ──────────────────────────────────────── */

@media (max-width: 768px) {
  .gam-dashboard__row {
    gap: 1.25rem;
    justify-content: center;
  }

  .gam-badges__grid {
    grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
  }

  .gam-xp-progress {
    min-width: 100px;
  }
}

/* ── Responsive: large mobile (640px) ────────────────────────────────── */

@media (max-width: 640px) {
  .gam-nav {
    gap: 0.4rem;
    font-size: 0.75rem;
  }

  .gam-badges__grid {
    grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
  }

  .gam-dashboard__row {
    gap: 1rem;
  }
}

/* ── Responsive: small mobile (480px) ────────────────────────────────── */

@media (max-width: 480px) {
  .gam-dashboard__row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .gam-dashboard__stat {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .gam-badges__grid {
    grid-template-columns: repeat(auto-fill, minmax(min(120px, 100%), 1fr));
    gap: 0.75rem;
  }

  .gam-badge {
    padding: 0.75rem;
  }

  .gam-xp {
    font-size: 0.72rem;
    padding: 0.15rem 0.45rem;
  }

  .gam-xp-progress {
    min-width: 0;
    width: 100%;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .gam-streak--at-risk .gam-streak__flame,
  .gam-xp--levelup,
  .gam-badge,
  .gam-xp-progress__fill {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
