/* ================================
   1. VARIABLES & THEME
   ================================ */
:root {
  /* Palette: Slate & Blue */
  --c-white: #ffffff;
  --c-black: #000000;
  
  --c-slate-50:  #f8fafc;
  --c-slate-100: #f1f5f9;
  --c-slate-200: #e2e8f0;
  --c-slate-300: #cbd5e1;
  --c-slate-400: #94a3b8;
  --c-slate-500: #64748b;
  --c-slate-800: #1e293b;
  --c-slate-900: #0f172a;

  --c-blue-500: #3b82f6;
  --c-blue-600: #2563eb;
  --c-blue-700: #1d4ed8;

  --c-amber:  #f59e0b;
  --c-emerald:#10b981;
  --c-red:    #ef4444;
  --c-purple: #8b5cf6;

  /* Semantic Variables */
  --bg-body: var(--c-slate-50);
  --bg-card: var(--c-white);
  --bg-input: var(--c-white);
  --bg-header: rgba(255,255,255,0.85);
  --bg-hover: var(--c-slate-50);
  
  --text-main: var(--c-slate-900);
  --text-muted: var(--c-slate-500);
  --border: var(--c-slate-200);

  --primary: var(--c-blue-600);
  --primary-hover: var(--c-blue-700);
  --primary-ring: rgba(37,99,235,0.2);

  --hero-gradient: radial-gradient(circle at 50% 0%, #eff6ff 0%, var(--bg-body) 75%);
  --premium-gradient: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);

  /* Measurements */
  --header-height: 64px;
  --container-max: 1200px;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}



/* Dark Mode Overrides */
body.dark-mode {
  --bg-body: var(--c-slate-900);
  --bg-card: var(--c-slate-800);
  --bg-input: #0b1220;
  --bg-header: rgba(15,23,42,0.85);
  --bg-hover: var(--c-slate-800); /* slightly lighter than card? or separate */
  
  --text-main: var(--c-slate-50);
  --text-muted: var(--c-slate-400);
  --border: #334155;
  
  --primary: var(--c-blue-500);
  --primary-hover: var(--c-blue-600);
  
  --hero-gradient: radial-gradient(circle at 50% 0%, #172554 0%, var(--bg-body) 75%);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
}

/* ================================
   2. RESET & BASE
   ================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  display: flex; flex-direction: column;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

a { text-decoration: none; color: inherit; cursor: pointer; }
button, input, textarea, select { font: inherit; outline: none; }
img { max-width: 100%; display: block; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.container {
  width: 100%; max-width: var(--container-max);
  margin: 0 auto; padding: 0 1.5rem;
}

.modal-backdrop{
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 3000; background: rgba(0,0,0,0.6);
}
.modal-card{
  width: 100%; max-width: 640px; background: var(--bg-card); padding: 18px;
  border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.modal-card h2{ margin: 0 0 8px }
.modal-card .tag{ display: inline-block; padding: 6px 8px; margin: 4px; border-radius: 8px; background: rgba(0,0,0,0.03); border: 1px solid var(--border) }

/* Onboarding subject list customisation */
#subjectList{padding:6px; max-height:340px; overflow:auto}
#subjectList label{background:transparent;padding:8px;border-radius:8px;display:block}


/* ================================
   3. COMPONENTS (Buttons & Inputs)
   ================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.6rem 1.2rem; border-radius: var(--radius-sm); font-weight: 600;
  cursor: pointer; transition: var(--transition); border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-main); font-size: 0.9rem;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: var(--text-muted); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: white; border-color: transparent; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 12px var(--primary-ring); border-color: transparent; }

.btn-premium { background: var(--premium-gradient); color: white; border: none; }
.btn-danger { background: var(--c-red); color: white; border: none; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; border-color: transparent; background: transparent; }
.icon-btn:hover { background: var(--bg-hover); border-color: var(--border); }

input, textarea, select {
  width: 100%; padding: 0.8rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-main); margin-bottom: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

/* ================================
   4. HEADER
   ================================ */
header {
  height: var(--header-height);
  background: var(--bg-header);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
}

.logo { font-weight: 800; font-size: 1.2rem; display: flex; align-items: center; gap: 0.6rem; color: var(--text-main); }
.logo i { color: var(--primary); font-size: 1.3rem; }

.user-area { display: flex; align-items: center; gap: 1rem; }

.gamification-bar { display: flex; gap: 0.8rem; margin-right: 0.5rem; }
.stat-badge {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.85rem; font-weight: 700;
  padding: 0.35rem 0.75rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 50px;
  box-shadow: var(--shadow-sm);
}
.streak-count i { color: var(--c-amber); }
.xp-count i { color: var(--c-purple); }

/* Dropdown */
.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  min-width: 200px; overflow: hidden; display: none; flex-direction: column;
  z-index: 200;
}
.user-dropdown.show { display: flex; animation: fadeIn 0.15s ease-out; }
.user-dropdown a { 
  padding: 0.75rem 1rem; font-size: 0.9rem; cursor: pointer; 
  transition: background 0.2s; display: flex; align-items: center; gap: 8px;
}
.user-dropdown a:hover { background: var(--c-slate-100); color: var(--primary); }
.user-dropdown i { width: 20px; text-align: center; }

