/* Custom CSS Design System - Discrete Math Quiz Application */

/* Fonts Import */
@import url('https://fonts.loli.net/css2?family=Outfit:wght@300;400;500;600;700;800&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap');

/* Design Tokens & CSS Variables */
:root {
  /* Light Mode Palette */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.8);
  --border-color: rgba(226, 232, 240, 0.8);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  
  --accent: #ec4899;
  --accent-hover: #db2777;
  
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.15);
  --error: #ef4444;
  --error-light: rgba(239, 68, 68, 0.15);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
  
  --backdrop-blur: 12px;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Palette overrides */
[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --border-color: rgba(255, 255, 255, 0.06);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(129, 140, 248, 0.15);
  
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  
  --success: #34d399;
  --success-light: rgba(52, 211, 153, 0.15);
  --error: #f87171;
  --error-light: rgba(248, 113, 113, 0.15);
}

/* Base Styles & Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  display: flex;
  overflow: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Layout Wrapper */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Sidebar Navigation */
.sidebar {
  width: 280px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 100;
  overflow-y: auto; /* Enable scrolling for small screen heights */
  scrollbar-width: thin; /* Firefox thin scrollbar */
  transition: all var(--transition-normal);
}

/* Custom scrollbar for sidebar to keep it clean */
.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 1.25rem;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-section {
  margin-bottom: 2rem;
}

.nav-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-left: 0.75rem;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.nav-item:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
  fill: none;
  stroke: currentColor;
}

