:root {
  --bg: #FFFFFF;
  --card: #F9FAFB;
  --muted: #64748B;
  --accent: #065F46;
  --glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --success: #10B981;
  --danger: #EF4444;
  --energy: #FF5733;
  --primary: #000000;
  --max-w: 980px;
  --border: #E2E8F0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
  --top-bar-height: 64px;
  --z-top-bar: 2000;
  --z-nav: 1000;

  --font-main: 'Lexend', system-ui, -apple-system, sans-serif;
  --font-code: 'Courier Prime', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: #0F172A;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.glass-panel {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-glass);
  border-radius: 16px;
}

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 20px;
}

/* Card Styles */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
}

/* Auth Styles */
.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
}

.logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  color: white;
  box-shadow: var(--shadow-lg);
}

.brand-text {
  text-align: center;
}

.brand-text h1 {
  font-size: 28px;
  margin: 0;
  color: #111827;
  font-weight: 700;
}

.brand-text p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 400;
}

.tabs {
  display: flex;
  background: var(--glass);
  border-radius: 12px;
  padding: 6px;
  margin-bottom: 28px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 12px 16px;
  text-align: center;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  color: var(--muted);
}

.tab.active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow);
}

.tab:not(.active):hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}

.form-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
}

.form-group input {
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  color: #1F2937;
  font-family: inherit;
  font-size: 16px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input::placeholder {
  color: #9CA3AF;
}

.password-toggle {
  position: relative;
}

.toggle-icon {
  position: absolute;
  right: 16px;
  top: 42px;
  cursor: pointer;
  color: var(--muted);
  background: white;
  padding: 4px;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.toggle-icon:hover {
  color: var(--accent);
}

.password-toggle {
  position: relative;
}

.toggle-icon {
  position: absolute;
  right: 16px;
  top: 42px;
  cursor: pointer;
  color: var(--muted);
  background: white;
  padding: 4px;
  border-radius: 4px;
}

.remember-forgot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
}

.remember input {
  accent-color: var(--accent);
}

.remember span {
  color: #374151;
}

.forgot {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.forgot:hover {
  text-decoration: underline;
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 16px 24px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: #374151;
  box-shadow: none;
}

.btn.ghost:hover {
  background: #F3F4F6;
  border-color: #D1D5DB;
  transform: none;
  box-shadow: none;
}

.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  color: var(--muted);
  font-size: 14px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.social-login {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.social-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--border);
  color: #374151;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.social-btn:hover {
  background: #F9FAFB;
  border-color: var(--accent);
  color: var(--accent);
}

.signup-prompt {
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  margin-top: 28px;
}

.signup-prompt a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.signup-prompt a:hover {
  text-decoration: underline;
}

.form-page {
  display: none;
}

.form-page.active {
  display: block;
}

/* Quiz Styles */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

/* Top Bar Styles */
.app-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-height);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: var(--z-top-bar);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.app-top-bar .brand {
  display: flex;
  flex-direction: row;
  /* Force horizontal layout */
  align-items: center;
  justify-content: flex-start;
  /* Ensure left alignment */
  gap: 12px;
  margin: 0;
  /* Reset default margin */
}

.app-top-bar .logo {
  width: 36px;
  height: 36px;
  font-size: 16px;
  border-radius: 8px;
  box-shadow: none;
  /* Flatter look for bar */
}

.app-top-bar .brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.02em;
}

/* Adjust body padding for top bar */
body {
  padding-top: calc(var(--top-bar-height) + 20px);
}

.grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

.sidebar .section {
  margin-bottom: 20px;
}

.section h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #111827;
  font-weight: 600;
}

.subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: white;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  color: #374151;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
  font-weight: 500;
}

