:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --border-radius: 12px;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --modal-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: bold;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gray-900);
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--gray-600);
}

.nav-links a {
  text-decoration: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: var(--primary-light);
  transition: all 0.2s;
}

.nav-links a:hover {
  background: #dbeafe;
}

/* Main Container */
.main-container {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

/* Screen Transitions */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.25s ease-in-out;
}

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

/* Card */
.card {
  background: #ffffff;
  border-radius: var(--border-radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--card-shadow);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.75rem;
}

.card-desc {
  color: var(--gray-600);
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--gray-700);
  margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Info Box */
.info-box {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.info-box ul {
  padding-left: 1.25rem;
  margin-top: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

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

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-800);
}
.btn-secondary:hover {
  background: var(--gray-300);
}

.btn-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.btn-warning:hover {
  background: #fde68a;
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover {
  background: #15803d;
}

.btn-block {
  width: 100%;
}

/* Top bar during exam */
.exam-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 0.85rem 1.25rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--gray-200);
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.exam-student {
  font-weight: 700;
  color: var(--gray-900);
}

.exam-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--gray-100);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.exam-meta-pill.warning {
  background: #fef3c7;
  color: #b45309;
}

.timer-pill {
  font-family: monospace;
  font-size: 1rem;
  font-weight: bold;
  background: #f8fafc;
  border: 1px solid var(--gray-300);
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
}

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

/* Question Header */
.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.task-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}

.points-badge {
  background: var(--gray-100);
  color: var(--gray-700);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.question-text {
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--gray-900);
  white-space: pre-line;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* Options (Single / Multiple Choice) */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.option-card {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: white;
}

.option-card:hover {
  border-color: var(--gray-300);
  background: #f8fafc;
}

.option-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-card input[type="radio"],
.option-card input[type="checkbox"] {
  margin-top: 0.25rem;
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

.option-text {
  font-size: 1rem;
  color: var(--gray-800);
  flex: 1;
}

/* True / False Layout */
.tf-buttons {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.tf-btn {
  flex: 1;
  padding: 1rem;
  text-align: center;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  background: white;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.tf-btn:hover {
  background: #f8fafc;
}

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

.tf-btn.selected-false {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
}

.reason-box {
  margin-top: 1rem;
  padding: 1rem;
  background: #fef2f2;
  border: 1px dashed var(--danger);
  border-radius: 8px;
}

.reason-box label {
  font-weight: 600;
  color: #991b1b;
  display: block;
  margin-bottom: 0.4rem;
}

/* Sub-questions / Calculations */
.subquestions-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.subquestion-item {
  background: #f8fafc;
  border: 1px solid var(--gray-200);
  padding: 1rem;
  border-radius: 8px;
}

.subquestion-label {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--gray-800);
}

/* Tables */
.quiz-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.quiz-table th, .quiz-table td {
  border: 1px solid var(--gray-300);
  padding: 0.65rem 0.85rem;
  text-align: left;
}

.quiz-table th {
  background: var(--gray-100);
  font-weight: 600;
}

/* Matching and Ordering items */
.sortable-item, .matching-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.sortable-handle {
  cursor: grab;
  color: var(--gray-600);
  display: flex;
  gap: 0.25rem;
}

.sort-btn-group {
  display: flex;
  gap: 0.35rem;
}

.btn-icon {
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
}
.btn-icon:hover {
  background: var(--gray-200);
}

/* Action Bar */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 30px;
  font-size: 0.95rem;
  box-shadow: var(--modal-shadow);
  z-index: 1000;
  display: none;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Results Screen */
.result-header {
  text-align: center;
  padding: 2rem 1rem;
}

.grade-badge-huge {
  display: inline-block;
  padding: 0.6rem 2rem;
  border-radius: 30px;
  font-size: 1.6rem;
  font-weight: 800;
  margin: 1rem 0;
}

.grade-5 { background: #dcfce7; color: #166534; border: 2px solid #86efac; }
.grade-4 { background: #e0f2fe; color: #075985; border: 2px solid #7dd3fc; }
.grade-3 { background: #fef9c3; color: #854d0e; border: 2px solid #fde047; }
.grade-2 { background: #ffedd5; color: #9a3412; border: 2px solid #fdba74; }
.grade-1 { background: #fee2e2; color: #991b1b; border: 2px solid #fca5a5; }

.score-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.stat-item {
  background: #f8fafc;
  border: 1px solid var(--gray-200);
  padding: 1rem 1.75rem;
  border-radius: 10px;
  text-align: center;
}

.stat-val {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--gray-900);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--gray-600);
  font-weight: 600;
  text-transform: uppercase;
}

/* Review Accordion */
.review-item {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.review-item-header {
  padding: 1rem 1.25rem;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
}

.review-item-body {
  padding: 1.25rem;
  background: #f8fafc;
  border-top: 1px solid var(--gray-200);
  font-size: 0.95rem;
}

.solution-box {
  background: #f0fdf4;
  border-left: 4px solid var(--success);
  padding: 0.85rem;
  border-radius: 4px;
  margin-top: 0.75rem;
  color: #14532d;
}

.user-answer-box {
  background: white;
  border: 1px solid var(--gray-300);
  padding: 0.75rem;
  border-radius: 4px;
  margin-top: 0.5rem;
}

/* Admin Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.data-table th {
  background: var(--gray-100);
  font-weight: 700;
  color: var(--gray-700);
  font-size: 0.85rem;
  text-transform: uppercase;
}

.data-table tr:hover {
  background: #f8fafc;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 1rem;
}

.modal-content {
  background: white;
  border-radius: var(--border-radius);
  max-width: 750px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem;
  box-shadow: var(--modal-shadow);
}

/* Responsive */
@media (max-width: 640px) {
  .action-bar {
    flex-direction: column-reverse;
  }
  .action-bar button {
    width: 100%;
  }
  .tf-buttons {
    flex-direction: column;
  }
}