.nav-count {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 700;
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

[data-theme="dark"] .nav-count {
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-item:hover .nav-count {
  background-color: white;
  color: var(--primary);
}

.nav-item.active .nav-count {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
}

/* Sidebar Footer & User Profile */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  height: 100%;
  overflow-y: auto;
  padding: 2rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Header Styling */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title-area h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 0.25rem;
}

.title-area p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Mode Switcher Buttons */
.segmented-control {
  background-color: var(--bg-secondary);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  gap: 0.25rem;
  box-shadow: var(--shadow-sm);
}

.segment-btn {
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  border: none;
  background-color: transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.segment-btn.active {
  background-color: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.segment-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
}

/* Primary buttons */
.btn {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background-color: var(--bg-secondary);
  border-color: var(--text-secondary);
}

/* Stats Row Dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

.stat-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon-wrapper {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary-light);
  color: var(--primary);
}

.stat-icon-wrapper.success {
  background-color: var(--success-light);
  color: var(--success);
}

.stat-icon-wrapper.accent {
  background-color: rgba(236, 72, 153, 0.1);
  color: var(--accent);
}

.stat-icon-wrapper.warning {
  background-color: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Main Practice/Exam Viewport */
.quiz-viewport {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex-grow: 1;
}

/* Search and Filter Panel */
.filter-panel {
  display: flex;
  gap: 1rem;
  align-items: center;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-sm);
}

.search-input-wrapper {
  position: relative;
  flex-grow: 1;
}

.search-input-wrapper svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.search-input {
  width: 100%;
  padding: 0.6rem 0.6rem 0.6rem 2.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: all var(--transition-fast);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Practice Card styling */
.question-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  transition: all var(--transition-normal);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.question-badge-row {
  display: flex;
  gap: 0.5rem;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  text-transform: uppercase;
}

.badge-category {
  background-color: var(--primary-light);
  color: var(--primary);
}

.badge-num {
  background-color: rgba(0, 0, 0, 0.04);
  color: var(--text-secondary);
}

[data-theme="dark"] .badge-num {
  background-color: rgba(255, 255, 255, 0.04);
}

.card-actions {
  display: flex;
  gap: 0.5rem;
}

.action-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.action-icon-btn:hover {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.action-icon-btn.active {
  color: var(--accent);
}

.action-icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.action-icon-btn.active svg {
  fill: var(--accent);
}

/* Question Statement */
.question-body {
  font-size: 1.15rem;
  font-weight: 550;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* Answer Inputs & Selectors */
.options-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.option-item:hover {
  border-color: var(--primary);
  background-color: var(--bg-secondary);
}

.option-prefix {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.option-item:hover .option-prefix {
  border-color: var(--primary);
  color: var(--primary);
}

/* Selected state */
.option-item.selected {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.option-item.selected .option-prefix {
  background-color: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Answer validation states (Practice Mode) */
.option-item.correct {
  border-color: var(--success) !important;
  background-color: var(--success-light) !important;
}

.option-item.correct .option-prefix {
  background-color: var(--success) !important;
  border-color: var(--success) !important;
  color: white !important;
}

.option-item.incorrect {
  border-color: var(--error) !important;
  background-color: var(--error-light) !important;
}

.option-item.incorrect .option-prefix {
  background-color: var(--error) !important;
  border-color: var(--error) !important;
  color: white !important;
}

/* Judgment Buttons */
.judgment-wrapper {
  display: flex;
  gap: 1rem;
  width: 100%;
}

.judgment-btn {
  flex: 1;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  font-family: inherit;
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  transition: all var(--transition-fast);
}

.judgment-btn svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.5;
}

.judgment-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.judgment-btn.selected-true {
  border-color: var(--primary);
  background-color: var(--primary-light);
  color: var(--primary);
}

.judgment-btn.correct {
  border-color: var(--success) !important;
  background-color: var(--success-light) !important;
  color: var(--success) !important;
}

.judgment-btn.incorrect {
  border-color: var(--error) !important;
  background-color: var(--error-light) !important;
  color: var(--error) !important;
}

/* Fill-in-the-blank input */
.fill-blank-wrapper {
  display: flex;
  gap: 0.75rem;
}

.fill-input {
  flex-grow: 1;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1.05rem;
  outline: none;
  transition: all var(--transition-fast);
}

.fill-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Subjective draft text area */
.subjective-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.subjective-textarea {
  width: 100%;
  height: 120px;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
  outline: none;
  transition: all var(--transition-fast);
}

.subjective-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Card Control Panel (Footer) */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.navigation-controls {
  display: flex;
  gap: 0.75rem;
}

/* Show explanation panel */
.solution-panel {
  background-color: var(--bg-primary);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--primary);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: slideDown 0.3s ease-out;
}

.solution-panel.correct-border {
  border-left-color: var(--success);
}

.solution-panel.incorrect-border {
  border-left-color: var(--error);
}

.solution-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.solution-header svg {
  width: 20px;
  height: 20px;
  stroke: var(--primary);
  stroke-width: 2;
  fill: none;
}

.solution-panel.correct-border .solution-header svg {
  stroke: var(--success);
}
.solution-panel.incorrect-border .solution-header svg {
  stroke: var(--error);
}

.solution-answer-block {
  font-weight: 600;
  font-size: 1.05rem;
}

.solution-analysis-block {
  color: var(--text-secondary);
  font-size: 0.95rem;
  white-space: pre-wrap;
  border-top: 1px dashed var(--border-color);
  padding-top: 0.75rem;
}

/* Animations */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Exam Mode UI */
.exam-header-widget {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.exam-timer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.exam-timer.warning {
  color: var(--error);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.5; }
}

.exam-progress-tracker {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-grow: 1;
  max-width: 400px;
  margin: 0 2rem;
}

.progress-bar-outer {
  flex-grow: 1;
  height: 8px;
  background-color: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-bar-inner {
  height: 100%;
  background-color: var(--primary);
  width: 0%;
  transition: width var(--transition-fast);
}

.progress-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Quick Navigator Grid in Exam */
.question-nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 0.5rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.nav-dot {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav-dot:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.nav-dot.answered {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.nav-dot.current {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.nav-dot.correct {
  background-color: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.nav-dot.incorrect {
  background-color: var(--error-light);
  border-color: var(--error);
  color: var(--error);
}

/* Exam Setup & Result Panels */
.exam-lobby-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  max-width: 600px;
  margin: 2rem auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
}

.exam-lobby-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.exam-lobby-icon svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

/* Exam Result Card */
.result-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem;
  box-shadow: var(--shadow-lg);
  max-width: 700px;
  margin: 1rem auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  text-align: center;
  align-items: center;
}

.score-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 8px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all var(--transition-slow);
}

.score-val {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--primary);
}

.score-max {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
  max-width: 480px;
  margin-top: 1rem;
}

.result-stat-item {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-stat-val {
  font-size: 1.5rem;
  font-weight: 700;
}

.result-stat-val.correct-color {
  color: var(--success);
}
.result-stat-val.error-color {
  color: var(--error);
}

.result-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 0.25rem;
}

/* Floating Notification toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-icon.success {
  background-color: var(--success-light);
  color: var(--success);
}

.toast-icon.info {
  background-color: var(--primary-light);
  color: var(--primary);
}

/* Math equations KaTeX wrapper improvements */
.katex-display {
  margin: 0.5em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2rem 0;
}

/* Custom Table style for Markdown / Truth tables */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.95rem;
}

th, td {
  border: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  text-align: center;
}

th {
  background-color: var(--bg-primary);
  font-weight: 700;
  color: var(--text-primary);
}

tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Empty bookmarks page */
.empty-bookmarks-card {
  text-align: center;
  padding: 4rem 2rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 500px;
  margin: 2rem auto;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Responsive Design tweaks */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .main-content {
    padding: 2rem;
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }
  .app-container {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
  }
  .main-content {
    padding: 1.5rem;
    height: auto;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .judgment-wrapper {
    flex-direction: column;
  }
  .card-footer {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  .navigation-controls {
    justify-content: space-between;
  }
  .exam-header-widget {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  .exam-progress-tracker {
    margin: 0;
    max-width: 100%;
  }
}

/* --- User Profile Card & Auth Styles --- */
.user-profile-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  transition: all var(--transition-fast);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.user-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.15rem;
}

/* Modal Overlay & Popups */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast) ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  position: relative;
  transform: scale(0.9);
  transition: transform var(--transition-fast) cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.show .modal-card {
  transform: scale(1);
}

.modal-close-btn {
  position: absolute;
  right: 1.25rem;
  top: 1.25rem;
  background: none;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  gap: 1.25rem;
}

.modal-tab-btn {
  border: none;
  background: none;
  padding: 0.5rem 0.25rem 0.75rem 0.25rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--text-muted);
  position: relative;
  transition: color var(--transition-fast);
}

.modal-tab-btn:hover {
  color: var(--text-primary);
}

.modal-tab-btn.active {
  color: var(--primary);
}

.modal-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2.5px;
  background-color: var(--primary);
  border-radius: 2px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Leaderboard Page Styles */
.leaderboard-table-wrapper {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

.leaderboard-table th {
  background-color: var(--bg-primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border: none;
  padding: 1.15rem 1rem;
}

.leaderboard-table td {
  border: none;
  border-top: 1px solid var(--border-color);
  padding: 1.15rem 1rem;
  font-size: 0.95rem;
}

.leaderboard-table tbody tr:hover {
  background-color: rgba(99, 102, 241, 0.03);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.85rem;
}

.rank-1 {
  background-color: #fef3c7;
  color: #d97706;
}

.rank-2 {
  background-color: #f1f5f9;
  color: #475569;
}

.rank-3 {
  background-color: #ffedd5;
  color: #ea580c;
}

.rank-other {
  background-color: transparent;
  color: var(--text-secondary);
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-top: 1rem;
}

.lobby-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lobby-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.lobby-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary-light);
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.lobby-card h3 {
  font-size: 1.2rem;
  font-weight: 750;
}

.lobby-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.lobby-card-meta {
  margin-top: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* --- Topic Mastery Panel Styles --- */
.mastery-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.mastery-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all var(--transition-normal);
}

.mastery-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(99, 102, 241, 0.2);
}

.mastery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mastery-header h3 {
  font-size: 0.95rem;
  font-weight: 750;
  color: var(--text-primary);
}

.mastery-percentage {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
}

.mastery-progress-bar-wrapper {
  background-color: rgba(0, 0, 0, 0.05);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

[data-theme="dark"] .mastery-progress-bar-wrapper {
  background-color: rgba(255, 255, 255, 0.05);
}

.mastery-progress-bar {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  height: 100%;
  border-radius: 4px;
  width: 0%;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.mastery-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .mastery-panel {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* --- Practice Answer Sheet Card --- */
.practice-answer-sheet-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.practice-sheet-title {
  font-size: 0.95rem;
  font-weight: 750;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.practice-sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 0.6rem;
}

.practice-sheet-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.practice-sheet-cell:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.practice-sheet-cell.current {
  border-color: var(--primary);
  background-color: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.practice-sheet-cell.correct {
  background-color: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.practice-sheet-cell.incorrect {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: var(--error);
  color: var(--error);
}

/* --- Comments and Discussion Board --- */
.comment-item {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
}

.comment-item:hover {
  background-color: rgba(99, 102, 241, 0.02);
}

.comment-user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

.comment-bubble {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.comment-text {
  font-size: 0.82rem;
  color: var(--text-primary);
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.comment-empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 1.5rem;
}

/* --- Floating AI Assistant Window --- */
#ai-floating-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transition: all var(--transition-normal);
}

#ai-floating-toggle:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

#ai-floating-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 999;
  width: 380px;
  height: 540px;
  max-height: calc(100vh - 120px);
  max-width: calc(100vw - 48px);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all var(--transition-normal);
}

#ai-floating-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-window-header {
  height: 54px;
  padding: 0 1.25rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-window-title {
  font-weight: 750;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-window-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

.ai-window-close:hover {
  opacity: 1;
}

.ai-window-context {
  background-color: rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-window-chat {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ai-msg-bubble {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  font-size: 0.82rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.ai-msg-bubble.user {
  align-self: flex-end;
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: 12px 12px 0 12px;
  font-weight: 600;
}

.ai-msg-bubble.assistant {
  align-self: flex-start;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 12px 12px 12px 0;
}

.ai-msg-bubble p {
  margin-bottom: 0.4rem;
}

.ai-msg-bubble p:last-child {
  margin-bottom: 0;
}

.ai-window-input-row {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  display: flex;
  gap: 0.5rem;
}

.ai-window-input-row input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.82rem;
  transition: border-color var(--transition-fast);
}

.ai-window-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.ai-window-input-row button {
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* --- Layout shift to prevent AI window from obstructing content --- */
@media (min-width: 1025px) {
  .main-content {
    transition: padding-right var(--transition-normal) ease;
  }
  .main-content.ai-open {
    padding-right: 420px; /* Leaves space for the 380px wide AI window + 40px margin */
  }
}
