* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px 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);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.header-stats {
  display: flex;
  gap: 16px;
  font-size: 14px;
  color: var(--gray-500);
}

.header-stats .stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-stats .stat-value {
  font-weight: 600;
  color: var(--gray-700);
}

.header-stats .correct { color: var(--success); }
.header-stats .wrong { color: var(--danger); }

.btn-stats {
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--gray-600);
  transition: all 0.2s;
}

.btn-stats:hover {
  background: var(--gray-200);
}

/* ===== LOGIN ===== */
.login-card {
  max-width: 400px;
  margin: 60px auto 0;
  background: white;
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
}

.login-input:focus {
  border-color: var(--primary);
}

.login-switch {
  text-align: center;
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 8px;
}

.login-switch a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-user {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-600);
}

/* ===== CONTAINER ===== */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ===== HOME SCREEN ===== */
.screen { display: none; }
.screen.active { display: block; }

.home-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--gray-900);
}

.home-subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 40px;
  font-size: 16px;
}

.subject-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.subject-card {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.subject-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg);
}

.subject-card.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.subject-card h3 {
  font-size: 18px;
  margin-bottom: 4px;
}

.subject-card .count {
  font-size: 14px;
  color: var(--gray-500);
}

.mode-section {
  margin-bottom: 32px;
}

.mode-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--gray-700);
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.mode-card {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.mode-card:hover {
  border-color: var(--primary-light);
}

.mode-card.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.mode-card h4 {
  font-size: 15px;
  margin-bottom: 4px;
}

.mode-card .mode-desc {
  font-size: 12px;
  color: var(--gray-500);
}

.mode-card .mode-count {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 8px;
}

.count-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.count-btn {
  width: 60px;
  height: 48px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  background: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--gray-700);
}

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

.count-btn.selected {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
}

.btn-start {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  padding: 14px 32px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-start:hover {
  background: #4338ca;
  box-shadow: var(--shadow-lg);
}

.btn-start:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* ===== QUIZ SCREEN ===== */
.progress-bar {
  background: var(--gray-200);
  border-radius: 999px;
  height: 6px;
  margin-bottom: 24px;
  overflow: hidden;
}

.progress-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}

.quiz-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--gray-500);
}

.question-card {
  background: white;
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.question-text {
  font-size: 17px;
  line-height: 1.6;
  margin-bottom: 24px;
  color: var(--gray-900);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
  line-height: 1.5;
}

.option:hover:not(.disabled) {
  border-color: var(--primary-light);
  background: #eef2ff;
}

.option .option-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--gray-200);
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-600);
}

.option.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.option.selected .option-letter {
  background: var(--primary);
  color: white;
}

.option.correct {
  border-color: var(--success);
  background: var(--success-bg);
}

.option.correct .option-letter {
  background: var(--success);
  color: white;
}

.option.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.option.wrong .option-letter {
  background: var(--danger);
  color: white;
}

.option.disabled {
  cursor: default;
}

.option.disabled:hover {
  border-color: var(--gray-200);
  background: var(--gray-50);
}

.option.disabled.correct:hover {
  border-color: var(--success);
  background: var(--success-bg);
}

.option.disabled.wrong:hover {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.quiz-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

.btn {
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.btn-next {
  background: var(--primary);
  color: white;
}

.btn-next:hover {
  background: #4338ca;
}

.btn-explain {
  background: white;
  color: var(--warning);
  border-color: var(--warning);
}

.btn-explain:hover {
  background: #fffbeb;
}

.btn-home {
  background: var(--gray-100);
  color: var(--gray-600);
  border-color: var(--gray-200);
}

.btn-home:hover {
  background: var(--gray-200);
}

.feedback {
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 15px;
}

.feedback.correct {
  background: var(--success-bg);
  color: var(--success);
}

.feedback.wrong {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ===== CHAT MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.chat-modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 700px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h3 {
  font-size: 16px;
  color: var(--gray-800);
}

.btn-close {
  background: var(--gray-100);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--gray-500);
}

.btn-close:hover {
  background: var(--gray-200);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
}

.message.assistant {
  align-self: flex-start;
  background: var(--gray-100);
  border-bottom-left-radius: 4px;
}

.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.loading {
  color: var(--gray-400);
  font-style: italic;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--primary);
}

.btn-send {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-send:hover {
  background: #4338ca;
}

.btn-send:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* ===== STATS MODAL ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stats-card {
  background: var(--gray-50);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stats-card .stats-number {
  font-size: 28px;
  font-weight: 700;
}

.stats-card .stats-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

.stats-card.new .stats-number { color: var(--primary); }
.stats-card.correct .stats-number { color: var(--success); }
.stats-card.wrong .stats-number { color: var(--danger); }
.stats-card.total .stats-number { color: var(--gray-700); }

.stats-subject {
  margin-bottom: 16px;
}

.stats-subject h4 {
  font-size: 14px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.stats-bar {
  height: 24px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: var(--gray-200);
}

.stats-bar .bar-correct {
  background: var(--success);
  transition: width 0.3s;
}

.stats-bar .bar-wrong {
  background: var(--danger);
  transition: width 0.3s;
}

.stats-bar .bar-new {
  background: var(--primary-light);
  transition: width 0.3s;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .subject-cards { grid-template-columns: 1fr; }
  .mode-cards { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .question-card { padding: 20px; }
  .container { padding: 20px 16px; }
}
