/* ==========================================================================
   Académie Linguistique Intensive — Mini-app Telegram
   Design adaptatif : suit le thème clair/sombre de Telegram via ses variables.
   ========================================================================== */

:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #1a1d24);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8b95a5);
  --accent: var(--tg-theme-button-color, #5b8def);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, #1e222b);

  --grad-1: #5b8def;
  --grad-2: #8b5cf6;
  --gold: #f5c451;
  --green: #34d399;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* --- Chargement --- */
.loading { text-align: center; padding-top: 35vh; color: var(--hint); }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 16px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- En-tête --- */
.hero {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 4px 20px;
}
.hero-flag {
  font-size: 44px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
  animation: pop 0.5s ease;
}
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.hello { font-size: 20px; font-weight: 700; }
.course { color: var(--hint); font-size: 14px; }

/* --- Cartes --- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

/* --- Carte niveau --- */
.level-card {
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
  color: #fff;
}
.level-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.level-badge {
  width: 58px; height: 58px; flex: 0 0 58px;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
  backdrop-filter: blur(4px);
}
.level-info .xp { font-size: 26px; font-weight: 800; }
.level-info .xp-next { font-size: 13px; opacity: 0.85; }

.bar {
  height: 12px; border-radius: 99px;
  background: rgba(255,255,255,0.25);
  overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0%;
  background: #fff;
  border-radius: 99px;
  transition: width 1s cubic-bezier(.2,.8,.2,1);
}
.bar-pct { font-size: 12px; opacity: 0.9; margin-top: 6px; text-align: right; }

/* --- Grille de stats --- */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px; text-align: center;
  box-shadow: var(--shadow);
}
.stat-emoji { font-size: 26px; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--hint); }

/* --- Titres de section --- */
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }

/* --- Badges --- */
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.badge {
  text-align: center;
  padding: 10px 4px;
  border-radius: 14px;
  background: var(--bg-secondary);
  transition: transform 0.2s;
}
.badge:active { transform: scale(0.94); }
.badge.locked { opacity: 0.35; filter: grayscale(1); }
.badge-emoji { font-size: 28px; }
.badge.owned .badge-emoji {
  filter: drop-shadow(0 2px 6px rgba(245,196,81,0.5));
}
.badge-name { font-size: 10px; color: var(--hint); margin-top: 4px; line-height: 1.2; }

/* --- Leçons --- */
.lessons { list-style: none; }
.lessons li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-size: 14px;
}
.lessons li:last-child { border-bottom: none; }
.lessons li::before { content: "📖"; font-size: 16px; }

/* --- CTA --- */
.cta {
  width: 100%;
  padding: 16px;
  margin-top: 6px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, opacity 0.15s;
}
.cta:active { transform: scale(0.97); opacity: 0.9; }

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

/* --- Erreur --- */
.error { text-align: center; padding-top: 30vh; color: var(--hint); }
.error-detail { font-size: 12px; margin-top: 8px; opacity: 0.7; }

/* Entrée animée des cartes */
.card, .stat { animation: rise 0.5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* Échelle de niveaux CECR dans la carte niveau */
.ladder { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.ladder .lvl {
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.18); color: #fff;
}
.ladder .lvl.done { background: rgba(255,255,255,0.30); }
.ladder .lvl.current {
  background: #fff; color: #1e293b;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transform: scale(1.08);
}
.ladder .lvl.locked { opacity: 0.5; }
