/* ============================================================
   main.css – EduLearn v3.1 – Học tập thông minh
   Design: Clean edu-app, mobile-first, warm blue + glass accents
   Glass: navbar, hero buttons, quiz timer, modal overlay
   Tất cả glass bọc @supports — máy yếu tự dùng fallback solid
   ============================================================ */

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

/* ── DESIGN TOKENS ───────────────────────────────────────── */
:root {
  /* Brand */
  --primary:        #2563EB;
  --primary-dark:   #1D4ED8;
  --primary-light:  #EFF6FF;
  --primary-mid:    #BFDBFE;
  --accent:         #7C3AED;
  --accent-light:   #F5F3FF;

  /* Semantics */
  --success:        #059669;
  --success-light:  #ECFDF5;
  --warning:        #D97706;
  --warning-light:  #FFFBEB;
  --danger:         #DC2626;
  --danger-light:   #FEF2F2;
  --info:           #0284C7;

  /* Surface */
  --bg:             #F0F4F8;
  --bg-card:        #FFFFFF;
  --bg-input:       #F8FAFC;
  --border:         #E2E8F0;
  --border-focus:   #93C5FD;

  /* Text */
  --text:           #0F172A;
  --text-secondary: #475569;
  --text-muted:     #94A3B8;
  --text-inv:       #FFFFFF;

  /* Shape */
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --radius-full:    9999px;

  /* Elevation */
  --shadow-xs:   0 1px 2px rgba(0,0,0,.05);
  --shadow:      0 1px 6px rgba(15,23,42,.08), 0 0 1px rgba(15,23,42,.06);
  --shadow-md:   0 4px 16px rgba(15,23,42,.10), 0 0 1px rgba(15,23,42,.06);
  --shadow-lg:   0 12px 32px rgba(15,23,42,.14);
  --shadow-card: 0 2px 8px rgba(37,99,235,.07), 0 0 0 1px rgba(37,99,235,.04);

  --transition: .18s ease;
  --nav-h: 58px;

  /* Glass — chỉ dùng ở vài chỗ, bọc @supports để máy yếu bỏ qua */
  --glass-bg:      rgba(255,255,255,.72);
  --glass-border:  rgba(255,255,255,.45);
  --glass-blur:    8px;
}

/* ── DARK MODE ───────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:             #0B1120;
  --bg-card:        #141B2D;
  --bg-input:       #1E2840;
  --border:         #1E2D4A;
  --border-focus:   #3B82F6;
  --text:           #E2E8F0;
  --text-secondary: #94A3B8;
  --text-muted:     #64748B;
  --primary-light:  #172554;
  --primary-mid:    #1E3A8A;
  --accent-light:   #1E1035;
  --success-light:  #052E16;
  --danger-light:   #3B0707;
  --warning-light:  #2D1700;
  --shadow:         0 1px 6px rgba(0,0,0,.3);
  --shadow-md:      0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:      0 12px 32px rgba(0,0,0,.5);
  --shadow-card:    0 2px 8px rgba(0,0,0,.3);
  --glass-bg:      rgba(20,27,45,.75);
  --glass-border:  rgba(255,255,255,.10);
}

/* ── BASE ────────────────────────────────────────────────── */
html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
button { font-family: inherit; }

/* ── NAVBAR ──────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 200;
  height: var(--nav-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem 0 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
/* Glass navbar — chỉ khi trình duyệt hỗ trợ, máy yếu tự bỏ qua */
@supports (backdrop-filter: blur(1px)) {
  .navbar {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom-color: var(--glass-border);
  }
}
.navbar-brand {
  font-size: 1.2rem; font-weight: 800;
  color: var(--primary); letter-spacing: -.5px;
  display: flex; align-items: center; gap: .35rem;
  cursor: pointer; user-select: none; flex-shrink: 0;
}
.navbar-brand span { color: var(--text); }
.navbar-nav {
  display: flex; align-items: center; gap: .3rem; margin-left: auto;
}
.nav-btn {
  padding: .42rem .9rem; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); font-size: .825rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
  white-space: nowrap; line-height: 1;
}
.nav-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary-mid); }
.nav-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.nav-btn.primary:hover { background: var(--primary-dark); }
.theme-toggle {
  width: 36px; height: 36px; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: var(--bg-input);
  cursor: pointer; font-size: 1rem; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--primary); background: var(--primary-light); }

