/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --bg2:         #1a1d27;
  --bg3:         #22263a;
  --border:      #2e3350;
  --text:        #e8eaf0;
  --text-muted:  #8890aa;
  --primary:     #5b8dee;
  --primary-dk:  #3a6fd8;
  --success:     #34c77b;
  --warning:     #f0a832;
  --danger:      #e05252;
  --partial:     #f0a832;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 4px 20px rgba(0,0,0,.4);
  --font:        'Segoe UI', system-ui, sans-serif;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; overflow-x: hidden; }
body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1.5rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  white-space: nowrap;
}
.navbar-center { flex: 1; }
.xp-bar-wrap { display: flex; align-items: center; gap: .5rem; }
.level-badge {
  font-size: .75rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  padding: .15rem .5rem;
  border-radius: 99px;
  white-space: nowrap;
}
.xp-bar-outer {
  flex: 1;
  height: 8px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
}
.xp-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a78bfa);
  border-radius: 99px;
  transition: width .6s ease;
}
.xp-label { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }
.navbar-right { display: flex; align-items: center; gap: 1rem; }
.streak-badge { font-weight: 700; font-size: .9rem; }
.nav-link { font-size: .85rem; color: var(--text-muted); }
.nav-link:hover { color: var(--text); }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

/* ── Section titles ──────────────────────────────────────────────────────── */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 1.8rem 0 .8rem;
  color: var(--text);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: .6rem 1.4rem;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-primary:hover { background: var(--primary-dk); }
.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  font-size: .9rem;
  cursor: pointer;
  transition: background .2s;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .9rem;
}