/* ================================
   5. VIEWS & LANDING
   ================================ */
.view { display: none; padding-bottom: 4rem; animation: fadeIn 0.3s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.landing-hero {
  padding: 3.5rem 0 4rem; background: var(--hero-gradient);
  border-bottom: 1px solid var(--border); margin-bottom: 2.5rem;
}
.landing-hero .hero-grid { display: grid; grid-template-columns: 1fr 380px; gap: 2rem; align-items: center; }
.landing-hero h1 { font-size: clamp(2rem, 4.5vw, 3rem); font-weight: 800; margin-bottom: 0.8rem; line-height: 1.05; color: var(--text-main); }
.landing-hero h1 span { color: var(--primary); }
.hero-lead { max-width: 60ch; margin-bottom: 1.25rem; color: var(--text-muted); font-size: 1.05rem; }
.hero-ctas { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }
.hero-trust { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem; }
.hero-visual { display:flex; justify-content:center; }
.mock-card { width: 320px; background: linear-gradient(180deg,var(--bg-card),#fff); border:1px solid var(--border); border-radius:14px; padding:12px; box-shadow: var(--shadow-lg); }
.mock-header { display:flex; justify-content:space-between; align-items:center; font-weight:700; color:var(--primary); padding:8px 6px; }
.mock-body { padding: 8px 6px 14px; display:flex; flex-direction:column; gap:8px; }
.mock-topic { background: var(--c-slate-50); padding:10px 12px; border-radius:10px; font-weight:600; color:var(--text-main); }
.mock-footer { padding:8px 6px; color:var(--text-muted); font-size:0.85rem; }

/* ================================
   6. DASHBOARD
   ================================ */
.dashboard-container {
  display: grid; grid-template-columns: 1fr 340px; gap: 2rem; padding-top: 2rem;
}
@media(max-width: 900px) { 
  .dashboard-container { grid-template-columns: 1fr; } 
  .sidebar-column { order: -1; } /* Stats on top on mobile */
}

/* Stats */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 1.5rem; border-radius: var(--radius-md); text-align: center;
  box-shadow: var(--shadow-sm); transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.stat-card .value { font-size: 2rem; font-weight: 800; color: var(--primary); display: block; line-height: 1; margin-bottom: 5px; }
.stat-card .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 700; }

/* Focus Timer */
.focus-timer-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--c-slate-50) 100%);
  border: 1px solid var(--border); padding: 2rem; border-radius: var(--radius-lg);
  text-align: center; margin-bottom: 2rem; position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.focus-timer-card::before {
  content:''; position: absolute; top:0; left:0; width:100%; height:4px;
  background: linear-gradient(90deg, var(--c-blue-500), var(--c-purple));
}
.timer-display { 
  font-size: 4rem; font-weight: 800; font-variant-numeric: tabular-nums; 
  letter-spacing: -2px; margin: 1rem 0; line-height: 1;
}
.timer-controls { display: flex; justify-content: center; gap: 1rem; }
.timer-active .timer-display { color: var(--primary); }

/* Landing Features */
.features-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 2rem; }
.feature-card { background: var(--bg-card); border:1px solid var(--border); padding:1.25rem; border-radius: var(--radius-md); text-align:center; box-shadow: var(--shadow-sm); transition: transform 0.18s; }
.feature-card h4 { margin-top: 0.5rem; margin-bottom: 0.5rem; font-size: 1rem; }
.feature-card p { color: var(--text-muted); font-size: 0.95rem; }
.feature-card i { color: var(--primary); }
.feature-card:hover { transform: translateY(-6px); border-color: var(--primary); box-shadow: var(--shadow-lg); }

