/* ── RESET & BASE ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #181c27;
  --bg3: #1e2235;
  --card: #1a1e2e;
  --card2: #212640;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #eef0f7;
  --text2: #9ba3c0;
  --text3: #5c6480;
  --accent: #6C63FF;
  --accent2: #8b85ff;
  --green: #2cb67d;
  --red: #e05a6b;
  --amber: #f4a261;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
  --bg: #f0f2fa;
  --bg2: #e8ebf5;
  --bg3: #dce0f0;
  --card: #ffffff;
  --card2: #f5f7ff;
  --border: rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.14);
  --text: #1a1e35;
  --text2: #4a5280;
  --text3: #8090b0;
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-top: var(--safe-top);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.3s, color 0.3s;
}

/* ── LAYOUT ──────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100dvh; }

.screen { display: none; flex-direction: column; flex: 1; }
.screen.active { display: flex; }

/* ── NAV BAR ─────────────────────────────────── */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 10px 4px 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text3); font-family: var(--font);
  font-size: 10px; font-weight: 500; letter-spacing: 0.3px;
  transition: color 0.2s;
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 1.8; transition: transform 0.2s; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: translateY(-2px); }

/* ── HEADER ──────────────────────────────────── */
.header {
  padding: 20px 20px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-title { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.header-sub { font-size: 13px; color: var(--text2); margin-top: 2px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2);
  transition: background 0.2s;
}
.icon-btn:active { background: var(--border2); }

/* ── SCROLL AREA ─────────────────────────────── */
.scroll { overflow-y: auto; flex: 1; padding-bottom: calc(70px + var(--safe-bottom)); }
.scroll::-webkit-scrollbar { display: none; }

/* ── HOME SCREEN ─────────────────────────────── */
.progress-ring-wrap { display: flex; flex-direction: column; align-items: center; padding: 16px 0 24px; }

.progress-ring-svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border2); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.8s cubic-bezier(.4,0,.2,1); }

