/* ================== VARIABLES ================== */
:root {
  --primary: #3b82f6; /* Blue */
  --primary-hover: #2563eb;
  --secondary: #64748b;
  --secondary-hover: #475569;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --info: #0ea5e9;
  --warning: #f59e0b;
  --review: #8b5cf6; /* Purple for Marked for Review */
  
  --bg-color: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --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);
  
  --transition: all 0.2s ease-in-out;
  
  --header-height: 64px;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --secondary: #94a3b8;
  --secondary-hover: #cbd5e1;
  --bg-color: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

/* ================== GLOBAL RESET ================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

/* ================== UTILITIES ================== */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.text-center { text-align: center; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.font-medium { font-weight: 500; }

.hidden { display: none !important; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.align-center { align-items: center; }

.m-t-3 { margin-top: 1rem; }
.m-b-3 { margin-bottom: 1rem; }
.m-b-4 { margin-bottom: 1.5rem; }
.m-y-3 { margin-top: 1rem; margin-bottom: 1rem; }
.ml-2 { margin-left: 0.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.mb-10 { margin-bottom: 3rem; }
.mt-4 { margin-top: 1rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.py-10 { padding-top: 3rem; padding-bottom: 3rem; }

/* ================== BUTTONS ================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  font-family: inherit;
}

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

.btn-secondary {
  background-color: var(--secondary);
  color: #fff;
}
.btn-secondary:hover { background-color: var(--secondary-hover); }

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background-color: var(--danger-hover); }

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

.btn-ghost {
  background-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background-color: var(--surface-hover);
  color: var(--text-main);
}

.btn-icon {
  padding: 0.5rem;
  border-radius: 50%;
  background: transparent;
  color: var(--text-main);
}
.btn-icon:hover { background-color: var(--surface-hover); }

.btn-block {
  width: 100%;
  display: block;
}

.btn-disabled, .btn:disabled {
  background-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

/* ================== COMPONENTS ================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: var(--border);
  color: var(--text-main);
}
.badge-success { background-color: var(--success); color: white; }
.badge-subtle { background-color: var(--surface); border: 1px solid var(--border); }
.badge-secondary { background-color: var(--secondary); color: white; }

.form-control {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text-main);
  font-family: inherit;
  outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* ================== LOADING SPINNER ================== */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================== HEADER / FOOTER ================== */
.app-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-main);
}

.logo-img {
  width: auto;
  height: 40px;
  display: block;
  object-fit: contain;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-footer {
  padding: 2rem 0;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 4rem;
}

/* ================== HOME PAGE ================== */
.hero {
  padding: 4rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 800px;
  margin: 0 auto;
}
.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 1rem;
  line-height: 1.2;
}
.hero-subtitle {
  font-size: 1.125rem;
  color: var(--text-muted);
  max-width: 600px;
}

.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.test-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.test-card:hover:not(.locked) {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.test-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.test-header h4 {
  font-size: 1.25rem;
  font-weight: 600;
}
.test-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
  flex-grow: 1;
}
.test-footer {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.test-stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}
.test-actions-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ================== TEST INTERFACE ================== */
body.test-mode {
  display: flex;
  flex-direction: column;
  overflow: auto !important;
}

.test-header {
  background-color: #1e293b; /* Always dark for focus */
  color: white;
  height: var(--header-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  flex-shrink: 0;
}
.test-info {
  display: flex;
  align-items: center;
  gap: 2rem;
}
.test-info h2 {
  font-size: 1.125rem;
  font-weight: 600;
}
.timer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  background-color: rgba(255,255,255,0.1);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.timer.warning {
  color: #fca5a5;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.7; }
  100% { opacity: 1; }
}
.test-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.test-actions .btn-icon { color: white; }

/* Test Layout */
.test-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  background-color: var(--bg-color);
}

/* Main Area */
.test-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.section-tabs-wrapper {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.section-tabs {
  display: flex;
  padding: 0 1rem;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.tab-btn:hover {
  color: var(--text-main);
  background-color: var(--surface-hover);
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.sec-badge {
  font-size: 0.75rem;
  background-color: var(--border);
  padding: 0.15rem 0.4rem;
  border-radius: 99px;
  color: var(--text-main);
}
.tab-btn.active .sec-badge {
  background-color: var(--primary);
  color: white;
}

/* Question Area */
.question-container {
  padding: 1.5rem;
  font-size: 18px;
  line-height: 1.7;
  flex: 1;
  max-height: 70vh;
  overflow-y: auto;
  background-color: var(--bg-color);
}
.question-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.question-badge {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
}
.marks-badge {
  font-size: 0.9rem;
  font-weight: 600;
  background-color: var(--surface);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.question-text {
  font-weight: 500;
  margin-bottom: 2rem;
  color: var(--text-main);
}

.math-block {
  display: block;
  margin: 1rem 0;
  overflow-x: auto;
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.option-label {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  cursor: pointer;
  transition: var(--transition);
}
.option-label:hover {
  border-color: var(--primary);
  background-color: var(--surface-hover);
}
.option-label.selected {
  border-color: var(--primary);
  background-color: rgba(59, 130, 246, 0.05); /* very light blue */
}
.option-input {
  margin-right: 1rem;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary);
}
.option-text {
  font-size: 1rem;
}

.action-footer {
  background-color: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.left-actions, .right-actions {
  display: flex;
  gap: 1rem;
}

/* Sidebar */
.test-sidebar {
  width: 320px;
  background-color: var(--surface);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status-legend {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.legend-row {
  display: flex;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
}
.status-box {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
/* Grid Button Statuses */
.status-box.not-visited, .grid-btn.not-visited {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}
.status-box.not-answered, .grid-btn.not-answered {
  background-color: var(--danger);
  border-color: var(--danger);
  color: white;
}
.status-box.answered, .grid-btn.answered {
  background-color: var(--success);
  border-color: var(--success);
  color: white;
}
.status-box.review, .grid-btn.review {
  background-color: var(--review);
  border-color: var(--review);
  color: white;
}
.status-box.answered-review, .grid-btn.answered-review {
  background-color: var(--review);
  border-color: var(--review);
  color: white;
  position: relative;
}
.grid-btn.answered-review::after, .status-box.answered-review::after {
  content: '';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  border: 1px solid var(--surface);
}

.section-summary {
  padding: 1rem;
  flex: 1;
  overflow-y: auto;
}
.question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  padding: 1rem;
  overflow-y: auto;
}
.grid-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
}
.grid-btn.current {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

/* ================== RESULTS PAGE ================== */
.result-dashboard {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
}
.score-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
}
.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 2rem;
  color: var(--text-muted);
}
.score-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 8px solid var(--primary);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-color);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
.score-inner {
  display: flex;
  flex-direction: column;
}
.score-number {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--primary);
}
.score-total {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}
.progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background-color: var(--primary);
  border-radius: 99px;
  transition: width 1s ease-out;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}
.stat-box {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: center;
}
.success-box { border-color: rgba(16, 185, 129, 0.3); }
.success-box .stat-icon { background-color: rgba(16, 185, 129, 0.1); }
.danger-box { border-color: rgba(239, 68, 68, 0.3); }
.danger-box .stat-icon { background-color: rgba(239, 68, 68, 0.1); }

.stat-content {
  display: flex;
  flex-direction: column;
}
.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}
.section-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.section-card h4 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}
.sec-stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.questions-review-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.review-item {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.review-item.correct { border-left: 4px solid var(--success); }
.review-item.incorrect { border-left: 4px solid var(--danger); }
.review-item.unattempted { border-left: 4px solid var(--secondary); }

.review-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.review-question {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 1rem;
}
.review-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.review-opt {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background-color: var(--bg-color);
}
.review-opt.is-correct {
  background-color: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}
.review-opt.is-wrong {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}


/* ================== MODALS ================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background-color: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 90%;
  max-width: 450px;
  box-shadow: var(--shadow-lg);
}
.modal h3 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}
.modal p {
  color: var(--text-muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
}

/* ================== MEDIA QUERIES ================== */
.mobile-only { display: none; }
.hidden-mobile { display: inline-flex; }

/* ================== IMAGE LOGOS ================== */
#home-header {
  text-align: center;
  margin-top: 20px;
}

.logo-home {
  width: 100px;
  margin-bottom: 10px;
  border-radius: 8px;
}

@media (max-width: 768px) {
  .hero-title { font-size: 2rem; }
  
  .test-main-area { border-right: none; border: none !important; }
  
  .test-container {
    height: auto;
    overflow: visible;
    padding: 10px;
    gap: 20px;
  }
  
  #question-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 300px;
    height: 100%;
    background: var(--surface);
    transition: transform 0.3s ease;
    z-index: 2000;
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
  }
  
  #question-panel.closed {
    transform: translateX(100%);
  }
  
  .logo-home {
    width: 80px;
  }
  
  .question-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  
  .option-image {
    max-width: 100px;
  }
  
  .mobile-only { display: inline-flex; }
  .hidden-mobile { display: none; }
  
  .question-container { padding: 1rem; font-size: 16px; }
  .action-footer {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }
  .left-actions, .right-actions {
    width: 100%;
    justify-content: space-between;
  }
  .left-actions .btn, .right-actions .btn { flex: 1; text-align: center; }
  
  .result-dashboard { grid-template-columns: 1fr; }
}