.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.chip:not(.active):hover {
  border-color: var(--accent);
  color: var(--accent);
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

select,
button {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  color: #374151;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card {
  padding: 24px;
  border-radius: 12px;
  background: white;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 280px;
}

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.prompt {
  font-size: 18px;
  margin: 16px 0;
  color: #111827;
  line-height: 1.6;
  font-weight: 500;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option {
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
  font-weight: 500;
}

.option:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.option.selected {
  background: rgba(37, 99, 235, 0.08);
  border-color: var(--accent);
  color: var(--accent);
}

.option.correct {
  background: rgba(16, 185, 129, 0.08);
  border-color: var(--success);
  color: var(--success);
}

.option.wrong {
  background: rgba(239, 68, 68, 0.08);
  border-color: var(--danger);
  color: var(--danger);
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.progress {
  height: 8px;
  background: #E5E7EB;
  border-radius: 4px;
  overflow: hidden;
}

.progress>i {
  display: block;
  height: 100%;
  background: linear-gradient(135deg, var(--accent), #1D4ED8);
  transition: width 0.3s ease;
  border-radius: 4px;
}

.results {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat {
  padding: 16px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--border);
  min-width: 140px;
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 24px;
  color: #111827;
  margin-top: 4px;
}

/* Confidence Rating */
.confidence-rating {
  margin: 20px 0;
  padding: 20px;
  background: var(--glass);
  border-radius: 12px;
  border: 1px solid var(--border);
  display: none;
}

.confidence-rating h4 {
  margin: 0 0 16px 0;
  color: #111827;
  font-weight: 600;
}

.confidence-buttons {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.confidence-btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 16px;
  font-weight: 500;
}

.confidence-btn:hover {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

/* Dashboard Styles */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.metric-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.progress-ring {
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.insight-item {
  padding: 16px;
  border-radius: 8px;
  background: #F9FAFB;
  margin-bottom: 12px;
  border-left: 4px solid var(--border);
}

.insight-item.high-priority {
  border-left-color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
}

.insight-item.medium-priority {
  border-left-color: var(--accent);
  background: rgba(37, 99, 235, 0.05);
}

.insight-item.low-priority {
  border-left-color: var(--success);
  background: rgba(16, 185, 129, 0.05);
}

/* Loading and Alerts */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 10;
  display: none;
  backdrop-filter: blur(4px);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(6, 95, 70, 0.2);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.alert {
  padding: 16px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  display: none;
  font-weight: 500;
}

.alert-error {
  background-color: rgba(239, 68, 68, 0.08);
  color: #DC2626;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background-color: rgba(16, 185, 129, 0.08);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

footer.small {
  margin-top: 24px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 20px 0;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .logo {
    width: 56px;
    height: 56px;
    font-size: 20px;
  }

  .card {
    padding: 24px;
  }

  .social-login {
    flex-direction: column;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    justify-content: center;
  }

  .brand-text h1 {
    font-size: 24px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 16px;
  }

  .card {
    padding: 20px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .results {
    flex-direction: column;
  }

  .stat {
    min-width: auto;
  }

  .confidence-buttons {
    flex-direction: column;
  }

  .confidence-btn {
    min-width: auto;
  }

  .tabs {
    flex-direction: column;
  }

  .brand {
    flex-direction: column;
    text-align: center;
  }
}

/* --- A/B Test: Subject Selection Variants --- */

/* Variant A: Chips Grid */
.subject-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.subject-chip {
  padding: 10px 16px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--border);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.subject-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.subject-chip.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

/* Loading Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(37, 99, 235, 0.2);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 1s ease-in-out infinite;
  margin: 20px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

/* Modern Utilities */
.text-center {
  text-align: center;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-4 {
  margin-top: 1rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.w-full {
  width: 100%;
}

.gap-2 {
  gap: 0.5rem;
}


.subject-carousel {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 4px 4px 20px 4px;
  /* Bottom padding for shadow */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* Firefox */
}

.subject-carousel::-webkit-scrollbar {
  display: none;
  /* Chrome/Safari */
}

.carousel-card {
  min-width: 140px;
  height: 140px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  scroll-snap-align: start;
  position: relative;
  user-select: none;
}

.carousel-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.carousel-card.selected {
  border: 2px solid var(--accent);
  background: rgba(37, 99, 235, 0.04);
}

.carousel-card.selected::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.carousel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
}

.subject-carousel-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* Critical for flex items */
  overflow: hidden;
  /* Hide scrollbars nicely */
  margin-top: 16px;
  position: relative;
}

/* --- AI Tutor Feature --- */

.ai-explanation-box {
  margin-top: 20px;
  background: white;
  border-radius: 12px;
  padding: 20px;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  /* Soft shadow */
  border: 2px solid transparent;
  background-clip: padding-box;
  animation: slideDown 0.3s ease-out;
}

/* Magic gradient border effect */
.ai-explanation-box::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  margin: -2px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #ec4899, #8b5cf6);
}

.ai-tutor-btn {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
  transition: all 0.2s ease;
}

.ai-tutor-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dynamic Subject Filters */
.subject-carousel-container {
  width: 100%;
  overflow-x: auto;
  padding: 10px 0;
  scrollbar-width: none;
}

.subject-carousel-container::-webkit-scrollbar {
  display: none;
}

.subject-carousel {
  display: flex;
  gap: 15px;
  padding: 5px;
}

.carousel-card {
  min-width: 140px;
  padding: 15px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.carousel-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.carousel-card.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.carousel-card i {
  font-size: 24px;
  margin-bottom: 5px;
}

.subject-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.subject-chip {
  padding: 8px 16px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.subject-chip:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

.subject-chip.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}