.ring-label { text-align: center; margin-top: 14px; }
.ring-label .pct { font-size: 36px; font-weight: 800; color: var(--accent); letter-spacing: -1px; }
.ring-label .desc { font-size: 13px; color: var(--text2); margin-top: 2px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.stat-card .label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .sub { font-size: 11px; color: var(--text2); margin-top: 2px; }
.c-green { color: var(--green); }
.c-red { color: var(--red); }
.c-amber { color: var(--amber); }
.c-accent { color: var(--accent); }

.section-title { font-size: 13px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.8px; padding: 20px 16px 10px; }

/* ── THEME CARDS ─────────────────────────────── */
.theme-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.theme-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  display: flex; align-items: center; gap: 14px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-user-select: none; user-select: none;
}
.theme-card:active { transform: scale(0.98); background: var(--card2); }
.theme-icon { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.theme-info { flex: 1; }
.theme-name { font-size: 14px; font-weight: 600; }
.theme-count { font-size: 12px; color: var(--text2); margin-top: 2px; }
.theme-progress-bar { height: 4px; background: var(--border2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.theme-progress-fill { height: 100%; border-radius: 2px; transition: width 0.5s; }
.theme-arrow { color: var(--text3); flex-shrink: 0; }

.cta-btn {
  margin: 16px; padding: 16px;
  background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-size: 16px; font-weight: 700;
  letter-spacing: 0.2px; transition: opacity 0.2s, transform 0.1s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.cta-btn:active { opacity: 0.88; transform: scale(0.98); }
.cta-btn.outline {
  background: transparent; border: 2px solid var(--accent); color: var(--accent);
}

/* ── QUIZ SCREEN ─────────────────────────────── */
.quiz-header { padding: 16px 16px 12px; }
.quiz-progress-bar { height: 5px; background: var(--border2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.quiz-progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s cubic-bezier(.4,0,.2,1); }
.quiz-meta { display: flex; align-items: center; justify-content: space-between; }
.quiz-tag { font-size: 11px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.quiz-num { font-size: 13px; color: var(--text2); font-weight: 500; }

.question-area { padding: 8px 16px 16px; }
.question-text { font-size: 18px; font-weight: 600; line-height: 1.45; letter-spacing: -0.2px; margin-bottom: 24px; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  text-align: left; cursor: pointer; color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  display: flex; align-items: center; gap: 12px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-user-select: none; user-select: none;
}
.option-btn:active:not(.locked) { transform: scale(0.98); }
.option-btn:hover:not(.locked) { border-color: var(--border2); background: var(--card2); }

.option-letter {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--bg3); color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
.option-btn.correct { border-color: var(--green); background: rgba(44,182,125,0.08); }
.option-btn.correct .option-letter { background: var(--green); color: white; }
.option-btn.wrong { border-color: var(--red); background: rgba(224,90,107,0.08); }
.option-btn.wrong .option-letter { background: var(--red); color: white; }
.option-btn.reveal { border-color: var(--green); background: rgba(44,182,125,0.06); }
.option-btn.locked { cursor: default; }

.feedback-card {
  margin-top: 16px; padding: 14px 16px;
  border-radius: var(--radius-sm); border: 1px solid;
  animation: slideUp 0.25s ease;
  display: none;
}
.feedback-card.show { display: block; }
.feedback-card.good { border-color: var(--green); background: rgba(44,182,125,0.06); }
.feedback-card.bad { border-color: var(--red); background: rgba(224,90,107,0.06); }
.feedback-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.feedback-text { font-size: 13px; color: var(--text2); line-height: 1.55; }

.next-btn {
  display: none;
  padding: 16px 0 calc(80px + var(--safe-bottom));
}
.next-btn.show { display: block; }
.next-btn button {
  width: 100%; padding: 15px;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-size: 16px; font-weight: 700;
  transition: opacity 0.2s;
}
.next-btn button:active { opacity: 0.88; }

/* ── END SCREEN ──────────────────────────────── */
.end-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 24px; text-align: center; }
.end-emoji { font-size: 64px; margin-bottom: 16px; }
.end-score { font-size: 52px; font-weight: 800; letter-spacing: -2px; margin-bottom: 4px; }
.end-label { font-size: 16px; color: var(--text2); margin-bottom: 28px; }
.end-badges { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 28px; }
.badge { padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.badge-pass { background: rgba(44,182,125,0.15); color: var(--green); }
.badge-fail { background: rgba(224,90,107,0.15); color: var(--red); }
.end-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.end-btns button { padding: 15px; border-radius: var(--radius-sm); cursor: pointer; font-family: var(--font); font-size: 15px; font-weight: 600; border: none; }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border) !important; }

/* ── RÉVISION SCREEN ─────────────────────────── */
.fiche-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.fiche-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}
.fiche-header {
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: background 0.15s;
}
.fiche-header:active { background: var(--card2); }
.fiche-q { flex: 1; font-size: 14px; font-weight: 500; line-height: 1.4; }
.fiche-chevron { color: var(--text3); transition: transform 0.25s; flex-shrink: 0; }
.fiche-card.open .fiche-chevron { transform: rotate(180deg); }
.fiche-answer {
  display: none; padding: 0 16px 14px 58px;
  font-size: 13px; color: var(--text2); line-height: 1.6;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.fiche-card.open .fiche-answer { display: block; }
.fiche-correct { font-weight: 700; color: var(--green); margin-bottom: 6px; font-size: 14px; }

/* ── SETTINGS SCREEN ─────────────────────────── */
.settings-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.setting-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.setting-info { flex: 1; }
.setting-name { font-size: 14px; font-weight: 500; }
.setting-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* Toggle switch */
.toggle { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border2); border-radius: 14px;
  transition: background 0.3s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  height: 22px; width: 22px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%;
  transition: transform 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

.setting-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }

.install-banner {
  margin: 0 16px 16px; padding: 14px 16px;
  background: linear-gradient(135deg, #6C63FF22, #8b85ff11);
  border: 1px solid #6C63FF44; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 12px;
}
.install-banner .info { flex: 1; font-size: 13px; color: var(--text2); }
.install-banner .info strong { color: var(--text); display: block; margin-bottom: 3px; }
.install-banner button { padding: 8px 14px; background: var(--accent); color: white; border: none; border-radius: 8px; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; }

/* ── QUIZ SELECTOR ───────────────────────────── */
.quiz-mode-selector { padding: 0 16px 16px; }
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.mode-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  cursor: pointer; transition: border-color 0.2s, background 0.15s;
  text-align: center;
}
.mode-card.selected { border-color: var(--accent); background: rgba(108,99,255,0.07); }
.mode-card-icon { font-size: 26px; margin-bottom: 8px; }
.mode-card-title { font-size: 14px; font-weight: 600; }
.mode-card-desc { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* ── ANIMATIONS ──────────────────────────────── */
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }
.pop { animation: pop 0.3s ease; }

/* ── TOAST ───────────────────────────────────── */
.toast {
  position: fixed; top: calc(20px + var(--safe-top));
  left: 50%; transform: translateX(-50%) translateY(-80px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 20px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 999; white-space: nowrap;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}
.toast.show { transform: translateX(-50%) translateY(0); }