.testimonials { margin-top: 2rem; display:flex; justify-content:center; }
.testimonial { max-width: 900px; background: linear-gradient(180deg,var(--bg-card), #fff); border:1px solid var(--border); padding:1.25rem 1.5rem; border-radius: var(--radius-md); color: var(--text-main); font-weight:600; }
.testimonial cite { display:block; margin-top:0.75rem; font-weight:700; color:var(--text-muted); font-size:0.9rem; }

@media(max-width: 980px) { 
  .dashboard-container { grid-template-columns: 1fr; } 
  .sidebar-column { order: -1; } /* Stats on top on mobile */
}

@media(max-width: 820px) {
  .landing-hero .hero-grid { grid-template-columns: 1fr; text-align: center; }
  .hero-visual { margin-top: 1rem; }
  .features-grid { grid-template-columns: 1fr; }
}

.section-header { 
  margin-bottom: 1.25rem; display: flex; justify-content: space-between; align-items: center; 
}
.section-header h2 { font-size: 1.25rem; font-weight: 700; margin: 0; }

/* Sidebar */
.panel {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 1.25rem; border-radius: var(--radius-md); margin-bottom: 1.5rem;
}
.panel h3 { font-size: 1rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; font-weight: 700; }

.leaderboard-list { display: flex; flex-direction: column; gap: 0.5rem; }
.leaderboard-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  font-size: 0.9rem; transition: 0.18s ease;
}
.leaderboard-row:hover { border-color: var(--primary); transform: translateX(4px); box-shadow: var(--shadow-sm); }
.leaderboard-row.is-me { border: 1px solid var(--primary); background: linear-gradient(90deg, rgba(37,99,235,0.06), rgba(37,99,235,0.02)); }
.rank-num { width: 24px; font-weight: 800; color: var(--text-muted); }
.rank-1 { color: #fbbf24; }
.rank-2 { color: #94a3b8; }
.rank-3 { color: #b45309; }

.badges-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.badge { text-align: center; opacity: 0.3; filter: grayscale(1); transition: 0.2s; }
.badge.unlocked { opacity: 1; filter: grayscale(0); }
.badge-icon { 
  width: 42px; height: 42px; margin: 0 auto 5px; 
  background: var(--c-slate-100); border-radius: 50%; 
  display: flex; align-items: center; justify-content: center; 
  color: var(--c-amber); border: 1px solid var(--border); 
}

/* ================================
   7. LIBRARY / GRID
   ================================ */
.search-toolbar {
  margin: 0 auto 2rem; max-width: 800px; display: flex; gap: 0.8rem;
  background: var(--bg-card); padding: 0.5rem 0.5rem 0.5rem 1.2rem; 
  border-radius: 50px; border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  align-items: center;
}
.search-input-wrapper { flex: 1; position: relative; display: flex; align-items: center; }
.search-input-wrapper i { color: var(--text-muted); margin-right: 0.5rem; }
.search-input-wrapper input { 
  border: none; background: transparent; margin: 0; padding: 0.5rem; 
  box-shadow: none; font-size: 1rem; width: 100%;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.5rem; }
.subject-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 1.75rem 1.25rem;
  text-align: center; position: relative; cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex; flex-direction: column; align-items: center;
}
.subject-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.subject-card h3 { font-size: 1.1rem; margin: 0.5rem 0; }
.subject-card .icon-box {
  width: 56px; height: 56px; background: var(--c-slate-100); color: var(--text-main);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin-bottom: 1rem; transition: 0.3s;
}
.subject-card:hover .icon-box { background: var(--primary); color: white; transform: rotate(-5deg) scale(1.1); }
.fav-btn { 
  position: absolute; top: 12px; right: 12px; background: none; border: none; 
  color: var(--c-slate-300); font-size: 1.25rem; transition: 0.2s;
}
.fav-btn:hover { transform: scale(1.2); }
.fav-btn.active { color: var(--c-amber); }
.status-dot { position: absolute; top: 16px; left: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--c-emerald); box-shadow: 0 0 0 2px var(--bg-card); }

/* ================================
   8. MODALS (Fixed)
   ================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  z-index: 2000; display: none; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }

.modal {
  background: var(--bg-card); width: 95%; max-width: 650px; max-height: 85vh;
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  transform: scale(0.95); transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .modal { transform: scale(1); }

.modal-header {
  padding: 1.25rem 1.75rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-card);
}
.modal-header h2 { font-size: 1.4rem; font-weight: 800; margin: 0; }
.modal-header .btn {
  width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted);
}
.modal-header .btn:hover { background: var(--c-slate-100); color: var(--c-red); border-color: var(--c-red); }

.modal-body { padding: 1.5rem 1.75rem; overflow-y: auto; }

/* AI Tabs (Segmented Control) */
.ai-tabs {
  display: flex; gap: 4px; margin-bottom: 1.5rem;
  background: var(--c-slate-100); padding: 4px; border-radius: 12px;
}
.ai-tab {
  flex: 1; text-align: center; padding: 0.6rem; cursor: pointer;
  border-radius: 8px; font-weight: 600; font-size: 0.9rem;
  color: var(--text-muted); transition: 0.2s;
}
.ai-tab:hover { color: var(--text-main); }
.ai-tab.active { background: var(--bg-card); color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

/* Content Areas */
.ai-content { display: none; animation: fadeIn 0.2s; }
.ai-content.active { display: block; }

/* Syllabus List Items */
#syllabusContainer { margin-bottom: 2rem; }
.checklist-item {
  display: flex; align-items: center; gap: 12px;
  padding: 0.9rem 1rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 0.6rem;
  cursor: pointer; transition: 0.2s; background: var(--bg-card);
  font-weight: 500;
}
.checklist-item:hover { border-color: var(--primary); transform: translateX(3px); }
.checklist-item i { font-size: 1.2rem; color: var(--c-slate-300); }
.checklist-item.checked { background: var(--c-slate-50); color: var(--text-muted); text-decoration: line-through; }
.checklist-item.checked i { color: var(--c-emerald); }

/* Resource Grid (Chips) */
.resource-grid {
  display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem;
}
.res-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0.5rem 1rem; background: var(--c-slate-50);
  border: 1px solid var(--border); border-radius: 50px;
  font-size: 0.85rem; font-weight: 600; color: var(--text-main);
  text-decoration: none; transition: 0.2s;
}
.res-btn i { color: var(--c-red); font-size: 1rem; }
.res-btn:hover {
  background: var(--bg-card); border-color: var(--primary); color: var(--primary);
  transform: translateY(-2px); box-shadow: var(--shadow-sm);
}

/* Chat & Premium Gates */
.premium-gate { 
  text-align: center; padding: 2.5rem; border: 2px dashed var(--border); 
  border-radius: var(--radius-md); background: var(--c-slate-50); margin-top: 1rem;
}
.premium-gate i { font-size: 2rem; color: var(--c-amber); margin-bottom: 1rem; display: block; }
.premium-gate h3 { margin-bottom: 0.5rem; }

#chatBox { 
  height: 350px; overflow-y: auto; background: var(--c-slate-50);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 1rem; margin-bottom: 1rem; display: flex; flex-direction: column; gap: 10px;
}
.chat-msg { padding: 10px 14px; border-radius: 12px; max-width: 85%; line-height: 1.4; font-size: 0.95rem; }
.chat-msg.user { background: var(--primary); color: white; margin-left: auto; border-bottom-right-radius: 2px; }
.chat-msg.ai { background: var(--bg-card); border: 1px solid var(--border); margin-right: auto; border-bottom-left-radius: 2px; }

/* Community Notes */
.note-card { 
  background: var(--bg-card); border: 1px solid var(--border); 
  padding: 1.25rem; border-radius: var(--radius-md); margin-bottom: 1rem; 
  transition: transform 0.2s;
}
.note-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.note-card b { display: block; margin-bottom: 0.5rem; color: var(--primary); }

/* ================================
   9. NOTIFICATIONS & VIEWER
   ================================ */
#notif-container { position: fixed; bottom: 30px; right: 30px; z-index: 4000; display: flex; flex-direction: column; gap: 10px; }
.notif { 
  padding: 1rem 1.5rem; background: var(--c-slate-800); color: white; 
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-weight: 600;
  animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.notif.success { background: var(--c-emerald); }
.notif.error { background: var(--c-red); }
.notif.xp { background: var(--premium-gradient); color: #000; }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

#resourceViewer { display: none; position: fixed; inset: 0; background: #000; z-index: 3000; flex-direction: column; }
#resourceViewer.active { display: flex; animation: fadeIn 0.2s; }
.viewer-header { height: 50px; background: #111; display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; color: #fff; font-weight: 700; }