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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #232636;
  --border: #2e3248;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg2: #ffffff;
  --bg3: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text2: #64748b;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ===== NAVBAR ===== */
.navbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.1rem;
}

.nav-icon { font-size: 1.4rem; }

.btn-theme {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
  font-size: 1rem; transition: all 0.2s;
}
.btn-theme:hover { background: var(--border); }

/* ===== CONTAINER ===== */
.container { max-width: 1280px; margin: 0 auto; padding: 32px 20px; }

/* ===== HERO ===== */
.hero {
  text-align: center;
  margin-bottom: 40px;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent2), #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.hero-sub { color: var(--text2); font-size: 1.1rem; margin-bottom: 24px; }

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex; justify-content: center; gap: 40px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 32px;
  max-width: 500px; margin: 0 auto;
}
.stat-item { text-align: center; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 800; color: var(--accent2); }
.stat-label { font-size: 0.75rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; }

/* ===== SEARCH ===== */
.search-bar {
  position: relative; max-width: 600px; margin: 0 auto 36px;
}
.search-bar input {
  width: 100%; padding: 14px 20px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text2); }

.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); z-index: 50;
}
.search-results.hidden { display: none; }
.search-result-item {
  padding: 12px 20px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg3); }
.search-result-item .res-chap { font-size: 0.75rem; color: var(--text2); margin-bottom: 2px; }
.search-result-item .res-title { font-weight: 600; }

/* ===== GRID ===== */
.chapitres-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* ===== CHAPTER CARD ===== */
.chapitre-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}
.chapitre-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.chapitre-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px;
}
.chap-num {
  background: var(--bg3); color: var(--text2);
  padding: 4px 10px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600;
  border: 1px solid var(--border);
}

/* Progress ring */
.progress-ring { position: relative; width: 44px; height: 44px; }
.progress-ring svg { width: 44px; height: 44px; transform: rotate(-90deg); }
.progress-ring circle {
  fill: none; stroke-width: 3;
  stroke-linecap: round;
}
.progress-ring .bg { stroke: var(--border); }
.progress-ring .fill {
  stroke: var(--accent);
  stroke-dasharray: 94.2 94.2;
  stroke-dashoffset: 94.2;
  transition: stroke-dashoffset 0.6s ease;
}
.progress-pct {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 0.6rem; font-weight: 700; color: var(--text2);
}

.card-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }
.card-desc { color: var(--text2); font-size: 0.875rem; margin-bottom: 16px; line-height: 1.5; }

.card-meta {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.meta-item {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.7rem; color: var(--text2);
}

.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== BUTTONS ===== */
.btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.15s;
  flex: 1; min-width: 70px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent2); }
.btn-outline { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg3); color: var(--text); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { opacity: 0.9; }
.btn-red { background: var(--red); color: white; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 860px;
  max-height: 90vh; overflow-y: auto;
  position: relative;
  transform: translateY(20px);
  transition: transform 0.25s;
}
.modal-overlay.active .modal { transform: translateY(0); }

.modal-close {
  position: sticky; top: 16px; float: right; margin: 16px 16px 0 0;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  width: 36px; height: 36px; font-size: 1.2rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  z-index: 10; transition: background 0.15s;
}
.modal-close:hover { background: var(--border); }
.modal-content { padding: 24px; clear: both; }

/* ===== COURS VIEW ===== */
.cours-header { margin-bottom: 32px; }
.cours-header h2 {
  font-size: 1.8rem; font-weight: 800; margin-bottom: 8px;
}
.cours-chapnum { color: var(--text2); font-size: 0.9rem; margin-bottom: 4px; }

.notion-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px; margin-bottom: 16px;
  border-left: 4px solid var(--accent);
  transition: border-color 0.2s;
}
.notion-type-theoreme { border-left-color: #f59e0b; }
.notion-type-formule { border-left-color: #06b6d4; }
.notion-type-methode { border-left-color: var(--green); }
.notion-type-exemple { border-left-color: #a78bfa; }

.notion-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 10px; }
.notion-card p { color: var(--text2); font-size: 0.9rem; line-height: 1.6; }

.formula-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px; margin-top: 12px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem; color: #60a5fa;
  white-space: pre-wrap;
}

.notion-extra {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
}
.notion-extra .extra-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.notion-exemple {
  background: rgba(99,102,241,0.10);
  border-left: 3px solid #818cf8;
}
.notion-exemple .extra-label { color: #818cf8; }
.notion-piege {
  background: rgba(245,158,11,0.10);
  border-left: 3px solid var(--yellow);
}
.notion-piege .extra-label { color: var(--yellow); }

.notion-badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 600;
  margin-bottom: 8px; text-transform: uppercase;
}
.badge-theoreme { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-formule { background: rgba(6,182,212,0.15); color: #06b6d4; }
.badge-methode { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-exemple { background: rgba(167,139,250,0.15); color: #a78bfa; }
.badge-definition { background: rgba(99,102,241,0.15); color: var(--accent2); }

.cours-nav { display: flex; gap: 12px; margin-top: 28px; justify-content: center; }

/* ===== QUIZ VIEW ===== */
.quiz-header { margin-bottom: 24px; }
.quiz-header h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }

.quiz-progress-bar {
  background: var(--bg3); border-radius: 100px; height: 8px;
  margin: 16px 0; overflow: hidden;
}
.quiz-progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 100px; transition: width 0.4s ease;
}

.quiz-counter { color: var(--text2); font-size: 0.9rem; }

.question-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 20px;
}
.question-text { font-size: 1.05rem; font-weight: 600; line-height: 1.5; margin-bottom: 20px; }

.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; text-align: left;
  font-size: 0.925rem; transition: all 0.15s;
  width: 100%;
}
.option-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--bg3); }
.option-btn .opt-letter {
  min-width: 28px; height: 28px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; color: var(--text2);
}
.option-btn.correct { border-color: var(--green); background: rgba(34,197,94,0.1); }
.option-btn.correct .opt-letter { background: var(--green); color: white; border-color: var(--green); }
.option-btn.wrong { border-color: var(--red); background: rgba(239,68,68,0.1); }
.option-btn.wrong .opt-letter { background: var(--red); color: white; border-color: var(--red); }
.option-btn:disabled { cursor: default; }