/* ================== MATH & MATCH TABLES ================== */
.match-table { 
  width: 100%; 
  border-collapse: collapse; 
  margin: 1.5rem 0; 
  font-size: 1rem;
}
.match-table th, .match-table td { 
  border: 1px solid var(--border); 
  padding: 0.75rem 1rem; 
  text-align: left; 
}
.match-table th {
  background-color: var(--surface-hover);
  font-weight: 600;
}

/* Base modifications for Option layouts */
.question-text {
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 2.5rem;
}
.options-container {
  gap: 1.2rem;
}
.option-text {
  font-size: 18px;
  line-height: 1.6;
}

@media (min-width: 900px) {
  /* Real Exam 3-Column Layout Override */
  .test-container {
    display: grid !important;
    grid-template-columns: 70% 30% !important;
    gap: 20px;
    padding: 20px;
    background-color: var(--surface-hover);
    height: calc(100vh - var(--header-height));
    max-width: 1400px;
    margin: 0 auto;
  }
  .test-main-area {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg);
    background-color: var(--surface);
    height: 100%;
  }
  .test-sidebar {
    width: 100% !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg);
    background-color: var(--surface);
    height: 100%;
  }
}

/* ================== MATH & RESPONSIVE MULTIMEDIA ================== */
.question-image {
  max-width: 100%;
  margin: 15px 0;
  border-radius: 10px;
}

.option-image {
  max-width: 120px;
  margin-top: 5px;
}

.math-content, .math-block {
  overflow-x: auto;
  padding: 10px 0;
}

.match-container {
  overflow-x: auto;
  width: 100%;
}

.match-table {
  width: 100%;
  border-collapse: collapse;
}

button, .option-label, .tab-btn {
  min-height: 44px;
}
