/* Optional deep-purple night palette. Brand gradients and semantic feedback stay intact. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #120A1B;
  --panel: #1D1228;
  --panel2: #29183A;
  --line: #49335D;
  --text: #F6F0FC;
  --muted: #C3B4D1;
  --blue-soft: #30203F;
  --navy: #180D25;
  --lux-ivory: #120A1B;
  --lux-surface: #1D1228;
  --lux-line: #49335D;
  --lux-ink: #F6F0FC;
  --lux-muted: #C3B4D1;
  --popup-bg: #251833;
  --popup-text: #F6F0FC;
  --popup-muted: #C3B4D1;
  --popup-border: #62477A;
  --popup-selected: #39224D;
  --popup-accent: #C58BFF;
}

:root[data-theme="dark"] html,
:root[data-theme="dark"] body {
  background: radial-gradient(ellipse at 8% 0%, #29163A 0, transparent 35%), linear-gradient(180deg, #120A1B, #170D22 65%, #100817) !important;
  color: #F6F0FC !important;
}
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .main,
:root[data-theme="dark"] .content,
:root[data-theme="dark"] .feature-sheet,
:root[data-theme="dark"] .feature-content,
:root[data-theme="dark"] .account-menu,
:root[data-theme="dark"] .bottom-more-sheet,
:root[data-theme="dark"] .mobile-bottom-nav {
  background: #1A1024 !important;
  color: #F6F0FC !important;
  border-color: #49335D !important;
}
:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .feature-modal-head,
:root[data-theme="dark"] .admin-dashboard-mode .feature-modal-head,
:root[data-theme="dark"] .home-update-heading,
:root[data-theme="dark"] .home-upcoming .home-update-heading {
  color: #FFFFFF !important;
}
:root[data-theme="dark"] .nav-label,
:root[data-theme="dark"] .nav-item,
:root[data-theme="dark"] .breadcrumb,
:root[data-theme="dark"] .top-name,
:root[data-theme="dark"] .home-course-heading h2,
:root[data-theme="dark"] .home-update-heading h2,
:root[data-theme="dark"] .home-update-heading h3,
:root[data-theme="dark"] .admin-section-title,
:root[data-theme="dark"] .feature-card h3,
:root[data-theme="dark"] .feature-form h3,
:root[data-theme="dark"] .feature-form label,
:root[data-theme="dark"] .feature-card,
:root[data-theme="dark"] .feature-card p,
:root[data-theme="dark"] .student-table td,
:root[data-theme="dark"] .student-profile-field,
:root[data-theme="dark"] .student-profile-field b,
:root[data-theme="dark"] .home-progress-copy b,
:root[data-theme="dark"] .home-shortcut-grid button,
:root[data-theme="dark"] .home-course-body h3,
:root[data-theme="dark"] .course-progress-section,
:root[data-theme="dark"] .course-chapter-row h4 {
  color: #F6F0FC !important;
}
:root[data-theme="dark"] .feature-card small,
:root[data-theme="dark"] .feature-toolbar p,
:root[data-theme="dark"] .feature-meta,
:root[data-theme="dark"] .image-hint,
:root[data-theme="dark"] .status-message,
:root[data-theme="dark"] .home-progress-copy small,
:root[data-theme="dark"] .home-shortcut-grid button small,
:root[data-theme="dark"] .home-current-date,
:root[data-theme="dark"] .home-course-body p,
:root[data-theme="dark"] .course-progress-summary,
:root[data-theme="dark"] .course-chapter-row small,
:root[data-theme="dark"] .sidebar-user small {
  color: #C3B4D1 !important;
}
:root[data-theme="dark"] .feature-tile,
:root[data-theme="dark"] .feature-card,
:root[data-theme="dark"] .feature-form,
:root[data-theme="dark"] .assessment-question,
:root[data-theme="dark"] .video-library-row,
:root[data-theme="dark"] .video-library-card,
:root[data-theme="dark"] .subject-card,
:root[data-theme="dark"] .admin-record-card,
:root[data-theme="dark"] .admin-student-card,
:root[data-theme="dark"] .student-filter-panel,
:root[data-theme="dark"] .community-compose,
:root[data-theme="dark"] .post-card,
:root[data-theme="dark"] .profile-preview,
:root[data-theme="dark"] .student-profile-summary,
:root[data-theme="dark"] .profile-edit-panel,
:root[data-theme="dark"] .home-progress-summary,
:root[data-theme="dark"] .home-planner-summary,
:root[data-theme="dark"] .home-shortcut-grid button,
:root[data-theme="dark"] .home-notice-card,
:root[data-theme="dark"] .home-upcoming-card,
:root[data-theme="dark"] .home-schedule-empty,
:root[data-theme="dark"] .home-section-error,
:root[data-theme="dark"] .home-course-body,
:root[data-theme="dark"] .admin-page-header,
:root[data-theme="dark"] .admin-dashboard-intro,
:root[data-theme="dark"] .result-summary-card,
:root[data-theme="dark"] .result-stat-card,
:root[data-theme="dark"] .result-chart-block,
:root[data-theme="dark"] .result-comparison-card,
:root[data-theme="dark"] .result-history-card,
:root[data-theme="dark"] .result-leaderboard-empty,
:root[data-theme="dark"] .planner-progress-card,
:root[data-theme="dark"] .planner-section,
:root[data-theme="dark"] .planner-task-card,
:root[data-theme="dark"] .planner-goal-card,
:root[data-theme="dark"] .planner-calendar,
:root[data-theme="dark"] .empty-state {
  background: #241731 !important;
  color: #F6F0FC !important;
  border-color: #49335D !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.22) !important;
}
:root[data-theme="dark"] .feature-form input,
:root[data-theme="dark"] .feature-form select,
:root[data-theme="dark"] .feature-form textarea,
:root[data-theme="dark"] .feature-input,
:root[data-theme="dark"] .comment-form input,
:root[data-theme="dark"] .profile-form input,
:root[data-theme="dark"] .profile-form select,
:root[data-theme="dark"] .student-filter-panel input,
:root[data-theme="dark"] .student-filter-panel select,
:root[data-theme="dark"] .community-compose textarea,
:root[data-theme="dark"] #authForm input,
:root[data-theme="dark"] #adminAuthForm input,
:root[data-theme="dark"] .admin-search,
:root[data-theme="dark"] .planner-task-form input,
:root[data-theme="dark"] .planner-task-form select,
:root[data-theme="dark"] .planner-task-form textarea {
  color: #F6F0FC !important;
  background: #170E21 !important;
  border-color: #59416F !important;
}
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color: #A996BA !important;
}
:root[data-theme="dark"] select,
:root[data-theme="dark"] select option,
:root[data-theme="dark"] select optgroup {
  color: #F6F0FC !important;
  background-color: #241731 !important;
}
:root[data-theme="dark"] .auth-screen,
:root[data-theme="dark"] .auth-shell,
:root[data-theme="dark"] .auth-form-side,
:root[data-theme="dark"] .auth-heading,
:root[data-theme="dark"] .password-reset-panel {
  background: #1A1024 !important;
  color: #F6F0FC !important;
  border-color: #49335D !important;
}
:root[data-theme="dark"] .auth-heading h2,
:root[data-theme="dark"] .auth-heading p,
:root[data-theme="dark"] .auth-terms,
:root[data-theme="dark"] .legal-links,
:root[data-theme="dark"] .auth-storage-note {
  color: #E8DDF2 !important;
}
:root[data-theme="dark"] .auth-storage-note,
:root[data-theme="dark"] .notice-preview,
:root[data-theme="dark"] .notice-preview-item,
:root[data-theme="dark"] .home-notice-card,
:root[data-theme="dark"] .home-upcoming-card,
:root[data-theme="dark"] .home-featured-course,
:root[data-theme="dark"] .home-course-more-empty {
  background: #241731 !important;
  border-color: #49335D !important;
}
:root[data-theme="dark"] .home-course-cover,
:root[data-theme="dark"] .course-cover,
:root[data-theme="dark"] .hero-card,
:root[data-theme="dark"] .classroom-banner,
:root[data-theme="dark"] .auth-visual,
:root[data-theme="dark"] .admin-dashboard-card {
  /* Existing purple branding gradients remain the visual accent in night mode. */
  color: #FFFFFF !important;
}
:root[data-theme="dark"] .admin-dashboard-card:nth-child(n) {
  background: linear-gradient(145deg, #2E1942, #21132F) !important;
  border-color: #52376A !important;
}
:root[data-theme="dark"] .admin-dashboard-icon,
:root[data-theme="dark"] .tile-icon,
:root[data-theme="dark"] .result-stat-card>span {
  background: #39234D !important;
  color: #D5A9FF !important;
  border-color: #62477A !important;
}
:root[data-theme="dark"] .mobile-nav-item { color: #BBA9CC !important; }
:root[data-theme="dark"] .mobile-nav-item.active,
:root[data-theme="dark"] .mobile-nav-item.active>span { color: #D5A9FF !important; }
:root[data-theme="dark"] .student-table-wrap,
:root[data-theme="dark"] .student-table,
:root[data-theme="dark"] .student-table td,
:root[data-theme="dark"] .student-table th { border-color: #49335D !important; }
:root[data-theme="dark"] .student-table th { background: #30203F !important; color: #D9C8E8 !important; }
:root[data-theme="dark"] .student-table td { background: #241731; }
:root[data-theme="dark"] .planner-tabs,
:root[data-theme="dark"] .result-tabs { background: #1A1024 !important; border-color: #49335D !important; }
:root[data-theme="dark"] .planner-tabs button,
:root[data-theme="dark"] .result-tabs button { color: #C3B4D1 !important; }
:root[data-theme="dark"] .planner-tabs button.is-active,
:root[data-theme="dark"] .result-tabs button.is-active { background: #39234D !important; color: #F6F0FC !important; }
:root[data-theme="dark"] .feature-modal { background: rgba(12,5,19,.78) !important; }
:root[data-theme="dark"] .appearance-toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 13px;
  border: 1px solid #62477A;
  border-radius: 12px;
  background: #30203F;
  color: #F6F0FC;
  font: 700 12px var(--font);
  cursor: pointer;
}
:root[data-theme="dark"] .appearance-toggle>span:first-child { color: #D5A9FF; font-size: 17px; }
:root[data-theme="dark"] .appearance-toggle:focus-visible { outline: 3px solid #B34DFF; outline-offset: 2px; }
:root[data-theme="dark"] .reader-paper,
:root[data-theme="dark"] .notes-reader iframe,
:root[data-theme="dark"] .pptx-slide-stage { background: #FFFFFF !important; color: #21152F !important; }

.appearance-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid #E4D4FA;
  border-radius: 12px;
  background: #F7F1FD;
  color: #421078;
  font: 700 12px var(--font);
  cursor: pointer;
}
.appearance-toggle>span:first-child { color: #7627C8; font-size: 17px; }
.appearance-toggle:focus-visible { outline: 3px solid rgba(118,39,200,.35); outline-offset: 2px; }
.auth-form-side>.appearance-toggle { align-self: flex-end; margin: -6px 0 12px; }
.account-menu-content>.appearance-toggle { width: 100%; margin: 10px 0; }
@media (prefers-reduced-motion: reduce) { :root[data-theme="dark"] *, :root[data-theme="dark"] *::before, :root[data-theme="dark"] *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
