:root {
  --bg: #0d1117;
  --bg-elevated: #161b22;
  --bg-card: #1c2333;
  --border: #2a3142;
  --text: #e6edf3;
  --text-dim: #8b96a5;
  --accent: #39ff88;
  --accent-dim: #1f8f52;
  --danger: #ff5c5c;
  --warn: #ffb454;
  --info: #58a6ff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: 'SF Mono', Menlo, monospace;
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
}

.streak-badge {
  font-size: 13px;
  color: var(--warn);
  font-weight: 600;
  background: rgba(255, 180, 84, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
}

.view {
  flex: 1;
  padding: 16px;
  padding-bottom: 96px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  font-size: 11px;
  font-family: inherit;
}

.tab-icon { font-size: 18px; }

.tab-btn.active { color: var(--accent); }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; color: var(--text); }
p { color: var(--text-dim); line-height: 1.5; }

.card-surface {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-value { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.theme-row:last-child { border-bottom: none; }

.theme-name { font-weight: 600; }
.theme-sub { font-size: 12px; color: var(--text-dim); }

.progress-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  width: 100px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #04140b; }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn:disabled { opacity: 0.4; }

select, textarea, input[type="file"] {
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 15px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
}
.empty-state .big { font-size: 40px; margin-bottom: 12px; }

/* Flashcard */
.flashcard-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.flashcard {
  width: 100%;
  min-height: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 14px;
}
.flashcard-theme {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
}
.flashcard-question { font-size: 19px; font-weight: 600; }
.flashcard-answer {
  font-size: 17px;
  color: var(--accent);
  border-top: 1px dashed var(--border);
  padding-top: 14px;
  white-space: pre-wrap;
}
.session-progress { font-size: 13px; color: var(--text-dim); }

.grade-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}
.grade-btn {
  padding: 12px 4px;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: #04140b;
}
.grade-again { background: var(--danger); }
.grade-hard { background: var(--warn); }
.grade-good { background: var(--accent); }
.grade-easy { background: var(--info); }

/* Quiz */
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.quiz-option {
  text-align: left;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.quiz-option.correct { border-color: var(--accent); background: rgba(57,255,136,0.12); }
.quiz-option.incorrect { border-color: var(--danger); background: rgba(255,92,92,0.12); }
.quiz-option:disabled { opacity: 0.85; }

.quiz-score {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 16px;
  right: 16px;
  max-width: 528px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---- Gamification ---- */
.game-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}
.hero-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.level-chip {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #04140b;
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.1;
  box-shadow: 0 0 18px rgba(57, 255, 136, 0.25);
}
.hero-info { min-width: 0; flex: 1; }
.hero-title { font-weight: 700; font-size: 16px; margin-bottom: 7px; }
.xp-bar {
  height: 8px;
  border-radius: 6px;
  background: var(--border);
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 6px;
  transition: width 0.5s ease;
}
.hero-xp { font-size: 11px; color: var(--text-dim); margin-top: 6px; }

.goal-ring {
  flex-shrink: 0;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--border) 0);
  display: grid;
  place-items: center;
  transition: background 0.5s ease;
}
.goal-ring.done { box-shadow: 0 0 16px rgba(57, 255, 136, 0.35); }
.goal-ring-inner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-card);
  display: grid;
  place-items: center;
  text-align: center;
}
.goal-count { font-size: 16px; font-weight: 800; color: var(--text); }
.goal-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }

.section-count {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}
.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px;
  text-align: center;
}
.badge-emoji { font-size: 24px; line-height: 1.2; }
.badge-label { font-size: 9px; color: var(--text-dim); margin-top: 4px; line-height: 1.2; }
.badge.locked { opacity: 0.45; }
.badge.locked .badge-emoji { filter: grayscale(1); }
.badge.unlocked { border-color: var(--accent-dim); }
.badge.unlocked .badge-label { color: var(--text); }

.session-xp {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 8px;
}

.quiz-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.combo-pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--warn);
  background: rgba(255, 180, 84, 0.14);
  padding: 3px 10px;
  border-radius: 999px;
  animation: pop-in 0.28s ease;
}

/* ---- Feedback juteux ---- */
.xp-pop {
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-bottom));
  transform: translateX(-50%);
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(57, 255, 136, 0.5);
  pointer-events: none;
  z-index: 40;
  animation: xp-float 1s ease-out forwards;
}
@keyframes xp-float {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.8); }
  25% { opacity: 1; transform: translate(-50%, -4px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}
@keyframes pop-in {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.celebrate-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 14, 0.72);
  backdrop-filter: blur(3px);
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.35s ease;
}
.celebrate-overlay.closing { opacity: 0; }
.celebrate-card {
  text-align: center;
  padding: 32px;
  animation: pop-in 0.4s cubic-bezier(0.2, 1.3, 0.5, 1);
}
.celebrate-emoji { font-size: 68px; }
.celebrate-title { font-size: 26px; font-weight: 800; color: var(--text); margin-top: 8px; }
.celebrate-sub { font-size: 15px; color: var(--accent); font-weight: 600; margin-top: 4px; }
.celebrate-hint { font-size: 12px; color: var(--text-dim); margin-top: 18px; }

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0.6; }
}

.badge-toast {
  position: fixed;
  right: 14px;
  left: 14px;
  max-width: 360px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.35s ease;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.badge-toast.out { opacity: 0; transform: translateX(20px); }
.badge-toast-emoji { font-size: 28px; }
.badge-toast-text { font-size: 13px; color: var(--text); line-height: 1.3; }
.badge-toast-text strong { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
@keyframes toast-in {
  0% { opacity: 0; transform: translateX(24px); }
  100% { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .xp-pop, .combo-pill, .celebrate-card, .confetti-piece, .badge-toast { animation: none; }
  .confetti-piece { display: none; }
}

.card-list-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.card-list-q { font-size: 14px; }
.card-list-theme { font-size: 11px; color: var(--accent); text-transform: uppercase; }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 4px 8px;
}