/* ── LAYOUT ──────────────────────────────────────────────── */
.main-container {
  max-width: 1100px; margin: 0 auto;
  padding: 1.5rem 1.125rem;
  min-height: calc(100vh - var(--nav-h));
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.2rem; border-radius: var(--radius-full);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; transition: all var(--transition); white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37,99,235,.35); }
.btn-secondary { background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover  { filter: brightness(1.08); }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { filter: brightness(1.08); }
.btn-ghost    { background: transparent; color: var(--primary); }
.btn-ghost:hover    { background: var(--primary-light); }
.btn-white { background: #fff; color: var(--primary); font-weight: 700; }
.btn-white:hover { background: var(--primary-light); }
.btn-outline-white {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.55);
}
.btn-outline-white:hover { background: rgba(255,255,255,.28); border-color: #fff; }
/* Glass hero buttons */
@supports (backdrop-filter: blur(1px)) {
  .btn-white {
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .btn-outline-white {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
}
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-sm { padding: .32rem .8rem; font-size: .78rem; }
.w-100 { width: 100%; justify-content: center; }

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-body { padding: 1.25rem; }
.card-header {
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: .95rem;
  display: flex; align-items: center; gap: .5rem;
}

/* ── HERO ─────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #1E40AF 50%, var(--accent) 100%);
  color: #fff; padding: 3rem 1.5rem 2.5rem;
  text-align: center; border-radius: var(--radius-xl);
  position: relative; overflow: hidden; margin-bottom: 2rem;
}
.hero::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle at 20% 50%, rgba(255,255,255,.07) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(255,255,255,.05) 0%, transparent 40%);
}
.hero h1 {
  font-size: clamp(1.6rem, 5vw, 2.6rem); font-weight: 800;
  margin-bottom: .6rem; position: relative;
  line-height: 1.25; letter-spacing: -.02em;
}
.hero p   {
  font-size: clamp(.9rem, 2.5vw, 1.05rem); opacity: .9;
  max-width: 500px; margin: 0 auto 1.5rem; position: relative;
}
.hero-btns {
  display: flex; gap: .75rem; justify-content: center;
  flex-wrap: wrap; position: relative;
}

/* ── WELCOME CARD ────────────────────────────────────────── */
.welcome-card {
  background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
  border: 1px solid var(--primary-mid);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1.75rem;
}
.welcome-emoji { font-size: 2rem; flex-shrink: 0; }

/* ── GRADE GRID ──────────────────────────────────────────── */
.grade-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem; margin-bottom: 2rem;
}
.grade-card {
  background: var(--bg-card); border: 2px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.35rem 1rem;
  cursor: pointer; transition: all var(--transition);
  text-align: center; position: relative; overflow: hidden;
}
.grade-card::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--primary-light), transparent);
  opacity: 0; transition: opacity var(--transition);
}
.grade-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.grade-card:hover::before { opacity: 1; }
.grade-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12), var(--shadow-md);
}
.grade-icon { font-size: 2.25rem; margin-bottom: .4rem; display: block; position: relative; }
.grade-name { font-weight: 700; font-size: .95rem; position: relative; }
.grade-count { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; position: relative; }

/* ── SUBJECT BOXES ───────────────────────────────────────── */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .85rem; margin-bottom: .5rem;
}
.subject-box {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem .9rem;
  text-align: center; cursor: pointer;
  transition: all var(--transition); user-select: none;
}
.subject-box:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.subject-box-icon  { font-size: 2rem; margin-bottom: .4rem; line-height: 1; }
.subject-box-name  { font-weight: 700; font-size: .88rem; margin-bottom: .2rem; color: var(--text); }
.subject-box-count { font-size: .72rem; color: var(--text-muted); }