/* ── Helpers ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.back-link { color: var(--text-muted); font-size: .88rem; }
.back-link:hover { color: var(--text); }

/* ══════════════════════════════════════════════════════════════════════════ */
/* DASHBOARD                                                                  */
/* ══════════════════════════════════════════════════════════════════════════ */
.hero-card {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: linear-gradient(135deg, #1e2240, #2a1f4a);
  border: 1px solid #3a3a6a;
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.hero-level { display: flex; align-items: center; gap: 1rem; }
.level-circle {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 900; color: #fff;
  box-shadow: 0 0 20px rgba(91,141,238,.4);
  flex-shrink: 0;
}
.level-name { font-size: 1.2rem; font-weight: 700; }
.level-sub  { font-size: .8rem; color: var(--text-muted); }
.hero-xp { flex: 1; min-width: 200px; }
.hero-xp-numbers { display: flex; justify-content: space-between; margin-bottom: .4rem; font-size: .9rem; }
.xp-current { font-weight: 700; color: #a78bfa; }
.xp-next    { color: var(--text-muted); font-size: .82rem; }
.hero-bar-outer {
  height: 12px;
  background: rgba(255,255,255,.1);
  border-radius: 99px;
  overflow: hidden;
}
.hero-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a78bfa);
  border-radius: 99px;
  transition: width .8s ease;
}
.hero-streak { text-align: center; }
.streak-fire { font-size: 1.8rem; }
.streak-count { font-size: 2rem; font-weight: 900; color: #f0a832; line-height: 1; }
.streak-label { font-size: .75rem; color: var(--text-muted); }
.streak-best  { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; }

/* Chapters grid */
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .9rem;
}
.chapter-card {
  display: flex;
  align-items: center;
  gap: .9rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  color: var(--text);
  transition: border-color .2s, transform .15s;
}
.chapter-card:hover { border-color: var(--primary); transform: translateY(-2px); text-decoration: none; }
.chapter-done    { border-color: var(--success) !important; }
.chapter-started { border-color: var(--primary); }
.chapter-number {
  width: 36px; height: 36px;
  background: var(--bg3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem;
  flex-shrink: 0;
}
.chapter-body { flex: 1; min-width: 0; }
.chapter-title { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-progress-bar {
  height: 4px; background: var(--bg3); border-radius: 99px;
  margin: .4rem 0;
  overflow: hidden;
}
.chapter-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .5s ease;
}
.chapter-done .chapter-progress-fill { background: var(--success); }
.chapter-stats { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); }
.badge-done    { color: var(--success); font-weight: 600; }
.badge-started { color: var(--primary); }
.badge-new     { color: var(--text-muted); }

/* Badges grid (dashboard) */
.badges-grid {
  display: flex; flex-wrap: wrap; gap: .6rem;
}
.badge-item {
  display: flex; align-items: center; gap: .4rem;
  padding: .4rem .8rem;
  border-radius: 99px;
  font-size: .82rem;
  border: 1px solid var(--border);
}
.badge-unlocked { background: var(--bg3); border-color: var(--primary); }
.badge-locked   { background: var(--bg2); opacity: .5; }
.badge-icon     { font-size: 1rem; }
.badge-name     { font-size: .78rem; }

/* Recent attempts */
.recent-list { display: flex; flex-direction: column; gap: .5rem; }
.recent-item {
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .88rem;
}
.recent-item:hover { border-color: var(--primary); text-decoration: none; }
.recent-ex     { font-weight: 600; min-width: 80px; }
.recent-status { flex: 1; }
.recent-xp     { color: #a78bfa; font-weight: 700; }
.recent-correct   { border-left: 3px solid var(--success); }
.recent-partial   { border-left: 3px solid var(--warning); }
.recent-incorrect { border-left: 3px solid var(--danger); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 380px; width: 90%;
  text-align: center;
}
.modal-box h2 { margin-bottom: .5rem; font-size: 1.4rem; }
.modal-box p  { color: var(--text-muted); margin-bottom: 1rem; }
.modal-box input {
  width: 100%; padding: .7rem 1rem;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; margin-bottom: 1rem;
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* CHAPTER PAGE                                                               */
/* ══════════════════════════════════════════════════════════════════════════ */
.chapter-page { }
.chapter-header { margin-bottom: 1rem; }
.chapter-header h1 { font-size: 1.3rem; margin-top: .4rem; }

.chapter-layout { display: flex; gap: 1.5rem; align-items: flex-start; }

.course-panel {
  width: 340px; flex-shrink: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky; top: 70px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
.course-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 1rem;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .9rem;
  position: sticky; top: 0;
}
.course-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); font-size: .75rem;
  padding: .2rem .6rem; border-radius: 6px; cursor: pointer;
}
.course-content { padding: 1rem; }
.course-heading { font-size: .95rem; font-weight: 700; margin: 1rem 0 .4rem; color: var(--primary); }
.course-list { padding-left: 1.2rem; margin: .4rem 0; }
.course-list li { margin-bottom: .3rem; font-size: .88rem; }
.course-para { font-size: .88rem; margin-bottom: .6rem; line-height: 1.7; }

.exercises-section { flex: 1; min-width: 0; }
.exercises-section h2 { font-size: 1.1rem; margin-bottom: .8rem; }
.exercises-list { display: flex; flex-direction: column; gap: .7rem; }

.exercise-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem;
  color: var(--text); transition: border-color .2s, transform .15s;
}
.exercise-card:hover { border-color: var(--primary); transform: translateX(3px); text-decoration: none; }
.exercise-status-correct   { border-left: 4px solid var(--success); }
.exercise-status-partial   { border-left: 4px solid var(--warning); }
.exercise-status-incorrect { border-left: 4px solid var(--danger); }
.exercise-status-not_started { border-left: 4px solid var(--border); }
.ex-number { font-weight: 700; font-size: .85rem; color: var(--primary); min-width: 36px; }
.ex-body { flex: 1; min-width: 0; }
.ex-title { font-weight: 600; font-size: .92rem; }
.ex-preview { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-status-badge { font-size: 1.1rem; }
.status-correct   { color: var(--success); }
.status-partial   { color: var(--warning); }
.status-incorrect { color: var(--danger); }
.status-new       { color: var(--text-muted); }

@media (max-width: 760px) {
  .chapter-layout { flex-direction: column; }
  .course-panel { width: 100%; position: static; max-height: 300px; }
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* EXERCISE PAGE                                                              */
/* ══════════════════════════════════════════════════════════════════════════ */
.exercise-page { }
.exercise-header {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.exercise-meta { flex: 1; display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.exercise-id-badge {
  background: var(--primary);
  color: #fff; font-weight: 700; font-size: .8rem;
  padding: .25rem .7rem; border-radius: 99px;
}
.exercise-title-text { font-weight: 600; font-size: 1rem; }

.course-float-btn {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: .45rem 1rem;
  border-radius: var(--radius); cursor: pointer;
  font-size: .88rem; transition: border-color .2s;
  white-space: nowrap;
}
.course-float-btn:hover { border-color: var(--primary); }

.exercise-layout { display: flex; gap: 1.5rem; align-items: flex-start; }
.exercise-main { flex: 1; min-width: 0; }

.exercise-statement h2 { font-size: 1rem; font-weight: 700; margin-bottom: .8rem; }
.statement-content p  { margin-bottom: .6rem; line-height: 1.8; }
.statement-content ul { padding-left: 1.2rem; margin-bottom: .6rem; }
.statement-content li { margin-bottom: .3rem; }
.statement-content h3 { font-size: .95rem; font-weight: 700; margin: .8rem 0 .4rem; }

.answer-section h2 { font-size: 1rem; font-weight: 700; margin-bottom: .8rem; }
#answer-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: .8rem 1rem;
  resize: vertical;
  transition: border-color .2s;
}
#answer-input:focus { outline: none; border-color: var(--primary); }
.answer-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .8rem;
}
.timer-display { font-size: .82rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.btn-submit { font-size: 1rem; padding: .7rem 1.8rem; }

/* Solution */
.solution-section h2 { font-size: 1rem; font-weight: 700; margin-bottom: .8rem; }
.solution-content { background: rgba(52,199,123,.05); border-radius: var(--radius); padding: 1rem; border: 1px solid rgba(52,199,123,.2); }
.solution-content p  { margin-bottom: .6rem; line-height: 1.8; }
.solution-content ul { padding-left: 1.2rem; margin-bottom: .6rem; }
.solution-content li { margin-bottom: .3rem; }

/* Self eval */
.self-eval h2 { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; }
.self-eval p  { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.eval-buttons { display: flex; gap: .8rem; flex-wrap: wrap; }
.btn-eval {
  flex: 1; min-width: 120px;
  padding: .75rem 1rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: .95rem; font-weight: 700; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.btn-eval:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.btn-correct  { background: rgba(52,199,123,.15); color: var(--success); border-color: var(--success); }
.btn-partial  { background: rgba(240,168,50,.15); color: var(--warning); border-color: var(--warning); }
.btn-incorrect{ background: rgba(224,82,82,.15);  color: var(--danger);  border-color: var(--danger); }

/* Feedback */
.feedback-section { }
.feedback-banner {
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  font-size: 1rem; font-weight: 600;
  margin-bottom: 1rem;
}
.feedback-correct  { background: rgba(52,199,123,.15); border: 1px solid var(--success); color: var(--success); }
.feedback-partial  { background: rgba(240,168,50,.15);  border: 1px solid var(--warning); color: var(--warning); }
.feedback-incorrect{ background: rgba(224,82,82,.12);   border: 1px solid var(--danger);  color: var(--danger); }

/* Hint */
.hint-section { margin-bottom: 1rem; }
.btn-hint {
  background: linear-gradient(135deg, #2d1f6e, #1f3a6e);
  border: 1px solid #4a5aaa;
  color: #c4b5fd;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer; font-size: .9rem; font-weight: 600;
  transition: border-color .2s;
}
.btn-hint:hover { border-color: #a78bfa; }
.hint-content { margin-top: .8rem; }
.hint-loading { display: flex; align-items: center; gap: .6rem; color: var(--text-muted); font-size: .9rem; padding: .6rem 0; }
.hint-text {
  background: rgba(91,141,238,.08);
  border: 1px solid rgba(91,141,238,.25);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  line-height: 1.8;
  font-size: .92rem;
  margin-bottom: .8rem;
}
.btn-hint-again {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); padding: .4rem .9rem;
  border-radius: var(--radius); cursor: pointer; font-size: .82rem;
}
.btn-hint-again:hover { border-color: var(--primary); color: var(--text); }

/* Nav buttons */
.nav-buttons { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .5rem; }
.nav-buttons a { text-decoration: none; }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Course side panel */
.course-side-panel {
  width: 320px; flex-shrink: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky; top: 70px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
.course-close-btn {
  background: none; border: none;
  color: var(--text-muted); font-size: 1rem;
  cursor: pointer; padding: .2rem .4rem;
}
.course-side-content { padding: 1rem; }
.course-side-content p  { font-size: .87rem; margin-bottom: .6rem; line-height: 1.7; }
.course-side-content ul { padding-left: 1.2rem; margin-bottom: .6rem; }
.course-side-content li { font-size: .87rem; margin-bottom: .3rem; }
.course-side-content h3 { font-size: .9rem; font-weight: 700; margin: 1rem 0 .4rem; color: var(--primary); }

@media (max-width: 820px) {
  .course-side-panel {
    position: fixed; right: 0; top: 56px; bottom: 0;
    width: min(340px, 90vw);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    z-index: 150;
    box-shadow: var(--shadow);
  }
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* STATS PAGE                                                                 */
/* ══════════════════════════════════════════════════════════════════════════ */
.stats-header { margin-bottom: 1.5rem; }
.stats-header h1 { font-size: 1.3rem; margin-top: .4rem; }

.stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .8rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat-value { font-size: 1.6rem; font-weight: 900; color: var(--primary); }
.stat-value small { font-size: .7rem; font-weight: 400; color: var(--text-muted); display: block; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }

/* Chapter bars */
.chapter-bars { display: flex; flex-direction: column; gap: .55rem; margin-bottom: .8rem; }
.chap-bar-row { display: flex; align-items: center; gap: .8rem; }
.chap-bar-label { width: 220px; flex-shrink: 0; font-size: .82rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chap-bar-label:hover { color: var(--text); }
.chap-bar-outer {
  flex: 1; height: 14px;
  background: var(--bg3);
  border-radius: 99px; overflow: hidden;
  display: flex;
}
.chap-bar-correct   { background: var(--success); height: 100%; transition: width .6s; }
.chap-bar-partial   { background: var(--warning);  height: 100%; transition: width .6s; }
.chap-bar-incorrect { background: var(--danger);   height: 100%; transition: width .6s; }
.chap-bar-count { font-size: .78rem; color: var(--text-muted); min-width: 36px; text-align: right; }
.bar-legend { display: flex; gap: 1rem; font-size: .75rem; margin-top: .3rem; }
.legend-correct   { color: var(--success); }
.legend-partial   { color: var(--warning); }
.legend-incorrect { color: var(--danger); }
.legend-none      { color: var(--text-muted); }

/* Badges full grid */
.badges-full-grid { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1.5rem; }
.badge-full-item {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.badge-full-item.badge-unlocked { border-color: var(--primary); }
.badge-full-item.badge-locked   { opacity: .5; }
.badge-icon-big { font-size: 1.5rem; }
.badge-info { }
.badge-info .badge-name { font-weight: 600; font-size: .9rem; }
.badge-info .badge-desc { font-size: .78rem; color: var(--text-muted); }

/* Activity */
.activity-list { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.5rem; }
.activity-row {
  display: flex; gap: 1.5rem; align-items: center;
  padding: .5rem .8rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .85rem;
}
.activity-date { color: var(--text-muted); min-width: 90px; }
.activity-exercises { flex: 1; }
.activity-xp { color: #a78bfa; font-weight: 700; }

.danger-zone { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }

/* ══════════════════════════════════════════════════════════════════════════ */
/* TOASTS                                                                     */
/* ══════════════════════════════════════════════════════════════════════════ */
#toast-zone {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; align-items: flex-end; gap: .6rem;
  z-index: 999;
}
.toast {
  padding: .7rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .3s ease;
}
.toast-xp {
  background: linear-gradient(135deg, #2d1f6e, #1f3a6e);
  border: 1px solid #a78bfa;
  color: #c4b5fd; font-size: 1.1rem;
}
.toast-badge {
  background: var(--bg2); border: 1px solid var(--primary);
  color: var(--text); display: flex; align-items: center; gap: .8rem;
  max-width: 260px;
}
.toast-icon { font-size: 1.4rem; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── AI Feedback block ───────────────────────────────────────────────────── */
.ai-feedback-section {
  transition: opacity .3s;
}
.ai-feedback-loading {
  display: flex; align-items: center; gap: .8rem;
  color: var(--text-muted); font-size: .95rem;
}
.ai-feedback-correct {
  display: flex; align-items: flex-start; gap: 1rem;
  background: rgba(52,199,123,.08);
  border: 1px solid var(--success) !important;
}
.ai-feedback-incorrect {
  background: rgba(224,82,82,.06);
  border: 1px solid var(--danger) !important;
}
.ai-feedback-warning {
  background: rgba(240,168,50,.08);
  border: 1px solid var(--warning) !important;
  color: var(--warning);
}
.ai-feedback-error {
  background: rgba(224,82,82,.08);
  border: 1px solid var(--danger) !important;
  color: var(--danger);
}
.feedback-icon { font-size: 2rem; line-height: 1; }
.feedback-body { flex: 1; }
.feedback-label { font-weight: 700; margin-bottom: .4rem; }
.feedback-hint {
  line-height: 1.7; font-size: .95rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}
.xp-gain {
  display: inline-block;
  margin-top: .5rem;
  background: linear-gradient(135deg, #2d1f6e, #1f3a6e);
  border: 1px solid #a78bfa;
  color: #c4b5fd;
  font-weight: 700;
  padding: .3rem .9rem;
  border-radius: 99px;
  font-size: .9rem;
}
.feedback-actions { display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; margin-top: .8rem; }
.btn-retry {
  background: var(--bg3);
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  transition: background .2s;
}
.btn-retry:hover { background: rgba(91,141,238,.15); }
.answer-readonly {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  font-size: .95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text-muted);
  font-style: italic;
}
.btn-show-answer {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .88rem;
  transition: border-color .2s, color .2s;
}
.btn-show-answer:hover { border-color: var(--warning); color: var(--warning); }

.confirm-warning {
  background: rgba(240,168,50,.1);
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  padding: .7rem 1rem;
  font-size: .88rem;
  color: var(--warning);
  margin-bottom: .7rem;
}
.confirm-buttons { display: flex; gap: .7rem; flex-wrap: wrap; }
.btn-confirm-yes {
  background: rgba(224,82,82,.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  transition: background .2s;
}
.btn-confirm-yes:hover { background: rgba(224,82,82,.25); }
.btn-confirm-no {
  background: var(--bg3);
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  transition: background .2s;
}
.btn-confirm-no:hover { background: rgba(91,141,238,.15); }
.ai-feedback-skipped {
  background: rgba(136,144,170,.08);
  border: 1px solid var(--border) !important;
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* MATH (KaTeX overrides for dark mode)                                       */
/* ══════════════════════════════════════════════════════════════════════════ */
.katex { font-size: 1.05em; }
.katex-display { margin: .8rem 0; overflow-x: auto; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* AUTH PAGES (login / setup)                                                  */
/* ══════════════════════════════════════════════════════════════════════════ */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-container { width: 100%; max-width: 400px; padding: 1rem; }
.auth-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { font-size: 2.5rem; margin-bottom: .8rem; }
.auth-title { font-size: 1.4rem; font-weight: 700; margin-bottom: .3rem; }
.auth-subtitle { font-size: .88rem; color: var(--text-muted); margin-bottom: 1.5rem; }
.auth-box .form-group { text-align: left; margin-bottom: 1rem; }
.auth-box .form-group label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .3rem; }
.auth-box .form-group input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .6rem .9rem;
  font-size: .95rem;
}
.auth-box .form-group input:focus { outline: none; border-color: var(--primary); }
.btn-full { width: 100%; padding: .75rem; margin-top: .5rem; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* FLASH MESSAGES                                                              */
/* ══════════════════════════════════════════════════════════════════════════ */
.flash {
  padding: .7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: .8rem;
  font-size: .9rem;
}
.flash-success { background: rgba(52,199,123,.12); border: 1px solid var(--success); color: var(--success); }
.flash-error   { background: rgba(224,82,82,.12);  border: 1px solid var(--danger);  color: var(--danger); }
.flash-info    { background: rgba(91,141,238,.12); border: 1px solid var(--primary); color: var(--primary); }

/* ══════════════════════════════════════════════════════════════════════════ */
/* NAVBAR — user / logout / admin link                                         */
/* ══════════════════════════════════════════════════════════════════════════ */
.nav-link-admin { color: var(--warning) !important; }
.nav-link-admin:hover { color: #fff !important; }
.nav-user { display: flex; align-items: center; gap: .5rem; }
.nav-username { font-size: .85rem; color: var(--text-muted); }
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: .2rem .55rem;
  font-size: .85rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); text-decoration: none; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* ADMIN PAGE                                                                  */
/* ══════════════════════════════════════════════════════════════════════════ */
.admin-page { max-width: 1200px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.admin-header h1 { font-size: 1.3rem; }
.admin-create-card { margin-bottom: 2rem; }
.admin-create-card h2 { font-size: 1rem; margin-bottom: 1rem; }

.form-row {
  display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end;
}
.form-row .form-group { display: flex; flex-direction: column; gap: .3rem; flex: 1; min-width: 150px; }
.form-row .form-group label { font-size: .82rem; color: var(--text-muted); }
.form-row .form-group input,
.form-row .form-group select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .5rem .8rem;
  font-size: .9rem;
}
.form-row .form-group input:focus,
.form-row .form-group select:focus { outline: none; border-color: var(--primary); }

.users-table-wrap { overflow-x: auto; }
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.users-table th {
  text-align: left;
  padding: .6rem .8rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.users-table td {
  padding: .65rem .8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: rgba(255,255,255,.02); }
.row-admin td { background: rgba(240,168,50,.04); }

.role-badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
}
.role-admin   { background: rgba(240,168,50,.15); color: var(--warning); border: 1px solid var(--warning); }
.role-student { background: rgba(91,141,238,.12); color: var(--primary); border: 1px solid var(--primary); }

.actions-cell { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form  { display: flex; gap: .4rem; align-items: center; }
.input-inline {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .35rem .6rem;
  font-size: .82rem;
  width: 130px;
}
.input-inline:focus { outline: none; border-color: var(--primary); }
.btn-sm {
  padding: .35rem .75rem;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}
.btn-sm.btn-secondary {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm.btn-secondary:hover { background: var(--border); }
.btn-sm.btn-danger { background: var(--danger); color: #fff; }
.btn-sm.btn-danger:hover { background: #c43f3f; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* RESPONSIVE — MOBILE (≤ 600px, iPhone)                                      */
/* ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  /* ── Navbar ── */
  .navbar { padding: .5rem .8rem; gap: .5rem; flex-wrap: wrap; }
  .navbar-center { order: 3; width: 100%; }
  .xp-bar-wrap { gap: .35rem; }
  .xp-label { display: none; }          /* masquer "X XP" : redondant avec la barre */
  .navbar-right { gap: .6rem; }
  .nav-username { display: none; }      /* prénom masqué : la place est trop limitée */
  .streak-badge { font-size: .8rem; }
  .nav-link { font-size: .8rem; }

  /* ── Main content ── */
  .main-content { padding: 1rem .75rem 3rem; }

  /* ── Hero dashboard ── */
  .hero-card { padding: 1rem; gap: 1rem; }
  .hero-xp { min-width: 0; width: 100%; }   /* casse le min-width: 200px */
  .hero-xp-numbers { flex-direction: column; gap: .1rem; }
  .level-circle { width: 52px; height: 52px; font-size: 1.3rem; }
  .level-name { font-size: 1rem; }

  /* ── Chapters grid ── */
  .chapters-grid { grid-template-columns: 1fr; }
  .chapter-card { flex-direction: row; }

  /* ── Recent activity ── */
  .recent-item { flex-wrap: wrap; gap: .3rem; font-size: .82rem; }
  .recent-ex { min-width: 0; }

  /* ── Chapter page ── */
  .chapter-layout { flex-direction: column; }
  .course-panel { width: 100% !important; position: static !important;
                  max-height: 260px; border-radius: var(--radius); }

  /* ── Exercise page ── */
  .exercise-layout { flex-direction: column; }
  .exercise-main { min-width: 0; }
  .exercise-nav { flex-direction: column; align-items: stretch; }
  .exercise-nav a, .exercise-nav button { text-align: center; }
  .feedback-actions { flex-direction: column; align-items: stretch; }
  .feedback-actions > * { text-align: center; }
  .timer-bar { font-size: .78rem; }

  /* ── Stats page ── */
  .stats-summary { grid-template-columns: repeat(2, 1fr); }
  .chap-bar-label { width: 120px; font-size: .75rem; }
  .chap-bar-count { min-width: 28px; font-size: .72rem; }
  .activity-row { flex-wrap: wrap; gap: .4rem; font-size: .8rem; }
  .activity-date { min-width: 0; }
  .badge-full-item { gap: .6rem; padding: .5rem .7rem; }
  .badge-icon-big { font-size: 1.2rem; }

  /* ── Admin page ── */
  .form-row { flex-direction: column; }
  .form-row .form-group { min-width: 0; }
  .admin-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .users-table { font-size: .78rem; }
  .users-table th, .users-table td { padding: .4rem .5rem; }
  .actions-cell { flex-direction: column; gap: .4rem; }
  .input-inline { width: 100%; }

  /* ── Auth pages ── */
  .auth-box { padding: 1.8rem 1.2rem; }

  /* ── KaTeX : scroll horizontal sur les formules longues uniquement ── */
  .katex-display { overflow-x: auto; max-width: 100%; }
}