.explanation-box {
  background: var(--bg); border-left: 4px solid var(--green);
  border-radius: var(--radius-sm); padding: 14px 16px;
  margin-top: 16px; font-size: 0.875rem; color: var(--text2);
  line-height: 1.5;
}
.explanation-box.hidden { display: none; }
.explanation-box strong { color: var(--text); }

.quiz-nav { display: flex; gap: 12px; justify-content: space-between; align-items: center; }

/* ===== RESULT VIEW ===== */
.result-view { text-align: center; padding: 20px 0; }
.result-score {
  font-size: 5rem; font-weight: 900;
  line-height: 1; margin-bottom: 8px;
}
.result-score.great { color: var(--green); }
.result-score.ok { color: var(--yellow); }
.result-score.bad { color: var(--red); }
.result-label { font-size: 1.2rem; color: var(--text2); margin-bottom: 32px; }
.result-details {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 24px;
  text-align: left;
}
.result-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.result-item:last-child { border-bottom: none; }
.result-icon { font-size: 1.1rem; flex-shrink: 0; }
.result-q { color: var(--text2); flex: 1; line-height: 1.4; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ===== FLASHCARDS VIEW ===== */
.flashcards-header { margin-bottom: 24px; }
.flashcards-header h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }
.fc-counter { color: var(--text2); font-size: 0.9rem; }

.flashcard-container {
  perspective: 1000px;
  height: 260px; cursor: pointer; margin-bottom: 24px;
  user-select: none;
}
.flashcard {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px; text-align: center;
}
.flashcard-back { transform: rotateY(180deg); }
.flashcard-face .fc-side {
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text2); margin-bottom: 16px;
}
.flashcard-face .fc-content {
  font-size: 1.1rem; font-weight: 600; line-height: 1.6;
  white-space: pre-line;
}
.flashcard-back .fc-content { color: var(--accent2); }
.flashcard-hint { color: var(--text2); font-size: 0.8rem; text-align: center; margin-bottom: 20px; }

.fc-nav { display: flex; gap: 12px; justify-content: center; }
.fc-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.fc-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); transition: all 0.2s;
}
.fc-dot.active { background: var(--accent); transform: scale(1.3); }
.fc-dot.seen { background: var(--text2); }

/* ===== MODE TABS ===== */
.mode-tabs {
  display: flex; gap: 4px; margin-bottom: 24px;
  background: var(--bg3); border-radius: var(--radius-sm);
  padding: 4px;
}
.mode-tab {
  flex: 1; padding: 8px;
  background: transparent; border: none;
  color: var(--text2); border-radius: 6px;
  cursor: pointer; font-size: 0.875rem; font-weight: 600;
  transition: all 0.15s;
}
.mode-tab.active { background: var(--accent); color: white; }
.mode-tab:hover:not(.active) { background: var(--border); color: var(--text); }

/* ===== HIDDEN UTILITY ===== */
.hidden { display: none !important; }

/* ===== BACK BUTTON ===== */
.btn-back {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 4px 10px; cursor: pointer;
  font-size: 1.1rem; transition: all 0.2s;
  margin-right: 4px;
}
.btn-back:hover { background: var(--border); }

/* ===== SUBJECT SELECTION ===== */
.hero-landing { margin-bottom: 48px; }

.subject-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 28px;
  max-width: 760px;
  margin: 0 auto;
}

.subject-card {
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}
.subject-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.subject-physique::before { background: #6366f1; }
.subject-maths::before    { background: #10b981; }

.subject-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.subject-physique:hover { border-color: #6366f1; }
.subject-maths:hover    { border-color: #10b981; }

.subject-card-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  line-height: 1;
}
.subject-card h2 {
  font-size: 1.8rem; font-weight: 800; margin-bottom: 6px;
}
.subject-desc {
  color: var(--text2); font-size: 0.9rem; margin-bottom: 20px;
}
.subject-progress-bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 100px;
  margin-bottom: 10px;
  overflow: hidden;
}
.subject-progress-fill {
  height: 100%;
  border-radius: 100px;
  width: 0%;
  transition: width 0.8s ease;
}
.subject-physique .subject-progress-fill { background: #6366f1; }
.subject-maths    .subject-progress-fill { background: #10b981; }
.subject-stat {
  font-size: 0.78rem; color: var(--text2); margin-bottom: 24px;
  min-height: 1.2em;
}
.btn-subject {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s;
  width: 100%;
}
.subject-physique:hover .btn-subject { border-color: #6366f1; color: #818cf8; background: rgba(99,102,241,0.08); }
.subject-maths:hover    .btn-subject { border-color: #10b981; color: #34d399; background: rgba(16,185,129,0.08); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .chapitres-grid { grid-template-columns: 1fr; }
  .stats-bar { gap: 20px; padding: 16px; }
  .modal { max-height: 95vh; }
  .card-actions { flex-direction: column; }
  .fc-nav { flex-direction: column; align-items: stretch; }
}