/* ── SUBJECT TABS ─────────────────────────────────────────── */
.subject-tabs {
  display: flex; gap: .5rem; margin-bottom: 1.5rem;
  overflow-x: auto; padding-bottom: .25rem;
  scrollbar-width: thin;
}
.subject-tab {
  padding: .5rem 1.2rem; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: var(--bg-card);
  font-weight: 700; font-size: .85rem; cursor: pointer;
  transition: all var(--transition); white-space: nowrap;
  color: var(--text-secondary);
}
.subject-tab:hover { border-color: var(--primary); color: var(--primary); }
.subject-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── CHAPTER ACCORDION ───────────────────────────────────── */
.chapter-group { margin-bottom: .85rem; }
.chapter-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .85rem 1.15rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-weight: 700; font-size: .93rem;
  transition: all var(--transition); user-select: none;
}
.chapter-header:hover { border-color: var(--primary); background: var(--primary-light); }
.chapter-header.open {
  border-color: var(--primary); background: var(--primary-light);
  color: var(--primary); border-radius: var(--radius) var(--radius) 0 0;
}
.chapter-arrow { margin-left: auto; transition: transform var(--transition); font-size: .7rem; }
.chapter-header.open .chapter-arrow { transform: rotate(180deg); }
.chapter-badge {
  background: var(--primary); color: #fff;
  border-radius: var(--radius-full); font-size: .72rem;
  padding: .15rem .6rem; font-weight: 700;
}
.chapter-lessons {
  display: none;
  border: 1px solid var(--primary); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.chapter-lessons.open { display: block; }

/* ── LESSON ROW ──────────────────────────────────────────── */
.lesson-row {
  display: flex; align-items: center; gap: .85rem;
  padding: .8rem 1.15rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.lesson-row:last-child { border-bottom: none; }
.lesson-row:hover { background: var(--primary-light); }
.lesson-num {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  font-weight: 800; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.lesson-info { flex: 1; min-width: 0; }
.lesson-title { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson-meta  { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }
.lesson-score { font-size: .78rem; color: var(--success); font-weight: 700; }
.lesson-actions { display: flex; gap: .4rem; flex-shrink: 0; }

/* ── BREADCRUMB ──────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: .4rem;
  font-size: .82rem; color: var(--text-muted);
  margin-bottom: 1.25rem; flex-wrap: wrap;
}
.breadcrumb a { color: var(--primary); font-weight: 600; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── SECTION TITLE ───────────────────────────────────────── */
.section-title {
  font-size: 1.05rem; font-weight: 800; margin-bottom: 1rem;
  display: flex; align-items: center; gap: .5rem;
}
.section-title::after {
  content: ''; flex: 1; height: 2px;
  background: var(--border); border-radius: var(--radius-full);
}

/* ── QUIZ ────────────────────────────────────────────────── */
.quiz-wrap {
  background: var(--bg-card); border-radius: var(--radius-xl);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.quiz-header {
  padding: 1.1rem 1.4rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.quiz-title { font-weight: 700; font-size: 1rem; }
.quiz-subtitle { font-size: .78rem; opacity: .85; margin-top: .12rem; }
.quiz-timer {
  background: rgba(255,255,255,.2);
  border-radius: var(--radius-full);
  padding: .38rem .95rem; font-weight: 700; font-size: .95rem;
  white-space: nowrap; min-width: 76px; text-align: center;
  transition: background .3s;
  border: 1px solid rgba(255,255,255,.25);
}
@supports (backdrop-filter: blur(1px)) {
  .quiz-timer {
    background: rgba(255,255,255,.15);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
}
.quiz-timer.warning { background: rgba(220,38,38,.75); animation: pulse 1s infinite; border-color: transparent; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.7} }

.quiz-body { padding: 1.35rem 1.25rem; }
.quiz-section { margin-bottom: 2rem; }
.section-header {
  padding: .65rem 1rem; margin-bottom: 1rem;
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-weight: 700; color: var(--primary);
}
.section-instruction { font-size: .8rem; font-weight: 500; color: var(--text-secondary); margin-top: .2rem; }

.question-card {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1rem;
  margin-bottom: .85rem; transition: border-color var(--transition);
}
.question-card:hover { border-color: var(--primary-mid); }
.question-text { font-weight: 600; margin-bottom: .75rem; line-height: 1.55; }
.question-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: .72rem; font-weight: 700; margin-right: .45rem; flex-shrink: 0;
}

.options-list { display: flex; flex-direction: column; gap: .45rem; }
.option-item {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .6rem .85rem; border-radius: var(--radius);
  border: 1.5px solid var(--border); cursor: pointer;
  transition: all var(--transition); font-size: .88rem;
  user-select: none; background: var(--bg-card);
}
.option-item:hover { border-color: var(--primary); background: var(--primary-light); }
.option-item.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.option-item.correct  { border-color: var(--success); background: var(--success-light); color: var(--success); }
.option-item.wrong    { border-color: var(--danger);  background: var(--danger-light);  color: var(--danger); }
.option-radio {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid var(--border); flex-shrink: 0; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.option-item.selected .option-radio { border-color: var(--primary); background: var(--primary); }
.option-item.correct  .option-radio { border-color: var(--success); background: var(--success); }
.option-item.wrong    .option-radio { border-color: var(--danger);  background: var(--danger); }
.option-radio::after {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #fff; opacity: 0;
}
.option-item.selected .option-radio::after,
.option-item.correct  .option-radio::after,
.option-item.wrong    .option-radio::after { opacity: 1; }

.option-check {
  width: 17px; height: 17px; border-radius: 4px;
  border: 2px solid var(--border); flex-shrink: 0; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); font-size: .7rem;
}
.option-item.selected .option-check { border-color: var(--primary); background: var(--primary); color: #fff; }

.scale-options { display: flex; gap: .5rem; flex-wrap: wrap; }
.scale-btn {
  width: 44px; height: 44px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--bg-card);
  font-weight: 700; cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; font-size: .9rem;
}
.scale-btn:hover  { border-color: var(--primary); background: var(--primary-light); }
.scale-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

.fill-input {
  width: 100%; padding: .55rem .85rem;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--text); font-size: .88rem;
  transition: border-color var(--transition);
}
.fill-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.explanation-box {
  margin-top: .75rem; padding: .6rem .85rem;
  background: #EFF6FF; border-left: 3px solid var(--info);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .83rem; color: var(--text-secondary); display: none;
}
.explanation-box.show { display: block; }

.quiz-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .65rem; justify-content: flex-end; align-items: center;
  background: var(--bg-input);
}

/* Result */
.quiz-result { padding: 2rem 1.5rem; text-align: center; }
.result-score { font-size: 3.5rem; font-weight: 900; color: var(--primary); line-height: 1; }
.result-grade { font-size: 1.05rem; font-weight: 600; margin-top: .5rem; }
.result-stats {
  display: flex; gap: 1.5rem; justify-content: center; flex-wrap: wrap;
  margin: 1.25rem 0;
}
.result-stat { text-align: center; }
.result-stat-val { font-weight: 800; font-size: 1.35rem; display: block; }
.result-stat-lbl { font-size: .76rem; color: var(--text-muted); }

/* ── PROGRESS BAR ────────────────────────────────────────── */
.progress-bar-wrap {
  height: 7px; background: var(--border);
  border-radius: var(--radius-full); overflow: hidden; margin: .65rem 0;
}
.progress-bar {
  height: 100%; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .5s ease;
}

/* ── SURVEY ──────────────────────────────────────────────── */
.survey-wrap {
  background: var(--bg-card); border-radius: var(--radius-xl);
  border: 2px solid var(--primary); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.survey-header {
  padding: 1.15rem 1.5rem;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: #fff;
}
.survey-header h2 { font-size: 1.05rem; font-weight: 700; }
.survey-header p  { font-size: .83rem; opacity: .85; margin-top: .2rem; }
.survey-body { padding: 1.35rem; }
.survey-question { margin-bottom: 1.4rem; }
.survey-question-text { font-weight: 600; margin-bottom: .75rem; }

/* ── MODALS ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15,23,42,.45);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
}
@supports (backdrop-filter: blur(1px)) {
  .modal-overlay { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 420px;
  overflow: hidden; animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }
.modal-header {
  padding: 1.1rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 1.05rem;
}
.modal-close {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--bg-input); color: var(--text-muted); cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--danger-light); color: var(--danger); }
.modal-body  { padding: 1.4rem; }
.modal-footer {
  padding: .9rem 1.4rem; border-top: 1px solid var(--border);
  display: flex; gap: .5rem; justify-content: flex-end;
}

/* ── FORMS ───────────────────────────────────────────────── */
.form-group { margin-bottom: .95rem; }
.form-label { font-size: .82rem; font-weight: 700; display: block; margin-bottom: .35rem; color: var(--text-secondary); letter-spacing: .01em; }
.form-control {
  width: 100%; padding: .62rem .9rem;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--bg-input); color: var(--text); font-size: .88rem;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-hint  { font-size: .76rem; color: var(--text-muted); margin-top: .3rem; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: .3rem; padding: .4rem .7rem; background: var(--danger-light); border-radius: var(--radius-sm); }

.form-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.1rem; }
.form-tab {
  padding: .55rem 1.2rem; font-weight: 700; cursor: pointer;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition); font-size: .88rem;
}
.form-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── PROFILE ─────────────────────────────────────────────── */
.profile-hero {
  background: linear-gradient(135deg, var(--primary), #1E3A8A, var(--accent));
  border-radius: var(--radius-xl); padding: 2rem;
  color: #fff; display: flex; align-items: center; gap: 1.5rem;
  flex-wrap: wrap; margin-bottom: 1.5rem;
}
.avatar-lg {
  width: 76px; height: 76px; border-radius: 50%;
  background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; flex-shrink: 0;
  border: 3px solid rgba(255,255,255,.45);
  font-weight: 800;
}
.profile-name  { font-size: 1.35rem; font-weight: 800; }
.profile-role  { font-size: .83rem; opacity: .85; margin-top: .1rem; }
.profile-stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-top: .75rem; }
.profile-stat  { text-align: center; }
.profile-stat-val { font-size: 1.45rem; font-weight: 800; display: block; }
.profile-stat-lbl { font-size: .74rem; opacity: .8; }

.badges-grid { display: flex; gap: .65rem; flex-wrap: wrap; }
.badge-chip {
  display: flex; align-items: center; gap: .4rem;
  padding: .38rem .8rem; border-radius: var(--radius-full);
  background: var(--primary-light); color: var(--primary);
  font-size: .8rem; font-weight: 700; border: 1px solid var(--primary-mid);
}

/* ── LEADERBOARD ─────────────────────────────────────────── */
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.leaderboard-table th {
  padding: .7rem 1rem; text-align: left;
  background: var(--primary-light); color: var(--primary);
  font-weight: 700; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .05em;
}
.leaderboard-table td { padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.leaderboard-table tr:last-child td { border-bottom: none; }
.leaderboard-table tr:hover td { background: var(--bg-input); }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 27px; height: 27px; border-radius: 50%;
  background: var(--bg-input); border: 1px solid var(--border);
  font-weight: 700; font-size: .78rem;
}

/* ── PAGE TABS ───────────────────────────────────────────── */
.page-tabs {
  display: flex; gap: .2rem; margin-bottom: 1.4rem;
  background: var(--bg-input); padding: .25rem;
  border-radius: var(--radius-full); width: fit-content;
  border: 1px solid var(--border);
}
.page-tab {
  padding: .42rem 1.05rem; border-radius: var(--radius-full);
  cursor: pointer; font-weight: 600; font-size: .85rem;
  color: var(--text-muted); transition: all var(--transition);
  border: none; background: transparent;
}
.page-tab.active { background: var(--bg-card); color: var(--primary); box-shadow: var(--shadow); }

/* ── TOAST ───────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 9999; display: flex; flex-direction: column; gap: .45rem;
}
.toast {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem; border-radius: var(--radius-lg);
  background: var(--bg-card); color: var(--text);
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
  font-size: .85rem; font-weight: 500;
  animation: slideInRight .22s ease;
  max-width: 300px;
}
@keyframes slideInRight { from { transform: translateX(16px); opacity: 0; } }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }

/* ── SPINNER ─────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin .65s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { display: flex; justify-content: center; padding: 2.5rem; }

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-icon  { font-size: 2.75rem; margin-bottom: .85rem; }
.empty-state p { font-size: .92rem; }

/* ── UTILITY ─────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-primary { color: var(--primary); }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }

/* ── MOBILE RESPONSIVE ───────────────────────────────────── */
@media (max-width: 768px) {
  .grade-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
}

@media (max-width: 640px) {
  :root { --nav-h: 54px; }

  .main-container { padding: .875rem .875rem; }

  /* Navbar mobile */
  .navbar { padding: 0 .875rem; }
  .navbar-brand span { display: none; }
  .nav-btn:not(.primary) {
    padding: .38rem .7rem;
    font-size: .78rem;
  }

  /* Hero mobile */
  .hero {
    padding: 2rem 1rem 1.75rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
  }
  .hero h1 { font-size: 1.55rem; }
  .hero p  { font-size: .88rem; }
  .hero-btns { gap: .5rem; }
  .btn-lg   { padding: .65rem 1.25rem; font-size: .9rem; }

  /* Grade grid 2 col on small */
  .grade-grid { grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: 1.25rem; }
  .grade-card { padding: 1rem .75rem; }
  .grade-icon { font-size: 1.9rem; }

  /* Subject grid */
  .subject-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }

  /* Quiz */
  .quiz-header { padding: .9rem 1rem; flex-wrap: wrap; }
  .quiz-body   { padding: 1rem .875rem; }
  .quiz-footer { flex-direction: column; padding: .875rem; }
  .quiz-footer .btn { width: 100%; justify-content: center; }

  /* Profile */
  .profile-hero { flex-direction: column; text-align: center; padding: 1.5rem 1rem; }
  .profile-stats { justify-content: center; gap: 1.25rem; }

  /* Modal full-width on mobile */
  .modal { max-width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  /* Toast bottom center */
  .toast-container { right: .75rem; left: .75rem; bottom: .875rem; }
  .toast { max-width: 100%; }

  /* Table scroll */
  .leaderboard-table { font-size: .8rem; }
  .leaderboard-table th,
  .leaderboard-table td { padding: .55rem .6rem; }
}

/* ── SAFE AREA (iPhone notch) ────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .toast-container { bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
  .quiz-footer      { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
}